@plot-pm/board 0.18.0 → 0.19.1

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/plot-tmp.sh CHANGED
@@ -85,10 +85,16 @@ _plot_tmp_create() {
85
85
  trap '__plot_tmp_pending="TERM 15"' TERM
86
86
  trap '__plot_tmp_pending="PIPE 13"' PIPE
87
87
  fi
88
+ # `mktemp` IGNORES THE GROUP SIGNAL. It is a process of its own in the
89
+ # script's group, and the handlers above do not reach it: a group TERM after
90
+ # it creates the path and before it prints the name ends it, and the name
91
+ # never reaches the registry. CI run 38169324238 left one
92
+ # `plot-host-prlist-err.*` this way (#1582). Ignored signals pass to the child,
93
+ # so it always prints the name; this shell still records the signal.
88
94
  if [ "${3:-}" = -d ]; then
89
- __plot_tmp_new=$(mktemp -d "${TMPDIR:-/tmp}/plot-$2.XXXXXX")
95
+ __plot_tmp_new=$(trap '' INT TERM PIPE; mktemp -d "${TMPDIR:-/tmp}/plot-$2.XXXXXX")
90
96
  else
91
- __plot_tmp_new=$(mktemp "${TMPDIR:-/tmp}/plot-$2.XXXXXX")
97
+ __plot_tmp_new=$(trap '' INT TERM PIPE; mktemp "${TMPDIR:-/tmp}/plot-$2.XXXXXX")
92
98
  fi
93
99
  __plot_tmp_rc=$?
94
100
  # THE PATH IS REGISTERED WHEN IT EXISTS, whatever the status says. bash 3.2
@@ -303,7 +303,7 @@ plot_pid_is_current() { # $1=pid $2=startedAt (ISO-8601) → 0 if current, 1 if
303
303
 
304
304
  # Convert the manifest's startedAt (ISO-8601) to epoch seconds.
305
305
  # `date -j -f` is macOS; `date -d` is GNU. Try both.
306
- if manifest_epoch=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$started" +%s 2>/dev/null); then
306
+ if manifest_epoch=$(date -j -u -f "%Y-%m-%dT%H:%M:%SZ" "$started" +%s 2>/dev/null); then
307
307
  :
308
308
  elif manifest_epoch=$(date -d "$started" +%s 2>/dev/null); then
309
309
  :
@@ -330,11 +330,12 @@ plot_pid_is_current() { # $1=pid $2=startedAt (ISO-8601) → 0 if current, 1 if
330
330
  fi
331
331
 
332
332
  # A process that started BEFORE the manifest's startedAt is a reused pid.
333
- # A process that started AT or AFTER is the real worker. We allow 2 seconds
334
- # of slack for clock skew and rounding — the wrapper writes the pid and then
335
- # the manifest's awk stamps it; if the second ticks over in between, the
336
- # process appears to have started 1 second before the manifest says.
337
- local slack=2
333
+ # A process that started AT or AFTER is the real worker. The slack is 3 s:
334
+ # the wrapper writes the pid and then the manifest's awk stamps it, so the
335
+ # second can tick over in between, and procps on Linux reports a start 0.8 to
336
+ # 1.2 s early (`SKEW_MS` in `test/reconcile/own-process.mjs`). The stamp is
337
+ # UTC, so the macOS parse takes `-u`; without it the stamp read as local time.
338
+ local slack=3
338
339
  [ "$proc_epoch" -ge "$((manifest_epoch - slack))" ]
339
340
  }
340
341
 
@@ -1188,6 +1189,20 @@ plot_worker_task_state() { # $1=worktree $2=pr-fact → finished|waiting|stalled
1188
1189
  printf '%s' "$answer"
1189
1190
  }
1190
1191
 
1192
+ # Whether the loop `$2` at the desk `$1` is a free agent waiting for a hand-over:
1193
+ # `.plot-worker.freewait`, with leading and trailing whitespace removed, names
1194
+ # exactly that pid. A DECLARED DUPLICATE of `deskWaitsFree`: `plot_worker_state`
1195
+ # runs once per desk per fleet-scan pass, so it does not ask a bundle, and
1196
+ # `packages/domain/corpus/desk-waits-free.corpus.test.ts` holds the pair.
1197
+ plot_worker_waits_free() { # $1=worktree $2=pid → 0 when the record names $2
1198
+ local fw; [ -n "$2" ] && [ -f "$1/.plot-worker.freewait" ] && fw=$(<"$1/.plot-worker.freewait") || return 1
1199
+ fw="${fw#"${fw%%[![:space:]]*}"}"; [ "${fw%"${fw##*[![:space:]]}"}" = "$2" ]
1200
+ }
1201
+
1202
+ # `deskLoopAlive` and `deskWaitsFree` for the desk paths on stdin, one answer
1203
+ # line per desk (`board/plot-desk-loop.mjs`). Asked once per operator command.
1204
+ plot_desk_loops() { PLOT_MANIFEST_DIR="${PLOT_MANIFEST_DIR:-}" node "${_plot_wstate_config%/*}/board/plot-desk-loop.mjs" "$@"; }
1205
+
1191
1206
  # Classify the worker in a worktree.
1192
1207
  #
1193
1208
  # $1 = worktree path
@@ -1324,6 +1339,14 @@ plot_worker_state() { # $1=worktree $2=pr-fact → "state\tpid\tcode"
1324
1339
  # means — `stalled` for work only this machine holds, `waiting` for a
1325
1340
  # marker, `finished` for a desk that is clear — because the process has
1326
1341
  # nothing left to say. No exit file exists: the wrapper has not exited.
1342
+ #
1343
+ # A FREE AGENT WAITS HERE: its loop polls for a hand-over with no agent
1344
+ # beneath it, and `.plot-worker.freewait` names the loop's pid
1345
+ # (`deskWaitsFree`'s reading). That desk is occupied, so it reads `running`.
1346
+ # ONLY FOR A PID WHOSE OWNERSHIP IS PROVEN: `started_at` is set only when
1347
+ # the manifest's `startedAt` passed `plot_pid_is_current` above, so a
1348
+ # reused pid, or a pid from the bare pid file, never reads as a free agent.
1349
+ [ -n "$started_at" ] && plot_worker_waits_free "$wt" "$pid" && { printf 'running\t%s\t' "$pid"; return; }
1327
1350
  printf '%s\t%s\t' "$(plot_worker_task_state "$wt" "$has_pr")" "$pid"
1328
1351
  return
1329
1352
  fi