Repository navigation
fix(agents): read the revamped pi job roster and hold a pane only on work that can still fire - #449
Merged
Merged
Conversation
… signal pi-config's `/loop` and pi-subagents now present scheduled work as one roster behind `manage_schedules`, with pause/resume, bounds and run-now. Two shapes the pi status lane read wrongly, both of which showed the pane the wrong state: A paused job is still listed. `/loop` keeps a paused loop's id, prompt and cadence and only unarms it, so `loop:rpc:schedules:list` returns it with `paused: true` and no `nextAt` — indistinguishable from a self-paced loop waiting for its wakeup, which is the one job shape that legitimately holds with no fire time. Presence alone therefore pinned the pane to `working` + `monitoring` for the rest of the session, on a loop that would never fire again. The reader now holds only on `!paused && enabled !== false`, which is the scheduler's word for the same decision. A loop armed between turns was invisible. Only pi-subagents' two events were subscribed, so `/loop` typed at an idle prompt — or a `manage_schedules` call that lands after the turn ended — moved the inventory with no post to ride it: the pane read `done` with the loop armed until the first fire. `loop:state`, the armed set `/loop` publishes itself once per real change, is now a third subscribed channel. It also closes the session-start order case: a restored loop's emit is caught when Orca's extension loads first, and Orca's own ask covers the other order, so neither ordering misses it. Tests: the generated extension is driven into the real listener; a paused live loop holds nothing, the revamped roster holds only what can still fire, and a `loop:state` between turns takes the pane to monitoring and a pause releases it.
The revamp bounded a job on both homes — `maxRuns`, `until` — and gave the live home one-shots. A bound is applied by the fire that reaches it, and a spent one-shot keeps no `nextAt`, so for the tick between that fire and the collection of the job the roster lists it in the one shape that holds with no fire time. On the live home the pane then held `monitoring` for up to the next re-check, and the one-shot's own removal publishes no further `loop:state` (it is already filtered out of the armed set), so nothing short of the 60s poll cleared it. The reader now applies `/loop`'s and the scheduler's own predicates: a job is armed only while its `runs`/`runCount` is under an unspent `maxRuns`, its `until` has not passed, and — live only — a one-shot has not fired. Those are the same three rules the extension uses to decide the job is done, so the pane stops claiming work at the moment the work stops being claimable rather than at the next poll. Tests cover a spent one-shot, a maxed `maxRuns` and a passed `until` on both homes holding nothing, and an armed one-shot that has not fired still holding.
…vered pi-codex-goal schedules its own re-entry (provider-limit auto-resume, five minutes out; a continuation sub-second after a turn) and emits nothing on pi.events, so the pi lane reads `done` during that wait. Deliberately out of scope for the job/loop lane: the fix is a signal from that extension, and an undocumented deliberate gap is what the next reader would read as a miss.
…eview The entry names the three shapes of the revamped pi job roster the lane read wrong and what replaced each rule. The gate-2 line says pending rather than claiming a round that has not run: the Claude Code CLI is rate-limited until 05:40 PT.
Both homes refuse a fire at or after `until`, so a job whose armed fire already sits past its bound is the one thing that will never happen — waiting for `until` itself held the pane for the whole window, and on the cold home nothing re-asks at that instant, so the release could lag a minute past it. The bound test now covers the armed fire as well as the clock, which needs no extra line: the reader computes `nextAt` before the test and judges both in one place. Also the reader's own comments: the poll no longer exists only because `/loop` publishes nothing (`loop:state` is bound now), and the doc bullet in LOCAL-PATCHES names the whole "can it still fire" set rather than the first two fields. Comments only; no behaviour change beyond the bound test.
R1 clean (2 MINOR, 2 NIT), delta on R2 with one doc NIT that is fixed here, and the MINOR left unfixed is named with why. Also states the base drift rather than rebasing: origin/main moved to 5ad2b7b, the merge base did not change, so the PR diff is this branch's own commits and a rebase would only re-scope the review.
… fire A second gate-2 round escalated the mid-fire release to SHOULD-FIX, and it is right: the bound tests buy nothing on the live home and cost exactly the window they were meant to protect. `/loop`'s fire() moves `runs` and *then* publishes the new armed set through `loop:state`, and starts the turn only after that, so a live job at or over its bound is mid-fire — re-asking synchronously dropped it and the release flush posted at 0 ms with `turnEnded` still true, reading `done` for the gap before `before_agent_start`. Meanwhile the 1s tick that removes a genuinely spent live loop publishes its own `loop:state`, so there was no stale window to close. The cold home is the opposite case and keeps its tests: the scheduler moves `runCount` in the same step it disables the job (`schedule.ts` finalize), so a firing cold job is never dropped, and a job at or over its bound (or armed past `until`) has no fire left. Bounds and `until` are now cold-only, on both the read and in the docs. Also corrected the `loop:state` claim in the source comment and LOCAL-PATCHES: the set it publishes holds only jobs with an armed fire, so pausing or ending a dynamic loop between wakeups moves nothing — that over-holds, bounded by the ≤60s re-check, and the doc said otherwise.
Gate-2 delta #2 left two comment findings. The module header still claimed `loop:state` covers a loop "paused, resumed or expired between turns", which the armed set cannot say for a dynamic loop between wakeups; it now says what the set holds and what moves it silently. The cold-bound comment claimed a firing cold job is never dropped, which is true but was asserted, not derived: in pi-subagents `runCount`, `enabled` and `nextRun` are all written in `finalize`, and a fire start persists only `lastStatus: "running"`, so a mid-fire job still reads its pre-fire count and the slot that fired. The comment now says that. Comments only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
pi-config's
/loopand pi-subagents were revamped into onemanage_schedulesroster over two homes —live loops that re-enter the session, cold jobs that spawn a subagent — with pause/resume, bounds
(
maxRuns/until) and one-shots. Orca's pi status lane holds a finished turn asworking+monitoring(rendered "Monitoring background tasks") while scheduled work is armed, but it read theroster by the old rules. Three shapes were wrong, all silent:
/loopkeeps a paused loop's id, prompt and cadence andonly unarms it, so the list returns it with
paused: trueand nonextAt— the one shape thatlegitimately holds with no fire time (a self-paced loop waiting for its wakeup). The pane sat in
monitoring for the rest of the session, on a job that would never fire again.
/looptyped at an idle prompt — or amanage_schedulescall landing after the turn end — movedthe inventory with no post to ride it. The pane read
donewith work armed until the first fire.a spent one-shot keeps no
nextAt, but both stay listed until the next tick, so the pane helduntil the 60s re-check.
What changed
src/main/pi/agent-status-scheduled-work-source.ts!pausedandenabled !== falseon bothhomes, plus — cold home only —
runCountunder an unspentmaxRunsand anuntilneitherpassed nor at-or-before the armed fire. The cold-only split is load-bearing: pi-subagents writes
runCount,enabledandnextRuntogether infinalize(a fire start persists onlylastStatus: "running"), so a mid-fire cold job still reads its pre-fire count and the slot thatfired;
/loopmovesrunswhen it arms the fire and starts the turn afterwards, so the sametest on the live home would release the pane for exactly the gap the hold exists to cover.
/loop'sloop:statebesidesubagents:scheduledandsubagents:scheduler_ready: the armed set/looppublishes whenever it changes, which announcesan arm, pause or resume between turns. It also closes the session-start ordering case — a restored
loop's emit is caught when Orca's extension loads first, and Orca's own
session_startask coversthe other order. A loop with no armed fire (a dynamic loop between wakeups) is outside that set,
so ending one moves nothing: that over-holds, bounded by the ≤60s re-check, never the reverse.
src/main/pi/agent-status-scheduled-work.test.ts— the generated extension is driven into the reallistener: a paused live loop holds nothing; the whole revamped roster holds only what can still fire;
a spent, maxed or past-
untillive loop keeps holding (it is mid-fire); the same bounds on thecold home hold nothing; an armed one-shot still holds; a
loop:statebetween turns takes the pane tomonitoring and a pause releases it.
LOCAL-PATCHES.md— thelocal(agents)scheduled-work section records this follow-up, the cold-onlysplit with its reason, and the one class deliberately left uncovered (below).
Audit — everything the revamp put on the wire
Checked against the installed extensions, not assumed:
loop.ts,shared/scheduled-rpc.ts): arm (typed/loopormanage_schedules),ScheduleWakeup, fixed/dynamic/one-shot fires, pause/resume (persisted, restored paused on/resume),run,update,/loop stop/stop all, 7-day TTL expiry, dynamic-loop end after twosilent ticks, fallback wakeup. Channel names, envelope (
{requestId}→…:reply:<id>), andjobView()fields unchanged.pi-subagents):toJobView()shape unchanged; all sixsubagents:scheduledkindsplus
scheduler_readyonly need to trigger a re-ask; pause isenabled: false; a bound disables thejob at the firing job's own
finalize; with scheduling switched off the channels are neverregistered, which the lane already treats as fail-safe (no inventory, no hold).
cache-keepalive.tsconsumesloop:statetoo and defines "work that re-enters thissession by itself" the same way this lane now does.
continue.ts,deepseek-*,copilot*,model-manager,nice-model-footer,fast-search,pi-picker-patch-guardschedule no re-entry.Deliberately not covered
plugins/pi-codex-goalschedules its own re-entry —provider-limit-auto-resumefive minutes after aprovider limit,
continuation-schedulersub-second after a turn — and emits nothing onpi.events, so the pane readsdoneduring that wait. Covering it needs that extension to publish thepending continuation first (a
goals:state-style channel naming the resume instant); it is not thejob/loop surface. Recorded in
LOCAL-PATCHES.md.Review findings
Three Opus rounds ran on this branch. Two were independent rounds on the same revision and disagreed on
severity for the same defect — recorded here because the disagreement is the interesting part:
until, was dropped whileits fire was still in flight:
/loop'sfire()movesruns, then publishes the new armed setthrough
loop:state, and only then callspi.sendUserMessage(), so a synchronous re-ask dropped thejob and the 0 ms release flush posted with
turnEndedstill true —donefor the gap, and probablya completion notification. The first round called this MINOR and "plausible, not confirmed"; the
second escalated it, and it was right. Bounds are now cold-only, where the counts move after the
fire; the live home keeps holding until
/loop's own tick collects the job, which publishes its ownloop:state, so nothing is left stale.untilkeeps holding until the nextre-ask, because nothing re-asks at that instant — at most 60 s, and
nextAt >= untilcovers thecommon case. It can only hold too long, never release early.
loop:stateclaim was too strong: the armed set holds only jobs with an armedfire, so pausing or ending a dynamic loop between wakeups moves nothing. Corrected in the source
header and
LOCAL-PATCHES.md.comment: the latter was asserted rather than derived, so I read
pi-subagents/schedule.ts— theclaim holds (
runCount/enabled/nextRunall move infinalize) and the comment now says so.outstanding ask per channel, key-diffed posts) and left as is.
Verification
src/main/pi/agent-status-scheduled-work.test.ts— 19 pass (the real generated extension into thereal listener; the row asserted is the row a pi pane publishes).
pi-pane-hold-evidence,pi-claude-child-events,agent-hook-listener-descendant-lifecycle,server-pi-subagent-hold-precedence,server-pi-subagent-hold-retraction,agent-status-restart-reannounce.pnpm tc:nodeclean;pnpm check:changed: format, oxlint, typecheck (all four projects) andchanged-code quality clean.
check:changedfailures remain and are pre-existing baseline drift, in files this branchdoes not touch:
direct-link-open-ratchet(renderer baselines) andmain-blocking-api-ratchet(ai-vault sqlite counts).
src/main/pi/**plus fork-owned docs.claude/opusathighreasoning. The branch was rebased onto5ad2b7bd33dbefore opening;git range-diffreports the commits patch-identical, so the reviewed code is the code here.Reviewed by Opus 5.5, high: R1 (1 blocking fixed, 2 MINOR fixed, 2 NIT fixed), delta on R2 clean, delta on R3 (2 MINOR fixed, clean)
Operational note
Orca rewrites the pi status extension on the next pi pane launch, so panes already open keep the old
file until relaunched — that is when the fixes begin applying to a live session.