Repository navigation
fix(resume): keep a killed pane's agent session; stop view state rotating snapshots - #379
Merged
amirlehmam merged 2 commits intoOct 27, 2026
Conversation
A PTY exit released the pane's agent handle: `clearAgentState` went through `forget()`, which marks the surface released, so the next autosave wrote the tab as a plain shell. That is right for the run state (it describes a dead process) and wrong for the handle. An agent that quits on its own releases first (Claude's SessionEnd, the Codex launcher, the OpenCode plugin), so a pane that reaches a PTY exit still holding a handle had its process killed from outside, and the conversation is still on disk to resume. Seen on 2.28.1: a Microsoft Store update of PowerShell terminated every packaged pwsh.exe at once. Ten Claude Code sessions ended in the same seven seconds, the next snapshot dropped 7 of the 11 agent ids, and the restore after the wmux update and reboot brought back bare shells. - `clearAgentState` keeps the record's handle in `orphanedSessions` and drops the record without marking it released. The sidebar still gets `unknown`. - `providerLookup` returns a kept handle to its own provider and clears the others, like a live record. - A new report in that tab replaces the kept handle; a release forgets it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fingerprint already skips the workspace `cwd`, `bounds` and `sidebarWidth`, because counting them lets the gate pass on almost every tick. The split tree has the same noise one level down, and it was counted: each surface's `cwd`/`currentCwd` (frozen into the tree on every save), its `resolvedShell`, and each leaf's `activeSurfaceIndex`. So a `cd` or a tab click was enough to spend a ring slot every five minutes, and the three-slot ring kept about the last fifteen minutes of ordinary use. This does not by itself explain the 2.28.1 incident behind the previous commit: there, the slots were spent on the dropped agent ids (fixed there), the first snapshot after launch (intended) and a new Claude session id (still counted). It keeps ordinary use from doing the same. Agent session ids, titles, tabs and splits still count as changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
On 2.28.1, a Microsoft Store update of PowerShell took most of the Claude and Codex conversations out of a 21-tab session. While it installs a new version, the Store terminates every packaged
pwsh.exe. Ten Claude Code sessions ended within seven seconds (20:14:25 to 20:14:32), right as the AppX deployment log shows the update starting and thenTerminateApplications. The next snapshot held 4 agent ids out of 11. The wmux update and reboot half an hour later restored exactly that: 21 tabs, 4 agents.Two things in wmux turned the kill into a loss.
1. A PTY exit released the pane's session handle.
clearAgentStatewent throughforget(), which marks the surface released, and the save-time lookup turns "released" into "clear the id". That is right for the run state, which describes a dead process. It is wrong for the handle. An agent that quits on its own releases first (Claude's SessionEnd, the Codex launcher, the OpenCode plugin), so a pane that reaches a PTY exit still holding a handle was killed from outside, and its conversation is still on disk. The Codex launcher already follows this rule ("Only an orderly CLI exit forgets the handle"); main's PTY-exit path did not.clearAgentStatekeeps the record's handle inorphanedSessionsand drops the record without marking it released. The sidebar still getsunknown, as grow wmux grow ;) #128 requires.providerLookupreturns a kept handle to its own provider and clears the others, like a live record.notifySessionChanged, since the saved id does not change.This reverses one test from #306:
forgets it when the PTY exited under itis nowkeeps the Claude id through the PTY exit. The case where the user exits the agent and then the shell dies keeps its own test and still clears the id.2. View state inside the split tree rotated the snapshot ring.
layoutFingerprintskips the workspacecwdbecause it moves on every prompt. But each surface's owncwd/currentCwd, itsresolvedShell, and each leaf'sactiveSurfaceIndexwere counted. Acdor a tab click spent a ring slot every five minutes, so the ring held about fifteen minutes of ordinary use. These keys are now stripped (TREE_VIEW_STATE). Agent ids, titles, tabs and splits still count.The second change alone would not have saved the incident's snapshot. Its three slots went to the dropped ids (fixed by change 1), the first snapshot after launch (intended), and a new Claude session id (still counted).
Not covered: if Claude Code runs its SessionEnd hook while being killed and the hook reaches wmux, that is still a release. It did not happen here. The snapshot written 14 s after the last Claude exit still held all 11 ids. They were gone from the next one, written after
TerminateApplicationshad killed the shells.Validation:
agent-session-persistence.test.ts: a killed pane keeps its Claude id (on the saved tree and on a fresh one), keeps a Codex handle under Codex, and keeps a restored id when the agent had reported state only. A new report replaces the kept handle, and a later release forgets it. The four "keeps" tests fail without the change.agent-state.test.ts: a PTY exit keeps the handle and is not a release, and it does not request a prompt save.session-snapshot.test.ts: a per-surfacecd, a tab switch and a new resolved shell path leave the fingerprint unchanged; a rename or a new conversation still changes it. The three "unchanged" tests fail without the change.npm run typecheckpasses.no-emptyerrors insession-persistence.ts. All four are already on master, on lines this PR does not touch.--maxWorkers=2: 5,764 passed, 15 skipped, 0 failed.🤖 Generated with Claude Code