Repository navigation
fix(terminal): keep the wake record when the shell shows through a hibernation kill - #27295
deepbluejay wants to merge 3 commits into
Conversation
…bernation kill Agent sleep writes a sleeping record, suppresses the PTY exit, then kills the PTY. The agent dies before the PTY does, so the pane can confirm its own shell in the foreground in between. That confirmation treated the record as stale and cleared it, so the exit found nothing to arm and the pane never resumed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue is established. Merge after normal checks. Pre-merge checks |
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
eb26f405-39d8-452d-b230-f7f19bad431b
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pty-connection-hibernation-kill-shell-foreground.test.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
…er the exit A command-finished read can still be awaiting the foreground process when the suppressed exit lands and arms the wake. The suppression is spent by then, so also recognise the record the pane has armed as its wake target. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Match the wake target to the current PTY. · pane-agent-identity.ts:205-214
src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts:205-214
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winMatch the wake target to the current PTY.
bindActivePanePtycan bind live PTY B without clearing the armed wake target or sleeping record. The foreground tracker can then confirm B as a shell before wake consumption. The record-only match skips stale-record cleanup for B.Suggested fix
const sleepingRecord = session.getSleepingRecordForPane(state) const ptyId = session.transport.getPtyId() + const wakeTarget = session.hibernatedWakeTarget // Why: a hibernation kill ends the agent before the PTY, so the shell shows through for a // moment. That record was just written as the wake hint; clearing it strands the pane. // A read can also settle after the exit armed the wake, when the suppression is already spent. const isHibernationWakeRecord = sleepingRecord !== null && noteArmsHibernatedPaneWake(sleepingRecord.record) && ((ptyId !== null && state.suppressedPtyExitIds[ptyId] === true) || - session.hibernatedWakeTarget?.record === sleepingRecord.record) + (wakeTarget?.record === sleepingRecord.record && + (ptyId === null || wakeTarget.ptyId === ptyId)))
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6a36243f-aba4-4931-bb9d-902bde47d02f
📒 Files selected for processing (2)
src/renderer/src/components/terminal-pane/pty-connection-hibernation-kill-shell-foreground.test.tssrc/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
- src/renderer/src/components/terminal-pane/pty-connection-hibernation-kill-shell-foreground.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The wake-target guard matched the record alone, so a shell confirmed on a PTY bound after the hibernated one (a restart) kept the stale record. Match the target's PTY too, as consumeHibernatedAgentWake already does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
@coderabbitai Re: the outside-diff comment "Match the wake target to the current PTY" ( Valid, and fixed in 0ce0221. The guard I added in 40c4ecd matched the armed wake target by record only. A restart can bind a new PTY to the pane without consuming the armed wake or clearing the sleeping record, so a shell confirmed on that new PTY kept the stale record. Before this PR that confirmation cleared it, so this was a regression from my own fix. The guard now also requires the target's PTY to be the one still bound (or no PTY bound), which is the same check New test: "clears the record once another PTY is bound in place of the hibernated one". It fails on 40c4ecd and passes now. The three existing tests in that file still pass, including the one where the confirmation settles after the exit with the hibernated PTY still bound. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
ast-grep outline src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
sed -n '170,240p' src/renderer/src/components/terminal-pane/pty-connection/pane-agent-identity.ts
ast-grep outline src/renderer/src/components/terminal-pane/pty-connection-hibernation-kill-shell-foreground.test.ts
sed -n '1,300p' src/renderer/src/components/terminal-pane/pty-connection-hibernation-kill-shell-foreground.test.ts
rg -n -C 12 'consumeHibernatedAgentWake\s*[:=(]' src/renderer/src/components/terminal-paneLength of output: 27610
The new regression test checks that a shell confirmation clears the record after a replacement PTY is bound. The existing tests retain coverage for confirmations during the kill and after the suppressed exit. This addresses “Match the wake target to the current PTY.” I verified the code and test assertions; I did not rerun the tests. ✏️ Learnings added
🧠 Learnings usedIf you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
|
Thanks @deepbluejay. Main landed the in-flight half of this in #28838, so I rebased the remaining late-confirmation half and your regression tests onto main in #29391 (you're credited as co-author). Closing this one in favour of that. |
ELI5
Agent sleep shuts down a finished agent tab to save memory and is supposed to bring it back when you open the tab again. Some slept tabs never came back: you opened the tab and it was a dead terminal. This makes those tabs wake up.
What Changed
claude --resume <id>by hand. It happens when the pane already knows an agent is running in it (the tracker identified the process, or the pane has a launch identity or a live hook icon), for example a pane restored after a relaunch, or a pane that was woken once and sleeps again.onConfirmedShellForegroundclears the sleeping record as stale. When the exit lands there is no record, so the wake is never armed. The fix skips that clear when the record is this pane's hibernation wake hint:noteArmsHibernatedPaneWake(record)and either the pane's current PTY has a suppressed exit pending, or the exit already armed this record assession.hibernatedWakeTarget. Everything else in the handler is unchanged.Why
The clear came in with #21714 to drop a stale sleeping identity after
/exit, and it is right for that. During a hibernation kill the record being cleared is the one the in-flight hibernation just wrote, so "confirmed shell means the record is stale" is the wrong conclusion in exactly this window. The guard reuses the signalssession-reconcile-dispose.tsandpty-exit-hibernate.tsalready use to recognise a hibernation kill, so a stale record beside an ordinary live PTY is still cleared as before.Alternatives I did not take: cancelling the tracker's pending read when hibernation starts (the pane would then never retire the dead agent's identity for the remaining second, and the handler would stay one missed caller away from the same failure), and re-writing the record after the exit (two writers for one record). Guarding the one decision that is wrong was the smallest change.
Linked Issue
Fixes #27294
Visual Proof
N/A. No UI change; the difference is whether a process is started when the tab is opened. State and process observations from the dev build are in Testing.
Testing
macOS (Apple silicon), dev build via
pnpm devwithORCA_BACKGROUND_LAUNCH=1, driven over CDP, real Claude Code, Agent sleep on with a 1 minute idle time. Not tested on Linux, Windows or SSH.Route 1, no relaunch: tabs A and B, run
claudein A to a finished turn, switch to B, let A sleep, open A (wakes), send one more prompt, switch to B, let A sleep again, open A.done/worktree-sleep); opening A gives it a new PTY within 6 seconds andclaude --resume <same session id>is running.Route 2, relaunch: run
claudein A, switch to B, quit and relaunch, do not open A, let A sleep, open A.Control: the first sleep of a hand-typed agent the tracker has not identified wakes with and without the fix, because the tracker takes its no-read fast path there.
Automated: new
pty-connection-hibernation-kill-shell-foreground.test.ts, three cases.main, passes here.mainand on this PR's first commit, passes here.I ran 9 related suites (86 tests),
pnpm run tc:web, oxlint, oxfmt andcheck:code-quality:changed; all pass. I did not run the fullpnpm testfor this change.AI Disclosure
Found, fixed and tested with Claude Code (Claude Opus 5.5). I hit the bug myself on 1.4.224 and reviewed the diff.
Review
Agent skill upstream boundary
Notes
suppressedPtyExitIds, which hibernation sets for local, remote-runtime and SSH panes alike; I only exercised local.bd85767e. The lines touched are unchanged onmainat314993c2.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)🤖 Generated with Claude Code