Skip to content

fix(pi): claim the status pane when the inherited owner PID is dead (STA-5245) - #16631

Merged
nwparker merged 4 commits into
mainfrom
brennanb2025/sta-5245-pi-status-dead-owner
Sep 11, 2026
Merged

nwparker merged 4 commits into
mainfrom
brennanb2025/sta-5245-pi-status-dead-owner

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

When a Pi-family agent restarts with an exited owner PID in its environment, the old guard suppresses every handler permanently. Probe the owner PID before suppressing: reclaim an exited owner (ESRCH), retain suppression for a live or unverifiable owner, and keep Prime frontend suppression intact. This preserves the contributor fix while reconciling current main's lifecycle handling.

Fixes #16109.

Verification on the pushed head

Head: c345037f4450ac6b73617847a2f2e5bbd4080780.

  • Real Pi loader, real exited/live child processes, and HTTP delivery pass on native macOS, Linux and Windows: https://github.com/stablyai/orca/actions/runs/34573576672 . All three generated variants are covered.
  • Actual OMP18.0.4 loader and ExtensionRunner on the connected Linux SSH host: 15/15 repeated baseline, dead-owner recovery, live-owner suppression, reload and successor-process checks pass.
  • Actual OMP18.0.4 in Windows Ubuntu24.04 WSL: the same 15/15 checks pass.
  • Actual Prime1.9.1 bundled public SDK on native Windows: 18/18 checks pass, including three repetitions of frontend suppression as well as the five owner scenarios.
  • Installed Windows Orca receiver, native Prime: the baseline guard emits no requests. The fixed extension emits agent_start and agent_end, receives HTTP204, and the installed last-status.json changes working → done for our own verification pane.
  • Installed Windows Orca receiver, WSL OMP: baseline emits nothing; fixed produces the same persisted working → done. Guest loopback was unavailable, exercising the existing real Windows curl.exe fallback successfully across the host boundary.
  • 163 Pi tests passed after main reconciliation; all10 focused recovery tests passed after adding EACCES, EINVAL and uncategorized-error coverage. Node typecheck and commit lint/format/React-doctor hooks passed. Broader CI remains separately visible below.

All host tests used isolated runtime files and our own terminal. No user agent configuration was changed. The installed receiver proof forwards actual network traffic; the persisted state comes from Orca, not a fixture receiver. Initial harness errors (unbundled Prime imports, expecting HTTP200 rather than204, and using idle rather than Orca's done) were corrected before counting the passing runs.

Scope and limits

The generated source executes on the agent's own host. No renderer, IPC or remote wire change. This verifies the reported dead-owner failure and recovery across native and WSL execution, including real installed hook delivery. Loader lifecycle events and successor processes are exercised directly; it does not claim every interactive /restart implementation or model provider was tested. Reuse of an exited PID by an unrelated live process remains a pre-existing limitation of PID-only ownership; unverifiable liveness intentionally keeps suppression.

Actual Pi TUI and Orca spinner proof

Loaded this PR's generated status extension into real Pi0.83.0 inside a hidden, CDP-verified Orca Electron app. Each launch inherited a PID from a child that had actually exited. The model was a deterministic local streaming endpoint; the interactive Pi TUI, agent lifecycle, hook transport and Orca UI were real.

Before: replaced only the owner condition with the original guard. Pi says Working while Orca incorrectly shows Idle; no hook status exists for the pane.

Pi working but Orca idle before

After: the unmodified generated extension reclaims the dead owner. Orca's workspace and tab spinners run while Pi is Working; the accepted state is working with hook provenance.

Pi and Orca working together after

Completion: the real provider response arrives, both spinners stop, Orca shows Pi ready, and the accepted state is done.

Pi ready after completion

The surrounding renderer was the isolated #20070 worktree (no owner-related renderer changes); the injected status source was generated directly from this PR's checked head. Full PR CI is green. Review found no remaining defect in the reported recovery path; the scope limits above remain explicit.

…STA-5245)

The managed pi/omp/prime-agent status extension suppressed itself whenever
ORCA_PI_STATUS_OWNED held a PID other than its own, with no check that the
owner still existed. A restart leaves the previous owner's PID in the
inherited env, so every later load returned early and the pane stopped
reporting status permanently.

Probe the owner before suppressing. Only ESRCH proves it is gone; any other
probe result keeps suppression so a live foreign owner still cannot
double-report. This mirrors the tri-state in
main/agent-hooks/managed-hook-owner-identity.ts, which the extension cannot
import because it loads inside the pi/omp runtime with no Orca deps.

Also extracts the generated-source test harness into its own module so the
suite stays under the max-lines limit.
@coderabbitai

coderabbitai Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The status handler now validates inherited owner PIDs and probes process existence before suppressing status-hook registration. Invalid or dead owners can be replaced by the current process, while EPERM continues to suppress registration. A shared VM-based test harness now mocks runtime dependencies, supports Pi, OMP, and prime-agent environments, captures hooks, and supports reloads. Tests cover restart ownership behavior.

Merge Risk: 🔵 Low · up to 9479e

