Skip to content

fix(pi): keep re-posting a child-held turn so async children never look stale - #48146

Merged
nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/46585-pi-held-turn-heartbeat
Nov 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
Pr1p:fix/46585-pi-held-turn-heartbeat

Conversation

@Pr1p

@Pr1p Pr1p commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When a Pi agent hands work to background child agents, Orca correctly keeps its turn marked "working" until those children finish. But the lead agent goes quiet while it waits, and after 30 minutes of silence Orca treats the turn as stale. On a paired server that meant the row could flip to a false "Done" and the running children disappeared from the list. Now the Pi status extension re-sends "still working, these children are running" every 10 minutes while children hold the turn, so the status never goes stale.

What Changed

Before: postAgentEndOnce() held back agent_end while children were running but posted nothing in its place. The extension only posts on events, so a turn whose reply ended with long-running children was silent until the last child settled. After the host's 30-minute freshness window (AGENT_STATUS_STALE_AFTER_MS), a paired server fell back to the PTY title, published a title-only done with no subagents, and re-pulling the workspace dropped the live child rows (#46585).

After: while isHeldByChildren() is true, the extension re-posts the held status through the existing postSubagentsUpdate() path every AGENT_STATUS_STALE_AFTER_MS / 3 (10 minutes). The provider normalizer restates the previous working payload and merges the live roster, so each repost is fresh evidence of exactly the held state.

Mechanism:

  • The unref()'d timer (heldTurnRepostCheck) lives on the shared SubagentRoster, next to runnerExitCheck. It only exists while children hold a turn.
  • It is synced when a child starts, when a child is forgotten, at run close-out, and on session_start. It is cleared by resetSubagentRoster() and by session_shutdown. On a Pi reload the old registration clears its timer at shutdown and the new one re-arms on session_start, so there is only ever one timer.
  • Each child lifecycle event (start, completion, runner exit) stamps lastChildEventAt. If a day passes with no child event, the reposts stop and normal host freshness decay takes over. That way a child that never reports again cannot pin the pane as working forever. The day bound matches pi-subagents' abandoned-slot release window (MAX_ABANDONED_SLOT_RELEASE_AFTER_MS = 24h, checked in pi-subagents origin/main).
  • The test harness now passes Date into the VM context so the generated extension can read the clock.

Why

#46585 suggests two fixes. This PR does the first one, where the status is produced: it keeps the status fresh while a turn is legitimately held open. The second one, how a server handles stale evidence, is covered separately by #46903 and #46968. This PR does not touch the 30-minute freshness constant, the desktop decay rule, or the server projection. Each repost is a real hook delivery stamped at receipt, not a re-dated old row. The post queue is latest-only, so repeated posts cannot make it grow.

Linked Issue

Fixes #46585

Visual Proof

N/A. Nothing visible changes in Orca's own UI. The change repeats an existing background status post while children hold a turn. The user-visible symptom (a false "Done" after 30 silent minutes on a paired server) needs a real Pi chat and 30 minutes of wall-clock silence, so the scripted fake-timer extension tests below verify it instead.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

agent-status-extension-held-turn-repost.test.ts runs the generated Pi extension in the existing VM harness with fake timers:

  • Child-held turn: no agent_end is posted. After two intervals there are two subagents_update posts carrying child-1. When the child completes, the real agent_end posts and the reposts stop.
  • Pi reload partway through an interval: still exactly one repost per interval, so no duplicate timers.
  • A child that goes silent for 24h: reposts stop at the cap (143 reposts), and no agent_end is invented.

Red/green: with only the three source files reverted to main, all 3 new tests fail. With the change, all of src/main/pi/managed-extensions/agent-status/ passes (23/23). Platform: macOS (vitest). CI gates were run on the touched files and are clean: anti-slop oxlint, code-quality native oxlint, ast-grep, the changed-code quality gate, oxlint, and oxfmt.

Performance

None, because the change runs inside the Pi extension process, not in Orca's main process or renderer. At most one unref()'d timer exists, and only while children hold a turn. It makes one small, existing hook post every 10 minutes, and there is no timer when idle. Microbenchmark of the work added to each child event (Date.now() plus the O(1) active.size / timer-null check): about 35 ns typical, and about 253 ns in the adversarial case where the timer is armed and cleared on every event.

Risk

Level: Low

The riskiest part is a timer that outlives its turn. It is cleared on every teardown path (child settle, run close-out, roster reset, session shutdown), it is never created while idle, and it stops on its own after a day with no child events. If it misfired, the worst case is one extra subagents_update that restates the live state. It can never post a completion. Older hosts already accept subagents_update. Back out with a plain revert.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: no new inputs, paths, or network endpoints; it reuses the existing local hook post. Cross-platform: plain timers, no platform-specific code. Remote/SSH: posts go through the existing hook path, so local and remote hosts both work. Mobile: consumes the same host status evidence, which now stays fresh. Backwards compatibility: subagents_update is an existing event.

Original fix by @Pr1p in #48146. Maintainer follow-ups: a single timer per registration across reloads, and a 24h quiet bound in place of sweeping runner PIDs.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Pi status extension now reposts the child roster every one-third of the agent-status stale interval while children hold a turn. It synchronizes the timer on session start and child lifecycle changes, and clears it when the hold ends or the roster resets. Reposting stops after 24 hours without a child event. Tests cover child completion, Pi reload, and the 24-hour limit.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 2748e

Pi leads with still-running async children now repost their held status every 10 minutes, so they should no longer go silent past the 30-minute freshness window. The change is small and covered by fake-timer tests for the repost, reload and 24-hour-cap cases. I found no merge-blocking risk, and the timer overhead is negligible.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Directly linked issue #46585 is open. Its requirement: a Pi lead with live async children must stay working, or at worst show "No recent update", with its child rows after 30 minutes of lead silence. …
Out of Scope Changes check Passed All changes since the previous review serve the held-turn repost objective for #46585:
- roster-source: the repost timer, its sync and clear helpers, the lastChildEventAt field, and the 24-hour quiet …
Title check Passed The title names the fix (keeping a child-held turn re-posted so async children never look stale) and the scope (pi). It matches the main change: a periodic held-turn status repost in the Pi extension,…
Description check Passed The description follows the template closely. It has ELI5, What Changed (before/after and mechanism), Why (alternatives and related PRs), Linked Issue (Fixes #46585), Visual Proof (N/A with reason), T…
Full details: Linked Issues check

Explanation

Directly linked issue #46585 is open. Its requirement: a Pi lead with live async children must stay working, or at worst show "No recent update", with its child rows after 30 minutes of lead silence. The issue offers two remedies. This PR implements the first: the extension reposts held status and the child roster before the 30-minute freshness window expires.

Reviewed head, src/main/pi/managed-extensions/agent-status/agent-status-subagent-roster-source.ts:

  • HELD_TURN_REPOST_INTERVAL_MS = AGENT_STATUS_STALE_AFTER_MS / 3, which is 10 minutes.
  • syncHeldTurnRepostCheck() arms a timer only while isHeldByChildren() is true. The timer is unref()'d.
  • The callback calls postSubagentsUpdate() when waiting is true, then re-syncs.
  • Teardown clears the timer in resetSubagentRoster, forgetSubagent, and the session-shutdown path.
  • Child start and session_start re-sync the timer.

The code also adds HELD_TURN_MAX_QUIET_MS = 24 hours. Reposts stop after 24 hours without child lifecycle events. The issue scenario uses children that run well over 30 minutes. Stopping after 24 hours of child silence is a bounded design choice, not a violation of the stated scenario. The current PR description does not mention this cap. The description is therefore not fully current with the code.

The test file (held-turn-repost.test.ts) covers: two reposts at 10 and 20 minutes with the child roster; no repost timer after a Pi reload; and repost stop after 24 hours with no child events. Earlier coverage of the no-child immediate agent_end path is described in the PR, but was not re-read here. Its status is not needed for this verdict.

No unmet coding requirement is demonstrated. Server-side projection and the desktop decay rule are out of scope, as the issue's first remedy allows.

Full details: Out of Scope Changes check

Explanation

All changes since the previous review serve the held-turn repost objective for #46585:

  • roster-source: the repost timer, its sync and clear helpers, the lastChildEventAt field, and the 24-hour quiet cap. These are timer mechanics.
  • handler-source: one syncHeldTurnRepostCheck() call in the non-OMP session_start path. This re-arms the timer after reload.
  • session-boundary-source: clearing the timer on shutdown when the replacement registration re-arms it, and recording lastChildEventAt when parked children are restored.
  • test-harness: a typing change to the VM context that adds Date. This supports the fake-timer tests.
  • New test file: covers the repost behavior.

The 24-hour cap and the reload re-sync extend the timer lifecycle. They do not touch the freshness constant, the desktop decay rule, or the server projection. The PR description does not mention the cap, but a missing description entry does not make the code unrelated. No unrelated change is demonstrated.

Full details: Title check

Explanation

The title names the fix (keeping a child-held turn re-posted so async children never look stale) and the scope (pi). It matches the main change: a periodic held-turn status repost in the Pi extension, with a 24h quiet bound and timer lifecycle handling. The title is specific and single-sentence. Its length (77 characters) is acceptable.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed (before/after and mechanism), Why (alternatives and related PRs), Linked Issue (Fixes #46585), Visual Proof (N/A with reason), Testing (tests listed, red/green evidence), Performance (None, with reasoning and a microbenchmark), Risk (Level: Low, with backout), AI Disclosure section left empty, Agent skill boundary checked, Notes, and Checklist. The AI Disclosure section is blank, which is acceptable for a team member but should be confirmed. The Testing checkboxes say manual testing is unchecked, which is consistent with the explanation given.

  • 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: d5799c13-b67e-4bd1-aa3d-d5b2a06d4a08
Commits

Reviewing files that changed from the base of the PR and between b516f6f and 2748e75.

Files selected for processing: 5

  • src/main/pi/managed-extensions/agent-status/agent-status-extension-held-turn-repost.test.ts
  • src/main/pi/managed-extensions/agent-status/agent-status-extension-test-harness.ts
  • src/main/pi/managed-extensions/agent-status/agent-status-handler-source.ts
  • src/main/pi/managed-extensions/agent-status/agent-status-session-boundary-source.ts
  • src/main/pi/managed-extensions/agent-status/agent-status-subagent-roster-source.ts

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

A Pi turn held open by async child agents posted nothing until the last
child settled. After the host's 30-minute freshness window, a paired
server fell back to the PTY title, published a title-only done, and
dropped the live child rows.

While children hold the turn, re-post the held status through the
existing subagents_update path every 10 minutes (a third of the
freshness window). The unref'd timer lives on the shared subagent
roster so a Pi reload keeps a single timer, re-arms on session_start,
and clears on child settle, run close-out, and session shutdown. It
stops after a day without child lifecycle events so a child that never
reports again cannot keep the pane working forever.

Fixes stablyai#46585

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/46585-pi-held-turn-heartbeat branch from b516f6f to 2748e75 Compare November 24, 2026 09:29
@nwparker nwparker changed the title fix(pi): keep posting a held turn while async children run fix(pi): keep re-posting a child-held turn so async children never look stale Nov 24, 2026
@nwparker
nwparker merged commit 2eeb09a into stablyai:main Nov 24, 2026
58 of 59 checks passed
lab-agent-np Bot added a commit to nplez1/orca that referenced this pull request Nov 24, 2026
* local(ci): clear the three red fork checks after the 2026-11-24 sync

Issue #463. Every red reproduced locally on f55ccb8 and is fallout from
upstream 7daf01d (PR stablyai#46786 retired ~93% of the test files and several
workflows) plus four collisions between long-standing fork patches and
upstream's new tests.

check-actions-enablement: macos-updater-tests.yml left REQUIRED and
EXPECTED_TRIGGERS. Upstream deleted the workflow with the updater suites it
ran, so the contract named a path no commit carries. Recorded in
LOCAL-PATCHES.md § local(ci); the two fork tests that pin contract-against-tree
went green from the removal.

fork-main-gates: max-lines pruned two dead rows and gained the upstream-owned
orca-runtime-bots.ts exemption its own header already claimed; focus-read,
main-blocking-helper and workspace-path-sync-fs pruned; two orphan ko.json keys
retired; the upstream-file-comments baseline re-based at the new sync base
(4752 lines against 5113, a 361-line shrink) with the growth reason recorded in
`accepted`.

Nightly: the e2e verdict contract follows upstream's unsharded job and its
report path; the two dead ledgers lost entries naming retired files; the tab
focus harness passes `fromKeyboard` as stablyai#46611 defined it; the webhook refusal
assertion follows the shipped copy; and the rate-limits isWatched patch is
split so the timer keeps the fork's gate while an owner return keeps upstream's.

The pi lane's cancel latch is the one real defect the nightly found. This fork
publishes one `subagent_async_state` snapshot per post instead of upstream's
`agent_start:subagent`, so a child starting right after Esc was held as late
work for the whole 15s window (stablyai#47627). The latch gained a marked LOCAL(nplez1)
rule for that shape and upstream's suite is kept and green. The held-turn repost
suite (stablyai#48146) needs the two `subagent:async-*` bindings this fork deliberately
removed, so it is a recorded fork-refactor deletion with its coverage owed.

* local(sync): point the retired repost suite at the commit that deleted it

* local(agents): mark the cancel latch's snapshot rule and keep its comment budget

The latch hunk needs a rationale in an upstream file, so it carries the
fork-comment-ok marker the ratchet asks for rather than growing the baseline,
and LOCAL-PATCHES.md § local(agents) now says why the rule is not "any snapshot
is a start".

* local(agents): say which check holds the OMP start, and warn against widening the event check

* local(sync): name the issue that owns the retired repost suite's coverage

* local(lint): record the eight blocking-helper rows the sync left over baseline

check:main-blocking-helper-ratchet fails on the PR revision and on f55ccb8
itself: eight upstream-owned files now reach a sync fs/SQLite helper through
upstream's own call chains (its SQLite storage layer, and the
project-folder-placement split that put a readdirSync behind
getWorktreePathSettings). None has a fork hunk, so they are recorded in the
fork overlay with a why rather than diverged, which is the ratchet's documented
escape for a call the fork cannot move.

The earlier reading that this was this machine only was wrong: the same eight
rows reproduce on the merge revision GitHub tests, so the runner sees them too.

* fix(mobile): give the shared photon connector row a mobile case

Upstream's shared connector list adds a photon entry for every bot, and the
fork's photon connector rides it. Mobile's typecheck has been red since the
sync because its words object lacked the field and needPage had no case for the
kind: TS2741 in connector-entry-rows.tsx and TS2366 in phone-connector-needs.ts.

The row is now listed with its mark and no press — the phone has no Photon
surface yet and the connector asks nothing of the owner, so listing it is the
honest half of parity rather than dropping it, which is what a switch with no
case for the kind was doing.

---------

Co-authored-by: Nathan Plesnicher <[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.

[Bug]: Pi row with running subagents turns Done and loses its child rows after 30 minutes of lead silence on a paired server

2 participants