@dibssoftware/dibs 0.0.180 → 0.0.195
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +111 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +379 -74
- package/docs/agents.md +303 -0
- package/docs/council.md +88 -0
- package/docs/files.md +3 -3
- package/docs/guard.md +86 -11
- package/docs/json.md +211 -0
- package/docs/later.md +5 -5
- package/docs/machines.md +6 -6
- package/docs/questions.md +104 -3
- package/docs/reference.md +124 -30
- package/docs/relay.md +135 -11
- package/docs/releasing.md +7 -1
- package/docs/scheduling.md +28 -6
- package/docs/secrets.md +53 -0
- package/docs/simulators.md +3 -3
- package/docs/windows.md +3 -3
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +79 -149
- package/src/about.mjs +341 -0
- package/src/acquire.mjs +113 -28
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +109 -48
- package/src/answers.mjs +2 -2
- package/src/board.mjs +21 -16
- package/src/broker.mjs +23 -7
- package/src/carry.mjs +287 -0
- package/src/codex.mjs +132 -0
- package/src/commands.mjs +254 -86
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +28 -12
- package/src/council.mjs +482 -0
- package/src/cwd.mjs +9 -0
- package/src/decisions.mjs +250 -0
- package/src/declare.mjs +96 -0
- package/src/diskreport.mjs +306 -0
- package/src/diskuse.mjs +420 -0
- package/src/diskwarn.mjs +68 -13
- package/src/doctor.mjs +149 -0
- package/src/doors.mjs +547 -0
- package/src/durable.mjs +143 -0
- package/src/envs.mjs +372 -0
- package/src/events.mjs +7 -2
- package/src/files.mjs +121 -7
- package/src/guard.mjs +288 -105
- package/src/guardd.mjs +8 -1
- package/src/halt.mjs +63 -0
- package/src/handoffs.mjs +362 -0
- package/src/history.mjs +34 -4
- package/src/hogs.mjs +36 -8
- package/src/jobprogress.mjs +283 -0
- package/src/later.mjs +21 -10
- package/src/lock.mjs +51 -11
- package/src/measure.mjs +60 -14
- package/src/media.mjs +240 -0
- package/src/news.mjs +31 -0
- package/src/notes.mjs +49 -8
- package/src/notices.mjs +126 -43
- package/src/ondemand.mjs +25 -2
- package/src/outcome.mjs +163 -0
- package/src/overlap.mjs +2 -2
- package/src/override.mjs +149 -79
- package/src/owner.mjs +15 -2
- package/src/people.mjs +236 -0
- package/src/pickup.mjs +72 -0
- package/src/picture.mjs +321 -0
- package/src/plain.mjs +84 -18
- package/src/platform.mjs +29 -7
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +11 -1
- package/src/progress.mjs +49 -3
- package/src/proof.mjs +102 -0
- package/src/push.mjs +271 -0
- package/src/questions.mjs +328 -57
- package/src/quota.mjs +1 -1
- package/src/recap.mjs +205 -0
- package/src/relay.mjs +262 -26
- package/src/remote.mjs +23 -10
- package/src/reviewgate.mjs +268 -0
- package/src/reviews.mjs +377 -0
- package/src/route.mjs +263 -0
- package/src/rules.mjs +216 -0
- package/src/schedule.mjs +238 -44
- package/src/schema.mjs +62 -0
- package/src/scratch.mjs +2 -2
- package/src/serve.mjs +3 -2
- package/src/service.mjs +5 -1
- package/src/signed.mjs +97 -0
- package/src/simpool.mjs +46 -1
- package/src/spend.mjs +375 -0
- package/src/state.mjs +43 -17
- package/src/talk.mjs +1082 -134
- package/src/thin.sh +2 -0
- package/src/trail.mjs +290 -0
- package/src/trailnote.mjs +209 -0
- package/src/util.mjs +7 -0
- package/src/vault.mjs +435 -0
- package/src/vendors.mjs +327 -0
- package/src/version.mjs +1 -1
- package/src/web.mjs +354 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/alerts.mjs
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
// list; the app turns a new one into a notification, at most one per cause
|
|
8
8
|
// every 30 minutes.
|
|
9
9
|
//
|
|
10
|
-
//
|
|
10
|
+
// Eight causes:
|
|
11
11
|
// wait a job waiting far longer than usual, worst when a person waits on it
|
|
12
12
|
// memory memory pressure or swap holding new jobs back, with what to close
|
|
13
13
|
// idle a slot held by a job that has done nothing for a long time
|
|
14
|
+
// slow a job far off its own pace, or running several times its usual time (src/jobprogress.mjs)
|
|
14
15
|
// ended jobs that failed, were stopped, or were lost on another machine
|
|
15
16
|
// dibs dibs itself: a service down or restarting, a crash, the hook failing
|
|
16
17
|
// disk free disk under the floor
|
|
@@ -19,25 +20,31 @@
|
|
|
19
20
|
//
|
|
20
21
|
// alerts.json keeps the open ones, the resolved ones for a day, and what the
|
|
21
22
|
// scan needs between runs: how far into the event log and the hook's log it
|
|
22
|
-
// has read, recent waits per resource, and the services' start counts.
|
|
23
|
-
//
|
|
24
|
-
//
|
|
23
|
+
// has read, recent waits per resource, and the services' start counts. The
|
|
24
|
+
// throttle watcher scans every SCAN_EVERY, so alerts keep up even when nobody
|
|
25
|
+
// looks; whatever shows the board scans too, every SCAN_EVERY without a
|
|
26
|
+
// watcher and every READER_EVERY with one.
|
|
25
27
|
import fs from 'node:fs';
|
|
26
28
|
import path from 'node:path';
|
|
27
29
|
import { HOME, paths, machine } from './config.mjs';
|
|
28
|
-
import { verdict } from './schedule.mjs';
|
|
29
|
-
import { stuckFor, minutes, andList } from './plain.mjs';
|
|
30
|
+
import { verdict, keptFree } from './schedule.mjs';
|
|
31
|
+
import { stuckFor, minutes, andList, waitingText, slowText } from './plain.mjs';
|
|
32
|
+
import { slowness } from './jobprogress.mjs';
|
|
30
33
|
import { processesNow, memoryUse } from './platform.mjs';
|
|
31
34
|
import { treeOf } from './measure.mjs';
|
|
32
35
|
import { withState, history } from './state.mjs';
|
|
33
36
|
import { markIdle, tableFirst } from './acquire.mjs';
|
|
34
37
|
import { sessionFiles } from './proc.mjs';
|
|
35
38
|
import { EVENTS } from './events.mjs';
|
|
36
|
-
import { serviceHealth } from './service.mjs';
|
|
39
|
+
import { serviceHealth, logName } from './service.mjs';
|
|
37
40
|
import { hogHint } from './hogs.mjs';
|
|
41
|
+
import { useHint } from './diskuse.mjs';
|
|
42
|
+
import { reportHint } from './diskreport.mjs';
|
|
38
43
|
import { underLock, heldBy } from './lock.mjs';
|
|
44
|
+
import { writeWhole, parsed } from './durable.mjs';
|
|
39
45
|
import { now, bytes, clock, gb, die } from './util.mjs';
|
|
40
46
|
import { dim, red, amber, wrap } from './style.mjs';
|
|
47
|
+
import { described } from './declare.mjs';
|
|
41
48
|
|
|
42
49
|
export const FILE = path.join(HOME, 'alerts.json');
|
|
43
50
|
// The throttle watcher's notes on the machine (src/cool.mjs noteCpu).
|
|
@@ -53,6 +60,13 @@ const STUCK_AFTER = 5 * MIN;
|
|
|
53
60
|
// Reads are cheap but not free (a verdict per waiter, the tail of two logs);
|
|
54
61
|
// the app polls every 2 s, so a scan stands for this long.
|
|
55
62
|
const SCAN_EVERY = 15e3;
|
|
63
|
+
// While the throttle watcher runs it scans every SCAN_EVERY, and a board, the page or the app
|
|
64
|
+
// scan only when nobody has for this long. A scan reads launchd once per service and top for
|
|
65
|
+
// memory: on 2026-11-11 that made every fifteenth-second board 2 s instead of 0.8. With no
|
|
66
|
+
// watcher, they scan every SCAN_EVERY as before.
|
|
67
|
+
const READER_EVERY = 60e3;
|
|
68
|
+
// A liveness hint only (kill 0, no ps): a reused pid costs alerts up to a minute's lag.
|
|
69
|
+
const watching = () => { try { process.kill(Number(fs.readFileSync(path.join(HOME, 'cool.pid'), 'utf8')), 0); return true; } catch (e) { return e.code === 'EPERM'; } };
|
|
56
70
|
// A wait is long past this, or past WAIT_TIMES its usual wait, whichever is later.
|
|
57
71
|
const WAIT_FLOOR = 10 * MIN;
|
|
58
72
|
const WAIT_TIMES = 3;
|
|
@@ -75,7 +89,7 @@ const FIRST_READ = 2 * 1024 ** 2;
|
|
|
75
89
|
// The rules a waiter is held by when the machine's memory, not a turn or dibs's budget, is in the way.
|
|
76
90
|
const PRESSURE = new Set(['pressure', 'swap', 'swaproom', 'ram', 'oversize']);
|
|
77
91
|
// Bumped when what makes an alert changes, so an upgrade rebuilds the open ones instead of closing them.
|
|
78
|
-
const RULES =
|
|
92
|
+
const RULES = 3;
|
|
79
93
|
// The same command failing this many times in a row, with no pass between, is worth the person's attention.
|
|
80
94
|
const REPEATS = 3;
|
|
81
95
|
// Exit codes a stopped command dies with: Ctrl-C, SIGKILL, SIGTERM.
|
|
@@ -91,8 +105,12 @@ export function stamp(at, t = now()) {
|
|
|
91
105
|
return `${day} ${clock(at)}`;
|
|
92
106
|
}
|
|
93
107
|
|
|
94
|
-
const what = x => (x
|
|
95
|
-
|
|
108
|
+
const what = x => described(x).replace(/\s+/g, ' ').slice(0, 70);
|
|
109
|
+
// A job as the person reads it: the agent, then its work in its own words. The number
|
|
110
|
+
// and the command to type go in run, for agents: the phone and the page show title, why
|
|
111
|
+
// and fix to the person, and on 2026-11-27 its Inbox read "alex-d5's #26745 (...)
|
|
112
|
+
// ... CPU budget: 2.6 of 10 cores in use, you need 9 ... dibs boost 26745 high".
|
|
113
|
+
const job = x => `${x.who}'s "${what(x)}"`;
|
|
96
114
|
const personWaits = q => q.prio === 'urgent' || q.prio === 'high' || typeof q.by === 'number';
|
|
97
115
|
const isDeploy = res => (res || []).some(r => r === 'deploy' || r.startsWith('deploy-') || r.startsWith('deploy:'));
|
|
98
116
|
// A failure the person cares about: a deploy, or a job they were waiting on.
|
|
@@ -106,9 +124,7 @@ function load() {
|
|
|
106
124
|
}
|
|
107
125
|
|
|
108
126
|
function save(st) {
|
|
109
|
-
|
|
110
|
-
fs.writeFileSync(tmp, JSON.stringify(st));
|
|
111
|
-
fs.renameSync(tmp, FILE);
|
|
127
|
+
writeWhole(FILE, JSON.stringify(st));
|
|
112
128
|
}
|
|
113
129
|
|
|
114
130
|
// One scan at a time. Whoever finds the lock taken shows what the file already
|
|
@@ -158,7 +174,8 @@ function readEvents(st, t) {
|
|
|
158
174
|
const x = { at: e.at, id: e.id, who: e.who, res: e.res, cmd: e.cmd, purpose: e.purpose, key: e.key, code: e.code, prio: e.prio, due: e.due };
|
|
159
175
|
if (by || STOPPED.has(e.code)) st.ended.push({ kind: 'stopped', ...x, by: by || null });
|
|
160
176
|
else if (e.code != null && e.code !== 0) st.ended.push({ kind: 'failed', ...x });
|
|
161
|
-
} else if (e.kind === '
|
|
177
|
+
} else if (e.kind === 'recovered') st.ended.push({ kind: e.kind, at: e.at, file: e.file, saved: e.saved, from: e.from, kept: e.kept, using: e.using });
|
|
178
|
+
else if (e.kind === 'lockstuck') st.ended.push({ kind: e.kind, at: e.at, key: e.key, pid: e.pid, cmd: e.cmd, held: e.held });
|
|
162
179
|
else if (e.kind === 'lost' || e.kind === 'crash') st.ended.push({ kind: e.kind, at: e.at, who: e.who, cmd: e.cmd, code: e.code, why: e.why, verb: e.verb });
|
|
163
180
|
}
|
|
164
181
|
st.ended = st.ended.filter(x => t - x.at < EVENT_KEEP);
|
|
@@ -202,7 +219,7 @@ export function memoryUsers(s, procs, use) {
|
|
|
202
219
|
const bytes = use.get(p.pid);
|
|
203
220
|
if (!bytes) continue;
|
|
204
221
|
const l = owner.get(p.pid);
|
|
205
|
-
const [name, cmd] = l ? [
|
|
222
|
+
const [name, cmd] = l ? [job(l)] : appOf(p, sessions);
|
|
206
223
|
const g = groups.get(name) || { name, bytes: 0, n: 0, dibs: !!l, ...(l && { id: l.id }), ...(cmd && { cmd: true }) };
|
|
207
224
|
g.bytes += bytes; g.n++;
|
|
208
225
|
groups.set(name, g);
|
|
@@ -249,7 +266,7 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
249
266
|
out.push({ id: `wait:#${q.id}`, cause: 'wait', level: personWaits(q) ? 'urgent' : 'warn', job: q.id, who: q.who, at: q.enq,
|
|
250
267
|
...(pressed(v) && !users && { want: 'users' }),
|
|
251
268
|
title: `${job(q)} has waited ${minutes(waited)}${usual >= MIN ? `, where ${q.res[0]} usually takes ${minutes(usual)}` : ''}${personWaits(q) ? `, and it's ${typeof q.by === 'number' ? `due by ${stamp(q.by, t)}` : q.prio}` : ''}`,
|
|
252
|
-
why: v
|
|
269
|
+
why: `Waiting for ${waitingText(s, q, v, cfg, hist, t, m)}`, ...waitFix(s, q, v, t, users) });
|
|
253
270
|
}
|
|
254
271
|
|
|
255
272
|
// Memory holding new jobs back.
|
|
@@ -260,10 +277,11 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
260
277
|
const close = list.filter(g => !g.dibs);
|
|
261
278
|
const ours = list.filter(g => g.dibs);
|
|
262
279
|
out.push({ id: 'memory', cause: 'memory', level: 'urgent', after: PRESSURE_AFTER, at: Math.min(...held.map(q => q.enq)), ...(!users && { want: 'users' }),
|
|
263
|
-
|
|
264
|
-
|
|
280
|
+
// The person reads agents and their work, not job numbers (2026-11-27).
|
|
281
|
+
title: `${swap ? 'Swap' : 'Memory'} is holding back ${andList(held.slice(0, 2).map(job))}${held.length > 2 ? ` and ${held.length - 2} more` : ''}`,
|
|
282
|
+
why: `Waiting for ${waitingText(s, held[0], verdicts.get(held[0].id), cfg, hist, t, m)}`,
|
|
265
283
|
detail: list.length ? `Using the most memory: ${list.map(sized).join(', ')}.` : '',
|
|
266
|
-
|
|
284
|
+
...memoryFix(list) });
|
|
267
285
|
}
|
|
268
286
|
|
|
269
287
|
// A slot held by a run that has used no CPU for a long while someone waits for it.
|
|
@@ -274,7 +292,22 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
274
292
|
if (!behind.length) continue;
|
|
275
293
|
out.push({ id: `idle:#${l.id}`, cause: 'idle', level: behind.some(personWaits) ? 'urgent' : 'warn', job: l.id, who: l.who, at: l.idleSince,
|
|
276
294
|
title: `${job(l)} has held ${l.res.join(', ')} for ${minutes(t - l.start)} and used no CPU for ${minutes(idle)}, while ${behind.length} job${behind.length > 1 ? 's wait' : ' waits'}`,
|
|
277
|
-
fix:
|
|
295
|
+
fix: "A job waiting on the network or another machine uses no CPU either. Stopping it ends it and lets the next job start.", run: `dibs stop ${l.id}` });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// A job far below its own earlier rate, or running several times as long as the same
|
|
299
|
+
// command usually takes (src/jobprogress.mjs slowness, which needs real history and a
|
|
300
|
+
// big gap). On 2026-11-27 a solver held the machine 7 hours at a sixth of its speed
|
|
301
|
+
// while a test waited 6 behind it, and nobody knew. dibs never stops it: whoever owns it decides.
|
|
302
|
+
for (const l of s.leases || []) {
|
|
303
|
+
const sl = slowness(l, hist, t);
|
|
304
|
+
if (!sl) continue;
|
|
305
|
+
const behind = waiting.filter(q => q.res.some(r => l.res.includes(r)));
|
|
306
|
+
const names = andList([...behind.slice(0, 2).map(job), ...(behind.length > 2 ? [`${behind.length - 2} more`] : [])]);
|
|
307
|
+
out.push({ id: `slow:#${l.id}`, cause: 'slow', level: behind.some(personWaits) ? 'urgent' : behind.length ? 'warn' : 'note', job: l.id, who: l.who,
|
|
308
|
+
title: `${job(l)} ${slowText(sl)}${behind.length ? `, while ${names} ${behind.length > 1 ? 'wait' : 'waits'} behind it` : ''}`,
|
|
309
|
+
fix: `dibs won't stop it. ${l.who} decides: if it's stuck or no longer worth the wait, stopping it lets ${behind.length ? 'the next one' : 'other work'} start; if it's working, leave it.`,
|
|
310
|
+
run: `dibs stop ${l.id}` });
|
|
278
311
|
}
|
|
279
312
|
|
|
280
313
|
// Jobs that failed, were stopped, or were lost, and dibs's own crashes. An
|
|
@@ -300,10 +333,10 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
300
333
|
// Stopped on purpose (exit 143 or 137, or dibs stop): on record in dibs alerts --all, nowhere louder.
|
|
301
334
|
out.push({ id: `stopped:#${x.id}`, cause: 'ended', level: 'note', at: x.at, job: x.id, who: x.who, quiet: true,
|
|
302
335
|
title: `${job(x)} was stopped${x.by ? ` by ${x.by}` : ''} at ${stamp(x.at, t)}${x.code != null ? ` (exit ${x.code})` : ''}`,
|
|
303
|
-
fix: `
|
|
336
|
+
fix: `Nothing else waits on it. It runs again only if ${x.who} starts it again.` });
|
|
304
337
|
} else if (x.kind === 'lost') {
|
|
305
338
|
out.push({ id: `lost:${x.at}`, cause: 'ended', level: 'urgent', at: x.at, who: x.who,
|
|
306
|
-
title: `${x.who}'s job was lost${x.code === 77 ? ' after it started' : ' before it started'} at ${stamp(x.at, t)}: ${x.why || x
|
|
339
|
+
title: `${x.who}'s job was lost${x.code === 77 ? ' after it started' : ' before it started'} at ${stamp(x.at, t)}: ${x.why || what(x)}`,
|
|
307
340
|
fix: x.code === 77 ? 'It may have run. Check what it changed before running it again.' : 'It never ran, so it\'s safe to run again.' });
|
|
308
341
|
} else if (x.kind === 'lockstuck') {
|
|
309
342
|
// Open while that same holder still has the lock; it closes the moment it lets go.
|
|
@@ -311,17 +344,36 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
311
344
|
if (now?.key !== x.key) continue;
|
|
312
345
|
out.push({ id: `lockstuck:${x.key}`, cause: 'dibs', level: 'urgent', at: x.at - x.held,
|
|
313
346
|
title: `dibs is stuck behind pid ${x.pid}${x.cmd ? ` (${x.cmd.slice(0, 80)})` : ''}: it has held the state lock for ${minutes(now.held)}, and every dibs command waits for it`,
|
|
314
|
-
fix: `
|
|
347
|
+
fix: `Ending pid ${x.pid} frees the lock, and every dibs command goes on at once.`, run: `kill ${x.pid}` });
|
|
348
|
+
} else if (x.kind === 'recovered') {
|
|
349
|
+
// A state file that didn't parse, put right (src/durable.mjs heal): what came back, what didn't.
|
|
350
|
+
const name = path.basename(x.file);
|
|
351
|
+
if (x.using) {
|
|
352
|
+
// The person's config.json, never written over: open until it parses again.
|
|
353
|
+
let fixed = false;
|
|
354
|
+
try { fixed = !!parsed(fs.readFileSync(x.file, 'utf8')); } catch {}
|
|
355
|
+
if (!fixed) out.push({ id: `recovered:${x.at}`, cause: 'dibs', level: 'warn', at: x.at,
|
|
356
|
+
title: `${name} isn't valid JSON since ${stamp(x.at, t)}, so dibs runs on its copy from ${stamp(x.from, t)}: changes made to it since aren't used`,
|
|
357
|
+
fix: `Fix ${x.file}, or remove it to get the defaults back. This closes once it reads.` });
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
out.push({ id: `recovered:${x.at}`, cause: 'dibs', level: 'warn', at: x.at,
|
|
361
|
+
title: x.from
|
|
362
|
+
? `${name} was broken at ${stamp(x.at, t)}, and dibs put back its copy from ${stamp(x.from, t)}${x.kept ? ` (${x.kept})` : ''}: whatever changed after that is lost`
|
|
363
|
+
: `${name} was broken at ${stamp(x.at, t)}, and with no earlier copy dibs started it empty: what it held is lost`,
|
|
364
|
+
fix: `${name !== 'state.json' ? '' : x.from ? 'A running job missing from the copy keeps running untracked, and a waiter missing from it was told to run again (exit 75). '
|
|
365
|
+
: 'Running jobs keep running untracked, and waiters were told to run again (exit 75). '}`
|
|
366
|
+
+ `The broken file is kept at ${x.saved}. dibs doctor checks every other file.`, run: 'dibs doctor' });
|
|
315
367
|
} else if (x.kind === 'crash') {
|
|
316
368
|
out.push({ id: `crash:${x.at}`, cause: 'dibs', level: 'urgent', at: x.at, who: x.who,
|
|
317
369
|
title: `dibs crashed at ${stamp(x.at, t)} running dibs ${x.verb || ''} for ${x.who}`,
|
|
318
|
-
fix:
|
|
370
|
+
fix: "It's a bug in dibs, not in the agent's work. Report it.", run: `dibs ask "crash in dibs ${x.verb || ''}"` });
|
|
319
371
|
}
|
|
320
372
|
}
|
|
321
373
|
for (const [k, g] of failed) {
|
|
322
374
|
const loud = g.cmd && g.n >= REPEATS;
|
|
323
375
|
out.push({ id: `failed:${hash(k)}`, cause: 'ended', level: loud ? 'warn' : 'note', at: g.first, last: g.at, who: g.who, ...(!loud && { quiet: true }),
|
|
324
|
-
title: `${g.who}'s ${what(g)} failed${g.n > 1 ? ` ${g.n} times in a row, last` : ''} at ${stamp(g.at, t)} (exit ${g.code})`,
|
|
376
|
+
title: `${g.who}'s run "${what(g)}" failed${g.n > 1 ? ` ${g.n} times in a row, last` : ''} at ${stamp(g.at, t)} (exit ${g.code})`,
|
|
325
377
|
fix: `${g.who} is the one to fix it; this closes when the same command passes.` });
|
|
326
378
|
}
|
|
327
379
|
|
|
@@ -330,19 +382,19 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
330
382
|
if (!h.running)
|
|
331
383
|
out.push({ id: `service:${k}`, cause: 'dibs', level: 'urgent',
|
|
332
384
|
title: `dibs's ${k} service isn't running${h.exit ? ` (it last exited with code ${h.exit})` : ''}: ${h.what}`,
|
|
333
|
-
fix: `Start it again
|
|
385
|
+
fix: `Start it again. Why it stopped is in ~/.dibs/${logName(k)}.`, run: `dibs service install ${k}` });
|
|
334
386
|
for (const k of new Set((st.restarts || []).map(r => r.k))) {
|
|
335
387
|
const rs = st.restarts.filter(r => r.k === k);
|
|
336
388
|
const last = rs[rs.length - 1];
|
|
337
389
|
out.push({ id: `restart:${k}`, cause: 'dibs', level: 'warn', at: rs[0].at,
|
|
338
390
|
title: `dibs's ${k} service crashed (exit ${last.exit}) and launchd started it again${rs.length > 1 ? `, ${rs.length} times in the last hour` : ''}, last at ${stamp(last.at, t)}`,
|
|
339
|
-
fix: `
|
|
391
|
+
fix: `Why is in ~/.dibs/${logName(k)}. Report it.`, run: `dibs ask "the ${k} service keeps exiting with ${last.exit}"` });
|
|
340
392
|
}
|
|
341
393
|
if (st.hook?.length) {
|
|
342
394
|
const last = st.hook[st.hook.length - 1];
|
|
343
395
|
out.push({ id: 'hook', cause: 'dibs', level: 'warn', at: st.hook[0].at,
|
|
344
396
|
title: `The Claude Code hook failed ${st.hook.length} time${st.hook.length > 1 ? 's' : ''} in the last hour, last at ${stamp(last.at, t)}: ${last.msg}`,
|
|
345
|
-
fix:
|
|
397
|
+
fix: "Those tool calls ran without dibs's checks. Report it.", run: `dibs ask "hook: ${last.msg.slice(0, 60)}"` });
|
|
346
398
|
}
|
|
347
399
|
|
|
348
400
|
// The hard stop (src/preempt.mjs hardStop): a job paused under 1 GB free, whatever it was.
|
|
@@ -362,52 +414,61 @@ export function detect({ s, cfg, hist, m, t, st, users }) {
|
|
|
362
414
|
for (const o of cpu.orphans || [])
|
|
363
415
|
out.push({ id: `orphan:${o.pid}`, cause: 'machine', level: 'warn',
|
|
364
416
|
title: `${o.name} ${o.pid} has run ${Math.round(o.age / HOUR)} hours outside dibs, using ${Math.round(o.cpu / HOUR)} CPU-hours, and its script ${o.script} is gone`,
|
|
365
|
-
fix:
|
|
417
|
+
fix: "Its script is gone, as happens when the session that started it has ended. dibs didn't start it, so it leaves it running.", run: `kill ${o.pid}` });
|
|
366
418
|
}
|
|
367
419
|
|
|
368
420
|
// Disk under the floor: nothing new starts.
|
|
369
421
|
const floor = bytes(cfg.minDisk || '0');
|
|
370
422
|
if (floor && m.diskFree != null && m.diskFree < floor)
|
|
371
423
|
out.push({ id: 'disk', cause: 'disk', level: 'urgent',
|
|
372
|
-
title: `Free disk is ${gb(m.diskFree).replace(/G$/, ' GB')},
|
|
424
|
+
title: `Free disk is ${gb(m.diskFree).replace(/G$/, ' GB')}, and dibs keeps ${keptFree(cfg)}, so only jobs that write next to nothing start; the rest wait for room`,
|
|
373
425
|
fix: diskFix() });
|
|
374
426
|
return out;
|
|
375
427
|
}
|
|
376
428
|
|
|
377
|
-
//
|
|
429
|
+
// What a boost does to a waiter, said as a fact: whether to use it is the person's call or its agent's.
|
|
430
|
+
const BOOST_MOVES = 'High priority moves a waiter 1 hour ahead in line, urgent 2 hours.';
|
|
431
|
+
|
|
432
|
+
// What holds a long-waiting job and what would let it start: { fix } in plain
|
|
433
|
+
// words for the person, and { run }, the command an agent types for it.
|
|
378
434
|
function waitFix(s, q, v, t, users) {
|
|
379
|
-
const boost = `dibs boost ${q.id} urgent -m "why"
|
|
435
|
+
const boost = { run: `dibs boost ${q.id} urgent -m "why"` };
|
|
380
436
|
if (v.rule === 'slot' || v.rule === 'files' || v.rule === 'together') {
|
|
381
437
|
// With one deploy per project (the per-repo lock), the one in the way is this project's.
|
|
382
438
|
const on = (s.leases || []).filter(x => x.res.includes(v.on));
|
|
383
439
|
const l = on.find(x => q.repo && x.repo === q.repo) || on[0] || v.ahead;
|
|
384
|
-
if (l && stuckFor(l, t)) return `${job(l)} holds ${v.on} and has done nothing for ${minutes(stuckFor(l, t))}:
|
|
385
|
-
|
|
440
|
+
if (l && stuckFor(l, t)) return { fix: `${job(l)} holds ${v.on} and has done nothing for ${minutes(stuckFor(l, t))}: stopping it lets this one start.`, run: `dibs stop ${l.id}` };
|
|
441
|
+
// The yield protocol (src/preempt.mjs): a --pausable job steps aside for urgent work by itself; any other is never stopped by dibs.
|
|
442
|
+
if (l) return { fix: `${job(l)} has had ${v.on} for ${minutes(t - l.start)}. High priority moves a waiter 1 hour ahead in line, urgent 2 hours. ${l.pausable
|
|
443
|
+
? 'It was started with --pausable: for urgent or high work, dibs pauses it, or has it save its progress and step aside, and picks it up again after.'
|
|
444
|
+
: "dibs doesn't stop a job not started with --pausable."}`, ...boost };
|
|
386
445
|
}
|
|
387
|
-
if (v.rule === 'ahead' && v.ahead) return `${job(v.ahead)} is ahead
|
|
446
|
+
if (v.rule === 'ahead' && v.ahead) return { fix: `${job(v.ahead)} is ahead of it. ${BOOST_MOVES}`, ...boost };
|
|
388
447
|
// What uses the memory, said here: an alert that points at another one that isn't there is no help.
|
|
389
448
|
if (pressed(v)) return memoryFix(users || []);
|
|
390
449
|
if (v.rule === 'memory') {
|
|
391
450
|
const big = (s.leases || []).filter(l => l.mem).sort((a, b) => b.mem - a.mem).slice(0, 3);
|
|
392
|
-
return `dibs's memory
|
|
451
|
+
return { fix: `dibs's memory is handed out to running jobs${big.length ? `, the biggest ${andList(big.map(l => `${job(l)} with ${gb(l.mem).replace(/G$/, ' GB')}`))}` : ''}. It starts as they end; if it can't wait, move it up.`, ...boost };
|
|
393
452
|
}
|
|
394
|
-
if (v.rule === 'disk' || v.rule === 'drain') return diskFix();
|
|
395
|
-
if (v.rule === 'load'
|
|
396
|
-
if (v.rule === '
|
|
397
|
-
if (v.rule === '
|
|
398
|
-
return `${v.
|
|
453
|
+
if (v.rule === 'disk' || v.rule === 'drain') return { fix: diskFix() };
|
|
454
|
+
if (v.rule === 'load') return { fix: 'The machine is past its load limit, where normal and lower work waits. High and urgent work starts past it.', run: `dibs boost ${q.id} high -m "why"` };
|
|
455
|
+
if (v.rule === 'cpu') return { fix: `The cores dibs hands out are in use, and waiters get them as they free up, in line order. ${BOOST_MOVES}`, run: `dibs boost ${q.id} high -m "why"` };
|
|
456
|
+
if (v.rule === 'idle') return { fix: 'It runs at idle priority, which waits while anyone else waits. At normal priority it takes its turn in arrival order.', run: `dibs boost ${q.id} normal` };
|
|
457
|
+
if (v.rule === 'reset') return { fix: `${v.on} is being reset after the last job; if that takes too long, check its onRelease in ~/.dibs/config.json.` };
|
|
458
|
+
return { fix: BOOST_MOVES, ...boost };
|
|
399
459
|
}
|
|
400
460
|
|
|
401
461
|
// What to close, from the biggest memory users on the machine.
|
|
402
462
|
function memoryFix(list) {
|
|
403
463
|
const close = list.filter(g => !g.dibs), ours = list.filter(g => g.dibs);
|
|
404
|
-
if (close.length) return `Close what you can of ${andList(close.slice(0, 3).map(sized))}. dibs won't close apps it didn't start.${ours.length ? ` Or stop
|
|
405
|
-
|
|
406
|
-
|
|
464
|
+
if (close.length) return { fix: `Close what you can of ${andList(close.slice(0, 3).map(sized))}. dibs won't close apps it didn't start.${ours.length ? ` Or stop ${ours[0].name}.` : ''}`,
|
|
465
|
+
...(ours.length && { run: `dibs stop ${ours[0].id}` }) };
|
|
466
|
+
if (ours.length) return { fix: `dibs's own jobs use it: stopping ${ours[0].name} frees the most.`, run: `dibs stop ${ours[0].id}` };
|
|
467
|
+
return { fix: "Close apps you aren't using; dibs won't close what it didn't start." };
|
|
407
468
|
}
|
|
408
469
|
|
|
409
470
|
function diskFix() {
|
|
410
|
-
return `Free disk: build output, caches and scratch folders${hogHint()}.`;
|
|
471
|
+
return `Free disk: build output, caches and scratch folders${hogHint()}${useHint()}${reportHint()}.`;
|
|
411
472
|
}
|
|
412
473
|
|
|
413
474
|
const median = xs => { if (!xs.length) return 0; const a = [...xs].sort((x, y) => x - y); return a[Math.floor(a.length / 2)]; };
|
|
@@ -438,10 +499,10 @@ export function merge(st, found, t) {
|
|
|
438
499
|
// Read what's new and bring alerts.json up to date, unless another process
|
|
439
500
|
// did within SCAN_EVERY. Returns the list to show. Never throws: the board,
|
|
440
501
|
// the watcher and the page call it, and none of them may fail over an alert.
|
|
441
|
-
export function scan({ s, cfg, hist, m = machine(), t = now(), force = false } = {}) {
|
|
502
|
+
export function scan({ s, cfg, hist, m = machine(), t = now(), force = false, watcher = false } = {}) {
|
|
442
503
|
try {
|
|
443
504
|
const was = load();
|
|
444
|
-
if (!force && was.at && t - was.at < SCAN_EVERY) return shown(was, t);
|
|
505
|
+
if (!force && was.at && t - was.at < (watcher || !watching() ? SCAN_EVERY : READER_EVERY)) return shown(was, t);
|
|
445
506
|
const st = locked(() => {
|
|
446
507
|
const st = load();
|
|
447
508
|
// Alerts made by older rules aren't resolved, only no longer said that way: start the open list over.
|
|
@@ -507,7 +568,7 @@ export function alertLines(list, t = now()) {
|
|
|
507
568
|
if (a.resolvedAt) out.push(dim(`Resolved at ${stamp(a.resolvedAt, t)}${a.dismissed ? ' (dismissed)' : ''}: ${a.title}.`));
|
|
508
569
|
else {
|
|
509
570
|
const paint = a.level === 'urgent' ? red : a.level === 'warn' ? amber : x => x;
|
|
510
|
-
out.push(paint(`${a.level === 'note' ? '' : '! '}${a.title} (since ${stamp(a.since, t)}).`), wrap(` Fix: ${a.fix}`, ' '));
|
|
571
|
+
out.push(paint(`${a.level === 'note' ? '' : '! '}${a.title} (since ${stamp(a.since, t)}).`), wrap(` Fix: ${a.fix}${a.run ? ` (${a.run})` : ''}`, ' '));
|
|
511
572
|
}
|
|
512
573
|
}
|
|
513
574
|
return out;
|
package/src/answers.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
|
|
9
9
|
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
10
|
-
const DOCS = ['skills/dibs/SKILL.md', 'README.md', ...['reference', 'guard', 'files', 'questions', 'later', 'machines', 'simulators', 'scheduling', 'relay'].map(d => `docs/${d}.md`)];
|
|
10
|
+
const DOCS = ['skills/dibs/SKILL.md', 'README.md', ...['reference', 'agents', 'json', 'guard', 'files', 'questions', 'later', 'machines', 'simulators', 'scheduling', 'relay'].map(d => `docs/${d}.md`)];
|
|
11
11
|
export const ISSUES = 'https://github.com/dibssoftware/dibs/issues';
|
|
12
12
|
// Two passages answer most questions; more is reading the docs.
|
|
13
13
|
const SHOW = 2;
|
|
@@ -16,7 +16,7 @@ const MAX_CHARS = 600;
|
|
|
16
16
|
const STOP = new Set(('the a an and or but to of in on for with is are was be it this that how do does i my me you your can why what when '
|
|
17
17
|
+ 'should would could not no if at as by from so get got use using run dibs it\'s don\'t doesn\'t there their they them about into just').split(' '));
|
|
18
18
|
|
|
19
|
-
const words = text => text.toLowerCase().match(/[a-z0-9][a-z0-9:_-]*/g)?.filter(w => (w.length > 2 || /^\d+$/.test(w)) && !STOP.has(w)) || [];
|
|
19
|
+
export const words = text => text.toLowerCase().match(/[a-z0-9][a-z0-9:_-]*/g)?.filter(w => (w.length > 2 || /^\d+$/.test(w)) && !STOP.has(w)) || [];
|
|
20
20
|
|
|
21
21
|
// A list or a table is one paragraph but many answers: shown whole and cut to its
|
|
22
22
|
// start, the item that matched was often past the cut. Each item and each table
|
package/src/board.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { resCfg } from './config.mjs';
|
|
4
4
|
import { tag, isMine } from './proc.mjs';
|
|
5
5
|
import { idleFor, UNPOLLED } from './acquire.mjs';
|
|
6
|
-
import { forecast, byRank, remaining, used, overBy, verdict, memUsed, cpuUsed, shownFree, swapGrowing, diskSqueeze, BREAKER_LINE, QUICK_LINE } from './schedule.mjs';
|
|
6
|
+
import { forecast, byRank, remaining, used, overBy, verdict, memUsed, cpuUsed, shownFree, swapGrowing, diskSqueeze, BREAKER_LINE, QUICK_LINE, EASED_LINE, fairShare } from './schedule.mjs';
|
|
7
7
|
import { grewLine, cappedLine } from './measure.mjs';
|
|
8
8
|
import { pauseLabel } from './preempt.mjs';
|
|
9
9
|
import { alongsideLabel } from './overlap.mjs';
|
|
@@ -13,7 +13,9 @@ import { agentsNow } from './agents.mjs';
|
|
|
13
13
|
import { remoteConf, call } from './remote.mjs';
|
|
14
14
|
import { bytes, dur, gb, clock, now, holder, when } from './util.mjs';
|
|
15
15
|
import { short, isFiles, sameAgent } from './files.mjs';
|
|
16
|
-
import { named, about, minutes, usingText, nextText, stuckFor, heldByLoad } from './plain.mjs';
|
|
16
|
+
import { named, about, minutes, usingText, nextText, stuckFor, heldByLoad, doneText, slowText } from './plain.mjs';
|
|
17
|
+
import { progressOf, slowness } from './jobprogress.mjs';
|
|
18
|
+
import { described } from './declare.mjs';
|
|
17
19
|
|
|
18
20
|
// Why a waiter isn't running, short enough for its board row: the rule and
|
|
19
21
|
// what it's stuck on (a file lease's path, a bucket's name). Disk says the
|
|
@@ -21,6 +23,7 @@ import { named, about, minutes, usingText, nextText, stuckFor, heldByLoad } from
|
|
|
21
23
|
// `dibs --json` carries it as is ("slot: xcode-build", "behind web-app").
|
|
22
24
|
export const waitReason = v => (v.ok ? null : v.rule === 'ahead' && v.ahead ? `behind ${tag(v.ahead)}`
|
|
23
25
|
: v.rule === 'load' && v.since != null ? heldByLoad(v)
|
|
26
|
+
: v.rule === 'halt' ? `held by ${v.by || 'the person'} ${v.until != null ? `until ${clock(v.until)}` : "until it's lifted"} (dibs halt)`
|
|
24
27
|
: v.rule === 'disk' ? v.why.replace('you need', 'needs')
|
|
25
28
|
: `${v.rule}${v.on ? `: ${short(v.on).replace(/^(files|quota):/, '')}` : ''}`);
|
|
26
29
|
const blockedBy = v => { const r = waitReason(v); return r && !/^(behind|held by) /.test(r) ? `blocked by ${r}` : r; };
|
|
@@ -53,14 +56,16 @@ export function boardOf(s, cfg, hist, t = now(), me = null) {
|
|
|
53
56
|
memUsed: memUsed(s), memBudget: bytes(cfg.budget), cpuUsed: cpuUsed(s), cores: cfg.cores,
|
|
54
57
|
held: [...s.leases].sort((a, b) => a.start - b.start).map(l => ({
|
|
55
58
|
res: l.res.map(r => short(r)), who: l.who, label: l.label, agentId: l.agentId, for: t - l.start, left: remaining(l, hist, t), idle: idleFor(l, t),
|
|
59
|
+
// How far the job says it is, and how it's off its pace, as words: other machines read them as they are.
|
|
60
|
+
done: progressOf(l, t) ? doneText(progressOf(l, t)) : null, slow: (sl => (sl ? slowText(sl) : null))(slowness(l, hist, t)),
|
|
56
61
|
stuck: s.queue.some(q => q.pid) && stuckFor(l, t) > 0,
|
|
57
|
-
prio: l.prio, paused: pauseLabel(l) || null, alongside: alongsideLabel(l) || (l.breaker ? BREAKER_LINE : l.quick ? QUICK_LINE : null), owner: ownerLabel(l) || null, purpose: l
|
|
62
|
+
prio: l.prio, paused: pauseLabel(l) || null, alongside: alongsideLabel(l) || (l.eased ? EASED_LINE : l.breaker ? BREAKER_LINE : l.quick ? QUICK_LINE : null), owner: ownerLabel(l) || null, purpose: described(l, cfg), cmd: l.cmd ? l.cmd.slice(0, 40) : null,
|
|
58
63
|
mem: l.mem, use: l.use?.mem ?? null, over: overBy(l) > 0, grew: grewLine(l) || null, ...you(l) })),
|
|
59
|
-
waiting: [...s.queue].sort(byRank(hist, t)).map(q => ({
|
|
64
|
+
waiting: [...s.queue].sort(byRank(hist, t, fairShare(s, cfg, t))).map(q => ({
|
|
60
65
|
res: q.res.map(r => short(r)), who: q.who, label: q.label, agentId: q.agentId, waited: t - q.enq, in: fc.has(q.id) ? fc.get(q.id) - t : null,
|
|
61
66
|
prio: q.prio, owner: ownerLabel(q) || null, due: q.by ? q.by - t : null, yielded: q.yieldRank != null, kept: !q.pid, holds: q.holding?.res.map(r => short(r)) || null,
|
|
62
67
|
blocked: q.pid ? waitingOn(s, q, cfg, hist, t) : null, capped: cappedLine(q) || null,
|
|
63
|
-
purpose: q
|
|
68
|
+
purpose: described(q, cfg), ...you(q) })),
|
|
64
69
|
free: Object.keys(cfg.resources).map(r => {
|
|
65
70
|
// A per-project resource is free for other projects up to its cap across them (src/schedule.mjs roomFor).
|
|
66
71
|
const c = resCfg(cfg, r), slots = c.exclusiveBy === 'repo' ? c.across ?? c.slots : c.slots;
|
|
@@ -80,7 +85,9 @@ export function limitsLine(s, cfg, m) {
|
|
|
80
85
|
const budget = bytes(cfg.budget), out = memUsed(s), free = shownFree(m);
|
|
81
86
|
const mem = `memory ${GB(out)} of ${GB(budget)} taken (${out >= budget ? 'none' : GB(budget - out)} left)${free != null ? `, ${GB(free)} free or reclaimable on the machine` : ''}${m.vmPressure >= 1 ? ', pressure high' : ''}`;
|
|
82
87
|
const floor = bytes(cfg.minDisk), sq = diskSqueeze(cfg, floor, m);
|
|
83
|
-
|
|
88
|
+
// The floor in force now, and the other one, so the number agents read is the one that holds them.
|
|
89
|
+
const room = cfg.swapRoom != null ? bytes(cfg.swapRoom) : 0;
|
|
90
|
+
const disk = m.diskFree == null ? 'disk unknown' : `disk ${GB(m.diskFree)} free (floor ${sq?.rule === 'swaproom' ? `${GB(sq.need)} while swapping, ${GB(floor)} otherwise` : `${GB(floor)}${room ? `, ${GB(floor + room)} while swapping` : ''}`}${sq?.rule === 'drain' ? `, falling ${GB(sq.fell)} in 5 min` : ''})`;
|
|
84
91
|
const over = cfg.maxSwap != null && m.swapUsed > bytes(cfg.maxSwap);
|
|
85
92
|
const swap = m.swapUsed == null ? '' : `swap ${GB(m.swapUsed)}${swapGrowing(m) ? `, growing (${GB(m.swapGrowth)} in 5 min)` : ', steady'}${over ? `, over maxSwap ${GB(bytes(cfg.maxSwap))}` : ''}`;
|
|
86
93
|
return [mem, disk, swap].filter(Boolean).join('; ');
|
|
@@ -95,23 +102,20 @@ export function boardLines(b, t = now(), age = 0, yours = x => x.you) {
|
|
|
95
102
|
if (b.held.length) {
|
|
96
103
|
out.push('', 'HELD');
|
|
97
104
|
for (const l of b.held)
|
|
98
|
-
out.push(` ${l.res.join(',').padEnd(14)} ${holder(l, tag).padEnd(28)} ${dur(l.for + age).padStart(7)}`
|
|
99
|
-
+ `${l.left != null ? ` ~${dur(l.left - age)} left` : ''}${l.prio && l.prio !== 'normal' ? ` [${l.prio}]` : ''}${l.owner ? ` [${l.owner}]` : ''}${l.idle ? ` [idle ${dur(l.idle + age)}${l.stuck ? ', may be stuck' : ''}]` : ''}${l.paused ? ` [${l.paused}]` : ''}${l.alongside ? ` [${l.alongside}]` : ''}`
|
|
105
|
+
out.push(` ${l.res.join(',').padEnd(14)} ${holder(l, tag).padEnd(28)} ${dur(l.for + age).padStart(7)}${l.purpose ? ` "${l.purpose}"` : ''}`
|
|
106
|
+
+ `${l.done ? ` ${l.done}` : ''}${l.left != null ? ` ~${dur(l.left - age)} left` : ''}${l.slow ? ` [${l.slow}]` : ''}${l.prio && l.prio !== 'normal' ? ` [${l.prio}]` : ''}${l.owner ? ` [${l.owner}]` : ''}${l.idle ? ` [idle ${dur(l.idle + age)}${l.stuck ? ', may be stuck' : ''}]` : ''}${l.paused ? ` [${l.paused}]` : ''}${l.alongside ? ` [${l.alongside}]` : ''}`
|
|
100
107
|
+ `${l.over ? ` [over: using ${gb(l.use)} of ${gb(l.mem)}]` : l.grew ? ` [${l.grew}]` : ''}`
|
|
101
|
-
+ `${l.
|
|
108
|
+
+ `${l.cmd ? ` ${l.cmd}` : ' (hold)'}${you(l)}`);
|
|
102
109
|
}
|
|
103
110
|
if (b.waiting.length) {
|
|
104
111
|
out.push('', "QUEUE (in the order they'll go)");
|
|
105
112
|
b.waiting.forEach((q, i) => {
|
|
106
113
|
const flags = [q.prio && q.prio !== 'normal' ? q.prio : '', q.owner || '', q.holds ? `holds ${q.holds.join(',')}, goes first` : '', q.blocked || '', q.capped || '', q.due != null ? `due ${clock(t - age + q.due)}` : '',
|
|
107
114
|
q.yielded ? 'let ahead' : '', q.kept ? 'place kept' : ''].filter(Boolean).join(', ');
|
|
108
|
-
out.push(` ${String(i + 1).padStart(2)} ${q.res.join(',').padEnd(11)} ${holder(q, tag).padEnd(28)} waited ${dur(q.waited + age).padStart(6)}`
|
|
109
|
-
+ `${q.in != null ? ` starts ~${clock(t - age + q.in)}` : ''}${flags ? ` [${flags}]` : ''}${
|
|
115
|
+
out.push(` ${String(i + 1).padStart(2)} ${q.res.join(',').padEnd(11)} ${holder(q, tag).padEnd(28)} waited ${dur(q.waited + age).padStart(6)}${q.purpose ? ` "${q.purpose}"` : ''}`
|
|
116
|
+
+ `${q.in != null ? ` starts ~${clock(t - age + q.in)}` : ''}${flags ? ` [${flags}]` : ''}${you(q)}`);
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
|
-
// An id typed from here can be someone else's: acting on it takes the owner by name (src/override.mjs).
|
|
113
|
-
if ([...b.held, ...b.waiting].some(x => x.id != null && !yours(x)))
|
|
114
|
-
out.push('', "Acting on a job that isn't yours (dibs boost, pause, resume, stop <id>): add --owner <the name before its #>.");
|
|
115
119
|
out.push('', `free: ${b.free.join(' ') || 'nothing'}`);
|
|
116
120
|
const caps = Object.entries(b.caps || {});
|
|
117
121
|
if (caps.length) out.push(`capped: ${caps.map(([who, c]) => `${who} at ${c.prio}${c.by ? ` (by ${c.by})` : ''}`).join(', ')}`);
|
|
@@ -145,7 +149,8 @@ function remoteSentences(b, cfg, age) {
|
|
|
145
149
|
// A hold's row has no command (null). A limited view blanks a run's command to '', so it still reads as a run.
|
|
146
150
|
const held = b.held.filter(l => l.res.includes(r)).map(l => {
|
|
147
151
|
const hold = l.cmd == null, left = l.left == null ? null : Math.max(l.left - age, 0);
|
|
148
|
-
|
|
152
|
+
const time = left == null ? (l.done ? '' : 'time left unknown') : hold ? `up to ${minutes(left)} left` : `${about(left)} left`;
|
|
153
|
+
return { who: l.who, hold, endsIn: left, endsText: [l.done, time].filter(Boolean).join(', ') };
|
|
149
154
|
});
|
|
150
155
|
const next = live.filter(q => q.res.includes(r)).map(q => q.who);
|
|
151
156
|
return `${named(cfg, r).label}: ${held.length ? usingText(held, named(cfg, r)) : 'free'}${next.length ? `. ${nextText(next)}` : ''}.`;
|
|
@@ -194,7 +199,7 @@ export function elsewhereLines(r, rc, me, t = now()) {
|
|
|
194
199
|
out.push('', 'SENT BETWEEN MACHINES');
|
|
195
200
|
for (const j of jobs)
|
|
196
201
|
out.push(` ${j.res.join(',').padEnd(14)} ${(j.agent || j.who).padEnd(20)} ${`${j.from} -> ${j.machine}`.padEnd(24)} ${j.state.padEnd(9)} ${dur(r.now - j.created).padStart(6)}`
|
|
197
|
-
+
|
|
202
|
+
+ ` "${described(j)}" ${j.cmd.join(' ').slice(0, 40)}`);
|
|
198
203
|
}
|
|
199
204
|
if (out.length) out.push('');
|
|
200
205
|
return out;
|
package/src/broker.mjs
CHANGED
|
@@ -16,8 +16,8 @@ import { pstart, makeAlive } from './proc.mjs';
|
|
|
16
16
|
import { processes } from './platform.mjs';
|
|
17
17
|
import { withState, history, kick, quiet, KEEP_PLACE } from './state.mjs';
|
|
18
18
|
import { sweepLock } from './lock.mjs';
|
|
19
|
-
import { decide, step, waiter, full, markIdle, saidText, abandon, POLL } from './acquire.mjs';
|
|
20
|
-
import { byRank } from './schedule.mjs';
|
|
19
|
+
import { decide, step, waiter, full, markIdle, saidText, abandon, leftText, POLL } from './acquire.mjs';
|
|
20
|
+
import { byRank, fairShare } from './schedule.mjs';
|
|
21
21
|
import { inversions, lift } from './override.mjs';
|
|
22
22
|
import { noticeScan } from './notices.mjs';
|
|
23
23
|
import { event } from './events.mjs';
|
|
@@ -111,7 +111,10 @@ function inlineCall(shell, fifo) {
|
|
|
111
111
|
wait: w => {
|
|
112
112
|
if (!process.execve) return 'stay';
|
|
113
113
|
withState(s => { const q = s.queue.find(x => x.id === w.me.id && x.pid === shell); if (q) keepFor(q, shell); });
|
|
114
|
-
|
|
114
|
+
// What this wait has said and when it began go with it: the Node that gets in line again
|
|
115
|
+
// said the whole picture a second time, and logged a second wait (2026-11-28, #26960).
|
|
116
|
+
const carry = JSON.stringify({ started: w.started, talk: w.talk.save(), blocked: w.blocked, saidAhead: w.saidAhead, warnedHolding: w.warnedHolding });
|
|
117
|
+
process.execve('/bin/sh', ['/bin/sh', THIN_SH, BIN, ...process.argv.slice(2)], { ...process.env, DIBS_THIN_RESUME: '1', DIBS_THIN_WAIT: carry });
|
|
115
118
|
},
|
|
116
119
|
};
|
|
117
120
|
}
|
|
@@ -145,7 +148,11 @@ export function ensureBroker() {
|
|
|
145
148
|
fs.closeSync(log);
|
|
146
149
|
}
|
|
147
150
|
// This loop never yields, so a child that died is a zombie, not an exit event.
|
|
148
|
-
|
|
151
|
+
// Where ps can't run (Codex's sandbox, 2026-11-26) there's no telling: it's waited out as a slow start.
|
|
152
|
+
const died = () => {
|
|
153
|
+
const r = spawnSync('ps', ['-o', 'stat=', '-p', String(child.pid)], { encoding: 'utf8' });
|
|
154
|
+
return r.stdout != null && !/^[^Z]/.test(r.stdout.trim());
|
|
155
|
+
};
|
|
149
156
|
for (let t0 = now(), checked = t0; now() - t0 < START_WAIT; sleepSync(20)) {
|
|
150
157
|
if (kick()) { try { fs.rmSync(BROKEN, { force: true }); } catch {} return true; }
|
|
151
158
|
if (child && now() - checked > CRASH_CHECK) {
|
|
@@ -188,6 +195,7 @@ function keepFor(q, shell) {
|
|
|
188
195
|
// up on the broker (why is keep: the place stays for its in-process retry).
|
|
189
196
|
// id 0: interrupted before it knew its id; its place is the one under its pid.
|
|
190
197
|
export function leaveLine(id, shell, why) {
|
|
198
|
+
let text = '';
|
|
191
199
|
// A low job lifted for this waiter alone goes back down as it leaves (src/override.mjs inversions).
|
|
192
200
|
lift(withState(s => {
|
|
193
201
|
// Its place by id when it knows it, else by its pid. A place kept with nobody on it (for its own
|
|
@@ -196,11 +204,17 @@ export function leaveLine(id, shell, why) {
|
|
|
196
204
|
|| (why !== 'keep' && x.keptFor === shell));
|
|
197
205
|
if (!q) return [];
|
|
198
206
|
if (why === 'keep') { keepFor(q, shell); return []; }
|
|
199
|
-
s
|
|
207
|
+
// A signal: this shell's stderr is the caller's, so it hears why its command never ran,
|
|
208
|
+
// and the place stays KEEP_PLACE for the same command (src/acquire.mjs leftText).
|
|
209
|
+
text = leftText(s, q, why, { again: q.wake?.again, started: q.wake?.started, ppid: q.wake?.ppid ?? q.ppid }, history());
|
|
200
210
|
if (q.wake?.notify) notified(q, signalExit(why));
|
|
201
211
|
if (q.wake) event({ kind: 'left', id: q.id, res: q.res, who: q.who, prio: q.prio || 'normal', type: q.kind, ms: now() - q.enq, why });
|
|
212
|
+
Object.assign(q, { pid: null, keepUntil: now() + KEEP_PLACE });
|
|
213
|
+
delete q.wake;
|
|
214
|
+
delete q.keptFor;
|
|
202
215
|
return inversions(s, loadConfig());
|
|
203
216
|
}));
|
|
217
|
+
if (text) process.stderr.write(text);
|
|
204
218
|
}
|
|
205
219
|
|
|
206
220
|
// --notify's line for a thin wait that ended before its command started (src/commands.mjs notifyOnExit).
|
|
@@ -249,6 +263,9 @@ const thinWaiters = s => s.queue.filter(q => q.wake && q.pid && q.wake.pid === q
|
|
|
249
263
|
export function broker() {
|
|
250
264
|
fs.mkdirSync(WAKE, { recursive: true });
|
|
251
265
|
const me = { pid: process.pid, pstart: pstart(process.pid) };
|
|
266
|
+
// The code it runs, read before it says it's the broker: read after, a release that landed in
|
|
267
|
+
// between went unnoticed and this broker never handed its waiters on (a flaky test, 2026-12-06).
|
|
268
|
+
const code = fs.readFileSync(path.join(SRC, 'version.mjs'), 'utf8');
|
|
252
269
|
const mine = withState(s => {
|
|
253
270
|
const b = s.broker;
|
|
254
271
|
if (b && b.pid !== me.pid && now() - b.beat < HUNG && makeAlive([b.pid])(b.pid, b.pstart)) return false;
|
|
@@ -262,7 +279,6 @@ export function broker() {
|
|
|
262
279
|
try { fs.unlinkSync(paths.ctl); } catch {}
|
|
263
280
|
if (spawnSync('mkfifo', ['-m', '600', paths.ctl], { stdio: 'ignore' }).status !== 0) throw new Error(`couldn't make the control FIFO ${paths.ctl}`);
|
|
264
281
|
const ctl = new net.Socket({ fd: fs.openSync(paths.ctl, O_RDWR | O_NONBLOCK), readable: true, writable: false });
|
|
265
|
-
const code = fs.readFileSync(path.join(SRC, 'version.mjs'), 'utf8');
|
|
266
282
|
const waits = new Map(); // queue id -> its wait (src/acquire.mjs waiter), with its FIFO as out
|
|
267
283
|
let cfg = loadConfig(), hist = history(), histAt = 0, beat = 0, idleSince = now(), pending = false, forced = false, pruned = 0, seen = '', fullAt = 0;
|
|
268
284
|
|
|
@@ -316,7 +332,7 @@ export function broker() {
|
|
|
316
332
|
if (s.broker && s.broker.pid !== me.pid) return null; // taken for hung and replaced: step aside
|
|
317
333
|
if (t - beat > BEAT || !s.broker) s.broker = { ...me, beat: (beat = t) };
|
|
318
334
|
markIdle(s);
|
|
319
|
-
const thin = thinWaiters(s).sort(byRank(hist));
|
|
335
|
+
const thin = thinWaiters(s).sort(byRank(hist, undefined, fairShare(s, cfg)));
|
|
320
336
|
for (const [id, w] of waits) if (!thin.some(q => q.id === id)) { w.out.close(); waits.delete(id); }
|
|
321
337
|
return thin.map(q => {
|
|
322
338
|
let w = waits.get(q.id);
|