Repository navigation
fix(pi): scope status completion to the run that ended - #20840
Conversation
A sibling extension can queue a follow-up run from inside its own `agent_settled` handler (a memory reminder does exactly that). Pi dispatches extension handlers in registration order and starts that run synchronously, so the status extension sees the follow-up's `agent_start` before its own `agent_settled` for the run that just ended. The completion post was deduped by one `agentEndReported` boolean that `agent_start` reset, so the older settlement consumed the latch and the follow-up run's own settlement was swallowed. The host kept the follow-up's last `message_end` (working) as its last word about the pane, with nothing left to correct it until the freshness window expired. Key the dedupe on the generation of the run that ENDED instead: the older settlement still reports its own completion (that run did finish), and the follow-up run now reports its own end exactly once. Fixes stablyai#20838
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe status handler now tracks agent completion by run generation instead of a shared boolean latch. It records the generation that ended and prevents duplicate completion posts for that generation. A regression test covers a follow-up run started during settlement and verifies that its Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The follow-up run completion path is covered without an identified remaining regression, so the change is ready to merge with normal checks. 🚥 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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Per-run completion dedupe —
src/main/pi/agent-status-handler-source.tsreplaces the pane-lifetimeagentEndReportedlatch withrunGeneration/endedRunGeneration/completionPostedGeneration.agent_startbumps the run, a terminalagent_endrecords the ended run, andpostAgentEndOnce()/checkPendingAgentEnd()post whilecompletionPostedGeneration !== endedRunGeneration, so a lateagent_settledfor a finished run can no longer swallow a follow-up run's own completion. - Regression coverage — new
src/main/pi/agent-status-extension-nested-run-settlement.test.tsreproduces the sibling-extension ordering (agent_end→ follow-upagent_start→ prioragent_settled) and asserts the host's final word isagent_end; it fails on the old boolean latch (last postmessage_end) and passes now.
I traced the willContinue, legacy-pending-recheck, OMP-immediate, and first-agent_settled-without-agent_end paths; each still publishes exactly one completion per ended run, and pnpm test src/main/pi passes 167/167 with a clean tree. The deliberate decision to let the older run's settlement still post its completion is load-bearing: I tried gating postAgentEndOnce() on endedRunGeneration === runGeneration, and it breaks the agent-status-ui-prompt cases where agent_settled is the completion boundary with no preceding agent_end (there endedRunGeneration stays 0 while runGeneration is 1). Since agent_settled carries no generation, the stale post cannot be distinguished from that legitimate case — so the current shape is the right call.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When an agent finishes a turn, Orca's Pi integration tells the sidebar "this pane is done". Another Pi extension can immediately start one more run from the settlement event (a memory reminder that asks the agent to continue does exactly that). In that shape the "done" message for the finished run was eaten and the follow-up run's own "done" was never sent, so the sidebar kept showing "working" even though the agent sat idle. This PR makes each run report its own end.
What Changed
src/main/pi/agent-status-handler-source.tsnow dedupes the completion post by the generation of the run that ended (runGeneration/endedRunGeneration/completionPostedGeneration) instead of a singleagentEndReportedboolean thatagent_startreset.agent_startbumpsrunGeneration.agent_end(terminal) recordsendedRunGeneration.postAgentEndOnce()posts whilecompletionPostedGeneration !== endedRunGeneration, so the idle-recheck path and the settlement path still cannot double-post for one run, while a later run is no longer suppressed.checkPendingAgentEnd()dedupes against the same generation pair.src/main/pi/agent-status-extension-nested-run-settlement.test.tsreproduces the event order Pi produces in this shape and asserts the follow-up run's completion is published. It fails on the previous code (agent_start → agent_end → agent_start → message_end → agent_end → message_end, so the host's last word isworking) and passes now.Deliberate call: the older run's settlement still posts its own completion. That run did finish; the bug was the follow-up run's completion being swallowed, not the earlier post.
Why
Pi dispatches extension events in registration order, and a sibling extension's
agent_settledhandler can start the next run synchronously (pi.sendMessage(..., { deliverAs: 'followUp', triggerTurn: true })→session.sendCustomMessage→_runAgentPrompt). The status extension therefore sees the follow-up'sagent_startbefore its ownagent_settledfor the run that just ended. Sinceagent_startreset the shared latch, the older settlement consumed it and the follow-up's own settlement posted nothing.The host keeps the last accepted event per pane, so its last word stayed the follow-up's final
message_end(working) with no later event able to correct it; the row only decayed when the 30-minute freshness window expired. Observed on a remote Orca host with a Pi pane whose session transcript showed the follow-up turn completing normally while the process sat idle.Linked Issue
Fixes #20838
Visual Proof
N/A — no visual change: no rendered UI or interaction code is touched. The fix changes which hook events are published for an unchanged status glyph, and the regression is covered by the unit test above.
Testing
pnpm test src/main/pi→ 167 passed (9 files), including the new regression test.pnpm tc:node,pnpm run check:code-quality:changed(scoped to this diff), andoxfmt --checkclean.agent-hooks/last-status.jsonheld the pane atmessage_end/workingfor 40+ minutes while the Pi process was idle.AI Disclosure
Implemented with the Pi coding agent (deepseek-flash via opencode-go, max reasoning). The root cause was reproduced from live host state and with the existing extension test harness before the fix; the human reviewed the diff.
Review
Agent review summary:
src/main/pi/agent-status-handler-source.tsfeeds the host-side hook publisher, so local, SSH, and remote-runtime panes all take the same path. The bug was observed on a remote host and the fix is host-side, so no client-side assumption is added.pi,omp, andprime-agent. The OMPwillContinuecontract, the legacy idle-recheck path, and the Prime daemon-worker guard are unchanged; all existing Pi extension tests, including the OMP lifecycle and UI-prompt suites, pass.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Nothing here changes the wire format or the hook payloads; only the dedupe key for the terminal
agent_endpost. Security, cross-platform, SSH/remote, mobile, backwards-compatibility, and performance were considered as above.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)