Skip to content

Prevent repeated automatic agent resume tabs - #6945

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-workspace-new-tab
Jun 30, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-workspace-new-tab

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Design review completed clean after tightening the design around the startup-in-progress gap.
  • Completeness verification initially found a lifecycle cleanup gap; that was fixed and re-verified clean.
  • Headline behavior status: implemented.
  • Broad app consistency: desktop workspace activation, terminal recovery tabs, sleeping/live agent status, session-history resumes, hydration, and cleanup paths were compared. The PR fixes automatic activation replay while preserving Prevent sleeping agents from getting stranded in stale terminals #6800 stale-terminal recovery and explicit user resume behavior.
  • Perf audit: clean. The new O(N) checks run only during activation recovery, introduce no polling/subprocess churn, and avoid persistence bloat.
  • Code-review loop: 2 rounds. Final reviewers returned clean. Findings fixed included a stale live-status tab-membership guard and removal of an unused slice API.

Validation

  • Electron culprit reproduction on a27278dbe confirmed the bad queued command shape: codex --dangerously-bypass-approvals-and-sandbox resume '019f163b-c91b-72c3-9786-7b8d74ac7a3d'.
  • Electron validation on this branch verified app identity for skua @ brennanb2025/fix-workspace-new-tab and exercised the replay path.
  • Fixed-branch replay result: first automatic recovery launched 1 tab; queued replay launched 0; startup-in-progress replay launched 0; final tab count stayed stable; stale sleeping records were cleared; the runtime claim remained on the resumed tab.
  • Merge-confidence validation also clicked the visible workspace activation path in Electron and observed one restored terminal only.
  • Screenshot evidence captured locally:
    • /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.png

Checks

  • 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 passed
  • pnpm run typecheck
  • pnpm run typecheck:web
  • pnpm run lint
  • touched-file pnpm exec oxlint ...
  • touched-file pnpm exec oxfmt --check ...
  • git diff --check

Boundaries and risks

  • Full real daemon stale-session recreation with a live Codex provider was not manufactured; the validated path exercises the renderer/store recovery logic and exact provider-session command shape from the recording.
  • SSH/live remote behavior was not separately tested because the diff compares structured metadata and store state only, without changing remote command construction or runtime RPC contracts.
  • A transient localization lint failure was resolved by merging current main, where the catalog repair already existed. The final PR diff is scoped to the resume-tab fix.

Post-PR stabilization

  • Waited 8 minutes after PR creation, then reviewed checks and CodeRabbit.
  • Fixed CodeRabbit's actionable comment about shortening a Why comment and pushed a follow-up commit.
  • Waited 8 minutes after the follow-up push and rechecked CodeRabbit; the recent review reported no actionable comments.
  • Resolved merge conflicts by merging current main; after the merge, the PR diff is limited to the resume-tab files.
  • Waited again after the merge push. Final GitHub verify check passed, and GitHub reports the PR as mergeable/clean.

@ghost

ghost commented Jun 30, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 5 individual chapters for you:

Title
1 Define resume claim types and metadata
2 Update terminal store for resume claims
3 Implement replay protection logic
4 Manage claim lifecycle and cleanup
5 Verify replay protection with tests
Open in Stage

Chapters generated by Stage for commit 43b9f39 on Jun 30, 2026 10:13pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds automatic agent resume claims to terminal state, threads resumeProviderSession through worktree startup and sleeping-session resume flows, and updates cleanup logic for orphan terminals and removed worktrees. It also adds tests covering replay prevention and claim cleanup. Separately, it adds new localized strings for ephemeral VM and per-workspace environment UI, and replaces one hardcoded error message with a translated message.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preventing repeated automatic agent resume tabs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description is detailed and covers summary, design, validation, testing, risks, and follow-up, though it doesn’t fully mirror every template section.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/renderer/src/i18n/locales/zh.json (1)

660-662: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Inconsistent English copy between two ephemeralVmsDescription strings.

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.ephemeralVmsDescription entry (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 win

Consider 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 in providerSessionsMatch/activeOrQueuedResumeClaimsProviderSession becoming 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2c0ac2a and 56203ca.

📒 Files selected for processing (15)
  • 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
  • src/renderer/src/lib/resume-sleeping-agent-session-replay.test.ts
  • src/renderer/src/lib/resume-sleeping-agent-session.test.ts
  • src/renderer/src/lib/resume-sleeping-agent-session.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/store/slices/store-cascades.test.ts
  • src/renderer/src/store/slices/terminal-orphan-helpers.ts
  • src/renderer/src/store/slices/terminals.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts

Comment on lines +277 to +283
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
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Suggested change
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
@brennanb2025
brennanb2025 merged commit bcb381e into main Jun 30, 2026
1 check passed
@brennanb2025
brennanb2025 deleted the brennanb2025/fix-workspace-new-tab branch June 30, 2026 22:30
brennanb2025 added a commit that referenced this pull request Jul 24, 2026
#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
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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
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.

1 participant