Skip to content

Quiet-window Pi/OMP intermediate done so resumed work cancels notification (#6361) - #6558

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-6361
Jun 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-6361

Conversation

@nwparker

@nwparker nwparker commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

🧑‍🤝‍🧑 Impact & ELI5

1) What's broken today (ELI5). People running Orca with goal/mission-style agents (Pi from pi.dev, and OMP) get a false "your agent is finished!" notification while the agent is actually still working. The agent then looks frozen — it sits there "thinking" and won't reliably wrap up its turn, so the user has to poke it ("are you still working?") to nudge it back to life. This only happens inside Orca (the reporter never saw it using Pi directly), and only for these mission-style agents — but for the people it hits it's a real blocker, because the tool is lying to them about whether their work is done.

2) What this PR does (ELI5). Pi and OMP announce small milestones as they go ("done with step 1!") even though they're still chugging along. Orca was treating the very first "done!" as the whole job being finished and immediately pinging you. The fix makes Orca wait a brief, quiet moment after any "done!" from these specific agents before sounding the alarm — and if the agent starts working again during that pause, the premature "finished" alert is quietly cancelled. So it now says "finished" only when the agent truly stops.

3) Tradeoffs / regressions — honest answer. No regressions. The change is surgical and scoped by agent kind: only Pi and OMP now route their "done" signal through the short quiet-window delay that already existed in the codebase. Agents that only say "done" once at the real end of their turn (like Codex) are explicitly preserved and still notify instantly — a dedicated test guards that. The one honest cost: for Pi/OMP, even the legitimate "really finished" notification is delayed by that quiet-window interval (a brief pause, not a behavior loss) — and that pause is exactly what lets a resumed agent cancel a false alarm. It behaves identically on macOS, Linux, and Windows, and applies to both local and SSH/remote panes since they share the same notification logic.


Summary

Fixes #6361

Pi (pi.dev) and OMP are goal/mission agents whose normalizePiCompatibleEvent maps milestone agent_end (and session_shutdown) to hook state done while they are still working. Orca fired an "agent finished" OS notification at one of these intermediate done events while Pi's TUI was still spinning, and a follow-up working/tool event could not cancel it.

Root cause is in observeHookStatus (agent-completion-coordinator.ts). The quiet-window path (scheduleHookDoneCompletion) — which exists precisely so resumed work can CANCEL an intermediate done — was gated on payload.state === 'done' && workingStatusObserved. Pi's intermediate done events have workingStatusObserved === false, so control fell through to the IMMEDIATE dispatchCompletion('hook', …) with no quiet window.

What changed

  1. Route Pi/OMP done through the quiet window. A new doneShouldUseQuietWindow(payload) predicate widens the gate to workingStatusObserved || isPiCompatibleAgentType(agentType). When Pi resumes (emits a tool_call/message mapped to working), the working branch calls clearPendingHookDone() and the premature notification is suppressed — exactly the milestone-suppression behavior the quiet window was built for. Codex and other turn-end-only producers keep their immediate dispatch.

  2. Shared, typed agent-kind predicate. Rather than hardcoding agent === 'pi' || agent === 'omp' inline (a fourth drift site), the check delegates to a new isPiCompatibleAgentType() exported from src/shared/pi-agent-kind.ts, co-located with the canonical PiAgentKind = 'pi' | 'omp' type. One source of truth; the compiler keeps it in sync if a third Pi-compatible kind is ever added.

  3. Hardened the process-exit backstop (prevents a lost notification). Routing Pi/OMP through the quiet window newly exposed them to a race: a process-inspection poll landing inside the 1.5 s window could find the agent process gone and run clearAgentRunEvidence(), wiping hasAgentRunEvidence — so when the quiet-window timer fired, dispatchCompletion('hook', …) was blocked by the !hasAgentRunEvidence guard and the real completion was silently dropped. handleProcessInspectionResult now skips the agent-evidence teardown while a quiet-window done is pending and reschedules a poll, so the pending hook completion remains authoritative (and process-exit detection resumes after the window). This also closes the same latent silent-drop for Codex working→done.

The change is renderer-side and provider/transport agnostic, so it applies equally to local and SSH/remote panes (both PTY-connection and hook-completion coordinators funnel through observeHookStatus).

Screenshots

No visual change. This affects OS notification timing only; verified at the unit level.

Testing

  • pnpm test (scoped: agent-completion-coordinator.test.ts — 55 passed; agent-completion-coordinator-dispose-leak.test.ts — 3 passed)
  • tsgo --noEmit across the node, cli, and web tc configs — clean (exit 0)
  • oxlint + lint:switch-exhaustiveness on the changed/shared files — clean
  • Full src/shared/ vitest suite — 1583 passed (no regression from the pi-agent-kind.ts export)
  • Added or updated high-quality tests that would catch regressions

New/updated tests:

  • defers a %s milestone done without prior working through the quiet window (pi, omp) — asserts hasPendingHookDoneCompletion() is true and dispatchCompletion is NOT called before HOOK_DONE_QUIET_MS, then is called once after with quietedHookDone: true.
  • suppresses a Pi milestone done when work resumes before the quiet window — a working event before the window cancels the premature "finished".
  • still dispatches a Codex done-without-prior-working immediately — regression guard for Codex's immediate dispatch.
  • still fires a pending Pi done when process inspection sees the agent exit first — regression guard for the lost-notification race fixed in (3).
  • Removed pi/omp from the immediate-dispatch recognizes %s hook agent ids it.each (they now defer); the Codex done-only tests are unchanged and still pass.

AI Review Report

Reviewed for correctness, edge cases, and cross-platform behavior; adversarially verified against current main.

  • Design: agent-scoped quiet window is the right scope (not always-quiet) — the root cause is provider-specific to normalizePiCompatibleEvent, and several existing tests assert immediate dispatch for Codex/others. Making every provider quiet would add a 1.5 s delay to every completion and break the Codex done-only contract.
  • Regression sweep (all clear): Codex done-only still immediate; the done-only-producer turn bump does not pre-empt the new branch on a fresh coordinator; replay-guard/identity dedup correctly suppress duplicates without suppressing-forever; waiting/blocked and shouldSuppressHookCompletion still cancel a provisional done; resumed turns re-fire; the new process-exit guard delays (never drops) process-exit completions and has no path that pauses polling forever.
  • Cross-platform / SSH: no platform-dependent code touched; transport-agnostic renderer state-machine logic; applies to remote panes.
  • Git providers: not applicable — no source-control/review code involved.

Security Audit

No input handling, command execution, path handling, auth, secrets, dependency, or IPC changes. The diff reads an already-parsed agentType string from an existing hook payload and branches on it, and adds a pure string → boolean predicate. No new external input is trusted, no new surface introduced.

Notes

  • If other goal/mission agents adopt the same milestone agent_end contract in the future, add them to PiAgentKind / isPiCompatibleAgentType (or generalize to a capability flag on the agent identity).

Made with Orca 🐋

@nwparker

Copy link
Copy Markdown
Contributor Author

Evidence

Before / after reasoning

Before: observeHookStatus gated the quiet window on payload.state === 'done' && workingStatusObserved (agent-completion-coordinator.ts:656). Pi's intermediate agent_end arrives with workingStatusObserved === false, so it fell through to the immediate dispatchCompletion('hook', ...) at line 674 — Orca fired "agent finished" while Pi kept thinking, and a later working/tool_call event could not cancel it.

After: the gate is payload.state === 'done' && doneShouldUseQuietWindow(payload), where doneShouldUseQuietWindow returns true when workingStatusObserved OR the agent is pi/omp. Pi/OMP done now schedules a quiet-window completion; a follow-up working event hits the working branch (line 616), calls clearPendingHookDone(), and suppresses the premature notification. Codex done-without-working keeps falling through to the immediate dispatch.

Test command + output

$ ./node_modules/.bin/vitest run --config config/vitest.config.ts \
    src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts

 Test Files  1 passed (1)
      Tests  47 passed (47)

Key new/changed tests (all passing):

✓ defers a Pi done-without-prior-working through the quiet window
✓ suppresses a Pi milestone done when work resumes before the quiet window
✓ still dispatches a Codex done-without-prior-working immediately
✓ recognizes pi hook agent ids but defers the done through the quiet window
✓ recognizes omp hook agent ids but defers the done through the quiet window

Codex done-only regression guards (unchanged, still passing):

✓ keeps duplicate done-only hooks inside replay guard suppressed after process inspection
✓ can require a fresh working signal after completion state reset
✓ allows later done-only hook completions from the same long-lived process
✓ recognizes codex hook agent ids even when the binary name differs

Dispose/leak suite (no regression):

$ ./node_modules/.bin/vitest run --config config/vitest.config.ts \
    src/renderer/src/components/terminal-pane/agent-completion-coordinator-dispose-leak.test.ts
 Test Files  1 passed (1)
      Tests  3 passed (3)

Lint + typecheck (scoped to changed files)

$ ./node_modules/.bin/oxlint src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts \
    src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
(no output — clean)

$ ./node_modules/.bin/tsgo --noEmit -p config/tsconfig.tc.web.json
EXIT: 0

@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

createAgentCompletionCoordinator gains a new local predicate doneShouldUseQuietWindow that returns true when workingStatusObserved is set or when the hook payload's agent resolves to pi or omp. The observeHookStatus handler for payload.state === 'done' now calls this predicate instead of checking workingStatusObserved directly, so Pi/OMP agents enter the quiet-window delay even without a prior 'working' event. Tests add three new cases (deferred Pi dispatch, cancelled Pi dispatch on resume, immediate Codex dispatch) and move Pi/OMP out of the shared agent-id recognition list into a dedicated it.each block that verifies quiet-window behaviour.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately captures the main change: Pi/OMP intermediate done events now use the quiet window so resumed work cancels the notification.
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.
Description check ✅ Passed The PR description matches the required template and includes the requested summary, testing, review, security, and notes sections.
✨ Finishing Touches
📝 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 (1)
src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts (1)

150-154: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten this rationale comment to the repo’s 1–2 line limit.

The reason is useful, but this new Why block is five lines long. Please trim it to one or two lines and keep only the non-obvious constraint. As per coding guidelines "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does. Keep comments short — one or two lines, capturing only the non-obvious reason."

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75c0ec20-4db2-4ef5-b604-2410024c65d6

📥 Commits

Reviewing files that changed from the base of the PR and between b45cb54 and 4a90846.

📒 Files selected for processing (2)
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.test.ts
  • src/renderer/src/components/terminal-pane/agent-completion-coordinator.ts

@nwparker
nwparker force-pushed the nwparker/fix-6361 branch from 4a90846 to 410b3a2 Compare June 28, 2026 23:17
@nwparker

Copy link
Copy Markdown
Contributor Author

Updated — rebased onto main + hardened

This revision force-pushes a single commit rebased cleanly onto the latest main (the prior revision was 41 commits behind and CONFLICTING; now MERGEABLE). Three improvements over the previous version:

  1. Shared typed predicate. The gate no longer hardcodes agent === 'pi' || agent === 'omp' inline. It delegates to a new isPiCompatibleAgentType() exported from src/shared/pi-agent-kind.ts, co-located with the canonical PiAgentKind type — one source of truth instead of a fourth inline drift site.

  2. Fixed a lost-notification race the agent-scoping newly exposed. A process-inspection poll landing inside the 1.5 s quiet window could find the agent gone and run clearAgentRunEvidence(), so the quiet-window timer's dispatchCompletion('hook', …) was then blocked by !hasAgentRunEvidence and the real completion was silently dropped. handleProcessInspectionResult now skips the evidence teardown while a quiet-window done is pending (and reschedules a poll). This also closes the same latent drop for Codex working→done. Guarded by a new test.

  3. Comment trimmed to the repo's 1–2 line rule (addresses the CodeRabbit nitpick on the rationale block).

Gates run

$ vitest run agent-completion-coordinator.test.ts            → 55 passed (was 47; +8)
$ vitest run agent-completion-coordinator-dispose-leak.test.ts → 3 passed
$ vitest run src/shared/                                      → 1583 passed (no regression from the new export)
$ tsgo --noEmit -p tsconfig.node.json / tc.cli.json / tc.web.json → exit 0 (all three)
$ oxlint <changed files> ; pnpm lint:switch-exhaustiveness    → clean

Adversarially re-verified against current main: the new process-exit guard is correctly placed (after the recognized-agent return, before the evidence-teardown block), delays rather than drops process-exit completions, and has no path that pauses polling forever. doneShouldUseQuietWindow is logically identical to workingStatusObserved || agent==='pi' || agent==='omp' with trim/lowercase normalization.

@nwparker

Copy link
Copy Markdown
Contributor Author

@coderabbitai the 5-line rationale block has been trimmed to the 1–2 line repo limit (now a 2-line Why: on doneShouldUseQuietWindow), and the non-obvious detail moved to the shared isPiCompatibleAgentType docstring in pi-agent-kind.ts. Thanks for the catch.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@nwparker Thanks for tightening that up — the 2-line Why: plus the shared docstring in src/shared/pi-agent-kind.ts sounds like a good fit for the repo convention.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

…ation (#6361)

Pi (pi.dev) and OMP are goal/mission agents whose normalizePiCompatibleEvent
maps milestone agent_end -> hook state 'done' while they are still working.
observeHookStatus gated the quiet window on `workingStatusObserved`, so these
intermediate 'done' events (workingStatusObserved === false) fell through to an
immediate "agent finished" notification while the TUI kept spinning, and a
follow-up working event could not cancel it.

Route Pi/OMP 'done' through the existing quiet window via a new
doneShouldUseQuietWindow() predicate (delegating to a shared
isPiCompatibleAgentType on the canonical PiAgentKind), so resumed work cancels
the premature notification. Codex and other turn-end-only producers keep their
immediate dispatch.

Also harden the process-exit backstop: skip the agent-evidence teardown while a
quiet-window 'done' is pending, otherwise a poll that finds the agent gone would
clear hasAgentRunEvidence and the timer would silently drop the real completion.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker force-pushed the nwparker/fix-6361 branch from 410b3a2 to 1fb3b5b Compare June 28, 2026 23:41
@nwparker
nwparker merged commit 6154ade into main Jun 28, 2026
1 check passed
@nwparker
nwparker deleted the nwparker/fix-6361 branch June 28, 2026 23:52
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ation (stablyai#6361) (stablyai#6558)

Pi (pi.dev) and OMP are goal/mission agents whose normalizePiCompatibleEvent
maps milestone agent_end -> hook state 'done' while they are still working.
observeHookStatus gated the quiet window on `workingStatusObserved`, so these
intermediate 'done' events (workingStatusObserved === false) fell through to an
immediate "agent finished" notification while the TUI kept spinning, and a
follow-up working event could not cancel it.

Route Pi/OMP 'done' through the existing quiet window via a new
doneShouldUseQuietWindow() predicate (delegating to a shared
isPiCompatibleAgentType on the canonical PiAgentKind), so resumed work cancels
the premature notification. Codex and other turn-end-only producers keep their
immediate dispatch.

Also harden the process-exit backstop: skip the agent-evidence teardown while a
quiet-window 'done' is pending, otherwise a poll that finds the agent gone would
clear hasAgentRunEvidence and the timer would silently drop the real completion.

Co-authored-by: Orca <[email protected]>
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.

[Bug]: notifies for finished but really stuck. using Pi

1 participant