Skip to content

fix(agents): settle and surface the OMP terminal lifecycle (#14278) - #14605

Closed
brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/omp-willcontinue-14278
Closed

brennanb2025 wants to merge 1 commit into
mainfrom
brennanb2025/omp-willcontinue-14278

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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)

  • The generated status extension's agent_end handler branches for OMP runtimes: willContinue === true keeps the pane active and arms no timer; anything else posts the terminal agent_end immediately. Pi and Prime keep their existing agent_settled / idle-recheck path untouched.
  • Registers tool_approval_requested / tool_approval_resolved handlers (guarded by isOmpRuntime(), omitted entirely for Prime, which has no OMP runtime).

Reporting (src/shared/agent-hook-listener.ts)

  • tool_approval_requested → blocked carrying the awaited tool name and the policy reason; tool_approval_resolved → back to working with that detail cleared. Both are OMP-gated.
  • One isPiCompatibleAskTool() predicate now drives both the blocked-state gate and the published prompt payload, so they can't drift (Pi names the tool AskUserQuestion, OMP names it ask).
  • OMP's ask input is published as the live interactivePrompt. Its input is already the canonical { questions: [{ question, options: [{ label, description }] }] } shape, so the existing parseQuestionsShape parser renders it with no new envelope and no tool-name aliasing. The JSON serialization used by both paths is factored into serializeQuestionPrompt().

Identity (src/shared/synthetic-agent-title.ts, src/shared/agent-title-owner.ts)

  • The Pi profile is marked titleIdentityFallback: true — it is the generic member of the pi-compatible title group, and every member emits its frames. resolveCompatibleAgentTypeForOwner still 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 hardcoded omp special case.

