@dibssoftware/dibs 0.0.179 → 0.0.181

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +31 -2
  2. package/README.md +4 -2
  3. package/bin/dibs-guard.mjs +10 -1
  4. package/bin/dibs.mjs +37 -10
  5. package/docs/benchmarks.md +1 -1
  6. package/docs/files.md +1 -1
  7. package/docs/guard.md +6 -0
  8. package/docs/questions.md +6 -2
  9. package/docs/reference.md +4 -4
  10. package/docs/relay.md +24 -9
  11. package/docs/releasing.md +4 -3
  12. package/docs/scheduling.md +4 -4
  13. package/docs/windows.md +14 -0
  14. package/package.json +1 -1
  15. package/skills/dibs/SKILL.md +6 -6
  16. package/src/acquire.mjs +93 -27
  17. package/src/agents.mjs +7 -22
  18. package/src/alerts.mjs +75 -29
  19. package/src/board.mjs +1 -2
  20. package/src/broker.mjs +26 -11
  21. package/src/commands.mjs +37 -14
  22. package/src/config.mjs +21 -4
  23. package/src/cool.mjs +105 -10
  24. package/src/diskwarn.mjs +4 -0
  25. package/src/events.mjs +10 -1
  26. package/src/files.mjs +52 -88
  27. package/src/guard.mjs +76 -30
  28. package/src/guardd.mjs +97 -0
  29. package/src/guardw.mjs +19 -0
  30. package/src/later.mjs +20 -25
  31. package/src/lock.mjs +308 -0
  32. package/src/measure.mjs +27 -7
  33. package/src/ondemand.mjs +5 -2
  34. package/src/override.mjs +39 -2
  35. package/src/plain.mjs +2 -2
  36. package/src/platform.mjs +175 -42
  37. package/src/preempt.mjs +51 -3
  38. package/src/primer.mjs +1 -1
  39. package/src/proc.mjs +45 -5
  40. package/src/questions.mjs +8 -22
  41. package/src/relay.mjs +137 -32
  42. package/src/remote.mjs +12 -8
  43. package/src/schedule.mjs +139 -26
  44. package/src/serve.mjs +16 -3
  45. package/src/service.mjs +9 -4
  46. package/src/state.mjs +139 -47
  47. package/src/stats.mjs +3 -2
  48. package/src/talk.mjs +169 -83
  49. package/src/trust.mjs +7 -1
  50. package/src/util.mjs +28 -2
  51. package/src/version.mjs +1 -1
  52. package/src/web.mjs +17 -26
  53. package/src/worker.mjs +2 -1
@@ -11,7 +11,7 @@ dibs runs on this machine. Agents take turns through it on the simulator, Xcode
11
11
  - No dibs for reads, edits, small commands, or long jobs that mostly wait on the network and use little CPU, memory or disk (crawlers, pollers, HTTP checks). The hook leaves those alone too.
12
12
  - Start `dibs listen` with run_in_background now, and again each time it exits: it wakes you when the person or dibs has something for you.
13
13
  - Waiting is normal. A call moved to the background is still waiting: don't run it again. A wait on memory, swap or disk protects the machine: keep waiting, and never lower `--mem` or raise `-p` to get past it.
14
- - Exit 75: it gave up waiting and your command never ran; run the same command again. Exit 74: not enough free disk; free your own build output, or tell the person.
14
+ - Exit 75: it gave up waiting and your command never ran; run the same command again. Exit 74: it can't fit on this disk, or its wait limit ran out; low disk just means a wait.
15
15
  - Decide what you can undo yourself. Ask the person only before something you can't undo (`dibs question ... --one-way`). Lines starting "Message from the person:" are theirs: act on them.
16
16
  - Post progress as you work: `dibs progress "what you did or found" --task <name> --eta 30m`, then `--done`.
17
17
  - The rest (holding across tool calls, file leases, other machines, every exit code, overriding jobs, questions) is below, under "When you need it", and in `dibs help`.
@@ -56,9 +56,9 @@ dibs run test -- sh -c 'npm run build && npm test' # a shell li
56
56
  - dibs on this machine was updated: it prints what changed since your last version, once
57
57
  - a newer dibs is out on dibs.cc ("dibs X is out (you have Y)"): the person upgrades it; don't upgrade it yourself. Asked at most every 6 hours per machine, never from a git checkout, off with `"updateCheck": false` in config.json.
58
58
 
