Skip to content

fix(resume): keep a killed pane's agent session; stop view state rotating snapshots - #379

Merged
amirlehmam merged 2 commits into
amirlehmam:masterfrom
clemrdh:fix/keep-agent-session-on-killed-pane
Oct 27, 2026
Merged

amirlehmam merged 2 commits into
amirlehmam:masterfrom
clemrdh:fix/keep-agent-session-on-killed-pane

Conversation

@clemrdh

@clemrdh clemrdh commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

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 then TerminateApplications. 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. clearAgentState went through forget(), 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.

  • clearAgentState keeps the record's handle in orphanedSessions and drops the record without marking it released. The sidebar still gets unknown, as grow wmux grow ;) #128 requires.
  • 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.
  • A PTY exit no longer calls notifySessionChanged, since the saved id does not change.

This reverses one test from #306: forgets it when the PTY exited under it is now keeps 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. layoutFingerprint skips the workspace cwd because it moves on every prompt. But each surface's own cwd/currentCwd, its resolvedShell, and each leaf's activeSurfaceIndex were counted. A cd or 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 TerminateApplications had 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-surface cd, 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 typecheck passes.
  • ESLint on the changed source reports 4 no-empty errors in session-persistence.ts. All four are already on master, on lines this PR does not touch.
  • Full suite with --maxWorkers=2: 5,764 passed, 15 skipped, 0 failed.

🤖 Generated with Claude Code

clemrdh and others added 2 commits October 26, 2026 23:50
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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-26T23:02:45.048925Z
We couldn’t complete this review. Comment @codex review to try again.
c615cd2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@amirlehmam
amirlehmam merged commit 6cb88c5 into amirlehmam:master Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants