@dibssoftware/dibs 0.0.181 → 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 +103 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +370 -73
- 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 +120 -9
- 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/package.json +1 -1
- package/skills/dibs/SKILL.md +79 -149
- package/src/about.mjs +341 -0
- package/src/acquire.mjs +111 -27
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +95 -42
- 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 +243 -82
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +27 -11
- 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 +118 -6
- package/src/guard.mjs +239 -86
- 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 +33 -9
- package/src/measure.mjs +42 -11
- 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 +19 -0
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +1 -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 +139 -20
- 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/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 +1078 -133
- 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 +353 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/schedule.mjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Who goes next. Pure functions of the state, config, history and clock, so
|
|
2
2
|
// they can be tested without processes.
|
|
3
|
-
import { resCfg, machine, hardware, RECENT, SWAP_WINDOW } from './config.mjs';
|
|
4
|
-
import { bytes, ms, dur, gb, now, runsOf, indexed, unpolled } from './util.mjs';
|
|
3
|
+
import { resCfg, machine, hardware, isEnv, RECENT, SWAP_WINDOW } from './config.mjs';
|
|
4
|
+
import { bytes, ms, dur, gb, size, clock, 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';
|
|
8
8
|
import { dibsMem } from './platform.mjs';
|
|
9
9
|
import { alongside, merge, onTop } from './overlap.mjs';
|
|
10
|
+
import { progressOf, cpuLeft } from './jobprogress.mjs';
|
|
10
11
|
|
|
11
12
|
const MIN = 6e4;
|
|
12
13
|
|
|
@@ -140,9 +141,13 @@ export const lent = (l, r) => !!l.pauses?.some(p => p.lease != null && (!r || !p
|
|
|
140
141
|
const OVER_SLACK = 0.1;
|
|
141
142
|
export const overBy = l => { const m = Math.max(l.mem, l.usual || 0); return l.use && l.use.mem > m * (1 + OVER_SLACK) ? l.use.mem - m : 0; };
|
|
142
143
|
|
|
143
|
-
// Time left on a lease, or null when there's nothing to go on.
|
|
144
|
+
// Time left on a lease, or null when there's nothing to go on. The job's own
|
|
145
|
+
// progress, once it has a rate, says more than any history; then the CPU its own
|
|
146
|
+
// runs usually take against what it has had (src/jobprogress.mjs); then their clock time.
|
|
144
147
|
export function remaining(l, hist, t = now()) {
|
|
145
148
|
if (l.kind === 'hold') return Math.max(l.expires - t, 0);
|
|
149
|
+
const own = progressOf(l, t)?.left ?? cpuLeft(l, hist, t);
|
|
150
|
+
if (own != null) return Math.max(own, MIN_LEFT);
|
|
146
151
|
const e = typical(hist, l.key) || l.est;
|
|
147
152
|
return e == null ? null : Math.max(e - (t - l.start - pausedFor(l, t)), MIN_LEFT);
|
|
148
153
|
}
|
|
@@ -172,10 +177,11 @@ export function recentUse(hist, who, res, t = now()) {
|
|
|
172
177
|
// recent use agents who used the same resources a lot in the last hour, up to -10m (fair share)
|
|
173
178
|
// holds already holds a lease (holdingOf), moves like high
|
|
174
179
|
// let ahead someone yielded their place to you
|
|
180
|
+
// fair share its session would go past its share while other sessions wait (fairShare, below): behind them
|
|
175
181
|
// A waiter that already holds part of what it needs (holdingOf) moves up this
|
|
176
182
|
// far: enough to pass waiters that hold nothing, not past a high job.
|
|
177
183
|
const HOLDING_SHIFT = 10 * MIN;
|
|
178
|
-
export function rankParts(q, hist, t = now()) {
|
|
184
|
+
export function rankParts(q, hist, t = now(), fair = null) {
|
|
179
185
|
const parts = [];
|
|
180
186
|
const add = (label, shift) => { if (Math.abs(shift) >= 1000) parts.push({ label, shift: Math.round(shift) }); };
|
|
181
187
|
// The quick lane goes to the front of its line, ahead of any priority: it's over in seconds.
|
|
@@ -190,16 +196,18 @@ export function rankParts(q, hist, t = now()) {
|
|
|
190
196
|
add(e < PROBE ? 'short job' : 'long job', PROBE - Math.min(e, LENGTH_MAX));
|
|
191
197
|
const usedRecently = recentUse(hist, q.who, q.res, t).total;
|
|
192
198
|
if (usedRecently > 0) add('recent use', -Math.min(SHARE_MAX, usedRecently * SHARE_RATE));
|
|
199
|
+
if (fair?.(q)) add(OVER_SHARE, -FAIR_SHIFT);
|
|
193
200
|
let value = q.enq - parts.reduce((a, p) => a + p.shift, 0);
|
|
194
201
|
if (q.yieldRank != null && q.yieldRank < value) { add('let ahead', value - q.yieldRank); value = q.yieldRank; }
|
|
195
202
|
return { value, parts };
|
|
196
203
|
}
|
|
197
204
|
|
|
198
|
-
export const rank = (q, hist, t = now()) => rankParts(q, hist, t).value;
|
|
205
|
+
export const rank = (q, hist, t = now(), fair = null) => rankParts(q, hist, t, fair).value;
|
|
199
206
|
// Each waiter's rank is worked out once per sort, not once per comparison.
|
|
200
|
-
|
|
207
|
+
// fair: fairShare(s, cfg) for the order dibs really starts them in; without it, the order before fair share.
|
|
208
|
+
export const byRank = (hist, t = now(), fair = null) => {
|
|
201
209
|
const memo = new Map();
|
|
202
|
-
const r = q => { if (!memo.has(q)) memo.set(q, rank(q, hist, t)); return memo.get(q); };
|
|
210
|
+
const r = q => { if (!memo.has(q)) memo.set(q, rank(q, hist, t, fair)); return memo.get(q); };
|
|
203
211
|
return (a, b) => r(a) - r(b) || a.id - b.id;
|
|
204
212
|
};
|
|
205
213
|
|
|
@@ -306,7 +314,15 @@ const drainRate = m => (m.diskDrain || 0) / Math.max(m.drainMs || 0, 30e3);
|
|
|
306
314
|
// need anyway; and while free disk falls fast enough to be under that within
|
|
307
315
|
// DRAIN_AHEAD, it waits for it to hold steady. Two builds writing 4 GB on a
|
|
308
316
|
// disk with 200 GB free hold nobody up. Null when neither applies.
|
|
309
|
-
|
|
317
|
+
// drain false: only the room kept for swap, for a job that writes next to nothing (tinyDisk),
|
|
318
|
+
// which can't make a falling disk fall faster.
|
|
319
|
+
// The floor as every message states it, so the rule agents read is the rule enforced: minDisk, and
|
|
320
|
+
// while the machine swaps, minDisk plus swapRoom. On 2026-11-27 one line said "until 8.0 GB of disk
|
|
321
|
+
// is free for swap to grow into" with 6.8 GB free while every other said the floor was 5 GB.
|
|
322
|
+
// swapNote is what follows the floor wherever it's named; keptFree is the two together.
|
|
323
|
+
export const swapNote = cfg => (cfg.swapRoom != null && bytes(cfg.swapRoom) > 0 ? `, ${GBs(bytes(cfg.minDisk) + bytes(cfg.swapRoom))} while the machine swaps` : '');
|
|
324
|
+
export const keptFree = cfg => `${GBs(bytes(cfg.minDisk))} free${swapNote(cfg)}`;
|
|
325
|
+
export function diskSqueeze(cfg, need, m = machine(), { drain = true } = {}) {
|
|
310
326
|
if (m.diskFree == null) return null;
|
|
311
327
|
// Swap over maxSwap that holds still with pressure normal is left over from
|
|
312
328
|
// an earlier crunch: macOS keeps it allocated for hours. On 2026-10-15 a flat
|
|
@@ -315,9 +331,9 @@ export function diskSqueeze(cfg, need, m = machine()) {
|
|
|
315
331
|
const room = cfg.swapRoom != null ? bytes(cfg.swapRoom) : 0;
|
|
316
332
|
if (cfg.swapRoom != null && paging && m.diskFree < need + room)
|
|
317
333
|
return { rule: 'swaproom', free: m.diskFree, need: need + room, room, used: m.swapUsed,
|
|
318
|
-
why: `disk: ${
|
|
334
|
+
why: `disk: ${GBs(m.diskFree)} free. dibs keeps ${keptFree(cfg)}, and the machine is swapping now (${GBs(m.swapUsed)} of swap), so nothing new starts until ${GBs(need + room)} is free${need > bytes(cfg.minDisk) ? ` (what this job needs plus the ${GBs(room)} kept for swap)` : ''}` };
|
|
319
335
|
const ahead = m.diskFree - drainRate(m) * DRAIN_AHEAD;
|
|
320
|
-
if (diskDraining(m) && ahead < need + room)
|
|
336
|
+
if (drain && diskDraining(m) && ahead < need + room)
|
|
321
337
|
return { rule: 'drain', free: m.diskFree, fell: m.diskDrain, projected: Math.max(0, ahead),
|
|
322
338
|
why: `free disk fell ${gb(m.diskDrain)} in 5 min to ${gb(m.diskFree)}, and at that rate it's under ${gb(need + room)} within ${DRAIN_AHEAD / MIN} min, so dibs starts nothing new until it holds steady` };
|
|
323
339
|
return null;
|
|
@@ -353,19 +369,24 @@ export const coresOf = l => (l.kind === 'run' && l.use?.cpu != null ? l.use.cpu
|
|
|
353
369
|
//
|
|
354
370
|
// Once a run is measured and its memory has stopped climbing (settled), the
|
|
355
371
|
// plan gives way to what it uses now. A run idle IDLE_BOOK books only that:
|
|
356
|
-
// it isn't climbing anywhere. A busy one books it plus
|
|
357
|
-
// move
|
|
358
|
-
//
|
|
372
|
+
// it isn't climbing anywhere. A busy one books it plus a margin (marginOf):
|
|
373
|
+
// footprints move between 10-second samples, and a test worker starting a
|
|
374
|
+
// browser adds most of a gigabyte. On 2026-10-15 two Playwright runs booked
|
|
359
375
|
// 12 of 11 GB on the strength of past peaks while using 3 GB between them, one
|
|
360
376
|
// idle for 7 minutes, and a high deploy waited 11 minutes with 12 GB free.
|
|
361
377
|
//
|
|
362
|
-
// A run measured for BOOK_AFTER books its peak plus
|
|
378
|
+
// A run measured for BOOK_AFTER books its peak plus the margin even while it
|
|
363
379
|
// still climbs, never more than its plan: on 2026-10-19 a test suite that asked
|
|
364
380
|
// 8 GB used 0.8, and three like it held 16 GB of an 11 GB budget while 18 jobs
|
|
365
381
|
// waited with 12 GB free. A waiter let into that gap still needs the memory to
|
|
366
382
|
// be really free (overBudget): the OS's pressure is the guard, not the asks.
|
|
367
383
|
const IDLE_BOOK = 5 * MIN; // the same 5 minutes acquire.mjs marks a run idle at (IDLE_AFTER)
|
|
368
|
-
|
|
384
|
+
// The margin grows with the job: a fifth of what it was measured at, at least MARGIN_MIN and at most
|
|
385
|
+
// BUSY_MARGIN. A flat gigabyte was nearly half again on a 2.3 GB solver, and on
|
|
386
|
+
// 2026-11-27 three of them, asked 5 GB and using 2.3 to 3 GB each, held about 9 GB of the 11 GB
|
|
387
|
+
// budget while a 2 GB browser run waited hours.
|
|
388
|
+
const BUSY_MARGIN = 1024 ** 3, MARGIN_MIN = 256 * 1024 ** 2, MARGIN_SHARE = 0.2;
|
|
389
|
+
export const marginOf = x => Math.min(BUSY_MARGIN, Math.max(MARGIN_MIN, x * MARGIN_SHARE));
|
|
369
390
|
// Long enough for a test suite to start its workers and a build its compiler:
|
|
370
391
|
// eighteen 10-second samples.
|
|
371
392
|
const BOOK_AFTER = 3 * MIN;
|
|
@@ -378,10 +399,10 @@ export const memOf = (l, t = now()) => {
|
|
|
378
399
|
// Stopped, it keeps every byte it had (they go to swap, not back to the machine), and it isn't
|
|
379
400
|
// measured while paused: never the idle discount, always the most it was seen using.
|
|
380
401
|
if (l.pausedAt) return Math.max(planned, l.peak?.mem || 0);
|
|
381
|
-
if (steady(l, t)) return l.idleSince && t - l.idleSince >= IDLE_BOOK ? l.use.mem : l.use.mem +
|
|
402
|
+
if (steady(l, t)) return l.idleSince && t - l.idleSince >= IDLE_BOOK ? l.use.mem : l.use.mem + marginOf(l.use.mem);
|
|
382
403
|
if (t - l.start - pausedFor(l, t) < BOOK_AFTER) return planned;
|
|
383
404
|
const peak = Math.max(l.peak?.mem || 0, l.use.mem);
|
|
384
|
-
return Math.min(peak +
|
|
405
|
+
return Math.min(peak + marginOf(peak), Math.max(planned, peak));
|
|
385
406
|
};
|
|
386
407
|
|
|
387
408
|
// How far into a run this command reaches its peak, the latest of its last
|
|
@@ -496,6 +517,26 @@ function breaksStall(s, me, cfg, hist, t, m) {
|
|
|
496
517
|
const pick = held.sort((a, b) => (a.mem || 0) - (b.mem || 0) || expected(a, hist) - expected(b, hist) || a.enq - b.enq || a.id - b.id)[0];
|
|
497
518
|
return pick.id === me.id;
|
|
498
519
|
}
|
|
520
|
+
// Warning-level memory pressure is a flag on the whole machine, and on 2026-11-27 it held every
|
|
521
|
+
// start below urgent for hours, a 2 GB browser run included, with gigabytes really free: light jobs
|
|
522
|
+
// passing it kept resetting the stall breaker's clock. So a job up to PRESSURE_SMALL that a person
|
|
523
|
+
// waits on (high, or a --by with its reason) or that has waited PRESSURE_PATIENCE starts through it
|
|
524
|
+
// when what the machine really has free (memAvail: free plus what the OS reclaims on demand) holds
|
|
525
|
+
// it and PRESSURE_SPARE more. One at a time: the next waits until that one's memory holds steady.
|
|
526
|
+
// Critical pressure, swap growing past maxSwap and the memory budget still hold it, and the watcher
|
|
527
|
+
// pauses jobs as before if pressure turns critical.
|
|
528
|
+
export const PRESSURE_SMALL = 3 * 1024 ** 3; // a browser suite or a test run; bigger is what makes pressure
|
|
529
|
+
export const PRESSURE_PATIENCE = 10 * MIN; // the stall breaker's STALL, counted from this job's own wait
|
|
530
|
+
const PRESSURE_SPARE = 1024 ** 3;
|
|
531
|
+
function easesPast(s, me, sw, m, t) {
|
|
532
|
+
if (sw.rule !== 'pressure' || sw.level === 'critical' || (me.mem || 0) > PRESSURE_SMALL || me.kind === 'hold') return false;
|
|
533
|
+
if (!waitedOn(me) && !(me.enq != null && t - me.enq >= PRESSURE_PATIENCE)) return false;
|
|
534
|
+
const free = shownFree(m);
|
|
535
|
+
if (free == null || free < (me.mem || 0) + PRESSURE_SPARE) return false;
|
|
536
|
+
return !s.leases.some(l => l.eased && !settled(l, t));
|
|
537
|
+
}
|
|
538
|
+
export const EASED_LINE = 'let in through memory pressure: it is small, the machine really has the room, and it had waited long or a person waits on it';
|
|
539
|
+
|
|
499
540
|
export const BREAKER_LINE = `let in: nothing had started for ${STALL / MIN} min, so dibs starts the smallest waiter, one at a time`;
|
|
500
541
|
|
|
501
542
|
// strict: the roomy rule doesn't apply (a job on top of a full resource has
|
|
@@ -513,7 +554,8 @@ const YOUNG = 3 * MIN, REAL_WAIT = 2 * MIN;
|
|
|
513
554
|
export const swapTaken = m => (swapGrowing(m) ? m.swapGrowth : 0);
|
|
514
555
|
// noSwap: swap growth doesn't count (the stall breaker let it by).
|
|
515
556
|
// hist: what the running jobs' own runs say about when they peak (growTo); without it, asks stand.
|
|
516
|
-
|
|
557
|
+
// eased: let past warning pressure (easesPast), which checked the room is really free.
|
|
558
|
+
function overBudget(s, q, cfg, strict = false, noSwap = false, t = now(), hist = null, eased = false) {
|
|
517
559
|
// A job as big as the whole budget runs when nothing else is.
|
|
518
560
|
if (!othersOf(s, q).length) return null;
|
|
519
561
|
const m = machine();
|
|
@@ -529,7 +571,7 @@ function overBudget(s, q, cfg, strict = false, noSwap = false, t = now(), hist =
|
|
|
529
571
|
// for minutes after it falls; on 2026-10-20 twenty jobs waited "blocked by
|
|
530
572
|
// memory" with 8.6 GB free and 1 of 10 cores busy.
|
|
531
573
|
// 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);
|
|
574
|
+
const room = () => ((q.mem || 0) <= LIGHT_MEM && !(m.vmPressure >= 2)) || eased || realRoom(q, cfg, m);
|
|
533
575
|
const fitsUse = () => memUsed(s, usedNow) + swap + q.mem <= budget && room();
|
|
534
576
|
if (mem + q.mem > budget && !fitsUse())
|
|
535
577
|
return { rule: 'memory', used: mem, of: budget, need: q.mem, ...(swap && { swap }),
|
|
@@ -554,7 +596,7 @@ function overBudget(s, q, cfg, strict = false, noSwap = false, t = now(), hist =
|
|
|
554
596
|
// A big job that started under YOUNG ago isn't in those readings yet, so the next one waits for it.
|
|
555
597
|
const bigYoung = s.leases.some(l => !covers(l, q) && l.kind === 'run' && (l.mem || 0) > LIGHT_MEM && t - (l.start || 0) < YOUNG);
|
|
556
598
|
const waitedOut = q.enq != null && t - q.enq >= REAL_WAIT && !bigYoung && !swapGrowing(m) && !(m.vmPressure >= 1);
|
|
557
|
-
if (!noSwap && !waitedOut && m.memAvail != null && (q.mem || 0) > LIGHT_MEM) {
|
|
599
|
+
if (!noSwap && !waitedOut && !eased && m.memAvail != null && (q.mem || 0) > LIGHT_MEM) {
|
|
558
600
|
// Its own hold or the dibs run it's nested in booked memory for it: that's no one else's.
|
|
559
601
|
// Only a job that just started may still grow into its booking: one that has run
|
|
560
602
|
// a while at less is done growing. On 2026-10-22 a ship's deploy and simulator,
|
|
@@ -717,7 +759,8 @@ export function mostHere(cfg, sent) {
|
|
|
717
759
|
// a bigger machine) is booked at most at mostHere instead: a lone job past the
|
|
718
760
|
// budget still runs. On 2026-10-18 a test run that had used 5 cores on the
|
|
719
761
|
// 10-core Mac was refused on a 4-core VM, though it asked for 3.
|
|
720
|
-
|
|
762
|
+
// A --mem dibs has replaced with what the command's runs used (learnedMem, src/measure.mjs sized) can't make it never fit.
|
|
763
|
+
export const explicitAsk = q => ({ mem: q.declared && !q.learnedMem ? q.asked ?? q.mem : 0, cpu: q.cpuDeclared ? q.askedCpu ?? q.cpu : 0, sent: q.sent });
|
|
721
764
|
export function capToMachine(cfg, q) {
|
|
722
765
|
const most = mostHere(cfg, q.sent);
|
|
723
766
|
let changed = false;
|
|
@@ -870,6 +913,19 @@ export const ALONE_ROOM = 1024 ** 3;
|
|
|
870
913
|
// and isn't held for the room kept for swap. On 2026-11-02 and 03 a Shop ship
|
|
871
914
|
// (#18328) waited about a day while idle sessions' swap kept free disk under 9 GB.
|
|
872
915
|
const HARD_FLOOR = 3 * 1024 ** 3;
|
|
916
|
+
// A command that only gives the machine something back: shutting a simulator down, deleting or erasing
|
|
917
|
+
// one, deleting a simulator runtime. It never waits on the disk floor or the machine's memory: on
|
|
918
|
+
// 2026-11-26, with 3.1 GB free and swap at 8.3 GB, an agent's xcrun simctl shutdown, wrapped in
|
|
919
|
+
// dibs run sim by the guard, waited for 5.1 GB of free disk it was about to help free. It still
|
|
920
|
+
// takes its turn on the resource: shutting down a simulator another agent is testing on breaks
|
|
921
|
+
// that agent's run. argv, or one sh -c string with nothing chained to it.
|
|
922
|
+
const FREES = /^(?:\S*\/)?(?:xcrun\s+)?simctl\s+(?:--set\s+\S+\s+)?(?:shutdown|delete|erase|runtime\s+delete)(?:\s+[^\s;&|<>`$()]+)*\s*$/;
|
|
923
|
+
export function freesOnly(cmd) {
|
|
924
|
+
if (!Array.isArray(cmd) || !cmd.length) return false;
|
|
925
|
+
const shell = /^(?:\S*\/)?(?:ba|z)?sh$/.test(cmd[0]) && cmd[1] === '-c' && cmd.length === 3;
|
|
926
|
+
return FREES.test(shell ? cmd[2].trim() : cmd.join(' '));
|
|
927
|
+
}
|
|
928
|
+
|
|
873
929
|
// A --by deadline counts only with its reason (-m): a bare one costs nothing to type.
|
|
874
930
|
export const waitedOn = q => q.prio === 'high' || q.prio === 'urgent' || (q.by != null && !!q.purpose);
|
|
875
931
|
const floorFor = (q, cfg) => (waitedOn(q) ? Math.min(bytes(cfg.minDisk), HARD_FLOOR) : bytes(cfg.minDisk));
|
|
@@ -883,30 +939,49 @@ export const TINY_DISK = 100 * 1024 ** 2;
|
|
|
883
939
|
// middle of the last ten (the most of them until there are DISK_RUNS) under TINY_DISK, and
|
|
884
940
|
// the last run, failed or not, under it too: one that ate more takes the exemption away
|
|
885
941
|
// until it's back down. A failed run alone, stopped early, says nothing about what a whole
|
|
886
|
-
// one eats.
|
|
942
|
+
// one eats. A small --disk (claimable) goes before all that: the job's own word beats
|
|
943
|
+
// readings other agents' writes muddy, unless its runs ate CLAIM_BROKEN.
|
|
887
944
|
export function tinyDisk(me, hist, cfg) {
|
|
888
945
|
// A --disk of minDisk or more says it isn't small, whatever its resource.
|
|
889
946
|
if (me.diskDeclared && (me.disk || 0) >= bytes(cfg.minDisk)) return false;
|
|
890
947
|
// A run the watcher cleared caches under reads low: the clean's room hid what it wrote (src/diskwarn.mjs clean).
|
|
891
948
|
const runs = runsOf(hist || [], me.key).filter(h => h.ate != null && !h.cleaned).slice(-10);
|
|
949
|
+
// A small --disk within its cap is taken at its word, over runs that seemed to eat a little more.
|
|
950
|
+
if (me.diskDeclared && claimable(me, cfg)) return !claimBroken(runs);
|
|
892
951
|
if (runs.length && runs.at(-1).ate >= TINY_DISK) return false;
|
|
893
952
|
const good = runs.filter(h => !h.failed).map(h => h.ate);
|
|
894
953
|
if (good.length >= TINY_RUNS) return (good.length < DISK_RUNS ? Math.max(...good) : mid(good)) < TINY_DISK;
|
|
895
|
-
// Too few runs to go by
|
|
896
|
-
//
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
954
|
+
// Too few runs to go by and no --disk: a first npm ci or a bundling deploy writes gigabytes,
|
|
955
|
+
// so a resource's kind alone never makes a job small.
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
// Whether a --disk is small enough to start a job under minDisk: under TINY_DISK anywhere, or up to
|
|
959
|
+
// CLAIM_MAX on a resource that declares no disk (tests, deploys, locks).
|
|
960
|
+
const claimable = (me, cfg) => (me.disk || 0) < TINY_DISK || ((me.disk || 0) <= CLAIM_MAX && me.res.every(r => isFiles(r) || !resCfg(cfg, r).disk));
|
|
961
|
+
// A job's runs show its --disk is wrong: the last one, or the middle of them, ate CLAIM_BROKEN or more.
|
|
962
|
+
// What a run "ate" is its share of the disk's fall while it ran (src/measure.mjs shareDisk), so it
|
|
963
|
+
// also holds what other agents wrote meanwhile: on 2026-11-26 test runs that write nothing read
|
|
964
|
+
// 136 MB each while one agent's scratch folder grew 2.6 GB, their --disk 50M was overruled, and
|
|
965
|
+
// eight agents' jobs sat under the floor for hours. Noise that size never reaches a gigabyte.
|
|
966
|
+
const CLAIM_BROKEN = 1024 ** 3;
|
|
967
|
+
const claimBroken = runs => runs.length > 0 && (runs.at(-1).ate >= CLAIM_BROKEN || mid(runs.map(h => h.ate)) >= CLAIM_BROKEN);
|
|
968
|
+
// The last runs' writes, for the message that says why a --disk wasn't believed.
|
|
969
|
+
export function brokenClaim(me, hist, cfg) {
|
|
970
|
+
if (!me.diskDeclared || !claimable(me, cfg)) return null;
|
|
971
|
+
const runs = runsOf(hist || [], me.key).filter(h => h.ate != null && !h.cleaned).slice(-10);
|
|
972
|
+
return claimBroken(runs) ? runs.at(-1).ate : null;
|
|
901
973
|
}
|
|
902
974
|
// Why a job held at the floor is held there, and, when its --disk is smaller, why that didn't
|
|
903
975
|
// lower it: agents read --disk 1G as the floor's size, and a deploy hit exit 74 twice at 2.6 GB
|
|
904
976
|
// free on 2026-11-10 with --disk 1G.
|
|
905
977
|
const GBs = b => gb(b).replace(/G$/, ' GB');
|
|
906
|
-
export function floorWhy(me, cfg) {
|
|
978
|
+
export function floorWhy(me, cfg, hist) {
|
|
907
979
|
const floor = floorFor(me, cfg);
|
|
908
|
-
const base =
|
|
980
|
+
const base = waitedOn(me) && floor < bytes(cfg.minDisk) ? `the ${GBs(floor)} dibs keeps free for a job a person waits on` : `the ${GBs(floor)} dibs keeps free${swapNote(cfg)}`;
|
|
909
981
|
if (!me.diskDeclared || (me.disk || 0) >= floor) return base;
|
|
982
|
+
const broke = brokenClaim(me, hist, cfg);
|
|
983
|
+
if (broke != null) return `${base}; its --disk ${size(me.disk || 0)} isn't believed, because its last run of this command ate ${GBs(broke)} of free disk.`
|
|
984
|
+
+ ` A run that eats under ${GBs(CLAIM_BROKEN)} makes it count again`;
|
|
910
985
|
const little = me.res.every(r => isFiles(r) || !resCfg(cfg, r).disk);
|
|
911
986
|
return `${base}; --disk ${GBs(me.disk || 0)} doesn't lower that: only a --disk ${little ? 'of 1 GB or less' : 'under 100 MB'}`
|
|
912
987
|
+ ` starts a job below it, or two runs of the same command that each wrote under 100 MB`;
|
|
@@ -931,13 +1006,31 @@ export function verdict(s, me, cfg, hist, t = now()) {
|
|
|
931
1006
|
return v;
|
|
932
1007
|
}
|
|
933
1008
|
|
|
1009
|
+
// dibs halt (src/halt.mjs): until it lifts, no new job starts. A file lease runs nothing, so it isn't held.
|
|
1010
|
+
// Read straight from the state, so a halt past its time holds nothing even before a reap drops it.
|
|
1011
|
+
export const halted = (s, t = now()) => (s.halt && !(s.halt.until != null && t >= s.halt.until) ? s.halt : null);
|
|
1012
|
+
// "until 14:37" or "until it's lifted", for every line that says why nothing starts.
|
|
1013
|
+
export const haltUntil = h => (h.until != null ? `until ${clock(h.until)}` : "until it's lifted");
|
|
1014
|
+
export const haltBy = h => `${h.by || 'the person'}${h.reason ? `: "${h.reason}"` : ''}`;
|
|
1015
|
+
|
|
1016
|
+
const YIELD_HOLD = 10 * MIN;
|
|
934
1017
|
function decide(s, me, cfg, hist, t) {
|
|
1018
|
+
const h = halted(s, t);
|
|
1019
|
+
if (h && !me.res.every(isFiles))
|
|
1020
|
+
return { ok: false, rule: 'halt', until: h.until ?? null, by: h.by || null,
|
|
1021
|
+
why: `the hold on new jobs to lift (${haltUntil(h)}, set by ${haltBy(h)}). Jobs already running go on. It lifts on its own; dibs halt off lifts it now` };
|
|
1022
|
+
// A job that stepped aside for a waiter (src/preempt.mjs yieldFor) lets it start first, or it would
|
|
1023
|
+
// take back the room it gave. At most YIELD_HOLD: a waiter held by something else mustn't keep it out for good.
|
|
1024
|
+
const yieldedTo = me.requeued === 'yield' && me.yieldTo != null && t - (me.yieldedAt ?? 0) < YIELD_HOLD && s.queue.find(q => q.id === me.yieldTo && q.pid);
|
|
1025
|
+
if (yieldedTo) return { ok: false, rule: 'ahead', why: `it stepped aside for #${yieldedTo.id} (${tag(yieldedTo)}), which hasn't started yet`, ahead: yieldedTo };
|
|
935
1026
|
// In the quick lane while there's room in it; the cap counts quick jobs running now.
|
|
936
1027
|
const quick = !!(me.quickPass ?? quickPass(me, hist, cfg)) && s.leases.filter(l => l.quick).length < QUICK_MAX;
|
|
937
1028
|
// A quick job dibs hasn't seen use much memory is booked small, as a featherweight is.
|
|
938
1029
|
const lightQuick = quick && !me.declared && runsOf(hist, me.key).slice(-10).every(h => h.mem == null || h.mem <= LIGHT_MEM);
|
|
939
1030
|
if ((me.mem || 0) > LIGHT_MEM && (featherweight(me, hist) || lightQuick || measuredLight(me, hist))) me = { ...me, mem: LIGHT_MEM, feather: true };
|
|
940
|
-
const
|
|
1031
|
+
const fair = fairShare(s, cfg, t);
|
|
1032
|
+
const overMe = fair(me);
|
|
1033
|
+
const myRank = rank(me, hist, t, fair);
|
|
941
1034
|
// When it would be done, at its slow runs: passing a waiter is a promise not to delay it.
|
|
942
1035
|
const myEnd = t + Math.max(expected(me, hist), slow(hist, me.key) || 0);
|
|
943
1036
|
const mine = holdsOf(s, me);
|
|
@@ -949,7 +1042,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
949
1042
|
// writes next to nothing: the load ceiling, the room kept for swap and a falling disk
|
|
950
1043
|
// don't hold it (over minDisk, it goes). On 2026-10-21 0.5 GB deploys waited 79 and 92 s
|
|
951
1044
|
// on the room kept for swap, and one waited 9 minutes on load.
|
|
952
|
-
const lightTurn = (me.mem || 0) <= LIGHT_MEM && me.res.every(r => cfg.resources[r]?.exclusive);
|
|
1045
|
+
const lightTurn = (me.mem || 0) <= LIGHT_MEM && me.res.every(r => cfg.resources[r]?.exclusive || isEnv(r));
|
|
953
1046
|
const pastCeiling = pastsCeiling(me) || quick || lightTurn;
|
|
954
1047
|
// Over the ceiling, a waiter that passes it doesn't wait behind ones the ceiling holds back.
|
|
955
1048
|
// Nor behind a place nobody is deciding for (its dibs stopped looking), or one the owner stopped:
|
|
@@ -957,9 +1050,11 @@ function decide(s, me, cfg, hist, t) {
|
|
|
957
1050
|
// src/state.mjs) every place is old, so none is taken for one nobody decides for.
|
|
958
1051
|
const ahead = s.queue
|
|
959
1052
|
.filter(q => q.pid && q.id !== me.id && !q.ownerStop && !(unpolled(q, t) && !(s.graceUntil > t)) && !(hot && pastCeiling && !pastsCeiling(q)))
|
|
960
|
-
.filter(q => { const r = rank(q, hist, t); return r < myRank || (r === myRank && q.id < me.id); })
|
|
1053
|
+
.filter(q => { const r = rank(q, hist, t, fair); return r < myRank || (r === myRank && q.id < me.id); })
|
|
961
1054
|
.filter(q => reservesFor(s, q, me, cfg))
|
|
962
|
-
|
|
1055
|
+
// Idle work waits while anyone else does: put ahead of a session over its share, it would wait for it.
|
|
1056
|
+
.filter(q => !(overMe && q.prio === 'idle' && me.prio !== 'idle'))
|
|
1057
|
+
.sort(byRank(hist, t, fair));
|
|
963
1058
|
// A waiter ahead that needs more free disk than there is can't start, so it
|
|
964
1059
|
// doesn't hold back one that leaves minDisk free after its own declared disk:
|
|
965
1060
|
// on 2026-10-15 a heavy job needing 10 GB, with 4 to 6 GB free, held the
|
|
@@ -967,9 +1062,15 @@ function decide(s, me, cfg, hist, t) {
|
|
|
967
1062
|
// it's ahead of everyone again. A job that would eat into that room waits.
|
|
968
1063
|
const floor = bytes(cfg.minDisk);
|
|
969
1064
|
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));
|
|
970
|
-
|
|
1065
|
+
// Under the floor, a job that writes next to nothing (tinyDisk) and has its own room passes them
|
|
1066
|
+
// too: on 2026-11-26 a --disk 50M test run sat 8th in line for over an hour behind suites the
|
|
1067
|
+
// floor held, though the disk had room for it.
|
|
1068
|
+
const leavesRoom = m.diskFree != null && (m.diskFree - floor >= (me.disk || 0) || me.frees
|
|
1069
|
+
|| (tinyDisk(me, hist, cfg) && m.diskFree >= diskNeed(s, me, cfg, hist).need));
|
|
971
1070
|
const blocks = q => {
|
|
972
1071
|
if (leavesRoom && diskStuck(q)) return false;
|
|
1072
|
+
// Over its share, a session doesn't fill the gaps other sessions wait on (fairShare).
|
|
1073
|
+
if (overMe && fairAhead(fair, q, me)) return true;
|
|
973
1074
|
// A waiter held for memory blocks a job of known length only when its own start is known, and comes first.
|
|
974
1075
|
if (known(me, hist) && overBudget(s, q, cfg, false, false, t, hist) && !budgetSure(s, q, cfg, hist, t)) return false;
|
|
975
1076
|
const at = soonestStart(s, q, cfg, hist, t);
|
|
@@ -998,7 +1099,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
998
1099
|
// Waiters ahead that will start before you'd finish take the open slots first; on a
|
|
999
1100
|
// per-project resource, only this project's (the cap across projects is room enough for the rest).
|
|
1000
1101
|
const before = ahead.filter(q => q.res.includes(r) && blocks(q) && (!byRepo(cfg, r) || laneOf(q) === laneOf(me)));
|
|
1001
|
-
if (before.length >= open) return { ok: false, rule: 'ahead', why: `${tag(before[0])} is ahead of you for ${r}`, on: r, ahead: before[0] };
|
|
1102
|
+
if (before.length >= open) return { ok: false, rule: 'ahead', why: `${tag(before[0])} is ahead of you for ${r}`, on: r, ahead: before[0], ...fairWhy(fair, before[0], me, overMe) };
|
|
1002
1103
|
}
|
|
1003
1104
|
// Learned clashes: a job that runs SLOW_PAIR times as slow beside one running now, or
|
|
1004
1105
|
// makes it that slow, waits for it, but no longer than its own run time since it
|
|
@@ -1015,6 +1116,8 @@ function decide(s, me, cfg, hist, t) {
|
|
|
1015
1116
|
// checking the disk again refused (exit 74) a run right after "you already have the
|
|
1016
1117
|
// simulator, so you go ahead" (2026-11-03). The watcher's low-disk pauses still hold it.
|
|
1017
1118
|
if (me.res.every(r => mine.has(r))) return { ok: true, covered: [...me.res] };
|
|
1119
|
+
// A command that only frees (freesOnly) has its turn now: the machine's limits are what it helps.
|
|
1120
|
+
if (me.frees) return { ok: true, covered: me.res.filter(r => mine.has(r)) };
|
|
1018
1121
|
// Below minDisk nothing else starts, urgent work included, but a job that writes next to
|
|
1019
1122
|
// nothing (tinyDisk): a full disk breaks every job on the machine, and on macOS swap needs it too.
|
|
1020
1123
|
const others = othersOf(s, me);
|
|
@@ -1022,7 +1125,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
1022
1125
|
const { need: needDisk, ate, others: crowded, tiny } = diskNeed(s, me, cfg, hist);
|
|
1023
1126
|
// An unreadable disk (null) doesn't stop work; the board and dibs run say it's unknown.
|
|
1024
1127
|
if (m.diskFree != null && m.diskFree < needDisk) {
|
|
1025
|
-
const floored = !tiny && needDisk === floorFor(me, cfg) && floorWhy(me, cfg);
|
|
1128
|
+
const floored = !tiny && needDisk === floorFor(me, cfg) && floorWhy(me, cfg, hist);
|
|
1026
1129
|
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
1130
|
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
1131
|
}
|
|
@@ -1037,14 +1140,15 @@ function decide(s, me, cfg, hist, t) {
|
|
|
1037
1140
|
let sw = (me.prio || 'normal') !== 'urgent' && busy && swapping(cfg, m);
|
|
1038
1141
|
let trial = false;
|
|
1039
1142
|
if (sw && sw.level !== 'critical' && !light && sw.rule === 'pressure' && probation(s, me, cfg, hist, t)) trial = true;
|
|
1040
|
-
|
|
1143
|
+
const eased = !!sw && !light && !trial && !quick && easesPast(s, me, sw, m, t);
|
|
1144
|
+
if (sw && (light || trial || quick || eased) && sw.level !== 'critical') sw = null;
|
|
1041
1145
|
// The same for the disk swap grows on: one job may still start alone, since waiting frees nothing then.
|
|
1042
1146
|
// Swap grows with memory, not with what a job writes, so a job let under the floor (tinyDisk) keeps the room past the floor.
|
|
1043
1147
|
// A light job can't grow the swap, so on a resource that writes little (exclusive, or declaring
|
|
1044
1148
|
// no disk: tests, deploys) only the floor holds it. On 2026-10-26 every start waited on the room
|
|
1045
1149
|
// kept for swap with 6.8 GB free, one-second test runs included.
|
|
1046
1150
|
const writesLittle = me.res.every(r => cfg.resources[r]?.exclusive || !resCfg(cfg, r).disk);
|
|
1047
|
-
const squeeze = !waitedOn(me) && busy && !sw && !quick && !(light && writesLittle) && diskSqueeze(cfg, tiny ? Math.max(needDisk, bytes(cfg.minDisk)) : needDisk, m);
|
|
1151
|
+
const squeeze = !waitedOn(me) && busy && !sw && !quick && !(light && writesLittle) && diskSqueeze(cfg, tiny ? Math.max(needDisk, bytes(cfg.minDisk)) : needDisk, m, { drain: !tiny });
|
|
1048
1152
|
let breaker = (sw || squeeze) && breaksStall(s, me, cfg, hist, t, m);
|
|
1049
1153
|
if (sw && !breaker) return { ok: false, why: swapWhy(sw), ...sw, machine: true };
|
|
1050
1154
|
if (squeeze && !breaker) return { ok: false, ...squeeze, machine: true };
|
|
@@ -1054,7 +1158,13 @@ function decide(s, me, cfg, hist, t) {
|
|
|
1054
1158
|
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));
|
|
1055
1159
|
if (!quick && head && t - head.enq > ms(cfg.starveAfter) && blocks(head))
|
|
1056
1160
|
return { ok: false, rule: 'ahead', why: `${tag(head)} has waited ${dur(t - head.enq)}, so it goes first`, ahead: head, starved: true };
|
|
1057
|
-
|
|
1161
|
+
// Over its share of memory, it doesn't take memory another session's waiter needs: one waiting
|
|
1162
|
+
// on memory now, or one about to start that wouldn't fit beside it.
|
|
1163
|
+
const fairHead = !quick && overMe?.pastMem && ahead.find(q => fairAhead(fair, q, me) && !neverFits(cfg, q)
|
|
1164
|
+
&& q.res.every(r => roomFor(s, q, r, cfg).open > 0)
|
|
1165
|
+
&& (overBudget(s, q, cfg, false, false, t, hist) || memUsed(s) + (me.mem || 0) + (q.mem || 0) > bytes(cfg.budget)));
|
|
1166
|
+
if (fairHead) return { ok: false, rule: 'ahead', why: `${tag(fairHead)} goes first: ${shareText(overMe, 'your session')}, more than its share`, ahead: fairHead, fair: overMe };
|
|
1167
|
+
let budget = overBudget(s, me, cfg, side.length > 0, breaker, t, hist, eased);
|
|
1058
1168
|
// Nothing starts past the memory budget (0.0.125). Jobs book what they're
|
|
1059
1169
|
// measured using once they've run a few minutes (memOf), so the gap between
|
|
1060
1170
|
// asks and use goes to waiters that way, with the machine's pressure as the guard.
|
|
@@ -1066,7 +1176,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
1066
1176
|
// 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
1177
|
if (budget && quick && me.feather) budget = null;
|
|
1068
1178
|
if (budget) return { ok: false, ...budget, ...(swapOnly && { machine: true }) };
|
|
1069
|
-
if (me.mem >= BIG_JOB && m.memFree < cfg.minFreeMem && s.leases.some(working) && !breaker)
|
|
1179
|
+
if (me.mem >= BIG_JOB && m.memFree < cfg.minFreeMem && s.leases.some(working) && !breaker && !eased)
|
|
1070
1180
|
return { ok: false, rule: 'ram', why: `machine memory: ${m.memFree}% free, big jobs need ${cfg.minFreeMem}%` };
|
|
1071
1181
|
// Stopped last time for using far more than it booked (src/preempt.mjs diskRequeue):
|
|
1072
1182
|
// it starts again only once what it's now booked at is really free and swap
|
|
@@ -1089,7 +1199,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
1089
1199
|
if ((me.prio || 'normal') === 'idle') {
|
|
1090
1200
|
if (m.memFree < IDLE_MEM_FREE) return { ok: false, rule: 'idle', why: `idle work waits for ${IDLE_MEM_FREE}% memory free (now ${m.memFree}%)` };
|
|
1091
1201
|
}
|
|
1092
|
-
return { ok: true, covered: me.res.filter(r => mine.has(r)), ...(quick && { quick: true }), ...(trial && { trial: true }), ...(side.length && { alongside: merge(side) }), ...(breaker && { breaker: true }), ...(loadPast && { loadPast: true, loadWaited: t - since }),
|
|
1202
|
+
return { ok: true, covered: me.res.filter(r => mine.has(r)), ...(quick && { quick: true }), ...(trial && { trial: true }), ...(side.length && { alongside: merge(side) }), ...(breaker && { breaker: true }), ...(eased && { eased: true }), ...(loadPast && { loadPast: true, loadWaited: t - since }),
|
|
1093
1203
|
...(!breaker && (me.prio || 'normal') !== 'urgent' && { gated: true }) };
|
|
1094
1204
|
}
|
|
1095
1205
|
|
|
@@ -1118,9 +1228,11 @@ export function forecastDetail(s, cfg, hist, t = now(), extra = null) {
|
|
|
1118
1228
|
};
|
|
1119
1229
|
const out = new Map();
|
|
1120
1230
|
const line = (extra ? [...s.queue, extra] : [...s.queue]).filter(q => q.pid || q === extra);
|
|
1121
|
-
|
|
1231
|
+
// Under a dibs halt with a time, nothing starts before it lifts.
|
|
1232
|
+
const from = Math.max(t, halted(s, t)?.until ?? t);
|
|
1233
|
+
for (const q of line.sort(byRank(hist, t, fairShare(s, cfg, t)))) {
|
|
1122
1234
|
const firsts = q.res.map(r => slotsFor(r, q)[0] ?? open());
|
|
1123
|
-
const startAt = Math.max(
|
|
1235
|
+
const startAt = Math.max(from, ...firsts.map(f => f.at));
|
|
1124
1236
|
const unsure = firsts.find(f => f.at > t && !f.sure);
|
|
1125
1237
|
const end = { at: startAt + expected(q, hist), sure: !unsure && known(q, hist), after: q };
|
|
1126
1238
|
for (const r of q.res) { const sl = slotsFor(r, q); sl.shift(); sl.push({ ...end }); sl.sort((a, b) => a.at - b.at); }
|
|
@@ -1131,3 +1243,85 @@ export function forecastDetail(s, cfg, hist, t = now(), extra = null) {
|
|
|
1131
1243
|
|
|
1132
1244
|
export const forecast = (s, cfg, hist, t = now(), extra = null) =>
|
|
1133
1245
|
new Map([...forecastDetail(s, cfg, hist, t, extra)].map(([id, f]) => [id, f.at]));
|
|
1246
|
+
|
|
1247
|
+
// Fair share between sessions. A session is a main agent with its subagents (one
|
|
1248
|
+
// Claude Code process, spid), or one dibs later job, which runs on its own. One
|
|
1249
|
+
// already running work that one more job would take past its share of a resource
|
|
1250
|
+
// another session waits for, or of the memory budget, while that session would
|
|
1251
|
+
// stay within its own: its waiters go behind that session's. It never pauses or stops anything to get there, and with
|
|
1252
|
+
// nobody else waiting it goes as before. On 2026-11-29 one session ran three
|
|
1253
|
+
// heavy solver jobs and took most of the memory, and other sessions' work and the
|
|
1254
|
+
// nightly browser checks waited behind its next ones.
|
|
1255
|
+
// Its share of a resource: the slots split evenly between the sessions holding or
|
|
1256
|
+
// waiting for it. Of memory: the budget split between the sessions holding memory
|
|
1257
|
+
// or waiting. Only configured resources count (a made-up lock costs nobody
|
|
1258
|
+
// anything), and not one kept per project (deploys), where sessions of different
|
|
1259
|
+
// projects don't share slots.
|
|
1260
|
+
// Urgent work and the quick lane aren't held back by it: urgent is seen by
|
|
1261
|
+
// everyone and said why, and a quick job is over in seconds.
|
|
1262
|
+
export const OVER_SHARE = 'over its share';
|
|
1263
|
+
// Past every other rule: quick (24h) and urgent are exempt, and high, a deadline and a hold add up to under 3h.
|
|
1264
|
+
const FAIR_SHIFT = 24 * 36e5;
|
|
1265
|
+
// src/later.mjs runs each job as `dibs run --as "later l3"` (or "<label>, later l3").
|
|
1266
|
+
const LATER_JOB = /(?:^|, )later (l\d+)$/;
|
|
1267
|
+
export const sessionOf = x => {
|
|
1268
|
+
if (x.spid) return `s${x.spid}`;
|
|
1269
|
+
const job = LATER_JOB.exec(x.label || '');
|
|
1270
|
+
return job ? `later ${job[1]}` : `w${x.who}`;
|
|
1271
|
+
};
|
|
1272
|
+
const NO_FAIR = Object.assign(() => null, { over: () => [] });
|
|
1273
|
+
export function fairShare(s, cfg, t = now()) {
|
|
1274
|
+
const waiters = s.queue.filter(q => q.pid && !q.ownerStop);
|
|
1275
|
+
// Only another session's waiter is ever put ahead of anyone.
|
|
1276
|
+
if (new Set(waiters.map(sessionOf)).size < 2) return NO_FAIR;
|
|
1277
|
+
const counted = r => !!cfg.resources[r] && !byRepo(cfg, r);
|
|
1278
|
+
const sessions = new Map();
|
|
1279
|
+
const of = k => sessions.get(k) || sessions.set(k, { key: k, name: null, slots: {}, mem: 0, waiters: [], leases: [] }).get(k);
|
|
1280
|
+
for (const l of s.leases) {
|
|
1281
|
+
const x = of(sessionOf(l));
|
|
1282
|
+
x.name ??= nameOf(l);
|
|
1283
|
+
x.leases.push(l);
|
|
1284
|
+
for (const r of l.res) if (counted(r) && !coveredNow(s, l, r) && !lent(l, r) && !onTop(l, r)) x.slots[r] = (x.slots[r] || 0) + 1;
|
|
1285
|
+
}
|
|
1286
|
+
for (const x of sessions.values()) x.mem = memUsed({ ...s, leases: x.leases }, l => memOf(l, t));
|
|
1287
|
+
for (const q of waiters) { const x = of(sessionOf(q)); x.name ??= nameOf(q); x.waiters.push(q); }
|
|
1288
|
+
const all = [...sessions.values()];
|
|
1289
|
+
const budget = bytes(cfg.budget);
|
|
1290
|
+
const memSessions = all.filter(x => x.mem > 0 || x.waiters.length).length;
|
|
1291
|
+
const sharing = r => all.filter(x => x.slots[r] || x.waiters.some(q => q.res.includes(r))).length;
|
|
1292
|
+
// Past its share by starting one more: a session running nothing never is, so a job bigger
|
|
1293
|
+
// than a share still gets its turn.
|
|
1294
|
+
const pastOn = (x, r) => (x.slots[r] || 0) > 0 && ((x.slots[r] || 0) + 1) * sharing(r) > resCfg(cfg, r).slots;
|
|
1295
|
+
const pastMem = (x, need) => x.mem > 0 && (x.mem + need) * memSessions > budget;
|
|
1296
|
+
// Someone else waits who would stay within their share: of r, or of memory (r null).
|
|
1297
|
+
const othersUnder = (x, r) => all.some(y => y !== x && y.waiters.some(q => (r ? q.res.includes(r) && !pastOn(y, r) : !pastMem(y, q.mem || 0))));
|
|
1298
|
+
const memo = new Map();
|
|
1299
|
+
const fair = q => {
|
|
1300
|
+
if (q.prio === 'urgent' || q.quickPass) return null;
|
|
1301
|
+
if (memo.has(q.id)) return memo.get(q.id);
|
|
1302
|
+
const x = sessions.get(sessionOf(q));
|
|
1303
|
+
const res = x ? q.res.filter(r => counted(r) && pastOn(x, r) && othersUnder(x, r)) : [];
|
|
1304
|
+
const mem = !!x && pastMem(x, q.mem || 0) && othersUnder(x, null);
|
|
1305
|
+
const out = res.length || mem ? share(x, res, mem) : null;
|
|
1306
|
+
memo.set(q.id, out);
|
|
1307
|
+
return out;
|
|
1308
|
+
};
|
|
1309
|
+
// The sessions at or past their share of r (or over their share of memory, r null) while others wait under theirs.
|
|
1310
|
+
fair.over = r => all.filter(x => (r ? counted(r) && pastOn(x, r) && othersUnder(x, r) : x.mem * memSessions > budget && othersUnder(x, null)))
|
|
1311
|
+
.map(x => share(x, r ? [r] : [], !r));
|
|
1312
|
+
const share = (x, res, mem) => ({ session: x.key, name: x.name, res: res.map(r => ({ r, held: x.slots[r] || 0, slots: resCfg(cfg, r).slots })),
|
|
1313
|
+
held: Object.entries(x.slots).map(([r, n]) => ({ r, held: n, slots: resCfg(cfg, r).slots })), mem: x.mem, overMem: x.mem * memSessions > budget,
|
|
1314
|
+
pastMem: mem, budget });
|
|
1315
|
+
return fair;
|
|
1316
|
+
}
|
|
1317
|
+
const nameOf = x => (LATER_JOB.test(x.label || '') ? `later ${LATER_JOB.exec(x.label)[1]}` : x.agent || x.who);
|
|
1318
|
+
// q goes before me by fair share: another session's waiter, under its share. Not idle work,
|
|
1319
|
+
// which waits while anyone else does, so waiting for it would be waiting for each other.
|
|
1320
|
+
const fairAhead = (fair, q, me) => sessionOf(q) !== sessionOf(me) && q.prio !== 'idle' && !fair(q);
|
|
1321
|
+
const fairWhy = (fair, q, me, overMe) => (overMe && fairAhead(fair, q, me) ? { fair: overMe } : {});
|
|
1322
|
+
// "session web-app has 3 of 3 heavy turns and 7.1 GB": what it holds that counts, and its memory.
|
|
1323
|
+
// Turns, not slots: the plain sentences use no word a person would have to learn (test/plain.test.mjs).
|
|
1324
|
+
export function shareText(x, who = `session ${x.name}`) {
|
|
1325
|
+
const slots = (x.res.length ? x.res : x.held).map(h => `${h.held} of ${h.slots} ${h.r} turn${h.slots === 1 ? '' : 's'}`);
|
|
1326
|
+
return `${who} has ${[...slots, `${gb(x.mem).replace(/G$/, ' GB')}${x.overMem ? ` of the ${gb(x.budget).replace(/G$/, ' GB')} budget` : ''}`].join(' and ')}`;
|
|
1327
|
+
}
|
package/src/schema.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// The documented --json layout (docs/json.md): one shape for a job wherever an
|
|
2
|
+
// agent reads one, so it never has to guess which key holds what. Every output
|
|
3
|
+
// that follows it says schema: SCHEMA. Old keys (held, waiting, res, who,
|
|
4
|
+
// purpose...) stay beside these for the readers that already use them.
|
|
5
|
+
import { short } from './files.mjs';
|
|
6
|
+
import { remaining, pausedFor, verdict } from './schedule.mjs';
|
|
7
|
+
import { waitReason } from './board.mjs';
|
|
8
|
+
import { pauseLabel } from './preempt.mjs';
|
|
9
|
+
import { described, declared } from './declare.mjs';
|
|
10
|
+
import { now, SCHEMA } from './util.mjs';
|
|
11
|
+
|
|
12
|
+
export { SCHEMA };
|
|
13
|
+
|
|
14
|
+
const words = (x, cfg) => (cfg ? described(x, cfg) : declared(x) ? x.purpose.trim() : null);
|
|
15
|
+
// Every job has every key, null when it doesn't apply, so a reader can count on each one.
|
|
16
|
+
const job = (x, cfg, state, more) => ({
|
|
17
|
+
id: x.id, state, kind: x.kind || x.type || 'run',
|
|
18
|
+
resource: (x.res || []).map(r => short(r)).join(','), resources: x.res || [],
|
|
19
|
+
agent: x.who ?? null, label: x.label || null,
|
|
20
|
+
what: words(x, cfg), declared: declared(x),
|
|
21
|
+
cmd: x.cmd ? String(x.cmd) : null, priority: x.prio || 'normal', mine: false,
|
|
22
|
+
place: null, queuedAt: null, startedAt: null, endedAt: null, waitedMs: null, ranMs: null, exitCode: null,
|
|
23
|
+
expectStartAt: null, expectEndAt: null, blockedBy: null, blocked: null, keptUntil: null, paused: null, by: null,
|
|
24
|
+
...more,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// A lease (running or paused) or a waiter, as it is now.
|
|
28
|
+
// order: the waiters by rank, for place; fc: forecast start times; mine(x): whether it's the caller's.
|
|
29
|
+
export function jobOf(x, { s, cfg, hist, t = now(), order = [], fc = null, mine = null } = {}) {
|
|
30
|
+
const own = mine ? !!mine(x) : false;
|
|
31
|
+
if (s.queue.includes(x)) {
|
|
32
|
+
const v = x.pid ? verdict(s, x, cfg, hist, t) : null;
|
|
33
|
+
return job(x, cfg, 'waiting', { mine: own, place: x.pid ? order.filter(q => q.pid).indexOf(x) + 1 || null : null, queuedAt: x.enq, waitedMs: Math.max(0, t - x.enq),
|
|
34
|
+
expectStartAt: (x.pid && fc?.get(x.id)) || null, blockedBy: v && !v.ok ? v.rule : null, blocked: v ? waitReason(v) : null,
|
|
35
|
+
// A place kept after a wait gave up (exit 75): the same command picks it up until then.
|
|
36
|
+
keptUntil: x.pid ? null : x.keepUntil || null });
|
|
37
|
+
}
|
|
38
|
+
const left = remaining(x, hist, t);
|
|
39
|
+
return job(x, cfg, x.pausedAt ? 'paused' : 'running', { mine: own, queuedAt: x.start - (x.waited || 0), startedAt: x.start, waitedMs: x.waited || 0,
|
|
40
|
+
ranMs: Math.max(0, t - x.start - pausedFor(x, t)), expectEndAt: x.kind === 'hold' ? x.expires : left == null ? null : t + left,
|
|
41
|
+
paused: x.pausedAt ? pauseLabel(x) : null, by: x.owner?.by || x.stopBy || null });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Every job on this machine now: running and paused first, then waiters in queue order.
|
|
45
|
+
export function jobsOf(s, ctx) {
|
|
46
|
+
return [...s.leases, ...ctx.order].map(x => jobOf(x, ctx));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Jobs that ended, from the event log's end events (src/events.mjs), oldest first.
|
|
50
|
+
export function doneJobs(events, since, mine = null) {
|
|
51
|
+
return events.filter(e => e.kind === 'end' && e.at >= since).map(e => job(e, null, 'done', { kind: e.type || 'run', mine: mine ? !!mine(e) : false,
|
|
52
|
+
queuedAt: e.at - e.ms - (e.waited || 0), startedAt: e.at - e.ms, endedAt: e.at, waitedMs: e.waited ?? null,
|
|
53
|
+
ranMs: Math.max(0, e.ms - (e.paused || 0)), exitCode: e.code ?? null }));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// What a run's end says as one JSON line, beside its sentence (src/commands.mjs endLine).
|
|
57
|
+
// ranMs is null when the command never started (127).
|
|
58
|
+
export function endJson(lease, code, ranMs) {
|
|
59
|
+
const t = now();
|
|
60
|
+
return { schema: SCHEMA, kind: 'end', started: ranMs != null, job: job(lease, null, 'done', { mine: true, queuedAt: lease.start - (lease.waited || 0),
|
|
61
|
+
startedAt: ranMs == null ? null : t - ranMs, endedAt: t, waitedMs: lease.waited || 0, ranMs, exitCode: code }) };
|
|
62
|
+
}
|
package/src/scratch.mjs
CHANGED
|
@@ -37,8 +37,8 @@ It shares free space with the rest of ${disk} but stops at ${quota.toUpperCase()
|
|
|
37
37
|
on its own volume instead of filling the disk every agent uses. .metadata_never_index keeps Spotlight off it.
|
|
38
38
|
|
|
39
39
|
Point jobs at it:
|
|
40
|
-
dibs run xcode-build -- xcodebuild ... -derivedDataPath ${VOLUME}/DerivedData
|
|
41
|
-
dibs run test -- env TMPDIR=${VOLUME}/tmp npm test
|
|
40
|
+
dibs run xcode-build -m "build the app" -- xcodebuild ... -derivedDataPath ${VOLUME}/DerivedData
|
|
41
|
+
dibs run test -m "run the unit tests" -- env TMPDIR=${VOLUME}/tmp npm test
|
|
42
42
|
A project's first build in a new DerivedData folder is a full rebuild.
|
|
43
43
|
|
|
44
44
|
Check it: dibs setup scratch --check Remove it: sudo diskutil apfs deleteVolume ${NAME}`);
|