The change restores status reporting after a dead inherited owner, but PID comparison can still mishandle equivalent numeric values with different string formatting and unnecessarily suppress status handlers in a bounded edge case. The PR is mergeable with explicit owner awareness or a small follow-up to normalize PID comparisons.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the Pi status-pane ownership fix and the dead inherited owner PID scenario. It is concise and directly matches the main change.
Description check ✅ Passed The description clearly explains the problem, solution, scope, linked issue, visual behavior, and extensive verification across Pi, OMP, Prime Agent, native platforms, and WSL. It does not reproduce a…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/pi/agent-status-handler-source.ts (1)

83-85: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Compare numeric PIDs before suppressing registration.

ownerPid !== selfPid compares strings. For example, "00123" is treated as a foreign live owner when process.pid is 123, so registration is skipped. Compare the validated numeric PID with process.pid.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8fe8bffa-786f-47c1-a025-3d3aeee36dde

📥 Commits

Reviewing files that changed from the base of the PR and between 44e8b33 and 9479e4d.

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

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: gates green except one, not marking merge-ready

Head reviewed and validated: 9479e4dec4abe855ab04b47afc930269ce3e4e93 (matches the live PR head).

Live reproduction and retest — same rig both times

Real omp v17.0.5 on macOS in an isolated profile, running the extension generated from this branch. Signal is POSTs arriving at the agent-hooks receiver.

Case before fix after fix reviewed head
control, no owner marker 3 3 2–3
stale / dead owner PID 0 3 3
live foreign owner (must stay suppressed) 0 0 0
out-of-range marker (2**31) 0 0 2

Control counts vary 2–3 because post() is fire-and-forget and races process exit — pre-existing, identical on both sides. The bug signal (0 vs ≥2) is unambiguous.

Review loop — 1 round, clean, and it caught a real gap

An orchestrated codex reviewer (gpt-5.6-sol, effort high) found that the first version of the probe misread an out-of-range marker: process.kill(2**31, 0) throws ERR_INVALID_ARG_TYPE, not ESRCH, so the guard read it as "alive" and kept the pane suppressed forever — the exact bug class this PR fixes. It tightened the range check to Number.isSafeInteger(parsed) && parsed >= 1 && parsed <= 0x7fffffff and added mutation-backed tests.

Verified independently rather than taken on report: pnpm tc (exit 0), oxlint src/main/pi/ (clean), pnpm test src/main/pi/ (69 passed). Mutation check re-run — with the source fix reverted to the origin/main version, 6 of the new tests fail.

Windows — verified, not assumed

The reported environment was Windows + WSL2, so process.kill semantics on win32 were the one real platform risk. Checked on a real Windows host (win32, node v24.18.0): self ok, missing PID ESRCH, 0x7fffffff ESRCH, PID 4/System EPERM, and an exited child raises ESRCH even while the parent still holds the child handle. No live process ever produced ESRCH, and protected PIDs raise EPERM, so suppression holds.

It also confirmed both range bounds are load-bearing on Windows: 2**31 throws ERR_INVALID_ARG_TYPE, and PID 0 returns ok rather than the POSIX process-group meaning.

Performance

Deterministic count of the new probe per real omp run: 0 calls in the common case — the ownerPid && short-circuit means the fix costs nothing at all when no marker is inherited — and exactly 1 per extension registration when a foreign marker exists. Never on an event or hook path.

CI

Green on 9479e4dec4: 47 pass, 0 fail. Two shards failed on the first attempt in unrelated suites (browser-route-h3-egress, browser-route-webrtc-egress), a different pair than the two unrelated suites that failed on the previous head (worktree-git-common-watch, updater.startup-scheduling). All four pass locally and all passed on re-run with no code change — flakes, not this PR.

The one gate I could not close

Electron UI validation is blocked, so this is not marked merge-ready. The user-visible effect is the sidebar/dashboard dot for a pi-family pane, which needs a live authenticated omp/pi agent inside a dev Orca instance. omp v17.0.5 cannot authenticate on the validation host: it sends x-api-key, and the only Claude auth available there is a bearer relay that answers 401 invalid x-api-key.

What that leaves untested is narrow: this PR changes no renderer, IPC, or main-process code, and the agent-hooks POSTs that feed the UI were proven to arrive. The unverified span is Orca's existing, unmodified render path.

To close it: run a dev Orca with a pi/omp pane authenticated against any provider omp supports, set ORCA_PI_STATUS_OWNED to a dead PID in that pane's env, and confirm the worktree dot reports live status instead of going silent.

Known limitation

A PID recycled onto an unrelated live process still reads as alive and keeps the pane suppressed. Strictly better than today's permanent silence; closing it would need a start-time-qualified marker written by main at launch, which is out of scope here.

@nwparker nwparker 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.

Reviewed owner validation, conservative error handling, Prime frontend suppression, reload and host boundaries. Actual Pi native3OS CI, OMP Linux/WSL, Prime Windows, installed Windows receiver delivery and rendered Pi/Orca spinner before-after all pass. Live/unverifiable owners remain suppressed; PID-reuse limitation is documented. Full PR CI green at c345037. No remaining finding in this fix.

@nwparker
nwparker merged commit 78e985c into main Sep 11, 2026
30 checks passed
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] pi-family agents stop reporting status permanently after an agent restart (dead-owner PID guard in orca-agent-status.ts)

2 participants