Repository navigation
fix(orchestration): wake coordinators with mail pointers - #12988
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe runtime now routes orchestration messages from 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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: 2
🧹 Nitpick comments (6)
tests/e2e/orchestration-idle-mail-delivery.spec.ts (2)
244-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace the
expect.poll(...).toBe('pending')wrappers with direct assertions.
expect.pollreturns on the first matching read. The row is alreadypendingat this point, so the poll settles immediately and adds no waiting. The file states this exact caveat at lines 209-213. The precedingexpectPointedandexpectSubmittedcalls already supply the time barrier. The same pattern appears at lines 269-273 and 361-365.♻️ Proposed change
- await expect - .poll(() => mailDisposition(readMailRow(userDataDir, messageId)), { - timeout: DELIVERY_TIMEOUT_MS - }) - .toBe('pending') + expect(mailDisposition(readMailRow(userDataDir, messageId))).toBe('pending')
347-355: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueThe 1s settle can make this test pass for the wrong reason.
If the
worker_donewaiter is not registered before line 358 sends the message, the push happens because no waiter existed at all, not because the waiter filtered the type out. The test still passes. The sibling test at line 300 fails loudly in the same situation, so only this one is affected. If the runtime exposes waiter state, poll for the registration instead of the fixed wait.tests/e2e/orchestration-idle-mail-restore.spec.ts (1)
48-74: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winBoth specs copy the same runtime-polling helpers. The shared root cause is that no module holds the runtime title and worktree polling used by both new specs, so each spec redefines them. The two copies can drift as the runtime contract changes.
tests/e2e/orchestration-idle-mail-restore.spec.ts#L48-L74: movewaitForRegisteredWorktreeandwaitForObservedTitleinto a shared module, for exampletests/e2e/helpers/orchestration-mail-runtime-wait.ts, and import them here along withPOINTER_COMMANDandDELIVERY_TIMEOUT_MS.tests/e2e/orchestration-idle-mail-delivery.spec.ts#L139-L154: delete the localwaitForObservedTitleand the inline worktree poll at lines 104-112, and import the shared versions instead.tests/e2e/helpers/orchestration-mail-store.ts (1)
23-30: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winOpen read paths read-only and set a busy timeout.
withMailDbopensorchestration.dbread-write without a timeout while the main process can write it.SyncDatabasesupportsreadonlyandtimeout; use{ readonly: true, timeout: 5000 }forreadMailRow/readMailbox, and only make the write path fromstartCoordinatorRunuse{ readonly: false, timeout: 5000 }.src/main/runtime/orca-runtime.test.ts (1)
33465-33476: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAssert an exact leaf count before indexing.
The test reads
[...leaves.values()][0]but only checkssize > 0. If the map ever contains more than the republished leaf, the assertions target an arbitrary record and the fence regression is not detected. Pin the count.♻️ Proposed tightening
- expect(leaves.size).toBeGreaterThan(0) + expect(leaves.size).toBe(1) const rebuilt = [...leaves.values()][0]src/main/runtime/rpc/methods/orchestration.test.ts (1)
313-313: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the delivered handle, not just the call.
toHaveBeenCalled()passes for any argument. The routing contract this PR changes is which mailboxsendnotifies. If the handler ever passed the sender handle instead of the recipient handle, this assertion would still pass. Pin the argument to the recipient handle used in this test's setup.expect(runtime.deliverPendingMessagesForHandle).toHaveBeenCalledWith(<recipient handle>)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7bdbbd78-88b7-4e3e-9b32-d349a2dbd2a5
📥 Commits
Reviewing files that changed from the base of the PR and between 7e60b33 and 460424a94b8699bf4557eaf139eb5f39171feebc.
📒 Files selected for processing (10)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/orchestration/formatter.test.tssrc/main/runtime/orchestration/formatter.tssrc/main/runtime/rpc/methods/orchestration.test.tssrc/main/runtime/terminal-send-stale-leaf-liveness.test.tstests/e2e/helpers/orchestration-mail-pane-agent.tstests/e2e/helpers/orchestration-mail-store.tstests/e2e/orchestration-idle-mail-delivery.spec.tstests/e2e/orchestration-idle-mail-restore.spec.ts
| } finally { | ||
| if (firstApp) { | ||
| await session.close(firstApp) | ||
| } | ||
| if (secondApp) { | ||
| await session.close(secondApp) | ||
| } | ||
| await session.dispose() | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
A failing close skips the remaining cleanup.
If session.close(firstApp) rejects, lines 181-184 never run. session.dispose() is then skipped, and per tests/e2e/helpers/orca-restart.ts that call performs cleanupE2EDaemons and removes the profile directory. Leftover daemons and temp profiles can affect later specs in this worker. Isolate each close so dispose() always runs.
🛡️ Proposed fix
} finally {
- if (firstApp) {
- await session.close(firstApp)
- }
- if (secondApp) {
- await session.close(secondApp)
- }
- await session.dispose()
+ for (const app of [firstApp, secondApp]) {
+ if (!app) continue
+ try {
+ await session.close(app)
+ } catch (error) {
+ console.warn('[e2e] failed to close Electron app', error)
+ }
+ }
+ await session.dispose()
}📝 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.
| } finally { | |
| if (firstApp) { | |
| await session.close(firstApp) | |
| } | |
| if (secondApp) { | |
| await session.close(secondApp) | |
| } | |
| await session.dispose() | |
| } | |
| } finally { | |
| for (const app of [firstApp, secondApp]) { | |
| if (!app) continue | |
| try { | |
| await session.close(app) | |
| } catch (error) { | |
| console.warn('[e2e] failed to close Electron app', error) | |
| } | |
| } | |
| await session.dispose() | |
| } |
|
Follow-up from the requested real Codex smoke test: The smoke test exposed a genuine runtime bug, not a reproduction-only failure. After synthetic Commit Post-fix verification:
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1974953d-bd07-4f9f-bb92-74e1d9edc0ee
📥 Commits
Reviewing files that changed from the base of the PR and between 460424a94b8699bf4557eaf139eb5f39171feebc and d21b68675b356acd248df804e972077d64f9c0a7.
📒 Files selected for processing (4)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/shared/agent-title-status.tssrc/shared/terminal-output-side-effects.ts
| const restoredStatus = this.ptyTitleTrackersByPtyId | ||
| .get(ptyId) | ||
| ?.tracker.restoreLastAgentExit() | ||
| if (restoredStatus !== null && restoredStatus !== undefined) { | ||
| current.lastAgentStatus = restoredStatus | ||
| for (const leaf of this.getLeavesForPty(ptyId)) { | ||
| if (leaf.lastAgentStatus !== null) { | ||
| continue | ||
| } | ||
| // Why: the foreground agent disproved the neutral title's exit signal; keep runtime delivery state aligned with the restored tracker. | ||
| leaf.lastAgentStatus = restoredStatus | ||
| if (restoredStatus === 'idle') { | ||
| this.deliverPendingMessagesForLeaf(leaf) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Restore path skips resolving tui-idle waiters.
When restoredStatus is 'idle', this branch restores leaf.lastAgentStatus from null to 'idle' and delivers pending mail via deliverPendingMessagesForLeaf. Elsewhere, an equivalent null→idle transition (applyTrackedPtyTitle, around line 10313) also calls this.resolveTuiIdleWaiters(leaf) (and resolvePtyTuiIdleWaiters for the PTY record). This restore branch does not.
A caller blocked on terminal.wait --for tui-idle for this pane stays blocked even though the agent's idle status is confirmed here, until an unrelated future title change happens to trigger the resolution path.
🐛 Proposed fix to resolve tui-idle waiters on restore
if (restoredStatus !== null && restoredStatus !== undefined) {
current.lastAgentStatus = restoredStatus
+ if (restoredStatus === 'idle') {
+ this.resolvePtyTuiIdleWaiters(current, ptyId)
+ }
for (const leaf of this.getLeavesForPty(ptyId)) {
if (leaf.lastAgentStatus !== null) {
continue
}
// Why: the foreground agent disproved the neutral title's exit signal; keep runtime delivery state aligned with the restored tracker.
leaf.lastAgentStatus = restoredStatus
if (restoredStatus === 'idle') {
+ this.resolveTuiIdleWaiters(leaf)
this.deliverPendingMessagesForLeaf(leaf)
}
}
}📝 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.
| const restoredStatus = this.ptyTitleTrackersByPtyId | |
| .get(ptyId) | |
| ?.tracker.restoreLastAgentExit() | |
| if (restoredStatus !== null && restoredStatus !== undefined) { | |
| current.lastAgentStatus = restoredStatus | |
| for (const leaf of this.getLeavesForPty(ptyId)) { | |
| if (leaf.lastAgentStatus !== null) { | |
| continue | |
| } | |
| // Why: the foreground agent disproved the neutral title's exit signal; keep runtime delivery state aligned with the restored tracker. | |
| leaf.lastAgentStatus = restoredStatus | |
| if (restoredStatus === 'idle') { | |
| this.deliverPendingMessagesForLeaf(leaf) | |
| } | |
| } | |
| } | |
| const restoredStatus = this.ptyTitleTrackersByPtyId | |
| .get(ptyId) | |
| ?.tracker.restoreLastAgentExit() | |
| if (restoredStatus !== null && restoredStatus !== undefined) { | |
| current.lastAgentStatus = restoredStatus | |
| if (restoredStatus === 'idle') { | |
| this.resolvePtyTuiIdleWaiters(current, ptyId) | |
| } | |
| for (const leaf of this.getLeavesForPty(ptyId)) { | |
| if (leaf.lastAgentStatus !== null) { | |
| continue | |
| } | |
| // Why: the foreground agent disproved the neutral title's exit signal; keep runtime delivery state aligned with the restored tracker. | |
| leaf.lastAgentStatus = restoredStatus | |
| if (restoredStatus === 'idle') { | |
| this.resolveTuiIdleWaiters(leaf) | |
| this.deliverPendingMessagesForLeaf(leaf) | |
| } | |
| } | |
| } |
d21b686 to
8bc659f
Compare
|
Rebased cleanly onto current |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
tests/e2e/orchestration-idle-mail-delivery.spec.ts (1)
179-188: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winPoll for both pointer fields in one stdin snapshot.
Line 187 performs a second stdin read after the command poll succeeds. If PTY output splits between those reads, the count assertion can fail. This reintroduces the previously reported test flake.
Proposed fix
async function expectPointed(pane: AgentPane, count = 1): Promise<void> { + const noun = count === 1 ? 'message' : 'messages' + const countPhrase = `${count} orchestration ${noun}` await expect - .poll(() => pane.agent.readStdin(), { - timeout: DELIVERY_TIMEOUT_MS, - message: 'mail pointer never reached the agent process' - }) - .toContain(POINTER_COMMAND) - const noun = count === 1 ? 'message' : 'messages' - expect(pane.agent.readStdin()).toContain(`${count} orchestration ${noun}`) + .poll(() => { + const stdin = pane.agent.readStdin() + return stdin.includes(POINTER_COMMAND) && stdin.includes(countPhrase) + }, { + timeout: DELIVERY_TIMEOUT_MS, + message: 'mail pointer never reached the agent process' + }) + .toBe(true) }
🧹 Nitpick comments (1)
tests/e2e/orchestration-idle-mail-delivery.spec.ts (1)
374-392: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy liftUse separate worker and coordinator panes.
Line 380 and Line 391 both use
pane.handle. Direct-recipient delivery and Run-coordinator routing therefore produce the same PTY result. Use a distinct worker pane and assert that only the coordinator pane receives and submits the pointer.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 804708d0-06ff-45ae-8da0-c097ff52a5de
📒 Files selected for processing (10)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/orchestration/formatter.test.tssrc/main/runtime/orchestration/formatter.tssrc/shared/agent-title-status.tssrc/shared/terminal-output-side-effects.tstests/e2e/helpers/orchestration-mail-pane-agent.tstests/e2e/helpers/orchestration-mail-store.tstests/e2e/orchestration-idle-mail-delivery.spec.tstests/e2e/orchestration-idle-mail-restore.spec.ts
🚧 Files skipped from review as they are similar to previous changes (8)
- src/shared/terminal-output-side-effects.ts
- src/main/runtime/orchestration/formatter.ts
- src/shared/agent-title-status.ts
- src/main/runtime/orchestration/formatter.test.ts
- tests/e2e/orchestration-idle-mail-restore.spec.ts
- tests/e2e/helpers/orchestration-mail-pane-agent.ts
- src/main/runtime/orca-runtime.test.ts
- src/main/runtime/orca-runtime.ts
| const checked = await client.call<{ messages: { id: string; body: string }[] }>( | ||
| 'orchestration.check', | ||
| { terminal: pane.handle, run: run.result.run.id } | ||
| ) | ||
| expect(checked.result.messages).toEqual([ | ||
| expect.objectContaining({ id: sent.result.message.id, body }) | ||
| ]) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Assert that orchestration.check consumes the mailbox row.
After orchestration.check returns, assert that mailDisposition(readMailRow(...)) becomes pulled. The current test proves retrieval but does not prove the required transition from pending unread mail to consumed mail.
|
Fixed the red Node 24/26 shard in Root cause: Verification:
|
) Wake idle Run coordinators with durable orchestration mail pointers while keeping message payloads in the store until check consumes them. Preserve waiter, Cursor, restart, real Codex title, and PTY replacement behavior.\n\nPart of stablyai#12953.
Summary
orca orchestration checkpointer instead of orchestration message payloadsrun:<id>mail through the modern Run's coordinator terminalcheckconsumes it and suppress duplicate pointers with an in-memory sequence watermarkPart of #12953 (Phase 1).
Verification
pnpm exec vitest run src/main/runtime/orca-runtime.test.ts src/main/runtime/orchestration/formatter.test.ts— 1093 passed, 1 skippedpnpm run typecheck:nodepnpm run lintpnpm exec electron-vite build --mode e2eSKIP_BUILD=1 npx playwright test tests/e2e/orchestration-idle-mail-delivery.spec.ts --config tests/playwright.config.ts --project=electron-headless --workers=1— 8 passed (1.1m)SKIP_BUILD=1 npx playwright test tests/e2e/orchestration-idle-mail-restore.spec.ts --config tests/playwright.config.ts --project=electron-headless --workers=1— 1 passed (12.6s)The Electron suite exercises a real pane/PTY path with a scriptable agent process, OSC status transitions, delayed Enter, and an stdin ledger.
A final API-backed Codex-to-Codex smoke test also passed. A real Codex worker sent
worker_donewith subjectfixed real-agent smoke complete; an already-idle real Codex coordinator received the pointer without a forced second turn, ranorca orchestration check, and verified the body named packageorca. The delivery was acknowledged and the worker released.Mutation checks
messagesmessageScreenshots
No visual change.
Security audit
No new external input, privilege boundary, persistence format, or wire protocol. The change reuses existing local PTY status and foreground-process evidence.
Notes
No RPC or remote-wire schema changes. The behavior applies to local, SSH, and folder-workspace PTYs through the existing runtime abstractions.