Repository navigation
fix(agents): settle and surface the OMP terminal lifecycle (#14278) - #14605
brennanb2025 wants to merge 1 commit into
Conversation
OMP never emits agent_settled and its ctx.isIdle can stay false through completion, so the generated status extension's idle recheck never fired and the pane stuck at "working". Settle on OMP's own agent_end contract instead: willContinue === true keeps the pane active, anything else is terminal. Also forward the approval lifecycle OMP suppresses unless an extension listens for it, publish the `ask` questions payload as a live prompt, and stop a generic Pi frame from downgrading a pane the hook already identified as OMP. Co-authored-by: Vlad Rafeev <[email protected]> Co-authored-by: outside.observer <[email protected]>
📝 WalkthroughWalkthroughThe change adds shared testing infrastructure for generated Pi, OMP, and Prime Agent extensions. OMP lifecycle handlers now report terminal completion and forward approval requests and resolutions. Shared state handling serializes question prompts and maps approval events to blocked and working states. Agent identity resolution preserves specific OMP identities when ownership uses a generic Pi identity. Tests cover lifecycle, approval, runtime exclusion, state transitions, and normalization. Merge Risk: ⚪ Minimal · up to The PR updates OMP lifecycle and status reporting, while the remaining suggestions are localized follow-ups with no concrete merge-blocking correctness, security, availability, or deployment risk. It is merge-ready after normal checks and review. 🚥 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.
🧹 Nitpick comments (3)
src/shared/agent-hook-listener.ts (1)
2101-2116: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winConsider publishing a structured approval payload for OMP approvals.
The existing
PermissionRequestpath at line 936 publishes{ approval: { tool, summary } }asinteractivePrompt, so clients can render an approval card. This OMP branch setsinteractivePrompt: undefinedand puts the reason intoolInput. The pane reads blocked, but no approval card appears. The producer also postsapproval_mode, which this extractor drops.Reuse the same envelope so both approval sources render identically.
src/main/pi/agent-status-extension-test-harness.ts (2)
182-184: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFail fast when the requested hook is not registered.
handlers[name]?.(...)resolves silently for an unknown name. If a generated hook name changes, specs such asagent-status-extension-omp-lifecycle.test.tsstill pass, because "no post" is the expected outcome in several cases. Throw for an unregistered name, and let specs that check absence readharness.handlersdirectly, as line 80 of that spec already does.♻️ Suggested change
callHook: async (name, event, hookContext) => { - await handlers[name]?.(event, hookContext) + const handler = handlers[name] + if (!handler) { + throw new Error(`no handler registered for hook: ${name}`) + } + await handler(event, hookContext) },
60-70: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReuse the exported kind type instead of repeating the union.
getPiAgentStatusExtensionSourcetakesPiAgentKind. This inline union duplicates that contract, so a new kind would not reach the harness signature. Import the type and use it forargs.kind.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: c5ca534d-5772-444b-ab05-af472cd70f40
📒 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/shared/agent-detection.test.tssrc/shared/agent-hook-listener.test.tssrc/shared/agent-hook-listener.tssrc/shared/agent-title-owner.tssrc/shared/synthetic-agent-title.ts
|
Superseded by #20603 (OMP terminal lifecycle settlement), which contains the current implementation and verification on . Closing this stale duplicate so review stays on the maintained PR. |
|
Superseded by #20603. |
ELI5
When an OMP agent finished a turn, the Orca sidebar could show that pane as "working" forever. Orca was waiting for OMP to say "I'm idle now" — a signal OMP never sends. OMP instead tells you on every turn-end whether it's about to keep going. Now Orca listens to that: still going → stay working; done → settle to done.
While in there, three more OMP states that were never reported are now reported: the pane goes to "action required" while OMP is parked on a tool-approval prompt, its clarifying-question card shows up live instead of only after the transcript loads, and a pane the hook already identified as OMP stops flipping its label back to Pi.
What Changed
Completion (
src/main/pi/agent-status-handler-source.ts)agent_endhandler branches for OMP runtimes:willContinue === truekeeps the pane active and arms no timer; anything else posts the terminalagent_endimmediately. Pi and Prime keep their existingagent_settled/ idle-recheck path untouched.tool_approval_requested/tool_approval_resolvedhandlers (guarded byisOmpRuntime(), omitted entirely for Prime, which has no OMP runtime).Reporting (
src/shared/agent-hook-listener.ts)tool_approval_requested→blockedcarrying the awaited tool name and the policy reason;tool_approval_resolved→ back toworkingwith that detail cleared. Both are OMP-gated.isPiCompatibleAskTool()predicate now drives both the blocked-state gate and the published prompt payload, so they can't drift (Pi names the toolAskUserQuestion, OMP names itask).askinput is published as the liveinteractivePrompt. Its input is already the canonical{ questions: [{ question, options: [{ label, description }] }] }shape, so the existingparseQuestionsShapeparser renders it with no new envelope and no tool-name aliasing. The JSON serialization used by both paths is factored intoserializeQuestionPrompt().Identity (
src/shared/synthetic-agent-title.ts,src/shared/agent-title-owner.ts)titleIdentityFallback: true— it is the generic member of thepi-compatibletitle group, and every member emits its frames.resolveCompatibleAgentTypeForOwnerstill lets the owner win, except when the owner is that generic identity and the incoming frame names a specific sibling. That is the oscillation described in the issue, fixed as profile data rather than a hardcodedompspecial case.Tests
agent-status-extension-test-harness.ts(matchingsrc/relay/agent-exec-handler-test-harness.tsandsrc/main/computer/desktop-script-provider-test-harness.ts), so the new OMP lifecycle specs get their own file instead of pushing the existing spec past themax-linesbudget. Nomax-linessuppression added; the ratchet is unchanged.Why
The idle-recheck loop in the generated extension encodes a Pi settle policy, and it was being applied to every Pi-compatible runtime. OMP has neither half of that policy, so the loop spun to its cap and gave up while the pane stayed at "working".
I verified OMP's contract against the installed OMP binary rather than assuming it:
agent_endis emitted as{ type: 'agent_end', messages, willContinue }, wherewillContinue: trueis set only on the paths that schedule an automatic continuation (compaction continuation, retry/fallback, unexpected-stop recovery, session-stop continuation). Every terminal path emits it absent.agent_settleddoes not exist in the binary at all.tool_approval_requested/tool_approval_resolvedcarry{ sessionId, toolName, toolCallId, reason?, approvalMode }and{ …, approved, reason? }, and OMP suppresses both unless an extension registers a handler — which is why they never reached Orca.asktool's declared parameters are the{ questions: [{ id, question, options: [{ label, description }], recommended }] }shape.OMP's own built-in notification bridge models the same lifecycle exactly this way —
agent_end→ return early ifwillContinue,tool_approval_requested→ permission pending,tool_approval_resolved→ permission replied — so this is the intended contract, not a workaround.Supersedes #14330 and #14279. Both consume
willContinueand both are right about the root cause; thanks to @dandaka and @devatnull, and their work is carried forward viaCo-authored-by. This PR differs from them in four ways:asktool name toask_user_questionto trickderiveInteractivePromptinto serializing the input. The parser already falls back to the canonical questions shape for any tool name, so no alias is needed — this calls the serializer directly and keeps one predicate for the state gate and the payload.if (incomingAgentType === 'omp' || ownerAgentType === 'omp') return 'omp'insideresolveCompatibleAgentTypeForOwner. TheownerAgentType === 'omp'half is unreachable (the function already returns the owner), and the specificity rule belongs in the title profile that defines the group. This models it astitleIdentityFallbackon the generic member instead.{ approval: { tool, summary } }interactive-prompt envelope for OMP approvals. That envelope drives the native-chat approval card, whose buttons write1(allow) andESC(deny) into the agent's TUI — a mapping derived from Claude's permission prompt. OMP prompts with a two-item["Approve", "Deny"]selector, and I could not verify from the binary that1/ESCcommit and deny correctly there, so this PR publishes the blocked approval state (which is what the issue asks for and what the sidebar needs) and deliberately does not synthesize a keystroke-sending card. Wiring the card with a verified OMP key mapping is a good follow-up.Linked Issue
Fixes #14278
Supersedes #14330 and #14279 (left open for the authors; not modified by this PR).
Visual Proof
N/A — no layout, copy, or component change. Everything here is main-process hook generation and status normalization; the user-visible effect is which status an existing sidebar row shows. The two states a reviewer would look for are already-existing renderings:
agent_endit already receives.blockedtreatment (OMP - action required).Both are asserted at the normalization seam rather than screenshotted, since the pixels are unchanged and only the state value differs. Reproducing the stuck-at-working state live needs an OMP session that hits a non-idle completion path, which I did not have a deterministic trigger for.
Testing
Each of the four behaviors is covered, and each test was proven to fail with only that part of the fix reverted:
willContinueabsent /false, configured + runtime-routed OMP)agent-status-extension-omp-lifecycle.test.tsagent_endbranch removedwillContinue: true, and no timer left armed)agent-hook-listener.test.ts→ "maps OMP ask to blocked and publishes its questions payload"agentKind === 'pi'agent-hook-listener.test.ts→ "blocks an OMP pane on a tool approval request and clears it on resolution"agent-detection.test.ts→ "keeps a live OMP identity from being downgraded by a generic Pi owner"titleIdentityFallbackremovedAlso asserted: Pi and Prime never post the approval events, and the listener returns
nullfor approval events from a non-OMP Pi-compatible agent.Commands run on macOS (arm64):
vitest run src/main/pi/ src/shared/agent-hook-listener.test.ts src/shared/agent-detection.test.ts— 279 passedvitest runover every suite importingagent-hook-listener/agent-title-owner/synthetic-agent-title(relay,src/main/agent-hooks, hook caches, subagent lifecycles) — 50 files, 714 passedvitest run src/renderer/src/components/native-chat src/shared/native-chat-*.test.ts— 76 files, 780 passed (the ask payload now reaches these parsers)oxlint,oxlint --config config/oxlint-code-quality-native-plugins.json,oxlint --type-aware --config config/oxlint-code-quality-type-aware.jsononsrc/main/pi+ the changedsrc/sharedfiles — cleanoxfmt --check— clean;check:max-lines-ratchet— OK, no new bypasses;check:reliability-gates— 82 gates passNot run locally: full
pnpm typecheck(OOM risk on this host — type-aware oxlint covers the changed files),pnpm build, and Linux/Windows/SSH. CI covers those.AI Disclosure
Implementation, verification against the OMP binary, and tests by Claude (Opus 5) in Claude Code.
Review
readStringand length-normalized bynormalizeInteractivePromptField. ThewillContinuecheck is a strict!== true, so a malformed value settles rather than hangs.blockedis an existingAGENT_STATUS_STATESmember andinteractivePromptis an existing field with its existing{ questions }shape, so an older client decodes both. The behavior an older client sees changes (an OMP pane now settles, and shows action-required during an approval), which is the fix.nativeChatRequiresLocalTranscript('omp')), so the liveaskpayload is now the only way an OMP question card can reach it; the payload uses the same parser mobile already runs for Pi and grok.willContinuesettle as terminal instead of sticking at "working" — fail-open in the safe direction. Pi and Prime paths are byte-identical apart from the shared predicate refactor. The extension re-registers on install, so an already-running OMP process keeps the old behavior until its next launch.isOmpRuntime()), and OMP itself emits approval events only because a handler now exists.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (scoped checks run locally; CI covers the full run)Author