Repository navigation
fix(terminal): a mounted terminal keeps its live output across a same-id shell respawn - #1333
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-id shell respawn The shell's view reference was a manager flag cleared when the shell exited, so a still-mounted leaf froze on the dead shell after a same-id respawn. It is now a view-scoped count with a detachTerminal release, owned per renderer page like agent PTY attaches (one shared ownership table), and TerminalLeaf detaches on unmount. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…anager once Round-1 review of #1333: the absent-session reference had no test, and a cold per-test import of the manager hit the default timeout under load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Review disposition (round 1 + verification, head
|
| Finding | Verdict | Disposition |
|---|---|---|
| a, b, c: the attach-while-shell-down path (a missing session takes a reference) had no test; removing it survived | valid | Test added in cb76010c: attach after exit, then a same-id respawn forwards. It kills the mutant. Verified by a and b |
| a: the new manager test hit the default 5 s timeout on a cold, contended run | valid | Root cause: the manager graph was imported inside the first test (~4 s). It is now imported once at module scope, and the tests take ms. Verified by a |
| c: the "second window's lane" test comment overclaims, because the window router gives a session one owner | valid | Comments corrected in the test and in sessionManager.ts: the count is about views within the receiving renderer |
| a (suspicion): an attach whose IPC reply is lost while the page lives could leave a reference | not reproduced | A page reload or destroy still releases it. No Electron path was found that loses only the reply |
Verification: a and b are MERGE-READY at cb76010c; c was MERGE-READY in round 1.
This was referenced Sep 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1281 (the terminal half; the agent half shipped in
2ab60d45). Refs #1283: this closes item 3, "attach counts not tied to a page", for plain terminals. #1311 (6cf6f054) already did it for agent PTYs. Items 1 (orchestration tombstones) and 2 (Codex window lease) remain open there.Plan:
docs/plans/2026-09-26-terminal-attach-survives-respawn.md(first commit).Problem
A plain terminal's live output depended on a manager flag,
terminalAttached.cleanupSessionStatedeleted it when the shell exited.TerminalLeafattaches only once per session id. A shell respawned under the same id (recover, from a delivery, a control call or a wake) buffered its bytes but never forwarded them. The xterm stayed on the dead shell while keystrokes reached the new one unseen, until a remount.What merges
SessionManager:terminalAttachCountsreplaces the flag. It is a per-view count, because two lanes can show one shell. Process cleanup leaves it alone, the same rule the agent PTY count follows since Same-id wake of a mounted terminal-view agent leaves the xterm frozen on the dead process #1281's agent half. The newdetachTerminalreleases one reference.attachTerminalreturnsnull, and takes no reference, only for a non-terminal id.rawViewOwnership, used for both agent PTY and terminal views, with one shared page-document map.attachTerminalnow sends the document; a newdetachTerminaldoes the same.TerminalLeafdetaches in its effect cleanup. An attach that resolves after unmount releases itself.Tests
sessionManager.terminalAttachRespawn.test.ts(new, 4 tests, drives the real manager with a fake PTY; the manager is imported once at module scope):ipc/session.test.ts, "terminal attach ownership": reload and destroy release a page's references; a stale page's detach is ignored and its attach takes nothing; a non-terminal attach takes no reference; one detach passes through per attach.TerminalLeaf.retention.renderer.test.tsx: unmount releases; a late attach releases itself.npx tsc -bis clean. Full suite (Node 24): 7247 passed, 1 skipped, 1 failed. The failure iscontrol.system.test.ts, which times out the same way on origin/main.Reviews: one round (a, b, c) plus a and b's verification, all MERGE-READY; the disposition is in the PR comments.
🤖 Generated with Claude Code