Repository navigation
fix(pi): report completion on agent_settled so intermediate agent_end stops firing false notifications - #8826
Conversation
📝 WalkthroughWalkthroughThe Pi status handler now detects 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
fe12a22 to
ec0d6f6
Compare
… stays silent (stablyai#8035) Pi's agent_end fires per low-level run — auto-retry, auto-compaction and queued follow-ups all emit it while the agent is still working — so Orca fired premature completion notifications. Pi >= 0.80.4 emits agent_settled exactly once when nothing is left to run. The extension now subscribes to both events: the first agent_settled proves runtime support and mutes agent_end reporting from then on; on older Pi/OMP runtimes (where unknown event names register silently and never fire) agent_end keeps reporting done exactly as before. The settled handler reports the existing agent_end hook event, so the agent-hooks server contract is unchanged.
ec0d6f6 to
3e36192
Compare
|
Maintainer review completed after independently reproducing the first-run failure. The original implementation still posted intermediate Evidence:
Reviewed for nested-process ownership, reload/stale-context cleanup, WSL/SSH transport, duplicate settlement races, and legacy compatibility. No remaining blocking findings. |
Jinwoo-H
left a comment
There was a problem hiding this comment.
Approved after independent reproduction, contributor rework, and clean regression validation.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c495a030-96e3-441f-ae5f-2a7599b7eef8
📥 Commits
Reviewing files that changed from the base of the PR and between ec0d6f6f8c67068221268fc10dcc2bc35f49cf11 and 3e36192.
📒 Files selected for processing (2)
src/main/pi/agent-status-extension-source.test.tssrc/main/pi/agent-status-handler-source.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/pi/agent-status-handler-source.ts
| await harness.callHook('agent_end', undefined, context) | ||
| await vi.advanceTimersByTimeAsync(100) | ||
| await harness.callHook('agent_start') | ||
| await harness.callHook('agent_end', undefined, context) | ||
| await vi.advanceTimersByTimeAsync(2_000) | ||
| await harness.callHook('agent_settled') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Verify cancellation before invoking the second agent_end.
The second agent_end clears the existing timer itself, so this test passes even if agent_start fails to cancel the original pending check. Make the old context become idle and assert no completion is delivered before starting the next cycle.
Proposed test adjustment
await harness.callHook('agent_end', undefined, context)
await vi.advanceTimersByTimeAsync(100)
await harness.callHook('agent_start')
+
+ context.isIdle.mockReturnValue(true)
+ await vi.advanceTimersByTimeAsync(2_000)
+ expect(
+ harness.fetchMock.mock.calls.map(
+ (call) => JSON.parse(String(call[1]?.body)).payload.hook_event_name
+ )
+ ).toEqual(['agent_start'])
+
+ context.isIdle.mockReturnValue(false)
await harness.callHook('agent_end', undefined, context)📝 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.
| await harness.callHook('agent_end', undefined, context) | |
| await vi.advanceTimersByTimeAsync(100) | |
| await harness.callHook('agent_start') | |
| await harness.callHook('agent_end', undefined, context) | |
| await vi.advanceTimersByTimeAsync(2_000) | |
| await harness.callHook('agent_settled') | |
| await harness.callHook('agent_end', undefined, context) | |
| await vi.advanceTimersByTimeAsync(100) | |
| await harness.callHook('agent_start') | |
| context.isIdle.mockReturnValue(true) | |
| await vi.advanceTimersByTimeAsync(2_000) | |
| expect( | |
| harness.fetchMock.mock.calls.map( | |
| (call) => JSON.parse(String(call[1]?.body)).payload.hook_event_name | |
| ) | |
| ).toEqual(['agent_start']) | |
| context.isIdle.mockReturnValue(false) | |
| await harness.callHook('agent_end', undefined, context) | |
| await vi.advanceTimersByTimeAsync(2_000) | |
| await harness.callHook('agent_settled') |
|
Follow-up after this landed: with OMP 17.0.2, a child AgentSession's settlement still appears to be observed as pane/root settlement. Orca shows 'OMP finished' with 'Using yield' while the visible parent continues working. The in-process OMP reproduction and likely event sequence are tracked in #9181. |
… stays silent (stablyai#8035) (stablyai#8826) Pi's agent_end fires per low-level run — auto-retry, auto-compaction and queued follow-ups all emit it while the agent is still working — so Orca fired premature completion notifications. Pi >= 0.80.4 emits agent_settled exactly once when nothing is left to run. The extension now subscribes to both events: the first agent_settled proves runtime support and mutes agent_end reporting from then on; on older Pi/OMP runtimes (where unknown event names register silently and never fire) agent_end keeps reporting done exactly as before. The settled handler reports the existing agent_end hook event, so the agent-hooks server contract is unchanged.
Summary
Fixes #8035.
ELI5: Pi's
agent_endmeans "this attempt ended," not necessarily "the whole task is finished." Pi may still retry, compact context, or run a queued follow-up. Orca now waits for Pi's realagent_settledsignal before reporting completion.Modern Pi reports completion exactly once from
agent_settled. On the first run, ambiguousagent_endevents are held while the extension context remains active. Older Pi/OMP runtimes that never emitagent_settledretain completion reporting through an idle-state fallback. The settled handler still posts the existingagent_endhook payload, so no receiver contract changes.Root cause and reproduction
Orca's completion quiet window is 1,500 ms, while Pi's default automatic retry delay is 2,000 ms. Posting the first
agent_endimmediately therefore produced this deterministic sequence:agent_end.The regression harness keeps Pi non-idle across multiple intermediate
agent_endevents and a 2-second retry-shaped gap. With the previous implementation it records three premature completion posts; with this implementation it records none beforeagent_settledand exactly one afterward.Implementation
agent_endcompletion whilectx.isIdle()is false.agent_settledarrives.agent_settledcannot race duplicate posts.Testing
pnpm typecheckoxlintandoxfmt --checkpnpm run check:max-lines-ratchetgit diff --checkCoverage includes retries longer than the notification quiet window, multiple intermediate ends, resumed work, duplicate settlement races, legacy Pi/OMP, missing and stale contexts, reloads, nested processes, WSL transport, and SSH/relay installation.
Trade-offs and regression risk
agent_settledfor every completed run; nonstandard loaders without hook context use the immediate compatibility fallback.No visual, receiver-protocol, auth, secret, path, command-execution, or generic completion-coordinator behavior changes.
Screenshots
No visual change.
Security audit
The change adds process-local event state and timers inside the generated Pi/OMP extension. It does not add input parsing, filesystem writes, commands, credentials, or new IPC/network endpoints.