Repository navigation
Fix Agent Hibernation never selecting live Claude Code sessions - #17306
teamleaderleo merged 2 commits into
Conversation
A live Claude session in a pane with only its own process tree is still marked as containing unrelated processes, so Agent Hibernation never selects it. Add the failing regression plus a guard that a genuinely unrelated process in the pane keeps the session unsafe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsVtv4Ck96SHeGWAqLTG97
Claude Code is indexed from its hook record and never process-detected, so its entry always reported containsUnrelatedProcess and failed the process-safety check for scheduled and memory-pressure hibernation. The loader now scopes a live hook PID against the same process snapshot used for process-detected agents. The entry takes that scope's verdict and termination set; without a fresh scope it stays unsafe as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AsVtv4Ck96SHeGWAqLTG97
|
All contributors have signed the CLA ✍️ ✅ |
|
Thanks for opening your first cmux pull request! We're a small team and the outside-PR queue is long, so a reply can take a while, sometimes longer than we'd like. If this one goes quiet and you'd like eyes on it, comment here and we'll pick it up. A few things that help:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe index loader now accepts panel-scoped process data for live hook-recorded agents. When a matching scope is available, the index uses it for process and hibernation details. Existing PID-only fallback behavior remains when the agent PID or scope is unavailable. ChangesClaude hook session process scope
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to This change lets idle live Claude sessions be selected for hibernation while still blocking it when unrelated processes share the pane. No merge-blocking risk was found; CI should confirm the new tests pass. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Live Claude sessions can now enter a destructive hibernation path. The inspected design retains panel attribution, process-identity checks, unrelated-process rejection, and recovery safeguards. No introduced security defect was established, but native execution and failure recovery remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (2 errors, 1 warning)
✅ Passed checks (22 passed)
Full details: Cmux Algorithmic ComplexityExplanation The diff adds a redundant full process scan and sort on each live-agent index load. Resolution Reuse the panel-to-process-ID map created by Full details: Cmux Architecture RethinkExplanation The new hook scope is wired only through Resolution Move hook-PID scope derivation into the shared process-census/index-loading owner, or route all fresh and cached index loads through one shared builder that receives the same process snapshot and derives detected-agent and hook-agent scopes. Remove the optional nil-by-default path for production hibernation callers, or otherwise make their omission impossible. Update scheduled, memory-pressure, post-snapshot, and pre-signal validation paths to use that shared scope logic. Add tests that load the same hook-backed session through each production path and verify the same panel scope, termination identities, and unrelated-process result. The first migration cut is to make
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I have read the CLA Document v2.2 and I hereby sign the CLA |
|
Thank you @KasperScript, great root-cause writeup, and the red/green tests make this easy to trust :D CI is approved and running; we'll merge once it's green. |
|
Merge receipt for |
7997c55 fix(cloud): update machine rename optimistically (manaflow-ai#17324) c9bdbd6 Fix missing Terminals tab while Cloud machine connects (manaflow-ai#17326) b047fa3 Fix Agent Hibernation never selecting live Claude Code sessions (manaflow-ai#17306) 9aefea4 cloud sidebar polish: header refresh, tab switch, empty states, errors and upgrade (manaflow-ai#17074) # Conflicts: # .github/workflows/ci-guards.yml # .github/workflows/ci.yml
|
Merged, thank you @KasperScript! Agent Hibernation can now pick live Claude Code sessions again :D |
Summary
Live Claude Code sessions can now be hibernated. Before, every hook-backed agent entry reported
containsUnrelatedProcess, so Agent Hibernation never selected one, on schedule or under memory pressure. Fixes #17305.Claude is indexed from its hook record and never process-detected, so its entry never got the process-tree scope that detected agents get.
SharedLiveAgentIndexLoadernow passesRestorableAgentSessionIndex.loada provider that scopes a live hook PID against the same process snapshot, usingagentHibernationProcessScopeas detected agents do. The PID must be cmux-attributed to that panel. The entry takes that scope's termination set, identities and unrelated-process verdict. With no scope (other callers, or a PID not attributed to the panel), the entry stays unsafe exactly as before.cmuxScopedProcessIDsByPanelKey()dropsprivateso the loader can reuse it.Related: #13834 makes resumed sessions idle and restorable. This change makes them pass the process-safety check after that.
Testing
Focused command, run locally on macOS 27 with Xcode 27:
./scripts/test-unit.sh -derivedDataPath <dir> -only-testing:cmuxTests/ClaudeHookSessionLivenessTests testb8f88fe6, the test-only commit: 5 tests ran and 1 failed. "A live Claude hook session in an exclusive pane is safe to hibernate" failed onterminationProcessIDs == [agentPID, mcpServerPID],containsUnrelatedProcess == falseandprocessSafetyAllowsScheduledHibernation. The other 4 passed, including the new guard that an unrelated process in the pane keeps the session unsafe.af1445a0, the fix: 5 tests ran and all passed.af1445a0:AgentHibernation*,RestorableAgent*,SharedLiveAgentIndex*,AggregateMemoryRetention*,AgentResumeLiveness*,ForkParentFallback*,CompletedRestoredAgent*andClaudeHook*(46 files). 340 Swift Testing tests in 40 suites passed.python3 scripts/verify-local.pypassed 17/17 static checks.E0463 can't find crate for tokio_macros). For these local runs only, I pointedNative/DiffSidecar/rust-toolchain.tomlat stable 1.99. That change isn't part of this PR.maxLiveTerminals1 stayed running for 7+ minutes.Changelog
Fixed: Agent Hibernation now hibernates idle background Claude Code sessions
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01AsVtv4Ck96SHeGWAqLTG97