Skip to content

fix(pi): let background subagent starts right after Esc mark the row working - #47627

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-47576
Nov 23, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-47576

Conversation

@nwparker

@nwparker nwparker commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

In Pi, if you press Esc and a background job starts within the next 15 seconds, the sidebar kept showing the grey Interrupted dot for the whole job. Orca mistook the new job for a leftover message from the turn you just cancelled. Now Orca can tell the two apart, so the row shows working while the background job runs.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​21 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​17

What Changed

Before: After Esc on a Pi turn, a background subagent start (subagent:async-started) arriving within 15 s left the row on Interrupted (done) for the whole run. The same start after 15 s showed working.

After: That start shows the row as working right away, then returns to done when the job completes. Late events from the cancelled turn are still held.

Mechanism:

  • The managed Pi status extension (agent-status-subagent-roster-source.ts) now marks its agent_start post with subagent_started: true, but only for pi-subagents async starts (forcedStatus === 'started'). OMP task:subagent:lifecycle starts are in-turn children that get aborted with the turn, so they are not marked.
  • Pi-family normalization (provider-dispatch.ts, via the new leaf module pi-subagent-start-event.ts) restates that post as agent_start:subagent. hookEventName already crosses SSH/WSL relays, so the marker survives remote paths.
  • The cancel-verdict latch (agent-hook-cancel-verdict-latch.ts) no longer holds a working update whose event is agent_start:subagent. It still holds replays, tool-progress events, and plain same-prompt work inside the 15 s window.

Why

The latch exists to drop late hooks from a cancelled turn. A background subagent start that isn't tied to a prompt looked the same as one of those hooks, so the latch dropped it and nothing posted it again. Of the options, an explicit marker from the extension is the narrowest: it changes nothing for other providers or other Pi events. Shortening the window or letting every no-prompt agent_start through would bring back the late-hook flicker that the latch prevents.

Linked Issue

Fixes #47576

Visual Proof

N/A. The only visible change is which existing status dot shows (working instead of Interrupted). Nothing new is rendered. The behavior was checked end to end through the real AgentHookServer and the real generated Pi extension (probe below).

Probe (real AgentHookServer + real generated Pi status extension, Esc then background start):

Scenario main this PR
Late tool end held, background start at +5 s done (interrupted) working
Background start 50 ms after Esc done (interrupted) working
Background start then its completion done / done working / done
In-turn OMP task child start after Esc done (interrupted, held) done (interrupted, held)
Control: background start at +20 s working working

Testing

  • Repro: the probe above follows the issue's steps (interrupt a Pi turn, emit subagent:async-started within 15 s, read the row state). It fails 3 of 5 cases on main and passes all 5 on this branch.

  • New unit test agent-hook-cancel-verdict-latch.test.ts sends the real generated extension's posts through normalizeHookPayload and the latch. A background start is applied. An OMP lifecycle start and a replayed start are still held. The test fails if the latch change is reverted.

  • vitest on src/shared/agent-hook-listener, src/main/pi/managed-extensions/agent-status, and src/main/agent-hooks/server all pass. Lint, oxfmt, anti-slop, ast-grep, and the changed-code quality gate are clean.

  • Platform: macOS (unit and integration level). The change is platform-neutral, and the marker uses an existing relay field for SSH/WSL.

  • I manually tested these changes locally (verified via the real-server probe and unit tests, not a GUI run)

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None, because this only runs per agent hook event, which is not a hot path. It adds one string comparison in the latch and one in Pi normalization. Measured old vs new: latch about 9 ns/op on main vs about 14 ns/op on this branch. Pi normalizeHookPayload about 1.0 µs/op on both. There is no new I/O, polling, or subprocess work.

Risk

Level: Low

The riskiest part is letting a held working update through. That is limited to posts the managed extension marks explicitly, and only pi-subagents async starts get marked. Older extensions or relays that don't send the flag keep today's behavior. If it goes wrong, a Pi row could briefly show working after Esc. A plain revert backs it out.

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

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)

Reported by @mmarabel

…working

The Pi status extension posts agent_start for a background subagent start
with the cached prompt and no explicit prompt, so within 15 s of an
interrupted turn the cancel-verdict latch held it as a late event of the
cancelled run and dropped it. The row stayed Interrupted for the whole run.

Mark the subagent:async-started post with subagent_started, restate it as
agent_start:subagent in Pi-family normalization (hookEventName already
crosses SSH/WSL relays), and let the latch apply it. OMP
task:subagent:lifecycle starts are in-turn children aborted with the turn,
so they stay held, as do replays and plain late same-prompt work. Older
extensions or relays keep today's behavior.

Fixes #47576

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

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Pi subagent starts now carry a marker that provider dispatch uses to restate agent_start as agent_start:subagent. The cancel-verdict latch exempts that event from within-window suppression. A test checks the latch result for a live background start, an OMP lifecycle start, and a replayed background start.

Severity of issue fixed: Medium

Merge Risk: Low · up to 996bd

Pi background subagent starts shortly after Esc now show the row as working instead of staying Interrupted. One edge case remains unverified: a delayed end event from the cancelled turn could briefly set the row back to done while the background job is still running. This affects only the status indicator and is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: background subagent starts right after Esc now mark the Pi row as working. It also names the provider (pi) and the fix type. This matches the raw summary, which adds a…
Linked Issues check Passed Issue #47576 requires that a Pi background subagent start (subagent:async-started) within 15 s of Esc shows the row as working, and that it stays working while the job runs. At the reviewed head, th…
Out of Scope Changes check Passed All changed areas connect to the #47576 objective. The extension change adds the explicit marker. The Pi-family normalization change and new leaf module carry the marker into the event name. The latch…
Description check Passed The description explains the user-facing problem (Pi background subagent start shown as Interrupted within 15 s of Esc), the before/after behavior, the mechanism across the three providers and latch, …
Full details: Title check

Explanation

The title names the main change: background subagent starts right after Esc now mark the Pi row as working. It also names the provider (pi) and the fix type. This matches the raw summary, which adds a subagent-start marker that the cancel-verdict latch lets through. The title is specific and concise.

Full details: Linked Issues check

Explanation

Issue #47576 requires that a Pi background subagent start (subagent:async-started) within 15 s of Esc shows the row as working, and that it stays working while the job runs. At the reviewed head, the managed Pi extension (agent-status-subagent-roster-source.ts) posts agent_start with subagent_started: true only for forcedStatus === 'started'. restatePiFamilyEventName (pi-subagent-start-event.ts) restates that post as agent_start:subagent. resolveCancelVerdictLatch (agent-hook-cancel-verdict-latch.ts) exempts PI_SUBAGENT_START_EVENT from the within-window working hold. Replays (isReplay === true), tool-progress events, and same-prompt work without an explicit prompt remain held. This matches the issue's suggested fix. The issue asks for no visual change, and none is made. I did not read the new unit test file, so test coverage rests on the PR description and summary. The cross-relay survival of hookEventName is also taken from the description, not verified in this review.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to the #47576 objective. The extension change adds the explicit marker. The Pi-family normalization change and new leaf module carry the marker into the event name. The latch change exempts only the marked event. The test file covers that behavior. The provider-dispatch change only updates the documented restatement cases to include Pi subagent starts. No unrelated behavior change appears in the summary. OMP lifecycle starts are excluded from the marker, which keeps other providers and Pi events unchanged.

Full details: Description check

Explanation

The description explains the user-facing problem (Pi background subagent start shown as Interrupted within 15 s of Esc), the before/after behavior, the mechanism across the three providers and latch, why this approach was chosen over alternatives, a linked issue (Fixes #47576), a visual proof justification (N/A with reason and a probe table), testing details, a performance statement, and a low risk level with a revert plan. The template's required sections are all present and substantively filled. Minor gaps: the 'Level' risk section is brief, the AI Disclosure section is left empty, and the Testing checkbox for manual testing is marked unchecked while the author notes the verification was not a GUI run. These are non-critical.

  • 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: 9c0bd425-bc88-41b4-885b-38585e5c4ec6
Commits

Reviewing files that changed from the base of the PR and between af2fccd and 996bd4e.

Files selected for processing: 5

  • src/main/pi/managed-extensions/agent-status/agent-status-subagent-roster-source.ts
  • src/shared/agent-hook-listener/provider-dispatch.ts
  • src/shared/agent-hook-listener/providers/pi-family/pi-subagent-start-event.ts
  • src/shared/agent-hook-listener/state/agent-hook-cancel-verdict-latch.test.ts
  • src/shared/agent-hook-listener/state/agent-hook-cancel-verdict-latch.ts

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

@nwparker
nwparker merged commit beac2a3 into main Nov 23, 2026
59 of 60 checks passed
@nwparker
nwparker deleted the bugbash/issue-47576 branch November 23, 2026 12:01
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 background work started right after Esc leaves the row on Interrupted

1 participant