@nodii/dev 0.6.210 → 0.6.212
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/README.md +51 -16
- package/dist/cli.js +55 -28
- package/dist/coordinator-watch.js +21 -17
- package/dist/core.js +1 -1
- package/dist/design.js +5 -2
- package/dist/figma.js +90 -4
- package/dist/flags.js +5 -3
- package/dist/floor.env +15 -0
- package/dist/harness.js +5 -1
- package/dist/heavy-slot.sh +138 -143
- package/dist/heavy.js +140 -5
- package/dist/lanes.js +51 -33
- package/dist/machine-floor.js +526 -0
- package/dist/review.js +4 -3
- package/dist/rulings.js +8 -9
- package/dist/safety.js +6 -2
- package/dist/session-kind.js +1 -1
- package/dist/starting.js +12 -0
- package/dist/watchdog.js +21 -16
- package/package.json +1 -1
package/dist/floor.env
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The machine's floor (DEV-PROCESS-2), shipped with @nodii/dev. Installed by the machine owner, with their password:
|
|
2
|
+
# sudo install -d -o root -g wheel -m 755 /etc/nodii
|
|
3
|
+
# sudo install -o root -g wheel -m 644 "$(npm root -g)/@nodii/dev/dist/floor.env" /etc/nodii/floor.env
|
|
4
|
+
# heavy-slot.sh and every lane launch, resume and keepalive read it only while root owns it and /etc/nodii and
|
|
5
|
+
# neither is group- or world-writable; else the same shipped defaults hold (machine-floor.js DEFAULTS).
|
|
6
|
+
MIN_AVAIL_GB=10 # available memory, after running jobs' reserved peaks, for a heavy check, launch or resume
|
|
7
|
+
LIGHT_MIN_AVAIL_GB=5 # the same for a light check (typecheck, lint, unit tests, a push)
|
|
8
|
+
MAX_SWAP_GB=24 # swap used, at most
|
|
9
|
+
MIN_DISK_GB=15 # disk free on /, at least
|
|
10
|
+
HEAVY_PEAK_GB=7 # what a running heavy job holds back, less what it uses
|
|
11
|
+
LIGHT_PEAK_GB=1 # what a running light job holds back, less what it uses
|
|
12
|
+
HEAVY_SLOTS=3 # heavy jobs at once, machine-wide
|
|
13
|
+
LANDING_RESERVE=1 # of them, slots only a push may use
|
|
14
|
+
LIGHT_SLOTS=8 # light jobs at once (everything but end-to-end, real-stack and browser work)
|
|
15
|
+
STAGGER_SEC=10 # gap between two admissions while another job runs
|
package/dist/harness.js
CHANGED
|
@@ -11,7 +11,7 @@ import { fileURLToPath } from "node:url";
|
|
|
11
11
|
import { promisify } from "node:util";
|
|
12
12
|
import { CliError, devRequest, query } from "./core.js";
|
|
13
13
|
import { classifyClaudeManaged, claudeManagedSettingsPath, managedClaudeHookBundle, managedHookBundle, nodiiCommandArgs, refreshManagedDispatchers, writeManagedClaudeHookBundle, writeManagedHookBundle } from "./managed-hooks.js";
|
|
14
|
-
import { heartbeatSettingsSnippet } from "./hooks.js";
|
|
14
|
+
import { heartbeatSettingsSnippet, settingsSnippet } from "./hooks.js";
|
|
15
15
|
import { nudgeSettingsSnippet } from "./nudges.js";
|
|
16
16
|
import { toolingDocsSettingsSnippet } from "./tooling-docs.js";
|
|
17
17
|
import { codexSafetyHooksSnippet, regroundingHooksSnippet, safetySettingsSnippet } from "./safety.js";
|
|
@@ -202,6 +202,10 @@ export function withSafetyHooks(harness) {
|
|
|
202
202
|
let hooks = addHookEntries(parsed.hooks, safetySettingsSnippet().hooks);
|
|
203
203
|
hooks = addHookEntries(hooks, regroundingHooksSnippet().hooks);
|
|
204
204
|
hooks = addHookEntries(hooks, heartbeatSettingsSnippet().hooks);
|
|
205
|
+
// Dev's generated settings may predate write logging. Keep the executable
|
|
206
|
+
// Figma post hook in every installed harness so lane writes reach their
|
|
207
|
+
// change set even while the methodology payload catches up.
|
|
208
|
+
hooks = addHookEntries(hooks, { PostToolUse: settingsSnippet().hooks.PostToolUse });
|
|
205
209
|
hooks = addHookEntries(hooks, nudgeSettingsSnippet().hooks);
|
|
206
210
|
hooks = addHookEntries(hooks, toolingDocsSettingsSnippet().hooks);
|
|
207
211
|
assertNodiiHooks(hooks, ".claude/settings.json");
|
package/dist/heavy-slot.sh
CHANGED
|
@@ -1,96 +1,90 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# heavy-slot (
|
|
2
|
+
# heavy-slot (v29, shipped with @nodii/dev): run a memory-heavy job (typecheck, build, full or affected test suite,
|
|
3
3
|
# a gate, `git push` and its pre-push hooks, an image build, a detached stack start) only when a machine-wide slot
|
|
4
|
-
# is free AND
|
|
4
|
+
# is free AND the machine clears its floor. Every session and lane on this machine shares one queue (MW2-51, K02-4).
|
|
5
5
|
#
|
|
6
|
-
# nodii-dev heavy run [--size light|heavy] -- <command...>
|
|
6
|
+
# nodii-dev heavy run [--size light|heavy] [--tighten READING=GB] -- <command...>
|
|
7
7
|
# wait for a slot of that size, run the command, release the slot when it exits
|
|
8
|
-
# nodii-dev heavy status the
|
|
8
|
+
# nodii-dev heavy status the floor file, the readings beside the floor, the classes, the ceilings,
|
|
9
|
+
# the slots held, the queue and the last hour's admissions
|
|
9
10
|
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
11
|
+
# v29 (DEV-PROCESS-2, "the machine cannot be overcommitted"): one floor, read before a job queues and again when a slot
|
|
12
|
+
# is free (machine-floor.js). Available memory after running jobs' reservations (each holds back its class's peak,
|
|
13
|
+
# 7 GB heavy or 1 GB light, less what it uses), swap used and disk free must clear it (10 GB available, 5 GB for a
|
|
14
|
+
# light job; 24 GB swap at most; 15 GB disk). Under it a job is refused at once with MACHINE_UNDER_FLOOR (exit 75),
|
|
15
|
+
# naming the reading, the figure and the five largest holders of memory: never queued, never let through (no lone-job
|
|
16
|
+
# and no landing exception; a push is refused too). The floor, the peaks, the ceilings (3 heavy slots, one only for
|
|
17
|
+
# pushes; 8 light) and the 10 s stagger live in root-owned /etc/nodii/floor.env, else the shipped defaults; no
|
|
18
|
+
# variable or user-writable file changes them. `--tighten memory=GB|swap=GB|disk=GB` makes one call stricter (a
|
|
19
|
+
# figure that would loosen the floor exits 2). Every decision is logged and `heavy status` lists the last hour.
|
|
20
|
+
# Nesting is proven by the process tree: a heavy-slot under a slot's holder runs in that slot.
|
|
21
|
+
#
|
|
22
|
+
# v27 (13 Nov, hub-401), v29: slots are sized to the job. Only end-to-end, real-stack and browser-flow work is heavy;
|
|
23
|
+
# everything else (typecheck, lint, unit tests, a push) takes a light slot: many run in parallel, under the light
|
|
24
|
+
# floor and with no stagger. Light slots are lock dirs under $D/light/<n> with their own queue $D/lq.
|
|
15
25
|
#
|
|
16
26
|
# [TOOL GAP hub-86] MW5-19 places this helper as the `heavy-slot` util (MW5-26: the first util to publish).
|
|
17
27
|
# Until the util pipeline (`nodii-dev util run`, ~/.nodii/utils) exists, @nodii/dev ships it and its hooks enforce it
|
|
18
|
-
# (hub-377). It
|
|
19
|
-
# the same lock directory, so a v23 copy still running elsewhere counts against the same slots.
|
|
28
|
+
# (hub-377). It uses the lock directory every older copy uses, so they count against the same slots.
|
|
20
29
|
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
# HEAVY_MIN_AVAIL_GB=16 admit only when available memory (RAM - app - wired - compressed, as Activity Monitor) >= this.
|
|
25
|
-
# `memory_pressure`'s "free percentage" is NOT used: it read 84% while far less was available.
|
|
26
|
-
# HEAVY_STAGGER_SEC=60 minimum gap between two admissions, so a job's memory growth shows before the next one starts
|
|
27
|
-
# HEAVY_LANDING_RESERVE=1 slots only a landing (`git push`, or anything under HEAVY_LANDING=1) may use
|
|
28
|
-
# HEAVY_RECLAIM_MIN=10 reclaim a slot held at least this long whose lane is down and whose agent is gone (0: never)
|
|
29
|
-
# LIGHT_SLOTS= concurrent light jobs machine-wide (v27); they do not count against HEAVY_SLOTS. Unset or
|
|
30
|
-
# 0: no light pool, every job takes a heavy slot. Only the machine's measured limits set it (K02-4).
|
|
31
|
-
# LIGHT_MIN_AVAIL_GB= admit a light job only when available memory >= this (v27); unset: HEAVY_MIN_AVAIL_GB
|
|
32
|
-
# LIGHT_MAX_TEST_FILES=20 a test run naming at most this many test files is light without --size (v27)
|
|
33
|
-
# Environment: NODII_RESOURCE_LIMITS (the limits file), HEAVY_SLOT_DIR (the lock directory), HEAVY_SLOT_POLL_SEC (10),
|
|
34
|
-
# HEAVY_LANE_PROBE (a command printing `up|down|unknown <why>` for a lane key; default `nodii-dev heavy lane-state`),
|
|
35
|
-
# HEAVY_RECLAIM_POLL_SEC (60: how often a holder checks whether its own slot is an orphan).
|
|
30
|
+
# Environment: HEAVY_SLOT_POLL_SEC (10), HEAVY_SIZE (light|heavy, as --size), HEAVY_LANE_PROBE (a command printing
|
|
31
|
+
# `up|down|unknown <why>` for a lane key; default `nodii-dev heavy lane-state`), HEAVY_RECLAIM_POLL_SEC (60: how often
|
|
32
|
+
# a holder checks whether its own slot is an orphan). None of them moves the floor, the file or the slot directory.
|
|
36
33
|
#
|
|
37
34
|
# Locks are mkdir dirs under /tmp/nodii-heavy-slots/<n> holding the owner pid; stale locks (dead pid) are reclaimed.
|
|
38
35
|
# v26 (NODII-DEV-CLI-86): a slot also records when it was granted (since), the lane (lane), the agent session that
|
|
39
|
-
# asked (session, session-start), the job's worktree (worktree)
|
|
40
|
-
#
|
|
36
|
+
# asked (session, session-start), the job's worktree (worktree), the job's process group (job) and, from v29, its
|
|
37
|
+
# class (size). A slot held 10 min whose lane is down and whose agent is gone is reclaimed; reclaims are logged to
|
|
38
|
+
# <lock dir>/reclaim.log.
|
|
41
39
|
# The whole body is one function, called on the last line: bash then parses the entire file before running any of it,
|
|
42
40
|
# so overwriting this file while copies are running cannot splice old and new code (15 Oct: an in-place cp of v6
|
|
43
41
|
# over a running v5 produced 'others: unbound variable'). Runs on the bash macOS ships (3.2) (MW5-22).
|
|
44
42
|
main() {
|
|
45
43
|
set -u
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
# v28: the floor's readings and the admission log live in machine-floor.js beside this file (one copy, shared with the
|
|
45
|
+
# Node CLI). It is found from this file's own path, never from the environment.
|
|
46
|
+
FLOOR_JS="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)/machine-floor.js"
|
|
47
|
+
# The runtime that reads the floor is never taken from PATH first: a fake `node` early on PATH could pass a --tighten
|
|
48
|
+
# check it never made. The install's own node (an npm or nvm prefix: <prefix>/lib/node_modules/@nodii/dev/dist), then
|
|
49
|
+
# the system's fixed locations, then PATH only when none exists (a bare checkout on a CI runner).
|
|
50
|
+
FLOOR_RT=""
|
|
51
|
+
for _rt in "$(dirname "$FLOOR_JS")/../../../../../bin/node" /opt/homebrew/bin/node /usr/local/bin/node /usr/bin/node; do
|
|
52
|
+
[ -x "$_rt" ] && { FLOOR_RT="$_rt"; break; }
|
|
53
|
+
done
|
|
54
|
+
[ -n "$FLOOR_RT" ] || FLOOR_RT=$(command -v node 2>/dev/null || command -v bun 2>/dev/null || true)
|
|
55
|
+
floor_js() { [ -n "$FLOOR_RT" ] && [ -f "$FLOOR_JS" ] || return 127; "$FLOOR_RT" "$FLOOR_JS" "$@"; }
|
|
56
|
+
TIGHTEN=""
|
|
57
|
+
# v29 (DEV-PROCESS-2): one slot directory, one floor file. No variable moves either: NODII_RESOURCE_LIMITS and
|
|
58
|
+
# HEAVY_SLOT_DIR are gone, and limits.env no longer sizes the queue (its LANE_CAP, STACK_CAP, LIGHT_LANE_CAP and
|
|
59
|
+
# DEV_SERVER_CAP stay there for the coordinator). The ceilings, the stagger and the floor come from root-owned
|
|
60
|
+
# /etc/nodii/floor.env through machine-floor.js, else its shipped defaults. Tests run a copy of this file.
|
|
61
|
+
D=/tmp/nodii-heavy-slots
|
|
48
62
|
# The pool this job takes a slot from: $D for heavy (where every older copy looks), $D/light for light (v27).
|
|
49
63
|
SD="$D"
|
|
50
64
|
POLL="${HEAVY_SLOT_POLL_SEC:-10}"; case "$POLL" in ''|*[!0-9]*|0) POLL=10;; esac
|
|
51
65
|
IS_LANDING=0
|
|
52
66
|
SIZE=heavy
|
|
67
|
+
RECLAIM_MIN=10
|
|
53
68
|
load_limits() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
LSLOTS="${LIGHT_SLOTS:-$LSLOTS}"; LMIN_GB="${LIGHT_MIN_AVAIL_GB:-$LMIN_GB}"; LMAX="${LIGHT_MAX_TEST_FILES:-$LMAX}"
|
|
69
|
+
# Shipped defaults if the floor's reader cannot run; the floor check itself then refuses (exit 75), so these only
|
|
70
|
+
# size a queue nothing can join.
|
|
71
|
+
SLOTS=3; RESERVE=1; LSLOTS=8; STAGGER=10
|
|
72
|
+
local out line; out=$(floor_js limits 2>/dev/null) || out=""
|
|
73
|
+
while IFS= read -r line; do
|
|
74
|
+
case "$line" in SLOTS=[0-9]*|RESERVE=[0-9]*|LSLOTS=[0-9]*|STAGGER=[0-9]*) eval "${line%%[!A-Z0-9=_]*}";; esac
|
|
75
|
+
done <<EOF2
|
|
76
|
+
$out
|
|
77
|
+
EOF2
|
|
64
78
|
# A garbled limit must never break the arithmetic below (an arithmetic error aborts the wait loop).
|
|
65
|
-
case "$SLOTS" in ''|*[!0-9]*|0) SLOTS=
|
|
66
|
-
case "$
|
|
67
|
-
case "$
|
|
68
|
-
# v27:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# v27: a light job uses the light pool's own cap and floor, with no stagger and no landing reserve.
|
|
72
|
-
if [ "$SIZE" = light ]; then SLOTS=$LSLOTS; MIN_GB=$LMIN_GB; STAGGER=0; RESERVE=0; fi
|
|
73
|
-
# v15 (24 Oct): landings get a reserved slot. A `git push` (whose pre-push runs the gates) stuck behind
|
|
74
|
-
# typechecks/tests blocks the whole fleet (HR's FE landings queued ~70 min, 10:30Z). Non-landing jobs may use
|
|
75
|
-
# only slots 1..SLOTS-RESERVE.
|
|
79
|
+
case "$SLOTS" in ''|*[!0-9]*|0) SLOTS=3;; esac; case "$RESERVE" in ''|*[!0-9]*) RESERVE=1;; esac
|
|
80
|
+
case "$LSLOTS" in ''|*[!0-9]*) LSLOTS=8;; esac
|
|
81
|
+
case "$STAGGER" in ''|*[!0-9]*) STAGGER=10;; esac
|
|
82
|
+
# v27: a light job uses the light pool's own cap, with no stagger and no landing reserve.
|
|
83
|
+
if [ "$SIZE" = light ]; then SLOTS=$LSLOTS; STAGGER=0; RESERVE=0; fi
|
|
84
|
+
# v15 (24 Oct): landings get a reserved slot. Non-landing jobs may use only slots 1..SLOTS-RESERVE.
|
|
76
85
|
MAXSLOT=$SLOTS
|
|
77
86
|
if [ "$IS_LANDING" != 1 ]; then MAXSLOT=$(( SLOTS - RESERVE )); [ "$MAXSLOT" -lt 1 ] && MAXSLOT=1; fi
|
|
78
87
|
}
|
|
79
|
-
avail_gb() {
|
|
80
|
-
# Activity Monitor's accounting: used = app memory (anonymous - purgeable) + wired + compressor; available = RAM - used.
|
|
81
|
-
# Counting inactive/free pages instead overstated headroom by ~5 GB, because the compressor (26 GB on 15 Oct,
|
|
82
|
-
# mostly the Docker VM) holds live processes' memory that no resident-size figure shows.
|
|
83
|
-
# A sandboxed lane (Codex seatbelt) can't read hw.memsize: an empty ram made available memory negative and the
|
|
84
|
-
# gate refused every job forever (23 Oct, DOCCLOUD-VIEW-1). Fall back to the value the coordinator records (v10).
|
|
85
|
-
if [ -r /proc/meminfo ] && ! command -v vm_stat >/dev/null 2>&1; then
|
|
86
|
-
awk '/^MemAvailable:/{printf "%d", $2/1048576; f=1} END{if(!f) printf "0"}' /proc/meminfo; return
|
|
87
|
-
fi
|
|
88
|
-
local ram; ram=$(sysctl -n hw.memsize 2>/dev/null); case "$ram" in ''|*[!0-9]*) ram=$(cat "$HOME/.config/nodii-resources/hw.memsize" 2>/dev/null);; esac
|
|
89
|
-
case "$ram" in ''|*[!0-9]*) echo 0; return;; esac
|
|
90
|
-
vm_stat | awk -v ram="$ram" '/page size of/{ps=$8} /Anonymous pages/{an=$3} /Pages purgeable/{p=$3}
|
|
91
|
-
/Pages wired/{w=$4} /occupied by compressor/{c=$5}
|
|
92
|
-
END{used=(an-p+w+c)*ps; printf "%d", (ram-used)/1073741824}'
|
|
93
|
-
}
|
|
94
88
|
mtime() { local m; m=$(stat -f %m "$1" 2>/dev/null) || m=$(stat -c %Y "$1" 2>/dev/null); case "$m" in ''|*[!0-9]*) echo "";; *) echo "$m";; esac; }
|
|
95
89
|
since_last_admit() {
|
|
96
90
|
# Any missing/empty/garbled stamp means "long ago". Never feed an empty string to $(( )): in bash an arithmetic
|
|
@@ -171,11 +165,9 @@ if [ "${1:-}" = "--status" ]; then
|
|
|
171
165
|
[ -d "$D" ] || mkdir -p "$D" 2>/dev/null
|
|
172
166
|
load_limits
|
|
173
167
|
local now held lheld q t tp o qd; now=$(date +%s); held=$(held_count "$D"); lheld=$(held_count "$D/light")
|
|
174
|
-
echo "heavy-slot
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
else echo "light slots ${lheld}/${LSLOTS} held (floor ${LMIN_GB} GB, no stagger; a test run naming at most ${LMAX} test files is light)"; fi
|
|
178
|
-
echo "available memory $(avail_gb) GB (floor ${MIN_GB} GB) · stagger ${STAGGER}s · reclaim after ${RECLAIM_MIN} min"
|
|
168
|
+
echo "heavy-slot v29 · slots in $D"
|
|
169
|
+
floor_js status 2>/dev/null || echo "floor unreadable (no node, or no $FLOOR_JS): every job is refused"
|
|
170
|
+
echo "slots ${held}/${SLOTS} held (landing reserve ${RESERVE}: other jobs use at most $(( SLOTS - RESERVE < 1 ? 1 : SLOTS - RESERVE ))) · light slots ${lheld}/${LSLOTS} held · reclaim after ${RECLAIM_MIN} min"
|
|
179
171
|
local lane why age
|
|
180
172
|
for o in "$D"/[0-9]* "$D"/light/[0-9]*; do
|
|
181
173
|
[ -d "$o" ] || continue
|
|
@@ -207,8 +199,10 @@ fi
|
|
|
207
199
|
SIZE="${HEAVY_SIZE:-}"
|
|
208
200
|
while [ $# -gt 0 ]; do
|
|
209
201
|
case "$1" in
|
|
210
|
-
--size) [ $# -ge 2 ] || { echo "usage: nodii-dev heavy run [--size light|heavy] -- <command...>" >&2; return 2; }; SIZE="$2"; shift 2;;
|
|
202
|
+
--size) [ $# -ge 2 ] || { echo "usage: nodii-dev heavy run [--size light|heavy] [--tighten READING=GB] -- <command...>" >&2; return 2; }; SIZE="$2"; shift 2;;
|
|
211
203
|
--size=*) SIZE="${1#--size=}"; shift;;
|
|
204
|
+
--tighten) [ $# -ge 2 ] || { echo "usage: nodii-dev heavy run [--size light|heavy] [--tighten READING=GB] -- <command...>" >&2; return 2; }; TIGHTEN="${TIGHTEN:+$TIGHTEN,}$2"; shift 2;;
|
|
205
|
+
--tighten=*) TIGHTEN="${TIGHTEN:+$TIGHTEN,}${1#--tighten=}"; shift;;
|
|
212
206
|
--) shift; break;;
|
|
213
207
|
*) break;;
|
|
214
208
|
esac
|
|
@@ -225,19 +219,32 @@ if { printf '%s' "$cmd" | grep -Eq '[ /]vite( |$)' && ! printf '%s' "$cmd" | gre
|
|
|
225
219
|
echo "[heavy-slot] run it OUTSIDE heavy-slot, at most DEV_SERVER_CAP host-wide, and kill it by PID when done." >&2
|
|
226
220
|
return 64
|
|
227
221
|
fi
|
|
228
|
-
#
|
|
229
|
-
#
|
|
230
|
-
#
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
222
|
+
# v29 (DEV-PROCESS-2): nesting is proven by the process tree, not by a variable. A heavy-slot whose ancestor holds a
|
|
223
|
+
# slot (an outer heavy-slot, whose job this is a descendant of) runs in that slot and never queues for a second one
|
|
224
|
+
# (K02-6; tenant's db:setup once sat 74 min waiting on itself). NODII_HEAVY_SLOT and NODII_HEAVY_SLOT_HELD are gone.
|
|
225
|
+
holders=" "
|
|
226
|
+
for o in "$D"/[0-9]* "$D"/light/[0-9]*; do
|
|
227
|
+
[ -d "$o" ] || continue
|
|
228
|
+
op=$(cat "$o/pid" 2>/dev/null); case "$op" in ''|*[!0-9]*) continue;; esac
|
|
229
|
+
dead "$op" || holders="$holders$op:${o#$D/} "
|
|
230
|
+
done
|
|
231
|
+
if [ "$holders" != " " ]; then
|
|
232
|
+
anc=$PPID; hops=0
|
|
233
|
+
while [ -n "$anc" ] && [ "$anc" -gt 1 ] 2>/dev/null && [ "$hops" -lt 64 ]; do
|
|
234
|
+
case "$holders" in *" $anc:"*)
|
|
235
|
+
inslot=${holders#*" $anc:"}; inslot=${inslot%% *}
|
|
236
|
+
echo "[heavy-slot] nested in slot ${inslot} held by pid ${anc}: running in it: $*" >&2
|
|
237
|
+
exec "$@";;
|
|
238
|
+
esac
|
|
239
|
+
anc=$(ps -o ppid= -p "$anc" 2>/dev/null | tr -d ' '); hops=$((hops + 1))
|
|
240
|
+
done
|
|
241
|
+
# hub-ee on #501: the proof needs an unbroken parent chain. setsid and nohup keep it while the parent lives; a
|
|
242
|
+
# daemon whose parent has exited, a process started by `docker exec` (no Docker on this machine) or a blocked `ps`
|
|
243
|
+
# break it. Then the call is NOT nested: it is a job of its own, read against the floor and queued like any other.
|
|
244
|
+
# No variable or file can claim a slot instead, since anything this user can write any session can forge. Say so
|
|
245
|
+
# when ps broke the chain, so a caller that waits on itself (K02-6) can tell why.
|
|
246
|
+
[ -z "$anc" ] && echo "[heavy-slot] nesting not proven: ps could not read a parent in this call's chain, so it runs as its own job (run heavy work from the slot's own command, in its process tree): $*" >&2
|
|
247
|
+
fi
|
|
241
248
|
# v18 (24 Oct): a teardown FREES memory, so it never waits for a slot. `docker compose … down -v` sat 3 min behind
|
|
242
249
|
# 14 queued jobs (12:27Z) while its stack kept its containers' memory.
|
|
243
250
|
case " $* " in *" compose "*" down"*|*" down "*|*stack:down*|*":down "*) exec "$@";; esac
|
|
@@ -258,10 +265,8 @@ if ! { : > "$D/.writable.$$"; } 2>/dev/null; then
|
|
|
258
265
|
return 77
|
|
259
266
|
fi
|
|
260
267
|
rm -f "$D/.writable.$$"
|
|
261
|
-
|
|
262
|
-
#
|
|
263
|
-
# HEAVY_LANDING=1, so every gate of the landing uses the reserve, not only the final push (HR land.sh, 10-24).
|
|
264
|
-
# v24: `git -C dir push` and `git -c k=v push` are landings too.
|
|
268
|
+
# A landing is a `git push` (v24: also `git -C dir push` and `git -c k=v push`). v29: HEAVY_LANDING=1 is gone; it let
|
|
269
|
+
# any job claim the landing reserve.
|
|
265
270
|
is_push() {
|
|
266
271
|
case "$(basename -- "${1:-}")" in git) ;; *) return 1;; esac; shift
|
|
267
272
|
while [ $# -gt 0 ]; do
|
|
@@ -272,41 +277,42 @@ is_push() {
|
|
|
272
277
|
*) return 1;;
|
|
273
278
|
esac
|
|
274
279
|
done; return 1; }
|
|
275
|
-
is_push "$@" && IS_LANDING=1
|
|
276
|
-
#
|
|
277
|
-
#
|
|
278
|
-
#
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
case "$s" in *"&&"*|*"||"*|*";"*|*"|"*|*'$('*|*'`'*|*"<"*|*">"*) return 1;; esac
|
|
284
|
-
load_limits
|
|
285
|
-
set -f
|
|
286
|
-
for w in $s; do
|
|
287
|
-
case "$w" in
|
|
288
|
-
vitest|*/vitest|jest|*/jest|mocha|*/mocha) runner=1;;
|
|
289
|
-
test) case "$prev" in bun|*/bun) runner=1;; esac;;
|
|
290
|
-
--test) case "$prev" in node|*/node) runner=1;; esac;;
|
|
291
|
-
*'*'*|*'?'*) set +f; return 1;;
|
|
292
|
-
*.test.[cm][jt]s|*.test.[jt]s|*.test.[jt]sx|*.spec.[cm][jt]s|*.spec.[jt]s|*.spec.[jt]sx) n=$((n + 1));;
|
|
293
|
-
esac
|
|
294
|
-
prev="$w"
|
|
295
|
-
done
|
|
296
|
-
set +f
|
|
297
|
-
[ "$runner" = 1 ] && [ "$n" -ge 1 ] && [ "$n" -le "$LMAX" ]
|
|
280
|
+
is_push "$@" && IS_LANDING=1
|
|
281
|
+
# v29 (the operator, 23 Nov about 20:05 IST: "NOTHING but E2E tests should require a heavy slot"): a job's size.
|
|
282
|
+
# Only end-to-end, real-stack and browser-flow work is heavy: Playwright, Cypress and other browser drivers, an e2e,
|
|
283
|
+
# integration, real-stack or stack script, an image build and a detached stack start. Everything else (typecheck,
|
|
284
|
+
# lint, unit tests, a `git push`) is light: it takes a light slot, under the light pool's own floor (5 GB) and with
|
|
285
|
+
# no stagger. `--size heavy` (or HEAVY_SIZE=heavy) makes any job heavy; `--size light` never makes end-to-end work light.
|
|
286
|
+
e2e_job() {
|
|
287
|
+
printf ' %s ' "$*" | grep -Eiq '[^a-z0-9](playwright|cypress|puppeteer|selenium|webdriver|e2e|browser-flow|real-stack|integration)([^a-z0-9]|$)|test:stack|stack:up|stack-up|:real([^a-z0-9]|$)|docker( buildx)? build|docker( |-)compose[^|;&]* (up|build)( |$)'
|
|
298
288
|
}
|
|
299
|
-
# A light slot skips the heavy cap, floor and stagger, so only a test run naming its test files may take one: an
|
|
300
|
-
# explicit --size light (or HEAVY_SIZE=light) on anything else is refused and takes a heavy slot (K02-4).
|
|
301
289
|
load_limits
|
|
302
|
-
if [ "$
|
|
303
|
-
elif
|
|
304
|
-
|
|
305
|
-
elif [ "$SIZE" = light ] && ! light_test_run "$@"; then
|
|
306
|
-
echo "[heavy-slot] --size light is only for a test run naming at most ${LMAX} test files; this job takes a heavy slot: $*" >&2
|
|
290
|
+
if [ "$SIZE" = heavy ]; then :
|
|
291
|
+
elif e2e_job "$@"; then
|
|
292
|
+
[ "$SIZE" = light ] && echo "[heavy-slot] --size light does not apply to end-to-end, real-stack or browser work; this job takes a heavy slot: $*" >&2
|
|
307
293
|
SIZE=heavy
|
|
294
|
+
elif [ "$LSLOTS" -eq 0 ]; then SIZE=heavy
|
|
295
|
+
else SIZE=light
|
|
308
296
|
fi
|
|
309
297
|
if [ "$SIZE" = light ]; then SD="$D/light"; mkdir -p "$SD" 2>/dev/null; fi
|
|
298
|
+
# v29 (DEV-PROCESS-2): every job reads the floor before it queues, and again when a slot is free. Under the floor it is
|
|
299
|
+
# refused at once (exit 75, MACHINE_UNDER_FLOOR, logged), never queued and never let through: no lone-job and no
|
|
300
|
+
# landing exception (hub-490: a push is refused under the floor too). --tighten makes the call stricter; a
|
|
301
|
+
# figure that would loosen the floor is a usage error (exit 2).
|
|
302
|
+
LANDING_FLAG=""; [ "$IS_LANDING" = 1 ] && LANDING_FLAG="--landing"
|
|
303
|
+
floor_gate() { local frc=0
|
|
304
|
+
floor_js check --class "$SIZE" --what "$JOB" ${TIGHTEN:+--tighten "$TIGHTEN"} $LANDING_FLAG "$@" || frc=$?
|
|
305
|
+
case "$frc" in
|
|
306
|
+
0) return 0;;
|
|
307
|
+
127) echo "[heavy-slot] MACHINE_UNDER_FLOOR: the floor cannot be read (no node, or no $FLOOR_JS); refusing: $JOB" >&2; return 75;;
|
|
308
|
+
2) return 2;;
|
|
309
|
+
*) return 75;;
|
|
310
|
+
esac; }
|
|
311
|
+
# hub-ee on #501: a holder killed with SIGKILL never runs its EXIT trap, so its slot stayed and its reservation was
|
|
312
|
+
# counted by the floor read below, which ran before any cleanup. Reap dead holders in both slot dirs first.
|
|
313
|
+
# machine-floor.js also leaves out a slot whose pid is dead or was reused by a later process.
|
|
314
|
+
held_count "$D" >/dev/null; held_count "$D/light" >/dev/null
|
|
315
|
+
local frc=0; floor_gate || frc=$?; [ "$frc" -eq 0 ] || return "$frc"
|
|
310
316
|
# v19 (24 Oct): FIFO. Waiters raced for freed slots, so an unlucky job starved: tenant's `test:stack:up` waited 71 min
|
|
311
317
|
# behind 14 newer jobs (12:27Z). Each non-landing waiter takes a ticket (time-ordered name); only the oldest
|
|
312
318
|
# (limit - held) live tickets may try for a slot. Landings keep their reserve and skip the line.
|
|
@@ -324,7 +330,7 @@ fifo_rank() { local r=0 t tp st; st=" $(stopped_pids | tr '\n' ' ') "
|
|
|
324
330
|
[ "$Q/$t" = "$TICKET" ] && { echo "$r"; return; }
|
|
325
331
|
case "$st" in *" $tp "*) continue;; esac
|
|
326
332
|
r=$((r + 1)); done; echo 0; }
|
|
327
|
-
local slot="" waited=0 said=-1 held rank LIMIT i l o
|
|
333
|
+
local slot="" waited=0 said=-1 held rank LIMIT i l o g others why
|
|
328
334
|
# A queued job says its place and its wait when it starts waiting and then once a minute; it never gives up, so a
|
|
329
335
|
# gate is never timed out by the queue (hub-377).
|
|
330
336
|
say() { if [ "$said" -lt 0 ] || [ $((waited - said)) -ge 60 ]; then said=$waited; echo "[heavy-slot] waiting ${waited}s: $1. Job: $JOB" >&2; fi; }
|
|
@@ -350,8 +356,7 @@ while :; do
|
|
|
350
356
|
l="$SD/$i"
|
|
351
357
|
if [ -d "$l" ]; then o=$(cat "$l/pid" 2>/dev/null || echo); dead "$o" && rm -rf "$l"; fi
|
|
352
358
|
if mkdir "$l" 2>/dev/null; then
|
|
353
|
-
echo $$ > "$l/pid"; echo "$(pwd) :: $*" > "$l/what"
|
|
354
|
-
a=$(avail_gb); a=${a:-0}
|
|
359
|
+
echo $$ > "$l/pid"; echo "$(pwd) :: $*" > "$l/what"; echo "$SIZE" > "$l/size"
|
|
355
360
|
# admission check and last-admit stamp happen while holding the admit lock, so two jobs can't pass the stagger together
|
|
356
361
|
# an admit lock older than 30s belongs to a process that died mid-check: reclaim it
|
|
357
362
|
if [ "$(admit_lock_age)" -gt 30 ]; then rmdir "$D/.admit" 2>/dev/null; fi
|
|
@@ -361,22 +366,13 @@ while :; do
|
|
|
361
366
|
# With every other slot idle, admit at once: a fixed 60 s gap serialised quick jobs (biome, lint) to one a
|
|
362
367
|
# minute and queued 29 of them with zero heavy jobs running (15 Oct 15:38Z).
|
|
363
368
|
others=0; for o in "$SD"/[0-9]*; do [ -d "$o" ] && [ "$o" != "$l" ] && others=$((others + 1)); done
|
|
364
|
-
# v27: "no other job is running" counts both pools. A light job alone in its pool beside running heavy jobs
|
|
365
|
-
# (or a heavy job beside light ones) is held by the floor like any other job: waiting can free memory then.
|
|
366
|
-
if [ "$SD" = "$D" ]; then alone=$(( others + $(held_count "$D/light") )); else alone=$(( others + $(held_count "$D") )); fi
|
|
367
|
-
# v24 (hub-377): with NO heavy job running, waiting cannot free memory (heavy jobs hold none of it), so the
|
|
368
|
-
# floor would stop every job on the machine for good, landings too: once every lane went through the queue,
|
|
369
|
-
# 6 GB available under a 14 GB floor with 0 slots held queued all of them. One job is then admitted, with a
|
|
370
|
-
# warning; the floor still holds every job beside it.
|
|
371
|
-
# v24 (hub-377): a landing is not held by the floor either, only by the cap and the stagger. On 13 Nov a
|
|
372
|
-
# landing waited 105 s with 3/6 slots held, because the machine's own load (no heavy job's) kept memory
|
|
373
|
-
# under the floor; a stuck landing blocks the fleet (v15), and a landing runs once and frees its lane.
|
|
374
369
|
# v24 (hub-377): the cap is checked again HERE, under the admit lock. The held count at the top of the loop
|
|
375
|
-
# is read before the lock, so two waiters could both see one free slot
|
|
376
|
-
#
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
370
|
+
# is read before the lock, so two waiters could both see one free slot and run one job over the cap.
|
|
371
|
+
# v29 (DEV-PROCESS-2): the floor is read again here, with every running job's expected peak held back (less
|
|
372
|
+
# what it already uses). Under it the job is refused, not queued: v24's lone-job and landing exceptions are gone.
|
|
373
|
+
if [ "$others" -lt "$LIMIT" ] && { [ "$others" -eq 0 ] || [ "$g" -ge "$STAGGER" ]; }; then
|
|
374
|
+
frc=0; floor_gate --self "$l" || frc=$?
|
|
375
|
+
if [ "$frc" -ne 0 ]; then rmdir "$D/.admit"; rm -rf "$l"; return "$frc"; fi
|
|
380
376
|
date +%s > "$SD/last-admit"; rmdir "$D/.admit"; slot="$l"; [ -n "$TICKET" ] && rm -f "$TICKET"; TICKET=""; break 2
|
|
381
377
|
fi
|
|
382
378
|
rmdir "$D/.admit"
|
|
@@ -385,24 +381,23 @@ while :; do
|
|
|
385
381
|
fi
|
|
386
382
|
done
|
|
387
383
|
# v12 (24 Oct): say WHICH gate is holding.
|
|
388
|
-
held=$(held_count)
|
|
384
|
+
held=$(held_count)
|
|
389
385
|
if [ "$held" -ge "$SLOTS" ]; then why="all ${SLOTS} slots held"
|
|
390
|
-
|
|
391
|
-
else why="${STAGGER}s stagger after the last admission (${held}/${SLOTS} held, ${av} GB available)"; fi
|
|
386
|
+
else why="${STAGGER}s stagger after the last admission (${held}/${SLOTS} held)"; fi
|
|
392
387
|
say "$why"
|
|
393
388
|
pause
|
|
394
389
|
done
|
|
395
390
|
# belt and braces: never run without a slot
|
|
396
391
|
[ -n "$slot" ] && [ -d "$slot" ] || { echo "[heavy-slot] internal error: no slot acquired; refusing to run: $*" >&2; exit 70; }
|
|
397
392
|
LBL=""; [ "$SIZE" = light ] && LBL=" light"
|
|
398
|
-
echo "[heavy-slot] got $(basename "$slot")/${SLOTS}${LBL} after ${waited}s
|
|
393
|
+
echo "[heavy-slot] got $(basename "$slot")/${SLOTS}${LBL} after ${waited}s: $*" >&2
|
|
394
|
+
# v28: record the admission and the readings it was made on, in the background so the job does not wait for it.
|
|
395
|
+
( floor_js record --class "$SIZE" --what "$JOB" ${TIGHTEN:+--tighten "$TIGHTEN"} $LANDING_FLAG ) </dev/null >/dev/null 2>&1 &
|
|
399
396
|
# v26: who holds the slot, for the orphan reclaim, and the marker the job's own heavy work runs under.
|
|
400
397
|
date +%s > "$slot/since"
|
|
401
398
|
lane_key > "$slot/lane"
|
|
402
399
|
echo "${CLAUDE_PID:-}" > "$slot/session"; [ -n "${CLAUDE_PID:-}" ] && started "$CLAUDE_PID" > "$slot/session-start"
|
|
403
400
|
{ git rev-parse --show-toplevel 2>/dev/null || pwd; } > "$slot/worktree"
|
|
404
|
-
# v27: a light slot's marker is light/<n>, so the nested check finds it under $D.
|
|
405
|
-
if [ "$SIZE" = light ]; then export NODII_HEAVY_SLOT="light/$(basename "$slot")"; else export NODII_HEAVY_SLOT="$(basename "$slot")"; fi
|
|
406
401
|
# Run the job as its OWN process group and forward INT/TERM to the whole group. Without this, stopping the wrapper
|
|
407
402
|
# left the job running (15 Oct: a sharded tsc kept spawning 4 GB shards after its wrapper was killed) AND released
|
|
408
403
|
# the slot, so the gate under-counted live memory.
|