Repository navigation
fix(pi): settle OMP status from the agent-end contract - #15658
brennanb2025 wants to merge 5 commits into
Conversation
📝 WalkthroughWalkthroughThe changes add a shared agent-status test harness and OMP lifecycle handling. OMP continuation events post 🚥 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: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3a0de56b-a047-4047-8afd-22fa669b5a38
📒 Files selected for processing (9)
src/main/pi/agent-status-extension-omp-lifecycle.test.tssrc/main/pi/agent-status-extension-source.test.tssrc/main/pi/agent-status-extension-test-harness.tssrc/main/pi/agent-status-handler-source.tssrc/main/runtime/command-finished-launch-authority.test.tssrc/main/runtime/command-finished-launch-authority.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/shared/agent-hook-listener-pi-compatible.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.
a89160c to
2a593b6
Compare
Review statusRebased onto current Follow-up pushed as
No other product changes. CodeRabbit’s fire-and-forget unhandled-rejection note is not a proven crash ( Landing order vs #15713This PR should land first. #15713 is the other half of the OMP work (identity + ask/approval forwarding), is CI-red, and explicitly does not own
TestsFocused ElectronIsolated-profile CDP launch of this branch ( Empty isolated profile: Workspace open (idle sidebar + Terminal 1 + Agents history): |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/main/runtime/orca-runtime.ts (1)
35592-35656: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftScope
acquisition.timedOutto timed callers.When the idle probe uses the direct provider-tail fallback, a slow capture can set the shared acquisition’s
timedOutflag after 750 ms. A concurrent caller withoutwait.timeoutMsthen returnsnullinstead of awaiting the same provider promise. Checktypeof wait.timeoutMs !== 'number'before checkingacquisition.timedOut. The visible-state fallback does not propagateretireOnTimeout, so this affects the direct provider-tail path.src/main/runtime/orca-runtime.test.ts (1)
20817-20823: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy liftRetire timed-out provider acquisitions
serializeProviderTerminalBufferkeeps timed-out acquisitions cached until the original promise settles. IfserializeProviderBuffernever settles, laterreadTerminalcalls return empty fallback data and never start a new serialization. Remove the acquisition on timeout or allow a replacement, then assert that a resolved follow-up snapshot restorestail.
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.test.ts (1)
13216-13250: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the repeated runtime setup for these authority tests.
The three new tests repeat the same
OrcaRuntimeServiceconstruction, the 12-method notifier mock, and the terminal creation. Only the pty id, the tab id, and the foreground-process value change. Extract a local factory such ascreateLaunchAuthorityRuntime({ ptyId, tabId, foregroundProcess })in this file. Do not name ithelpersorutils, per the naming guideline.As per coding guidelines: "Do not use vague names such as
helpers,utils,common,misc, orshared-stufffor files, folders, or modules; use concrete domain-oriented names instead."Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7f9578c8-740e-4141-a7b3-cf90a9012714
📒 Files selected for processing (2)
src/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
|
Codex revision complete. What changed:
What I kept:
Verification:
|
OMP never idles in ctx.isIdle() and has no agent_settled hook, so Orca's idle-recheck left the sidebar running after a finished turn. Honor willContinue for configured and runtime-routed OMP, and keep leaked nested-shell OSC 133;D from retiring hook authority while the execution host still shows the agent in the foreground. Fixes #14879 STA-4521 Co-authored-by: Bing.Z <[email protected]>
…neration entry The command-finished guard required a shell in SHELL_NAMES, so a user on ksh/dash/tcsh/csh/ash/elvish/xonsh could never settle launched-agent hook authority until the pty itself exited. Those are bare shells for every consumer of the predicate, so widening the set is the correct scope. The settle-generation Map also kept one entry per abnormally-exited SSH pty: that branch preserves launch authority by design (unverifiable, not exited), but the counter is bookkeeping for a check that can no longer land.
Pruning can remove a PTY without onPtyExit, so the settle-generation Map leaked one entry per disconnected record. Pin overlapping 133;D so a stale shell-foreground read cannot retire a later nested settle.
299da64 to
eb278f7
Compare
|
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)
14001-14135: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winRetire every pane-key authority before setting
hookAuthorityAlreadyRetired.
AgentHookServerstores authority independently per pane key. A PTY can be rebound while the deferred attempt waits, but the attempt captures and retires only its initial pane key. Since the current-state check does not fencepaneKey, the rebind can leave authority active while the fullpaneKeysretirement loop is skipped. Capture and retire every current pane-key receipt, or sethookAuthorityAlreadyRetiredonly after all keys are retired.
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.test.ts (1)
13626-13635: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace the fixed microtask flush with a deterministic flush.
await Promise.resolve()twice assumes an exact number of microtask ticks betweenforeground.resolve(...)and the continuation afterawait this.ptyController?.confirmForegroundProcess?.(ptyId)inmaybeRetireLaunchAuthorityAfterCommandFinished. The assertions that follow check that authority is unchanged. If the continuation has not resumed yet, the assertion passes for the wrong reason, so the fence under test is never exercised.The same pattern appears at Lines 13445-13448, 13487-13490, 13538-13541, 13581-13583, and 13667-13669.
Use
await vi.advanceTimersByTimeAsync(0)inside the fake-timer block, which drains pending microtasks and timers, instead of counting ticks.♻️ Proposed change for the ABA test
firstForeground.resolve('zsh') - await Promise.resolve() - await Promise.resolve() + await vi.advanceTimersByTimeAsync(0) expect( harness.runtime.getOrchestrationDispatchAuthority(replacement.handle)?.launchTokenHash ).toBe(replacementAuthority.launchTokenHash) secondForeground.resolve('omp') - await Promise.resolve() - await Promise.resolve() + await vi.advanceTimersByTimeAsync(0)
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 14c61652-88a3-4945-b7f5-bf4c80cdbd97
📒 Files selected for processing (26)
src/main/agent-hooks/server-authority-evidence.test.tssrc/main/agent-hooks/server-pane-authority.test.tssrc/main/agent-hooks/server.tssrc/main/daemon/daemon-foreground-confirmation-protocol.test.tssrc/main/daemon/daemon-protocol-version.test.tssrc/main/daemon/daemon-protocol-version.tssrc/main/daemon/daemon-pty-adapter-protocol-compatibility.test.tssrc/main/daemon/daemon-pty-adapter.tssrc/main/daemon/session.test.tssrc/main/daemon/session.tssrc/main/daemon/types.tssrc/main/index.tssrc/main/ipc/pty-runtime-kill-and-exit.test.tssrc/main/pi/agent-status-extension-omp-lifecycle.test.tssrc/main/pi/agent-status-extension-source.test.tssrc/main/pi/agent-status-extension-test-harness.tssrc/main/pi/agent-status-handler-source.tssrc/main/providers/ssh-pty-provider.test.tssrc/main/providers/ssh-pty-provider.tssrc/main/runtime/command-finished-launch-authority.test.tssrc/main/runtime/command-finished-launch-authority.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/shared/agent-hook-listener-pi-compatible.test.tssrc/shared/shell-process-detection.test.tssrc/shared/shell-process-detection.ts
🚧 Files skipped from review as they are similar to previous changes (8)
- src/main/pi/agent-status-extension-omp-lifecycle.test.ts
- src/main/pi/agent-status-extension-test-harness.ts
- src/shared/shell-process-detection.ts
- src/main/pi/agent-status-extension-source.test.ts
- src/shared/agent-hook-listener-pi-compatible.test.ts
- src/main/pi/agent-status-handler-source.ts
- src/main/runtime/command-finished-launch-authority.ts
- src/main/runtime/command-finished-launch-authority.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
| if (restored || fence) { | ||
| this.markPaneAuthorityAbsent(ownerPaneKey) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Invalidate the stable-pane receipt after alias restoration.
When restorePaneAuthority(SOURCE) restores a retired SOURCE -> TARGET alias, ownerPaneKey still equals SOURCE. Line 2090 records a new receipt for SOURCE, but later captures resolve SOURCE to TARGET and retain the old retirement receipt for TARGET.
A delayed overlapping 133;D callback can then match that old receipt and retire the reattached pane. Re-resolve the pane key after restoreRetiredPaneFence, then record the absent receipt for the restored owner. Add an alias restoration race test.
Proposed fix
if (restored || fence) {
- this.markPaneAuthorityAbsent(ownerPaneKey)
+ this.markPaneAuthorityAbsent(this.resolvePaneKeyAlias(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 (restored || fence) { | |
| this.markPaneAuthorityAbsent(ownerPaneKey) | |
| } | |
| if (restored || fence) { | |
| this.markPaneAuthorityAbsent(this.resolvePaneKeyAlias(paneKey)) | |
| } |
OMP exposes no agent_settled hook and ctx.isIdle() can stay false after a finished turn, so Orca's idle-recheck loop backed off and spun forever and the pane stayed "working" indefinitely. OMP instead marks non-terminal agent_end events with willContinue; honor that for configured and runtime-routed OMP and treat an absent flag as terminal. Extracted from #15658, which bundles this with a launch-authority change that conflicts with in-flight #17077. Only the settle half lands here. STA-4130 Co-authored-by: Bing.Z <[email protected]>
OMP exposes no agent_settled hook and ctx.isIdle() can stay false after a finished turn, so Orca's idle-recheck loop backed off and spun forever and the pane stayed "working" indefinitely. OMP instead marks non-terminal agent_end events with willContinue; honor that for configured and runtime-routed OMP and treat an absent flag as terminal. Extracted from #15658, which bundles this with a launch-authority change that conflicts with in-flight #17077. Only the settle half lands here. STA-4130 Co-authored-by: Bing.Z <[email protected]>
* fix(pi): settle OMP status from the agent_end contract OMP exposes no agent_settled hook and ctx.isIdle() can stay false after a finished turn, so Orca's idle-recheck loop backed off and spun forever and the pane stayed "working" indefinitely. OMP instead marks non-terminal agent_end events with willContinue; honor that for configured and runtime-routed OMP and treat an absent flag as terminal. Extracted from #15658, which bundles this with a launch-authority change that conflicts with in-flight #17077. Only the settle half lands here. STA-4130 Co-authored-by: Bing.Z <[email protected]> * fix(pi): preserve non-terminal continuation guards Keep the base Pi and Prime willContinue guard while settling terminal OMP events directly. Add regression coverage so sibling runtimes cannot publish a false completion after conflict resolution. --------- Co-authored-by: Bing.Z <[email protected]> Co-authored-by: Merge Sim <sim@local>
* fix(pi): settle OMP status from the agent_end contract OMP exposes no agent_settled hook and ctx.isIdle() can stay false after a finished turn, so Orca's idle-recheck loop backed off and spun forever and the pane stayed "working" indefinitely. OMP instead marks non-terminal agent_end events with willContinue; honor that for configured and runtime-routed OMP and treat an absent flag as terminal. Extracted from stablyai#15658, which bundles this with a launch-authority change that conflicts with in-flight stablyai#17077. Only the settle half lands here. STA-4130 Co-authored-by: Bing.Z <[email protected]> * fix(pi): preserve non-terminal continuation guards Keep the base Pi and Prime willContinue guard while settling terminal OMP events directly. Add regression coverage so sibling runtimes cannot publish a false completion after conflict resolution. --------- Co-authored-by: Bing.Z <[email protected]> Co-authored-by: Merge Sim <sim@local>


ELI5
When an OMP agent finishes a turn, the Orca sidebar could keep showing it as running. Orca was waiting for OMP to say "I'm idle now" — a signal OMP never sends. OMP instead tells you on every
agent_endwhether it is about to keep going. This PR listens to that: still going → stay working; done → settle immediately. It also stops a nested bash tool's "command finished" marker from making Orca think the OMP process itself has exited.What Changed
agent_endhandler branches for OMP runtimes (configured and runtime-routed from a Pi-kind pane):willContinue === truekeeps the pane working and arms no idle-recheck timer; anything else posts the terminalagent_endimmediately without consultingctx.isIdle().agent_settled/ idle-recheck path.133;Dno longer retires launched-agent hook authority until the execution host confirms a shell is in the foreground. A recognized agent (including OMP) stays live; a missing/failed process read isunverifiable, notexited.Why
OMP's
agent_endpayload documentswillContinue?: boolean:truemeans an automatic continuation is scheduled; any other value is terminal. OMP does not exposeagent_settled, andctx.isIdle()can stay false after a finished turn, so the idle-recheck loop never posted done.That contract alone is necessary but not sufficient. Full-screen agents leak nested-shell OSC
133;Donto the main PTY. Orca treated every133;Das "the launched agent command exited" and retired hook authority, so a later realagent_endreturned HTTP 204 and was silently suppressed. The renderer already confirms foreground before trusting133;D; main now does the same, and an unverifiable read cannot retire a live pane.Linked Issue
Fixes #14879
Fixes STA-4521
Also covers the stuck-at-working completion path of #14278 / STA-4130 (same
willContinueroot).Supersedes #14884. Thanks to @bbingz — the
willContinuehandler and configured/runtime-routed split are carried forward (Co-authored-by). This PR differs from #14884 in:process.argvpointing atomp), not onlyprocess.title.agent_startthen terminalagent_end) driving the posted status sequence to done, not an isolatedagent_endpost.max-linesbudget instead of growing the existing 700-line file.133;Dno longer retires hook authority while the execution host still shows OMP in the foreground — the path that made awillContinue-only change insufficient in live testing.unverifiable, not agent exit, so SSH blips cannot retire a live OMP pane.Visual Proof
N/A — generated extension + main-process launch-authority logic. The only user-visible effect is the existing sidebar/tab running indicator settling to idle after a completed OMP turn; that transition is asserted at the hook and runtime seams. A live OMP turn was not driven in Electron in this pass (OMP 17.0.5 is installed locally; the reporter's stuck state is on 1.4.185 with a completed TUI at
π > …).Testing
TDD on the OMP contract (
src/main/pi/agent-status-extension-omp-lifecycle.test.ts):isIdle()was true; final events with non-idle context never posted done)isOmpRuntimebranch removed, tests kept)Also:
pnpm vitest run --config config/vitest.config.ts src/main/pi— 4 files, 70/70 passedpnpm vitest run --config config/vitest.config.ts src/main/runtime/command-finished-launch-authority.test.ts src/shared/agent-hook-listener-pi-compatible.test.ts— passedorca-runtime.test.tscases for shell-foreground retire, OMP-foreground keep, unverifiable keep, and restored-receipt retire — passedpnpm typecheck— passedoxlint --deny-warningson changed files — cleanoxfmton changed files only — cleanFull
pnpm lint/pnpm test/pnpm buildleft to CI.Review
willContinueis a strict=== truecheck on an in-process extension event. Foreground confirmation uses the existing execution-host PTY APIs.recognizeAgentProcess/isShellProcess(Windows.execovered).ptyControlleron the execution host. A failed/null read does not retire authority (unverifiable, notexited). PTY exit still retires immediately when the host confirms the process is gone.agent_endis what it already understands as done.willContinuesettle as terminal (fail-open to done). Pi and Prime paths are unchanged. No wire/RPC/stream opcode changes.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Author
Out of scope (file separately)
$$<hash>:L$$pane keys never reach the hook pipeline. Distinct from this event-contract / 133;D root.π :/π >/π !title classification. Distinct.askprompt payload,tool_approval_*forwarding, Pi/OMP title-identity oscillation) — not the stuck-running indicator. Covered by fix(agents): settle and surface the OMP terminal lifecycle (#14278) #14605.