From 637a5bdd59be9669a8b843ff77cf38f3b2042aad Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 04:26:37 +0000 Subject: [PATCH 1/2] fix(scenarios): skill-eval turns are spawned without the host's memory variables A turn inherited CLAUDE_COWORK_MEMORY_PATH_OVERRIDE and CLAUDE_MEMORY_STORES from a project container, so both arms read the project's memory and the no-skill arm could score as if it had the skill. turnEnv now drops them, listed as CLAUDE_MEMORY_ENV beside the billing and effort variables. Claude-Session: https://claude.ai/code/session_01L6bhgXWFXqMUE85PmLT9AE Co-authored-by: Claude --- .../37842-skill-evals-memory-isolated.md | 8 +++++ packages/qa/scenarios/README.md | 5 +++ packages/qa/scenarios/src/runner/driver.ts | 10 ++++++ packages/qa/scenarios/src/skill-evals/run.ts | 13 +++++-- .../test/skill-evals/skill-evals.test.ts | 36 ++++++++++++++++--- 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 .changeset/37842-skill-evals-memory-isolated.md diff --git a/.changeset/37842-skill-evals-memory-isolated.md b/.changeset/37842-skill-evals-memory-isolated.md new file mode 100644 index 00000000000..61eb31769f4 --- /dev/null +++ b/.changeset/37842-skill-evals-memory-isolated.md @@ -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, and the README says a round is isolated from project memory. diff --git a/packages/qa/scenarios/README.md b/packages/qa/scenarios/README.md index da9a633746b..5a6815049ef 100644 --- a/packages/qa/scenarios/README.md +++ b/packages/qa/scenarios/README.md @@ -1018,6 +1018,11 @@ 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 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 diff --git a/packages/qa/scenarios/src/runner/driver.ts b/packages/qa/scenarios/src/runner/driver.ts index 8a91503001c..371666e40a9 100644 --- a/packages/qa/scenarios/src/runner/driver.ts +++ b/packages/qa/scenarios/src/runner/driver.ts @@ -228,6 +228,16 @@ 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. Every skill-eval turn is + * spawned without them (`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 }; diff --git a/packages/qa/scenarios/src/skill-evals/run.ts b/packages/qa/scenarios/src/skill-evals/run.ts index aac7be78bc4..fcf624a4a59 100644 --- a/packages/qa/scenarios/src/skill-evals/run.ts +++ b/packages/qa/scenarios/src/skill-evals/run.ts @@ -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: * @@ -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'; @@ -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; } diff --git a/packages/qa/scenarios/test/skill-evals/skill-evals.test.ts b/packages/qa/scenarios/test/skill-evals/skill-evals.test.ts index 7033a25a62e..6c94cdb9049 100644 --- a/packages/qa/scenarios/test/skill-evals/skill-evals.test.ts +++ b/packages/qa/scenarios/test/skill-evals/skill-evals.test.ts @@ -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'; @@ -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', () => { @@ -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([ From ac1dd475766e60f1db15123977b7b3ab95025a9d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 05:05:18 +0000 Subject: [PATCH 2/2] fix(scenarios): the scenario runner's build and ask turns go without the host's memory variables too ClaudeCodeDriver.turnEnv drops CLAUDE_MEMORY_ENV beside the billing and effort variables, so a scenario round run in a project container does not read the project's memory either. Claude-Session: https://claude.ai/code/session_01L6bhgXWFXqMUE85PmLT9AE Co-authored-by: Claude --- .../37842-skill-evals-memory-isolated.md | 2 +- packages/qa/scenarios/README.md | 3 ++- packages/qa/scenarios/src/runner/driver.ts | 11 +++++++--- .../qa/scenarios/test/runner/units.test.ts | 20 +++++++++++++++---- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.changeset/37842-skill-evals-memory-isolated.md b/.changeset/37842-skill-evals-memory-isolated.md index 61eb31769f4..8da47e9237a 100644 --- a/.changeset/37842-skill-evals-memory-isolated.md +++ b/.changeset/37842-skill-evals-memory-isolated.md @@ -5,4 +5,4 @@ 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, and the README says a round is isolated from project memory. +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. diff --git a/packages/qa/scenarios/README.md b/packages/qa/scenarios/README.md index 5a6815049ef..8533f8543e8 100644 --- a/packages/qa/scenarios/README.md +++ b/packages/qa/scenarios/README.md @@ -1022,7 +1022,8 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o 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`). + `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 diff --git a/packages/qa/scenarios/src/runner/driver.ts b/packages/qa/scenarios/src/runner/driver.ts index 371666e40a9..d7cc7951eb4 100644 --- a/packages/qa/scenarios/src/runner/driver.ts +++ b/packages/qa/scenarios/src/runner/driver.ts @@ -233,8 +233,9 @@ export const CLAUDE_EFFORT_ENV = 'CLAUDE_CODE_EFFORT_LEVEL'; * 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. Every skill-eval turn is - * spawned without them (`turnEnv` in `src/skill-evals/run.ts`). + * 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; @@ -461,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; } diff --git a/packages/qa/scenarios/test/runner/units.test.ts b/packages/qa/scenarios/test/runner/units.test.ts index 48205af0075..cb83f0d4458 100644 --- a/packages/qa/scenarios/test/runner/units.test.ts +++ b/packages/qa/scenarios/test/runner/units.test.ts @@ -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, @@ -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); }); @@ -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'; @@ -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 { @@ -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`$/);