Repository navigation
Prevent repeated automatic agent resume tabs - #6945
Conversation
|
Ready to review this PR? Stage has broken it down into 5 individual chapters for you:
Chapters generated by Stage for commit 43b9f39 on Jun 30, 2026 10:13pm UTC. |
📝 WalkthroughWalkthroughThis PR adds automatic agent resume claims to terminal state, threads 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/renderer/src/i18n/locales/zh.json (1)
660-662: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueInconsistent English copy between two
ephemeralVmsDescriptionstrings.The "Dev Tools" search-keyword entry says "Give each workspace its own on-demand, disposable environment on any provider, connected over an Orca server or SSH" while the
Settings.ephemeralVmsDescriptionentry (line 6122) drops "on-demand" and "connected": "Give each workspace its own disposable environment on any provider, over an Orca server or SSH." Since these are English source strings duplicated into zh.json (not yet localized), the divergence should be fixed at the source (en.json) so both copies stay in sync once translated.Also applies to: 6120-6122
src/renderer/src/lib/resume-sleeping-agent-session-replay.test.ts (1)
36-196: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider a negative-match test.
Coverage is solid for the queued/live/claim blocking paths. A test asserting that a record with a different
providerSession(same worktree/agent) is not blocked would guard against the matching logic inproviderSessionsMatch/activeOrQueuedResumeClaimsProviderSessionbecoming overly broad in future changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d1ec988f-6f32-4579-8ae9-b5314a666a82
📒 Files selected for processing (15)
src/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/lib/ephemeral-vm-workspace-target.tssrc/renderer/src/lib/resume-sleeping-agent-session-replay.test.tssrc/renderer/src/lib/resume-sleeping-agent-session.test.tssrc/renderer/src/lib/resume-sleeping-agent-session.tssrc/renderer/src/lib/worktree-activation.tssrc/renderer/src/store/slices/store-cascades.test.tssrc/renderer/src/store/slices/terminal-orphan-helpers.tssrc/renderer/src/store/slices/terminals.tssrc/renderer/src/store/slices/worktrees.test.tssrc/renderer/src/store/slices/worktrees.ts
| if (activeOrQueuedResumeClaimsProviderSession(record, currentState)) { | ||
| // Why: main can replay the old wake record after we have already queued | ||
| // the same provider session in a fresh tab. Clear the stale replay so | ||
| // workspace activation cannot fork the same agent every time. | ||
| state.clearSleepingAgentSession(record.paneKey) | ||
| continue | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Trim the "Why" comment to two lines.
As per coding guidelines, comments explaining non-obvious behavior should be "Keep comments short — one or two lines, capturing only the non-obvious reason." This block spans three lines.
✏️ Proposed fix
- // Why: main can replay the old wake record after we have already queued
- // the same provider session in a fresh tab. Clear the stale replay so
- // workspace activation cannot fork the same agent every time.
+ // Why: main can replay the old wake record after the same provider
+ // session was already queued in a fresh tab; clear the stale replay.
state.clearSleepingAgentSession(record.paneKey)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (activeOrQueuedResumeClaimsProviderSession(record, currentState)) { | |
| // Why: main can replay the old wake record after we have already queued | |
| // the same provider session in a fresh tab. Clear the stale replay so | |
| // workspace activation cannot fork the same agent every time. | |
| state.clearSleepingAgentSession(record.paneKey) | |
| continue | |
| } | |
| if (activeOrQueuedResumeClaimsProviderSession(record, currentState)) { | |
| // Why: main can replay the old wake record after the same provider | |
| // session was already queued in a fresh tab; clear the stale replay. | |
| state.clearSleepingAgentSession(record.paneKey) | |
| continue | |
| } |
Source: Coding guidelines
…space-new-tab # Conflicts: # src/renderer/src/i18n/locales/en.json # src/renderer/src/i18n/locales/es.json # src/renderer/src/i18n/locales/ja.json # src/renderer/src/i18n/locales/ko.json # src/renderer/src/i18n/locales/zh.json # src/renderer/src/lib/ephemeral-vm-workspace-target.ts
#10057) * test(session): guard against workspace-reopen tab fork-bomb (STA-1111) Relates to STA-1111 (already fixed on main by #6945). The runaway-tab-on-reopen bug was fixed by #6945 (activeOrQueuedResumeClaimsProviderSession dedup guard) hours before the ticket was filed. Verified: disabling that guard makes tab count climb 1->2->3->4 across reopens; restoring it holds at 1. This adds a revert-sensitive regression test covering the created-agent and sleeping-resume reopen paths so it cannot regress. Test plan: 2 new tests pass; fail if the #6945 guard is removed. * test(session): isolate automatic resume replay coverage * test(session): assert resumed tab identity stays stable
stablyai#10057) * test(session): guard against workspace-reopen tab fork-bomb (STA-1111) Relates to STA-1111 (already fixed on main by stablyai#6945). The runaway-tab-on-reopen bug was fixed by stablyai#6945 (activeOrQueuedResumeClaimsProviderSession dedup guard) hours before the ticket was filed. Verified: disabling that guard makes tab count climb 1->2->3->4 across reopens; restoring it holds at 1. This adds a revert-sensitive regression test covering the created-agent and sleeping-resume reopen paths so it cannot regress. Test plan: 2 new tests pass; fail if the stablyai#6945 guard is removed. * test(session): isolate automatic resume replay coverage * test(session): assert resumed tab identity stays stable
Summary
Prevents repeated automatic recovery of the same sleeping Codex provider session from creating a new terminal tab on every workspace activation. A valid stranded session can still recover once, but exact same-session replays are cleared while that resume is queued, starting, or live.
This does not change explicit user-triggered session-history / AI Vault resumes; users can still intentionally open multiple tabs from those surfaces.
Design approach
The regression was traced to #6800's stale-terminal recovery path: activation could treat a replayed sleeping-session record as recoverable again after the first recovery tab had already been queued. The fix adds runtime-only automatic resume claims keyed by tab id, and also stores provider-session metadata on automatic resume startup payloads. Resume suppression is scoped by worktree, agent, tab membership, and provider-session key/id.
Runtime claims are intentionally not persisted or hydrated. They are cleaned when tabs close, when orphan terminal state is reconciled, and when worktrees are purged/deleted.
Review outcomes
Validation
a27278dbeconfirmed the bad queued command shape:codex --dangerously-bypass-approvals-and-sandbox resume '019f163b-c91b-72c3-9786-7b8d74ac7a3d'.skua @ brennanb2025/fix-workspace-new-taband exercised the replay path./tmp/orca-electron-evidence/resume-fork-fix-clean-baseline.png/tmp/orca-electron-evidence/resume-fork-fix-clean-after-validation.png/tmp/orca-electron-evidence-stage9/resume-recovery-before-activation.png/tmp/orca-electron-evidence-stage9/resume-recovery-after-activation.pngChecks
pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/resume-sleeping-agent-session.test.ts src/renderer/src/lib/resume-sleeping-agent-session-replay.test.ts src/renderer/src/store/slices/store-cascades.test.ts src/renderer/src/store/slices/worktrees.test.ts- 333 tests passedpnpm run typecheckpnpm run typecheck:webpnpm run lintpnpm exec oxlint ...pnpm exec oxfmt --check ...git diff --checkBoundaries and risks
main, where the catalog repair already existed. The final PR diff is scoped to the resume-tab fix.Post-PR stabilization
Whycomment and pushed a follow-up commit.main; after the merge, the PR diff is limited to the resume-tab files.verifycheck passed, and GitHub reports the PR as mergeable/clean.