Skip to content

fix(server): prevent legacy terminal history collisions across threads - #24574

Merged
juliusmarminge merged 10 commits into
mainfrom
takeover/pr-18671
Nov 14, 2026
Merged

juliusmarminge merged 10 commits into
mainfrom
takeover/pr-18671

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

Legacy history lookup could resolve another thread’s current history file, exposing its scrollback or deleting it. The server now rejects legacy filenames in the case-insensitive terminal_ namespace across migration and both deletion paths.

Original description by @Batuhan1999

Problem

A legacy terminal history filename can collide with another thread's current history file. Opening or deleting a terminal for a client-supplied ID such as terminal_YQ can read or remove thread a's history.

Change

Reserve the terminal_ namespace, ignoring letter case, in one legacy-name resolver. History migration, individual terminal deletion and whole-thread deletion all use that resolver. Current history handling and ordinary legacy migration remain intact.

Scope and approval

Preserves @Batuhan1999's original contribution in #18671, originally separated from #18669. Main snapshot a3ca1a57d6 is integrated with contributor ancestry retained. This changes the server's history filename handling; clients, contracts and providers are unchanged.

Verification

At 9f70943e77, based on a3ca1a57d6:

  • All 103 terminal-manager tests pass, along with server typecheck and focused lint/format checks.
  • Reduced the original two cases to one public Manager lifecycle test. It verifies empty history on the colliding thread and preservation of the other thread's file after both individual and whole-thread deletion.
  • Four temporary guard-removal probes independently reproduced the read/migration, individual-delete and whole-thread-delete failures. Production code was restored byte-for-byte.
  • Fresh full cumulative Opus 5.5 and GPT-6.1 Sol reviews found no code defects. Main's bounded history, inherited-history neutralization, tracing, shell startup and closed-terminal behavior are retained.

Filesystem behavior was exercised on Linux. The mixed-case protection for case-insensitive macOS/Windows filesystems was reviewed from source but was not run on those filesystems. No separate browser/device session was needed for this server filesystem change.

Implementation and tests: Claude Opus 5.5 and Claude Fable 5.1 through T3 Code. Independent review: Claude Opus 5.5 and GPT-6.1 Sol, standard service tiers.

Takeover

Credits @Batuhan1999’s original contribution in #18671; contributor ancestry is retained on this replacement branch.
Adapted the guard to main’s bounded-filename API and shared it with whole-thread deletion. Replaced the original regression with lowercase and mixed-case lifecycle cases.
Reserved-prefix legacy files are intentionally ignored because they can overlap encoded or hashed current history filenames.

Evidence

Fixture matrix · Runtime capture report · Public drivers, transcripts and logs

Fixture rows Before After Proof
R1 read/migrate Actor reads owner scrollback; owner loses history Actor empty; owner history retained Real server RPC and service transcript
R2 individual delete Owner history removed Owner history retained Real server RPC and service transcript
R3 whole-thread delete Owner history removed Owner history retained Real server RPC and service transcript
M1–M3 mixed-case Alias surrogate read/removed Surrogate retained Linux service transcript; native aliasing unverified
S1–S3 sanitized prefix Owner history read/removed Owner history retained Service transcript
H1–H3 hashed name Owner history read/removed Owner history retained Service transcript
L1–L3 ordinary legacy Migrates/deletes intended history Same Compatibility controls
C1–C3 current/default/named Loads/deletes intended files Same Compatibility controls
P1–P3 reserved ID own-current Own history works; deletion harms owner Own history works; owner preserved Service transcript
C6 bounded filenames (9 cases) Encoded/hashed default and named work Same Compatibility controls
T1 ordering Fresh seed per independent action Same Sequential calls; persisted-file snapshots

Captures: before 909e4c9482, after dc98776633. Linux x64 / Node 26.12.1; real files, inert-PTY service scenarios plus real node-pty and WebSocket RPC. All seeds are synthetic, in fresh homes under /tmp/ev-18671; no live userdata. No render path changed, so UI captures and pixel diffs do not apply. What else changed: no behavior beyond guarded legacy resolution and deletion; ordinary/current-history controls agree.

Verification log
  • 45/45 focused Manager cases pass after final main merge; removing the guard fails both collision cases, removing case folding fails mixed-case only. Main had 43 existing cases; the original PR added one; replacement adds two parameterized cases.
  • Focused lint/format and server typecheck pass; one existing lint warning remains in unchanged code.
  • One independent full-diff review round: GPT-6.1 Sol MERGE and Claude Opus 5.5 MERGE; no blocking findings. Existing ordinary legacy migration coverage confirmed.
  • Complexity: linear ID sanitization/case folding; directory filter O(entries × ID length). Approximately 3,000-token malformed probes remain sub-millisecond; no new regex/parser.
  • Final head: 4f9c30a87f, merged main 3cc31ed27c. Both terminal files are byte-identical to the captured revision. Final-head proof audit: SUFFICIENT, including final-head RPC rerun.
  • CI: pending publication; no merge performed.
  • Unverified surfaces: native case-insensitive macOS/Windows filesystem execution; Linux mixed-case surrogate verifies guard semantics. Only server paths changed; web, desktop and mobile captures do not apply.
  • Implementation/tests: Claude Opus 5.5 via T3 Code. Reviews: GPT-6.1 Sol and Claude Opus 5.5. Evidence/proof audit/PR lead: GPT-6.1 Sol through Codex in T3 Code.

Batuhan1999 and others added 9 commits October 12, 2026 16:20
The legacy history filename is the sanitized thread id, so a thread id
such as "terminal_YQ" names thread "a"'s current history file. Opening
that thread migrated thread "a"'s history into it and removed the
original, and deleting its history removed thread "a"'s file. Skip the
legacy lookup, migration, and deletion when the legacy name has the
current "terminal_" prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ent threads

A thread id such as "terminal_YQ" sanitizes to the same legacy filename that
thread "a" uses today, so opening it migrated and deleted thread "a"'s
history, and closing with deleteHistory removed it again. Legacy names now
resolve to nothing when they carry the "terminal_" prefix, so read, delete,
and thread-wide delete all leave the other thread's file alone. One test
covers all three paths.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
On case-insensitive filesystems (macOS, Windows) a thread id such as
"Terminal_YQ" produced a legacy name that did not match the "terminal_"
prefix check yet resolved to another thread's current terminal_YQ.log,
so readHistory migrated it and deleteHistory removed it. Compare the
prefix without case so the reserved namespace covers every casing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
# Conflicts:
#	apps/server/src/terminal/Manager.test.ts
#	apps/server/src/terminal/Manager.ts
…thread's file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Oct 24, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at d46050d

Macroscope's review found this PR approvable — The change prevents ambiguous legacy filenames from being read, migrated, or deleted as another thread's terminal history. Current history paths remain unchanged, and skipped legacy files are left intact.

You can add or adjust custom eligibility rules. Learn more.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: d899bdd · PR result: d46050d · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@juliusmarminge juliusmarminge added bugfix Fix PR opened by an issue lead; enters the PR loop pr:needs-julius Needs Julius: route gate, unverifiable surface, or blocked labels Oct 24, 2026
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Legacy history lookup and thread-wide deletion now skip filenames for sanitized thread IDs that begin with terminal_, regardless of case. Regression tests verify that opening or deleting the matching thread does not change an aliased file.

Changes: Legacy history path guard

Layer / File(s) Summary
Legacy history eligibility and deletion
apps/server/src/terminal/Manager.ts, apps/server/src/terminal/Manager.test.ts
Legacy history lookup and thread-wide deletion skip filenames for sanitized thread IDs beginning with terminal_, regardless of case. Tests cover lowercase and mixed-case aliases and verify that their files and contents remain unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: adamulek123

Merge Risk: Minimal · up to d4605

This change stops a legacy terminal history filename from resolving to another thread's history file, and ordinary legacy migration is intended to stay the same. No merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: legacy terminal history filename handling is changed so that one thread cannot read or delete another thread's history. The title is specific and follows the conventio…
Description check Passed The description states the problem, the change, the scope, and the verification. It explains that a legacy history filename can collide with another thread's current history file. It describes the gua…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: legacy terminal history filename handling is changed so that one thread cannot read or delete another thread's history. The title is specific and follows the conventional commit form. The change is in apps/server/src/terminal/Manager.ts, and the summary describes a guard for legacy filenames in the terminal_ namespace. The title matches that change.

Full details: Description check

Explanation

The description states the problem, the change, the scope, and the verification. It explains that a legacy history filename can collide with another thread's current history file. It describes the guard that reserves the case-insensitive terminal_ namespace in one resolver used by migration, individual deletion, and whole-thread deletion. It links the original issue and contribution, and it lists tests and manual checks with results. It also states what was not verified, which is native case-insensitive macOS and Windows filesystems. The template headings Problem, Change, Scope, and Verification are present, and the Problem section is filled in. The description does not follow the template's section layout exactly. It places the problem statement at the top and wraps the original author's text in a details block. The description is mostly complete, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4f9c30a and d46050d.

Files selected for processing: 2

  • apps/server/src/terminal/Manager.test.ts
  • apps/server/src/terminal/Manager.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Main replaced the legacy size guard with historyPaths/historyExists; the
terminal_ namespace guard now gates the legacy entry in historyPaths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Nov 14, 2026
@juliusmarminge

Copy link
Copy Markdown
Member Author

Evidence

Evidence from the real server on Linux with a case-sensitive filesystem, driven through WebSocket RPC. Screenshots and recordings show the driver's live server-response transcript, not the web terminal UI.

For each operation, use fresh data: open a/term-1, write echo OWNER_A_MARKER_$((6*7)), verify persisted terminal_YQ.log, stop and restart the server, then open or delete history for terminal_YQ. Reopen a/term-1 and inspect its history.

Operation Before — d899bddfa2 After — d46050d5c1
Open colliding thread Before: colliding thread receives owner marker and owner loses it After: no marker leaks and owner retains history
Delete one terminal's history Before: close-terminal deletes owner history After: close-terminal preserves owner history
Delete all thread terminal history Before: close-all deletes owner history After: close-all preserves owner history
Recordings Before: all three interactions After: all three interactions

Reproduction and capture driver · Base transcript · Head transcript

All three reported collisions reproduced on base and were absent on head. The mixed-case Terminal_YQ variant on a case-insensitive filesystem was not exercised.

Not shown:

  • The mixed-case Terminal_YQ collision on a case-insensitive filesystem was not exercised; both runs used Linux with a case-sensitive filesystem.
  • Web, desktop, and mobile terminal rendering was not captured; this proof exercises the real server's terminal RPC and persistence behavior.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 14, 2026
@juliusmarminge
juliusmarminge merged commit 96051c6 into main Nov 14, 2026
52 checks passed
@juliusmarminge
juliusmarminge deleted the takeover/pr-18671 branch November 14, 2026 07:45
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 14, 2026
vedprakash2302 added a commit to vedprakash2302/Cody that referenced this pull request Nov 14, 2026
Brings in upstream through 96051c6 (pingdotgg#24574). No conflicts.

- WSL backends start in the Linux home (pingdotgg#35719); Cody's ~/.cody home and the
  forwarded Windows sign-in helper are unchanged.
- OpenCode explicit background waits (pingdotgg#35272) sit beside Cody's fork cut in the
  OpenCode 2 adapter.
AIdoesmyjob pushed a commit to AIdoesmyjob/t3code that referenced this pull request Nov 14, 2026
pingdotgg#24574)

Co-authored-by: Batuhan1999 <Batuhan.Ckr@outlook.de>
(cherry picked from commit 96051c6)
Pipyakas pushed a commit to Pipyakas/t3code that referenced this pull request Nov 15, 2026
pingdotgg#24574)

Co-authored-by: Batuhan1999 <Batuhan.Ckr@outlook.de>
(cherry picked from commit 96051c6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fix PR opened by an issue lead; enters the PR loop pr:needs-julius Needs Julius: route gate, unverifiable surface, or blocked size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants