@plot-pm/board 0.13.0 → 0.14.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/dist/board-server.mjs +120 -119
- package/package.json +2 -1
- package/plot-approve.sh +18 -0
- package/plot-config.sh +17 -0
- package/plot-deliver.sh +39 -0
- package/plot-dispatch.sh +344 -40
- package/plot-host.sh +734 -83
- package/plot-reap.sh +106 -4
- package/plot-state-receipt.sh +308 -0
- package/plot-worker-state.sh +201 -2
package/plot-worker-state.sh
CHANGED
|
@@ -489,6 +489,140 @@ plot_worker_cpu_centis() { # $1=pid → total CPU centiseconds of pid+descendant
|
|
|
489
489
|
}'
|
|
490
490
|
}
|
|
491
491
|
|
|
492
|
+
# The name a live agent's process carries, as a substring of its command.
|
|
493
|
+
#
|
|
494
|
+
# CONFIGURABLE BECAUSE THE AGENT IS THE PROJECT'S, NOT PLOT'S. Principle 5 —
|
|
495
|
+
# Plot hardcodes no tooling — and the `Worker command` key already says every
|
|
496
|
+
# project names its own. This is the default because it is what this estate
|
|
497
|
+
# runs; a project whose agent is a different binary sets `PLOT_AGENT_PROCESS`
|
|
498
|
+
# and nothing else changes.
|
|
499
|
+
: "${PLOT_AGENT_PROCESS:=claude}"
|
|
500
|
+
|
|
501
|
+
# Whether an AGENT — not merely the wrapper — is alive under this pid.
|
|
502
|
+
#
|
|
503
|
+
# THE DEFECT THIS ANSWERS. The pid this fleet records is the loop shell, and
|
|
504
|
+
# `kill -0` on it succeeds for the whole `Worker bound` (28800 s) whether or not
|
|
505
|
+
# an agent still runs inside it. Measured 2026-09-11, in one session: FOUR
|
|
506
|
+
# agents ended mid-slice, none failed a build, none wrote a marker, and every
|
|
507
|
+
# one reported `running` with a plausible quiet time. Three left 8 commits and 9
|
|
508
|
+
# uncommitted files on their desks — one step from done, and all three would
|
|
509
|
+
# have been reaped as abandoned.
|
|
510
|
+
#
|
|
511
|
+
# EXISTENCE, NOT MOTION, AND THAT IS THE WHOLE DISTINCTION FROM THE CUE BELOW.
|
|
512
|
+
# `plot_worker_activity` samples CPU twice and asks whether the subtree is
|
|
513
|
+
# MOVING; an agent blocked on a network read is `idle` and perfectly alive. This
|
|
514
|
+
# asks whether there is an agent in the subtree AT ALL, which is a set
|
|
515
|
+
# membership test over one snapshot rather than a delta over two. The cue may
|
|
516
|
+
# never decide liveness, and this may never be read as a cue.
|
|
517
|
+
#
|
|
518
|
+
# ACCUMULATED CPU CANNOT DECIDE IT EITHER. Measured 2026-09-12 on this machine,
|
|
519
|
+
# a dead agent's tree held three `bash` children at 0:41.50, 0:41.22 and
|
|
520
|
+
# 0:40.31 — forty seconds of CPU each, burnt before the agent died. Only the
|
|
521
|
+
# PRESENCE of the agent process separates that tree from a live one.
|
|
522
|
+
#
|
|
523
|
+
# THE SAME ONE-SNAPSHOT WALK `plot_worker_cpu_centis` USES, and for its reason:
|
|
524
|
+
# a `pgrep -P` recursion forks a process per descendant on a scan the board
|
|
525
|
+
# polls every 5 s. It is also the only shape that reaches the real depth —
|
|
526
|
+
# measured on a healthy agent the same day, `claude` sat THREE levels below the
|
|
527
|
+
# recorded pid (`sh` → `bash` → `bash` → `claude`), so a depth-limited probe
|
|
528
|
+
# reports every live agent absent.
|
|
529
|
+
#
|
|
530
|
+
# ABSENT IS NOT FALSE, the rule this file keeps re-learning. A pid naming no
|
|
531
|
+
# process at all returns 2 — *could not look* — rather than 1, because a failure
|
|
532
|
+
# to observe is not evidence of something to see. The caller has already
|
|
533
|
+
# established the pid answers `kill -0` before it asks this.
|
|
534
|
+
# How long a wrapper must have been alive before its empty subtree means
|
|
535
|
+
# anything.
|
|
536
|
+
#
|
|
537
|
+
# THE STARTUP WINDOW IS REAL AND IT IS THIS READING'S OWN. `kill -0` succeeds
|
|
538
|
+
# the instant the wrapper exists, and the agent is forked some time after that —
|
|
539
|
+
# measured 2026-09-12, 37 to 237 ms for a `sh` forking a trivial child, and a
|
|
540
|
+
# real agent boots in seconds. A reading taken inside that window sees a worker
|
|
541
|
+
# that is STARTING and would call it stopped.
|
|
542
|
+
#
|
|
543
|
+
# The file already documents the same hazard one level down: *"There is a
|
|
544
|
+
# sub-millisecond window after the wrapper starts and before `.plot-worker.pid`
|
|
545
|
+
# is written, and a scan landing in it reads `none` — honest."* That window is
|
|
546
|
+
# tolerable because `none` tells a reader to look again; this one is not, because
|
|
547
|
+
# the whole point of the reading is to let something ACT on a stopped agent, and
|
|
548
|
+
# acting on a starting one hands its desk away as it boots.
|
|
549
|
+
#
|
|
550
|
+
# THIRTY SECONDS, AND IT IS A GUESS SAID OUT LOUD. Nothing has measured how long
|
|
551
|
+
# an agent takes to appear under its wrapper on a loaded machine; this is an
|
|
552
|
+
# order of magnitude above the worst observed fork and an order below the
|
|
553
|
+
# shortest slice. It is overridable so the tests need not wait, and a project on
|
|
554
|
+
# slower hardware can raise it.
|
|
555
|
+
: "${PLOT_AGENT_GRACE_SECONDS:=30}"
|
|
556
|
+
|
|
557
|
+
# The whole seconds a pid has been alive, or empty when it cannot be read.
|
|
558
|
+
#
|
|
559
|
+
# `etime` RATHER THAN `lstart`, because this needs a DURATION and `lstart` is a
|
|
560
|
+
# date a caller would have to parse and subtract. `[[DD-]HH:]MM:SS` is parsed
|
|
561
|
+
# from the right, the way `plot_worker_cpu_centis` parses its clock and for the
|
|
562
|
+
# same reason: an absolute-seconds assumption wraps at 60.
|
|
563
|
+
plot_pid_elapsed_seconds() { # $1=pid → whole seconds, or empty
|
|
564
|
+
local pid="$1" raw
|
|
565
|
+
[ -n "$pid" ] || return 1
|
|
566
|
+
raw=$(ps -o etime= -p "$pid" 2>/dev/null | tr -d ' ') || return 1
|
|
567
|
+
[ -n "$raw" ] || return 1
|
|
568
|
+
printf '%s' "$raw" | awk '
|
|
569
|
+
{
|
|
570
|
+
n = split($0, dh, "-")
|
|
571
|
+
days = (n == 2) ? dh[1] : 0
|
|
572
|
+
t = (n == 2) ? dh[2] : dh[1]
|
|
573
|
+
m = split(t, p, ":")
|
|
574
|
+
total = 0; mult = 1
|
|
575
|
+
for (i = m; i >= 1; i--) { total += p[i] * mult; mult *= 60 }
|
|
576
|
+
print total + (days * 86400)
|
|
577
|
+
}'
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
plot_worker_agent_alive() { # $1=pid → 0 agent present, 1 absent, 2 unaskable
|
|
581
|
+
local root="$1" age
|
|
582
|
+
[ -n "$root" ] || return 2
|
|
583
|
+
case "$root" in *[!0-9]*) return 2 ;; esac
|
|
584
|
+
|
|
585
|
+
# A WRAPPER YOUNGER THAN THE GRACE IS UNASKABLE, NEVER ABSENT. It may be
|
|
586
|
+
# starting its agent right now, and `2` is the answer that says *could not
|
|
587
|
+
# look* — which the callers already resolve to today's behaviour. Absent is
|
|
588
|
+
# not false, and a failure to observe is not evidence of something to see.
|
|
589
|
+
age=$(plot_pid_elapsed_seconds "$root") || age=""
|
|
590
|
+
if [ -n "$age" ] && [ "$age" -lt "$PLOT_AGENT_GRACE_SECONDS" ] 2>/dev/null; then
|
|
591
|
+
return 2
|
|
592
|
+
fi
|
|
593
|
+
|
|
594
|
+
# `comm=` IS THE EXECUTABLE, `command=` IS THE WHOLE INVOCATION, and this
|
|
595
|
+
# needs the second. A wrapper whose argv merely NAMES the agent would match on
|
|
596
|
+
# `command=`, so the match is anchored to the executable's own basename —
|
|
597
|
+
# taken from `comm=`, which macOS truncates but never rewrites.
|
|
598
|
+
ps -o pid=,ppid=,comm= -ax 2>/dev/null | awk -v root="$root" -v want="$PLOT_AGENT_PROCESS" '
|
|
599
|
+
{ pid[$1] = $1; ppid[$1] = $2
|
|
600
|
+
# Everything after pid and ppid is the command; keep its basename.
|
|
601
|
+
c = $0; sub(/^[ \t]*[0-9]+[ \t]+[0-9]+[ \t]+/, "", c)
|
|
602
|
+
sub(/.*\//, "", c)
|
|
603
|
+
comm[$1] = c }
|
|
604
|
+
END {
|
|
605
|
+
if (!(root in pid)) { exit 2 }
|
|
606
|
+
# The same relaxation the CPU walker uses: sweep the ppid map until the
|
|
607
|
+
# subtree stops growing. Depth is unbounded, which is the point.
|
|
608
|
+
inset[root] = 1
|
|
609
|
+
changed = 1
|
|
610
|
+
while (changed) {
|
|
611
|
+
changed = 0
|
|
612
|
+
for (p in ppid) {
|
|
613
|
+
if (!(p in inset) && (ppid[p] in inset)) { inset[p] = 1; changed = 1 }
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
# THE ROOT ITSELF IS EXCLUDED. The recorded pid is the loop shell by
|
|
617
|
+
# construction, and a shell that matched would make every desk read alive.
|
|
618
|
+
for (p in inset) {
|
|
619
|
+
if (p == root) continue
|
|
620
|
+
if (index(comm[p], want) > 0) { exit 0 }
|
|
621
|
+
}
|
|
622
|
+
exit 1
|
|
623
|
+
}'
|
|
624
|
+
}
|
|
625
|
+
|
|
492
626
|
# Whether a RUNNING worker's child is doing work — `working`, `idle`, or "".
|
|
493
627
|
#
|
|
494
628
|
# A CUE, NOT A STATE. The row already reads `running`; this is the secondary
|
|
@@ -691,7 +825,54 @@ plot_worker_state() { # $1=worktree $2=pr-fact → "state\tpid\tcode"
|
|
|
691
825
|
return
|
|
692
826
|
fi
|
|
693
827
|
fi
|
|
694
|
-
#
|
|
828
|
+
# THE WRAPPER LIVES. DOES AN AGENT? `kill -0` answered about the loop shell,
|
|
829
|
+
# and that shell outlives its agent for the whole `Worker bound` — measured
|
|
830
|
+
# 2026-09-11, four agents ended mid-slice and every one reported `running`.
|
|
831
|
+
# So the pid answering is a precondition for this question, never the answer
|
|
832
|
+
# to it.
|
|
833
|
+
#
|
|
834
|
+
# ONLY A DEFINITE ABSENCE MOVES THE READING. Return 2 is *could not look* —
|
|
835
|
+
# a pid that vanished between `kill -0` and here — and it falls through to
|
|
836
|
+
# `running`, which is what this reported before the reading existed. Absent
|
|
837
|
+
# is not false.
|
|
838
|
+
#
|
|
839
|
+
# AND THE QUESTION IS ONLY ASKED OF A DESK PLOT LAUNCHED A WORKER INTO,
|
|
840
|
+
# which `.plot-worker.wrapper.pid` is the proof of. A recorded pid with no
|
|
841
|
+
# wrapper file beside it was never started by `start_worker` — a hand-made
|
|
842
|
+
# desk, or a fixture writing a pid by hand — so Plot has no grounds to
|
|
843
|
+
# expect an agent beneath it, and asking would reinterpret every such pid as
|
|
844
|
+
# an orphan.
|
|
845
|
+
#
|
|
846
|
+
# Measured 2026-09-12 in CI: `--status` reported `finished` for a desk whose
|
|
847
|
+
# recorded pid was the TEST RUNNER — alive 1436 s, with no agent beneath it.
|
|
848
|
+
# The grace window cannot catch that, because the process is old.
|
|
849
|
+
#
|
|
850
|
+
# THE WRAPPER FILE RATHER THAN THE MANIFEST, and that is a measurement too:
|
|
851
|
+
# the one genuinely orphaned desk on this machine carries NO manifest — the
|
|
852
|
+
# registry it was written to has moved — and gating on one defeated the
|
|
853
|
+
# detection for exactly the population this exists to serve. The wrapper
|
|
854
|
+
# file is also the better evidence: the manifest is written by the
|
|
855
|
+
# dispatcher BEFORE the launch, while this file is written by the wrapper
|
|
856
|
+
# process itself, so its presence proves a worker really ran here. It is the
|
|
857
|
+
# file's own rule one line over — *"the process that knows a pid is the one
|
|
858
|
+
# that writes it"*.
|
|
859
|
+
if [ ! -f "$wt/.plot-worker.wrapper.pid" ]; then
|
|
860
|
+
printf 'running\t%s\t' "$pid"
|
|
861
|
+
return
|
|
862
|
+
fi
|
|
863
|
+
if plot_worker_agent_alive "$pid"; then
|
|
864
|
+
printf 'running\t%s\t' "$pid"
|
|
865
|
+
return
|
|
866
|
+
elif [ "$?" -eq 1 ]; then
|
|
867
|
+
# The wrapper is alive and the agent is gone. The DESK decides what that
|
|
868
|
+
# means — `stalled` for work only this machine holds, `waiting` for a
|
|
869
|
+
# marker, `finished` for a desk that is clear — because the process has
|
|
870
|
+
# nothing left to say. No exit file exists: the wrapper has not exited.
|
|
871
|
+
printf '%s\t%s\t' "$(plot_worker_task_state "$wt" "$has_pr")" "$pid"
|
|
872
|
+
return
|
|
873
|
+
fi
|
|
874
|
+
# Unaskable: the process table could not be read for this pid. Report what
|
|
875
|
+
# `kill -0` established and nothing more.
|
|
695
876
|
printf 'running\t%s\t' "$pid"
|
|
696
877
|
return
|
|
697
878
|
fi
|
|
@@ -780,7 +961,9 @@ plot_worker_state() { # $1=worktree $2=pr-fact → "state\tpid\tcode"
|
|
|
780
961
|
#
|
|
781
962
|
# worktree_here pid_recorded liveness exit blocked dirty unpushed
|
|
782
963
|
#
|
|
783
|
-
# `liveness` is `live`, `stale` or `dead
|
|
964
|
+
# `liveness` is `live`, `stale`, `orphaned` or `dead` — `orphaned` being a pid
|
|
965
|
+
# that answers with no agent process under it, which is a live wrapper whose
|
|
966
|
+
# agent has gone; `exit` is the code as read, empty for
|
|
784
967
|
# an unreadable record and the literal `-` for an absent one, because an empty
|
|
785
968
|
# field cannot say which of the two it is and the rule answers them alike only
|
|
786
969
|
# because it was told they differ. The PR fact is NOT here: it comes from the
|
|
@@ -825,7 +1008,23 @@ plot_worker_readings() { # $1=worktree → "here\tpid\tliveness\texit\tblocked\t
|
|
|
825
1008
|
# uncheckable pid honest rather than pessimistic.
|
|
826
1009
|
if [ -n "$started_at" ] && ! plot_pid_is_current "$pid" "$started_at"; then
|
|
827
1010
|
liveness=stale
|
|
1011
|
+
elif [ ! -f "$wt/.plot-worker.wrapper.pid" ]; then
|
|
1012
|
+
# NO WRAPPER FILE, NO AGENT QUESTION — the gate `plot_worker_state`
|
|
1013
|
+
# applies, repeated here because these two must not drift: a desk Plot
|
|
1014
|
+
# never launched a worker into has no agent Plot can expect.
|
|
1015
|
+
liveness=live
|
|
1016
|
+
elif plot_worker_agent_alive "$pid"; then
|
|
1017
|
+
liveness=live
|
|
1018
|
+
elif [ "$?" -eq 1 ]; then
|
|
1019
|
+
# THE FOURTH WORD, and it belongs in this field rather than in a private
|
|
1020
|
+
# branch inside `plot_worker_state`. `stale` set the precedent: it means
|
|
1021
|
+
# *the pid exists and is not our worker*, and this means *the pid exists
|
|
1022
|
+
# and our worker is no longer inside it*. Both are facts about what the
|
|
1023
|
+
# recorded pid names, which is what this field is.
|
|
1024
|
+
liveness=orphaned
|
|
828
1025
|
else
|
|
1026
|
+
# Unaskable — `kill -0` answered, the process table did not. Report what
|
|
1027
|
+
# was established.
|
|
829
1028
|
liveness=live
|
|
830
1029
|
fi
|
|
831
1030
|
fi
|