Files
loki/scripts
d22738f280 fix(orchestration): autopilot stops dispatching agents that said they're unavailable (#137)
31 of the last 34 nightly runs closed non-success. The cause was not agent
quality — it was that the scheduler ignored the fleet's own safety rails.

`evaluateDispatchGates` has always refused to dispatch an agent reporting
`status: working|blocked`, one sitting behind a pending blocker file, or one
stuck in a no-op loop. Those gates ran ONLY on /api/control/dispatch, where a
client posts the handoff. The nightly cron hand-rolled its own gate list and
had none of them, so every night it woke agents that had explicitly declared
themselves unavailable — one handoff literally read "do not re-invoke next_best
on a plain schedule". Such a nudge cannot succeed by construction: the agent
correctly declines, writes no fresh handoff, and an hour later the reaper
stamps the run partial/timeout. The rails existed; the scheduled path just
didn't use them.

- autopilot-eligibility: project persisted project_states into the SSOT
  GateInput so a cron reaches the same verdict as the page. A stale `working`
  claim with no live process decays to dispatchable (an agent killed mid-turn
  must not be frozen out forever); `blocked` never expires, because it is a
  standing decision about the world, not a claim about a process.
- nudge-idle: replace the hand-rolled failure brake with the SSOT decision and
  log WHY each project was refused, so a quiet fleet stays explainable.

Two ledger-truthfulness fixes found in the same trace:

- The reaper inferred liveness from handoff freshness, but handoffs are written
  at END of turn — so a working agent looked dead the whole time it worked.
  datacat was stamped `timeout` at 05:00 while its agent went on until 11:00.
  Liveness now comes from the runner heartbeat, with a 12h ceiling so a wedged
  process can't hold a run open forever.
- The reaper judged handoff freshness against started_at while the closer used
  deliveredAt. A handoff landing between them was "work" to one and "stale" to
  the other, so the run never closed and was reaped partial with a NULL summary
  — a recorded failure whose reason nobody could read. One floor, both paths.

12 new tests pin the invariant that scheduler and Control cannot diverge.

Co-authored-by: test <test@test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-02 18:42:28 +02:00
..