Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/482-format-26-golden.documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`wasm/golden` gains `format_26` (a worker's `alive_ms`); no earlier golden changed.
1 change: 1 addition & 0 deletions changelog.d/482-last-tracker-write.changed.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions changelog.d/482-worker-heartbeat.added.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions core/src/redact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { .. }
Expand Down
14 changes: 13 additions & 1 deletion core/src/work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Key> },
/// 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.
Expand Down Expand Up @@ -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",
}
}
Expand Down Expand Up @@ -1453,6 +1463,7 @@ impl WorkRecord {
| WorkRecord::WorkerStarted { .. }
| WorkRecord::WorkerStopped { .. }
| WorkRecord::WorkerFinished
| WorkRecord::WorkerAlive { .. }
| WorkRecord::FlakeSet { .. }
| WorkRecord::FlakeCleared { .. }
| WorkRecord::Unknown => None,
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions core/src/work_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
}

/// One entry on the flake list, with how often ingest re-ran a check for it.
Expand Down Expand Up @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions core/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 11 additions & 0 deletions core/tests/work_format_26.jsonl
Original file line number Diff line number Diff line change
@@ -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"]}
4 changes: 2 additions & 2 deletions dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions dashboard/check/browser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
8 changes: 5 additions & 3 deletions dashboard/src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 23 additions & 2 deletions dashboard/src/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/fold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`, ...). */
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/ui/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Loading
Loading