Skip to content

fix(pi): keep status hooks off the Pi turn critical path - #8355

Merged
AmethystLiang merged 1 commit into
mainfrom
bug-orca-keeps-disconnecting-from-running-pi-age
Jul 12, 2026
Merged

AmethystLiang merged 1 commit into
mainfrom
bug-orca-keeps-disconnecting-from-running-pi-age

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Orca keeps disconnecting from a running Pi agent. Pi awaits its extension event handlers, and Orca's installed status extension awaited each loopback status post(). When the Orca receiver stalled (app restarting, loopback briefly unavailable), that awaited post hung the Pi event handler — stalling or disconnecting the running turn.

A second cause: session_shutdown was mapped to done. Pi emits session_shutdown on reload / new / resume / fork while the PTY stays alive, so a live turn could be marked complete prematurely.

Fix

  • Take status delivery off the Pi critical path. post() is now fire-and-forget (returns void). It stores the latest pending snapshot and drains through a single active request (drainPosts). A stalled receiver can no longer hold the turn.
  • Bound the delivery. At most one active request + one latest-pending snapshot (latest-only coalescing), with a 1s AbortController timeout so a hung request is abandoned and the newest status still proceeds. WSL curl fallback preserved.
  • Only agent_end proves completion. Dropped the session_shutdown handler and stopped normalizing session_shutdown → done. Real process exit is still cleared by PTY teardown.
  • Split the generated handler registrations into agent-status-handler-source.ts (keeps both transport and handler source under the max-lines limit).

Tests

  • New generated-extension tests: pending-fetch does not hold handler open; latest-only bound (one active + one pending); 1s timeout aborts and advances the latest status; session_shutdown handler is not registered.
  • Shared normalizer: session_shutdown → no status; agent_end remains authoritative done.
  • Added reliability gate agent-status.pi-hook-liveness.
pnpm exec vitest run --config config/vitest.config.ts \
  src/main/pi/agent-status-extension-source.test.ts \
  src/main/agent-hooks/server.test.ts --maxWorkers=1

→ 2 files, 238 tests passed. pnpm typecheck passes.

Made with Orca 🐋

Pi awaits its extension event handlers, so an awaited loopback status
post that stalls (Orca restarting / receiver unavailable) blocked the
running Pi turn and disconnected it. Make post() fire-and-forget with a
latest-only pending slot drained by a single active request and a 1s
AbortController timeout, so a stalled receiver can never hold the turn.

Also stop treating session_shutdown as turn completion: Pi emits it on
reload/new/resume/fork while the PTY stays alive, so only agent_end
proves done (real exit is cleared by PTY teardown). Split the generated
handler registrations into agent-status-handler-source.ts.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@AmethystLiang, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5796bdff-b32a-4371-ba54-b4ed7419445d

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf9c38 and 2f202ec.

📒 Files selected for processing (6)
  • config/reliability-gates.jsonc
  • src/main/agent-hooks/server.test.ts
  • src/main/pi/agent-status-extension-source.test.ts
  • src/main/pi/agent-status-extension-source.ts
  • src/main/pi/agent-status-handler-source.ts
  • src/shared/agent-hook-listener.ts

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.

@AmethystLiang
AmethystLiang merged commit 21c0e45 into main Jul 12, 2026
3 checks passed
@AmethystLiang
AmethystLiang deleted the bug-orca-keeps-disconnecting-from-running-pi-age branch July 12, 2026 05:04
@AmethystLiang

AmethystLiang commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Post-merge tracking: this resolves #7791. The issue is closed, #7802 is closed as superseded, and mixed PR #7838 is also closed; its separate #7813 browser bug remains open for a focused fix.

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Pi awaits its extension event handlers, so an awaited loopback status
post that stalls (Orca restarting / receiver unavailable) blocked the
running Pi turn and disconnected it. Make post() fire-and-forget with a
latest-only pending slot drained by a single active request and a 1s
AbortController timeout, so a stalled receiver can never hold the turn.

Also stop treating session_shutdown as turn completion: Pi emits it on
reload/new/resume/fork while the PTY stays alive, so only agent_end
proves done (real exit is cleared by PTY teardown). Split the generated
handler registrations into agent-status-handler-source.ts.

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.

1 participant