# Proof audit pass 1 — terminal legacy history collision

Result: no code blocker found in the requested server-only scope. Proof is ready for independent pass 2. This is a service-level runtime transcript, not server-RPC integration evidence. No screenshots or recordings are required for this server-only change.

Audited replacement: [dc98776633](https://github.com/pingdotgg/t3code/commit/dc98776633a556a05aad14550c89d235d5a0e1e1), branch `takeover/pr-18671`, worktree `/home/ubuntu/wt/pr-18671`. Original [#18671](https://git.cafe/pingdotgg/t3code/pulls/18671) / [#18671](https://github.com/pingdotgg/t3code/pull/18671), fork `Batuhan1999/t3code:fix/terminal-legacy-history-collision`, head [9f70943e77](https://github.com/pingdotgg/t3code/commit/9f70943e771071135c6a7f7caf708a548b3b449b).

Before: [909e4c9482](https://github.com/pingdotgg/t3code/commit/909e4c948278afc2b3e1e665075fb1755a13f894), the merge-base of refreshed `origin/main` and replacement head. Refreshed origin main: [3cc31ed27c](https://github.com/pingdotgg/t3code/commit/3cc31ed27c8956b36cee35a50509fb7c6869592b). Stale local `main` was not used.

The complete merge-base-to-head diff contains only `Manager.ts` (4 added, 2 removed lines) and `Manager.test.ts` (22 added lines). The fixture plan was written after reading that complete diff and before running evidence. The changed surface is the shared server filesystem service; no clients, transports, contracts or provider adapters changed. All consumers use the same Manager. No client-specific captures are relevant.

## Evidence and method

- Complete diff: [complete.diff](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/d327351cee5edda8/complete.diff); pre-execution fixture plan: [matrix-plan.md](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/7685fcbc16a18bfb/matrix-plan.md).
- Public executable driver: [driver.mjs](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/db1ca3b46ed3c1ed/driver.mjs). Runtime transcripts: [before.jsonl](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/7820bfbddc6cf3e6/before.jsonl) and [after.jsonl](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/e46d5f2eb7098f2f/after.jsonl).
- Regression test output: [tests-before.txt](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/fe9bbfbabd030b1a/tests-before.txt) (2 expected failures, 43 filtered/skipped) and [tests-after.txt](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/e907a8c526c9d557/tests-after.txt) (45 passed). Baseline test overlay: [before-tests.config.ts](https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/350e98695e4e0c54/before-tests.config.ts).

Runtime uses the production public `makeWithOptions`, `open` and `close` APIs, real Node filesystem services, and a deterministic inert PTY adapter. It starts no HTTP/WebSocket server, runs no actual shell, opens no database, and reads no live userdata. The `--home-dir` flag belongs to the public proof driver; it is not a claim that the server CLI or RPC transport was exercised. After used fresh `/tmp/ev-18671`; before used fresh `/tmp/ev-18671-before`. Each row has independent seeded files under `<home>/<row>/logs/terminals`. Owner observations use a fresh Manager to avoid an in-memory history masking persisted data loss. Actions finish through service completion/close; there are no sleep or polling loops.

The driver loads exact selected-revision Manager source with a read-only in-memory module overlay. Other production dependencies come from the audited checkout; they are identical between before and after because the complete diff changes only Manager and its test. No worktree source was edited. Test-before likewise runs the new regression cases with exact before Manager source through an external Vite load hook.

`PASS` in before transcripts means the driver confirmed the expected buggy behavior; it does not mean the old code satisfies the spec.

## Fixture matrix

Notation: `B(id)` is UTF-8 base64url without padding. Default terminal ID is `term-1`. Current default filename is `terminal_B(thread).log`; named current filename is `terminal_B(thread)_B(terminal).log`. Legacy filename replaces non `[a-zA-Z0-9._-]` characters with `_`, then appends `.log`. Seed payload `owner-a\n` is synthetic. Every affected row is **runtime transcript**, including interaction/order rows; no UI recordings.

| Rows | Affected service branch | Data / seed | Reproduction | Observed before → after |
|---|---|---|---|---|
| R1 | Read/migrate, lowercase | `terminal_YQ.log = owner-a\n`, owner `a`, colliding thread `terminal_YQ`; colliding thread own current absent | Open colliding thread, close without deleting; fresh Manager opens `a` and colliding thread | Colliding loads `owner-a\n`, owner loads empty → colliding empty, owner loads `owner-a\n`; owner file preserved |
| R2 | Individual deletion | Fresh same seed as R1; neither thread opened before deletion | `close({threadId:"terminal_YQ", terminalId:"term-1", deleteHistory:true})`; fresh Managers open both threads | Owner file gone and both load empty → owner file retained, owner loads `owner-a\n`, colliding empty |
| R3 | Whole-thread deletion | Independently fresh same seed | `close({threadId:"terminal_YQ", deleteHistory:true})`; fresh Managers open both | Same before/after result as R2; independently exercises directory filter |
| M1–M3 | Mixed-case read/migrate, individual delete, whole-thread delete | Exact `Terminal_YQ.log` alias surrogate and lowercase `terminal_YQ.log` owner copy, both `owner-a\n`; actor `Terminal_YQ` | Repeat R1–R3 with mixed-case actor | Before consumes/deletes exact mixed-case surrogate; after retains it and actor loads empty. Lowercase owner copy loads `owner-a\n` in both on Linux. Native case-insensitive filesystem behavior is not claimed |
| S1–S3 | Sanitized reserved-prefix read and both deletions | Actor `terminal:YQ` sanitizes to `terminal_YQ`; same owner seed | Repeat R1–R3 | Same result as R1–R3; proves guard applies after sanitization |
| H1–H3 | Current hashed-name collisions, same three branches | Owner ID is 300 `x` characters; current filename `terminal_sha256.<sha256-base64url>.log`; actor equals basename without `.log` | Repeat R1–R3 with hashed owner and actor, exact names in transcript | Before reads/removes owner history; after actor empty and owner retains `owner-a\n` |
| L1 | Ordinary legacy migration compatibility | `ordinary.log = legacy\n`; unrelated `a` current = `owner-a\n` | Open `ordinary`, close, inspect files, fresh-open both threads | Both load `legacy\n` for ordinary; legacy file removed and current contains payload; `a` unchanged |
| L2–L3 | Ordinary legacy deletion compatibility | Independently seed L1 | Individual/default and whole-thread deletion before any open | Both remove ordinary legacy file, ordinary then empty; `a` unchanged |
| C1 | Current precedence and named-terminal compatibility | ordinary legacy=`legacy\n`, own default=`own-current\n`, own named=`own-named\n`, unrelated `a` current=`owner-a\n` | Open ordinary default and named, close, fresh-open owner | Both load own current/default and named payloads; unrelated owner unchanged |
| C2–C3 | Current deletion compatibility | Independently seed C1 | Delete default individually, or whole thread | Both delete own default; individual retains named current, whole-thread removes it; unrelated `a` retained |
| P1 | Reserved ID own current remains valid | Actor `terminal_YQ` own default and named current plus `a` current, using distinct payloads | Open actor default/named, then fresh-open owner | Both load actor's own current correctly and owner remains intact |
| P2–P3 | Reserved ID own-current deletion + collision isolation | Independently seed P1 | Individual or whole-thread deletion before open | Both remove intended actor files; before also removes `a`, after preserves `a`. Individual retains actor named current; whole-thread removes it |
| C6 | Already-fit encoded and overlong current compatibility | Existing Manager tests: 120-character encoded ID; nested subagent/300-character ID and long terminal IDs | Focused existing Manager test file | Replacement suite passes; no additional runtime expansion required |
| T1 | Time / interaction / operation ordering | Each above row starts with independent synthetic files; no prior migration before deletion rows | Sequential public service calls, deterministic completion, new Manager for observation | Runtime transcripts record seeds, action, file map and histories; no UI recording, no wall-clock claim |

## Exact execution and concise before/after transcript

Run from `/home/ubuntu/wt/pr-18671`:

```sh
vp test run apps/server/src/terminal/Manager.test.ts
node /tmp/proof-18671/driver.mjs --home-dir /tmp/ev-18671 --phase after
node /tmp/proof-18671/driver.mjs --home-dir /tmp/ev-18671-before --phase before
```

The baseline tests ran from `apps/server`:

```sh
vp test run --config /tmp/proof-18671/before-tests.config.ts src/terminal/Manager.test.ts -t 'never resolves a'
```

Test-before fails both prefix cases at the history assertion: expected `""`, actual `"thread a\n"`. After passes all 45 cases. Both runtime phases completed 21 rows; full JSONL includes every seed, file map immediately after action, actor history, fresh owner history and assertion result.

| Row | Before actor loads | Before owner `a` loads | After actor loads | After owner `a` loads |
|---|---|---|---|---|
| R1 migration | `owner-a\n` | empty | empty | `owner-a\n` |
| R2 individual deletion | empty | empty | empty | `owner-a\n` |
| R3 thread deletion | empty | empty | empty | `owner-a\n` |

For R1 before, the action leaves only `terminal_dGVybWluYWxfWVE.log = owner-a\n`: migration moved the owner's history into the colliding thread. After, `terminal_YQ.log` remains `owner-a\n` and the colliding thread's own current is empty. For R2/R3 before, the file map immediately after deletion is `{}`; after it retains `terminal_YQ.log = owner-a\n`.

## Required pass-2 proof

Independently download the public driver, inspect it, and rerun **at least one affected scenario** against both exact revisions with independent fresh scratch homes. R2 is the smallest isolated delete scenario; R1 is the direct history-leak scenario. Do not reuse any existing evidence home or edit the worktree. Example:

```sh
curl -fL 'https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/db1ca3b46ed3c1ed/driver.mjs' -o /tmp/ev-18671-public-driver.mjs
node /tmp/ev-18671-public-driver.mjs --repo /home/ubuntu/wt/pr-18671 --home-dir /tmp/ev-18671-pass2-before --phase before --row R2
node /tmp/ev-18671-public-driver.mjs --repo /home/ubuntu/wt/pr-18671 --home-dir /tmp/ev-18671-pass2-after --phase after --row R2
```

Acceptance for R2: identical synthetic seed in both phases; before file removed and owner history empty; after owner file byte-for-byte unchanged and owner history `owner-a\n`; actor history empty in both. Check revision headers and the complete diff; do not infer results from `PASS` alone. Audit **all delivered transcripts**: 21 runtime rows per phase, the two expected baseline test failures, and 45 after tests passed. Verify mixed-case evidence is described as a surrogate, and check ordinary legacy/current controls. Preserve the distinction between this service proof and RPC integration. If pass 2 requires real RPC proof, run an isolated server with its own fresh home and synthetic fixtures; no live userdata, real agents, UI captures or unrelated Manager states are needed. That additional RPC run is not delivered by this pass.

## FRICTION

| category | happened | remedy |
|---|---|---|
| scratch driver import | Initial driver attempt used CommonJS resolution for the import-only contracts export; failed before home creation | Resolve contracts via its exact source entry; final driver completed all rows |
| test accounting | Current suite reports 45 tests, unlike historical PR text claiming 103 | Report actual output at audited replacement; two collision tests are collected and fail on baseline |
| filesystem platform | Linux does not naturally alias `Terminal_YQ.log` to `terminal_YQ.log` | Seed exact mixed-case surrogate; disclose native macOS/Windows filesystem verification remains unperformed |
| integration scope | Public Manager driver rather than server RPC | Explicitly label service-level evidence; public rerun commands supplied; isolated RPC can supplement during capture |

Read-only outcome: no code edits, commits, pushes, PR comments, server processes or live userdata access. Scratch/evidence remain outside the repository. Final worktree status was clean. Original PR forge checks refer to original head and do not certify the replacement; this pass makes no replacement CI or mergeability claim.
