Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/37842-skill-evals-memory-isolated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@objectstack/scenarios': patch
---

Clause-②: no
Metadata-protocol: none

A skill-eval round run inside a project container no longer reads that project's memory. Each turn used to inherit the container's memory variables (`CLAUDE_COWORK_MEMORY_PATH_OVERRIDE`, `CLAUDE_MEMORY_STORES`), so the turns of both arms could answer from the project's own notes and the without-skill arm scored as if it had the skill. Every turn is now spawned without them, listed as `CLAUDE_MEMORY_ENV` next to the API-billing and effort variables. The scenario runner's own build and ask turns (`npx @objectstack/scenarios run`) are spawned without them too, and the README says both kinds of turn are isolated from project memory.
6 changes: 6 additions & 0 deletions packages/qa/scenarios/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,12 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o
- **Login**: the scenario runner's guard, imported from `src/runner/driver.ts`. A round refuses to start while
`ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN` is set, or when `claude auth status` reports no login or an API-key
login. Every turn is spawned without those two variables. Never an API-billed key.
- **Isolated from project memory**: a round run inside a project container is isolated from that project's memory.
The container sets `CLAUDE_COWORK_MEMORY_PATH_OVERRIDE` and `CLAUDE_MEMORY_STORES` so its own sessions read the
project's memory store, and a turn that inherited them would answer from those notes in both arms, so the no-skill
arm could score as if it had the skill. Every turn is spawned without them, beside the billing variables and
`CLAUDE_CODE_EFFORT_LEVEL` (`CLAUDE_MEMORY_ENV` in `src/runner/driver.ts`). The scenario runner's build and ask
turns are spawned without them too, so both kinds of turn are isolated.
- **The arms**: each turn is one `claude -p` in a fresh temporary directory. The prompt goes on stdin. The two arms
differ only in the bundle. The with-skill arm copies it into `.claude/skills/BUNDLE/` without its `evals/`, so the
turn cannot read the assertions it is graded on. The no-skill arm's directory is empty. Both arms take the same
Expand Down
17 changes: 16 additions & 1 deletion packages/qa/scenarios/src/runner/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ export class ApiBillingRefusedError extends Error {
*/
export const CLAUDE_EFFORT_ENV = 'CLAUDE_CODE_EFFORT_LEVEL';

/**
* The variables that point the `claude` CLI at the host's memory: a project
* container sets them so its own sessions read and write the project's memory
* store, and a child spawned with them reads that store too. A skill-eval turn
* that inherits them answers from the host's notes in both arms, so the
* no-skill arm can score as if it had the skill, and a scenario turn builds
* or answers from them. Every turn either runner spawns goes without them
* (`ClaudeCodeDriver.turnEnv` here, `turnEnv` in `src/skill-evals/run.ts`).
*/
export const CLAUDE_MEMORY_ENV = ['CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', 'CLAUDE_MEMORY_STORES'] as const;

/** The child environment: the caller's, with every API-billing variable removed. */
export function subscriptionOnlyEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
const out = { ...env };
Expand Down Expand Up @@ -451,10 +462,14 @@ export class ClaudeCodeDriver implements AgentDriver {
return raw === undefined || raw === '' || raw === 'unset' || raw === 'auto' ? undefined : raw;
}

/** A turn's environment: no API-billing variable, and no {@link CLAUDE_EFFORT_ENV} to override the `--effort` the turn passes. */
/**
* A turn's environment: no API-billing variable, no {@link CLAUDE_EFFORT_ENV} to override the `--effort` the turn
* passes, and no {@link CLAUDE_MEMORY_ENV} variable pointing the turn at the host's memory store.
*/
private turnEnv(): NodeJS.ProcessEnv {
const env = subscriptionOnlyEnv();
delete env[CLAUDE_EFFORT_ENV];
for (const k of CLAUDE_MEMORY_ENV) delete env[k];
return env;
}

Expand Down
13 changes: 10 additions & 3 deletions packages/qa/scenarios/src/skill-evals/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
* The login guard is the scenario runner's, imported and never copied
* (`subscriptionOnlyEnv`, `assertSubscriptionLogin`): a round refuses to start
* while `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN` is set or the CLI reports
* an API-key login, and every turn is spawned with neither variable.
* an API-key login, and every turn is spawned with neither variable. Nor is a
* turn spawned with the host's memory variables (`CLAUDE_MEMORY_ENV`): a round
* run inside a project container never reads that project's memory.
*
* What a turn's record can say:
*
Expand Down Expand Up @@ -36,7 +38,7 @@ import { spawnSync } from 'node:child_process';
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

import { assertSubscriptionLogin, CLAUDE_EFFORT_ENV, effortLevelsFromHelp, subscriptionOnlyEnv } from '../runner/driver.js';
import { assertSubscriptionLogin, CLAUDE_EFFORT_ENV, CLAUDE_MEMORY_ENV, effortLevelsFromHelp, subscriptionOnlyEnv } from '../runner/driver.js';
import { runTurnProcess, type TurnProcessRun } from '../runner/drivers/process.js';
import { parseStreamJson } from '../runner/transcript.js';
import type { TurnProcess } from '../runner/transcript.js';
Expand Down Expand Up @@ -492,10 +494,15 @@ export function preflight(bin: string, env: NodeJS.ProcessEnv = process.env, run
return { version: ver.stdout.trim(), authMethod };
}

/** A turn's environment: no API-billing variable, and no effort variable overriding `--effort`. */
/**
* A turn's environment: no API-billing variable, no effort variable overriding
* `--effort`, and no memory variable pointing the turn at the host's memory
* store, so a turn sees only what its arm gives it.
*/
export function turnEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
const out = subscriptionOnlyEnv(env);
delete out[CLAUDE_EFFORT_ENV];
for (const k of CLAUDE_MEMORY_ENV) delete out[k];
return out;
}

