# Usage-cache write reproduction

AI-assisted; verified with the tests and tools listed above.

Both captures show live terminal output while the real bundled server runs, not test output or a reenacted transcript. `SERVER STDERR` lines come directly from its stdout/stderr pipe; `DRIVER`, `DISK`, `HTTP`, and `OBSERVED` lines are explicitly labeled instrumentation. Startup credentials and paths are excluded, and native executable paths are replaced by `[Node runtime]`.

Environment for both: Linux x64, Node 26.12.1, `NODE_OPTIONS=--max-old-space-size=1536`, `T3CODE_DEV_SEED=0`, isolated HOME/XDG directories, an empty Codex home, 1440x900 video at 8 fps, dark terminal, Monospace 12. No real provider turn or account was used in either published run.

1. Create separate worktrees at the base and head commits specified below. Run `vp i`, then `vp run --filter t3 build:bundle` in each, sequentially.
2. Place the four scripts in one scratch directory. Run `python3 seed.py <seed-directory>` once. Both sides read this same synthetic source: 2,700 JSONL files, 1,000 unique assistant records each, within the preceding 30 days.
3. Start with no `.t3` in either checkout. The driver creates synthetic settings, seven valid empty superseded cache files, two temp directories aged two hours, and one recent temp directory.
4. Run `headless-desktop ./record.sh <base-checkout> <seed-directory> <new-base-output-directory> Before`. The driver issues a session credential privately, starts that checkout's `apps/server/dist/bin.mjs serve`, and calls `server.getUsageSummary` with `awaitRefresh=true` over the real authenticated WebSocket RPC.
5. Observe cache persistence, server fatal output, and the final directory listing. The driver stops its server and closes the recording. Confirm the port is free before the next run.
6. Run the identical command with the head checkout, a new output directory, and the label `After`. After a completed save the driver also probes the authenticated environment endpoint and lists artifacts.

Base: [44e894ffd7](https://git.cafe/pingdotgg/t3code/commit/44e894ffd72ed50cbd7996f21a2825a5240db7d5), the merge-base with origin/main. Published run: 20:09:28–20:10:13 UTC on 2026-11-10. Its 2,700,000-record scan completed; cache persistence then aborted in `EncodeUtf8String`, WebSocket closed 1006, no v11 cache was saved, and an additional empty temporary directory remained. All seeded legacy files and stale directories remained.

Head: [00231afbed](https://git.cafe/pingdotgg/t3code/commit/00231afbedb1313f2fb2b16e06e7935b6a250ebe). Published run: 20:10:40–20:11:34 UTC. The same 2,700,000-record scan completed, a 363,984,010-byte v11 cache was saved, and the server answered HTTP 200 after persistence. Only the v11 cache and the recent temp directory remained; all seven legacy files and both stale directories were removed.

The two published servers did not overlap. A prior discarded pilot encountered an HTTP-503 startup readiness race; the uploaded RPC driver retries readiness responses before issuing the usage request. Both published recordings use the same final scripts. Videos were reviewed across their timelines and at their outcomes before upload.

Limits: this is server-side proof, not a desktop-shell or mobile UI demonstration. Legacy fixtures are small valid empty cache documents, so preservation of real history when migrating a populated legacy cache is not covered. Arbitrarily large histories, a hard cache-size limit, restart/loading of the saved large cache, and cleanup without a successful cache save are not demonstrated. The recent temp directory deliberately remains; the cleanup grace period is one hour.
