Skip to content

Commit 637a5bd

Browse files
committed
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 <noreply@anthropic.com>
1 parent 581ae76 commit 637a5bd

5 files changed

Lines changed: 64 additions & 8 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@objectstack/scenarios': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
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.

‎packages/qa/scenarios/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,11 @@ pnpm --filter @objectstack/scenarios skill-evals --self-test # the runner's o
10181018
- **Login**: the scenario runner's guard, imported from `src/runner/driver.ts`. A round refuses to start while
10191019
`ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN` is set, or when `claude auth status` reports no login or an API-key
10201020
login. Every turn is spawned without those two variables. Never an API-billed key.
1021+
- **Isolated from project memory**: a round run inside a project container is isolated from that project's memory.
1022+
The container sets `CLAUDE_COWORK_MEMORY_PATH_OVERRIDE` and `CLAUDE_MEMORY_STORES` so its own sessions read the
1023+
project's memory store, and a turn that inherited them would answer from those notes in both arms, so the no-skill
1024+
arm could score as if it had the skill. Every turn is spawned without them, beside the billing variables and
1025+
`CLAUDE_CODE_EFFORT_LEVEL` (`CLAUDE_MEMORY_ENV` in `src/runner/driver.ts`).
10211026
- **The arms**: each turn is one `claude -p` in a fresh temporary directory. The prompt goes on stdin. The two arms
10221027
differ only in the bundle. The with-skill arm copies it into `.claude/skills/BUNDLE/` without its `evals/`, so the
10231028
turn cannot read the assertions it is graded on. The no-skill arm's directory is empty. Both arms take the same

