@nodii/dev 0.6.126 → 0.6.128

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/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
4
  import { homedir, platform } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.126";
7
+ export const VERSION = "0.6.128";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
@@ -92,20 +92,21 @@ if [ "${1:-}" = "--status" ]; then
92
92
  [ -d "$D" ] || mkdir -p "$D" 2>/dev/null
93
93
  load_limits
94
94
  local now held q t tp o; now=$(date +%s); held=$(held_count)
95
- echo "heavy-slot v24 · limits $LIMITS"
95
+ echo "heavy-slot v25 · limits $LIMITS"
96
96
  echo "slots ${held}/${SLOTS} held (landing reserve ${RESERVE}: other jobs use at most $(( SLOTS - RESERVE < 1 ? 1 : SLOTS - RESERVE )))"
97
97
  echo "available memory $(avail_gb) GB (floor ${MIN_GB} GB) · stagger ${STAGGER}s"
98
98
  for o in "$D"/[0-9]*; do
99
99
  [ -d "$o" ] || continue
100
100
  t=$(mtime "$o"); echo " slot $(basename "$o") pid $(cat "$o/pid" 2>/dev/null) for $(( now - ${t:-$now} ))s: $(cat "$o/what" 2>/dev/null)"
101
101
  done
102
- q=0
102
+ q=0; local sp=0 st; st=" $(ps -axo pid=,stat= 2>/dev/null | awk '$2 ~ /^T/ {print $1}' | tr '\n' ' ') "
103
103
  for t in $(ls "$D/q" 2>/dev/null | sort); do
104
104
  tp=$(cat "$D/q/$t" 2>/dev/null)
105
105
  if dead "$tp"; then rm -f "$D/q/$t"; continue; fi
106
+ case "$st" in *" $tp "*) sp=$((sp + 1)); echo " stopped: pid ${tp} waiting $(( now - ${t%%.*} ))s (holds no place until it resumes)"; continue;; esac
106
107
  q=$((q + 1)); echo " queued $q: pid ${tp} waiting $(( now - ${t%%.*} ))s"
107
108
  done
108
- echo "queue ${q} waiting"
109
+ echo "queue ${q} waiting, ${sp} stopped"
109
110
  return 0
110
111
  fi
111
112
 
@@ -164,10 +165,17 @@ is_push "$@" && IS_LANDING=1; [ "${HEAVY_LANDING:-}" = 1 ] && IS_LANDING=1
164
165
  local Q="$D/q" TICKET=""; mkdir -p "$Q" 2>/dev/null
165
166
  if [ "$IS_LANDING" != 1 ]; then TICKET="$Q/$(date +%s).$(printf '%06d' $$)"; echo $$ > "$TICKET"; fi
166
167
  trap '[ -n "$TICKET" ] && rm -f "$TICKET"' EXIT
167
- fifo_rank() { local r=0 t tp
168
+ # v25 (13 Nov, hub-377): a STOPPED waiter (ps state T: ^Z, SIGSTOP, a suspended session) never polls, so it can never
169
+ # take a slot, yet it kept its rank: eight stopped head tickets held 46 live waiters for an hour with 1/6 slots held
170
+ # (05:30Z, reported by rbac-edge-strip). A stopped waiter keeps its ticket, so it gets its place back when it resumes,
171
+ # but it no longer counts toward anyone's rank while stopped. One `ps` per rank check, not one per ticket.
172
+ stopped_pids() { ps -axo pid=,stat= 2>/dev/null | awk '$2 ~ /^T/ {print $1}'; }
173
+ fifo_rank() { local r=0 t tp st; st=" $(stopped_pids | tr '\n' ' ') "
168
174
  for t in $(ls "$Q" 2>/dev/null | sort); do
169
175
  tp=$(cat "$Q/$t" 2>/dev/null); if dead "$tp"; then rm -f "$Q/$t"; continue; fi
170
- [ "$Q/$t" = "$TICKET" ] && { echo "$r"; return; }; r=$((r + 1)); done; echo 0; }
176
+ [ "$Q/$t" = "$TICKET" ] && { echo "$r"; return; }
177
+ case "$st" in *" $tp "*) continue;; esac
178
+ r=$((r + 1)); done; echo 0; }
171
179
  local slot="" waited=0 said=-1 held rank LIMIT i l o a g others av why
172
180
  # A queued job says its place and its wait when it starts waiting and then once a minute; it never gives up, so a
173
181
  # gate is never timed out by the queue (hub-377).
@@ -209,8 +217,15 @@ while :; do
209
217
  # floor would stop every job on the machine for good, landings too: once every lane went through the queue,
210
218
  # 6 GB available under a 14 GB floor with 0 slots held queued all of them. One job is then admitted, with a
211
219
  # warning; the floor still holds every job beside it.