59
- Exit 0 ends with "To keep listening, start dibs listen again with run_in_background." Exit 3 means nothing came within `--for` (60m by default). Either way, start it again. `--json` gives `{ messages }`, `{ updated, changes }` or `{ release }`.
59
+ Exit 0 starts with "First start dibs listen again with run_in_background": do that before anything else. It has no time limit: it waits until something comes, and when your session ends it exits quietly on its own. `--for 30m` sets a limit; then exit 3 means nothing came in that time, and you start it again. `--json` gives `{ messages }`, `{ updated, changes }` or `{ release }`.
60
60
 
61
- One listener per agent: the main agent of a session, and each subagent, separately. A newer one replaces the older, which exits 0 saying another took over. Messages that arrive while you work come with your next tool call instead; none is lost or handed over twice. If you end a turn after your listener exited, the hook keeps you going once with "re-arm: your dibs listen has ended". The board, `dibs threads` and `dibs tell` say who is listening.
61
+ One listener per agent: the main agent of a session, and each subagent, separately. A newer one replaces the older, which exits 0 saying another took over. Messages that arrive while you work come with your next tool call instead; none is lost or handed over twice. If the main agent of a session ends a turn with no listener running, the hook keeps it going to start one ("no dibs listen is running for you"), once a turn and at most 3 turns in a row without one starting. Subagents are never kept going for it. The board, `dibs threads` and `dibs tell` say who is listening.
62
62
 
63
63
  ### Holding across tool calls
64
64
 
@@ -69,7 +69,7 @@ A script running under `dibs run deploy` that calls `dibs run xcode-build` waits
69
69
  ### When dibs holds you back
70
70
 
71
71
  - **Memory, swap or disk** ("waiting for memory pressure to ease", "this machine to stop swapping", "free disk to stop falling"): dibs is protecting the machine. Keep waiting. Don't pass a smaller `--mem` or a higher `-p` to get past it. A memory wait names the jobs holding the most: if one is yours and finished, end it.
72
- - **Disk at your turn:** a resource that declares a disk need (the simulator asks 8 GB) is refused with exit 74 when that much isn't free and nothing running will free it. If your job needs less, pass `--disk 1G` on the hold and on each `dibs run`. A job whose own past runs ate more disk than is free waits for disk too, even alone. While you wait on something else, the wait message says early when disk will hold you next, so free your own build output then.
72
+ - **Disk at your turn:** low disk is a wait, like memory: your run or hold stays in line and starts the moment there's room (a person or another job frees it). dibs gives up on it (exit 74) only when it can't fit on this disk even empty of other jobs, or, outside Claude Code, its wait limit runs out. A command whose last runs (two or more) ate under 100 MB starts below the 5 GB floor (only 1 GB has to be free). Before it has runs, only `--disk` says it's small: under 100 MB anywhere, or 1 GB or less on test, deploy or a lock (an honest `--disk 200M` on a suite that writes nothing); its runs overrule it if they eat more. Under 1 GB free, dibs pauses whichever job is writing the most, yours included, and resumes it at 2 GB: free your own build output, don't end it. While you wait on something else, the wait message says early when disk will hold you next, so free your own build output then.
73
73
  - **Paused** ("paused your job: free disk is low", or for urgent work): leave it, it resumes by itself.
74
74
  - **Load** ("waiting for the machine to cool down"): ends within 20 minutes.
75
75
  - **A person is waiting on the job now:** run it with `-p high -m "why"`, or send it to another machine with `--on <machine>` (`dibs machines`). That's the only reason to raise it.
@@ -82,14 +82,14 @@ A script running under `dibs run deploy` that calls `dibs run xcode-build` waits
82
82
  |---|---|---|
83
83
  | the command's own | it ran | read it as usual |
84
84
  | 75 | gave up waiting: your command never started and didn't fail (outside Claude Code, after `--max-wait`, 8m by default), or a question got no answer | rerun the same command within 2 minutes to keep your place, or add `--wait`. On a question: nothing was decided, skip that step |
85
- | 74 | not enough free disk | the message says how much it needed. Free your own build output, or tell the person; if this run needs less, pass a smaller `--disk` on that `dibs run` (a hold's `--disk` doesn't cover the runs under it). Never delete in another session's `/private/tmp/claude-*` folder |
85
+ | 74 | this run can't fit on this disk even when it's empty of other jobs, or (outside Claude Code) its wait limit ran out. Low disk otherwise just means you wait | the message says how much it needed. Free your own build output, or tell the person; if this run needs less, pass a smaller `--disk` on that `dibs run` (a hold's `--disk` doesn't cover the runs under it). Never delete in another session's `/private/tmp/claude-*` folder |
86
86
  | 76 | lost the coordinator or the other machine before the job started | nothing ran there: send it again |
87
87
  | 77 | lost the other machine after the job started | it may have run, or still be running: check before running it again, above all a deploy |
88
88
  | 70 | dibs itself crashed | a bug in dibs, not your command: `dibs ask "..."` |
