Skip to content

Keep a Pi chat awake while its background subagents run - #38207

Merged
brennanb2025 merged 8 commits into
mainfrom
brennanb2025/pi-subagent-idle-stop
Nov 5, 2026
Merged

brennanb2025 merged 8 commits into
mainfrom
brennanb2025/pi-subagent-idle-stop

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Tracked in #28710 (the background-subagent report; the idle-window setting in that issue is separate).

Problem

A Pi coordinator in a native chat can start a pi-subagents worker in the background and end its turn. Orca's idle sweep then stopped that chat 30 quiet minutes later, even though the worker was still running. On Windows the workers are child processes of Pi, so they died with it: the run stayed "running" on disk, no result came back, and nothing woke the coordinator. The same flow in a terminal tab finished a 45-minute worker. The reporter saw 9 of 11 long workers die 29–33 minutes after the coordinator's last turn.

Why: the sweep stops an idle agent unless it still owes work, and nothing told it about Pi's background work.

What changes for users

A Pi chat with background subagents still running is no longer stopped. Once the work and its wake-up turn are done, it stops after the usual 30 quiet minutes. Nothing new appears on screen, and clear, compaction and Stop behave as before.

How it works

  • The registry: Pi extensions that keep detached work alive already declare it in a shared session-liveness registry, and Pi hosts ask that registry right before evicting an idle session. pi-subagents registers there on every session start and releases on shutdown or reload. It counts queued and running background runs, nested children, undelivered results and the pending wake turn.
  • The bridge: Orca runs Pi as a child process, so it loads a small bridge extension into native-chat Pi launches only (written to Orca's app data, passed with --extension). The bridge installs the registry when it loads. Each bridge instance announces itself with a fresh id on its status line and watches a private folder Orca made for that child.
  • The question, right before an idle stop: Orca drops one request file named for the current bridge instance into that folder. The bridge evaluates the registry at that moment and answers on its status line.
    • "idle" (the only answer that allows the stop): a timely answer from the current instance.
    • "active": keeps the chat and restarts its idle window.
    • No answer within 5 seconds, a watcher error, or no ready instance: skips this sweep and asks again on the next one.
    • Not under session lock: the question is asked outside the session lock, so it never delays a send, Stop or close. The sweep rechecks the chat before stopping it.
  • Cleanup: the folder is removed when the child exits. A folder left by a crashed Orca is removed only once the Orca process that created it is gone.

Differences from the common pattern

  • Intended: the question crosses a process boundary (a request file and a status-line answer) instead of an in-process call. Native chat runs Pi as a separate process. A Pi prompt, slash command or dialog would be visible to other extensions or could reach the model, so the probe uses a private folder instead.
  • Intended: only a fresh "idle" allows a stop, and silence never does. Orca can pause reading Pi's output under journal backpressure, and a missed notification must not stop a live worker. The cost is that a broken bridge keeps a quiet chat running until Pi exits or the user stops it.
  • Intended: no cap on how long declared work keeps a chat awake. The reference Pi host has none, and no other Orca agent has one today.
  • Intended: no per-run subagent rows for Pi. The registry gives one yes/no per session and declares itself idle-eviction-only.

Not covered

  • Pi without pi-subagents, or a version without the registry: still idle-stops after 30 quiet minutes, as before (nothing registers as busy).
  • The bridge or its folder can't be prepared: that chat launches without it and is unprotected; Orca logs a warning.
  • The bridge file fails to load after it was prepared (deleted or quarantined in between, or rejected by a future Pi): Pi exits at startup, so that chat cannot start.

Review path

Full path: the lifecycle of a native-chat agent process (idle stop). Plan reviewed by the independent Claude and Codex reviewers. Two design questions went to the independent decider:

  • how the stop is confirmed: ask at stop time;
  • how the question travels: a private folder rather than a Pi dialog or command.

Tests

  • Bridge, against a real folder and file watcher: providers that register after load, another session's provider, a provider that throws, a registration the reference host rejects, and a reloaded predecessor's requests left unanswered.
  • Orca's probe client, fed the bridge's recorded real output (Windows, Pi 1.5.0 + pi-subagents 0.84.0): "unknown" before ready, "busy" while a worker ran, "idle" after its wake turn, "unknown" after shutdown and on an unanswered request, and the unprotected path for a child launched without the bridge.
  • Idle sweep: a running agent is stopped only after a fresh "idle". "busy" keeps it and "unknown" skips.
Files Added Deleted Net
Test 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​297
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​399 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​375

The idle sweep stopped a Pi chat 30 quiet minutes after its last turn even
while pi-subagents workers it had started in the background were still
running. On Windows those workers are children of Pi and died with it, so
the coordinator never got their results.

Pi extensions with detached work already declare it through the shared
session-liveness registry that Pi hosts read before idle eviction, and
pi-subagents registers there. Native chat runs Pi as a child process, so
Orca now loads a small bridge extension into native-chat Pi launches that
installs that registry at load and reports, over Pi's RPC stdout, whether
the session has active providers. The Pi adapter keeps the last report and
the idle sweep treats it like provider-held sends: the chat is not stopped
while work is declared, and idles a full window after it ends. Nothing else
reads it, so clear and compaction are unchanged.

Tracked in #28710.
@brennanb2025
brennanb2025 marked this pull request as ready for review November 4, 2026 19:23
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The change adds a Pi extension that reports background-work status through filesystem probes. Pi launch setup passes the extension and probe directory to the child process, and RPC dialog callbacks route its status frames to background-work state. The session adapter exposes idle confirmation to the agent session idle sweep. The sweep asks for confirmation before stopping a running child, then rechecks that the child remains eligible.

Merge Risk: Minimal · up to edce9

No actionable regression was established, so the change is mergeable with normal checks.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Inconclusive The description follows the template well. It has a plain-language problem statement, a user-facing before and after, a mechanism section, the reasons for the design choices, tests, and a not-covered … Add an ELI5 section in plain language. Add a Visual Proof section with a before and after for the sidebar-visible stop behavior, or write N/A with a reason. Replace the empty 'Fixes #' line with the issue number, or confirm the issue link m…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title "Keep a Pi chat awake while its background subagents run" matches the main change. The PR adds a bridge that asks Pi's session-liveness registry whether background work is active before the …
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.
Full details: Title check

Explanation

The title "Keep a Pi chat awake while its background subagents run" matches the main change. The PR adds a bridge that asks Pi's session-liveness registry whether background work is active before the idle sweep stops a native-chat Pi session. The title is short, specific, and states the user-facing effect.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 19 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Full details: Description check

Explanation

The description follows the template well. It has a plain-language problem statement, a user-facing before and after, a mechanism section, the reasons for the design choices, tests, and a not-covered list. The Linked Issue section cites #28710, which is referenced as the background-subagent report, and the description notes the issue's idle-window setting is separate. The ELI5, Visual Proof, Risk level, Review, and Checklist sections are missing or unfilled. The Visual Proof section needs either a before and after for the behavior change or a N/A reason. The Risk section needs a Level value. The Testing checkboxes are unchecked and the AI Disclosure section is blank. The Linked Issue section uses 'Tracked in' and 'Fixes #' is empty, so the template's required issue link is not clearly satisfied.

Resolution

Add an ELI5 section in plain language. Add a Visual Proof section with a before and after for the sidebar-visible stop behavior, or write N/A with a reason. Replace the empty 'Fixes #' line with the issue number, or confirm the issue link meets the outside-contributor rule. Set the Risk Level to Low, Medium, or High. State the revert path. Check the Testing boxes that apply, and note which platforms were tested locally. Complete the Checklist items, or mark them with a reason. Fill in the AI Disclosure section if an AI model was used, or confirm the author is a StablyAI team member.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9479dd88-f66d-4fe0-af9e-785c2568a3bb
Commits

Reviewing files that changed from the base of the PR and between 075fef9 and edce953.

Files ignored due to path filters: 1
  • src/main/runtime/__snapshots__/structured-agent-launch-parity.test.ts.snap is excluded by !**/*.snap
Files selected for processing: 2
  • src/main/native-chat/agent-session-wire/structured-agent-session-idle-sweep.ts
  • src/main/runtime/structured-agent-launch-parity.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Keep the bridge ticking after a failed report so the next answer is
re-derived, validate registrations the same way the reference host does,
log a bridge that could not be written, and use type guards in its test.
A cached report could be stale when work starts between samples, so the
idle sweep now asks a running child's provider right before stopping it
and stops only on a fresh idle answer. Pi's bridge answers requests that
Orca drops into a private per-child folder, replying on its status line,
so the probe never becomes a dialog or a prompt other extensions or the
model would see. A child launched without the bridge stops as before;
one with the bridge but no ready instance is left for the next sweep.
Recorded on Windows from Pi 1.5.0 with pi-subagents 0.84.0 and the bridge:
ready, active while a worker ran, idle after its wake turn, and shutdown.
…nswers

A launch abandoned before Pi started left its prepared folder behind, so
the bridge now creates the folder itself. An answer with no probe pending
could throw while reading Pi's output; replies are now matched exactly and
anything else times out as unknown. Leftover folders are reclaimed only
when their Orca process is proven gone.
The idle stop now re-reads the chat idle setting after the provider's
answer, so switching a chat to Never during the probe keeps its agent.
Normalize each Pi launch's private probe folder in the launch parity
snapshots, which now include the background-work bridge.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: done on edce953, full path. Tracked in #28710.

What broke: a Pi native chat waiting on a pi-subagents background worker looked idle to Orca. After 30 quiet minutes the idle sweep stopped Pi, killing the worker (Windows) or losing its wake-up turn, so the result never came back.

What changes: before stopping a quiet Pi chat, Orca asks Pi, through a small bridge extension and a private per-chat folder, whether a registered provider (pi-subagents) still owns work. Only a fresh "idle" answer from the current bridge lets the sweep stop the chat; "active" keeps it running and silence or a malformed reply skips that tick. Once the work ends the chat still idle-stops a full window later. Other agents are unchanged.

Review: independent Claude Opus-medium and Codex-high reviewers, 9 rounds, both ready at edce953 with no open P0/P1. Design rulings by an independent decider: ask at eviction rather than cache (D1); filesystem request plus status reply as the transport (D2); keep it as one fix (D3). Reference comparison done: the host-side session-liveness registry is the common pattern, probed at eviction; our only addition is the transport across the subprocess boundary. Deferred: no log when a bridged Pi never reports ready (P3); no cross-agent cap on how long open work keeps a chat awake (listed separately, out of scope).

QA (real app runs):

  • Windows, branch vs main, Pi 1.5.0 + pi-subagents 0.84.0: with the subagent's control notices off, main idle-stopped Pi and its worker about 30 min in with no completion; the branch kept Pi alive, the worker finished and the chat replied FINISHED. With notices on (the plain flow) neither copy idles, because each notice wakes the chat.
  • Windows branch: extension reload mid-run keeps the worker; release check (Pi idle-stops about 34 min after work ends, next message starts a fresh Pi); /clear during a worker; Pi without pi-subagents; a Pi extension that fails to load shows the same startup message as main and leaves no folder behind. Claude and Codex chats still idle-stop when untouched.
  • macOS (this Mac): Pi alive at 36 min, worker finished, chat replied FINISHED; Pi idle-stopped about 35 min later and say OK started a fresh Pi. Probe folders cleaned up on stop and after quit on both platforms.
Windows main at 45 min (bug) Windows branch at 45 min macOS branch at 45 min macOS after release
main branch mac mac release

Noticed, not part of this PR: picking Pi in the New tab menu opens a Pi terminal, not a native chat (the chat is reached via Configure Pi → Launch chat).

@brennanb2025
brennanb2025 merged commit f249010 into main Nov 5, 2026
54 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/pi-subagent-idle-stop branch November 5, 2026 03:50
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