Files
gbrain/test
ded4aeaeae fix(cycle): stamp last_full_cycle_at for the resolved source; stale freshness forces autopilot fanout (#1993, #2060)
Two fixes to the per-source cycle freshness loop:

1. runCycle's freshness stamp now keys off cycleSourceId (opts.sourceId ??
   the source resolved from brainDir) — the same id the cycle locked and
   scoped its phases to — instead of raw opts.sourceId. The autopilot's
   inline cycle passes brainDir with no explicit sourceId, so the stamp
   never fired and cycle_freshness stayed stale forever. Keeps master's
   !aborted guard and the last_source_cycle_at write. (takeover of #1993)

2. autopilot's dispatch decision now consults per-source cycle staleness:
   countStaleSources (new pure helper in autopilot-fanout.ts) over
   listAllSources({ localPathOnly: true }). A stale source forces the
   fanout path and blocks the healthy-sleep gate, so a brain sitting at
   score 70-94 with a small targeted plan can no longer starve per-source
   cycle dispatch indefinitely. Fail-open to 0 on read errors;
   dispatchPerSource's existing throttles (skipped_fresh / fanoutMax /
   failure cooldown) bound the work. (#2060)

Tests: cycle-last-full-cycle-at gains the brainDir-resolves-source and
brainDir-matches-nothing cases (first one fails without fix 1);
autopilot-fanout unit tests cover countStaleSources; the fanout wiring
guard pins the staleCycleSources terms in shouldFullCycle/shouldSleep.

Co-authored-by: 100menotu001 <100menotu001@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 14:24:01 -07:00
..