From 66687c706e09fc934ca93dd9aeef5de9745dc598 Mon Sep 17 00:00:00 2001 From: Gabriel Loewen Date: Thu, 19 Nov 2026 22:03:14 -0800 Subject: [PATCH 1/2] Record a worker's heartbeat so the dashboard tells a busy worker from a stuck one (#482) --- .../482-format-26-golden.documentation.md | 1 + changelog.d/482-last-tracker-write.changed.md | 1 + changelog.d/482-worker-heartbeat.added.md | 1 + core/src/redact.rs | 1 + core/src/work.rs | 14 ++++- core/src/work_fold.rs | 29 ++++++++++ core/tests/format.rs | 33 +++++++++++ core/tests/work_format_26.jsonl | 11 ++++ dashboard/README.md | 4 +- dashboard/check/browser.mjs | 8 ++- dashboard/src/activity.ts | 8 ++- dashboard/src/card.ts | 25 ++++++++- dashboard/src/fold.ts | 2 + dashboard/src/ui/app.css | 1 + dashboard/src/ui/now-section.ts | 2 +- dashboard/src/ui/workers-view.ts | 13 ++++- dashboard/src/workers.ts | 2 + dashboard/test/activity.test.ts | 16 +++++- dashboard/test/card.test.ts | 6 +- dashboard/test/workers.test.ts | 26 ++++++++- docs/design/supervise.md | 20 ++++++- docs/threat-model-citations.json | 9 ++- docs/threat-model.md | 2 + docs/upgrades.md | 3 +- docs/work-tracker.md | 1 + mcp/src/main.rs | 1 + mcp/src/supervise.rs | 41 ++++++++++++++ mcp/src/supervise/tests.rs | 30 ++++++++++ tracker/src/http.rs | 26 +++++++++ tracker/src/http/tests/workers.rs | 34 +++++++++++ tracker/src/tracker/tests/workers.rs | 56 +++++++++++++++++++ tracker/src/tracker/workers.rs | 39 ++++++++++++- wasm/golden/format_26.jsonl | 11 ++++ wasm/golden/format_26.state.json | 1 + wasm/src/lib.rs | 12 +++- wasm/tests/golden.rs | 4 ++ 36 files changed, 467 insertions(+), 27 deletions(-) create mode 100644 changelog.d/482-format-26-golden.documentation.md create mode 100644 changelog.d/482-last-tracker-write.changed.md create mode 100644 changelog.d/482-worker-heartbeat.added.md create mode 100644 core/tests/work_format_26.jsonl create mode 100644 wasm/golden/format_26.jsonl create mode 100644 wasm/golden/format_26.state.json diff --git a/changelog.d/482-format-26-golden.documentation.md b/changelog.d/482-format-26-golden.documentation.md new file mode 100644 index 00000000..c6df0e1c --- /dev/null +++ b/changelog.d/482-format-26-golden.documentation.md @@ -0,0 +1 @@ +`wasm/golden` gains `format_26` (a worker's `alive_ms`); no earlier golden changed. diff --git a/changelog.d/482-last-tracker-write.changed.md b/changelog.d/482-last-tracker-write.changed.md new file mode 100644 index 00000000..d8e77bc0 --- /dev/null +++ b/changelog.d/482-last-tracker-write.changed.md @@ -0,0 +1 @@ +The dashboard calls a holder's last record "last tracker write" instead of "last active" or "last activity", since a long step with no tracker write is not inactivity. diff --git a/changelog.d/482-worker-heartbeat.added.md b/changelog.d/482-worker-heartbeat.added.md new file mode 100644 index 00000000..1b9b3dcc --- /dev/null +++ b/changelog.d/482-worker-heartbeat.added.md @@ -0,0 +1 @@ +The supervisor records once a minute which command workers' processes are still running (`worker_alive`, format 26, `POST /v1/work/workers/alive`). The dashboard shows `process running` or `no heartbeat for 7 min` in the Workers dialog and next to a holder on cards, rows and the Now line, so a worker in a long quiet step is told from a stuck one. Raise the log to format 26 for the heartbeat to be written. diff --git a/core/src/redact.rs b/core/src/redact.rs index fa50ac28..1f349692 100644 --- a/core/src/redact.rs +++ b/core/src/redact.rs @@ -1216,6 +1216,7 @@ pub fn redact_record(record: &mut WorkRecord) { | WorkRecord::WorkerStarted { .. } | WorkRecord::WorkerStopped { .. } | WorkRecord::WorkerFinished + | WorkRecord::WorkerAlive { .. } | WorkRecord::AdmissionUndone { .. } | WorkRecord::IntakeTier { .. } | WorkRecord::FlakeCleared { .. } diff --git a/core/src/work.rs b/core/src/work.rs index 4afad2f3..3175b14f 100644 --- a/core/src/work.rs +++ b/core/src/work.rs @@ -140,8 +140,12 @@ pub const FORMAT_V24: u32 = 24; /// person's take-back of it. pub const FORMAT_V25: u32 = 25; +/// The format that added `worker_alive`: a supervisor's periodic note that +/// the processes of its workers are still running. +pub const FORMAT_V26: u32 = 26; + /// The highest record format this build reads and writes. -pub const FORMAT: u32 = FORMAT_V25; +pub const FORMAT: u32 = FORMAT_V26; /// Most live workers one supervisor may have, whatever the tracker's config says. pub const MAX_WORKERS_PER_SUPERVISOR: usize = 64; @@ -1263,6 +1267,11 @@ pub enum WorkRecord { /// supervisor on the record; it ends the worker as a stop does, so its /// token dies and its name is never reused. Format 24. WorkerFinished, + /// A supervisor says the processes of these workers of its own are still + /// running. Recorded at most once a minute; a worker nothing is written for + /// has no process the supervisor watches, or its supervisor is down. + /// Format 26. + WorkerAlive { workers: Vec }, /// A person adds or replaces an entry on the team's flake list: a failed /// check named `check`, whose job log contains `pattern` when one is /// given, is a known flake tracked by `issue`. Format 22. @@ -1380,6 +1389,7 @@ impl WorkRecord { WorkRecord::CheckFailed { .. } => "check_failed", WorkRecord::WorkerStopped { .. } => "worker_stopped", WorkRecord::WorkerFinished => "worker_finished", + WorkRecord::WorkerAlive { .. } => "worker_alive", WorkRecord::Unknown => "unknown", } } @@ -1453,6 +1463,7 @@ impl WorkRecord { | WorkRecord::WorkerStarted { .. } | WorkRecord::WorkerStopped { .. } | WorkRecord::WorkerFinished + | WorkRecord::WorkerAlive { .. } | WorkRecord::FlakeSet { .. } | WorkRecord::FlakeCleared { .. } | WorkRecord::Unknown => None, @@ -1583,6 +1594,7 @@ impl WorkRecord { | WorkRecord::FlakeCleared { .. } | WorkRecord::FlakeRetried { .. } => FORMAT_V22, WorkRecord::WorkerFinished => FORMAT_V24, + WorkRecord::WorkerAlive { .. } => FORMAT_V26, WorkRecord::AdmissionUndone { .. } | WorkRecord::IntakeTier { .. } | WorkRecord::Accepted { diff --git a/core/src/work_fold.rs b/core/src/work_fold.rs index 1f3e686a..7e40a03a 100644 --- a/core/src/work_fold.rs +++ b/core/src/work_fold.rs @@ -1042,6 +1042,11 @@ pub struct Worker { /// It ended by its own `worker_finished`, not a stop. #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub finished: bool, + /// When its supervisor last recorded the worker's process as running + /// (`worker_alive`, format 26). None for a worker no heartbeat named, + /// such as a hosted one. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub alive_ms: Option, } /// One entry on the flake list, with how often ingest re-ran a check for it. @@ -4161,9 +4166,33 @@ impl State { started_ms: rec.at_ms, stopped_ms: None, finished: false, + alive_ms: None, }, ); } + WorkRecord::WorkerAlive { workers } => { + if rec.actor != Actor::Agent || rec.sup.is_some() { + return Err(Reject::ActorNotAllowed); + } + // All or none: a name that is not a live worker of this + // supervisor refuses the whole note. + let mine = |k: &Key| { + self.workers + .get(k) + .is_some_and(|w| w.supervisor == rec.by && w.stopped_ms.is_none()) + }; + if workers.is_empty() + || workers.len() > MAX_WORKERS_PER_SUPERVISOR + || !workers.iter().all(mine) + { + return Err(Reject::BadWorker); + } + for k in workers { + if let Some(w) = self.workers.get_mut(k) { + w.alive_ms = Some(rec.at_ms); + } + } + } WorkRecord::WorkerFinished => { // Only a worker itself, acting for its live supervisor: the // worker check above has already tied `by` to a live worker. diff --git a/core/tests/format.rs b/core/tests/format.rs index 90ac4c22..7f161942 100644 --- a/core/tests/format.rs +++ b/core/tests/format.rs @@ -1720,3 +1720,36 @@ fn the_twenty_fifth_format_stamps_the_policy_acceptance_and_its_take_back() { assert_eq!(r2.admitted_by.as_deref(), Some("routine")); assert!(r2.hold.is_some()); } + +/// A log at format 26: a supervisor records which of its own live workers +/// are running; a note naming another supervisor's worker, no worker, a +/// stopped worker, or written by a worker or a person is refused. Its folded +/// state is pinned in `wasm/golden/format_26.state.json`. +const FORMAT_26_LOG: &str = include_str!("work_format_26.jsonl"); + +#[test] +fn the_twenty_sixth_format_stamps_worker_alive_and_records_only_a_supervisors_own_workers() { + assert_eq!(kbl_core::work::FORMAT_V26, 26); + const { assert!(FORMAT >= kbl_core::work::FORMAT_V26) }; + let log = entries(FORMAT_26_LOG); + for (_, r) in &log { + assert!(r.v >= r.min_format(), "{}", r.record.kind()); + } + assert_eq!(log[4].1.min_format(), 26); + let s = fold(&log); + let why: Vec<_> = s.rejections.iter().map(|r| (r.offset, r.why)).collect(); + assert_eq!( + why, + [ + (5, Reject::BadWorker), + (6, Reject::BadWorker), + (7, Reject::ActorNotAllowed), + (8, Reject::ActorNotAllowed), + (10, Reject::BadWorker) + ] + ); + let alive = |w: &str| s.workers[&kbl_core::names::Key::new(w).unwrap()].alive_ms; + assert_eq!(alive("sup-w1"), Some(1040)); + assert_eq!(alive("sup-w2"), None); + assert_eq!(alive("other-w1"), None); +} diff --git a/core/tests/work_format_26.jsonl b/core/tests/work_format_26.jsonl new file mode 100644 index 00000000..03ad0a7a --- /dev/null +++ b/core/tests/work_format_26.jsonl @@ -0,0 +1,11 @@ +{"v":26,"at_ms":1000,"by":"gabriel","actor":"person","kind":"format_raised","to":26} +{"v":21,"at_ms":1010,"by":"sup","actor":"agent","kind":"worker_started","worker":"sup-w1","token_sha256":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"} +{"v":21,"at_ms":1011,"by":"sup","actor":"agent","kind":"worker_started","worker":"sup-w2","token_sha256":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"} +{"v":21,"at_ms":1012,"by":"other","actor":"agent","kind":"worker_started","worker":"other-w1","token_sha256":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"} +{"v":26,"at_ms":1040,"by":"sup","actor":"agent","kind":"worker_alive","workers":["sup-w1"]} +{"v":26,"at_ms":1050,"by":"sup","actor":"agent","kind":"worker_alive","workers":["sup-w2","other-w1"]} +{"v":26,"at_ms":1060,"by":"sup","actor":"agent","kind":"worker_alive","workers":[]} +{"v":26,"at_ms":1070,"by":"sup-w1","actor":"agent","sup":"sup","kind":"worker_alive","workers":["sup-w1"]} +{"v":26,"at_ms":1080,"by":"gabriel","actor":"person","kind":"worker_alive","workers":["sup-w1"]} +{"v":21,"at_ms":1090,"by":"sup","actor":"agent","kind":"worker_stopped","worker":"sup-w2"} +{"v":26,"at_ms":1100,"by":"sup","actor":"agent","kind":"worker_alive","workers":["sup-w2"]} diff --git a/dashboard/README.md b/dashboard/README.md index 42ece9c2..f339a868 100644 --- a/dashboard/README.md +++ b/dashboard/README.md @@ -22,7 +22,7 @@ Definitions are in [Flow metrics](../docs/flow-metrics.md). Nothing is per perso Workers (sidebar button, or `Show supervisors and their workers` in the palette) shows each supervisor with the workers it started, from the fold's `workers_json()` ([supervise](../docs/design/supervise.md#dashboard)). A row has the worker's state (Working with an item, Idle, Finished by its own report, or Stopped), the vendor and model the supervisor recorded -at start, how long ago it started or ended, and the item it holds with the attempt and when the holder last wrote. A +at start, how long ago it started or ended, and the item it holds with the attempt and when the holder last wrote to the tracker. Under the state, a worker the supervisor vouched for in the last 3 minutes reads `process running` and one it stopped vouching for reads `no heartbeat for 7 min`; the same words follow the holder on a card, a row and the item's Now line. A worker with no heartbeat recorded, such as a hosted one, says nothing. A person signed in to the tracker gets a Stop on each live worker and a Stop all per supervisor (and for every supervisor when there are several), which asks first and then sends one `POST /v1/work/workers/stop` per worker, so the held item goes back at once. Signed out, the dialog says so instead of showing the buttons. Only recorded fields are shown; the @@ -64,7 +64,7 @@ fold's `activity_json(item)` ([What is happening](../docs/work-tracker.md)) and interrupt a screen reader; the relative times refresh with the log. Each time is focusable and shows its absolute value on focus or hover, and a screen reader reads both. A record the fold refused (a `done` with a cost of its own on a format 8 log, say) stays in Activity marked "refused" with the reason, and counts for nothing: not in Attempts, the Now line's -last activity or a child's answer. A held item that waits on a person reads as waiting, never as working. +last tracker write or a child's answer. A held item that waits on a person reads as waiting, never as working. **Handoff** (in the panel's fields, and above the strip under a Needs you row) shows what the item's latest finished attempt handed off, so a merge, steer or reject can be decided without opening other tabs: the agent's last progress diff --git a/dashboard/check/browser.mjs b/dashboard/check/browser.mjs index 213b29be..713cd4cb 100644 --- a/dashboard/check/browser.mjs +++ b/dashboard/check/browser.mjs @@ -663,7 +663,7 @@ try { // Item detail: the Now line, the live timeline and the attempts. Times are relative and live, and // a fold a person opened stays open when a record redraws the panel. const text = (sel) => page.eval(`document.querySelector(${JSON.stringify(sel)})?.textContent ?? ''`); - check(/^agent-1 is working on this, attempt 1, last activity /.test(await text('.panel .now-text')), `the panel says who works on the item (${await text('.panel .now-text')})`); + check(/^agent-1 is working on this, attempt 1, last tracker write /.test(await text('.panel .now-text')), `the panel says who works on the item (${await text('.panel .now-text')})`); const newest = await text('.panel .tl-entry:first-child .tl-head strong'); check(newest === 'Edited core/src/cache.rs', `the timeline lists the newest record first (saw "${newest}")`); check(await page.eval(`!!document.querySelector('.panel .tl-entry time[datetime]')`), 'each timeline entry has a machine-readable time'); @@ -1038,17 +1038,21 @@ try { { const w = (r) => page.eval(`window.__push(${JSON.stringify({ v: 24, actor: 'agent', at_ms: Date.now(), ...r })}); true`); const hash = (c) => c.repeat(64); - await page.eval(`window.__push({ v: 24, kind: 'format_raised', to: 24, actor: 'person', by: 'maintainer', at_ms: Date.now() }); window.__push({ kind: 'imported', item: 'wk-1', source: 'github', title: 'Held by a worker', upstream_id: 'GetFelix/felix#7001', actor: 'tracker', by: 'ingest', at_ms: Date.now() }); window.__push({ kind: 'accepted', item: 'wk-1', tier: 1, actor: 'person', by: 'maintainer', at_ms: Date.now() }); true`); + await page.eval(`window.__push({ v: 26, kind: 'format_raised', to: 26, actor: 'person', by: 'maintainer', at_ms: Date.now() }); window.__push({ kind: 'imported', item: 'wk-1', source: 'github', title: 'Held by a worker', upstream_id: 'GetFelix/felix#7001', actor: 'tracker', by: 'ingest', at_ms: Date.now() }); window.__push({ kind: 'accepted', item: 'wk-1', tier: 1, actor: 'person', by: 'maintainer', at_ms: Date.now() }); true`); for (const [n, c, extra] of [['sup-a', 'a', { vendor: 'anthropic', model: 'sonnet' }], ['sup-b', 'b', { vendor: 'example', profile: 'cloud' }], ['sup-c', 'c', {}], ['sup-d', 'd', {}]]) { await w({ by: 'sup', kind: 'worker_started', worker: n, token_sha256: hash(c), supervisor_token_sha256: hash('f'), ...extra }); } await w({ by: 'sup-a', sup: 'sup', kind: 'claimed', item: 'wk-1', attempt: 1, deadline_ms: Date.now() + 3_600_000 }); await w({ by: 'sup-c', sup: 'sup', kind: 'worker_finished' }); + // The supervisor last vouched for sup-a a moment ago and for sup-b ten minutes ago; a hosted worker has no heartbeat. + await w({ v: 26, by: 'sup', kind: 'worker_alive', workers: ['sup-a'] }); + await w({ v: 26, by: 'sup', kind: 'worker_alive', workers: ['sup-b'], at_ms: Date.now() - 10 * 60_000 }); await page.eval(`window.__push({ v: 24, kind: 'worker_stopped', worker: 'sup-d', actor: 'person', by: 'maintainer', at_ms: Date.now() }); true`); await page.eval(`[...document.querySelectorAll('.sidebar-foot button')].find((b) => b.textContent === 'Workers').click(); true`); await page.waitFor(`!!document.querySelector('dialog.workers section[data-supervisor=sup] tr[data-worker=sup-d]')`); const rows = await page.eval(`[...document.querySelectorAll('dialog.workers tr[data-worker]')].map((r) => r.dataset.worker + ':' + r.dataset.state).join(' ')`); check(rows === 'sup-a:working sup-b:idle sup-c:finished sup-d:stopped', `workers: one group, live workers first, finished and stopped kept (${rows})`); + check(await page.eval(`(() => { const b = (n) => document.querySelector('dialog.workers tr[data-worker=' + n + '] [data-beat]'); return b('sup-a')?.dataset.beat === 'running' && b('sup-a').textContent === 'process running' && b('sup-b')?.dataset.beat === 'silent' && /^no heartbeat for 1\\d min$/.test(b('sup-b').textContent) && !b('sup-c') && !b('sup-d'); })()`), 'workers: a recent heartbeat reads as running, an old one as silent, and a worker with none says nothing'); check(await page.eval(`document.querySelector('dialog.workers tr[data-worker=sup-a] a[data-item=wk-1]')?.textContent === 'wk-1 Held by a worker'`), 'workers: a working worker names the item it holds'); check(await page.eval(`document.querySelector('dialog.workers tr[data-worker=sup-a]').textContent.includes('anthropic ยท sonnet') && document.querySelector('dialog.workers tr[data-worker=sup-c]').textContent.includes('finished')`), 'workers: the recorded launch fields and the finish show'); check(await page.eval(`(() => { const t = (n) => document.querySelector('dialog.workers tr[data-worker=' + n + ']').textContent; return !/not recorded|None/.test(t('sup-c') + t('sup-d')) && t('sup-c').includes('Nothing held') && t('sup-d').includes('Nothing held'); })()`), 'workers: a finished or stopped worker with nothing recorded shows no filler and Nothing held'); diff --git a/dashboard/src/activity.ts b/dashboard/src/activity.ts index eaef889e..c57778a5 100644 --- a/dashboard/src/activity.ts +++ b/dashboard/src/activity.ts @@ -3,7 +3,7 @@ import type { BlockedRow, ItemRow } from './fold.ts'; import { stageLabel } from './list.ts'; import { assigneePerson, needsLine } from './writes.ts'; -import { blockText, prText } from './card.ts'; +import { beat, blockText, prText } from './card.ts'; export interface ActivityEvent { offset: number; @@ -85,11 +85,13 @@ export function nowLine(item: ItemRow, blocked: readonly BlockedRow[], events: r // while the item is in Needs you, nobody is working it. if (item.holder && item.held_attempt && item.stage !== 'needs_you') { const last = item.active_ms ?? lastWrite(events, item.held_attempt)?.at_ms ?? null; - const quiet = last === null ? 'no activity recorded yet' : `last activity ${since(last, now)}`; + const quiet = last === null ? 'no activity recorded yet' : `last tracker write ${since(last, now)}`; // Renewals are not recorded, so a passed claim-time deadline says nothing about a live agent. const deadline = item.hold_deadline_ms; const lapse = deadline != null && deadline > now ? `. Claimed with a deadline ${since(deadline, now)}` : ''; - return { text: `${item.holder} is working on this, attempt ${item.held_attempt}, ${quiet}${lapse}.`, tone: 'ok' }; + const alive = beat(item.holder_alive_ms, now); + const process = alive ? `, ${alive.text}` : ''; + return { text: `${item.holder} is working on this, attempt ${item.held_attempt}, ${quiet}${process}${lapse}.`, tone: alive?.silent ? 'warn' : 'ok' }; } const waits = waitsText(item, blocked); switch (item.stage) { diff --git a/dashboard/src/card.ts b/dashboard/src/card.ts index 2c30af38..55f01984 100644 --- a/dashboard/src/card.ts +++ b/dashboard/src/card.ts @@ -42,11 +42,32 @@ export function ago(ms: number, now: number): string { return h < 24 ? `${h} h ago` : `${Math.round(h / 24)} d ago`; } +/** A heartbeat older than this reads as silence: three of the supervisor's one-minute beats missed. */ +export const BEAT_STALE_MS = 3 * 60_000; + +/** What the supervisor's last heartbeat says about a worker's process. */ +export interface Beat { + /** Beats stopped coming; the process may be gone or the supervisor down. */ + silent: boolean; + text: string; +} + +/** + * The recorded heartbeat as words: `process running` while beats are recent, `no heartbeat for 7 min` after. + * Null when none was ever recorded, which is also what a hosted worker has, so nothing is said. + */ +export function beat(alive_ms: number | null | undefined, now: number): Beat | null { + if (alive_ms == null) return null; + if (now - alive_ms <= BEAT_STALE_MS) return { silent: false, text: 'process running' }; + return { silent: true, text: `no heartbeat for ${ago(alive_ms, now).replace(/ ago$/, '')}` }; +} + /** Who holds the item, on which attempt, and how long it has been quiet. Null when no agent holds it. */ export function workingLine(i: ItemRow, now: number): string | null { if (!i.holder || !i.held_attempt) return null; - const quiet = i.active_ms ? `, last active ${ago(i.active_ms, now)}` : ''; - return `${i.holder} working, attempt ${i.held_attempt}${quiet}`; + const quiet = i.active_ms ? `, last tracker write ${ago(i.active_ms, now)}` : ''; + const alive = beat(i.holder_alive_ms, now); + return `${i.holder} working, attempt ${i.held_attempt}${quiet}${alive ? `, ${alive.text}` : ''}`; } export interface ChildSummary { diff --git a/dashboard/src/fold.ts b/dashboard/src/fold.ts index 42afe71c..27d24393 100644 --- a/dashboard/src/fold.ts +++ b/dashboard/src/fold.ts @@ -104,6 +104,8 @@ export interface ItemRow { /** The agent that holds it and when it last wrote, in the tracker's clock (ms). */ holder?: string | null; active_ms?: number | null; + /** When the holder's supervisor last recorded its process as running (`worker_alive`), or null. */ + holder_alive_ms?: number | null; /** When the agent's claim runs out, in the tracker's clock (ms). */ hold_deadline_ms?: number | null; /** The item this one is a child of, and what kind of work it is (`fix`, `triage`, `augment`, `review`, ...). */ diff --git a/dashboard/src/ui/app.css b/dashboard/src/ui/app.css index 39af77bd..0600cfee 100644 --- a/dashboard/src/ui/app.css +++ b/dashboard/src/ui/app.css @@ -374,6 +374,7 @@ kbd { min-width: 20px; padding: 1px var(--space-1); border: 1px solid var(--line .worker-state { font-weight: 600; } .worker-state.working { color: var(--ok); } .worker-state.releasing { color: var(--warn); } +.workers-table .beat.silent { color: var(--warn); font-weight: 600; } .worker-state.idle, .worker-state.finished, .worker-state.stopped { color: var(--muted); } /* The worker table is five columns; on a phone each worker becomes a small block instead. */ diff --git a/dashboard/src/ui/now-section.ts b/dashboard/src/ui/now-section.ts index b76bce79..d83e41cb 100644 --- a/dashboard/src/ui/now-section.ts +++ b/dashboard/src/ui/now-section.ts @@ -1,5 +1,5 @@ // The panel's Now line: one sentence on who holds the item and how recently it moved, or why -// it is not moving. It re-reads the clock on a timer, so "last activity 40 s ago" stays true. +// it is not moving. It re-reads the clock on a timer, so "last tracker write 40 s ago" stays true. import { nowLine, type ActivityEvent } from '../activity.ts'; import type { ItemRow } from '../fold.ts'; import type { ViewState } from '../state.ts'; diff --git a/dashboard/src/ui/workers-view.ts b/dashboard/src/ui/workers-view.ts index e134c0e4..ebedd5a1 100644 --- a/dashboard/src/ui/workers-view.ts +++ b/dashboard/src/ui/workers-view.ts @@ -1,9 +1,10 @@ // The Workers dialog: each supervisor with the workers it started, what each holds now, how // the ones that ended ended, and a stop for one worker or for a whole group. Everything shown is -// a recorded field of `worker_started`, `worker_stopped` or `worker_finished`, or of the hold. +// a recorded field of `worker_started`, `worker_stopped`, `worker_finished` or `worker_alive`, or of the hold. import { since } from '../activity.ts'; import type { ItemRow } from '../fold.ts'; import type { ViewState } from '../state.ts'; +import { beat } from '../card.ts'; import { groups, launchText, liveCount, liveNames, STATE_TEXT, summary, type Group, type WorkerLine, type WorkerRow } from '../workers.ts'; import { modal } from './dialog.ts'; import { h } from './dom.ts'; @@ -34,10 +35,16 @@ function holdCell(w: WorkerLine, s: ViewState, now: number, open: (id: string) = open(hold.item); }, }, hold.title ? `${hold.item} ${hold.title}` : hold.item); - const quiet = hold.active_ms ? `last active ${since(hold.active_ms, now)}` : ''; + const quiet = hold.active_ms ? `last tracker write ${since(hold.active_ms, now)}` : ''; return h('span', {}, link, h('span', { class: 'muted small' }, ` attempt ${hold.attempt}${quiet ? `, ${quiet}` : ''}`)); } +/** What the supervisor's last heartbeat says about a live worker's process; nothing for one that was never named in one. */ +function beatLine(w: WorkerLine, now: number): Node | null { + const b = w.state === 'working' || w.state === 'idle' ? beat(w.alive_ms, now) : null; + return b ? h('div', { class: `beat small ${b.silent ? 'silent' : 'muted'}`, 'data-beat': b.silent ? 'silent' : 'running' }, b.text) : null; +} + function ended(w: WorkerLine, now: number): string { if (w.stopped_ms === null) return `started ${since(w.started_ms, now)}`; return `${w.finished ? 'finished' : 'stopped'} ${since(w.stopped_ms, now)}`; @@ -94,7 +101,7 @@ export function workersView(on: WorkersHandlers) { const live = w.state === 'working' || w.state === 'idle'; return h('tr', { 'data-worker': w.worker, 'data-state': w.state }, h('th', { scope: 'row' }, w.worker, h('div', { class: 'muted small' }, ended(w, now))), - h('td', {}, h('span', { class: `worker-state ${w.state}` }, STATE_TEXT[w.state])), + h('td', {}, h('span', { class: `worker-state ${w.state}` }, STATE_TEXT[w.state]), beatLine(w, now)), h('td', {}, launchText(w) || null), h('td', {}, holdCell(w, s, now, on.open, () => m.close())), h('td', { class: 'num' }, live && on.canStop() diff --git a/dashboard/src/workers.ts b/dashboard/src/workers.ts index 60fdc0ac..fa3870f6 100644 --- a/dashboard/src/workers.ts +++ b/dashboard/src/workers.ts @@ -15,6 +15,8 @@ export interface WorkerRow { stopped_ms: number | null; /** It ended by its own `worker_finished` (format 24), not a stop. */ finished: boolean; + /** When its supervisor last recorded the process as running (`worker_alive`, format 26); null if never. */ + alive_ms: number | null; holds: { item: string; attempt: number } | null; } diff --git a/dashboard/test/activity.test.ts b/dashboard/test/activity.test.ts index 5d5bdc09..27e8f35c 100644 --- a/dashboard/test/activity.test.ts +++ b/dashboard/test/activity.test.ts @@ -18,11 +18,21 @@ test('since says how long ago, and how far ahead', () => { test('the Now line names the holder, the attempt, the last activity and the claim deadline', () => { const held = item({ stage: 'held', holder: 'agent1', held_attempt: 2, active_ms: NOW - 40_000, hold_deadline_ms: NOW + 50_000 }); const n = nowLine(held, [], [], NOW); - assert.equal(n.text, 'agent1 is working on this, attempt 2, last activity 40 s ago. Claimed with a deadline in 50 s.'); + assert.equal(n.text, 'agent1 is working on this, attempt 2, last tracker write 40 s ago. Claimed with a deadline in 50 s.'); assert.equal(n.tone, 'ok'); const late = nowLine({ ...held, hold_deadline_ms: NOW - 5_000 }, [], [], NOW); assert.equal(late.tone, 'ok'); - assert.equal(late.text, 'agent1 is working on this, attempt 2, last activity 40 s ago.'); + assert.equal(late.text, 'agent1 is working on this, attempt 2, last tracker write 40 s ago.'); +}); + +test('the Now line adds the worker heartbeat and warns when it went quiet', () => { + const held = item({ stage: 'held', holder: 'agent1', held_attempt: 2, active_ms: NOW - 6 * 60_000 }); + const busy = nowLine({ ...held, holder_alive_ms: NOW - 20_000 }, [], [], NOW); + assert.equal(busy.text, 'agent1 is working on this, attempt 2, last tracker write 6 min ago, process running.'); + assert.equal(busy.tone, 'ok'); + const stuck = nowLine({ ...held, holder_alive_ms: NOW - 9 * 60_000 }, [], [], NOW); + assert.equal(stuck.text, 'agent1 is working on this, attempt 2, last tracker write 6 min ago, no heartbeat for 9 min.'); + assert.equal(stuck.tone, 'warn'); }); test('the Now line says what a waiting item waits on', () => { @@ -97,7 +107,7 @@ test('a refused record is shown as refused and counts for nothing', () => { assert.match(t[3].detail ?? '', /did not take effect/); assert.equal(t[3].failed, true); const n = nowLine({ ...held, active_ms: null }, [], events, NOW); - assert.match(n.text, /last activity 10 min ago/, 'a refused write is not activity'); + assert.match(n.text, /last tracker write 10 min ago/, 'a refused write is not activity'); const acts = new Map([['k', [ev({ kind: 'answer', chosen: 'nope', refused: 'not_open_question' })]]]); const kid = item({ id: 'k', parent: 'a', work: 'triage', stage: 'ready' }); assert.equal(linked(item(), [item(), kid], [], acts).children[0].answer, null); diff --git a/dashboard/test/card.test.ts b/dashboard/test/card.test.ts index e0424e83..ac82e63a 100644 --- a/dashboard/test/card.test.ts +++ b/dashboard/test/card.test.ts @@ -32,7 +32,11 @@ test('children roll up under their top root with a progress chip', () => { test('the working line names the agent, attempt and time since it last wrote', () => { const held: ItemRow = { ...root, holder: 'agent-1', held_attempt: 2, active_ms: 1_000_000 }; - assert.equal(workingLine(held, 1_000_000 + 3 * 60_000), 'agent-1 working, attempt 2, last active 3 min ago'); + assert.equal(workingLine(held, 1_000_000 + 3 * 60_000), 'agent-1 working, attempt 2, last tracker write 3 min ago'); + // The supervisor's recorded heartbeat tells a busy worker from a stuck one. + const now = 1_000_000 + 6 * 60_000; + assert.equal(workingLine({ ...held, holder_alive_ms: now - 30_000 }, now), 'agent-1 working, attempt 2, last tracker write 6 min ago, process running'); + assert.equal(workingLine({ ...held, holder_alive_ms: now - 5 * 60_000 }, now), 'agent-1 working, attempt 2, last tracker write 6 min ago, no heartbeat for 5 min'); assert.equal(workingLine(root, 0), null); assert.equal(ago(0, 30_000), 'just now'); assert.equal(ago(0, 2 * 3_600_000), '2 h ago'); diff --git a/dashboard/test/workers.test.ts b/dashboard/test/workers.test.ts index bd26a883..5d95edf8 100644 --- a/dashboard/test/workers.test.ts +++ b/dashboard/test/workers.test.ts @@ -3,6 +3,7 @@ import { createRequire } from 'node:module'; import { test } from 'node:test'; import { COMMANDS } from '../src/keys.ts'; import { Tracker, type Fetch } from '../src/tracker.ts'; +import { beat } from '../src/card.ts'; import { groups, launchText, liveNames, stateOf, stopEach, stopRequest, summary, workers, type WorkerRow } from '../src/workers.ts'; import { items } from '../src/fold.ts'; import type { Outcome } from '../src/writes.ts'; @@ -21,7 +22,7 @@ function folded() { const person = (o: object) => apply({ by: 'gabriel', actor: 'person', ...o }); const agent = (by: string, o: object) => apply({ v: 24, by, actor: 'agent', ...o }); const as = (by: string, sup: string, o: object) => apply({ v: 24, by, sup, actor: 'agent', ...o }); - person({ v: 24, kind: 'format_raised', to: 24 }); + person({ v: 26, kind: 'format_raised', to: 26 }); apply({ kind: 'imported', item: 'r1', source: 'github', upstream_id: 'GetFelix/felix#1', title: 'Fix the lease', actor: 'tracker', by: 'ingest' }); person({ kind: 'accepted', item: 'r1', tier: 1 }); const start = (by: string, worker: string, hash: string, extra: object = {}) => @@ -32,6 +33,7 @@ function folded() { start('sup', 'sup-d', 'd'); start('other', 'other-x', 'e'); as('sup-a', 'sup', { kind: 'claimed', item: 'r1', attempt: 1, deadline_ms: 1800000090000 }); + agent('sup', { v: 26, kind: 'worker_alive', workers: ['sup-a', 'sup-b'] }); as('sup-c', 'sup', { kind: 'worker_finished' }); person({ v: 24, kind: 'worker_stopped', worker: 'sup-d' }); assert.deepEqual(JSON.parse(fold.state_json()).rejections, []); @@ -66,7 +68,7 @@ test('a group is a supervisor with live workers first, and says how the pool end }); test('a worker that holds a missing item still shows it, and an ended worker is Releasing while it still holds', () => { - const row = (o: Partial): WorkerRow => ({ worker: 's-a', supervisor: 's', vendor: null, profile: null, model: null, started_ms: 1, stopped_ms: null, finished: false, holds: null, ...o }); + const row = (o: Partial): WorkerRow => ({ worker: 's-a', supervisor: 's', vendor: null, profile: null, model: null, started_ms: 1, stopped_ms: null, finished: false, alive_ms: null, holds: null, ...o }); const [g] = groups([row({ holds: { item: 'gone', attempt: 2 } })], []); assert.deepEqual(g.workers[0].hold, { item: 'gone', attempt: 2, title: null, stage: null, active_ms: null }); assert.equal(stateOf(row({ stopped_ms: 5, holds: { item: 'gone', attempt: 2 } })), 'releasing'); @@ -121,3 +123,23 @@ test('stopping several workers skips one already stopped and reports the first r test('Workers is a palette command', () => { assert.ok(COMMANDS.some((c) => c.id === 'workers')); }); + +test('a heartbeat the supervisor recorded reaches the worker row and the held item, and no other', () => { + const fold = folded(); + const rows = workers({ workersJson: () => fold.workers_json() }); + const at = (n: string) => rows.find((w) => w.worker === n)!.alive_ms; + assert.equal(typeof at('sup-a'), 'number'); + assert.equal(at('sup-a'), at('sup-b')); + assert.equal(at('sup-c'), null); + assert.equal(at('other-x'), null); + const held = items({ itemsJson: () => fold.items_json(), format: () => 26 } as never).find((i) => i.id === 'r1')!; + assert.equal(held.holder_alive_ms, at('sup-a')); +}); + +test('a recent heartbeat reads as running, an old one as silence, and none says nothing', () => { + const now = 10_000_000; + assert.deepEqual(beat(now - 30_000, now), { silent: false, text: 'process running' }); + assert.deepEqual(beat(now - 7 * 60_000, now), { silent: true, text: 'no heartbeat for 7 min' }); + assert.equal(beat(null, now), null); + assert.equal(beat(undefined, now), null); +}); diff --git a/docs/design/supervise.md b/docs/design/supervise.md index 05a42122..e37f50be 100644 --- a/docs/design/supervise.md +++ b/docs/design/supervise.md @@ -13,6 +13,7 @@ Issue [#420](https://github.com/GetFelix/KBL/issues/420). This page is the desig | `worker_started {worker, token_sha256, supervisor_token_sha256, vendor?, profile?, model?}` | The supervisor's agent token | The writer is an agent and not itself a worker (one level). `worker` is `-`, never used before. Both hashes are 64 hex digits; the worker's is unique. At most 64 live workers per supervisor | | `worker_stopped {worker}` | The worker's supervisor, a person, or the tracker when the supervisor is gone | The worker is live. Its token stops working and its name is never reused | | `worker_finished` (format 24) | The worker itself, with `sup` set | The writer is a live worker acting for its live supervisor. It ends the worker as a stop does, and the worker shows `finished` | +| `worker_alive {workers}` (format 26) | The supervisor's agent token | Every name is a live worker of the writer, and there are 1 to 64. All or none: one name that is not refused the note. Sets each worker's `alive_ms` | | `released` with reason `supervisor_gone` | The tracker | The hold goes back and the try it used is given back. Written when a supervisor is gone, and also when a worker is stopped or finishes | | `sup` on any record | The tracker, from the token | Set exactly when `by` is a live worker, and then it must be that worker's supervisor (`bad_worker` otherwise). Any record with `sup` is format 21 | @@ -132,12 +133,27 @@ worker a person or the tracker stopped is dropped the same way and listed under after 3 quick or failed ends in a row. A hosted worker that dies without calling it is still counted live until it is stopped. +### Heartbeat + +A worker's last tracker write says little: a long step, such as a build, goes minutes without one. So once a minute +`kbl-mcp` checks which command workers' processes are still running and records them with one `worker_alive` +(`POST /v1/work/workers/alive {workers}`). The tracker leaves out any name that is not the supervisor's live worker, so a +worker that ended since the check does not refuse the note, and writes nothing when none is left. A tracker below +format 26 refuses the call and the supervisor carries on. A hosted worker has no process to check, so it never gets one. + +The dashboard reads the field and does not infer anything from it. A live worker whose last heartbeat is under 3 minutes +old shows `process running`, an older one `no heartbeat for 7 min`, and one with no heartbeat shows nothing. The same +words follow the holder on a card, a row and the item's Now line, next to `last tracker write 6 min ago`, so a long +quiet step reads as a running process and a dead supervisor or process reads as silence. A worker whose process ended is +stopped by its supervisor in the same round, so it shows Stopped, never silent. + ### Dashboard The dashboard's Workers dialog shows the group: each supervisor, the workers it started, and for each its state, launch fields, age and hold (see the [dashboard README](../../dashboard/README.md)). It reads `worker_started`, -`worker_stopped`, `worker_finished` and the hold from the fold, nothing else, so a worker that died without -reporting shows Working or Idle until someone stops it. A signed-in person can stop one worker or every live worker +`worker_stopped`, `worker_finished`, `worker_alive` and the hold from the fold, nothing else. A hosted worker that died +without reporting shows Working or Idle until someone stops it; a command worker whose process ended is stopped by its +supervisor, and one whose supervisor went quiet shows `no heartbeat` ([heartbeat](#heartbeat)). A signed-in person can stop one worker or every live worker of a supervisor; each stop is the same `POST /v1/work/workers/stop` a supervisor calls. ![The Workers dialog: two supervisors, a stop-all confirm, working, finished and stopped workers](../screenshots/dashboard-workers.png) diff --git a/docs/threat-model-citations.json b/docs/threat-model-citations.json index e3397213..c36cc6ad 100644 --- a/docs/threat-model-citations.json +++ b/docs/threat-model-citations.json @@ -173,7 +173,8 @@ "if it.accepted {", "if rec.actor != Actor::Tracker {", "if it.pr.as_deref() != Some(status.pr.as_str()) {", - "if source.len() > MAX_PR_REF || repo.len() > MAX_PR_REF {" + "if source.len() > MAX_PR_REF || repo.len() > MAX_PR_REF {", + "|| !workers.iter().all(mine)" ], "core/src/work_fold.rs#upstream_sync": [ "if it.parent.is_some() {", @@ -499,6 +500,9 @@ "tracker/src/http.rs#usage_of": [ "fn usage_of(usage: Vec, cost_micros: Option) -> Result, Error> {" ], + "tracker/src/http.rs#worker_alive": [ + "Ok(a) if a.supervisor().is_none() => a," + ], "tracker/src/http.rs#worker_finish": [ "Ok(a) if a.supervisor().is_some() => a," ], @@ -747,6 +751,9 @@ "tracker/src/tracker/tools.rs#triage_lists": [ "|| related.len() > MAX_TRIAGE_LIST" ], + "tracker/src/tracker/workers.rs#workers_alive": [ + ".filter(|k| names.contains(k))" + ], "tracker/src/tracker/workers.rs#finish_worker": [ "WorkRecord::WorkerFinished," ], diff --git a/docs/threat-model.md b/docs/threat-model.md index 81d1b30e..ce565230 100644 --- a/docs/threat-model.md +++ b/docs/threat-model.md @@ -275,6 +275,7 @@ in `check_sizes` (`tracker/src/tracker/tools.rs#check_sizes`). | `POST /v1/work/workers` | `worker_started` | Agent token only, and not a worker's: the fold refuses a worker that starts workers (`core/src/work_fold.rs#step_record`). The name must be `-` (`tracker/src/http.rs#worker_start`); agent names have no `-`, so it is never an agent's (`core/src/names.rs#worker`). The supervisor's token hash is logged with it. Caps per supervisor and per team (`tracker/src/tracker/workers.rs#start_worker`), 64 per supervisor in the fold. The token is 256 random bits, returned once; only its SHA-256 is logged. Vendor, profile and model are 1 to 64 bytes with no control or text-direction characters. Format 21 | | `POST /v1/work/workers/stop` | `worker_stopped`, `released` | The worker's own supervisor or a person (`core/src/work_fold.rs#step_record`). The token fails once the record is applied (`tracker/src/tracker/workers.rs#refresh_workers`), and the hold goes back in the same call with `supervisor_gone`, no try spent (`tracker/src/tracker/workers.rs#release_held`). A release that did not land is retried by every sweep (`tracker/src/tracker/workers.rs#release_stopped_holds`), and meanwhile the fold refuses any write by the stopped worker (`core/src/work_fold.rs#check_worker`) | | `POST /v1/work/workers/finish` | `worker_finished`, `released` | A worker's own token only: an agent without workers, a supervisor and a person get 403 (`tracker/src/http.rs#worker_finish`). The fold takes it only from an agent actor acting for its live supervisor, so a person or supervisor cannot end a worker this way, and a second finish is `bad_worker` (`core/src/work_fold.rs#step_record`). A hold it still has goes back with `worker_finished`, which spends the try, so finishing over and over cannot hand a poison item back free (`tracker/src/tracker/workers.rs#finish_worker`); the response names a release that failed, and the sweep retries it. Format 24 | +| `POST /v1/work/workers/alive` | `worker_alive` | A supervisor's own agent token only: a worker's token and a person get 403 (`tracker/src/http.rs#worker_alive`). The tracker drops every name that is not a live worker of the caller before writing, and the fold refuses a note that names another supervisor's or a stopped worker (`tracker/src/tracker/workers.rs#workers_alive`, `core/src/work_fold.rs#step_record`). At most 64 names, one write a minute from `kbl-mcp`. The note is only a claim the supervisor makes about its own workers' processes, and the dashboard shows it as that. Format 26 | | A supervisor revoked, removed or given another token | `worker_stopped`, `released` | The tracker stops every live worker of that identity and releases its holds with `supervisor_gone`, no try spent (`tracker/src/tracker/workers.rs#stop_workers`): at once on revoke (`tracker/src/tracker.rs#revoke`), and on a 5 s check otherwise, only on evidence (`tracker/src/teams.rs#stop_orphans`) | | A worker name and an agent name, in any order | refused | Worker names are `-`, split at the first `-`, and agent names have no `-` (`core/src/names.rs#worker`): no agent added before, after or after a revoke can take a worker's name, no worker takes an agent's, and one supervisor cannot name another's worker. From format 21 the fold refuses an agent record under a name with a `-` that is not that live worker (`core/src/work_fold.rs#check_worker`), and a stopped name is never reused (`core/src/work_fold.rs#step_record`). A hold is acted on only by the name that took it, never its supervisor or a sibling | | `POST /v1/work/workers/exchange` | none | No bearer: the code is the credential. A code is 256 random bits, made only for a start with `exchange: true`, kept in memory by its SHA-256, traded once (removed on the first try, good or not) and for 10 minutes; at most 1024 wait at once (`tracker/src/http/exchange.rs#Codes::redeem`). A start with `exchange` answers no token, and a replayed one answers no code, so one token never has two codes (`tracker/src/http.rs#worker_start`) | @@ -567,6 +568,7 @@ token. A kind an actor may not write is refused with `actor_not_allowed`. | `worker_started` | Agent, not a worker | Named `-`, never reused, hash unique, 64 live per supervisor (`core/src/work_fold.rs#step_record`). Format 21 | | `worker_stopped` | The worker's supervisor, a person, or the tracker | `core/src/work_fold.rs#step_record`. Format 21 | | `worker_finished` | A worker, for itself | Agent actor with `sup` set, from a live worker of its live supervisor; refused as `actor_not_allowed` for anyone else, `bad_worker` once the worker has ended (`core/src/work_fold.rs#step_record`, `core/src/work_fold.rs#check_worker`). Format 24 | +| `worker_alive` | A supervisor, for its own workers | Agent actor with no `sup`; refused as `actor_not_allowed` for a worker, a person or the tracker. Every name must be a live worker of the writer, 1 to 64, else `bad_worker` for the whole note (`core/src/work_fold.rs#step_record`). Sets only `alive_ms`, which gates nothing. Format 26 | | `format_raised` | Person | Only upward, only to a format the tracker's build reads, and stamped with that format (`core/src/work_fold.rs#format_gate`). An older reader stops at it ([upgrades.md](upgrades.md)) | ## Records on the run log diff --git a/docs/upgrades.md b/docs/upgrades.md index 824e36fc..09d84efc 100644 --- a/docs/upgrades.md +++ b/docs/upgrades.md @@ -67,7 +67,7 @@ byte as before. Each build has one number, `FORMAT` in `core/src/work.rs`: the highest format it reads and writes. It reads every format from 1 up to that. Today `FORMAT` -is 25. +is 26. A log with no records starts at `FORMAT`: the tracker writes the raise as the log's first record when it starts on an empty log, so a new stack needs no @@ -111,6 +111,7 @@ on it. | 23 | `check_failed` (ingest): a failed check with the end of its job log, once per request, check and head commit. With `fix`, which only the tracker sets under `auto_fix_tries`, the fold opens a `fix_check` child; a red check with an open `fix_check` for it is not Needs you, and green checks close the fix (a held one when its agent lets go). It refuses a check the last status does not show failing (`not_failing`) and a repeat (`duplicate`) ([work tracker](work-tracker.md#failed-checks-become-fix-work)) | Until the raise, `check_failed` is refused with `format`, so every red check goes to Needs you as before. A reader below 23 stops at the raise | | 24 | `worker_finished`: a hosted worker's own report that it is done ([supervise](design/supervise.md#hook-workers-that-finish)). Only the worker writes it, with its supervisor on the record; the fold ends the worker as a stop does, so its token dies and its name is never reused. Anyone else's is refused (`actor_not_allowed`, `bad_worker`) | Until the raise, `POST /v1/work/workers/finish` is refused with `format`, and a hook worker counts as live until its supervisor stops it. A reader below 24 stops at the raise | | 25 | The triage policy ([work tracker](work-tracker.md#accepting-routine-triage-by-policy)): `accepted` with `admitted_by`, which only the tracker writes for a rule, `intake_tier`, the tracker's record of an intake rule's tier for an admitted root, and `admission_undone`, a person's take-back of such an acceptance. An `accepted` with `admitted_by` before the raise is refused (`format`), and so is `admission_undone` | Until the raise the tracker runs no rule, so every triage waits for a person as before, and `POST /v1/work/proposals/undo-admission` is refused with `format`. A reader below 25 stops at the raise | +| 26 | `worker_alive`: a supervisor's note that the processes of some of its own live workers are running ([supervise](design/supervise.md#heartbeat)). Only the supervisor's agent token writes it. The fold sets the worker's `alive_ms` and refuses the whole note when a name is not a live worker of that supervisor, the list is empty or over 64, or a worker or a person wrote it (`bad_worker`, `actor_not_allowed`) | Until the raise, `POST /v1/work/workers/alive` is refused with `format`, a supervisor ignores that, and the dashboard shows no heartbeat. A reader below 26 stops at the raise | `org.events` ([teams](design.md#teams)) has its own number, `ORG_FORMAT` in `core/src/org.rs`, now 2. It follows the same rules. An org admin raises it with `POST /v1/org/records` and `{"record": {"kind": "format_raised", "to": 2}}`; a reader below the new format stops at the raise. diff --git a/docs/work-tracker.md b/docs/work-tracker.md index 5b9db5dc..63bc5300 100644 --- a/docs/work-tracker.md +++ b/docs/work-tracker.md @@ -495,6 +495,7 @@ record if the fold accepts it: | `POST /v1/work/workers` `{worker, vendor?, profile?, model?}` (agent token) | `worker_started`. Registers a worker named `-` that acts for you, and returns its token once. Capped by `KBL_MAX_WORKERS` per supervisor (default 8) and `KBL_MAX_TEAM_WORKERS` per team (default 32), refused with `worker_cap` past them. [Format 21](upgrades.md#formats); see [supervise](design/supervise.md) | | `POST /v1/work/workers/stop` `{worker}` (agent or person token) | `worker_stopped`. The worker's token stops working and the item it holds goes back in the same call, at no cost to its tries (a stop whose release did not land is finished by the next sweep). The dashboard's Workers dialog sends it with the viewer's person token. When a supervisor is revoked, removed or given another token, the tracker stops its workers and releases their holds at no cost to the items' tries | | `POST /v1/work/workers/finish` `{}` (a worker's token) | `worker_finished`. The worker says it is done: it ends like a stop, and anything it holds goes back and spends a try. Refused for any other token. [Format 24](upgrades.md#formats); see [supervise](design/supervise.md#hook-workers-that-finish) | +| `POST /v1/work/workers/alive` `{workers}` (a supervisor's token) | `worker_alive`. The supervisor says which of its live workers' processes are running; names that are not its live workers are left out, and nothing is written when none is left. Refused for a worker's or a person's token. [Format 26](upgrades.md#formats); see [supervise](design/supervise.md#heartbeat) | | `POST /v1/work/workers/exchange` `{code}` (no token) | Trades the one-time code a start with `exchange: true` answered, instead of a token, for the worker's token. A code works once and for 10 minutes and is kept in memory only, so a tracker restart loses it. For hosted workers started through a hook; see [supervise](design/supervise.md) | | `GET /v1/work/workers` (agent or person token) | Your workers, or every worker for a person: supervisor, vendor, profile, model, what each holds, when it stopped, and whether it finished on its own | | `POST /v1/work/prices` `{model, unit, price_micros, effective_from_ms?, expected_price?}` | `price_set`: the price of one unit of a model from now, or from a later time. See [Cost and spend](#cost-and-spend) | diff --git a/mcp/src/main.rs b/mcp/src/main.rs index faa1dc42..ecf2cc61 100644 --- a/mcp/src/main.rs +++ b/mcp/src/main.rs @@ -183,6 +183,7 @@ async fn serve() -> Result<()> { Box::new(|name| std::env::var(name).ok()), )?; sup.spawn_top_up(); + sup.spawn_heartbeat(); Some(sup) } _ => None, diff --git a/mcp/src/supervise.rs b/mcp/src/supervise.rs index 2e7de941..b4a9b361 100644 --- a/mcp/src/supervise.rs +++ b/mcp/src/supervise.rs @@ -32,6 +32,9 @@ pub(crate) const MAX_POOL: usize = 64; const MAX_NAMES: u32 = 99_999; /// Workers in a row that fail or exit too soon before the top-up pauses. const PAUSE_AFTER: u32 = 3; +/// How often the supervisor records that its workers' processes are running. +/// The dashboard calls a worker silent after several of these are missed. +const HEARTBEAT: Duration = Duration::from_secs(60); /// How many ready items one look at the queue reads. const PEEK: u64 = 50; /// How long a hook may take to answer. @@ -169,6 +172,44 @@ impl Supervisor { }); } + /// Records every `HEARTBEAT` which command workers' processes are still + /// running, so a person can tell a busy worker from a stuck one. + pub(crate) fn spawn_heartbeat(&self) { + let me = self.clone(); + tokio::spawn(async move { + let mut tick = tokio::time::interval(HEARTBEAT); + tick.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Delay); + loop { + tick.tick().await; + me.beat().await; + } + }); + } + + /// One heartbeat: a `worker_alive` for the workers whose process is + /// running now. A tracker below format 26 refuses it, which is fine. + pub(crate) async fn beat(&self) { + let alive: Vec = { + let mut pool = self.0.pool.lock().await; + pool.workers + .iter_mut() + .filter(|(_, r)| !r.stop_pending) + .filter_map(|(name, r)| { + let child = r.child.as_mut()?; + matches!(child.try_wait(), Ok(None)).then(|| name.clone()) + }) + .collect() + }; + if alive.is_empty() { + return; + } + let _ = self + .0 + .api + .call("/v1/work/workers/alive", json!({ "workers": alive })) + .await; + } + /// One top-up round: reap, then fill the pool. pub(crate) async fn round(&self) { let mut pool = self.0.pool.lock().await; diff --git a/mcp/src/supervise/tests.rs b/mcp/src/supervise/tests.rs index 4b63b980..16b0dab0 100644 --- a/mcp/src/supervise/tests.rs +++ b/mcp/src/supervise/tests.rs @@ -23,6 +23,8 @@ struct Script { lose_start_reply: bool, /// Workers that reported they are done. finished: Vec, + /// The worker lists of each heartbeat. + alive: Vec, /// Stops are refused with this text. refuse_stop: Option<&'static str>, /// Starts are refused with this text. @@ -53,6 +55,10 @@ impl TrackerApi for Fake { Ok(json!({ "worker": name, "token": format!("kblw_{name}") })) } } + "/v1/work/workers/alive" => { + s.alive.push(body["workers"].clone()); + Ok(json!({ "written": true })) + } "/v1/work/workers/stop" => { if let Some(why) = s.refuse_stop { return Err(CallError::Refused(why.into())); @@ -318,6 +324,30 @@ async fn workers_that_keep_failing_pause_the_top_up() { assert_eq!(sup.status().await.unwrap()["failed"], json!([])); } +#[tokio::test] +async fn a_heartbeat_names_the_workers_whose_process_is_running_and_no_other() { + let dir = scratch(); + let fake = Fake::default(); + fake.0.lock().unwrap().ready = ready(1); + // The worker sleeps, so its process is running at the first beat. + let sup = setup(&dir, "", "0", "30", &fake); + sup.beat().await; + assert!( + fake.0.lock().unwrap().alive.is_empty(), + "no worker, no beat" + ); + sup.start(1, json!({}), None, None).await.unwrap(); + sup.beat().await; + assert_eq!(fake.0.lock().unwrap().alive, [json!(["sup-w1"])]); + sup.stop(None, true).await.unwrap(); + sup.beat().await; + assert_eq!( + fake.0.lock().unwrap().alive.len(), + 1, + "a stopped worker is not vouched for" + ); +} + #[tokio::test] async fn a_pause_from_refused_launches_says_why() { let dir = scratch(); diff --git a/tracker/src/http.rs b/tracker/src/http.rs index 9f61f183..589254d2 100644 --- a/tracker/src/http.rs +++ b/tracker/src/http.rs @@ -237,6 +237,7 @@ fn work_routes() -> Router>> { ) .route("/v1/work/workers/stop", post(worker_stop::)) .route("/v1/work/workers/finish", post(worker_finish::)) + .route("/v1/work/workers/alive", post(worker_alive::)) .route("/v1/work/prices", post(price::)) .route("/v1/work/rules", post(rules::)) .route("/v1/work/classify", post(classify::)) @@ -1028,6 +1029,12 @@ struct WorkerExchangeBody { #[serde(deny_unknown_fields)] struct WorkerFinishBody {} +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +struct WorkerAliveBody { + workers: Vec, +} + #[derive(Deserialize)] #[serde(deny_unknown_fields)] struct WorkerStopBody { @@ -1146,6 +1153,25 @@ async fn worker_finish( reply(call.keyed(rk, call.tracker().finish_worker(&worker)).await) } +/// A supervisor says which of its workers' processes are still running. A +/// worker has no workers to vouch for. +async fn worker_alive(call: Call, Keyed(b, rk): Keyed) -> Response { + let sup = match call.agent() { + Ok(a) if a.supervisor().is_none() => a, + Ok(_) => { + return denied(( + StatusCode::FORBIDDEN, + "this call is for a supervisor's token", + )); + } + Err(d) => return denied(d), + }; + reply( + call.keyed(rk, call.tracker().workers_alive(&sup, b.workers)) + .await, + ) +} + /// An agent sees the workers it started; a person sees every worker. async fn worker_list(call: Call) -> Response { let sup = match &call.caller { diff --git a/tracker/src/http/tests/workers.rs b/tracker/src/http/tests/workers.rs index f8e866ee..597f48f3 100644 --- a/tracker/src/http/tests/workers.rs +++ b/tracker/src/http/tests/workers.rs @@ -219,3 +219,37 @@ async fn a_person_stops_any_worker_and_the_list_shows_it_stopped() { assert_eq!(status, StatusCode::CONFLICT); assert_eq!(again["why"], "bad_worker", "{again}"); } + +#[tokio::test] +async fn only_a_supervisor_records_its_workers_alive() { + let app = app_21().await; + raise_to(&app, 26).await; + let (_, reply) = call( + &app, + "/v1/work/workers", + Some("tok-w1"), + json!({ "worker": "w1-a" }), + ) + .await; + let tok = reply["token"].as_str().unwrap().to_owned(); + let alive = json!({ "workers": ["w1-a"] }); + // Not a person, not another supervisor's token, not the worker itself. + for token in ["tok-gab", &tok] { + let (status, _) = call(&app, "/v1/work/workers/alive", Some(token), alive.clone()).await; + assert_eq!(status, StatusCode::FORBIDDEN, "{token}"); + } + let (status, body) = call( + &app, + "/v1/work/workers/alive", + Some("tok-dup"), + alive.clone(), + ) + .await; + assert_eq!(status, StatusCode::OK, "{body}"); + assert_eq!(body["written"], false, "not its worker"); + let (status, body) = call(&app, "/v1/work/workers/alive", Some("tok-w1"), alive).await; + assert_eq!(status, StatusCode::OK, "{body}"); + assert_eq!(body["written"], true); + let (_, listed) = get_json(&app, "/v1/work/workers", Some("tok-w1")).await; + assert!(listed["workers"][0]["alive_ms"].is_u64(), "{listed}"); +} diff --git a/tracker/src/tracker/tests/workers.rs b/tracker/src/tracker/tests/workers.rs index 8928d166..a407c7e5 100644 --- a/tracker/src/tracker/tests/workers.rs +++ b/tracker/src/tracker/tests/workers.rs @@ -31,6 +31,14 @@ async fn at_24(fake: &Fake) -> Tracker { t } +async fn at_26(fake: &Fake) -> Tracker { + let t = start(fake).await; + t.person_record(key("gab"), WorkRecord::FormatRaised { to: 26 }) + .await + .unwrap(); + t +} + /// Starts `worker` for `sup`, bound to the token `sup` has in these tests. async fn start_for(t: &Tracker, sup: &str, worker: &str) -> Result { t.start_worker( @@ -395,3 +403,51 @@ async fn a_failed_release_after_a_finish_is_reported_and_the_sweep_finishes_it() assert!(core.state.held_by("sup-w1").is_none()); assert_eq!(tries_on(&core.state, "a1"), 1); } + +#[tokio::test] +async fn a_supervisor_records_which_of_its_own_live_workers_are_running() { + let fake = Fake::default(); + let t = at_26(&fake).await; + start_for(&t, "sup", "sup-w1").await.unwrap(); + start_for(&t, "sup", "sup-w2").await.unwrap(); + start_for(&t, "other", "other-w1").await.unwrap(); + t.stop_worker(Actor::Agent, key("sup"), key("sup-w2")) + .await + .unwrap(); + let names = |n: &[&str]| n.iter().map(|s| s.to_string()).collect::>(); + let done = t + .workers_alive(&agent("sup"), names(&["sup-w1", "sup-w2", "other-w1"])) + .await + .unwrap(); + assert_eq!(done["written"], true); + { + let core = t.0.core.lock().await; + assert!(core.state.workers[&key("sup-w1")].alive_ms.is_some()); + assert_eq!(core.state.workers[&key("sup-w2")].alive_ms, None); + assert_eq!(core.state.workers[&key("other-w1")].alive_ms, None); + assert!(core.state.rejections.is_empty()); + } + // Nothing of its own and live: nothing is written. + let before = fake.log().len(); + let none = t + .workers_alive(&agent("sup"), names(&["sup-w2", "other-w1"])) + .await + .unwrap(); + assert_eq!(none["written"], false); + assert_eq!(fake.log().len(), before); + // A restart keeps the heartbeat. + let t = start(&fake).await; + assert!(t.workers(Some(&key("sup"))).await["workers"][0]["alive_ms"].is_number()); +} + +#[tokio::test] +async fn a_heartbeat_needs_the_log_at_format_26() { + let fake = Fake::default(); + let t = at_24(&fake).await; + start_for(&t, "sup", "sup-w1").await.unwrap(); + let err = t + .workers_alive(&agent("sup"), vec!["sup-w1".into()]) + .await + .unwrap_err(); + assert!(matches!(err, Error::Format(_)), "{err}"); +} diff --git a/tracker/src/tracker/workers.rs b/tracker/src/tracker/workers.rs index 89d49765..7d34aca5 100644 --- a/tracker/src/tracker/workers.rs +++ b/tracker/src/tracker/workers.rs @@ -2,7 +2,7 @@ //! its own token, acting with the supervisor's grants and under its caps. use kbl_core::org::TokenHash; -use kbl_core::work::SUPERVISOR_GONE; +use kbl_core::work::{MAX_WORKERS_PER_SUPERVISOR, SUPERVISOR_GONE}; use kbl_core::work_fold::{State, Worker}; use super::*; @@ -156,6 +156,42 @@ impl Tracker { ) } + /// A supervisor records that the processes of these workers are running. + /// Names that are not its live workers are left out, since a worker may + /// have ended since the supervisor looked; nothing is written when none + /// is left. + pub(crate) async fn workers_alive( + &self, + supervisor: &AgentName, + names: Vec, + ) -> Result { + if names.len() > MAX_WORKERS_PER_SUPERVISOR { + return Err(Error::Invalid(format!( + "at most {MAX_WORKERS_PER_SUPERVISOR} workers" + ))); + } + let names = names + .iter() + .map(|n| Key::new(n).map_err(|_| Error::Invalid(format!("{n} is not a worker name")))) + .collect::, _>>()?; + self.begin().await?; + let by = Key::new(supervisor.as_str()).expect("an agent name is a key"); + let mut core = self.0.core.lock().await; + let mut workers: Vec = core + .state + .live_workers(&by) + .map(|(k, _)| k.clone()) + .filter(|k| names.contains(k)) + .collect(); + workers.dedup(); + if workers.is_empty() { + return Ok(json!({ "kind": "worker_alive", "written": false })); + } + let record = WorkRecord::WorkerAlive { workers }; + let offset = self.append(&mut core, Actor::Agent, by, record).await?; + Ok(json!({ "kind": "worker_alive", "written": true, "offset": offset })) + } + /// Gives back what an ended worker still holds, as a gone supervisor's /// workers do: no try is spent. async fn release_held(&self, core: &mut Core, worker: &Key) -> Result, Error> { @@ -241,6 +277,7 @@ impl Tracker { "started_ms": w.started_ms, "stopped_ms": w.stopped_ms, "finished": w.finished, + "alive_ms": w.alive_ms, "holds": holds.map(|(item, attempt)| json!({ "item": item, "attempt": attempt })), }) }) diff --git a/wasm/golden/format_26.jsonl b/wasm/golden/format_26.jsonl new file mode 100644 index 00000000..03ad0a7a --- /dev/null +++ b/wasm/golden/format_26.jsonl @@ -0,0 +1,11 @@ +{"v":26,"at_ms":1000,"by":"gabriel","actor":"person","kind":"format_raised","to":26} +{"v":21,"at_ms":1010,"by":"sup","actor":"agent","kind":"worker_started","worker":"sup-w1","token_sha256":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"} +{"v":21,"at_ms":1011,"by":"sup","actor":"agent","kind":"worker_started","worker":"sup-w2","token_sha256":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"} +{"v":21,"at_ms":1012,"by":"other","actor":"agent","kind":"worker_started","worker":"other-w1","token_sha256":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"} +{"v":26,"at_ms":1040,"by":"sup","actor":"agent","kind":"worker_alive","workers":["sup-w1"]} +{"v":26,"at_ms":1050,"by":"sup","actor":"agent","kind":"worker_alive","workers":["sup-w2","other-w1"]} +{"v":26,"at_ms":1060,"by":"sup","actor":"agent","kind":"worker_alive","workers":[]} +{"v":26,"at_ms":1070,"by":"sup-w1","actor":"agent","sup":"sup","kind":"worker_alive","workers":["sup-w1"]} +{"v":26,"at_ms":1080,"by":"gabriel","actor":"person","kind":"worker_alive","workers":["sup-w1"]} +{"v":21,"at_ms":1090,"by":"sup","actor":"agent","kind":"worker_stopped","worker":"sup-w2"} +{"v":26,"at_ms":1100,"by":"sup","actor":"agent","kind":"worker_alive","workers":["sup-w2"]} diff --git a/wasm/golden/format_26.state.json b/wasm/golden/format_26.state.json new file mode 100644 index 00000000..d1752b6f --- /dev/null +++ b/wasm/golden/format_26.state.json @@ -0,0 +1 @@ +{"at":10,"items":{},"edges":[],"release_edges":[],"budgets":{},"workers":{"other-w1":{"supervisor":"other","token_sha256":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc","started_ms":1012},"sup-w1":{"supervisor":"sup","token_sha256":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc","started_ms":1010,"alive_ms":1040},"sup-w2":{"supervisor":"sup","token_sha256":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","supervisor_token_sha256":"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc","started_ms":1011,"stopped_ms":1090}},"rejections":[{"offset":5,"why":"bad_worker"},{"offset":6,"why":"bad_worker"},{"offset":7,"why":"actor_not_allowed"},{"offset":8,"why":"actor_not_allowed"},{"offset":10,"why":"bad_worker"}],"upstream":{},"source_stalls":{},"child_keys":[],"format":26,"policy_since":0} \ No newline at end of file diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 2d2de77b..73b58219 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -146,7 +146,8 @@ impl Folder { /// or null; one with an `until_ms` in the past no longer holds, which the page checks /// against its own clock. `assignee` is who works it (`{"person": k}`), or null; `held_attempt` is /// the attempt an agent holds, or null; `holder` and `active_ms` name that - /// agent and when it last wrote. `redos_left` is how many redos the item's budget still + /// agent and when it last wrote; `holder_alive_ms` is when its supervisor last recorded the + /// holder's process as running, or null (no heartbeat, or the holder is not a live worker). `redos_left` is how many redos the item's budget still /// allows and `redo_pending` is true while a redo waits for an agent. `parent`, `work`, `upstream` (the root's /// `owner/repo#number`), `pr`, `pr_phase`, `pr_checks` and `failing_check` /// let a card nest and describe itself. `hold_deadline_ms` is when the hold lapses @@ -188,6 +189,12 @@ impl Folder { "pr_checks": pr.map(|p| p.checks), "failing_check": pr.and_then(|p| p.failing.as_ref()).map(|f| &f.name), "holder": i.hold.as_ref().map(|h| &h.by), + "holder_alive_ms": i + .hold + .as_ref() + .and_then(|h| self.state.workers.get(&h.by)) + .filter(|w| w.stopped_ms.is_none()) + .and_then(|w| w.alive_ms), "active_ms": i.hold.as_ref().map(|h| h.active_ms), "stage": self.state.stage(&i.id), "tier": i.tier, @@ -368,7 +375,7 @@ impl Folder { } /// Every delegated worker, stopped ones included, as `{worker, supervisor, vendor, - /// profile, model, started_ms, stopped_ms, finished, holds}` in name order. `holds` is + /// profile, model, started_ms, stopped_ms, finished, alive_ms, holds}` in name order. `holds` is /// `{item, attempt}` while the worker holds an item, else null. Token hashes are not /// included: the page has no use for them. pub fn workers_json(&self) -> String { @@ -387,6 +394,7 @@ impl Folder { "started_ms": w.started_ms, "stopped_ms": w.stopped_ms, "finished": w.finished, + "alive_ms": w.alive_ms, "holds": holds.map(|(item, attempt)| json!({ "item": item, "attempt": attempt })), }) }) diff --git a/wasm/tests/golden.rs b/wasm/tests/golden.rs index 972b7efd..72aaf3dd 100644 --- a/wasm/tests/golden.rs +++ b/wasm/tests/golden.rs @@ -150,6 +150,10 @@ fn logs() -> Vec<(&'static str, String)> { "format_25", std::fs::read_to_string(format!("{core}/work_format_25.jsonl")).unwrap(), ), + ( + "format_26", + std::fs::read_to_string(format!("{core}/work_format_26.jsonl")).unwrap(), + ), ( "pre_review", std::fs::read_to_string(format!("{core}/work_pre_review.jsonl")).unwrap(), From c03143bed142b41c689a132d62be2681b6d7f101 Mon Sep 17 00:00:00 2001 From: Gabriel Loewen Date: Thu, 19 Nov 2026 22:20:36 -0800 Subject: [PATCH 2/2] supervise test: no third ready item for the top-up to start while the first two are reaped --- mcp/src/supervise/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcp/src/supervise/tests.rs b/mcp/src/supervise/tests.rs index d83480d4..a0450181 100644 --- a/mcp/src/supervise/tests.rs +++ b/mcp/src/supervise/tests.rs @@ -187,7 +187,7 @@ async fn until_reaped(sup: &Supervisor, want: usize) { async fn a_worker_gets_its_own_token_in_a_private_file_and_none_of_the_supervisors() { let dir = scratch(); let fake = Fake::default(); - fake.0.lock().unwrap().ready = ready(3); + fake.0.lock().unwrap().ready = ready(2); let sup = setup(&dir, "", "0", "0", &fake); let reply = sup .start(2, json!({ "repo": "o/r" }), None, None)