212
- if { [ "$a" -ge "$MIN_GB" ] || [ "$others" -eq 0 ]; } && { [ "$others" -eq 0 ] || [ "$g" -ge "$STAGGER" ]; }; then
213
- [ "$a" -lt "$MIN_GB" ] && echo "[heavy-slot] available ${a} GB is under the floor ${MIN_GB} GB, but no other heavy job is running, so waiting cannot free memory: admitting this one job alone." >&2
220
+ # v24 (hub-377): a landing is not held by the floor either, only by the cap and the stagger. On 13 Nov a
221
+ # landing waited 105 s with 3/6 slots held, because the machine's own load (no heavy job's) kept memory
222
+ # under the floor; a stuck landing blocks the fleet (v15), and a landing runs once and frees its lane.
223
+ # v24 (hub-377): the cap is checked again HERE, under the admit lock. The held count at the top of the loop
224
+ # is read before the lock, so two waiters could both see one free slot, take two slot numbers and run one
225
+ # job over the cap (seen in the suite under load: 3 at once with a limit of 2; v23 had the same race).
226
+ if [ "$others" -lt "$LIMIT" ] && { [ "$a" -ge "$MIN_GB" ] || [ "$others" -eq 0 ] || [ "$IS_LANDING" = 1 ]; } && { [ "$others" -eq 0 ] || [ "$g" -ge "$STAGGER" ]; }; then
227
+ if [ "$a" -lt "$MIN_GB" ] && [ "$others" -eq 0 ]; then echo "[heavy-slot] available ${a} GB is under the floor ${MIN_GB} GB, but no other heavy job is running, so waiting cannot free memory: admitting this one job alone." >&2
228
+ elif [ "$a" -lt "$MIN_GB" ]; then echo "[heavy-slot] available ${a} GB is under the floor ${MIN_GB} GB; a landing is held only by the cap and the stagger: admitting it." >&2; fi
214
229
  date +%s > "$D/last-admit"; rmdir "$D/.admit"; slot="$l"; [ -n "$TICKET" ] && rm -f "$TICKET"; TICKET=""; break 2
215
230
  fi
216
231
  rmdir "$D/.admit"
package/dist/heavy.js CHANGED
@@ -249,12 +249,21 @@ function queued(argv) {
249
249
  return ["bash", "sh", "zsh"].includes(name) && /(?:^|\/)heavy-slot\.sh$/.test(argv.find((word, i) => i > 0 && !word.startsWith("-")) ?? "");
250
250
  }
251
251
 
252
- // `nodii-dev lane check --gate …` and `nodii-dev receipt write --run …` queue each gate themselves.
252
+ // `nodii-dev lane check --gate …` and `nodii-dev receipt write --run …` queue each gate themselves, and
253
+ // `nodii-dev run … -- CMD` queues CMD when it is heavy (needsSlot).
253
254
  function selfQueued(argv) {
254
255
  const name = plainName(argv[0]);
255
256
  if (!/^nodii-dev(?:\.js)?$/.test(name)) return false;
256
257
  const [command, action] = argv.slice(1).filter((word) => !word.startsWith("-"));
257
- return (command === "lane" && action === "check") || (command === "receipt" && action === "write");
258
+ return (command === "lane" && action === "check") || (command === "receipt" && action === "write") || command === "run";
259
+ }
260
+
261
+ /** Whether ARGV, run directly (no shell), is heavy work not yet in the queue; a shell running a string counts its commands. */
262
+ export function needsSlot(argv) {
263
+ if (!argv?.length || queued(argv)) return false;
264
+ const name = plainName(argv[0]);
265
+ const inner = ["bash", "sh", "zsh"].includes(name) ? argv.findIndex((word) => /^-[a-z]*c[a-z]*$/.test(word)) : -1;
266
+ return inner !== -1 ? unqueuedHeavy(argv[inner + 1] ?? "").jobs.length > 0 : heavyArgv(argv);
258
267
  }
259
268
 
260
269
  /**
package/dist/runs.js CHANGED
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import { basename } from "node:path";
5
5
  import { CliError, devRequest, encode } from "./core.js";
6
+ import { heavySlotArgv, needsSlot } from "./heavy.js";
6
7
 
7
8
  export const RUN_ID_ENV = "NODII_DEV_RUN_ID";
8
9
  const DEFAULT_HEARTBEAT_MS = 60_000;
@@ -230,7 +231,9 @@ export async function superviseRun({
230
231
 
231
232
  try {
232
233
  try {
233
- child = spawn(command[0], command.slice(1), {
234
+ // Heavy work waits for a machine-wide heavy slot first (hub-377, MW2-51); a nested call runs at once (K02-6).
235
+ const [file, args] = needsSlot(command) ? heavySlotArgv(command) : [command[0], command.slice(1)];
236
+ child = spawn(file, args, {
234
237
  shell: false,
235
238
  stdio: ["inherit", "pipe", "pipe"],
236
239
  });
package/dist/safety.js CHANGED
@@ -845,9 +845,10 @@ export async function safetyPreHook(payload, contextOrResolver = safetyContext,
845
845
  context.devBoundaries = provenLane(context) && createsAnyBranch(command) ? await devBoundaries(context.lane?.key, request) : null;
846
846
  const violation = commandViolations(command, context)[0];
847
847
  if (violation && provenLane(context)) blocked(violation);
848
- // hub-377 (MW2-51, K02-4): a lane's heavy work goes through the machine's slot queue. A heredoc body
849
- // read as text is not a command, so it is left out before the command is judged.
850
- const heavy = provenLane(context) ? heavyViolation(withoutHeredocBodies(command), { original: command }) : null;
848
+ // hub-377 (MW2-51, K02-4): a lane's heavy work goes through the machine's slot queue. This is host load, not
849
+ // ownership, so it binds every lane session, proven or not: a lane working in a repository with no lane
850
+ // marker still shares the machine. A heredoc body read as text is not a command, so it is left out first.
851
+ const heavy = provenLane(context) || context.role === "lane" ? heavyViolation(withoutHeredocBodies(command), { original: command }) : null;
851
852
  if (heavy) blocked(heavy);
852
853
  if (usesNoVerify(command) && context.role === "coordinator" && context.noVerifyReason)
853
854
  await recordNoVerifyReason(cwd, context.noVerifyReason);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.126",
3
+ "version": "0.6.128",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {