Skip to content

fix(server): retain unfinished terminal sequences in attach history - #42817

Merged
juliusmarminge merged 14 commits into
pingdotgg:mainfrom
StiensWout:wf/find-d223da4ce8001e92eeb6f3fb
Nov 25, 2026
Merged

juliusmarminge merged 14 commits into
pingdotgg:mainfrom
StiensWout:wf/find-d223da4ce8001e92eeb6f3fb

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Joining or reconnecting to a terminal could display part of its title as output when the history limit cut through a control sequence. Updated viewers opt in to snapshots that carry parser state for discarded prefixes, so they can skip the continuation and still replay the next escape sequence. Older viewers keep the legacy replay format.

Related: #42761, #42760, #25192

Reproduction on main

Commit 21a96989b0 (main), in the running web app:

  1. Open the app in a browser and start a thread on a project.
  2. Open the thread's terminal.
  3. Run a program that sets the terminal title to two hundred thousand characters that each take three bytes, and does not end that title with a bell.
  4. Have the program start a second title with the escape that begins a title and the text Build, then wait several seconds.
  5. While it waits, open the same thread in a second browser tab and open that tab's terminal.
  6. Let the program finish the second title with the text progress and a bell, then print a line that says ready.

The second tab's terminal shows the word progress and then the line ready. Expected: The second tab's terminal shows the line ready, and the title text stays out of the terminal.

The cause is at apps/server/src/terminal/Manager.ts:3722. Ran cd apps/server && pnpm exec vp test run src/terminal/Manager.test.ts with the repro test added: it failed in 2 of 2 runs on a clean checkout, with expected 'progress\u0007ready\r\n' to be 'ready\r\n' in the output.

Evidence

Environment: Linux x64, the repository's own tests.

Proven: the repro fails at the test commit 7924b2e45d and passes on the head 25bc30412e, both on main c478fde9fe.

Before After
Commit 7924b2e45d 25bc30412e
Result failed with "expected 'progress\u0007ready\r\n' to be 'ready\r\n'" passed

Outside view: a person sees it in the running web app by following the steps under Reproduction on main.

Tests

  • 7924b2e45d adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed c478fde9fe323fd6d10ef9a0b109b015546fb8e0 passed on head.

Not in this change

  • Older viewers retain the existing limitations of shortened replay and byte budgets that cannot fit an introducer. Matching the parser mode alone cannot preserve a command’s parameters.

Who did the work

  • Repro written by GPT 6.2 Sol, in Codex
  • Outside view by Grok 4.7, in Grok
  • Duplicate check judged by Claude Opus 5.5, in Claude Code
  • Written by GPT 6.2 Sol, in Codex
  • Trimmed by Claude Opus 5.5, in Claude Code
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex, and by Gemini 4 Neon, in Antigravity
  • Reproduction, checks and proof run by a program on base and head, not by an agent

Made in T3 Code by GPT 6.2 Sol, Claude Opus 5.5, Grok 4.7 and Gemini 4 Neon

StiensWout and others added 11 commits November 25, 2026 13:28
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
A zero budget already falls through to the retained history, since no sequence or introducer fits.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…etention

An empty history has no ESC, so it already returns the retained history.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…-byte path

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
The viewer input and the omitted-state assertion no longer branch on the flag.

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:L 100-499 changed lines (additions + deletions). labels Nov 25, 2026
@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 25, 2026
…e92eeb6f3fb

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Terminal snapshots can carry parser state for omitted control-sequence prefixes. The server uses a client capability flag when creating and streaming snapshots. Client output handling skips matching continuation data. Tests cover attach, observe, resync, and split sequences.

Changes: Terminal snapshot replay

Layer / File(s) Summary
Snapshot history and sequence-state contract
packages/contracts/src/terminal.ts
Adds snapshot history retention and continuation-skipping helpers. Observe and attach inputs accept a capability flag, and snapshots can include historySequenceState.
Server snapshot construction and stream delivery
apps/server/src/terminal/Manager.ts, apps/server/src/terminal/Manager.test.ts
Snapshot paths use the capability flag to select retained history and sequence state. Tests cover attach, observe, and resync snapshots with bounded history.
Client snapshot replay and continuation handling
packages/client-runtime/src/state/terminal.ts, packages/client-runtime/src/state/terminalOutput.ts, packages/client-runtime/src/state/terminalSession.ts, packages/client-runtime/src/state/runtime.test.ts, packages/client-runtime/src/state/terminalSession.test.ts
Client requests enable snapshot sequence state. Output state initializes parser state from snapshots and skips matching continuation data. Tests cover split control sequences and later output.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ClientRuntime
  participant TerminalManager
  participant TerminalOutputState
  ClientRuntime->>TerminalManager: attach or observe with supportsSnapshotSequenceState
  TerminalManager-->>ClientRuntime: snapshot with history and optional historySequenceState
  ClientRuntime->>TerminalOutputState: resetOutput with snapshot
  TerminalManager-->>ClientRuntime: subsequent terminal output
  ClientRuntime->>TerminalOutputState: appendOutput with continuation chunk
  TerminalOutputState-->>ClientRuntime: output after matching continuation is skipped
Loading

Suggested reviewers: juliusmarminge

Merge Risk: Minimal · up to de74e

This change stops terminal title text from appearing as output when attach history cuts through an unfinished control sequence. Updated clients opt in to the new behavior, and older viewers keep the existing replay format. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(server): retain unfinished terminal sequences in attach history" matches the main change. The server now keeps parser state for unfinished escape sequences omitted from attach snapshot …
Description check Passed The description follows the template sections (Problem, Change, Scope, Verification) and gives a clear problem statement, reproduction steps, and the cause location. The Change section is weak: it say…
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 "fix(server): retain unfinished terminal sequences in attach history" matches the main change. The server now keeps parser state for unfinished escape sequences omitted from attach snapshot history, so viewers skip the leftover title text. The title is a conventional commit, short, and names the affected area (server, attach history).

Full details: Description check

Explanation

The description follows the template sections (Problem, Change, Scope, Verification) and gives a clear problem statement, reproduction steps, and the cause location. The Change section is weak: it says the fix lets updated viewers opt in to parser state but does not explain how the change works across the server, contracts, and client runtime, or why those components must change together. The Scope section does not link a tracked issue for the bug. It cites related PRs and issues (#42761, #42760, #25192), but it does not say which issue shows the bug, and it does not state that a maintainer requested the PR or explain why an issue is unnecessary. The Verification section gives a focused failing test and a before/after result, which meets the template. It also notes that 'Tests pass' alone is insufficient, and the author provides more than that. The description is mostly complete, so the check passes, but the Change and Scope sections need improvement.

Finishing Touches

Generate unit tests (beta)

  • 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 49bad08 and de74e90.

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; 4 remain after this review.

Reuse the existing manager fixture instead of a second hand-rolled one, and drop a client case that repeated the zero-budget attach path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Reconnected the web terminal during an unfinished OSC title containing 200,000 U+2500 characters, then resumed with progress, BEL and ready. Base exposes progressready; head correctly displays only ready. Chromium, 1280×800, light theme, fresh synthetic state on each side. Initial shell prompt paths are masked in recordings.

Before After
cef38e408d 49bad08089
Before: progress leaks After: only ready
Before recording After recording

Scenario source

Not shown:

  • The scenario exercised browser reload/reconnect rather than a simultaneous second-tab join; the original live-view versus joining-view comparison was not separately captured.
  • Mobile, desktop, legacy viewers and other unfinished terminal sequence types were not exercised by this focused web reproduction.

@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 25, 2026
…e92eeb6f3fb

Keep main's compacted CSI replay (pingdotgg#42808) for every viewer; snapshot parser state now only stands in for long strings and oversized prefixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Real web app, fresh databases, Replay-seeded thread, 1280×800 viewport, light theme. Wrote an unfinished OSC title containing 200,000 U+2500 characters, followed by another unfinished title prefix and Build. Attached a second independent web client during the pause, then emitted progress + BEL + ready + newline. The second client was hosted in a same-origin iframe. Identical scenario on both commits; scenarios:prove exited 0.

Before After
1c3f0ee88f de74e909b7
Incorrectly displays progressready Correctly displays only ready
Before: title continuation leaks into output After: title continuation stays hidden
Before recording After recording

Scenario source. Recordings omit setup frames containing local paths. Captures visually inspected.

@juliusmarminge
juliusmarminge merged commit e6738fd into pingdotgg:main Nov 25, 2026
38 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 25, 2026
@StiensWout
StiensWout deleted the wf/find-d223da4ce8001e92eeb6f3fb branch November 25, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 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