Skip to content

fix(pi): avoid blocking on status hooks - #7802

Closed
mmarabel wants to merge 1 commit into
stablyai:mainfrom
mmarabel:bug-orca-keeps-disconnecting-from-running-pi-age
Closed

mmarabel wants to merge 1 commit into
stablyai:mainfrom
mmarabel:bug-orca-keeps-disconnecting-from-running-pi-age

Conversation

@mmarabel

@mmarabel mmarabel commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Keep Orca's managed Pi status extension from blocking running Pi turns while it reports agent status. Hook events now enqueue ordered background POSTs with a 1s abort timeout instead of awaiting loopback delivery inside Pi event handlers.

Fixes #7791.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test (run under Node 24.17.0; failed on unrelated timing-sensitive tests listed below)
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Additional validation run:

  • pnpm vitest run src/main/pi/agent-status-extension-source.test.ts src/main/pi/titlebar-extension-service.test.ts --maxWorkers=1
  • pnpm run typecheck:node
  • pnpm exec vitest run --config config/vitest.config.ts src/main/ssh/ssh-system-transport.integration.test.ts src/main/attribution/terminal-attribution.test.ts src/relay/git-handler-pull-reconciliation.test.ts src/relay/subprocess.test.ts src/main/daemon/node-pty-fd-leak.test.ts --maxWorkers=1 --testTimeout=60000

pnpm test notes:

  • First exact run under the default Node 26.3.0 failed renderer tests because window.localStorage was unavailable in that unsupported Node runtime.
  • Re-ran under the repo-required Node 24.17.0. The full suite reached 20,792 passing tests but timed out in five unrelated macOS/relay/attribution tests under parallel load. Re-running those failed files serially with an increased Vitest timeout passed (48/48).

AI Review Report

Reviewed the Pi managed-extension path for blocking behavior, event ordering, and regression coverage. The main risk checked was that Pi awaits extension event handlers, so awaited hook POSTs can pause active agent work if Orca's loopback hook server stalls or restarts. The change keeps events ordered via a promise queue while returning synchronously from Pi handlers.

Cross-platform review: no keyboard shortcuts, labels, UI layout, path separators, or Electron platform APIs changed. The generated extension uses standard fetch, AbortController, and timer APIs in the Pi Node runtime, and keeps existing endpoint-file parsing for macOS, Linux, and Windows endpoint formats.

SSH/remote/local review: this touches local Pi/OMP managed extension source only; remote hook routing and SSH relay handling are unchanged. Agent compatibility checked for Pi and OMP shared extension generation and existing titlebar-extension tests.

Security Audit

No new command execution, filesystem writes, credentials, IPC channels, or dependency changes. The POST body remains the existing JSON hook envelope sent to localhost with the existing hook token. The new abort timeout reduces denial-of-service/stall risk from an unavailable or wedged local hook receiver. Endpoint parsing and token handling are unchanged.

Notes

Agent-specific change for Pi/OMP managed hooks. Follow-up risk is limited to status delivery timing: because posts are now backgrounded, status updates may arrive shortly after the Pi event handler returns, but ordering is preserved within the queue.

X handle: N/A

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR modifies the generated Pi agent status extension source to make hook POST delivery non-blocking. It introduces a fixed timeout constant and a serialized post queue, reworks the post() helper into a fire-and-forget function chained through a new postOnce() that uses AbortController to cancel slow requests, and swallows delivery errors. Pi lifecycle event handlers are updated to call post() without awaiting it. A new test verifies the generated source contains these non-blocking, timeout-bounded behaviors.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code and tests address #7791 by making status hook delivery non-blocking and ordered, with a timeout to prevent stalls.
Out of Scope Changes check ✅ Passed The changes stay focused on Pi status hook delivery and regression coverage, with no unrelated feature work evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and accurately summarizes the main change: non-blocking Pi status hooks.
Description check ✅ Passed The description includes all required sections and provides specific testing, AI review, security, and notes details.

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/main/pi/agent-status-extension-source.ts (1)

112-118: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoff

Serialized queue can accumulate a backlog and lag status under bursty events.

post() chains every event onto a single serialized postQueue, and each postOnce() can take up to HOOK_POST_TIMEOUT_MS (1s). During high-frequency streaming (e.g. rapid tool_execution_start/tool_call), events can arrive faster than the queue drains, so reported status may fall progressively behind the agent's real state and the tail of pending posts grows for the session lifetime.

Since these are point-in-time status snapshots, consider coalescing — e.g. dropping/replacing a pending update for the same event type rather than delivering every queued item in order. Not blocking; the current approach is correct, just potentially wasteful under load.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d08350ff-e2c5-4e49-a230-971223398b66

📥 Commits

Reviewing files that changed from the base of the PR and between 745765b and 25ad861.

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

@AmethystLiang

Copy link
Copy Markdown
Contributor

Thanks for identifying the awaited Pi hook path. Closing this as superseded by merged PR #8355.

#8355 keeps the non-blocking, one-second-bounded delivery intent from this PR, but replaces the serialized promise backlog with a strict bound of one active request plus one latest pending snapshot. It also adds executed generated-extension behavior tests and fixes the separate session_shutdown false-completion path from #7791.

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]: Orca keeps disconnecting from running Pi agents

3 participants