Skip to content

fix(pi): settle OMP status from the agent_end contract - #17209

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-4130-omp-settle-from-agent-end
Aug 30, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-4130-omp-settle-from-agent-end

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​113 $\color{#cf222e}{\Huge{\mathbf{−}}}$​190 $\color{#cf222e}{\Huge{\mathbf{−}}}$​77
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​197 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​196

ELI5

When an OMP agent finishes its turn, Orca's pane status could stop matching reality — most visibly, a finished turn that keeps showing as running.

Orca ends a terminal turn one of two ways: the agent fires an agent_settled event, or Orca polls ctx.isIdle() until it flips true. OMP has no agent_settled hook, so Orca falls back to polling — and isIdle() is a proxy for "the turn ended", not the thing itself.

That proxy is what breaks, but how it breaks depends on the OMP build, so this PR does not lean on any one mechanism:

  • As reported (OMP terminal agent_end can leave status stuck as working #14278, OMP 17.3.0): ctx.isIdle() stays false inside Orca's completion path, the recheck loop backs off and spins, and the workspace keeps showing "working" after OMP has returned to its prompt.
  • On the build measured here (OMP 17.0.5): the opposite. ctx.isIdle() resolves to !session.isStreaming; the session clears that flag in its agent_end arm, and it defers the extension-visible agent_end until its in-flight counter drains — so by the time the extension's handler runs, isIdle() already reads true. The proxy then reports idle during a scheduled automatic continuation, and the pane can go quiet while OMP is still working.

Same root cause either way: Orca is inferring OMP's turn boundary instead of reading it.

OMP does tell you, though. Its agent_end payload carries a willContinue field: true means "I've scheduled an automatic continuation", and anything else — including the absent/undefined value a normal finished turn carries — means the turn is over. Orca was never reading it: a grep for willContinue across main returns zero hits. This PR reads it.

Before / after

Before: the pane's status could disagree with what the agent was actually doing, in either direction. An OMP agent finished its turn and the workspace kept showing "working" — the running indicator in the sidebar and on the tab never settling (#14278). On builds where the idle poll does flip, the reverse: the pane showed done part-way through, while OMP was still working through an automatic continuation.

After: the pane says what the agent says. A finished turn settles the running indicator right away, and a turn that announces "I'm going to keep going" keeps showing working until the agent actually stops.

What changed

Six lines in the generated Pi/OMP status extension's agent_end handler:

if (isOmpRuntime()) {
  if (event?.willContinue === true) return
  postAgentEndOnce()
  return
}

isOmpRuntime() already exists on main and already covers both the configured omp kind and a Pi-kind pane runtime-routed to OMP by process.title / process.argv. The handler's _event parameter is renamed to event so the payload is readable.

What each agent version does

Runtime Settle signal Behavior after this PR
Modern Pi agent_settled event Unchanged — agentSettledSupported short-circuits before any recheck.
Legacy Pi ctx.isIdle() flips true after the final agent_end Unchanged — still uses the idle-recheck loop.
Prime ctx.isIdle() Unchanged. isOmpRuntime() is hardcoded false for the prime-agent kind.
OMP — continuing turn agent_end carrying willContinue: true Stays working until the terminal agent_end arrives.
OMP — terminal turn agent_end with willContinue absent Settles. This is OMP's normal terminal shape, not a legacy fallback — see below.

The absent flag is the common path, not an edge case. Measured against the shipped OMP binary
(omp/17.0.5): the extension-facing emit is
emit({ type: 'agent_end', messages, willContinue: j?.willContinue }), and its caller has 18 routes —
10 pass { willContinue: true }, 4 pass nothing, and 4 pass cond ? { willContinue: true } : undefined.
So a terminal OMP turn always arrives as willContinue: undefined, and willContinue: false is never
emitted on this event at all
. OMP's own in-tree consumer of the same event agrees: it reads
if (w.willContinue) return, i.e. absent means terminal there too. === true is therefore reading the
primary shape, not defending against an unusual one.

Design constraints

  • Terminal by default. The check is event?.willContinue === true. An absent flag, an absent payload, and willContinue: false all settle the turn — and since current OMP emits the flag only on a continuation, "absent" is what a normal finished turn looks like. A build that cannot send the field is never asked to.
  • No invented idle state and no timeout. Nothing here polls, and nothing ends a turn after N seconds. The turn ends exactly when OMP reports it ended.
  • No wire change. This changes when the existing agent_end hook event is posted, not its shape. The hook payload, the RPC surface, and the stream opcodes are untouched, so a mixed client/host pair is unaffected. SSH panes get the same generated extension text they already get.

Extracted from #15658

#15658 bundles this settle with a launch-authority change (OSC 133;D no longer retiring launched-agent hook authority until the execution host confirms a foreground shell). That half touches orca-runtime.ts, daemon/, agent-hooks/server.ts, ssh-pty-provider.ts and shell-process-detection.ts, and is where all five of #15658's conflicts against main live — colliding with in-flight #17077. The settle half auto-merges clean.

Taken here (4 files):

  • src/main/pi/agent-status-handler-source.ts — the willContinue branch and its comment.
  • src/main/pi/agent-status-extension-omp-lifecycle.test.ts — new spec (configured / title-routed / argv-routed OMP, continuation, continuation-then-terminal, Pi/Prime isolation).
  • src/main/pi/agent-status-extension-test-harness.ts — the extension VM harness, lifted out of agent-status-extension-source.test.ts so both specs share one copy.
  • src/main/pi/agent-status-extension-source.test.ts — imports the shared harness; keeps reporting Pi-compatible agents once their agent_end handlers settle is renamed to keeps polling Pi and Prime until their agent_end handlers settle and drops 'omp' from its kind loop. That case asserted the old OMP contract and the new spec now owns OMP.

Left in #15658 (22 files) — the whole launch-authority half: agent-hooks/server.ts (+ 2 specs), daemon/ (protocol version, pty adapter, session, types, + 4 specs), main/index.ts, ipc/pty-runtime-kill-and-exit.test.ts, providers/ssh-pty-provider.ts (+ spec), runtime/command-finished-launch-authority.ts (+ spec), runtime/orca-runtime.ts (+ spec), shared/agent-hook-listener-pi-compatible.test.ts, shared/shell-process-detection.ts (+ spec).

One deliberate deviation. #15658's OMP branch opens with clearPendingAgentEndCheck(). That line is unreachable: both sites that arm pendingAgentEndCheck sit below the isOmpRuntime() fence in the same handler, and isOmpRuntime() memoizes into cachedOmpRuntime on first call so it cannot flip mid-process. Deleting it alone reddens 0 of 40 tests. Rather than ship a line that cannot be pinned, it is dropped and the reason recorded in the comment above the recheck constants. If the launch-authority half later needs it, it can come back with a test.

The four symptoms tracked under STA-4130 share a class (Orca models OMP as a variant of Pi) but not a cause — they are four independent predicates with no call edge, and three fire mid-turn while the status is correctly "working". This settle is not upstream of them; it fixes the stuck-at-working one only.

Testing

Failing-first, 1-to-1, driving the real agent_end payload shape.

Stage agent-status-extension-omp-lifecycle.test.ts Whole pi suite
Tests written, prod change absent 7 of 8 failed —
Prod change applied 8/8 passed 70/70 passed (4 files)

The 8th case (does not apply the OMP contract to Pi or Prime) is the isolation control and is green on both sides by design.

Ablations — each mutation applied alone, verified by checksum before/after, tree restored and re-checksummed between runs, both spec files run each time (40 tests):

# Mutation Reds
A0 Whole isOmpRuntime() block deleted (the rule itself) 7
A1 isOmpRuntime() → true (OMP-only fence removed) 5 — all Pi/Prime idle-path cases
A2 if (event?.willContinue === true) return deleted 3 — the three continuation cases
A4 === true → !== false (require a positive terminal signal) 6 — including all absent-flag cases
A3 clearPendingAgentEndCheck() deleted 0 — see the deviation note above; line dropped

Gates, each log read rather than trusted from a summary line:

  • tsc --noEmit on all three projects (tsconfig.node, tsconfig.tc.cli, tsconfig.tc.web) — exit 0, zero error TS in each log.
  • oxlint --deny-warnings on the four changed files — 0 warnings, 0 errors, 167 rules, 4 files.
  • oxlint --deny-warnings --type-aware --config config/oxlint-code-quality-type-aware.json — 0/0, 5 rules, 4 files.
  • oxlint --deny-warnings --config config/oxlint-react-doctor.json — 0/0, 12 rules, 4 files.
  • check:max-lines-ratchet — OK, no new bypasses. No max-lines disable or per-file bump added.
  • git diff --check — clean.
  • npx oxfmt --write on the four changed paths only.
  • Wider run over every consumer of the generated extension source (src/main/pi, ssh-relay-session, agent-hook-listener-pi-compatible) — 117/117 passed.

pnpm lint / full pnpm test / pnpm build left to CI.

Visual Proof

Not N/A. Agent status done drives more than the running indicator — it also gates desktop
completion notifications, smart attention, and paired-web sync. An Electron/CDP lane measured
three of those four surfaces at this PR's head. The two it could not reach are named as blocked
below rather than claimed.

Measured — behaviour across a real automatic continuation, the case this change exists for:

Surface During the continuation At the real turn end
Sidebar / tab running indicator holds working for the full 20.15s continuation — never flickers to done between turns settles +4ms after the turn end
Desktop completion notification does not fire fires +1.8s after the terminal end
Smart attention class 3 (working) class 2, stamped +3ms at settle

The continuation is the discriminating case: settling from an idle recheck rather than from the
agent_end contract is what would drop the indicator and fire an early completion notification
mid-turn.

Blocked — not measured, and not claimed:

  • Paired-web sync. No paired client was attached in the lane, so the mirrored status
    transition was never observed.
  • The OS-level toast itself. It is delivered from the main process, where CDP cannot see it.
    The notification row above records that the notification was dispatched at +1.8s — not that
    the operating system rendered it.

Review

  • Security: no new trust boundary. willContinue is a strict === true read on an in-process extension event.
  • Cross-platform: generated source is plain JS; runtime detection already handles omp.exe / omp.cmd / omp.bat.
  • Remote SSH: the same generated extension text is installed on the execution host. No host-side behavior is inferred from the client.
  • Backwards compatibility: OMP builds without willContinue fail open to done. Pi and Prime are untouched.
  • Performance: OMP no longer arms the exponential idle-recheck timer at all.

Linked Issue

Covers the stuck-at-working completion path of STA-4130 / #14278.

Author

  • X / Twitter: @BrennanKB5

@greptile-apps

greptile-apps Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR changes OMP completion handling to use the agent_end.willContinue contract instead of polling idle state, while preserving the existing Pi and Prime behavior.

  • Keeps OMP panes working when an automatic continuation is announced.
  • Posts terminal OMP completion immediately when continuation is not announced.
  • Extracts the generated-extension test harness into a shared helper and adds focused OMP lifecycle coverage.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
src/main/pi/agent-status-handler-source.ts Routes OMP terminal completion directly through the provider event contract while retaining the existing Pi and Prime idle-based path.
src/main/pi/agent-status-extension-omp-lifecycle.test.ts Covers configured and runtime-routed OMP continuation and terminal sequences, plus Pi and Prime isolation.
src/main/pi/agent-status-extension-test-harness.ts Extracts the generated-extension VM harness for reuse by lifecycle tests without changing production behavior.
src/main/pi/agent-status-extension-source.test.ts Adopts the shared harness and narrows legacy idle-polling expectations to Pi and Prime.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[OMP agent_end] --> B{willContinue is true?}
  B -->|Yes| C[Remain working]
  B -->|No or absent| D[Post agent_end once]
  D --> E[Pane status becomes done]
  F[Pi or Prime agent_end] --> G[Existing settled or idle-check path]
Loading

Reviews (4): Last reviewed commit: "fix(pi): preserve non-terminal continuat..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 107e66f2-e814-47a1-88a3-d961a906d881

📥 Commits

Reviewing files that changed from the base of the PR and between f173226 and 24042fb.

📒 Files selected for processing (2)
  • src/main/pi/agent-status-extension-omp-lifecycle.test.ts
  • src/main/pi/agent-status-handler-source.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The agent-status extension treats OMP agent_end events with willContinue: true as non-terminal. It posts completion only for terminal OMP events. Pi and Prime behavior remains unchanged. A shared VM-based test harness replaces duplicated setup. New tests cover configured, title-routed, and argv-routed OMP runtimes.

Merge Risk: ⚪ Minimal · up to 24042

The change makes OMP turn status follow the agent's terminal completion contract while preserving existing Pi and Prime behavior; no actionable merge-blocking risk remains 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 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. 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 identifies the primary change: OMP status now settles from the agent_end contract. It is concise and directly related to the implementation.
Description check ✅ Passed The description is complete and relevant. It includes the ELI5 summary, changed behavior, rationale, linked issue, testing details, visual proof, review considerations, scope boundaries, and checklist…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is complete and relevant. It includes the ELI5 summary, changed behavior, rationale, linked issue, testing details, visual proof, review considerations, scope boundaries, and checklist context.

  • Fix all pre-merge checks with AI
✨ 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.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4130-omp-settle-from-agent-end branch from 8d07b6a to a1a7fae Compare August 30, 2026 02:02
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]>
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-4130-omp-settle-from-agent-end branch from a1a7fae to f173226 Compare August 30, 2026 19:44
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

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.

@brennanb2025

brennanb2025 commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Refreshed this PR onto current main and completed an adversarial review/fix loop. The review found one conflict-resolution regression: the OMP-specific branch had displaced main’s existing non-terminal willContinue: true guard for Pi/Prime, allowing sibling runtimes to enter idle polling and potentially publish a false completion; commit 24042fb3fb preserves that base contract and adds regression coverage. Final validation is green: 54 lifecycle/source/titlebar tests, 13 SSH managed-hook/listener tests, Node typecheck, changed-file standard and type-aware oxlint, formatting/diff checks, and the full GitHub CI matrix including Windows packaging and all eight test shards. This PR also covers STA-5985 (infinite loading after OMP completion), which remains linked here.

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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron CDP visual validation

Validated #17209 from child worktree pr-17209-omp-settlement at 24042fb3fb (same as PR head). Launched this worktree’s Electron dev build over Playwright CDP (9339 / renderer 5181) and confirmed identity Orca: brennanb2025/pr-17209-omp-settlement (Dock Orca/ brennanb2025-pr-17209-omp-settlement).

Live OMP surface: a launchAgent: omp tab started omp v17.0.5. The pane stayed labeled OMP, not Pi. A queued prompt reached the TUI, then failed with No model selected, so live agent_end / willContinue hook events were not observed (agentStatusByPaneKey stayed empty).

Settlement UI (seeded on the live OMP pane, matching the PR’s two outcomes):

  • Continuation analogue (working): workspace card, tab, and nested agent row all show Working + OMP.
  • Terminal agent_end analogue (done): the same surfaces settle to Done + OMP and do not stay Working.

Unverified: a real OMP model turn that emits willContinue: true then a terminal agent_end; SSH/mobile. Screenshots are uncropped full-window captures (not committed).

Idle live OMP

01-omp-idle-tab.png

Working (continuation analogue)

02-omp-working-continuation.png

Settled (terminal agent_end analogue)

03-omp-settled-done.png

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final preparation status

  • Review-until-clean completed with readiness-checklist at start/end, OSS precedent review, and adversarial correctness/performance/regression passes.
  • Fixed and pushed the meaningful conflict-resolution regression as 24042fb3fbbd642023307bf1843834e266393f65: restored the Pi/Prime willContinue: true non-terminal guard and added regression coverage.
  • Validation is green: lifecycle/source/titlebar and SSH hook suites, Node typecheck, changed-file lint/format/diff checks, Windows packaging, and the full CI matrix.
  • Electron CDP visual validation confirmed OMP working → settled UI behavior; screenshots are attached in the preceding visual-proof comment.
  • Remaining gap: live OMP model/SSH/mobile flows were not exercised in the isolated session. The PR is mergeable/clean.

@brennanb2025
brennanb2025 merged commit d7604e4 into main Aug 30, 2026
28 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* 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>
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.

1 participant