Skip to content

fix(agents): read the revamped pi job roster and hold a pane only on work that can still fire - #449

Merged
nplez1 merged 10 commits into
mainfrom
nplez1/New-Loop-Job-Support
Nov 22, 2026
Merged

nplez1 merged 10 commits into
mainfrom
nplez1/New-Loop-Job-Support

Conversation

@nplez1

@nplez1 nplez1 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Why

pi-config's /loop and pi-subagents were revamped into one manage_schedules roster 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 as working +
monitoring (rendered "Monitoring background tasks") while scheduled work is armed, but it read the
roster by the old rules. Three shapes were wrong, all silent:

  1. A paused job held the pane forever. /loop keeps a paused loop's id, prompt and cadence and
    only unarms it, so the list returns it with paused: true and no nextAt — the one shape that
    legitimately 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.
  2. 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 landing after the turn end — moved
    the inventory with no post to ride it. The pane read done with work armed until the first fire.
  3. A job that can no longer fire kept holding. A bound is applied by the fire that reaches it and
    a spent one-shot keeps no nextAt, but both stay listed until the next tick, so the pane held
    until the 60s re-check.

What changed

  • src/main/pi/agent-status-scheduled-work-source.ts
    • The reader distinguishes listed from armed: !paused and enabled !== false on both
      homes, plus — cold home only — runCount under an unspent maxRuns and an until neither
      passed nor at-or-before the armed fire. The cold-only split is load-bearing: pi-subagents writes
      runCount, enabled and nextRun together in finalize (a fire start persists only
      lastStatus: "running"), so a mid-fire cold job still reads its pre-fire count and the slot that
      fired; /loop moves runs when it arms the fire and starts the turn afterwards, so the same
      test on the live home would release the pane for exactly the gap the hold exists to cover.
    • The lane subscribes /loop's loop:state beside subagents:scheduled and
      subagents:scheduler_ready: the armed set /loop publishes whenever it changes, which announces
      an 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_start ask covers
      the 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 real
    listener: a paused live loop holds nothing; the whole revamped roster holds only what can still fire;
    a spent, maxed or past-until live loop keeps holding (it is mid-fire); the same bounds on the
    cold home hold nothing; an armed one-shot still holds; a loop:state between turns takes the pane to
    monitoring and a pause releases it.
  • LOCAL-PATCHES.md — the local(agents) scheduled-work section records this follow-up, the cold-only
    split 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:

  • Live home (loop.ts, shared/scheduled-rpc.ts): arm (typed /loop or manage_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 two
    silent ticks, fallback wakeup. Channel names, envelope ({requestId} → …:reply:<id>), and
    jobView() fields unchanged.
  • Cold home (pi-subagents): toJobView() shape unchanged; all six subagents:scheduled kinds
    plus scheduler_ready only need to trigger a re-ask; pause is enabled: false; a bound disables the
    job at the firing job's own finalize; with scheduling switched off the channels are never
    registered, which the lane already treats as fail-safe (no inventory, no hold).
  • Adjacent: cache-keepalive.ts consumes loop:state too and defines "work that re-enters this
    session by itself" the same way this lane now does. continue.ts, deepseek-*, copilot*,
    model-manager, nice-model-footer, fast-search, pi-picker-patch-guard schedule no re-entry.

Deliberately not covered

plugins/pi-codex-goal schedules its own re-entry — provider-limit-auto-resume five minutes after a
provider limit, continuation-scheduler sub-second after a turn — and emits nothing on
pi.events, so the pane reads done during that wait. Covering it needs that extension to publish the
pending continuation first (a goals:state-style channel naming the resume instant); it is not the
job/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:

  • SHOULD-FIX (fixed). A live job at or over its bound, or with a passed until, was dropped while
    its fire was still in flight: /loop's fire() moves runs, then publishes the new armed set
    through loop:state, and only then calls pi.sendUserMessage(), so a synchronous re-ask dropped the
    job and the 0 ms release flush posted with turnEnded still true — done for the gap, and probably
    a 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 own
    loop:state, so nothing is left stale.
  • MINOR (left, over-holds only). A cold job held across its until keeps holding until the next
    re-ask, because nothing re-asks at that instant — at most 60 s, and nextAt >= until covers the
    common case. It can only hold too long, never release early.
  • MINOR (fixed). The loop:state claim was too strong: the armed set holds only jobs with an armed
    fire, so pausing or ending a dynamic loop between wakeups moves nothing. Corrected in the source
    header and LOCAL-PATCHES.md.
  • MINOR ×2 (fixed, comment-only, from the last delta). The reader's header and its cold-bound
    comment: the latter was asserted rather than derived, so I read pi-subagents/schedule.ts — the
    claim holds (runCount/enabled/nextRun all move in finalize) and the comment now says so.
  • NIT ×3 (fixed). Two stale comments; a duplicate refresh per cold change, which is harmless (one
    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 the
    real listener; the row asserted is the row a pi pane publishes).
  • Pi lane suites — 101 pass: 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:node clean; pnpm check:changed: format, oxlint, typecheck (all four projects) and
    changed-code quality clean.
  • Two check:changed failures remain and are pre-existing baseline drift, in files this branch
    does not touch: direct-link-open-ratchet (renderer baselines) and main-blocking-api-ratchet
    (ai-vault sqlite counts).
  • Gate 1 not required — no global input; the diff is src/main/pi/** plus fork-owned docs.
  • Gate 2: claude/opus at high reasoning. The branch was rebased onto 5ad2b7bd33d before opening;
    git range-diff reports 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.

… 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.
@nplez1
nplez1 merged commit 5355161 into main Nov 22, 2026
10 checks passed
@nplez1
nplez1 deleted the nplez1/New-Loop-Job-Support branch November 22, 2026 00:39
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