Tests

  • The VM harness that runs the generated extension moved to agent-status-extension-test-harness.ts (matching src/relay/agent-exec-handler-test-harness.ts and src/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 the max-lines budget. No max-lines suppression 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_end is emitted as { type: 'agent_end', messages, willContinue }, where willContinue: true is 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_settled does not exist in the binary at all.
  • tool_approval_requested / tool_approval_resolved carry { 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.
  • The ask tool'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 if willContinue, 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 willContinue and both are right about the root cause; thanks to @dandaka and @devatnull, and their work is carried forward via Co-authored-by. This PR differs from them in four ways:

  1. fix(pi): settle OMP status on terminal agent_end via willContinue #14330 fixes only the completion path and leaves the issue's other four expected behaviors open. This closes the whole issue.
  2. fix(agents): report OMP terminal and interactive states #14279 aliases OMP's ask tool name to ask_user_question to trick deriveInteractivePrompt into 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.
  3. fix(agents): report OMP terminal and interactive states #14279 hardcodes if (incomingAgentType === 'omp' || ownerAgentType === 'omp') return 'omp' inside resolveCompatibleAgentTypeForOwner. The ownerAgentType === '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 as titleIdentityFallback on the generic member instead.
  4. fix(agents): report OMP terminal and interactive states #14279 publishes an { approval: { tool, summary } } interactive-prompt envelope for OMP approvals. That envelope drives the native-chat approval card, whose buttons write 1 (allow) and ESC (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 that 1/ESC commit 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:

  • Before: an OMP pane that has finished stays on the working spinner row indefinitely. After: it settles to the done row on the same agent_end it already receives.
  • Before: an OMP pane parked on a tool-approval prompt renders as working. After: it renders through the existing blocked treatment (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

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Each of the four behaviors is covered, and each test was proven to fail with only that part of the fix reverted:

Behavior Test Fails without fix
Completion settles (willContinue absent / false, configured + runtime-routed OMP) agent-status-extension-omp-lifecycle.test.ts 5/7 fail with the agent_end branch removed
Continuation must not settle (willContinue: true, and no timer left armed) same file ✔ (in the 5 above)
Question wait publishes its prompt agent-hook-listener.test.ts → "maps OMP ask to blocked and publishes its questions payload" ✔ with the predicate reverted to agentKind === 'pi'
Approval wait blocks and clears agent-hook-listener.test.ts → "blocks an OMP pane on a tool approval request and clears it on resolution" ✔ with the approval state mapping removed
Identity does not oscillate agent-detection.test.ts → "keeps a live OMP identity from being downgraded by a generic Pi owner" ✔ with titleIdentityFallback removed

Also asserted: Pi and Prime never post the approval events, and the listener returns null for 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 passed
  • vitest run over every suite importing agent-hook-listener / agent-title-owner / synthetic-agent-title (relay, src/main/agent-hooks, hook caches, subagent lifecycles) — 50 files, 714 passed
  • vitest 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.json on src/main/pi + the changed src/shared files — clean
  • oxfmt --check — clean; check:max-lines-ratchet — OK, no new bypasses; check:reliability-gates — 82 gates pass

Not 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

  • Security: no new trust boundary. The approval events arrive on the same authenticated loopback hook route as every other Pi event; fields are read through the existing readString and length-normalized by normalizeInteractivePromptField. The willContinue check is a strict !== true, so a malformed value settles rather than hangs.
  • Cross-platform (Linux/Windows/Mac): the change lives in the generated extension string (plain JS, no platform APIs) and in shared normalization. No paths, shells, or shortcuts touched; the WSL curl fallback carries the new events unchanged.
  • Remote SSH: no wire change. No new fields and no new stream opcodes — blocked is an existing AGENT_STATUS_STATES member and interactivePrompt is 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.
  • Mobile: benefits without a client change. Mobile cannot read an OMP transcript (nativeChatRequiresLocalTranscript('omp')), so the live ask payload 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.
  • Backwards compatibility: OMP builds predating willContinue settle 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.
  • Performance: net reduction. The exponential idle-recheck timer loop no longer runs at all for OMP. The two new handlers are no-ops on non-OMP runtimes (cached isOmpRuntime()), and OMP itself emits approval events only because a handler now exists.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (scoped checks run locally; CI covers the full run)

Author

  • X / Twitter: @BrennanKB5

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]>
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 a63e7

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% 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 summarizes the primary change: fixing OMP terminal lifecycle settlement and status reporting.
Description check ✅ Passed The description covers the required sections, explains the changes and rationale, documents testing, and identifies CI coverage for unchecked full commands.
Linked Issues check ✅ Passed The implementation and tests address all coding objectives in [#14278], including settlement, continuation, identity, prompts, approvals, and Pi/Prime preservation.
Out of Scope Changes check ✅ Passed The changes remain focused on [#14278]; the shared harness and added tests directly support lifecycle, state, identity, and regression coverage.
✨ Finishing Touches 💡 1
📝 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.

🧹 Nitpick comments (3)
src/shared/agent-hook-listener.ts (1)

2101-2116: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Consider publishing a structured approval payload for OMP approvals.

The existing PermissionRequest path at line 936 publishes { approval: { tool, summary } } as interactivePrompt, so clients can render an approval card. This OMP branch sets interactivePrompt: undefined and puts the reason in toolInput. The pane reads blocked, but no approval card appears. The producer also posts approval_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 win

Fail fast when the requested hook is not registered.

handlers[name]?.(...) resolves silently for an unknown name. If a generated hook name changes, specs such as agent-status-extension-omp-lifecycle.test.ts still pass, because "no post" is the expected outcome in several cases. Throw for an unregistered name, and let specs that check absence read harness.handlers directly, 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 value

Reuse the exported kind type instead of repeating the union.

getPiAgentStatusExtensionSource takes PiAgentKind. This inline union duplicates that contract, so a new kind would not reach the harness signature. Import the type and use it for args.kind.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c5ca534d-5772-444b-ab05-af472cd70f40

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb8836 and a63e7f4.

📒 Files selected for processing (9)
  • src/main/pi/agent-status-extension-omp-lifecycle.test.ts
  • src/main/pi/agent-status-extension-source.test.ts
  • src/main/pi/agent-status-extension-test-harness.ts
  • src/main/pi/agent-status-handler-source.ts
  • src/shared/agent-detection.test.ts
  • src/shared/agent-hook-listener.test.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-title-owner.ts
  • src/shared/synthetic-agent-title.ts

@nwparker

Copy link
Copy Markdown
Contributor

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.

@nwparker

Copy link
Copy Markdown
Contributor

Superseded by #20603.

@nwparker nwparker closed this Sep 19, 2026
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.

OMP terminal agent_end can leave status stuck as working

2 participants