89
89
  | 127 | the command didn't start | check the command and its path |
90
90
  | 2 | bad usage: a near-miss resource name, a high or urgent boost without `-m`, a job bigger than this machine (ask for what it names, or `--anywhere`), `--on` or `dibs machines` outside a group, or a run you already have going | read the message: it names the fix |
91
91
  | 1 | nothing matched (`mine` with nothing held, `release` with nothing to give back) | usually the clean result |
92
- | 3 | `dibs listen` heard nothing within `--for` (60m by default) | start it again with run_in_background |
92
+ | 3 | `dibs listen --for <time>` heard nothing in that time (without `--for` it waits as long as your session lives) | start it again with run_in_background |
93
93
 
94
94
  ### Files other agents may edit
95
95
 
package/src/acquire.mjs CHANGED
@@ -2,27 +2,28 @@
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { spawn } from 'node:child_process';
5
+ import { fileURLToPath } from 'node:url';
5
6
  import { resCfg, machine, paths, HOME, loadConfig } from './config.mjs';
6
7
  import { identity, pstart, tag } from './proc.mjs';
7
8
  import { processes, parent, OS } from './platform.mjs';
8
- import { withState, history, KEEP_PLACE } from './state.mjs';
9
+ import { withState, peek, history, setLockDeadline, KEEP_PLACE } from './state.mjs';
9
10
  import { preempt } from './preempt.mjs';
10
11
  import { isFiles, short, shellRes, projectKey } from './files.mjs';
11
12
  import { jobSize } from './simpool.mjs';
12
13
  import { sized, grewLine, grewPlain, treeOf } from './measure.mjs';
13
14
  import { isQuota, quotaProblem, quotaBlock, takeQuota } from './quota.mjs';
14
- import { capWaiter } from './override.mjs';
15
+ import { capWaiter, inversions, lift } from './override.mjs';
15
16
  import { verdict, forecast, expected, remaining, byRank, holdingOf, PRIORITY_SHIFT, PRIORITIES, NEEDS_REASON, used, overBy, STALL, neverFits, explicitAsk, capToMachine, quickPass } from './schedule.mjs';
16
17
  import { event } from './events.mjs';
17
18
  import { startLine } from './overlap.mjs';
18
- import { dur, clock, die, say, sleep, now, ms, gb, SIGNALS, signalExit, KEY_SPLIT, noSpace, OFF_LIMITS, callerPid } from './util.mjs';
19
+ import { dur, clock, die, say, sleep, now, ms, gb, SIGNALS, signalExit, KEY_SPLIT, noSpace, OFF_LIMITS, callerPid, POLLED_EVERY, UNPOLLED, GHOST_AFTER } from './util.mjs';
19
20
  import { plainBoard, startPhrase, askFirst, named, andList, lower, ordinal, moves, stuckFor, STUCK_AFTER } from './plain.mjs';
20
21
  import { quoted, wrap, width } from './style.mjs';
21
22
  import { noticeScan } from './notices.mjs';
22
23
  import { notify } from './talk.mjs';
23
24
  import { mayShip, loadShipTarget } from './remote.mjs';
24
25
 
25
- const BIN = path.join(path.dirname(new URL(import.meta.url).pathname), '..', 'bin', 'dibs.mjs');
26
+ const BIN = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'dibs.mjs');
26
27
 
27
28
  // How long dibs run waits in line outside Claude Code, where nothing moves a
28
29
  // long call to the background and the tool may kill it.
@@ -73,14 +74,16 @@ export const defaultMaxWait = () =>
73
74
  backgroundable() ? Infinity : process.env.DIBS_MAX_WAIT ? ms(process.env.DIBS_MAX_WAIT) : DEFAULT_MAX_WAIT;
74
75
 
75
76
  // Said once, when the wait starts, so nobody has to guess what happens at the end of it.
76
- function waitTerms(w) {
77
+ function waitTerms(w, disk) {
77
78
  if (w.maxWait === Infinity)
78
79
  return !w.info.waitSet
79
80
  ? "No time limit. If this tool call times out, Claude Code moves it to the background and tells you when it ends: don't run it again, or it runs twice."
80
81
  : 'No time limit (--wait).';
81
- return `Gives up at ${clock(w.started + w.maxWait)} if it's still waiting (exit 75: your command won't have run). To wait as long as it takes, add --wait.`;
82
+ return `Gives up at ${clock(w.started + w.maxWait)} if it's still waiting (exit ${disk ? 74 : 75}: your command won't have run). To wait as long as it takes, add --wait.`;
82
83
  }
83
84
 
85
+ const GB = x => gb(x).replace(/G$/, ' GB');
86
+
84
87
  // The command as the agent typed it, to paste back.
85
88
  const again = () => `dibs ${quoted(process.argv.slice(2))}`;
86
89
 
@@ -89,6 +92,12 @@ const again = () => `dibs ${quoted(process.argv.slice(2))}`;
89
92
  // Every process group the run spans counts: a test runner's workers split off
90
93
  // into groups of their own, and a run whose own group sleeps while they work isn't idle.
91
94
  // A simulator the run is using counts too (src/measure.mjs treeOf): its work runs there.
95
+ // The process table markIdle reads, read before taking the lock when a run may need it:
96
+ // at load 30, ps -A took 0.6 to 4 s, and under the lock every other dibs waited that long too.
97
+ export function tableFirst() {
98
+ if (peek().leases.some(l => l.kind === 'run' && l.pgid && !l.pausedAt)) processes();
99
+ }
100
+
92
101
  export function markIdle(s, procs) {
93
102
  const runs = s.leases.filter(l => l.kind === 'run' && l.pgid && !l.pausedAt); // a paused job is quiet on purpose
94
103
  if (!runs.length) return;
@@ -238,11 +247,13 @@ const left = (w, why) => { if (w.blocked) note(w, 'left', { ms: now() - w.me.enq
238
247
  // state read drops it once this process is gone.
239
248
  function leave(w, keep) {
240
249
  try {
241
- withState(s => {
250
+ // A low job lifted for this waiter alone goes back down as it leaves (src/override.mjs inversions).
251
+ lift(withState(s => {
242
252
  const q = s.queue.find(x => x.id === w.me.id);
243
253
  if (keep && q) Object.assign(q, { pid: null, keepUntil: now() + KEEP_PLACE });
244
254
  else s.queue = s.queue.filter(x => x.id !== w.me.id);
245
- });
255
+ return inversions(s, w.cfg);
256
+ }));
246
257
  } catch (e) { if (!noSpace(e)) throw e; }
247
258
  }
248
259
 
@@ -288,7 +299,7 @@ async function saved(w, fn) {
288
299
  // Its size again from what its command has used, as dibs learns now: on
289
300
  // 2026-10-20 nine browser runs sized when one run had read 15 GB still waited,
290
301
  // two hours on, for the whole budget the new rule no longer planned.
291
- const POLLED_EVERY = 60e3;
302
+ export { UNPOLLED }; // src/board.mjs reads it from here
292
303
  function resize(cur, w) {
293
304
  if (cur.sent) return;
294
305
  const base = { mem: cur.asked ?? cur.mem, cpu: cur.cpu, disk: cur.disk };
@@ -298,9 +309,37 @@ function resize(cur, w) {
298
309
  if (n.usual != null) cur.usual = n.usual; else delete cur.usual;
299
310
  Object.assign(w.info.size, { mem: n.mem, usual: n.usual });
300
311
  }
312
+ // Adds the time since the rule last changed to the rule that held it then, and
313
+ // notes the new one. Kept on the queue entry, not in the waiter's memory: #17303
314
+ // waited 10h22m on 2026-11-01 and its start event named 64 minutes of it, since
315
+ // each of four new brokers began the count again. Written only when the rule
316
+ // changes, so a poll that changes nothing still leaves the state file alone. A
317
+ // stretch nobody decided for it (no broker, a waiter stopped) is 'unpolled',
318
+ // from the last time its dibs looked, so every second it waited has a name.
319
+ function heldFor(cur, rule, looked) {
320
+ const t = now(), held = { ...cur.held };
321
+ let from = cur.heldAt ?? cur.enq;
322
+ const add = (k, ms) => { if (k && ms > 0) held[k] = (held[k] || 0) + ms; };
323
+ const gap = looked != null && t - looked > UNPOLLED;
324
+ if (gap) { add(cur.heldRule ?? rule, looked - from); add('unpolled', t - Math.max(looked, from)); from = t; }
325
+ if (!gap && rule === cur.heldRule && cur.heldAt != null) return;
326
+ add(cur.heldRule ?? rule, t - from);
327
+ if (Object.keys(held).length) cur.held = held;
328
+ if (rule) cur.heldRule = rule; else delete cur.heldRule;
329
+ cur.heldAt = t;
330
+ }
301
331
  export function decide(s, w) {
332
+ const r = judge(s, w);
333
+ const moves = inversions(s, w.cfg);
334
+ if (moves.length) r.lift = moves;
335
+ return r;
336
+ }
337
+ function judge(s, w) {
302
338
  const { me, cfg, hist, info } = w;
303
- const cur = s.queue.find(x => x.id === me.id) || me;
339
+ const cur = s.queue.find(x => x.id === me.id);
340
+ // No place, no turn: one taken out of line (stopped, or left unlooked-at, src/state.mjs reap)
341
+ // stays out. Running on from this copy of it, a waiter would start with nobody's place.
342
+ if (!cur) { const x = s.stopped?.[me.id]; return x ? { stopped: true, by: x.by, reason: x.reason } : { gone: true }; }
304
343
  if (cur.ownerStop) { s.queue = s.queue.filter(x => x.id !== me.id); return { stopped: true, by: cur.stopBy, reason: cur.stopReason }; }
305
344
  // Kept current here, so it lapses when the hold ages out or ends.
306
345
  const holding = holdingOf(s, cur, cfg);
@@ -308,6 +347,7 @@ export function decide(s, w) {
308
347
  resize(cur, w);
309
348
  // When its dibs last looked, so the board can tell a waiter that could start from one nobody
310
349
  // is deciding for. Once a minute at most: a poll that changes nothing leaves the state file alone.
350
+ const looked = cur.polledAt;
311
351
  if (!(now() - (cur.polledAt || 0) < POLLED_EVERY)) cur.polledAt = now();
312
352
  // Kept on the entry, so other waiters rank it at the front too (src/schedule.mjs quickPass).
313
353
  if (quickPass(cur, hist, cfg)) cur.quickPass = true; else delete cur.quickPass;
@@ -316,12 +356,8 @@ export function decide(s, w) {
316
356
  if (!v.ok && v.rule === 'slot' && !cur.quickPass) v = quotaBlock(s, cur, cfg, hist) || preempt(s, cur, cfg, hist) || v;
317
357
  if (v.ok) v = quotaBlock(s, cur, cfg, hist) || v;
318
358
  // What held it and for how long, for its start event: on 2026-10-24 a 2-second test waited
319
- // 3 minutes with 11 GB of disk free, and the log said only that it waited. Kept in the
320
- // waiter's memory, so a poll that changes nothing still leaves the state file alone.
321
- const t = now();
322
- if (w.heldRule) w.heldBy = { ...w.heldBy, [w.heldRule]: (w.heldBy?.[w.heldRule] || 0) + t - w.heldAt };
323
- w.heldRule = v.ok ? null : v.rule || 'other';
324
- w.heldAt = t;
359
+ // 3 minutes with 11 GB of disk free, and the log said only that it waited.
360
+ heldFor(cur, v.ok ? null : v.rule || 'other', looked);
325
361
  // For the stall breaker (schedule.mjs): whether the machine, not the line, holds this one back.
326
362
  if (!v.ok && v.machine) cur.machineHeld = true; else delete cur.machineHeld;
327
363
  // When the load ceiling alone started holding it: after LOAD_STARVE it starts anyway (schedule.mjs).
@@ -347,7 +383,7 @@ export function decide(s, w) {
347
383
  // Sitting on one resource while waiting for another wastes it for everyone.
348
384
  // A file lease doesn't count: it keeps edits off files while you work, and a job waiting for a test slot doesn't change that.
349
385
  const sitting = s.leases.filter(l => l.kind === 'hold' && me.spid && l.pid === me.spid && !l.res.some(x => me.res.includes(x)) && !l.res.every(isFiles));
350
- return { v, line: waitLine(s, cur, v, cfg, hist, w.talk.told), idle: !s.leases.length, sitting, holding: cur.holding };
386
+ return { v, line: waitLine(s, cur, v, cfg, hist, w.talk.told), sitting, holding: cur.holding };
351
387
  }
352
388
  s.queue = s.queue.filter(x => x.id !== me.id);
353
389
  takeQuota(s, cur, cfg);
@@ -355,7 +391,7 @@ export function decide(s, w) {
355
391
  purpose: cur.purpose, cmd: me.cmd, key: me.key, est: info.est, prio: cur.prio, by: cur.by,
356
392
  cwd: info.cwd, ppid: info.ppid, start: now(), waited: now() - cur.enq, agentId: info.agentId, sessionId: info.sessionId,
357
393
  owner: cur.owner, askedPrio: cur.askedPrio };
358
- if (w.heldBy) lease.held = Object.fromEntries(Object.entries(w.heldBy).map(([k, x]) => [k, Math.round(x)]));
394
+ if (cur.held) lease.held = Object.fromEntries(Object.entries(cur.held).map(([k, x]) => [k, Math.round(x)]));
359
395
  if (v.covered.length) lease.covered = v.covered;
360
396
  if (v.alongside) lease.alongside = v.alongside;
361
397
  if (v.trial) lease.trial = true;
@@ -381,11 +417,20 @@ export function decide(s, w) {
381
417
  // through w.out (exit 74, 75, or the owner's stop).
382
418
  export function step(r, w) {
383
419
  const { me, cfg, out } = w;
420
+ if (r.lift) {
421
+ lift(r.lift);
422
+ for (const m of r.lift) if (!m.bg && m.for === me.id) out.say(`lifted #${m.id} (${m.who}'s low-priority job on ${m.res.join(',')}) off background priority, so you aren't stuck behind it while the machine is busy. It goes back down once nobody waits on it.`);
423
+ }
384
424
  if (r.stopped) {
385
425
  left(w, 'owner stop');
386
426
  return out.die(`stopped by ${r.by || 'the owner (the person at this machine)'} on purpose (dibs stop)${r.reason ? `: "${r.reason}"` : ''}. This was taken out of line and your command did not run.`
387
427
  + `${r.reason ? '' : ' Find out why before trying again: dibs history, or ask whoever stopped it.'}`, signalExit('SIGTERM'));
388
428
  }
429
+ if (r.gone) {
430
+ left(w, 'place gone');
431
+ return out.die(`#${me.id} is no longer in line: it was taken out, or nothing had looked at it for ${dur(GHOST_AFTER)}.`
432
+ + ` Your command did NOT run (exit 75). Run it again to get back in line:\n ${w.info.again}`, 75);
433
+ }
389
434
  if (r.never) {
390
435
  left(w, 'never fits');
391
436
  const text = neverText(r.never, me, cfg, null);
@@ -416,16 +461,25 @@ export function step(r, w) {
416
461
  out.say(`you're keeping ${andList(kept.map(x => named(cfg, x).the))} reserved while you wait, so nobody else can use it.`
417
462
  + ` Give it back (dibs release ${kept[0]}) or ask for everything at once: dibs run ${[...new Set([...kept, ...me.res])].join(',')} -- <command>`);
418
463
  }
419
- // Waiting can't free disk when nothing else is running.
420
- if (r.v.disk && (r.idle || r.v.alone)) {
421
- left(w, 'not enough disk');
464
+ // Low disk is waited out, like memory: a person or a job ending frees space, and the run
465
+ // starts the moment there's room, checked again at every poll. Until 0.0.179 a run with
466
+ // nothing else running was refused at once (exit 74): on 2026-11-02 a TestFlight ship
467
+ // waited 10 hours, then its inner dibs hold sim was refused with 6.7 GB free, and a
468
+ // scheduled job died the same way. Only a run that needs more than the whole disk is.
469
+ const total = r.v.disk && machine().diskTotal;
470
+ if (total && r.v.need > total) {
471
+ left(w, 'never fits the disk');
422
472
  leave(w, false);
423
- return out.die(`not enough free disk: ${gb(r.v.free).replace(/G$/, ' GB')} free, it needs ${gb(r.v.need).replace(/G$/, ' GB')}, and nothing running will free any.`
424
- + ` Your command did NOT run (exit 74). Free some space, or pass --disk with what this job really needs if that's less, then run it again:\n ${w.info.again}\n ${OFF_LIMITS}`, 74);
473
+ return out.die(`not enough disk, ever: it needs ${GB(r.v.need)} free and the whole disk is ${GB(total)}.`
474
+ + ` Your command did NOT run (exit 74). If this run needs less, pass --disk with what it really needs:\n ${w.info.again}`, 74);
425
475
  }
426
476
  if (now() - w.started >= w.maxWait) {
427
477
  note(w, 'timeout', { ms: now() - me.enq });
428
478
  leave(w, w.maxWait > 0);
479
+ // Outside Claude Code the wait has a limit; ended by the disk, it says so (exit 74).
480
+ if (r.v.disk)
481
+ return out.die(`${w.maxWait ? `gave up after ${dur(now() - w.started)} in the queue: ` : ''}not enough free disk: ${GB(r.v.free)} free, it needs ${GB(r.v.need)}${r.v.floorWhy ? `: ${r.v.floorWhy}` : ''}.`
482
+ + ` Your command did NOT run (exit 74). Free some space${r.v.floorWhy ? '' : ", or pass --disk with what this job really needs if that's less"}, then run it again${w.maxWait ? `, or add --wait to wait until there's room` : ''}:\n ${w.info.again}\n ${OFF_LIMITS}`, 74);
429
483
  if (!w.maxWait)
430
484
  return out.die(`not free yet. ${r.line.why} --no-wait doesn't wait, so your command did NOT run (exit 75).`
431
485
  + ` See when it frees up: dibs when ${shellRes(me.res.map(x => short(x)))}`, 75);
@@ -457,7 +511,7 @@ export function step(r, w) {
457
511
  // every MOVE_EVERY), or now and then.
458
512
  const l = r.line;
459
513
  const what = w.talk.step(l);
460
- if (what === 'full') out.said(`queued for ${andList(me.res.map(x => named(cfg, x).the))}.${me.kind === 'hold' ? ' dibs hold waits for its turn like dibs run, then returns.' : ''}`, l.head, l.why, l.ask, w.maxWait > 0 ? waitTerms(w) : '');
514
+ if (what === 'full') out.said(`queued for ${andList(me.res.map(x => named(cfg, x).the))}.${me.kind === 'hold' ? ' dibs hold waits for its turn like dibs run, then returns.' : ''}`, l.head, l.why, l.ask, w.maxWait > 0 ? waitTerms(w, r.v.disk) : '');
461
515
  else if (what === 'change') out.said(`still queued (${dur(now() - w.started)}). ${l.head}`, l.why);
462
516
  else if (what === 'moved') out.say(`still queued (${dur(now() - w.started)}). You ${l.moved}`);
463
517
  else if (what === 'repeat') out.say(`still queued (${dur(now() - w.started)}). ${l.head}`);
@@ -611,6 +665,7 @@ export async function acquire(o, kind, cfg) {
611
665
  if (machine().diskFree == null) say("couldn't read free disk space, so the disk check is off for this request.");
612
666
 
613
667
  const started = now();
668
+ if (maxWait !== Infinity) setLockDeadline(started + maxWait);
614
669
  const w = waiter({ started, maxWait, waitSet: o.maxWait != null, for: o.for, est: o.est, agentId: o.agentId, sessionId: process.env.CLAUDE_CODE_SESSION_ID,
615
670
  cwd: process.cwd(), ppid: callerPid(), sstart: id.sstart, size: { mem, cpu, asked, askedCpu, usual }, again: again(), path: o.thin?.fifo,
616
671
  notify: o.notify ? path.resolve(o.notify) : undefined, follow: process.env.DIBS_REMOTE_JOB ? { pid: callerPid(), pstart: pstart(callerPid()) } : undefined }, cfg, hist, stderrOut);
@@ -621,9 +676,16 @@ export async function acquire(o, kind, cfg) {
621
676
  const hold = sig => { early ||= sig; if (w.full) process.exit(signalExit(sig)); };
622
677
  for (const sig of SIGNALS) process.on(sig, hold);
623
678
  w.me = await saved(w, s => {
624
- // Only a place someone left behind can be picked up again, never a live waiter's.
625
- let q = s.queue.find(x => x.ticket === ticket && !x.pid);
626
- if (q) { Object.assign(q, { pid, pstart: myStart, keepUntil: null }); delete q.wake; delete q.keptFor; }
679
+ // Its own place first: this process, by pid and start time, getting in line again (a thin waiter's
680
+ // shell become Node keeps both). Then one kept for it, then one a timed-out wait left for this command.
681
+ // Never a live waiter's place, nor one kept for another process: on 2026-11-04 pid 97301 had #19783
682
+ // and #19784 for one command, and #19783, which nothing decided for any more, held heavy for 21 h.
683
+ const me = x => myStart && x.pid === pid && x.pstart === myStart;
684
+ let q = s.queue.find(x => x.ticket === ticket && me(x))
685
+ || s.queue.find(x => x.ticket === ticket && !x.pid && x.keptFor === pid)
686
+ || s.queue.find(x => x.ticket === ticket && !x.pid && !x.keptFor);
687
+ // Stamped as looked-at now: a place picked up is decided for again from here on.
688
+ if (q) { Object.assign(q, { pid, pstart: myStart, keepUntil: null, polledAt: now() }); delete q.wake; delete q.keptFor; }
627
689
  else {
628
690
  q = { id: ++s.seq, ticket, res, mem, cpu, disk, asked, askedCpu, usual, pid, pstart: myStart, enq: now(), polledAt: now(),
629
691
  who: id.who, agent: id.agent, label: id.label, spid: id.spid, purpose: o.purpose || '', cmd, key, kind,
@@ -635,6 +697,8 @@ export async function acquire(o, kind, cfg) {
635
697
  if (sent) q.sent = true; // placed here by the coordinator for its size (neverFits)
636
698
  s.queue.push(q);
637
699
  }
700
+ // A process waits for one thing: any other place under it was left behind, and only holds others back.
701
+ s.queue = s.queue.filter(x => x === q || !(me(x) || (!x.pid && x.keptFor === pid)));
638
702
  // Without -m, a wait for the rest of what a ship needs says what the ship is for.
639
703
  if (!q.purpose) q.purpose = holdingOf(s, q, cfg)?.purpose || '';
640
704
  if (o.prio && !q.owner) q.prio = o.prio; // a place picked up again keeps the owner's word on it
@@ -673,6 +737,7 @@ export async function acquire(o, kind, cfg) {
673
737
  processes(); // read the process table before taking the lock, not while holding it
674
738
  noticeScan(); // a waiter is who notices a job ahead of it is stuck: tell that job's agent (src/notices.mjs)
675
739
  }
740
+ machine(); // and the machine's readings, which decide() needs: a fresh one is up to 3 spawns
676
741
  // A budget changed while this waits counts, as it does for the broker's waiters.
677
742
  const at = configAt();
678
743
  if (at !== cfgAt) { cfgAt = at; w.cfg = freshConfig() || w.cfg; }
@@ -686,6 +751,7 @@ export async function acquire(o, kind, cfg) {
686
751
  const to = await loadShipTarget(me, cfg, w.info.cwd, { temp: MEMORY_HELD.has(x.ship) });
687
752
  if (to) return shipTo(w, to, bail, x.ship);
688
753
  } else if (x) {
754
+ setLockDeadline(null); // it runs now: its changes to the state wait as long as they must
689
755
  for (const sig of SIGNALS) process.removeListener(sig, bail);
690
756
  if (o.thin) o.thin.go(x.lease);
691
757
  return x.lease;
package/src/agents.mjs CHANGED
@@ -13,7 +13,8 @@ import fs from 'node:fs';
13
13
  import path from 'node:path';
14
14
  import { HOME } from './config.mjs';
15
15
  import { identity, makeAlive } from './proc.mjs';
16
- import { now, sleepSync, fakeFull } from './util.mjs';
16
+ import { underLock, commit } from './lock.mjs';
17
+ import { now, fakeFull } from './util.mjs';
17
18
 
18
19
  const FILE = path.join(HOME, 'agents.json');
19
20
  const LOCK = path.join(HOME, 'agents.lock');
@@ -30,8 +31,6 @@ const PENDING_FOR = 2 * 6e4;
30
31
  const QUIET_FOR = 60 * 6e4;
31
32
  // The hook gives up on the lock after this and lets the spawn through.
32
33
  const LOCK_WAIT = 1000;
33
- // A lock this old belongs to a hook that died holding it.
34
- const LOCK_STALE = 5000;
35
34
 
36
35
  // The Agent tool was called Task in older Claude Code.
37
36
  const SPAWN_TOOLS = new Set(['Agent', 'Task']);
@@ -40,31 +39,17 @@ const SPAWN_TOOLS = new Set(['Agent', 'Task']);
40
39
  export const agentSlots = cfg => (Number(cfg?.agents?.slots) > 0 ? Number(cfg.agents.slots) : null);
41
40
 
42
41
  function locked(fn) {
43
- fs.mkdirSync(HOME, { recursive: true });
44
- const t0 = now();
45
- for (;;) {
46
- try { fs.mkdirSync(LOCK); break; } catch (e) {
47
- if (e.code !== 'EEXIST') throw e;
48
- try { if (now() - fs.statSync(LOCK).mtimeMs > LOCK_STALE) fs.rmSync(LOCK, { recursive: true, force: true }); } catch {}
49
- if (now() - t0 > LOCK_WAIT) throw new Error(`${LOCK} stayed locked for ${LOCK_WAIT} ms`);
50
- sleepSync(5 + Math.random() * 10);
51
- }
52
- }
53
- try {
42
+ const r = underLock(LOCK, h => {
54
43
  let list = [];
55
44
  try { list = JSON.parse(fs.readFileSync(FILE, 'utf8')).agents || []; } catch (e) { if (e.code !== 'ENOENT' && !(e instanceof SyntaxError)) throw e; }
56
45
  const before = JSON.stringify(list);
57
46
  list = reap(list);
58
47
  const out = fn(list);
59
- if (JSON.stringify(list) !== before) {
60
- fakeFull('state');
61
- fs.writeFileSync(`${FILE}.tmp`, JSON.stringify({ agents: list }, null, 1));
62
- fs.renameSync(`${FILE}.tmp`, FILE);
63
- }
48
+ if (JSON.stringify(list) !== before) commit(h, FILE, JSON.stringify({ agents: list }, null, 1), { fake: () => fakeFull('state') });
64
49
  return out;
65
- } finally {
66
- fs.rmSync(LOCK, { recursive: true, force: true });
67
- }
50
+ }, { wait: LOCK_WAIT, files: [FILE] });
51
+ if (!r) throw new Error(`${LOCK} stayed locked for ${LOCK_WAIT} ms`);
52
+ return r.out;
68
53
  }
69
54
 
70
55
  // Drop kept slots nobody took, subagents of a session that has exited, and