@dibssoftware/dibs 0.0.179 → 0.0.180
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 +23 -2
- package/README.md +4 -2
- package/bin/dibs-guard.mjs +10 -1
- package/bin/dibs.mjs +28 -9
- package/docs/benchmarks.md +1 -1
- package/docs/files.md +1 -1
- package/docs/guard.md +6 -0
- package/docs/questions.md +6 -2
- package/docs/reference.md +4 -4
- package/docs/relay.md +9 -7
- package/docs/releasing.md +4 -3
- package/docs/scheduling.md +4 -4
- package/docs/windows.md +14 -0
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +5 -5
- package/src/acquire.mjs +91 -26
- package/src/agents.mjs +7 -22
- package/src/alerts.mjs +59 -21
- package/src/board.mjs +1 -2
- package/src/broker.mjs +26 -11
- package/src/commands.mjs +25 -9
- package/src/config.mjs +21 -4
- package/src/cool.mjs +104 -9
- package/src/diskwarn.mjs +4 -0
- package/src/events.mjs +10 -1
- package/src/files.mjs +49 -87
- package/src/guard.mjs +24 -8
- package/src/guardd.mjs +97 -0
- package/src/guardw.mjs +19 -0
- package/src/later.mjs +20 -25
- package/src/lock.mjs +292 -0
- package/src/measure.mjs +9 -4
- package/src/ondemand.mjs +5 -2
- package/src/override.mjs +39 -2
- package/src/plain.mjs +2 -2
- package/src/platform.mjs +165 -35
- package/src/preempt.mjs +51 -3
- package/src/primer.mjs +1 -1
- package/src/proc.mjs +35 -5
- package/src/questions.mjs +8 -22
- package/src/relay.mjs +10 -22
- package/src/remote.mjs +12 -8
- package/src/schedule.mjs +139 -26
- package/src/serve.mjs +16 -3
- package/src/service.mjs +4 -3
- package/src/state.mjs +139 -47
- package/src/stats.mjs +3 -2
- package/src/talk.mjs +160 -77
- package/src/trust.mjs +7 -1
- package/src/util.mjs +28 -2
- package/src/version.mjs +1 -1
- package/src/web.mjs +15 -25
- package/src/worker.mjs +2 -1
package/src/remote.mjs
CHANGED
|
@@ -125,10 +125,16 @@ export function tarExtract(dir, buf, only = null) {
|
|
|
125
125
|
return members;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
// A path with its links resolved, the same way every time it's compared. On
|
|
129
|
+
// Windows only the native call also expands 8.3 names (C:\Users\RUNNER~1): the JS
|
|
130
|
+
// one left a temp folder short and the home folder long, so the job's folder came
|
|
131
|
+
// out as ../../RUNNER~1/... relative to its own project.
|
|
132
|
+
const real = p => { try { return (OS === 'windows' ? fs.realpathSync.native : fs.realpathSync)(p); } catch { return p; } };
|
|
133
|
+
|
|
128
134
|
// The folder a working copy comes from: the git repo around cwd, or cwd itself.
|
|
129
135
|
function projectRoot(cwd = process.cwd()) {
|
|
130
|
-
try { return
|
|
131
|
-
catch { return cwd; }
|
|
136
|
+
try { return real(execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()); }
|
|
137
|
+
catch { return real(cwd); }
|
|
132
138
|
}
|
|
133
139
|
// A load-held job may go to an on-demand machine on its own (acquire.mjs step)
|
|
134
140
|
// only when it can run there. Never one that needs macOS: a resource that
|
|
@@ -167,14 +173,13 @@ export function mayShip(me, cfg, cwd) {
|
|
|
167
173
|
if (macOnly(me.cmd, cwd) || !remoteConf(() => null) || namesPaths(me.cmd)) return false;
|
|
168
174
|
const root = gitRoot(cwd);
|
|
169
175
|
if (!root) return false;
|
|
170
|
-
|
|
171
|
-
try { home = fs.realpathSync(home); } catch {}
|
|
176
|
+
const home = real(os.homedir());
|
|
172
177
|
return !(root === path.parse(root).root || home === root || home.startsWith(root.endsWith(path.sep) ? root : root + path.sep));
|
|
173
178
|
}
|
|
174
179
|
// Only a git working copy ships on its own: that's what the copy is, and a
|
|
175
180
|
// folder outside git may hold anything.
|
|
176
181
|
function gitRoot(cwd) {
|
|
177
|
-
try { return
|
|
182
|
+
try { return real(execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()); }
|
|
178
183
|
catch { return null; }
|
|
179
184
|
}
|
|
180
185
|
// A command that names a path of this machine (/Users/..., ~/...) means a file the
|
|
@@ -258,7 +263,7 @@ function workingCopy(root, cwd = process.cwd()) {
|
|
|
258
263
|
if (st.isDirectory()) continue; // a submodule
|
|
259
264
|
(SECRET.test(f) ? secret : kept).push(f);
|
|
260
265
|
}
|
|
261
|
-
const cwdRel = path.relative(root,
|
|
266
|
+
const cwdRel = path.relative(root, real(cwd)).split(path.sep).join('/');
|
|
262
267
|
return { files: kept.sort(), secret, cwdRel };
|
|
263
268
|
}
|
|
264
269
|
|
|
@@ -292,8 +297,7 @@ export async function remoteRun(o, cfg) {
|
|
|
292
297
|
if (o.on && !ruleAllows(rule, o.on, rc.name)) return refuse(o.on, rule);
|
|
293
298
|
const root = projectRoot();
|
|
294
299
|
// Your home folder, or a folder above it, holds far more than a project, keys included.
|
|
295
|
-
|
|
296
|
-
try { home = fs.realpathSync(home); } catch {}
|
|
300
|
+
const home = real(os.homedir());
|
|
297
301
|
if (root === path.parse(root).root || home === root || home.startsWith(root.endsWith(path.sep) ? root : root + path.sep)) {
|
|
298
302
|
const msg = `${root} is your home folder or above it, and dibs won't send all of that to another machine. Run from the project's folder`;
|
|
299
303
|
if (o.on && o.on !== rc.name) die(msg);
|
package/src/schedule.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Who goes next. Pure functions of the state, config, history and clock, so
|
|
2
2
|
// they can be tested without processes.
|
|
3
3
|
import { resCfg, machine, hardware, RECENT, SWAP_WINDOW } from './config.mjs';
|
|
4
|
-
import { bytes, ms, dur, gb, now, runsOf, indexed } from './util.mjs';
|
|
4
|
+
import { bytes, ms, dur, gb, now, runsOf, indexed, unpolled } from './util.mjs';
|
|
5
5
|
import { tag, isMine } from './proc.mjs';
|
|
6
6
|
import { isFiles, overlap, short, clash, coversAgent, elsewhere } from './files.mjs';
|
|
7
7
|
import { poolBlock } from './simpool.mjs';
|
|
@@ -210,10 +210,17 @@ export const sum = (xs, f) => xs.reduce((a, x) => a + f(x), 0);
|
|
|
210
210
|
// never queue behind yourself. Two subagents of one session are different
|
|
211
211
|
// agents when the guard told dibs which is which (src/files.mjs).
|
|
212
212
|
const covers = (h, x) => (h.kind === 'hold' && !!x.spid && h.pid === x.spid && coversAgent(h, x)) || (!!x.outer && h.id === x.outer);
|
|
213
|
-
|
|
213
|
+
// A hold or outer run is one slot, so it covers one run on each of its resources at a time; a
|
|
214
|
+
// second run alongside the first needs a slot of its own. On 2026-11-10 at 23:44 a session's hold
|
|
215
|
+
// on playwright covered four of its subagents' runs at once, each 5 to 7.5 GB, past slots: 2 and
|
|
216
|
+
// past the memory budget (a covered run is charged nothing): swap reached 13.7 GB and the Mac froze.
|
|
217
|
+
const inside = (s, h, r, not) => s.leases.filter(o => o !== h && o.id !== not && o.covered?.includes(r) && covers(h, o));
|
|
218
|
+
export const holdsOf = (s, me) => new Set(s.leases.filter(l => covers(l, me)).flatMap(l => l.res.filter(r => !inside(s, l, r, me.id).length)));
|
|
214
219
|
// Slots of r in use. A run covered by its own hold or outer run doesn't count
|
|
215
|
-
// twice, but only while that lasts: once it ends, the run is a user again.
|
|
216
|
-
|
|
220
|
+
// twice, but only while that lasts: once it ends, the run is a user again. Of several runs that
|
|
221
|
+
// say they're covered by one hold (a state written before the rule above), only the first is.
|
|
222
|
+
export const coveredNow = (s, l, r) => l.covered?.includes(r)
|
|
223
|
+
&& s.leases.some(h => h !== l && h.res.includes(r) && covers(h, l) && !inside(s, h, r, l.id).some(o => o.id < l.id));
|
|
217
224
|
|
|
218
225
|
// What a waiter already holds while it waits, or null: the dibs run it's
|
|
219
226
|
// nested in, unless that runs at low or idle priority, and its session's holds
|
|
@@ -368,12 +375,36 @@ const usedNow = l => (l.kind === 'run' && l.use?.mem != null ? l.use.mem : plann
|
|
|
368
375
|
export const memOf = (l, t = now()) => {
|
|
369
376
|
const planned = plannedOf(l);
|
|
370
377
|
if (l.kind !== 'run' || l.use?.mem == null) return planned;
|
|
378
|
+
// Stopped, it keeps every byte it had (they go to swap, not back to the machine), and it isn't
|
|
379
|
+
// measured while paused: never the idle discount, always the most it was seen using.
|
|
380
|
+
if (l.pausedAt) return Math.max(planned, l.peak?.mem || 0);
|
|
371
381
|
if (steady(l, t)) return l.idleSince && t - l.idleSince >= IDLE_BOOK ? l.use.mem : l.use.mem + BUSY_MARGIN;
|
|
372
382
|
if (t - l.start - pausedFor(l, t) < BOOK_AFTER) return planned;
|
|
373
383
|
const peak = Math.max(l.peak?.mem || 0, l.use.mem);
|
|
374
384
|
return Math.min(peak + BUSY_MARGIN, Math.max(planned, peak));
|
|
375
385
|
};
|
|
376
386
|
|
|
387
|
+
// How far into a run this command reaches its peak, the latest of its last
|
|
388
|
+
// PEAK_RUNS measured runs, or null when one of them didn't say (recorded before
|
|
389
|
+
// 0.0.180) or none was measured.
|
|
390
|
+
const PEAK_RUNS = 5;
|
|
391
|
+
function peaksBy(hist, key) {
|
|
392
|
+
const runs = runsOf(hist || [], key).filter(h => h.mem > 0).slice(-PEAK_RUNS);
|
|
393
|
+
return runs.length && runs.every(h => h.peakIn != null) ? Math.max(...runs.map(h => h.peakIn)) : null;
|
|
394
|
+
}
|
|
395
|
+
// A measured run that has gone well past where its command's runs peak is done
|
|
396
|
+
// growing into its ask: it books what memOf says, not the ask. On 2026-11-03 an
|
|
397
|
+
// Xcode job booked at 11G, measured at 0.1 GB, held a 6G deploy on "the machine
|
|
398
|
+
// doesn't have the room" for as long as it ran. A command that peaks late (a
|
|
399
|
+
// link, an archive) keeps its ask until then, so its ramp has the room.
|
|
400
|
+
const PEAK_SLACK = 2 * MIN;
|
|
401
|
+
const pastPeak = (l, hist, t) => {
|
|
402
|
+
if (l.kind !== 'run' || l.use?.mem == null || !l.key || !hist) return false;
|
|
403
|
+
const p = peaksBy(hist, l.key);
|
|
404
|
+
return p != null && t - l.start - pausedFor(l, t) > p * 1.25 + PEAK_SLACK;
|
|
405
|
+
};
|
|
406
|
+
export const growTo = (hist, t = now()) => l => (pastPeak(l, hist, t) ? memOf(l, t) : plannedOf(l));
|
|
407
|
+
|
|
377
408
|
// The lease a run sits inside, when its own hold or outer dibs run covers all
|
|
378
409
|
// it asked for, or null.
|
|
379
410
|
const coverOf = (s, l) => (l.covered && l.res.every(r => coveredNow(s, l, r)) ? s.leases.find(h => h !== l && covers(h, l)) || null : null);
|
|
@@ -397,7 +428,10 @@ export function memUsed(s, of = memOf) {
|
|
|
397
428
|
// The leases taking the most memory, biggest first, for a memory wait to name.
|
|
398
429
|
// asked: what it asked for (--mem or its resource's default); use: what its
|
|
399
430
|
// last measurement found, or null before the first.
|
|
400
|
-
|
|
431
|
+
// Ranked by what each one was measured using, where there's a measurement: on 2026-11-03 an
|
|
432
|
+
// 11 GB booking using 0.1 GB took the blame for a pressure wait it wasn't causing.
|
|
433
|
+
const blame = l => l.use?.mem ?? memOf(l);
|
|
434
|
+
export const memHolders = (s, n = 3) => s.leases.filter(l => memOf(l) > 0 && !coverOf(s, l)).sort((a, b) => blame(b) - blame(a)).slice(0, n)
|
|
401
435
|
.map(l => ({ id: l.id, who: l.agent || l.who, label: l.label, purpose: l.purpose || '', mem: memOf(l), asked: l.asked ?? l.mem ?? 0, use: l.use?.mem ?? null, idleSince: l.idleSince || null }));
|
|
402
436
|
|
|
403
437
|
// Memory the OS says is free right now, in bytes, or null.
|
|
@@ -478,7 +512,8 @@ export const cpuUsed = s => Math.round(sum(s.leases.filter(l => !lent(l) && !l.p
|
|
|
478
512
|
const YOUNG = 3 * MIN, REAL_WAIT = 2 * MIN;
|
|
479
513
|
export const swapTaken = m => (swapGrowing(m) ? m.swapGrowth : 0);
|
|
480
514
|
// noSwap: swap growth doesn't count (the stall breaker let it by).
|
|
481
|
-
|
|
515
|
+
// hist: what the running jobs' own runs say about when they peak (growTo); without it, asks stand.
|
|
516
|
+
function overBudget(s, q, cfg, strict = false, noSwap = false, t = now(), hist = null) {
|
|
482
517
|
// A job as big as the whole budget runs when nothing else is.
|
|
483
518
|
if (!othersOf(s, q).length) return null;
|
|
484
519
|
const m = machine();
|
|
@@ -493,7 +528,9 @@ function overBudget(s, q, cfg, strict = false, noSwap = false, t = now()) {
|
|
|
493
528
|
// growing, the job plus a reserve free): it starts. Booking keeps a job's peak
|
|
494
529
|
// for minutes after it falls; on 2026-10-20 twenty jobs waited "blocked by
|
|
495
530
|
// memory" with 8.6 GB free and 1 of 10 cores busy.
|
|
496
|
-
|
|
531
|
+
// A light job can't make the paging worse, so only critical pressure takes the room away from it (as for the swap gate).
|
|
532
|
+
const room = () => ((q.mem || 0) <= LIGHT_MEM && !(m.vmPressure >= 2)) || realRoom(q, cfg, m);
|
|
533
|
+
const fitsUse = () => memUsed(s, usedNow) + swap + q.mem <= budget && room();
|
|
497
534
|
if (mem + q.mem > budget && !fitsUse())
|
|
498
535
|
return { rule: 'memory', used: mem, of: budget, need: q.mem, ...(swap && { swap }),
|
|
499
536
|
why: `memory budget: ${gb(mem)} of ${gb(budget)} handed out or in use${swap ? ` (${gb(swap)} of it swap that grew in the last 5 min)` : ''}, you need ${gb(q.mem)}` };
|
|
@@ -501,7 +538,8 @@ function overBudget(s, q, cfg, strict = false, noSwap = false, t = now()) {
|
|
|
501
538
|
// what they asked for. One of them may still grow into its ask, so the room
|
|
502
539
|
// must be real: memory pressure normal, swap still, and the job plus a
|
|
503
540
|
// reserve free on the machine.
|
|
504
|
-
|
|
541
|
+
// A running job past where its command's runs peak counts at what it books (growTo), not its ask.
|
|
542
|
+
if (memUsed(s, growTo(hist, t)) + swap + q.mem > budget && !room())
|
|
505
543
|
return { rule: 'memory', used: mem, of: budget, need: q.mem, pressure: true, free: realFree(m), reserve: ROOM_RESERVE, high: m.vmPressure >= 1, growing: swapGrowing(m),
|
|
506
544
|
why: `memory: running jobs ask for more than they use, but the machine doesn't have the room to show for it (${realFree(m) == null ? 'free memory unknown' : `${gb(realFree(m))} free`}${m.vmPressure >= 1 ? ', memory pressure high' : ''}${swapGrowing(m) ? ', swap growing' : ''}), you need ${gb(q.mem)} plus ${gb(ROOM_RESERVE)} to spare` };
|
|
507
545
|
// Within the budget, the machine must still have it: what's really available
|
|
@@ -597,7 +635,7 @@ function soonestStart(s, q, cfg, hist, t = now()) {
|
|
|
597
635
|
at = Math.max(at, Math.min(...s.leases.filter(l => l.res.includes(r) && !lent(l, r) && !onTop(l, r) && (across || !byRepo(cfg, r) || laneOf(l) === laneOf(q))).map(l => slotEnd(s, l, hist, t, r))));
|
|
598
636
|
}
|
|
599
637
|
}
|
|
600
|
-
if (overBudget(s, q, cfg)) at = Math.max(at, budgetFrees(s, q, cfg, hist, t));
|
|
638
|
+
if (overBudget(s, q, cfg, false, false, t, hist)) at = Math.max(at, budgetFrees(s, q, cfg, hist, t));
|
|
601
639
|
return at;
|
|
602
640
|
}
|
|
603
641
|
// Whether q's turn at the budget rests only on jobs whose run time dibs knows
|
|
@@ -730,6 +768,14 @@ const INSTANT = 15e3;
|
|
|
730
768
|
// (2 GB for a test run) doesn't book it past the budget. Critical pressure and
|
|
731
769
|
// the disk floor still do. On 2026-10-23 a 70 ms node --test of one file waited
|
|
732
770
|
// minutes on "memory pressure high" behind a 4 GB Docker build.
|
|
771
|
+
// Light by its own runs: the last ten measured at LIGHT_MEM or less, at least LIGHT_RUNS of them,
|
|
772
|
+
// whatever it asked for. On 2026-11-03 a deploy that asked for 6 GB and used under 0.5 GB waited on
|
|
773
|
+
// memory pressure that an 11 GB Xcode booking using 0.1 GB was blamed for.
|
|
774
|
+
const LIGHT_RUNS = 3;
|
|
775
|
+
export function measuredLight(me, hist) {
|
|
776
|
+
const runs = runsOf(hist, me.key).slice(-10).filter(h => h.mem != null);
|
|
777
|
+
return runs.length >= LIGHT_RUNS && runs.every(h => h.mem <= LIGHT_MEM);
|
|
778
|
+
}
|
|
733
779
|
export function featherweight(me, hist) {
|
|
734
780
|
const d = typical(hist, me.key) ?? (me.declared ? null : me.est);
|
|
735
781
|
if (d == null || d >= INSTANT) return false;
|
|
@@ -799,7 +845,9 @@ function ownDisk(hist, key) {
|
|
|
799
845
|
// A --disk given in so many words is the job's own: on 2026-10-26 a streaming loader that writes one
|
|
800
846
|
// 12 MB chunk was held for 23 GB it had "eaten" on a run whose swap grew while it sat paused.
|
|
801
847
|
export function diskNeed(s, me, cfg, hist) {
|
|
802
|
-
const floor =
|
|
848
|
+
const floor = floorFor(me, cfg);
|
|
849
|
+
// A job that writes next to nothing keeps only ALONE_ROOM free, under the floor (tinyDisk).
|
|
850
|
+
if (tinyDisk(me, hist, cfg)) return { need: (me.diskDeclared ? me.disk || 0 : 0) + ALONE_ROOM, ate: null, others: othersOf(s, me).length > 0, tiny: true };
|
|
803
851
|
// With others running, a resource that declares disk (simulators, builds, browsers, heavy) also
|
|
804
852
|
// counts what its kind of job usually eats. Alone, or on a resource that declares none, the
|
|
805
853
|
// job's own runs still count: starting a job that always eats more than there is only fails it.
|
|
@@ -815,7 +863,60 @@ export function diskNeed(s, me, cfg, hist) {
|
|
|
815
863
|
return { need: Math.max(learned ?? me.disk ?? 0, floor, ate != null ? ate + (others ? floor : ALONE_ROOM) : 0), ate, others };
|
|
816
864
|
}
|
|
817
865
|
// A job alone still leaves this much free past what it eats: the system writes while it runs too.
|
|
818
|
-
const ALONE_ROOM = 1024 ** 3;
|
|
866
|
+
export const ALONE_ROOM = 1024 ** 3;
|
|
867
|
+
|
|
868
|
+
// A job the person is waiting on (high, urgent, or a --by deadline with its reason) may take the headroom
|
|
869
|
+
// down to this, the same hard floor the watcher pauses jobs at (src/preempt.mjs DISK_FLOOR),
|
|
870
|
+
// and isn't held for the room kept for swap. On 2026-11-02 and 03 a Shop ship
|
|
871
|
+
// (#18328) waited about a day while idle sessions' swap kept free disk under 9 GB.
|
|
872
|
+
const HARD_FLOOR = 3 * 1024 ** 3;
|
|
873
|
+
// A --by deadline counts only with its reason (-m): a bare one costs nothing to type.
|
|
874
|
+
export const waitedOn = q => q.prio === 'high' || q.prio === 'urgent' || (q.by != null && !!q.purpose);
|
|
875
|
+
const floorFor = (q, cfg) => (waitedOn(q) ? Math.min(bytes(cfg.minDisk), HARD_FLOOR) : bytes(cfg.minDisk));
|
|
876
|
+
|
|
877
|
+
// A job that eats less than this of the disk starts under minDisk: holding it back
|
|
878
|
+
// frees nothing. On 2026-11-02 and 03 a post-deploy check that only makes HTTP calls,
|
|
879
|
+
// a test suite that writes nothing (--disk 200M) and a later job that uploads a 100 MB
|
|
880
|
+
// archive were all refused (exit 74) with 4.4 to 5 GB free, and a prod build went out unchecked.
|
|
881
|
+
export const TINY_DISK = 100 * 1024 ** 2;
|
|
882
|
+
// Whether a job is that small. Its own runs say first: at least TINY_RUNS good ones, the
|
|
883
|
+
// middle of the last ten (the most of them until there are DISK_RUNS) under TINY_DISK, and
|
|
884
|
+
// the last run, failed or not, under it too: one that ate more takes the exemption away
|
|
885
|
+
// until it's back down. A failed run alone, stopped early, says nothing about what a whole
|
|
886
|
+
// one eats. With too few runs, only a small --disk does (diskNeed takes it at its word).
|
|
887
|
+
export function tinyDisk(me, hist, cfg) {
|
|
888
|
+
// A --disk of minDisk or more says it isn't small, whatever its resource.
|
|
889
|
+
if (me.diskDeclared && (me.disk || 0) >= bytes(cfg.minDisk)) return false;
|
|
890
|
+
// A run the watcher cleared caches under reads low: the clean's room hid what it wrote (src/diskwarn.mjs clean).
|
|
891
|
+
const runs = runsOf(hist || [], me.key).filter(h => h.ate != null && !h.cleaned).slice(-10);
|
|
892
|
+
if (runs.length && runs.at(-1).ate >= TINY_DISK) return false;
|
|
893
|
+
const good = runs.filter(h => !h.failed).map(h => h.ate);
|
|
894
|
+
if (good.length >= TINY_RUNS) return (good.length < DISK_RUNS ? Math.max(...good) : mid(good)) < TINY_DISK;
|
|
895
|
+
// Too few runs to go by: only its own word makes it small. A first npm ci or a bundling deploy
|
|
896
|
+
// writes gigabytes, so a resource's kind alone never does. Up to CLAIM_MAX on a resource that
|
|
897
|
+
// declares no disk (tests, deploys, locks), or under TINY_DISK anywhere.
|
|
898
|
+
if (!me.diskDeclared) return false;
|
|
899
|
+
const claim = me.disk || 0;
|
|
900
|
+
return claim < TINY_DISK || (claim <= CLAIM_MAX && me.res.every(r => isFiles(r) || !resCfg(cfg, r).disk));
|
|
901
|
+
}
|
|
902
|
+
// Why a job held at the floor is held there, and, when its --disk is smaller, why that didn't
|
|
903
|
+
// lower it: agents read --disk 1G as the floor's size, and a deploy hit exit 74 twice at 2.6 GB
|
|
904
|
+
// free on 2026-11-10 with --disk 1G.
|
|
905
|
+
const GBs = b => gb(b).replace(/G$/, ' GB');
|
|
906
|
+
export function floorWhy(me, cfg) {
|
|
907
|
+
const floor = floorFor(me, cfg);
|
|
908
|
+
const base = `the ${GBs(floor)} dibs keeps free${waitedOn(me) && floor < bytes(cfg.minDisk) ? ' for a job a person waits on' : ''}`;
|
|
909
|
+
if (!me.diskDeclared || (me.disk || 0) >= floor) return base;
|
|
910
|
+
const little = me.res.every(r => isFiles(r) || !resCfg(cfg, r).disk);
|
|
911
|
+
return `${base}; --disk ${GBs(me.disk || 0)} doesn't lower that: only a --disk ${little ? 'of 1 GB or less' : 'under 100 MB'}`
|
|
912
|
+
+ ` starts a job below it, or two runs of the same command that each wrote under 100 MB`;
|
|
913
|
+
}
|
|
914
|
+
// Runs it takes to be small by history alone: one could be a run that happened to write little.
|
|
915
|
+
const TINY_RUNS = 2;
|
|
916
|
+
// The most a --disk alone can claim on a resource that declares no disk, itself included: agents
|
|
917
|
+
// write --disk 1G, and a deploy that said so waited out 2.6 GB free twice on 2026-11-10. On
|
|
918
|
+
// 2026-11-03 a test suite that writes nothing said --disk 200M and was refused at 4.4 GB free.
|
|
919
|
+
const CLAIM_MAX = 1024 ** 3;
|
|
819
920
|
|
|
820
921
|
// The verdict, and for a job held by something else (its turn, memory, cores) a
|
|
821
922
|
// word that free disk will hold it next, while there's still time to free some.
|
|
@@ -835,7 +936,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
835
936
|
const quick = !!(me.quickPass ?? quickPass(me, hist, cfg)) && s.leases.filter(l => l.quick).length < QUICK_MAX;
|
|
836
937
|
// A quick job dibs hasn't seen use much memory is booked small, as a featherweight is.
|
|
837
938
|
const lightQuick = quick && !me.declared && runsOf(hist, me.key).slice(-10).every(h => h.mem == null || h.mem <= LIGHT_MEM);
|
|
838
|
-
if ((me.mem || 0) > LIGHT_MEM && (featherweight(me, hist) || lightQuick)) me = { ...me, mem: LIGHT_MEM, feather: true };
|
|
939
|
+
if ((me.mem || 0) > LIGHT_MEM && (featherweight(me, hist) || lightQuick || measuredLight(me, hist))) me = { ...me, mem: LIGHT_MEM, feather: true };
|
|
839
940
|
const myRank = rank(me, hist, t);
|
|
840
941
|
// When it would be done, at its slow runs: passing a waiter is a promise not to delay it.
|
|
841
942
|
const myEnd = t + Math.max(expected(me, hist), slow(hist, me.key) || 0);
|
|
@@ -851,8 +952,11 @@ function decide(s, me, cfg, hist, t) {
|
|
|
851
952
|
const lightTurn = (me.mem || 0) <= LIGHT_MEM && me.res.every(r => cfg.resources[r]?.exclusive);
|
|
852
953
|
const pastCeiling = pastsCeiling(me) || quick || lightTurn;
|
|
853
954
|
// Over the ceiling, a waiter that passes it doesn't wait behind ones the ceiling holds back.
|
|
955
|
+
// Nor behind a place nobody is deciding for (its dibs stopped looking), or one the owner stopped:
|
|
956
|
+
// neither can start, so neither holds anyone back. Just after the machine wakes (graceUntil,
|
|
957
|
+
// src/state.mjs) every place is old, so none is taken for one nobody decides for.
|
|
854
958
|
const ahead = s.queue
|
|
855
|
-
.filter(q => q.pid && q.id !== me.id && !(hot && pastCeiling && !pastsCeiling(q)))
|
|
959
|
+
.filter(q => q.pid && q.id !== me.id && !q.ownerStop && !(unpolled(q, t) && !(s.graceUntil > t)) && !(hot && pastCeiling && !pastsCeiling(q)))
|
|
856
960
|
.filter(q => { const r = rank(q, hist, t); return r < myRank || (r === myRank && q.id < me.id); })
|
|
857
961
|
.filter(q => reservesFor(s, q, me, cfg))
|
|
858
962
|
.sort(byRank(hist, t));
|
|
@@ -862,12 +966,12 @@ function decide(s, me, cfg, hist, t) {
|
|
|
862
966
|
// whole heavy line. It keeps its place, and once the disk has room for it,
|
|
863
967
|
// it's ahead of everyone again. A job that would eat into that room waits.
|
|
864
968
|
const floor = bytes(cfg.minDisk);
|
|
865
|
-
const diskStuck = q => m.diskFree != null && m.diskFree < Math.max(q.disk || 0, floor);
|
|
969
|
+
const diskStuck = q => m.diskFree != null && m.diskFree < (tinyDisk(q, hist, cfg) ? (q.diskDeclared ? q.disk || 0 : 0) + ALONE_ROOM : Math.max(q.disk || 0, floor));
|
|
866
970
|
const leavesRoom = m.diskFree != null && m.diskFree - floor >= (me.disk || 0);
|
|
867
971
|
const blocks = q => {
|
|
868
972
|
if (leavesRoom && diskStuck(q)) return false;
|
|
869
973
|
// A waiter held for memory blocks a job of known length only when its own start is known, and comes first.
|
|
870
|
-
if (known(me, hist) && overBudget(s, q, cfg) && !budgetSure(s, q, cfg, hist, t)) return false;
|
|
974
|
+
if (known(me, hist) && overBudget(s, q, cfg, false, false, t, hist) && !budgetSure(s, q, cfg, hist, t)) return false;
|
|
871
975
|
const at = soonestStart(s, q, cfg, hist, t);
|
|
872
976
|
if (q.mem >= BIG_SHARE * bytes(cfg.budget) && at - t > RESERVE_SOON) return false;
|
|
873
977
|
return at < myEnd;
|
|
@@ -911,14 +1015,17 @@ function decide(s, me, cfg, hist, t) {
|
|
|
911
1015
|
// checking the disk again refused (exit 74) a run right after "you already have the
|
|
912
1016
|
// simulator, so you go ahead" (2026-11-03). The watcher's low-disk pauses still hold it.
|
|
913
1017
|
if (me.res.every(r => mine.has(r))) return { ok: true, covered: [...me.res] };
|
|
914
|
-
// Below minDisk nothing else starts, urgent work included
|
|
915
|
-
// a full disk breaks every job on the machine, and on macOS swap needs it too.
|
|
1018
|
+
// Below minDisk nothing else starts, urgent work included, but a job that writes next to
|
|
1019
|
+
// nothing (tinyDisk): a full disk breaks every job on the machine, and on macOS swap needs it too.
|
|
916
1020
|
const others = othersOf(s, me);
|
|
917
1021
|
// The floor plus what it usually eats (diskNeed).
|
|
918
|
-
const { need: needDisk, ate, others: crowded } = diskNeed(s, me, cfg, hist);
|
|
1022
|
+
const { need: needDisk, ate, others: crowded, tiny } = diskNeed(s, me, cfg, hist);
|
|
919
1023
|
// An unreadable disk (null) doesn't stop work; the board and dibs run say it's unknown.
|
|
920
|
-
if (m.diskFree != null && m.diskFree < needDisk)
|
|
921
|
-
|
|
1024
|
+
if (m.diskFree != null && m.diskFree < needDisk) {
|
|
1025
|
+
const floored = !tiny && needDisk === floorFor(me, cfg) && floorWhy(me, cfg);
|
|
1026
|
+
if (floored) return { ok: false, rule: 'disk', why: `disk: ${gb(m.diskFree)} free, you need ${gb(needDisk)} (${floored})`, disk: true, free: m.diskFree, need: needDisk, floorWhy: floored };
|
|
1027
|
+
return { ok: false, rule: 'disk', why: `disk: ${gb(m.diskFree)} free, you need ${gb(needDisk)}${tiny ? (me.diskDeclared ? ` (the ${gb(me.disk || 0)} its --disk says, and ${gb(ALONE_ROOM)} kept free)` : ` (a job that writes next to nothing still leaves ${gb(ALONE_ROOM)} free)`) : ate != null && ate + (crowded ? floorFor(me, cfg) : ALONE_ROOM) >= needDisk ? ` (${crowded ? `the ${gb(floorFor(me, cfg))} dibs keeps free` : `${gb(ALONE_ROOM)} to spare`}, plus the ${gb(ate)} this usually takes; --disk <size> says this run needs less)` : ''}`, disk: true, free: m.diskFree, need: needDisk, ...(ate != null && { usual: ate }) };
|
|
1028
|
+
}
|
|
922
1029
|
// While the machine swaps, only urgent work starts on top of what's running.
|
|
923
1030
|
// With nothing else working, one job may start: waiting can't make the swap
|
|
924
1031
|
// go down then, and swap the OS hasn't reclaimed yet mustn't stop dibs for good.
|
|
@@ -932,35 +1039,41 @@ function decide(s, me, cfg, hist, t) {
|
|
|
932
1039
|
if (sw && sw.level !== 'critical' && !light && sw.rule === 'pressure' && probation(s, me, cfg, hist, t)) trial = true;
|
|
933
1040
|
if (sw && (light || trial || quick) && sw.level !== 'critical') sw = null;
|
|
934
1041
|
// The same for the disk swap grows on: one job may still start alone, since waiting frees nothing then.
|
|
1042
|
+
// Swap grows with memory, not with what a job writes, so a job let under the floor (tinyDisk) keeps the room past the floor.
|
|
935
1043
|
// A light job can't grow the swap, so on a resource that writes little (exclusive, or declaring
|
|
936
1044
|
// no disk: tests, deploys) only the floor holds it. On 2026-10-26 every start waited on the room
|
|
937
1045
|
// kept for swap with 6.8 GB free, one-second test runs included.
|
|
938
1046
|
const writesLittle = me.res.every(r => cfg.resources[r]?.exclusive || !resCfg(cfg, r).disk);
|
|
939
|
-
const squeeze = (me
|
|
1047
|
+
const squeeze = !waitedOn(me) && busy && !sw && !quick && !(light && writesLittle) && diskSqueeze(cfg, tiny ? Math.max(needDisk, bytes(cfg.minDisk)) : needDisk, m);
|
|
940
1048
|
let breaker = (sw || squeeze) && breaksStall(s, me, cfg, hist, t, m);
|
|
941
1049
|
if (sw && !breaker) return { ok: false, why: swapWhy(sw), ...sw, machine: true };
|
|
942
1050
|
if (squeeze && !breaker) return { ok: false, ...squeeze, machine: true };
|
|
943
1051
|
// A light job may pass one stuck on the budget, but not once that one has
|
|
944
1052
|
// waited long, unless it'll be done before that one could start. Waiters
|
|
945
1053
|
// stuck on something else (machine memory, disk) don't hold anyone up.
|
|
946
|
-
const head = ahead.find(q => q.res.every(r => roomFor(s, q, r, cfg).open > 0) && !neverFits(cfg, q) && overBudget(s, q, cfg));
|
|
1054
|
+
const head = ahead.find(q => q.res.every(r => roomFor(s, q, r, cfg).open > 0) && !neverFits(cfg, q) && overBudget(s, q, cfg, false, false, t, hist));
|
|
947
1055
|
if (!quick && head && t - head.enq > ms(cfg.starveAfter) && blocks(head))
|
|
948
1056
|
return { ok: false, rule: 'ahead', why: `${tag(head)} has waited ${dur(t - head.enq)}, so it goes first`, ahead: head, starved: true };
|
|
949
|
-
let budget = overBudget(s, me, cfg, side.length > 0, breaker, t);
|
|
1057
|
+
let budget = overBudget(s, me, cfg, side.length > 0, breaker, t, hist);
|
|
950
1058
|
// Nothing starts past the memory budget (0.0.125). Jobs book what they're
|
|
951
1059
|
// measured using once they've run a few minutes (memOf), so the gap between
|
|
952
1060
|
// asks and use goes to waiters that way, with the machine's pressure as the guard.
|
|
953
1061
|
// Held only by swap growth, the budget is a machine gate like swap itself: the stall breaker may pass it.
|
|
954
|
-
const swapOnly = budget?.swap && !overBudget(s, me, cfg, side.length > 0, true);
|
|
1062
|
+
const swapOnly = budget?.swap && !overBudget(s, me, cfg, side.length > 0, true, t, hist);
|
|
955
1063
|
if (swapOnly && breaksStall(s, me, cfg, hist, t, m)) { budget = null; breaker = true; }
|
|
1064
|
+
// A quick job booked as a featherweight is done before the budget it would pass means
|
|
1065
|
+
// anything; the machine's own pressure still holds it at critical. On 2026-11-03 a
|
|
1066
|
+
// test whose last run took 14.9 s at 95 MB waited 29 minutes on the budget, then ran in 0.8 s (#18336).
|
|
1067
|
+
if (budget && quick && me.feather) budget = null;
|
|
956
1068
|
if (budget) return { ok: false, ...budget, ...(swapOnly && { machine: true }) };
|
|
957
1069
|
if (me.mem >= BIG_JOB && m.memFree < cfg.minFreeMem && s.leases.some(working) && !breaker)
|
|
958
1070
|
return { ok: false, rule: 'ram', why: `machine memory: ${m.memFree}% free, big jobs need ${cfg.minFreeMem}%` };
|
|
959
1071
|
// Stopped last time for using far more than it booked (src/preempt.mjs diskRequeue):
|
|
960
1072
|
// it starts again only once what it's now booked at is really free and swap
|
|
961
1073
|
// has stopped growing, or it would land in the same crunch.
|
|
962
|
-
|
|
963
|
-
|
|
1074
|
+
// Stopped under memory pressure that pausing couldn't ease (pressureRequeue): the same.
|
|
1075
|
+
if ((me.requeued === 'over' || me.requeued === 'memory') && ((realFree(m) ?? 0) < me.mem || swapGrowing(m)))
|
|
1076
|
+
return { ok: false, rule: 'oversize', machine: true, why: `${gb(me.mem)} of memory to be really free and swap to hold still, since ${me.requeued === 'over' ? 'it used far more than it booked last time' : 'memory pressure stopped it last time'}`
|
|
964
1077
|
+ ` (now ${gb(realFree(m) ?? 0)} free${swapGrowing(m) ? ', swap growing' : ''})` };
|
|
965
1078
|
const pool = poolBlock(s, me, cfg, mine, m);
|
|
966
1079
|
if (pool) return { ok: false, ...pool };
|
package/src/serve.mjs
CHANGED
|
@@ -140,6 +140,18 @@ export function place(workers, need, t = now()) {
|
|
|
140
140
|
// The Tailscale address of this machine. Ask Tailscale itself when its CLI is
|
|
141
141
|
// around; otherwise a 100.64.0.0/10 address on a tunnel interface. That range
|
|
142
142
|
// alone isn't enough: carrier-grade NAT and some hotspots use it too.
|
|
143
|
+
// A log line said once for as long as it stays the same, per key: the Tailscale
|
|
144
|
+
// address is tried every 30 s, and on 2026-11-10 failed all day (EADDRNOTAVAIL),
|
|
145
|
+
// one line each time. null clears the key, so the next failure is said again.
|
|
146
|
+
export function oncePerChange(log) {
|
|
147
|
+
const last = new Map();
|
|
148
|
+
return (key, line) => {
|
|
149
|
+
if (line == null) return last.delete(key);
|
|
150
|
+
if (last.get(key) !== line) log(line);
|
|
151
|
+
last.set(key, line);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
143
155
|
function tailscaleIp() {
|
|
144
156
|
for (const cli of TS_CLI) {
|
|
145
157
|
try {
|
|
@@ -692,14 +704,15 @@ export async function serve(o) {
|
|
|
692
704
|
const addrs = () => [...listening.keys()].filter(h => h !== '127.0.0.1').map(h => `http://${h}:${port}`);
|
|
693
705
|
try { made = makeServer({ token: rc.token, log, self: rc.name, joinUrl, port, addrs }); } catch (e) { die(e.message); }
|
|
694
706
|
const { server } = made;
|
|
707
|
+
const first = o.bind || '127.0.0.1';
|
|
708
|
+
const failed = oncePerChange(log);
|
|
695
709
|
const listen = host => new Promise(resolve => {
|
|
696
710
|
if (listening.has(host)) return resolve(true);
|
|
697
711
|
const s = server();
|
|
698
|
-
s.once('error', e => {
|
|
699
|
-
s.listen(port, host, () => { listening.set(host, s); resolve(true); });
|
|
712
|
+
s.once('error', e => { failed(host, `can't listen on ${host}:${port}: ${e.message}${host === first ? '' : '. Trying again every 30 s, quietly'}`); resolve(false); });
|
|
713
|
+
s.listen(port, host, () => { failed(host, null); listening.set(host, s); resolve(true); });
|
|
700
714
|
});
|
|
701
715
|
const up = host => log(`listening on http://${host}:${port}`);
|
|
702
|
-
const first = o.bind || '127.0.0.1';
|
|
703
716
|
if (!await listen(first)) die(o.bind ? `can't listen on ${o.bind}:${port}` : `port ${port} is taken. Is a coordinator already running? (dibs machines)`);
|
|
704
717
|
// "listening" comes after remote.json is saved: whatever waits for the line
|
|
705
718
|
// and then reads the file (a test on 2026-10-16) found it missing.
|
package/src/service.mjs
CHANGED
|
@@ -20,9 +20,10 @@ const KINDS = {
|
|
|
20
20
|
throttle: { args: ['throttle', '--watch'], what: 'moves hot work outside dibs to background priority' },
|
|
21
21
|
web: { args: ['web'], what: 'the page and MCP server showing your agents\' work' },
|
|
22
22
|
relay: { args: ['relay'], what: 'reach the page from any browser through the encrypted relay (dibs pair --remote)' },
|
|
23
|
+
guard: { args: ['guard', 'serve'], what: 'answers the Claude Code hook without starting Node for every tool call' },
|
|
23
24
|
};
|
|
24
25
|
// Things started by hand before the service existed; stopped so the service can take over.
|
|
25
|
-
const PIDFILES = { worker: 'worker.pid', throttle: 'cool.pid' };
|
|
26
|
+
const PIDFILES = { worker: 'worker.pid', throttle: 'cool.pid', guard: 'guard.pid' };
|
|
26
27
|
|
|
27
28
|
const label = k => `dev.dibs.${k}`;
|
|
28
29
|
// DIBS_LAUNCH_AGENTS and DIBS_LAUNCHCTL stand in for ~/Library/LaunchAgents and launchctl in tests.
|
|
@@ -88,7 +89,7 @@ function install(k) {
|
|
|
88
89
|
if (PIDFILES[k]) stopManual(k);
|
|
89
90
|
if (OS === 'macos') {
|
|
90
91
|
// Jobs a worker runs inherit its scheduling class, so it can't be Background.
|
|
91
|
-
const type = { serve: 'Standard', worker: 'Interactive', throttle: 'Background', web: 'Standard', relay: 'Standard' }[k];
|
|
92
|
+
const type = { serve: 'Standard', worker: 'Interactive', throttle: 'Background', web: 'Standard', relay: 'Standard', guard: 'Interactive' }[k];
|
|
92
93
|
fs.mkdirSync(path.dirname(plist(k)), { recursive: true });
|
|
93
94
|
fs.writeFileSync(plist(k), `<?xml version="1.0" encoding="UTF-8"?>
|
|
94
95
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
@@ -210,7 +211,7 @@ export async function service(args) {
|
|
|
210
211
|
if (kinds.includes('relay')) { const s = await relayStatus(); if (s) console.log(` relay: ${s}`); }
|
|
211
212
|
return;
|
|
212
213
|
}
|
|
213
|
-
if (!kinds.length) die(`which? dibs service ${action} serve|worker|throttle|web|relay (several at once is fine)`);
|
|
214
|
+
if (!kinds.length) die(`which? dibs service ${action} serve|worker|throttle|web|relay|guard (several at once is fine)`);
|
|
214
215
|
// A service runs for weeks and listens on the network: not on a Node with a known hole.
|
|
215
216
|
const hole = action === 'install' && !process.env.DIBS_ALLOW_UNPATCHED && unpatched();
|
|
216
217
|
if (hole) die(`${hole}. The service would run on that Node (${process.execPath}): put a fixed one first on your PATH and run this again.`);
|