@soleur/opencode 3.359.8 → 3.359.10
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/lib/harness.ts
CHANGED
|
@@ -500,9 +500,18 @@ export function pollInstructions(harness: Harness): string {
|
|
|
500
500
|
" wind down on its own: it keeps polling the same endpoint at the same cadence",
|
|
501
501
|
" for its full timeout. Layering is the default failure because each re-scope",
|
|
502
502
|
" feels like a new need rather than a replacement.",
|
|
503
|
-
" In the Soleur repo a hook additionally REPORTS a re-arm
|
|
504
|
-
" still watching, naming the task ids to stop. It does not
|
|
505
|
-
"
|
|
503
|
+
" In the Soleur repo a hook additionally REPORTS a re-arm of a hand-rolled `gh pr checks`",
|
|
504
|
+
" loop on a target you are still watching, naming the task ids to stop. It does not",
|
|
505
|
+
" block, and it cannot see the `monitor-pr-checks.sh` command at all. That script",
|
|
506
|
+
" therefore holds its own per-PR lock, which works in any session. A second monitor on a",
|
|
507
|
+
" repo + PR that a live one already watches prints one `DUPLICATE MONITOR` line and exits",
|
|
508
|
+
" 4 without polling. Exit 4 means the PR IS being watched: it is not a PR failure and not",
|
|
509
|
+
" a reason to re-arm. Only if this session still has a running Monitor task for that PR,",
|
|
510
|
+
" read that task's output. Otherwise the holder belongs to a resumed or other session (or",
|
|
511
|
+
" one you already stopped): confirm `ps -o args= -p <pid>` names the script, `kill <pid>`,",
|
|
512
|
+
" then arm once. Killing ends that other session's watch with no verdict line, so a session",
|
|
513
|
+
" whose watch exits with no terminal line should read the PR state, not re-arm. The lock",
|
|
514
|
+
" fails open, loudly, when it cannot be established.",
|
|
506
515
|
"- After merge: watch release workflows to `completed`, then invoke `soleur:postmerge`.",
|
|
507
516
|
"- FORBIDDEN: asking the operator to watch merge/deploy status.",
|
|
508
517
|
"",
|
package/package.json
CHANGED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# shellcheck shell=bash disable=SC2034
|
|
2
|
+
# monitor-lock.sh — per-(repo, PR) exclusion for monitor-pr-checks.sh (P4c of #10924).
|
|
3
|
+
# SOURCED, never executed (so no exec bit). It changes no shell option, is `set -u` safe, and is
|
|
4
|
+
# bash 3.2-safe: no flock, `timeout`, associative arrays, `${x,,}` or `printf %(%s)T` (stock macOS has none).
|
|
5
|
+
# The ML_* variables below are this file's API, read by the sourcing script (hence the SC2034 disable above).
|
|
6
|
+
# Trailing `# mut:<name>` comments are load-bearing: plugins/soleur/test/monitor-lock.test.sh anchors its
|
|
7
|
+
# mutation battery on them. Keep each on its own statement and leave the marker in place when editing.
|
|
8
|
+
#
|
|
9
|
+
# THE LOCK is a symlink $LOCKDIR/pr-checks+<owner>+<repo>+<pr>.lock whose TARGET is the
|
|
10
|
+
# holder record <pid>|<lstart>|<epoch>. `ln -s` is an atomic create-or-fail AND an atomic
|
|
11
|
+
# record (the Emacs lockfile idiom), so there is no half-written window and no flock. The name
|
|
12
|
+
# joins its parts with `+`, which the repo grammar excludes, so `a__b/c` and `a/b__c` cannot
|
|
13
|
+
# collide. The PR number is normalised (`007` is `7`).
|
|
14
|
+
#
|
|
15
|
+
# HOLDER LIVENESS needs all of: a numeric pid, `ps` still lists it (NOT `kill -0`: EPERM reads
|
|
16
|
+
# another user's live process as dead), its state is not zombie, and its recorded start time is
|
|
17
|
+
# present and equals the current one (pid reuse). `lstart` follows the caller's TZ, so every read
|
|
18
|
+
# pins TZ=UTC LC_ALL=C. A holder that fails any test is stale and is reclaimed, under a short
|
|
19
|
+
# `mkdir` guard so two contenders cannot both reclaim the same record.
|
|
20
|
+
#
|
|
21
|
+
# KNOWN RESIDUALS (each degrades to a duplicate monitor, today's behaviour, never to a silent false
|
|
22
|
+
# refusal): a holder in another PID namespace reads as dead; two sessions that resolve different lock
|
|
23
|
+
# directories never see each other; a wall-clock step can shift `lstart`; a holder whose stdout reader
|
|
24
|
+
# vanished keeps the lock until its next write, and INT/QUIT do not stop a backgrounded bash. The key is the
|
|
25
|
+
# repo gh will poll (--repo, GH_REPO, else origin), so on a fork clone where gh resolves a different repo than
|
|
26
|
+
# origin (an `upstream` remote, `gh repo set-default`) it can FALSE-REFUSE a watch of a same-numbered PR in the
|
|
27
|
+
# fork: pass --repo there. A `<lock>.reclaim` guard stuck by a killed reclaimer fails that key open (loudly)
|
|
28
|
+
# until it is a minute or two old, then is swept.
|
|
29
|
+
#
|
|
30
|
+
# API (main shell only: a `$(...)` subshell would drop the state and never run the EXIT trap)
|
|
31
|
+
# monitor_lock_acquire <owner/repo | origin-url> <pr>
|
|
32
|
+
# 0 acquired (or already ours) 1 held by a live OTHER process 2 not established
|
|
33
|
+
# sets ML_STATE (held|held-by-other|disabled|unavailable), ML_WHY, ML_REPO,
|
|
34
|
+
# ML_HOLDER_PID and ML_HOLDER_AGE (rc 1 only)
|
|
35
|
+
# monitor_lock_release
|
|
36
|
+
# removes the link only if it still names us; idempotent; never branches on $?
|
|
37
|
+
#
|
|
38
|
+
# Env: SOLEUR_MONITOR_LOCK=off bypass (loud)
|
|
39
|
+
# SOLEUR_MONITOR_LOCK_DIR lock directory (default $XDG_RUNTIME_DIR or /tmp, per uid)
|
|
40
|
+
# SOLEUR_MONITOR_LOCK_GRACE_S spacing of the two release-race retries on a live holder (1)
|
|
41
|
+
#
|
|
42
|
+
# To see who holds a lock: readlink <lockdir>/pr-checks+<owner>+<repo>+<pr>.lock (pid|lstart|epoch)
|
|
43
|
+
# ps -o args= -p <pid>
|
|
44
|
+
|
|
45
|
+
ML_STATE=""; ML_WHY=""; ML_REPO=""; ML_HOLDER_PID=""; ML_HOLDER_AGE=""
|
|
46
|
+
_ML_LINK=""; _ML_VALUE=""; _ML_D=""
|
|
47
|
+
|
|
48
|
+
# _ml_norm <owner/repo | url> — print lowercase owner/repo, or return 1. Strips any user:token@,
|
|
49
|
+
# scheme, host (must be github.com), trailing `/` and `.git`; the credential never reaches a name.
|
|
50
|
+
# Lowercased FIRST so an upper-case `.GIT` suffix is stripped like `.git`.
|
|
51
|
+
_ml_norm() {
|
|
52
|
+
local s host path rest auth
|
|
53
|
+
s="$(printf '%s' "${1:-}" | tr '[:upper:]' '[:lower:]')"
|
|
54
|
+
s="${s%/}"; s="${s%.git}"; s="${s%/}"
|
|
55
|
+
case "$s" in
|
|
56
|
+
*://*) rest="${s#*://}"; auth="${rest%%/*}"
|
|
57
|
+
case "$rest" in */*) path="${rest#*/}" ;; *) path="" ;; esac
|
|
58
|
+
host="${auth##*@}"; host="${host%%:*}" ;;
|
|
59
|
+
*@*:*) rest="${s#*@}"; host="${rest%%:*}"; path="${rest#*:}" ;;
|
|
60
|
+
github.com/*) host="github.com"; path="${s#*/}" ;; # GH_REPO may carry the host: HOST/OWNER/REPO
|
|
61
|
+
*) host="github.com"; path="$s" ;;
|
|
62
|
+
esac
|
|
63
|
+
case "$host" in github.com|www.github.com) ;; *) return 1 ;; esac
|
|
64
|
+
[[ "$path" =~ ^[a-z0-9][a-z0-9._-]*/[a-z0-9._-]+$ ]] || return 1
|
|
65
|
+
printf '%s' "$path"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# _ml_dir — set _ML_D to a usable lock directory (a real directory, ours, writable, and not writable by
|
|
69
|
+
# group or other), or return 1. The ownership/symlink/mode test is what stops a pre-created hostile
|
|
70
|
+
# /tmp path, or a loosely-shared SOLEUR_MONITOR_LOCK_DIR, from becoming the lock root.
|
|
71
|
+
_ml_dir() {
|
|
72
|
+
local d="${SOLEUR_MONITOR_LOCK_DIR:-${XDG_RUNTIME_DIR:-/tmp}/soleur-monitor-locks-$(id -u 2>/dev/null || echo 0)}"
|
|
73
|
+
local loose
|
|
74
|
+
_ML_D=""
|
|
75
|
+
case "$d" in /*) : ;; *) d="./$d" ;; esac # a relative dir starting with - must not read as a find predicate
|
|
76
|
+
if [ -L "$d" ]; then return 1; fi
|
|
77
|
+
if [ ! -e "$d" ]; then ( umask 077; mkdir -p "$d" ) 2>/dev/null || return 1; fi
|
|
78
|
+
# A failing find must refuse (empty output would otherwise read as "nobody else can write").
|
|
79
|
+
loose="$(find "$d" -maxdepth 0 \( -perm -020 -o -perm -002 \) 2>/dev/null)" || return 1
|
|
80
|
+
if [ -d "$d" ] && [ -O "$d" ] && [ -w "$d" ] && [ -z "$loose" ]; then
|
|
81
|
+
_ML_D="$d"; return 0
|
|
82
|
+
fi
|
|
83
|
+
return 1
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
# _ml_ident <pid> — print "<stat>|<lstart with spaces as _>", or return 1 when ps cannot read it.
|
|
87
|
+
_ml_ident() {
|
|
88
|
+
local out p st rest
|
|
89
|
+
out="$(TZ=UTC LC_ALL=C ps -o pid= -o stat= -o lstart= -p "$1" 2>/dev/null)" || return 1 # mut:tz
|
|
90
|
+
[ -n "$out" ] || return 1
|
|
91
|
+
read -r p st rest <<<"$out"
|
|
92
|
+
[ "$p" = "$1" ] && [ -n "$st" ] || return 1
|
|
93
|
+
printf '%s|%s' "$st" "$(printf '%s' "$rest" | tr -s ' \t' '__')"
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
# _ml_alive <pid> <recorded-lstart> — 0 when that exact process is still running. A record with no
|
|
97
|
+
# start time cannot prove the pid was not reused, so it is stale.
|
|
98
|
+
_ml_alive() {
|
|
99
|
+
local pid="$1" rec="$2" ident st cur
|
|
100
|
+
[[ "$pid" =~ ^[0-9]{1,10}$ ]] && [ "$pid" -ge 1 ] || return 1
|
|
101
|
+
ident="$(_ml_ident "$pid")" || return 1
|
|
102
|
+
st="${ident%%|*}"; cur="${ident#*|}"
|
|
103
|
+
case "$st" in Z*) return 1 ;; esac # mut:zombie
|
|
104
|
+
[ -n "$rec" ] && [ "$rec" = "$cur" ] || return 1 # mut:lstart
|
|
105
|
+
return 0
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
# _ml_reclaim <link> <stale-record> — remove a stale lock, serialised by a `mkdir` guard so that two
|
|
109
|
+
# contenders that both read the same stale record cannot interleave their compare and their remove
|
|
110
|
+
# (the loser would delete the winner's fresh lock). 0 when this call did the reclaim step, 1 when
|
|
111
|
+
# another process holds the guard (the caller retries).
|
|
112
|
+
_ml_reclaim() {
|
|
113
|
+
local g="$1.reclaim"
|
|
114
|
+
if ! mkdir "$g" 2>/dev/null; then
|
|
115
|
+
# A guard left by a reclaimer that died inside its few-microsecond window must not wedge the key.
|
|
116
|
+
if [ -n "$(find "$g" -maxdepth 0 -mmin +1 2>/dev/null)" ]; then rmdir "$g" 2>/dev/null; fi
|
|
117
|
+
return 1
|
|
118
|
+
fi
|
|
119
|
+
# Remove only what we saw: a symlink still naming the stale record, or a regular-file stand-in. An ABSENT link is
|
|
120
|
+
# left alone, since a fresh lock may be created in the instant after we looked.
|
|
121
|
+
if [ -L "$1" ]; then
|
|
122
|
+
if [ "$(readlink "$1" 2>/dev/null)" = "$2" ]; then rm -f "$1"; fi
|
|
123
|
+
elif [ -e "$1" ]; then
|
|
124
|
+
rm -f "$1"
|
|
125
|
+
fi
|
|
126
|
+
rmdir "$g" 2>/dev/null
|
|
127
|
+
return 0
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
_ml_unavailable() { ML_STATE="unavailable"; ML_WHY="$1"; return 2; }
|
|
131
|
+
|
|
132
|
+
monitor_lock_acquire() {
|
|
133
|
+
ML_STATE=""; ML_WHY=""; ML_REPO=""; ML_HOLDER_PID=""; ML_HOLDER_AGE=""; _ML_LINK=""; _ML_VALUE=""
|
|
134
|
+
local pr="${2:-}" key link me ident mylstart value now holder hpid hls hep
|
|
135
|
+
local spins=0 reclaims=0 waited=0 grace="${SOLEUR_MONITOR_LOCK_GRACE_S:-1}"
|
|
136
|
+
if [ "${SOLEUR_MONITOR_LOCK:-}" = "off" ]; then ML_STATE="disabled"; ML_WHY="SOLEUR_MONITOR_LOCK=off"; return 2; fi
|
|
137
|
+
ML_REPO="$(_ml_norm "${1:-}")" || { ML_REPO=""; _ml_unavailable "repo not derivable (needs a github.com owner/repo)"; return 2; }
|
|
138
|
+
# gh honours GH_HOST, and the key names github.com only: another host's same-numbered PR must not collide with it.
|
|
139
|
+
case "${GH_HOST:-github.com}" in github.com|www.github.com) ;; *) _ml_unavailable "GH_HOST targets another host (the lock keys github.com repos only)"; return 2 ;; esac
|
|
140
|
+
[[ "$pr" =~ ^[0-9]{1,9}$ ]] || { _ml_unavailable "PR number is not numeric"; return 2; }
|
|
141
|
+
pr=$((10#$pr))
|
|
142
|
+
_ml_dir || { _ml_unavailable "lock directory unusable (must be a real directory we own, not writable by others)"; return 2; }
|
|
143
|
+
me="$$"
|
|
144
|
+
ident="$(_ml_ident "$me")" || { _ml_unavailable "ps cannot read this process start time"; return 2; }
|
|
145
|
+
mylstart="${ident#*|}"
|
|
146
|
+
now="$(date +%s 2>/dev/null)"; [[ "$now" =~ ^[0-9]{1,10}$ ]] || now=0
|
|
147
|
+
value="$me|$mylstart|$now"
|
|
148
|
+
key="${ML_REPO//\//+}"
|
|
149
|
+
link="$_ML_D/pr-checks+$key+$pr.lock" # mut:key
|
|
150
|
+
while :; do
|
|
151
|
+
spins=$((spins + 1))
|
|
152
|
+
if [ "$spins" -gt 12 ]; then _ml_unavailable "lock contended or not creatable"; return 2; fi
|
|
153
|
+
# A real directory must be refused BEFORE `ln`: given a directory as the link name, ln creates the link
|
|
154
|
+
# INSIDE it. -n stops it following an existing symlink-to-directory the same way.
|
|
155
|
+
if [ -d "$link" ] && [ ! -L "$link" ]; then _ml_unavailable "lock path is a directory"; return 2; fi
|
|
156
|
+
if ln -sn "$value" "$link" 2>/dev/null; then
|
|
157
|
+
_ML_LINK="$link"; _ML_VALUE="$value"; ML_STATE="held"; return 0
|
|
158
|
+
fi
|
|
159
|
+
if [ -L "$link" ]; then
|
|
160
|
+
holder="$(readlink "$link" 2>/dev/null)" || holder=""
|
|
161
|
+
elif [ -e "$link" ]; then
|
|
162
|
+
holder="" # a regular file stand-in: a malformed record, stale
|
|
163
|
+
else
|
|
164
|
+
continue # vanished between ln and the read (a release race); spins bounds the retries
|
|
165
|
+
fi
|
|
166
|
+
IFS='|' read -r hpid hls hep <<<"$holder"
|
|
167
|
+
# Already ours only when the record is OURS in full: a record that merely names our pid (a killed
|
|
168
|
+
# predecessor, or another PID namespace) carries a foreign start time and must be reclaimed, or
|
|
169
|
+
# the next monitor would read this live holder as pid-reused and steal the lock.
|
|
170
|
+
if [ "$hpid" = "$me" ] && [ "$hls" = "$mylstart" ]; then
|
|
171
|
+
_ML_LINK="$link"; _ML_VALUE="$holder"; ML_STATE="held"; return 0
|
|
172
|
+
fi
|
|
173
|
+
if _ml_alive "$hpid" "$hls"; then
|
|
174
|
+
if [ "$waited" -lt 2 ]; then
|
|
175
|
+
waited=$((waited + 1)); sleep "$grace"; continue
|
|
176
|
+
fi
|
|
177
|
+
ML_HOLDER_PID="$hpid"; ML_STATE="held-by-other"
|
|
178
|
+
if [[ "$hep" =~ ^[0-9]{1,10}$ ]] && [ "$now" -ge "$((10#$hep))" ]; then ML_HOLDER_AGE=$((now - 10#$hep)); else ML_HOLDER_AGE="?"; fi
|
|
179
|
+
return 1
|
|
180
|
+
fi
|
|
181
|
+
# Stale: dead, reused pid, zombie, no start time or malformed.
|
|
182
|
+
if [ "$reclaims" -ge 1 ]; then _ml_unavailable "lock contended (stale record reclaimed twice)"; return 2; fi
|
|
183
|
+
if _ml_reclaim "$link" "$holder"; then reclaims=1; else sleep 0.1 2>/dev/null || sleep 1; fi
|
|
184
|
+
done
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
monitor_lock_release() {
|
|
188
|
+
[ -n "$_ML_LINK" ] || return 0
|
|
189
|
+
if [ -L "$_ML_LINK" ] && [ "$(readlink "$_ML_LINK" 2>/dev/null)" = "$_ML_VALUE" ]; then rm -f "$_ML_LINK"; fi # mut:release-cond
|
|
190
|
+
_ML_LINK=""; _ML_VALUE=""
|
|
191
|
+
return 0
|
|
192
|
+
}
|
|
@@ -45,10 +45,23 @@
|
|
|
45
45
|
# Emits one line per poll:
|
|
46
46
|
# [OPEN|BLOCKED|automerge=true] 73/78 pass · 0 fail · 0 cancel · 2 pending → test-scripts,...
|
|
47
47
|
# and exactly one terminal line:
|
|
48
|
-
# MERGED — ... | CLOSED WITHOUT MERGE — ... | CHECKS SETTLED — ... | TIMEOUT — ...
|
|
48
|
+
# MERGED — ... | CLOSED WITHOUT MERGE — ... | CHECKS SETTLED — ... | TIMEOUT — ... | DUPLICATE MONITOR — ... (exit 4)
|
|
49
49
|
#
|
|
50
|
-
# Exit 0 on a merge or an all-green settle; 1 on a red/closed terminal
|
|
51
|
-
#
|
|
50
|
+
# Exit 0 on a merge or an all-green settle; 1 on a red/closed terminal or any stop that needs a human
|
|
51
|
+
# (BEHIND, DIRTY, DRAFT, BLOCKED, LEFT THE MERGE QUEUE UNMERGED, a stalled or unapproved ready run);
|
|
52
|
+
# 2 on timeout; 3 on usage error or when no temp file can be created; 4 when another live monitor already
|
|
53
|
+
# watches this repo + PR (the PR is being watched: not a PR failure, and do not re-arm blindly).
|
|
54
|
+
# The caller's Monitor watch ends when this exits.
|
|
55
|
+
#
|
|
56
|
+
# One monitor per PR (P4c of #10924): after argument validation and the temp-file setup, and BEFORE any gh
|
|
57
|
+
# call, the script takes a per-(repo, PR) lock (lib/monitor-lock.sh). A second monitor waits about
|
|
58
|
+
# 2 x SOLEUR_MONITOR_LOCK_GRACE_S (2 s) in case the holder is releasing, then prints one `DUPLICATE MONITOR`
|
|
59
|
+
# line and exits 4. A lock that cannot be established prints `monitor-lock: UNAVAILABLE (...)` and the watch
|
|
60
|
+
# runs anyway; SOLEUR_MONITOR_LOCK=off bypasses it (prints `DISABLED`). SOLEUR_MONITOR_LOCK_DIR overrides
|
|
61
|
+
# the lock directory. A stale lock (dead, zombie or pid-reused holder) never blocks. The repo is --repo,
|
|
62
|
+
# else GH_REPO, else `git remote get-url origin`. To see a holder:
|
|
63
|
+
# readlink "${XDG_RUNTIME_DIR:-/tmp}/soleur-monitor-locks-$(id -u)/pr-checks+<owner>+<repo>+<pr>.lock"
|
|
64
|
+
# (owner and repo lowercased). On a fork clone where gh resolves a different repo than origin, pass --repo.
|
|
52
65
|
#
|
|
53
66
|
# CI_DRAFT_LIGHT (ADR-276 S3, #9728): a red `test` row is read through ci-head-verdict.sh. pending-full and no-run report it
|
|
54
67
|
# PENDING (`test(ready run <state>)`), stalled and awaiting-approval end the watch (exit 1) with the recovery command, and
|
|
@@ -103,7 +116,52 @@ if [[ -z "$ERRTMP" || ! -w "$ERRTMP" ]]; then
|
|
|
103
116
|
"${TMPDIR:-/tmp}" >&2
|
|
104
117
|
exit 3
|
|
105
118
|
fi
|
|
106
|
-
|
|
119
|
+
|
|
120
|
+
# Per-PR monitor lock (P4c of #10924). ONE exit funnel: every way out after the lock is taken (terminal
|
|
121
|
+
# verdicts, TERM, HUP) runs _cleanup via the EXIT trap. There is deliberately NO INT/TERM trap: a trapped
|
|
122
|
+
# TERM is deferred until the foreground `sleep` below returns, which keeps the lock for up to --interval
|
|
123
|
+
# after the watch was stopped (the plugin test pins a release within 4 s of TERM at --interval 10).
|
|
124
|
+
# SIGKILL runs no trap; the next monitor reclaims the dead holder's lock instead.
|
|
125
|
+
ML_LIB="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd -P)/lib/monitor-lock.sh"
|
|
126
|
+
ML_LOADED=0
|
|
127
|
+
if [[ -r "$ML_LIB" ]]; then
|
|
128
|
+
# shellcheck source=lib/monitor-lock.sh
|
|
129
|
+
source "$ML_LIB" && ML_LOADED=1
|
|
130
|
+
fi
|
|
131
|
+
[[ "$ML_LOADED" == "1" ]] || monitor_lock_release() { :; }
|
|
132
|
+
_cleanup() {
|
|
133
|
+
monitor_lock_release # mut:cleanup-release
|
|
134
|
+
rm -f "$ERRTMP"
|
|
135
|
+
}
|
|
136
|
+
trap _cleanup EXIT
|
|
137
|
+
|
|
138
|
+
# acquire_or_exit — the ONE chokepoint for the lock. Runs in the main shell (a `$(...)` subshell would
|
|
139
|
+
# drop the lock state and never run the EXIT trap). A live other holder -> one terminal line, exit 4, no gh call.
|
|
140
|
+
# Anything that merely prevents the lock from being established runs the watch anyway, loudly.
|
|
141
|
+
acquire_or_exit() {
|
|
142
|
+
local lock_repo lrc=0
|
|
143
|
+
if [[ "$ML_LOADED" != "1" ]]; then
|
|
144
|
+
echo "monitor-lock: UNAVAILABLE (lib/monitor-lock.sh not found or not loadable next to this script) - running without exclusion"
|
|
145
|
+
return 0
|
|
146
|
+
fi
|
|
147
|
+
# The repo gh will poll: --repo, else GH_REPO, else the origin remote. `remote get-url` resolves url.insteadOf
|
|
148
|
+
# aliases that `config --get` returns raw (an aliased origin would otherwise silently lose the lock).
|
|
149
|
+
lock_repo="${REPO_ARG[1]:-${GH_REPO:-}}"
|
|
150
|
+
[[ -n "$lock_repo" ]] || lock_repo="$(git remote get-url origin 2>/dev/null || git config --get remote.origin.url 2>/dev/null || true)"
|
|
151
|
+
monitor_lock_acquire "$lock_repo" "$PR" || lrc=$?
|
|
152
|
+
case "$lrc" in
|
|
153
|
+
0) return 0 ;;
|
|
154
|
+
1) printf 'DUPLICATE MONITOR — PR #%s is already watched by pid %s (watching for %ss, repo %s). This watch exits without polling. Only if this session still has a running Monitor task for that PR, read that task'"'"'s output. Otherwise it belongs to a resumed or other session (or one you already stopped): check that "ps -o args= -p %s" names monitor-pr-checks.sh, then stop it with: kill %s — and arm this watch once.\n' \
|
|
155
|
+
"$PR" "$ML_HOLDER_PID" "$ML_HOLDER_AGE" "$ML_REPO" "$ML_HOLDER_PID" "$ML_HOLDER_PID"
|
|
156
|
+
exit 4 ;;
|
|
157
|
+
*) if [[ "$ML_STATE" == "disabled" ]]; then
|
|
158
|
+
echo "monitor-lock: DISABLED (SOLEUR_MONITOR_LOCK=off) - running without exclusion"
|
|
159
|
+
else
|
|
160
|
+
echo "monitor-lock: UNAVAILABLE (${ML_WHY:-unknown}) - running without exclusion"
|
|
161
|
+
fi ;;
|
|
162
|
+
esac
|
|
163
|
+
return 0
|
|
164
|
+
}
|
|
107
165
|
|
|
108
166
|
# ── Red-on-main annotation (terminal-fail exit path ONLY) ─────────────────────
|
|
109
167
|
# Runs at most once per watch — never per-tick. The gh budget for this is
|
|
@@ -211,6 +269,7 @@ ci_verdict() {
|
|
|
211
269
|
case "$m" in n/a|full-decided|pending-full|no-run|stalled|awaiting-approval) V_STATE="$m" ;; *) return 1 ;; esac
|
|
212
270
|
}
|
|
213
271
|
|
|
272
|
+
acquire_or_exit
|
|
214
273
|
n=0; prev_sig=""; queue_seen=0
|
|
215
274
|
while :; do
|
|
216
275
|
n=$((n + 1))
|
|
@@ -111,7 +111,7 @@ See `knowledge-base/project/learnings/workflow-patterns/2026-06-30-update-branch
|
|
|
111
111
|
|
|
112
112
|
### 7. Cleanup + report
|
|
113
113
|
|
|
114
|
-
Arming returns at ENQUEUE, not at merge. Run `cleanup-merged` only once the PRs it should reap read `MERGED`. Wait on each enqueued PR with a BOUND (90 polls x 60s, the Phase 7 cap), through the Monitor tool / AwaitShell (never a backgrounded loop): `bash "${CLAUDE_PLUGIN_ROOT}/scripts/monitor-pr-checks.sh" <N> --interval 60 --max-polls 90`. It reads the merge queue (`sync-pr-behind.sh <N> --queue-state`) and ends `MERGED`, or `LEFT THE MERGE QUEUE UNMERGED` with the removal reason (the dequeue arm above: ONE re-enqueue, then report), or a timeout; it never syncs or pushes. An enqueued PR that never reaches `MERGED` is that dequeue arm, not a merged PR:
|
|
114
|
+
Arming returns at ENQUEUE, not at merge. Run `cleanup-merged` only once the PRs it should reap read `MERGED`. Wait on each enqueued PR with a BOUND (90 polls x 60s, the Phase 7 cap), through the Monitor tool / AwaitShell (never a backgrounded loop): `bash "${CLAUDE_PLUGIN_ROOT}/scripts/monitor-pr-checks.sh" <N> --interval 60 --max-polls 90`. It reads the merge queue (`sync-pr-behind.sh <N> --queue-state`) and ends `MERGED`, or `LEFT THE MERGE QUEUE UNMERGED` with the removal reason (the dequeue arm above: ONE re-enqueue, then report), or a timeout; it never syncs or pushes. A watch that exits 4 (`DUPLICATE MONITOR`) means a live monitor already watches that PR (a re-run drain re-arms every enqueued PR, so this is the expected outcome there). If that watch is a Monitor or AwaitShell task of THIS session, it is still your watch: read its output. Otherwise it reports to a session that may be gone: read the queue once with `sync-pr-behind.sh <N> --queue-state` (a `dequeued` answer is the dequeue arm below; `gh pr view` cannot show a silent dequeue), keep the PR in the set awaiting `MERGED`, never count it as done, and never loop on that read. To hear the outcome yourself, confirm `ps -o args= -p <pid>` names `monitor-pr-checks.sh`, `kill <pid>` (that ends the other session's watch with no verdict line, so that session must read the PR state rather than re-arm), and arm once. An enqueued PR that never reaches `MERGED` is that dequeue arm, not a merged PR:
|
|
115
115
|
|
|
116
116
|
```bash
|
|
117
117
|
bash "${CLAUDE_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree-manager.sh" cleanup-merged
|
|
@@ -117,6 +117,12 @@ case "$-" in
|
|
|
117
117
|
;;
|
|
118
118
|
esac
|
|
119
119
|
|
|
120
|
+
# Count --agents-expected from the panel THIS diff's class prescribes AFTER the
|
|
121
|
+
# skill's own substitutions (the structural-enumeration seat replaces one
|
|
122
|
+
# adversarial seat; shellcheck replaces semgrep on a bash-only diff), not from
|
|
123
|
+
# every seat considered. An over-count commits `Reviewed-Coverage: degraded`;
|
|
124
|
+
# the fix is a `git reset --soft` of the unpushed empty commits and a re-emit.
|
|
125
|
+
# Why: #11286 — expected 11 for a 9-seat panel.
|
|
120
126
|
usage() {
|
|
121
127
|
cat <<'EOF'
|
|
122
128
|
Usage: emit-review-trailer.sh [--findings <n>] [--summary <text>]
|