Expand Down
20 changes: 16 additions & 4 deletions packages/qa/scenarios/test/runner/units.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { makeDriver, parseArgs } from '../../src/runner/cli.js';
import {
ApiBillingRefusedError,
assertSubscriptionLogin,
CLAUDE_MEMORY_ENV,
ClaudeCodeDriver,
DEFAULT_ASK_MAX_TURNS,
DEFAULT_AUTHOR_MAX_TURNS,
Expand Down Expand Up @@ -1172,8 +1173,8 @@ describe("the seed's load plan — reference cycles found from the card's own lo
* `claude-opus-5-5`; with no `--model` it serves `stand-in`. `--help` prints
* the `--effort` entry as Claude Code 2.1.325 does (its level list wrapped onto
* the next line), or no such entry under `STAND_IN_NO_EFFORT`; an `ENV` turn
* answers its argument list and the `CLAUDE_CODE_EFFORT_LEVEL` it was started
* with.
* answers its argument list, the `CLAUDE_CODE_EFFORT_LEVEL` it was started
* with and which of the host's memory variables it was started with.
*/
const STAND_IN = `#!/usr/bin/env node
process.on('SIGTERM', () => { process.stderr.write('stand-in: terminated\\n'); process.exit(143); });
Expand All @@ -1197,7 +1198,7 @@ process.stdin.on('end', () => {
const text = input.startsWith('ARGV')
? JSON.stringify(args)
: input.startsWith('ENV')
? JSON.stringify({ argv: args, effortEnv: process.env.CLAUDE_CODE_EFFORT_LEVEL ?? null })
? JSON.stringify({ argv: args, effortEnv: process.env.CLAUDE_CODE_EFFORT_LEVEL ?? null, memoryEnv: ['CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', 'CLAUDE_MEMORY_STORES'].filter((k) => process.env[k] !== undefined) })
: 'stdin ' + input.length + ' · longest argv ' + longest;
const asked = args.indexOf('--model') === -1 ? undefined : args[args.indexOf('--model') + 1];
const served = asked === undefined ? 'stand-in' : asked === 'retired' ? 'claude-opus-5-5' : 'claude-' + asked + '-4-5-20250929';
Expand Down Expand Up @@ -1394,7 +1395,7 @@ describe('the live driver against a stand-in `claude`: the prompt on stdin, and
return at === -1 ? undefined : argv[at + 1];
};
/** An `ENV` turn's answer: the stand-in's argument list and the effort variable it was started with. */
const envOf = (t: ParsedTurn) => JSON.parse(t.replyText) as { argv: string[]; effortEnv: string | null };
const envOf = (t: ParsedTurn) => JSON.parse(t.replyText) as { argv: string[]; effortEnv: string | null; memoryEnv: string[] };
/** The refusal's message, or `undefined` when nothing was refused. */
const refusalOf = (run: () => unknown): string | undefined => {
try {
Expand Down Expand Up @@ -1453,6 +1454,17 @@ describe('the live driver against a stand-in `claude`: the prompt on stdin, and
}
});

it('the host’s memory variables never reach a turn: a build turn and an ask turn are both started without them', async () => {
vi.stubEnv('PATH', `${dir}${delimiter}${process.env.PATH ?? ''}`);
vi.stubEnv('CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', '/host/project/memory');
vi.stubEnv('CLAUDE_MEMORY_STORES', 'host-store');
expect([...CLAUDE_MEMORY_ENV].sort()).toEqual(['CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', 'CLAUDE_MEMORY_STORES']);
const d = makeDriver('claude', parseArgs([]));
const built = (await d.author(task('ENV'))).turn;
const asked = await d.ask(ask('ENV'));
expect([envOf(built).memoryEnv, envOf(asked).memoryEnv]).toEqual([[], []]);
});

it('an effort level the CLI’s own `--help` does not list is refused before any turn — the CLI would warn, run at its default and exit 0 — and so is any effort on a CLI with no `--effort`', () => {
vi.stubEnv('PATH', `${dir}${delimiter}${process.env.PATH ?? ''}`);
expect(refusalOf(() => makeDriver('claude', parseArgs(['--effort', 'turbo'])))).toMatch(/^--effort takes one of the levels `claude` 2\.1\.0 \(stand-in\) accepts \(low, medium, high, xhigh, max\), not `turbo`$/);
Expand Down
36 changes: 31 additions & 5 deletions packages/qa/scenarios/test/skill-evals/skill-evals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { join } from 'node:path';

import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { ApiBillingRefusedError } from '../../src/runner/driver.js';
import { API_BILLING_ENV, ApiBillingRefusedError, CLAUDE_EFFORT_ENV, CLAUDE_MEMORY_ENV } from '../../src/runner/driver.js';
import type { TurnProcessRun } from '../../src/runner/drivers/process.js';
import { ARM_TOOLS, armArgs, prepareArmWorkdir } from '../../src/skill-evals/arms.js';
import { hashCase, loadSkillEvalCatalog, notUserInvocable, parseEvalFile, selectBundles, type SkillEvalCase } from '../../src/skill-evals/cases.js';
import { main, parseSkillEvalArgs, regradeRound, ROUND_RECORD_SCHEMA, triggerFieldLine, turnsLine } from '../../src/skill-evals/cli.js';
import { gradeAnswer } from '../../src/skill-evals/grade.js';
import { executeRound, judgeTurn, planRound, preflight, rateLimitStop, regradeRecord, regradeRecords, type SkillEvalRunRecord } from '../../src/skill-evals/run.js';
import { executeRound, judgeTurn, planRound, preflight, rateLimitStop, regradeRecord, regradeRecords, type SkillEvalRunRecord, turnEnv } from '../../src/skill-evals/run.js';
import { runSelfTest, SELF_TEST_BATTERIES, SELF_TEST_BATTERY_FLOOR, selfTestReached } from '../../src/skill-evals/self-test.js';
import { renderSummaryMarkdown, summariseRound } from '../../src/skill-evals/summary.js';

Expand Down Expand Up @@ -102,6 +102,29 @@ describe('the login guard, imported from the scenario runner: a round refuses an
});
});

describe('a turn\'s environment: the host\'s, minus API billing, the effort override and the host\'s memory', () => {
const host = {
PATH: '/usr/bin',
HOME: '/home/u',
ANTHROPIC_API_KEY: 'sk-x',
ANTHROPIC_AUTH_TOKEN: 't',
CLAUDE_CODE_EFFORT_LEVEL: 'max',
CLAUDE_COWORK_MEMORY_PATH_OVERRIDE: '/host/project/memory',
CLAUDE_MEMORY_STORES: 'host-store',
};

it('a host env carrying the memory variables yields a turn env without them, and keeps the rest', () => {
expect(turnEnv(host)).toEqual({ PATH: '/usr/bin', HOME: '/home/u' });
});

it('removes every name the three lists hold, and the memory list names both variables a project container sets', () => {
const out = turnEnv(host);
for (const k of [...API_BILLING_ENV, CLAUDE_EFFORT_ENV, ...CLAUDE_MEMORY_ENV]) expect(out).not.toHaveProperty(k);
expect([...CLAUDE_MEMORY_ENV].sort()).toEqual(['CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', 'CLAUDE_MEMORY_STORES']);
expect(host).toHaveProperty('CLAUDE_MEMORY_STORES', 'host-store'); // the caller's env is never edited
});
});

describe('the grader: every must_contain present, no must_not_contain, literal and case-sensitive', () => {
const c = { mustContain: ["engine.find('account'", '$icontains'], mustNotContain: ['$contains:'] };
it('passes a conforming answer', () => {
Expand Down Expand Up @@ -196,26 +219,29 @@ describe('the arms: one fresh directory per turn, differing only in the bundle',
}
});

it('a round hands each turn its arm\'s directory, the prompt on stdin and an environment with no API key or effort override; records land and directories go', async () => {
it('a round hands each turn its arm\'s directory, the prompt on stdin and an environment with no API key, effort override or host memory; records land and directories go', async () => {
vi.stubEnv('ANTHROPIC_API_KEY', 'sk-should-not-reach');
vi.stubEnv('CLAUDE_CODE_EFFORT_LEVEL', 'max');
vi.stubEnv('CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', '/host/project/memory');
vi.stubEnv('CLAUDE_MEMORY_STORES', 'host-store');
try {
const root = writeCatalog();
const cat = loadSkillEvalCatalog(root);
const cases = selectBundles(cat, ['alpha-skill']);
const seen: Array<{ args: readonly string[]; cwd: string; input: string; skills: string[]; envKey: boolean; envEffort: boolean }> = [];
const seen: Array<{ args: readonly string[]; cwd: string; input: string; skills: string[]; envKey: boolean; envEffort: boolean; envMemory: string[] }> = [];
const out = mkdtempSync(join(scratch, 'out-'));
const exec = await executeRound(planRound(cases, 1), {
bin: 'claude', skillsRoot: root, catalog: { bundles: cat.bundles, unlisted: cat.unlistedBundles }, outDir: out, maxTurns: 5, caseTimeoutMs: 1000, concurrency: 1, maxUtilization: 0.9,
runTurn: async (_bin, args, o) => {
const skillsDir = join(o.cwd, '.claude', 'skills');
const skills = existsSync(skillsDir) ? readdirSync(skillsDir) : [];
seen.push({ args, cwd: o.cwd, input: o.input, skills, envKey: o.env.ANTHROPIC_API_KEY !== undefined, envEffort: o.env.CLAUDE_CODE_EFFORT_LEVEL !== undefined });
seen.push({ args, cwd: o.cwd, input: o.input, skills, envKey: o.env.ANTHROPIC_API_KEY !== undefined, envEffort: o.env.CLAUDE_CODE_EFFORT_LEVEL !== undefined, envMemory: CLAUDE_MEMORY_ENV.filter((k) => o.env[k] !== undefined) });
return exited(stream({ skills, answer: 'uses $icontains and orderBy' }));
},
});
expect(seen.map((s) => [s.input, s.skills.join()])).toEqual([['prompt 1', 'alpha-skill'], ['prompt 1', ''], ['prompt 2', 'alpha-skill'], ['prompt 2', '']]);
expect(seen.every((s) => !s.envKey && !s.envEffort)).toBe(true);
expect(seen.map((s) => s.envMemory)).toEqual([[], [], [], []]);
expect(seen.every((s) => !existsSync(s.cwd))).toBe(true);
expect(exec.records.map((r) => r.verdict)).toEqual(['pass', 'pass', 'pass', 'pass']);
expect(readdirSync(join(out, 'runs')).sort()).toEqual([
Expand Down
Loading