‎packages/qa/scenarios/src/runner/driver.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,16 @@ export class ApiBillingRefusedError extends Error {
228228
*/
229229
export const CLAUDE_EFFORT_ENV = 'CLAUDE_CODE_EFFORT_LEVEL';
230230

231+
/**
232+
* The variables that point the `claude` CLI at the host's memory: a project
233+
* container sets them so its own sessions read and write the project's memory
234+
* store, and a child spawned with them reads that store too. A skill-eval turn
235+
* that inherits them answers from the host's notes in both arms, so the
236+
* no-skill arm can score as if it had the skill. Every skill-eval turn is
237+
* spawned without them (`turnEnv` in `src/skill-evals/run.ts`).
238+
*/
239+
export const CLAUDE_MEMORY_ENV = ['CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', 'CLAUDE_MEMORY_STORES'] as const;
240+
231241
/** The child environment: the caller's, with every API-billing variable removed. */
232242
export function subscriptionOnlyEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
233243
const out = { ...env };

‎packages/qa/scenarios/src/skill-evals/run.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
* The login guard is the scenario runner's, imported and never copied
99
* (`subscriptionOnlyEnv`, `assertSubscriptionLogin`): a round refuses to start
1010
* while `ANTHROPIC_API_KEY` or `ANTHROPIC_AUTH_TOKEN` is set or the CLI reports
11-
* an API-key login, and every turn is spawned with neither variable.
11+
* an API-key login, and every turn is spawned with neither variable. Nor is a
12+
* turn spawned with the host's memory variables (`CLAUDE_MEMORY_ENV`): a round
13+
* run inside a project container never reads that project's memory.
1214
*
1315
* What a turn's record can say:
1416
*
@@ -36,7 +38,7 @@ import { spawnSync } from 'node:child_process';
3638
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
3739
import { join } from 'node:path';
3840

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

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

‎packages/qa/scenarios/test/skill-evals/skill-evals.test.ts‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import { join } from 'node:path';
1515

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

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

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

105+
describe('a turn\'s environment: the host\'s, minus API billing, the effort override and the host\'s memory', () => {
106+
const host = {
107+
PATH: '/usr/bin',
108+
HOME: '/home/u',
109+
ANTHROPIC_API_KEY: 'sk-x',
110+
ANTHROPIC_AUTH_TOKEN: 't',
111+
CLAUDE_CODE_EFFORT_LEVEL: 'max',
112+
CLAUDE_COWORK_MEMORY_PATH_OVERRIDE: '/host/project/memory',
113+
CLAUDE_MEMORY_STORES: 'host-store',
114+
};
115+
116+
it('a host env carrying the memory variables yields a turn env without them, and keeps the rest', () => {
117+
expect(turnEnv(host)).toEqual({ PATH: '/usr/bin', HOME: '/home/u' });
118+
});
119+
120+
it('removes every name the three lists hold, and the memory list names both variables a project container sets', () => {
121+
const out = turnEnv(host);
122+
for (const k of [...API_BILLING_ENV, CLAUDE_EFFORT_ENV, ...CLAUDE_MEMORY_ENV]) expect(out).not.toHaveProperty(k);
123+
expect([...CLAUDE_MEMORY_ENV].sort()).toEqual(['CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', 'CLAUDE_MEMORY_STORES']);
124+
expect(host).toHaveProperty('CLAUDE_MEMORY_STORES', 'host-store'); // the caller's env is never edited
125+
});
126+
});
127+
105128
describe('the grader: every must_contain present, no must_not_contain, literal and case-sensitive', () => {
106129
const c = { mustContain: ["engine.find('account'", '$icontains'], mustNotContain: ['$contains:'] };
107130
it('passes a conforming answer', () => {
@@ -196,26 +219,29 @@ describe('the arms: one fresh directory per turn, differing only in the bundle',
196219
}
197220
});
198221

199-
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 () => {
222+
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 () => {
200223
vi.stubEnv('ANTHROPIC_API_KEY', 'sk-should-not-reach');
201224
vi.stubEnv('CLAUDE_CODE_EFFORT_LEVEL', 'max');
225+
vi.stubEnv('CLAUDE_COWORK_MEMORY_PATH_OVERRIDE', '/host/project/memory');
226+
vi.stubEnv('CLAUDE_MEMORY_STORES', 'host-store');
202227
try {
203228
const root = writeCatalog();
204229
const cat = loadSkillEvalCatalog(root);
205230
const cases = selectBundles(cat, ['alpha-skill']);
206-
const seen: Array<{ args: readonly string[]; cwd: string; input: string; skills: string[]; envKey: boolean; envEffort: boolean }> = [];
231+
const seen: Array<{ args: readonly string[]; cwd: string; input: string; skills: string[]; envKey: boolean; envEffort: boolean; envMemory: string[] }> = [];
207232
const out = mkdtempSync(join(scratch, 'out-'));
208233
const exec = await executeRound(planRound(cases, 1), {
209234
bin: 'claude', skillsRoot: root, catalog: { bundles: cat.bundles, unlisted: cat.unlistedBundles }, outDir: out, maxTurns: 5, caseTimeoutMs: 1000, concurrency: 1, maxUtilization: 0.9,
210235
runTurn: async (_bin, args, o) => {
211236
const skillsDir = join(o.cwd, '.claude', 'skills');
212237
const skills = existsSync(skillsDir) ? readdirSync(skillsDir) : [];
213-
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 });
238+
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) });
214239
return exited(stream({ skills, answer: 'uses $icontains and orderBy' }));
215240
},
216241
});
217242
expect(seen.map((s) => [s.input, s.skills.join()])).toEqual([['prompt 1', 'alpha-skill'], ['prompt 1', ''], ['prompt 2', 'alpha-skill'], ['prompt 2', '']]);
218243
expect(seen.every((s) => !s.envKey && !s.envEffort)).toBe(true);
244+
expect(seen.map((s) => s.envMemory)).toEqual([[], [], [], []]);
219245
expect(seen.every((s) => !existsSync(s.cwd))).toBe(true);
220246
expect(exec.records.map((r) => r.verdict)).toEqual(['pass', 'pass', 'pass', 'pass']);
221247
expect(readdirSync(join(out, 'runs')).sort()).toEqual([

0 commit comments

Comments
 (0)