Repository navigation
Description
Context
Claude backend tests write host observation storage into the real user's ~/.claude/transcript-archive/, outside the test's temporary root. They also leave it behind after the test.
The storage root is join(transcriptPaths(options.backend.brainPath, turnEnvironment).archive, "native-observations") (packages/ui-backend-claude/src/turn-runner.ts:196). The archive location falls back to HOME/.claude when the turn's profile sets no CLAUDE_CONFIG_DIR (export function transcriptPaths, packages/ui-backend-claude/src/transcript-archive.ts:32-41). Many tests build profiles with buildEnv: () => ({}), and the test preload (scripts/test-network-preload.ts, wired through packages/ui-backend-claude/bunfig.toml) does not isolate HOME.
Observed on a development host on 2026-10-25: 19,689 directories under ~/.claude/transcript-archive/, dated from 2026-10-16 on. They are named after test temporary roots. The largest groups are -tmp-api-failure-* (6,664, packages/ui-backend-claude/tests/api-failure.test.ts), -tmp-backend-contract-* (2,594), -tmp-brain-handoff-* (2,321), -tmp-brain-module-lock-* (1,067), -tmp-claude-requirements-* (776, version-requirements.test.ts), -tmp-brain-jobs-posture-*, -tmp-brain-claude-yield-* (autonomous-yield.test.ts) and -tmp-retry-observations-*. CI runners accumulate the same directories in the runner's home for the job's lifetime. This predates #2416's off-loop change (#2901). That change did make it visible as a log line when a test's teardown raced the save, which the follow-up PR for #2416 removes.
Scope
Make every Claude backend test that runs a turn keep host state inside its own temporary root. Either the test preload points HOME (and CLAUDE_CONFIG_DIR where unset) at a per-run temporary directory that it removes, or the affected tests' profiles set CLAUDE_CONFIG_DIR. The first covers future tests too.
Out of scope
- The production fallback to
~/.claude(host behaviour, unchanged). - Cleaning existing directories on developer machines. A one-line note in the PR is enough.
Acceptance criteria
- A guard fails if any test in
packages/ui-backend-claudecreates or modifies anything under the invoking user's real~/.claude. It is shown failing before the change, for example onapi-failure.test.ts. bun run test packages/ui-backend-claudeleaves~/.claude/transcript-archiveunchanged: its directory count is identical before and after, recorded in the PR.- No test weakens the observation-storage refusals (redirected or aliased storage) to get there.
Verification
bun run test packages/ui-backend-claude, plus the guard's failing-first receipt.
Contract impact
None.
Safe current-main control (2026-10-25)
At inspected main ab746a434c4ada11734ffea4e208d1d6211f1aca, the unmodified api-failure.test.ts ran against an empty disposable HOME with CLAUDE_CONFIG_DIR absent in that child environment: 23 pass / 0 fail / 307 assertions, exit 0, and no retained transcript-archive directory. This passing control alone does not disprove the report because the observation save is asynchronous.
A temporary copy outside authored source then kept only the owning fixture brain alive for 100 ms after startTurn returned, leaving every original assertion and profile unchanged. The single an answered turn carries no failure case passed (1 pass / 22 filtered / 4 assertions, exit 0) and left one transcript-archive directory with one native-observation file under that disposable HOME, outside the fixture’s own brain/root and after its teardown. This demonstrates the fallback persistence path with a changed cleanup schedule; it does not measure the historical directory counts or prove the natural timing of every affected file. Real user storage was never used as the probe destination. Raw held-control log SHA-256: 50379306b35b0788af86c026eab0e40beab6d9fbd9d31949b759cfa884356939.
The regression guard should compare path membership and exact sentinel bytes/metadata or recorded write attempts, not only directory counts: an overwrite can keep the count unchanged. Cover default profiles and explicit profile overrides, restore environment values/property state after each owning scope, and await owned pending saves before removing temporary storage. Preserve the production fallback and aliased/unreadable-storage refusals. Test-only mocks still use the shared network guard. Existing user directories are outside this task.
2026-10-25 triage at main ab746a434c4ada11734ffea4e208d1d6211f1aca: Verified the source fallback and reproduced its external-to-fixture persistence using an owned disposable HOME and a delayed-teardown control, with original assertions intact. Added a meaningful write/sentinel guard beyond directory counts and async-save cleanup requirements. The test-isolation brief is ready; no real user directory was read, changed or cleaned.
2026-11-15 implementation review: refreshed the two current-source storage-path citations against main 2702e2bdd; the fallback and scope remain unchanged.
Activity
schlessera commentedon Oct 25, 2026
2026-10-25 triage at main
ab746a434c4ada11734ffea4e208d1d6211f1aca: Verified the source fallback and reproduced its external-to-fixture persistence using an owned disposable HOME and a delayed-teardown control, with original assertions intact. Added a meaningful write/sentinel guard beyond directory counts and async-save cleanup requirements. The test-isolation brief is ready; no real user directory was read, changed or cleaned.schlessera commentedon Nov 15, 2026
Claimed for implementation. Claim token:
claim-d63c695c. Branch:fix/2902-claude-test-host-storage.schlessera commentedon Nov 15, 2026
Implementation is in draft PR #4042. Refreshed the current-source storage-path citations against main; production fallback and storage refusals are unchanged.
Failing-first and mutation runs show the original external-to-fixture observation writes using a disposable invoking home. Isolation and swallowed-write regression probes now pass, and final local preflight passes all gates with 1,208 fast invariant tests. The full Claude package run left the invoking transcript-archive directory count unchanged (13,996 before and after); its native failures reproduce on main under the local namespace restrictions. The unrelated container visibility limitation is already tracked in #3318.
Hosted heavy feedback has been requested at https://github.com/schlessera/brain-kit/actions/runs/43758894373. The orchestrator will review that result and owns candidate confirmation and landing; the issue claim remains held.
schlessera commentedon Nov 15, 2026
Current head is
722c47ce2c1cb23b415b04b4e0ec4cf2be157b6b. The last change is a type annotation on the explicit-profile regression probe. Final typecheck and all local preflight checks pass (1,208 fast invariants); the receipt and collision audit are recorded in PR #4042.The current hosted feedback request is https://github.com/schlessera/brain-kit/actions/runs/43759114618. It supersedes the preceding-head request. The claim stays held for orchestrator-owned review and landing.
schlessera commentedon Nov 16, 2026
Current-head heavy feedback succeeded: https://github.com/schlessera/brain-kit/actions/runs/43792329398. Resource receipts confirm checkout
0c059885f53c46baa599164fe9c8bb16b2f6d59f; all selected proof jobs and all 30 previously failing cases pass. The PR body now records the result, the refreshed collision audit (31 closure overlaps, no path/unknown collision), and the matching passed local receipt. Both release milestones remain 0.45.0; the worktree is clean. No code changed during this verification, no new follow-up issue was filed, and the claim remains held for orchestrator-owned candidate confirmation and landing.schlessera commentedon Nov 16, 2026
Merged in #4042 as
8abc051cbthrough the integration lease (orchestrator merge queue for 0.45.0). Candidate confirmation passed on the exact head; the squash's own main run carries the post-merge heavy categories.