Repository navigation
test(serve): pin zero duplicate agent resumes across headless serve desktop promotion - #12666
Conversation
…esktop promotion STA-1716 / #8457 acceptance criterion 6 asked for an automated regression over desktop exit + surviving daemon sessions + headless serve lock owner + a GUI activation attempt. The lifecycle fixes landed (#8646, #12212, #12574) but nothing asserted the outcome the incident was actually about: how many agents the promoted renderer resumes. The new test drives the real modules end to end — packaged serve takes the single-instance lock, a forced relaunch reaches its second-instance handler, the activation gate coalesces until the persistent provider settles, one window opens, and the renderer hydrating inside that process resumes zero agents both before and after its panes rebind the surviving daemon PTYs. settleServeDesktopActivation moves out of index.ts so the test exercises the production decision instead of mirroring it. Red evidence: reverting the hidden-pane ownership predicate to its pre-#12574 form launches 2 duplicate `codex resume` tabs; also zeroing the live-PTY check makes both hydration passes red; dropping the duplicate-serve argv guard opens a window for `--serve`; always marking the gate ready removes the fail-closed diagnostic; refusing to open a window drops both promotion assertions.
📝 WalkthroughWalkthroughServe startup now uses 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 (1)
src/renderer/src/lib/serve-desktop-promotion-session-continuity.test.ts (1)
175-206: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNarrow the
as nevercast so the seeded store shape stays type-checked.Line 202 casts the whole seeded object to
never. That disables type checking for every key in this literal, includingterminalLayoutsByTabIdandptyIdsByTabId.makeTerminalTabat Line 139 returnsRecord<string, unknown>, which forces the outer cast.The risk is a silently vacuous test.
expectNoAgentWasResumedverifiestabsByWorktreeandsleepingAgentSessionsByPaneKey, so a rename in those two keys fails the test. It does not verifyptyIdsByTabIdorterminalLayoutsByTabId. Those two keys are the only difference between thereattached: falseandreattached: truecases. If either key is renamed in the store, thereattachedparameter becomes a no-op, both hydration tests still report0resumes, and the regression coverage disappears without a failure.Replace the cast with a partial store type so a renamed key breaks the build.
♻️ Proposed change to keep the seeded keys type-checked
-function makeTerminalTab(id: string): Record<string, unknown> { +type AppStoreState = ReturnType<typeof useAppStore.getState> +type TerminalTab = AppStoreState['tabsByWorktree'][string][number] + +function makeTerminalTab(id: string): TerminalTab { return { id, ptyId: null, worktreeId: WORKTREE_ID, title: 'codex', customTitle: null, color: null, sortOrder: 0, createdAt: 1 - } + } as TerminalTab }sleepingAgentSessionsByPaneKey: Object.fromEntries( records.map((record) => [record.paneKey, record]) ) - } as never, + } satisfies Partial<AppStoreState> as Partial<AppStoreState>, false )
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 616bc9f6-a0c8-4bf3-8907-51aaad0d2b45
📒 Files selected for processing (5)
config/reliability-gates.jsoncconfig/tsconfig.tc.web.jsonsrc/main/index.tssrc/main/startup/serve-desktop-activation.tssrc/renderer/src/lib/serve-desktop-promotion-session-continuity.test.ts
| { | ||
| "date": "2026-08-05", | ||
| "runner": "local", | ||
| "platform": "macos", | ||
| "command": "pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/serve-desktop-promotion-session-continuity.test.ts", | ||
| "result": "passed", | ||
| "durationSeconds": 2, | ||
| "summary": "Six tests passed joining the serve lock owner, the activation gate, and the promoted renderer's resume accounting. Red evidence: reverting the hidden-pane ownership predicate launched two duplicate codex resume tabs; additionally zeroing the live-PTY check made both hydration passes red; removing the duplicate-serve argv guard opened a window for `--serve`; always marking the gate ready removed the fail-closed diagnostic; refusing to open a window dropped both promotion assertions." | ||
| }, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Advance the manifest updatedAt to cover the new evidence-run date.
Line 988 records "date": "2026-08-05". Line 3 still declares "updatedAt": "2026-08-04". Every other evidence run in this manifest is dated on or before 2026-08-04, so updatedAt currently reads as the high-water mark for recorded evidence. This change breaks that property.
Set updatedAt to 2026-08-05.
🛠️ Proposed fix
"schemaVersion": 1,
- "updatedAt": "2026-08-04",
+ "updatedAt": "2026-08-05",
"policy": {…esktop promotion (stablyai#12666) STA-1716 reported that a packaged `orca serve` could become the single-instance owner after the desktop app exits, leaving Dock/Finder unable to restore a window — and that forcing a reopen made the headless process hydrate a renderer that interrupted and DUPLICATED live agent sessions. Verification against main found every criterion already fixed (stablyai#8646 for desktop promotion and the fail-closed CLI, stablyai#12212 for duplicate serve activation, stablyai#12574 + stablyai#9729 for the resume/ownership guards). The genuine gap was criterion 6: the ticket's own automated regression never existed. An existing reliability gate asserted PTY identity survives promotion, but nothing asserted what the incident was actually about — how many agents the promoted renderer resumes. This adds that coverage: a unit/service-level journey that drives the real single-instance lock, activation gate, settle and focus paths, then runs the real resume logic against a store seeded as a renderer freshly mounted inside the serve process, asserting zero duplicate resumes. `settleServeDesktopActivation` moved from `index.ts` into its own module with identical semantics, so the test drives the real decision rather than re-implementing it — the earlier repro had to mirror that logic locally, which is the "test passes without running the scenario" failure mode. Proven to be a real oracle: breaking each guard individually turns it red, and reverting the pre-stablyai#12574 pane form reproduces the incident exactly (two duplicate `codex resume` tabs).
Closes STA-1716 (#8457) acceptance criterion 6.
Description
STA-1716 / #8457 reported that a packaged
orca servecan own the single-instance lock after the desktop app quits with Cmd+Q, so a forced relaunch (open -n -a Orca) mounts a renderer inside the headless process, and hydration cold-restores panes whose daemon PTYs are still alive — launching duplicatecodex resume <session>agents and printingConversation interruptedin the surviving ones.The lifecycle fixes have all landed: #8646 built the supported headless-to-desktop handoff (activation gate,
orca openwaiting for a real window, fail-closed when the persistent provider is missing), #12212 stopped a duplicateorca servefrom dragging the headless owner into the foreground, and #12574 stopped hidden restorable panes from being forked into replacement resume tabs. What was missing is the assertion the incident was actually about: how many agents the promoted renderer resumes. The existing gate covers PTY identity across promotion; nothing covered resume accounting.This PR adds that regression and registers it in the
#8457reliability gate.settleServeDesktopActivationmoves fromsrc/main/index.tsintosrc/main/startup/serve-desktop-activation.tsso the test exercises the production decision instead of re-implementing it — the prior repro test for this issue had to mirror it, which is exactly the failure mode where a test passes without the scenario running.Evidence
pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/lib/serve-desktop-promotion-session-continuity.test.ts— 6 passed.The test drives the real modules in sequence:
shouldSkipSingleInstanceLock/shouldBypassSingleInstanceLock(packaged serve keeps the lock),acquireSingleInstanceLock+shouldActivateDesktopForSecondInstance(the relaunch reaches the headless owner'ssecond-instancehandler),createServeDesktopActivationGate+settleServeDesktopActivation(coalesce until the persistent provider settles),focusExistingMainWindow(exactly one window is constructed), thenresumeSleepingAgentSessionsForWorktreeagainst the real app store seeded as a renderer freshly mounted inside that process — three survivingcodexagent panes on one worktree, only one of them the visible tab.Oracle: zero launches, no new tab, no queued startup command, no automatic-resume claim, and every surviving session record left identity-equal. Asserted both before the panes rebind their PTYs (cold hydration) and after (live PTY map populated).
Each guard was broken to confirm the test is real, then restored:
paneWillConnectOnActivationback to its pre-#12574 visible-tab formcodex resumetabsstablePaneHasLivePtyforced to see no live PTYsshouldActivateDesktopForSecondInstancealways true--servesettleServeDesktopActivationalways marking readyfocusExistingMainWindowrefusing to openAlso green:
src/main/startup,src/main/window,src/main/runtime/orca-runtime.test.ts,src/cli/runtime-client.test.ts, and theresume-sleeping-agent-session/wake-sleeping-agents-in-backgroundsuites — 59 files, 1562 tests. Typecheck (node + cli + web), oxlint, changed-code quality audit, andcheck:reliability-gatesall pass.ELI5
When you quit Orca with Cmd+Q, a background
orca servecan be left holding the door. Reopening Orca used to walk in through that background process and accidentally start fresh copies of agents that were still running, cutting off the originals mid-sentence. That's fixed. This PR adds the alarm that goes off if anyone breaks it again: it walks the whole path — background server holds the lock, you force a reopen, a window appears — and then checks that exactly zero agents were restarted.User-regression-tradeoffs
Test-only behavior change. The one production edit moves a four-line decision out of
index.tsinto the module it already belongs to, with identical semantics (hasPersistentPtyProvideris the negation of the previousinstanceof LocalPtyProvidercheck);src/main/startup/serve-desktop-activation-wiring.test.tsstill pins the call site and its ordering.config/tsconfig.tc.web.jsongains five explicit main-process file entries because it is a composite project and the test imports those pure lifecycle modules — same pattern already used there forsrc/main/wsl.tsand friends.