@soleur/opencode 3.354.29 → 3.354.30
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/package.json
CHANGED
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
# consume the marker, so a PR the agent fixed and re-armed is not reported again. The
|
|
51
51
|
# fences reach this on a BEHIND tick via --step and on every 5th OPEN tick via --queue-state.
|
|
52
52
|
# Before 1. Armed BEHIND on a merge-queue repo (2026-10-09, PR 9839; extended to --step and the hook 2026-10-20, #9869): a PR
|
|
53
|
-
# that GitHub reports BEHIND or UNKNOWN (never DIRTY), with auto-merge armed and a merge_queue rule on
|
|
54
|
-
# before any git work — nothing fetched, merged or pushed. The window it closes is between the arm and the enqueue, where
|
|
53
|
+
# that GitHub reports BEHIND or UNKNOWN (never DIRTY), with auto-merge armed and a merge_queue rule on the PR's OWN base branch (its
|
|
54
|
+
# baseRefName; #10832), is skipped before any git work — nothing fetched, merged or pushed. The window it closes is between the arm and the enqueue, where
|
|
55
55
|
# queue_gate sees no entry and a push restarts every required check for nothing. ONE predicate (queue_wait_eval() below)
|
|
56
56
|
# serves three callers: the standalone loop answers `kind=queue_wait` rc=0 (exit 0); a FLAGLESS `--step` answers
|
|
57
57
|
# `kind=queue_wait` rc=14 (exit 14: not 11, the fences' uncounted no-op arm, which an OLD pasted fence would loop on
|
|
@@ -59,6 +59,13 @@
|
|
|
59
59
|
# pre-merge hook. The Phase 7 fences pass `--fence`, which skips the guard entirely: the fence owns the queue-mode
|
|
60
60
|
# decision and its expiry fallback, and its legitimate sync arms (expiry, DIRTY-derived BEHIND, no merge_queue rule, a
|
|
61
61
|
# failed armed read) must still sync. `--fence` is accident prevention, not authentication.
|
|
62
|
+
# Interim non-main refusal (#10832): this script's sync merges origin/main, so an ARMED BEHIND or UNKNOWN PR whose base is not
|
|
63
|
+
# main and has NO merge_queue rule (or whose base name is empty or outside the allowlist: `badbase` also refuses a git-legal name
|
|
64
|
+
# such as `rel+1` or `topic@x`, even when that base has a queue) is not synced either: flagless `--step` and the standalone loop
|
|
65
|
+
# answer `kind=gh` exit 4 with a NOT A TRANSIENT ERROR text, `--queue-wait` prints `queue_wait` (read-only; the hook would treat a
|
|
66
|
+
# non-zero exit as "sync anyway"). UNKNOWN is refused at flagless `--step` and `--queue-wait` only: the standalone loop exits
|
|
67
|
+
# `not_behind` for it before the guard. It does not cover `--fence`, a disarmed, DIRTY, BLOCKED or CLEAN PR, or the fences' own
|
|
68
|
+
# expiry arm; a convenience interlock, not an authorization boundary. An unknown internal verdict fails CLOSED at every caller.
|
|
62
69
|
# Every tagged line is `[pr-behind-sync] kind=<k> rc=<n> — …` on STDOUT (a Monitor
|
|
63
70
|
# streams stdout only). rc is git's own exit status where a git command failed, else
|
|
64
71
|
# this script's exit code. Exit codes: see usage() / --help — the one table.
|
|
@@ -96,9 +103,13 @@ usage: sync-pr-behind.sh <pr-number> [--max-attempts N]
|
|
|
96
103
|
--step one sync attempt on the current branch (merge origin/main, push).
|
|
97
104
|
A PR in the merge queue is skipped (a push would dequeue it). Without
|
|
98
105
|
--fence it also refuses an OPEN, armed PR that GitHub reports BEHIND or
|
|
99
|
-
UNKNOWN (never DIRTY)
|
|
100
|
-
kind=queue_wait, exit 14, nothing fetched, merged or pushed (the queue
|
|
101
|
-
makes the PR current; a resync restarts every required check).
|
|
106
|
+
UNKNOWN (never DIRTY) whose own base branch (baseRefName) has a merge_queue
|
|
107
|
+
rule: kind=queue_wait, exit 14, nothing fetched, merged or pushed (the queue
|
|
108
|
+
makes the PR current; a resync restarts every required check). A non-main
|
|
109
|
+
base with no merge_queue rule, or an empty or unsupported base name (also a
|
|
110
|
+
git-legal name outside the allowlist, e.g. rel+1, even if that base has a
|
|
111
|
+
queue), is refused too, while armed: kind=gh, exit 4 (this script only merges
|
|
112
|
+
origin/main; sync by hand against that base). The Phase
|
|
102
113
|
7 fence's call: the fence owns the queue-mode decision (rule, armed,
|
|
103
114
|
expiry); do not call it from your own loop
|
|
104
115
|
--fence with --step only: the Phase 7 / merge-pr poll fences pass this;
|
|
@@ -115,8 +126,10 @@ usage: sync-pr-behind.sh <pr-number> [--max-attempts N]
|
|
|
115
126
|
PR_QUEUE_TIMEOUT and PR_QUEUE_REPO (one attempt, no retry)
|
|
116
127
|
--queue-wait print `queue_wait` or `proceed` and exit 0, or `kind=gh` exit 4 (a failed, hung or
|
|
117
128
|
unparseable read is never read as `proceed`). `queue_wait` = the PR is OPEN, GitHub
|
|
118
|
-
reports BEHIND or UNKNOWN (not DIRTY), auto-merge is armed and
|
|
119
|
-
rule
|
|
129
|
+
reports BEHIND or UNKNOWN (not DIRTY), auto-merge is armed and the PR's own base branch has a
|
|
130
|
+
merge_queue rule; also printed for an armed BEHIND PR whose base is not main and has no
|
|
131
|
+
merge_queue rule, or is empty or unsupported (this script only merges origin/main). One
|
|
132
|
+
pr view snapshot (state, mergeStateStatus, autoMergeRequest, baseRefName) and one rules
|
|
120
133
|
read; no GraphQL queue read, no worktree, nothing written. The pre-merge hook calls it
|
|
121
134
|
after --queue-state said not_queued. `--queue-state`: is the PR in the queue;
|
|
122
135
|
`--queue-wait`: should a sync be skipped. Env: PR_QUEUE_TIMEOUT and PR_QUEUE_REPO (the pr view read is a single attempt)
|
|
@@ -132,7 +145,11 @@ exit codes (each non-zero exit prints one tagged `kind=<k> rc=<n>` line on stdou
|
|
|
132
145
|
2 usage error or unknown argument (kind=usage)
|
|
133
146
|
3 not inside a work tree (kind=not_worktree)
|
|
134
147
|
4 a gh call failed (kind=gh): gh pr view (standalone, flagless --step, --queue-wait), the merge-queue
|
|
135
|
-
read after one retry, or (armed BEHIND PR) the
|
|
148
|
+
read after one retry, or (armed BEHIND PR) the merge-queue rule read of the PR's base branch; also,
|
|
149
|
+
for an ARMED BEHIND PR (UNKNOWN: flagless --step only; the standalone loop exits not_behind for it
|
|
150
|
+
first): a non-main base with no merge-queue rule, or an empty or unsupported base name (standalone,
|
|
151
|
+
flagless --step; NOT A TRANSIENT ERROR, nothing merged or pushed; not under --fence; --queue-wait
|
|
152
|
+
answers `queue_wait` with exit 0 for the same PR, so the pre-merge hook skips its own merge)
|
|
136
153
|
5 fetching main failed (kind=fetch)
|
|
137
154
|
6 merge conflict, or merge not committed (hook) — the merge was aborted (kind=merge)
|
|
138
155
|
7 git push failed — the local merge commit is retained (kind=push)
|
|
@@ -181,6 +198,42 @@ if [[ "$NMODE" -gt 1 ]]; then usage_err "at most one of --step, --queue-state, -
|
|
|
181
198
|
if [[ "$FENCE" == 1 && "$MODE" != step ]]; then usage_err "--fence is only valid with --step"; fi
|
|
182
199
|
if [[ "$MODE" != loop && "$MAX_ATTEMPTS" != 1 ]]; then usage_err "--step, --queue-state and --queue-wait take no --max-attempts"; fi
|
|
183
200
|
|
|
201
|
+
# The env bounds and the stderr sanitiser, once each (#10832; before this they were pasted into four readers and three sanitised
|
|
202
|
+
# strings, so a change to a bound or to the sanitiser had to be made in every copy). qb_bounds sets QB_TIMEOUT / QB_ATTEMPTS / QB_NAP
|
|
203
|
+
# from PR_QUEUE_TIMEOUT / PR_QUEUE_ATTEMPTS / PR_QUEUE_RETRY_SLEEP, each clamped to its documented range (anything else is the
|
|
204
|
+
# default); EVERY reader (queue_state_read, queue_read_settled, queue_wait_eval, qw_snapshot) calls it itself first and reads the
|
|
205
|
+
# QB_* globals directly. QB_* (and QW_BASE, which queue_wait_eval resets on entry) are deliberately NOT initialised here, so that a reader
|
|
206
|
+
# reading them before ANY qb_bounds call aborts under `set -u` (loud) instead of running on defaults that ignore the env. That net is
|
|
207
|
+
# thin: once one reader has called qb_bounds the globals exist for every later reader on the path, so the guarantee that each reader
|
|
208
|
+
# calls it first is the S1 census in the test suite, not `set -u`. qb_bounds is called directly, never inside `$( )`, so the globals
|
|
209
|
+
# survive. qb_clean is a stdin filter for gh's raw stderr, which reaches a
|
|
210
|
+
# model-visible `kind=gh` line: only [:alnum:] and ._:/=- and space survive (ESC, CR and a forged tag line cannot); LC_ALL=C because BSD
|
|
211
|
+
# tr (macOS) is locale-aware. Neither helper exits. qb_match <string> <ERE> classifies under LC_ALL=C in a subshell (qw_base_path's trick):
|
|
212
|
+
# under a UTF-8 locale `[^[:space:]]` also excludes U+2003, U+3000 and U+2028, all legal in a ref name, so a strict answer regex run in the
|
|
213
|
+
# caller's locale would fail on such a base and turn a refusal into `kind=gh` rc 4, which the hook reads as "sync anyway". A match is only
|
|
214
|
+
# a classification: the caller then splits the answer with `read -r` (no BASH_REMATCH survives the subshell).
|
|
215
|
+
LOOP_BASEREF="" # the standalone loop's base branch, set once before the loop; initialised because queue_wait_gate reads it under set -u
|
|
216
|
+
qb_bounds() {
|
|
217
|
+
QB_TIMEOUT="${PR_QUEUE_TIMEOUT:-10}"; QB_ATTEMPTS="${PR_QUEUE_ATTEMPTS:-2}"; QB_NAP="${PR_QUEUE_RETRY_SLEEP:-2}"
|
|
218
|
+
[[ "$QB_TIMEOUT" =~ ^[1-9][0-9]{0,3}$ ]] || QB_TIMEOUT=10
|
|
219
|
+
[[ "$QB_ATTEMPTS" =~ ^[1-9]$ ]] || QB_ATTEMPTS=2
|
|
220
|
+
[[ "$QB_NAP" =~ ^[0-9]{1,3}$ ]] || QB_NAP=2
|
|
221
|
+
}
|
|
222
|
+
qb_clean() { LC_ALL=C tr -c '[:alnum:] ._:/=-' '?'; }
|
|
223
|
+
qb_match() ( LC_ALL=C; [[ "$1" =~ $2 ]] )
|
|
224
|
+
# qw_base_path <base> — prints the rules-URL path segment for a PR's base branch, exit 1 for an empty or unsupported name. A branch name
|
|
225
|
+
# is untrusted text (the PR author edits it) that reaches an API path and a model-visible line, so only plain components of
|
|
226
|
+
# [A-Za-z0-9._-] joined by single `/` are accepted (no `%`, `?`, `#`, `//`, a leading `.` or `-`, `..`, `.lock`; at most 255 characters)
|
|
227
|
+
# and the `/` is encoded as %2F (the admin-merge-ready.sh precedent). Hand-rolled and stricter than that script's regex on purpose: this
|
|
228
|
+
# script has no standalone jq and targets macOS bash 3.2, and here the value is echoed. A subshell function body, so LC_ALL=C (a locale
|
|
229
|
+
# range like [A-Za-z] accepts accented letters) cannot leak and `exit` cannot end the script.
|
|
230
|
+
qw_base_path() (
|
|
231
|
+
LC_ALL=C; b="${1:-}"
|
|
232
|
+
[[ ${#b} -le 255 && "$b" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*(/[A-Za-z0-9][A-Za-z0-9._-]*)*$ ]] || exit 1
|
|
233
|
+
[[ "$b" != *..* && "$b" != *.lock && "$b" != *.lock/* ]] || exit 1
|
|
234
|
+
printf '%s' "${b//\//%2F}"
|
|
235
|
+
)
|
|
236
|
+
|
|
184
237
|
# queue_state_read — THE ONE copy of the merge-queue GraphQL read and its jq verdict program (the
|
|
185
238
|
# pre-merge hook and monitor-pr-checks.sh reach it through --queue-state). Sets QS_OUT to
|
|
186
239
|
# `<queued|not_queued> <state> <armed|disarmed> removal=<reason|none>` (`-` for a field the answer lacks;
|
|
@@ -192,15 +245,12 @@ if [[ "$MODE" != loop && "$MAX_ATTEMPTS" != 1 ]]; then usage_err "--step, --queu
|
|
|
192
245
|
# `bash -c` so a gh that is a shell function (an exported test mock) is still reached, and under
|
|
193
246
|
# timeout/gtimeout when present so a hung call cannot hang a poll tick or a hook.
|
|
194
247
|
queue_state_read() {
|
|
195
|
-
|
|
248
|
+
qb_bounds
|
|
196
249
|
local owner='{owner}' repo='{repo}' n=0 rc out errf query jqp
|
|
197
|
-
[[ "$to_s" =~ ^[1-9][0-9]{0,3}$ ]] || to_s=10
|
|
198
|
-
[[ "$attempts" =~ ^[1-9]$ ]] || attempts=2
|
|
199
|
-
[[ "$nap" =~ ^[0-9]{1,3}$ ]] || nap=2
|
|
200
250
|
if [[ "${PR_QUEUE_REPO:-}" =~ ^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$ ]]; then owner="${PR_QUEUE_REPO%%/*}"; repo="${PR_QUEUE_REPO#*/}"; fi
|
|
201
251
|
local to=()
|
|
202
|
-
if command -v timeout >/dev/null 2>&1; then to=(timeout -k 2 "$
|
|
203
|
-
elif command -v gtimeout >/dev/null 2>&1; then to=(gtimeout -k 2 "$
|
|
252
|
+
if command -v timeout >/dev/null 2>&1; then to=(timeout -k 2 "$QB_TIMEOUT")
|
|
253
|
+
elif command -v gtimeout >/dev/null 2>&1; then to=(gtimeout -k 2 "$QB_TIMEOUT"); fi
|
|
204
254
|
# shellcheck disable=SC2016 # the GraphQL `$owner`/`$name`/`$number` are variables of the query, not shell
|
|
205
255
|
query='
|
|
206
256
|
query($owner: String!, $name: String!, $number: Int!) {
|
|
@@ -229,7 +279,7 @@ query($owner: String!, $name: String!, $number: Int!) {
|
|
|
229
279
|
else "-" end)
|
|
230
280
|
end'
|
|
231
281
|
errf="$(mktemp)" || { QS_CAUSE=gh_error; QS_DETAIL="mktemp failed"; return 1; } # lint-trap-ownership: ok — removed by rm -f on every return path of queue_state_read; a kill leaves one tiny file
|
|
232
|
-
while [[ "$n" -lt "$
|
|
282
|
+
while [[ "$n" -lt "$QB_ATTEMPTS" ]]; do
|
|
233
283
|
n=$((n + 1)); rc=0
|
|
234
284
|
# shellcheck disable=SC2016 # $1..$5 are bash -c's own positional parameters, not this shell's
|
|
235
285
|
out="$(${to[@]+"${to[@]}"} bash -c 'gh api graphql -F owner="$4" -F name="$5" -F number="$1" -f query="$2" --jq "$3"' \
|
|
@@ -237,7 +287,7 @@ query($owner: String!, $name: String!, $number: Int!) {
|
|
|
237
287
|
if [[ "$rc" -ne 0 ]]; then
|
|
238
288
|
case "$rc" in 124|137|143) QS_CAUSE=timeout ;; *) QS_CAUSE=gh_error ;; esac
|
|
239
289
|
# gh's raw stderr reaches the `kind=gh rc=4` line a Monitor streams to the model: ESC, CR and a forged tag line must not.
|
|
240
|
-
QS_DETAIL="$(printf '%s' "rc=$rc $(head -c 200 "$errf")" |
|
|
290
|
+
QS_DETAIL="$(printf '%s' "rc=$rc $(head -c 200 "$errf")" | qb_clean)"
|
|
241
291
|
else
|
|
242
292
|
out="${out%%$'\n'*}"
|
|
243
293
|
case "${out%% *}" in
|
|
@@ -245,7 +295,7 @@ query($owner: String!, $name: String!, $number: Int!) {
|
|
|
245
295
|
*) QS_CAUSE=unparseable; QS_DETAIL="read returned '${out:0:80}' (want queued or not_queued)" ;;
|
|
246
296
|
esac
|
|
247
297
|
fi
|
|
248
|
-
if [[ "$n" -lt "$
|
|
298
|
+
if [[ "$n" -lt "$QB_ATTEMPTS" ]]; then sleep "$QB_NAP"; fi
|
|
249
299
|
done
|
|
250
300
|
rm -f "$errf"
|
|
251
301
|
return 1
|
|
@@ -267,10 +317,9 @@ dq_candidate() {
|
|
|
267
317
|
# dequeue candidate, so the instant the queue's own merge lands (not queued, OPEN, about to read MERGED) is never
|
|
268
318
|
# reported as a dequeue. Returns 1 (QS_CAUSE set) when either read fails: a failed read is never a verdict.
|
|
269
319
|
queue_read_settled() {
|
|
270
|
-
|
|
271
|
-
[[ "$nap" =~ ^[0-9]{1,3}$ ]] || nap=2
|
|
320
|
+
qb_bounds
|
|
272
321
|
queue_state_read || return 1
|
|
273
|
-
if dq_candidate "$1"; then sleep "$
|
|
322
|
+
if dq_candidate "$1"; then sleep "$QB_NAP"; queue_state_read || return 1; fi
|
|
274
323
|
return 0
|
|
275
324
|
}
|
|
276
325
|
|
|
@@ -278,95 +327,151 @@ queue_read_settled() {
|
|
|
278
327
|
# #9869). Between `gh pr merge --auto` and the enqueue a PR is OPEN, BEHIND, armed and NOT in the queue, so queue_gate (which
|
|
279
328
|
# only sees an entry) lets it through, and a sync there pushes a commit that restarts every required check for nothing: on a
|
|
280
329
|
# merge-queue repo the queue makes the PR current itself. Fires when the PR is OPEN, GitHub says BEHIND or UNKNOWN (UNKNOWN is
|
|
281
|
-
# recompute lag; DIRTY never: a conflicting or kb-index-class PR still resolves) AND auto-merge is armed AND
|
|
282
|
-
# merge_queue rule (one rules read, selected by `.type`, never by position: merge_queue is not the first rule on a live repo, and
|
|
330
|
+
# recompute lag; DIRTY never: a conflicting or kb-index-class PR still resolves) AND auto-merge is armed AND the PR's own base
|
|
331
|
+
# branch has a merge_queue rule (one rules read, selected by `.type`, never by position: merge_queue is not the first rule on a live repo, and
|
|
283
332
|
# the read asks for 100 rules per page: a merge_queue beyond rule 100 would read as absent). It always RETURNS 0 and reports
|
|
284
|
-
# through QW_VERDICT (wait | proceed | unreadable) and QW_DETAIL: a distinct non-zero return would kill a caller under
|
|
333
|
+
# through QW_VERDICT (wait | proceed | unreadable | badbase | foreign) and QW_DETAIL: a distinct non-zero return would kill a caller under
|
|
285
334
|
# `set -euo pipefail` on the common proceed path. A rules read that still fails after PR_QUEUE_ATTEMPTS tries (default 2, like
|
|
286
335
|
# queue_state_read), or answers empty or non-numeric, is `unreadable`: the one place this script fails CLOSED on an unreadable
|
|
287
|
-
# rules answer (ADR-270 addendum 2026-10-09) — an unknown answer is not a yes. The cause is in QW_DETAIL.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
336
|
+
# rules answer (ADR-270 addendum 2026-10-09) — an unknown answer is not a yes. The cause is in QW_DETAIL. The rules read is of the
|
|
337
|
+
# PR's OWN base branch (its baseRefName, the third argument: #10832), not a fixed `main`; the URL for base `main` is unchanged. The base
|
|
338
|
+
# is validated (qw_base_path) only AFTER the OPEN, BEHIND/UNKNOWN and armed checks, so a PR that never reaches the rules read is never
|
|
339
|
+
# affected by an odd or empty base. Two more internal verdicts besides wait / proceed / unreadable, each with its own arm at every caller (and a fail-closed `*)` arm for anything else): `badbase` (the base is empty or
|
|
340
|
+
# unsupported: no request is made) and `foreign` (the base is not `main` and has no merge_queue rule: this script's sync merges
|
|
341
|
+
# origin/main, which is wrong for that PR, so the guarded callers refuse rather than sync). The refusal is a convenience interlock, not
|
|
342
|
+
# an authorization boundary: a PR author can retarget between the snapshot and the read.
|
|
343
|
+
queue_wait_eval() { # <state_line: "<STATE> <MERGESTATE>"> <armed|disarmed|-> <base>
|
|
344
|
+
qb_bounds
|
|
345
|
+
local am="$2" base="${3:-}" out="" rc=0 n=0 detail="" errf owner='{owner}' repo='{repo}' bp="" to=()
|
|
346
|
+
QW_VERDICT=proceed; QW_DETAIL=""; QW_BASE=""
|
|
292
347
|
[[ "$1" == OPEN\ * ]] || return 0
|
|
293
348
|
[[ ( "$1" == *BEHIND* || "$1" == *UNKNOWN* ) && "$1" != *DIRTY* ]] || return 0
|
|
294
349
|
[[ "$am" == armed ]] || return 0
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
350
|
+
if ! bp="$(qw_base_path "$base")"; then
|
|
351
|
+
QW_VERDICT=badbase; QW_DETAIL="base branch '$(printf '%s' "$base" | qb_clean | cut -c1-60)' is empty or not a supported branch name"
|
|
352
|
+
return 0
|
|
353
|
+
fi
|
|
354
|
+
QW_BASE="$base"
|
|
298
355
|
if [[ "${PR_QUEUE_REPO:-}" =~ ^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$ ]]; then owner="${PR_QUEUE_REPO%%/*}"; repo="${PR_QUEUE_REPO#*/}"; fi
|
|
299
|
-
if command -v timeout >/dev/null 2>&1; then to=(timeout -k 2 "$
|
|
300
|
-
elif command -v gtimeout >/dev/null 2>&1; then to=(gtimeout -k 2 "$
|
|
356
|
+
if command -v timeout >/dev/null 2>&1; then to=(timeout -k 2 "$QB_TIMEOUT")
|
|
357
|
+
elif command -v gtimeout >/dev/null 2>&1; then to=(gtimeout -k 2 "$QB_TIMEOUT"); fi
|
|
301
358
|
errf="$(mktemp)" || { QW_VERDICT=unreadable; QW_DETAIL="rule read not attempted (mktemp failed)"; return 0; } # lint-trap-ownership: ok — removed by rm -f on every return path of queue_wait_eval; a kill leaves one tiny file
|
|
302
|
-
while [[ "$n" -lt "$
|
|
359
|
+
while [[ "$n" -lt "$QB_ATTEMPTS" ]]; do
|
|
303
360
|
n=$((n + 1)); rc=0
|
|
304
|
-
# shellcheck disable=SC2016 # $1..$
|
|
305
|
-
out="$(${to[@]+"${to[@]}"} bash -c 'gh api "repos/$1/$2/rules/branches
|
|
306
|
-
_ "$owner" "$repo" '[.[] | select(.type == "merge_queue")] | length' 2>"$errf")" || rc=$?
|
|
361
|
+
# shellcheck disable=SC2016 # $1..$4 are bash -c's own positional parameters, not this shell's
|
|
362
|
+
out="$(${to[@]+"${to[@]}"} bash -c 'gh api "repos/$1/$2/rules/branches/$4?per_page=100" --jq "$3"' \
|
|
363
|
+
_ "$owner" "$repo" '[.[] | select(.type == "merge_queue")] | length' "$bp" 2>"$errf")" || rc=$?
|
|
307
364
|
out="${out%%$'\n'*}"
|
|
308
365
|
if [[ "$rc" -eq 0 && "$out" =~ ^[0-9]{1,6}$ ]]; then break; fi
|
|
309
366
|
detail="rc=$rc answered=${out:0:40} $(head -c 160 "$errf" | tr '\n' ' ')"
|
|
310
|
-
if [[ "$n" -lt "$
|
|
367
|
+
if [[ "$n" -lt "$QB_ATTEMPTS" ]]; then sleep "$QB_NAP"; fi
|
|
311
368
|
done
|
|
312
369
|
rm -f "$errf"
|
|
313
370
|
if [[ "$rc" -eq 0 && "$out" =~ ^[0-9]{1,6}$ ]]; then
|
|
314
|
-
if (( 10#$out >= 1 )); then QW_VERDICT="wait"; QW_DETAIL="rules=$out"
|
|
371
|
+
if (( 10#$out >= 1 )); then QW_VERDICT="wait"; QW_DETAIL="rules=$out"
|
|
372
|
+
elif [[ "$QW_BASE" != main ]]; then QW_VERDICT=foreign; fi
|
|
315
373
|
return 0
|
|
316
374
|
fi
|
|
317
|
-
detail="$(printf '%s' "$detail" |
|
|
375
|
+
detail="$(printf '%s' "$detail" | qb_clean)"
|
|
318
376
|
QW_VERDICT=unreadable; QW_DETAIL="rule read failed after $n attempt(s) ($detail)"
|
|
319
377
|
return 0
|
|
320
378
|
}
|
|
321
379
|
|
|
322
|
-
# The refusal text shared by every caller that refuses (the standalone loop, a flagless --step): what to do instead of a resync.
|
|
380
|
+
# The refusal text shared by every caller that refuses (the standalone loop, a flagless --step): what to do instead of a resync. The
|
|
381
|
+
# advice differs by the validated base (QW_BASE, always set when a `wait` verdict exists): for `main` the Phase 7 poll's expiry fallback
|
|
382
|
+
# is the sanctioned sync and a disarm / hand-sync / re-arm is safe; for any other base that sync merges origin/main, which is wrong for
|
|
383
|
+
# the PR, so the text says to sync by hand against that base and never to disarm and re-arm. The `main` text is byte-identical to the
|
|
384
|
+
# pre-#10832 text (pinned by a golden row in the suite). The echoed base is cut to 60 characters (it is validated, but may be 255 long).
|
|
323
385
|
qw_refusal() {
|
|
324
|
-
|
|
386
|
+
local b="${QW_BASE:0:60}" poll hand
|
|
387
|
+
if [[ "$QW_BASE" == main ]]; then
|
|
388
|
+
poll="; with no poll running, re-arm the Phase 7 poll with CLAUDE_PLUGIN_ROOT exported — its expiry fallback after 6 idle ticks is the sanctioned sync"
|
|
389
|
+
hand="Truly need a hand sync? Disarm first (gh pr merge $PR --disable-auto), sync, then re-arm."
|
|
390
|
+
else
|
|
391
|
+
poll=""
|
|
392
|
+
hand="Truly need a hand sync? This script and the Phase 7 poll's expiry fallback only merge origin/main, which is wrong for a PR based on '$b': sync by hand against that base (fetch origin <base>, merge origin/<base>, push) and do not disarm and re-arm."
|
|
393
|
+
fi
|
|
394
|
+
printf '%s' "PR #$PR is BEHIND, auto-merge is armed (not in the queue yet) and $b has a merge queue: not syncing — a resync alone restarts every required check and the queue makes the PR current. Wait for MERGED or a dequeue$poll. Red required check? Push the fix itself, not a resync. $hand Green and never enqueued? Follow plugins/soleur/skills/ship/references/merge-queue-dequeue.md ('Armed and green but never enqueued')."
|
|
325
395
|
}
|
|
326
|
-
# ... and the unreadable-rules text (fail closed): an unknown answer is not a yes.
|
|
396
|
+
# ... and the unreadable-rules text (fail closed): an unknown answer is not a yes. The hand-sync clause is conditional on the base as above.
|
|
327
397
|
qw_unreadable() { # <detail>
|
|
328
|
-
|
|
398
|
+
local b="${QW_BASE:0:60}" retry hand
|
|
399
|
+
if [[ "$QW_BASE" == main ]]; then
|
|
400
|
+
retry="Retry the poll"
|
|
401
|
+
hand="resync by hand only after confirming $b has no merge queue"
|
|
402
|
+
else
|
|
403
|
+
retry="Retry this check (not the Phase 7 poll's fence: it merges origin/main, which is wrong for a PR based on '$b')"
|
|
404
|
+
hand="resync by hand only after confirming $b has no merge queue, and then against that base (this script and the Phase 7 poll's fallback merge origin/main, which is wrong for a PR based on '$b')"
|
|
405
|
+
fi
|
|
406
|
+
printf '%s' "merge-queue $1 — not syncing: that read decides whether this armed BEHIND PR may be resynced and an unknown answer is not a yes. $retry; a persistent failure means the token cannot read repository rules (raise PR_QUEUE_ATTEMPTS, or $hand)."
|
|
407
|
+
}
|
|
408
|
+
# The interim non-main refusal (#10832): an armed BEHIND or UNKNOWN PR whose base is not `main` and has no merge_queue rule. This
|
|
409
|
+
# script only ever merges origin/main, which is wrong for such a PR, so it is not syncing; the text LEADS with NOT A TRANSIENT ERROR
|
|
410
|
+
# because a retry cannot help, and does not advise "disarm, sync, re-arm" (that walks into the very merge this refuses) or retargeting
|
|
411
|
+
# (the script has never synced from a non-main trunk, so a repo whose default branch is not main would be told to do the impossible).
|
|
412
|
+
# <state_line> is GitHub's `<STATE> <MERGESTATE>` (the foreign verdict also fires for UNKNOWN, so the text echoes the real state).
|
|
413
|
+
qw_foreign() { # <state_line>
|
|
414
|
+
local sl
|
|
415
|
+
sl="${1%%$'\n'*}"; sl="$(printf '%s' "${sl:0:60}" | qb_clean)" # the loop passes gh's raw `2>&1` answer: first line only, cut and sanitised
|
|
416
|
+
printf '%s' "NOT A TRANSIENT ERROR - PR #$PR is armed and ${sl#* } on base '${QW_BASE:0:60}', not main, and that base has no merge queue; this script only syncs from origin/main (merging main into that PR would be wrong), so it is not syncing and retrying will not help. Sync by hand against that base (fetch origin <base>, merge origin/<base>, then push)."
|
|
329
417
|
}
|
|
418
|
+
# ... and the unusable-base text (empty, or a name outside qw_base_path's set; QW_DETAIL names the sanitised base).
|
|
419
|
+
qw_badbase() { printf '%s' "NOT A TRANSIENT ERROR - $QW_DETAIL; this script only syncs from origin/main, so it is not syncing; sync by hand against the PR's base branch (fetch origin <base>, merge origin/<base>, then push)."; }
|
|
420
|
+
# ... and the unknown-verdict text (the `*)` arm of every caller: a verdict this script cannot name is a bug here, never a transient gh error).
|
|
421
|
+
qw_unknown() { printf '%s' "NOT A TRANSIENT ERROR - unknown queue_wait verdict '$(printf '%s' "$QW_VERDICT" | head -c 60 | qb_clean)' — not syncing (an unknown answer is not a yes); this is a bug in this script, report it"; }
|
|
330
422
|
|
|
331
|
-
# qw_snapshot — ONE bounded `gh pr view <PR> --json state,mergeStateStatus,autoMergeRequest` for the flagless --step and --queue-wait
|
|
423
|
+
# qw_snapshot — ONE bounded `gh pr view <PR> --json state,mergeStateStatus,autoMergeRequest,baseRefName` for the flagless --step and --queue-wait
|
|
332
424
|
# (no GraphQL queue read: --queue-wait's caller already classified queued / not_queued, and a second read would race a
|
|
333
|
-
# just-dequeued PR that still reads armed). Sets QW_STATE (`<STATE> <MERGESTATE>`)
|
|
425
|
+
# just-dequeued PR that still reads armed). Sets QW_STATE (`<STATE> <MERGESTATE>`), QW_ARMED (armed | disarmed) and QW_BASEREF (the PR's base branch, possibly empty: it is
|
|
426
|
+
# validated only inside queue_wait_eval, after the armed check, so an odd base never fails a path that does not reach the rules read; the
|
|
427
|
+
# answer is split with `read -r` only, never a suffix expansion, which would read a base named `disarmed` as the armed bit). It runs under
|
|
334
428
|
# the same timeout wrapper and PR_QUEUE_REPO handling as the other reads, with gh's stderr kept OUT of the string the match
|
|
335
429
|
# tests, and a strict match on the answer. ANY failure — non-zero, hung, empty, garbage — is `kind=gh` exit 4: never read as "not armed".
|
|
336
430
|
qw_snapshot() {
|
|
337
|
-
|
|
338
|
-
|
|
431
|
+
qb_bounds
|
|
432
|
+
local out="" rc=0 errf pvd repo_arg="" to=() st ms am base
|
|
433
|
+
QW_STATE=""; QW_ARMED=""; QW_BASEREF=""
|
|
339
434
|
if [[ "${PR_QUEUE_REPO:-}" =~ ^[A-Za-z0-9._-]+/[A-Za-z0-9._-]+$ ]]; then repo_arg="$PR_QUEUE_REPO"; fi
|
|
340
|
-
if command -v timeout >/dev/null 2>&1; then to=(timeout -k 2 "$
|
|
341
|
-
elif command -v gtimeout >/dev/null 2>&1; then to=(gtimeout -k 2 "$
|
|
435
|
+
if command -v timeout >/dev/null 2>&1; then to=(timeout -k 2 "$QB_TIMEOUT")
|
|
436
|
+
elif command -v gtimeout >/dev/null 2>&1; then to=(gtimeout -k 2 "$QB_TIMEOUT"); fi
|
|
342
437
|
errf="$(mktemp)" || { tag gh 4 "pr view snapshot not attempted (mktemp failed) — not syncing; retry the poll"; exit 4; } # lint-trap-ownership: ok — removed by rm -f on every path of qw_snapshot; a kill leaves one tiny file
|
|
343
438
|
# shellcheck disable=SC2016 # $1..$3 are bash -c's own positional parameters, not this shell's
|
|
344
|
-
out="$(${to[@]+"${to[@]}"} bash -c 'if [[ -n "$3" ]]; then gh pr view "$1" --repo "$3" --json state,mergeStateStatus,autoMergeRequest --jq "$2"; else gh pr view "$1" --json state,mergeStateStatus,autoMergeRequest --jq "$2"; fi' \
|
|
345
|
-
_ "$PR" '"\(.state) \(.mergeStateStatus) \(if .autoMergeRequest == null then "disarmed" else "armed" end)"' "$repo_arg" 2>"$errf")" || rc=$?
|
|
439
|
+
out="$(${to[@]+"${to[@]}"} bash -c 'if [[ -n "$3" ]]; then gh pr view "$1" --repo "$3" --json state,mergeStateStatus,autoMergeRequest,baseRefName --jq "$2"; else gh pr view "$1" --json state,mergeStateStatus,autoMergeRequest,baseRefName --jq "$2"; fi' \
|
|
440
|
+
_ "$PR" '"\(.state) \(.mergeStateStatus) \(if .autoMergeRequest == null then "disarmed" else "armed" end) \(.baseRefName // "")"' "$repo_arg" 2>"$errf")" || rc=$?
|
|
346
441
|
out="${out%%$'\n'*}"
|
|
347
|
-
if [[ "$rc" -eq 0 && "$out"
|
|
442
|
+
if [[ "$rc" -eq 0 ]] && qb_match "$out" '^(OPEN|CLOSED|MERGED) [A-Z_]+ (armed|disarmed) [^[:space:]]*$'; then
|
|
348
443
|
rm -f "$errf"
|
|
349
|
-
|
|
444
|
+
read -r st ms am base <<<"$out"
|
|
445
|
+
QW_STATE="$st $ms"; QW_ARMED="$am"; QW_BASEREF="$base"
|
|
350
446
|
return 0
|
|
351
447
|
fi
|
|
352
|
-
pvd="$(printf '%s' "rc=$rc answered=${out:0:40} $(head -c 160 "$errf")" |
|
|
448
|
+
pvd="$(printf '%s' "rc=$rc answered=${out:0:40} $(head -c 160 "$errf")" | qb_clean)"
|
|
353
449
|
rm -f "$errf"
|
|
354
450
|
tag gh 4 "pr view snapshot read failed ($pvd) — not syncing: whether this PR is armed and BEHIND decides if a resync is allowed, and an unknown answer is not a yes. Retry."
|
|
355
451
|
exit 4
|
|
356
452
|
}
|
|
357
453
|
|
|
454
|
+
# qw_probe — the snapshot plus the predicate, the place that passes the PR's base for the two snapshot callers (--queue-wait and the flagless
|
|
455
|
+
# --step guard); queue_wait_gate is the loop's own call site and passes LOOP_BASEREF (a forgotten base argument at a copy is the bug class,
|
|
456
|
+
# and the suite pins each call). Called directly (never inside `$( )`) so QW_VERDICT, QW_DETAIL and QW_BASE reach the caller.
|
|
457
|
+
qw_probe() { qw_snapshot; queue_wait_eval "$QW_STATE" "$QW_ARMED" "$QW_BASEREF"; }
|
|
458
|
+
|
|
358
459
|
# --queue-wait: the read-only verdict for the pre-merge hook (#9869), handled beside --queue-state before the worktree check.
|
|
359
460
|
# Armed means autoMergeRequest != null in THIS snapshot, so an armed PR that is already in the queue also reads queue_wait (the
|
|
360
|
-
# stricter, safe direction for a caller that decides whether to push). Writes nothing — no marker.
|
|
461
|
+
# stricter, safe direction for a caller that decides whether to push). Writes nothing — no marker. A foreign or unusable base answers
|
|
462
|
+
# `queue_wait` too (not `kind=gh`: the hook treats any non-zero exit as "sync anyway", which would merge origin/main into that PR).
|
|
361
463
|
if [[ "$MODE" == queue_wait ]]; then
|
|
362
464
|
QW_STATE=""; QW_ARMED=""
|
|
363
|
-
|
|
364
|
-
queue_wait_eval "$QW_STATE" "$QW_ARMED"
|
|
465
|
+
qw_probe
|
|
365
466
|
case "$QW_VERDICT" in
|
|
366
467
|
wait) echo queue_wait; exit 0 ;;
|
|
468
|
+
foreign) echo queue_wait; exit 0 ;;
|
|
469
|
+
badbase) echo queue_wait; exit 0 ;;
|
|
367
470
|
unreadable) tag gh 4 "$(qw_unreadable "$QW_DETAIL")"; exit 4 ;;
|
|
471
|
+
proceed) echo proceed; exit 0 ;;
|
|
472
|
+
# An unknown verdict is NOT proceed: the stricter answer, one line, rc 0 (the hook reads any non-zero exit as "sync anyway").
|
|
473
|
+
*) echo queue_wait; exit 0 ;;
|
|
368
474
|
esac
|
|
369
|
-
echo proceed; exit 0
|
|
370
475
|
fi
|
|
371
476
|
|
|
372
477
|
# step_guard — a FLAGLESS --step (#9869): refuse an armed BEHIND/UNKNOWN PR of a merge-queue repo with exit 14, a code of its
|
|
@@ -375,12 +480,15 @@ fi
|
|
|
375
480
|
# does not fall back to a hand merge. Unreadable is fail closed (kind=gh, exit 4), as in the standalone loop.
|
|
376
481
|
step_guard() {
|
|
377
482
|
QW_STATE=""; QW_ARMED=""
|
|
378
|
-
|
|
379
|
-
queue_wait_eval "$QW_STATE" "$QW_ARMED"
|
|
483
|
+
qw_probe
|
|
380
484
|
case "$QW_VERDICT" in
|
|
381
485
|
wait) tag queue_wait 14 "NOT AN ERROR in itself (GitHub says: $QW_STATE) — exit 14 means this caller is not the current Phase 7 fence: re-READ ship/SKILL.md from disk and re-paste its fence (a copy held in context predates --fence); the PR itself needs no sync. $(qw_refusal)"
|
|
382
486
|
exit 14 ;;
|
|
487
|
+
foreign) tag gh 4 "$(qw_foreign "$QW_STATE")"; exit 4 ;;
|
|
488
|
+
badbase) tag gh 4 "$(qw_badbase)"; exit 4 ;;
|
|
383
489
|
unreadable) tag gh 4 "$(qw_unreadable "$QW_DETAIL")"; exit 4 ;;
|
|
490
|
+
proceed) return 0 ;;
|
|
491
|
+
*) tag gh 4 "$(qw_unknown)"; exit 4 ;;
|
|
384
492
|
esac
|
|
385
493
|
}
|
|
386
494
|
|
|
@@ -467,17 +575,21 @@ queue_gate() {
|
|
|
467
575
|
|
|
468
576
|
# Armed-and-BEHIND gate for the standalone loop (2026-10-09, PR 9839): queue_wait_eval's verdict, as the loop answers it. Runs
|
|
469
577
|
# after queue_gate, whose QS_OUT carries the armed bit (no extra call). `wait` -> `kind=queue_wait` rc=0, exit 0 with nothing
|
|
470
|
-
# fetched, merged or pushed; `proceed` -> return, the sync goes on; `unreadable
|
|
578
|
+
# fetched, merged or pushed; `proceed` -> return, the sync goes on; `unreadable`, `foreign` (a non-main base with no queue rule) and
|
|
579
|
+
# `badbase` (an empty or unsupported base) -> `kind=gh` exit 4. The base is LOOP_BASEREF, resolved once before the loop. The standalone answer has NO
|
|
471
580
|
# expiry of its own: re-arming the Phase 7 poll is the bound (its fallback sync).
|
|
472
581
|
queue_wait_gate() { # <state_line>
|
|
473
582
|
local v st am rm
|
|
474
583
|
read -r v st am rm <<<"$QS_OUT"
|
|
475
|
-
queue_wait_eval "$1" "$am"
|
|
584
|
+
queue_wait_eval "$1" "$am" "$LOOP_BASEREF"
|
|
476
585
|
case "$QW_VERDICT" in
|
|
477
586
|
wait) tag queue_wait 0 "$(qw_refusal)"; exit 0 ;;
|
|
587
|
+
foreign) tag gh 4 "$(qw_foreign "$1")"; exit 4 ;;
|
|
588
|
+
badbase) tag gh 4 "$(qw_badbase)"; exit 4 ;;
|
|
478
589
|
unreadable) tag gh 4 "$(qw_unreadable "$QW_DETAIL")"; exit 4 ;;
|
|
590
|
+
proceed) return 0 ;;
|
|
591
|
+
*) tag gh 4 "$(qw_unknown)"; exit 4 ;;
|
|
479
592
|
esac
|
|
480
|
-
return 0
|
|
481
593
|
}
|
|
482
594
|
|
|
483
595
|
# One sync attempt. Returns the exit code documented in usage() and prints the tagged
|
|
@@ -564,10 +676,16 @@ if [[ "$MODE" == step ]]; then
|
|
|
564
676
|
fi
|
|
565
677
|
|
|
566
678
|
# Standalone: the PR number must name THIS branch, or the sync lands on the wrong PR.
|
|
567
|
-
|
|
568
|
-
|
|
679
|
+
# The same read also carries the PR's base branch (baseRefName) for queue_wait_eval, so the loop adds no gh call. The base is resolved ONCE
|
|
680
|
+
# per run: a mid-loop retarget is judged against the old base (bounded by --max-attempts: each further BEHIND iteration can merge again if main
|
|
681
|
+
# moved, so the stale judgement can cost up to that many merges). Any answer
|
|
682
|
+
# that is not exactly `<head> <base>` on one line (a single token, or a multi-line answer because stderr is merged by 2>&1) leaves head_ref
|
|
683
|
+
# as the whole answer, as before, and LOOP_BASEREF empty; an empty base is fatal only where queue_wait_eval reaches the rules read.
|
|
684
|
+
rc=0; head_ref="$(gh pr view "$PR" --json headRefName,baseRefName --jq '"\(.headRefName) \(.baseRefName // "")"' 2>&1)" || rc=$?
|
|
685
|
+
if [[ "$rc" -ne 0 ]]; then tag gh "$rc" "gh pr view failed: $(printf '%s' "$head_ref" | head -c 200 | qb_clean)"; exit 4; fi
|
|
686
|
+
if qb_match "$head_ref" '^[^[:space:]]+ [^[:space:]]*$'; then read -r head_ref LOOP_BASEREF <<<"$head_ref"; fi
|
|
569
687
|
if [[ "$head_ref" != "$BRANCH" ]]; then
|
|
570
|
-
tag wrong_branch 12 "PR #$PR's head branch is '$head_ref' but this worktree is on '$BRANCH' — cd to that PR's worktree (or pass the right PR number); not syncing."
|
|
688
|
+
tag wrong_branch 12 "PR #$PR's head branch is '$(printf '%s' "$head_ref" | head -c 200 | qb_clean)' but this worktree is on '$BRANCH' — cd to that PR's worktree (or pass the right PR number); not syncing."
|
|
571
689
|
exit 12
|
|
572
690
|
fi
|
|
573
691
|
|
|
@@ -576,12 +694,16 @@ while [[ "$attempt" -lt "$MAX_ATTEMPTS" ]]; do
|
|
|
576
694
|
attempt=$((attempt + 1))
|
|
577
695
|
rc=0; state_line="$(gh pr view "$PR" --json state,mergeStateStatus \
|
|
578
696
|
--jq '"\(.state) \(.mergeStateStatus)"' 2>&1)" || rc=$?
|
|
579
|
-
if [[ "$rc" -ne 0 ]]; then tag gh "$rc" "gh pr view failed: $state_line"; exit 4; fi
|
|
697
|
+
if [[ "$rc" -ne 0 ]]; then tag gh "$rc" "gh pr view failed: $(printf '%s' "$state_line" | head -c 200 | qb_clean)"; exit 4; fi
|
|
580
698
|
|
|
581
|
-
|
|
699
|
+
# gh's stderr is merged into the answer (2>&1), so even an rc-0 read can carry junk: every echo of it is sanitised (the tests below
|
|
700
|
+
# still look at the raw $state_line). The cut is a substring, not `| head -c 200`: this is an assignment under pipefail, and a head
|
|
701
|
+
# that exits early SIGPIPEs the printf on a long answer (rc 141, loop dead with no tag line).
|
|
702
|
+
sdisp="$(printf '%s' "${state_line:0:200}" | qb_clean)"
|
|
703
|
+
tag state 0 "PR #$PR state: $sdisp (branch: $BRANCH)"
|
|
582
704
|
|
|
583
705
|
if [[ "$state_line" == MERGED* || "$state_line" == CLOSED* ]]; then
|
|
584
|
-
tag closed 0 "PR is ${
|
|
706
|
+
tag closed 0 "PR is ${sdisp%% *} — no sync needed"
|
|
585
707
|
exit 0
|
|
586
708
|
fi
|
|
587
709
|
|
|
@@ -634,8 +756,8 @@ while [[ "$attempt" -lt "$MAX_ATTEMPTS" ]]; do
|
|
|
634
756
|
|
|
635
757
|
rc=0; state_line="$(gh pr view "$PR" --json state,mergeStateStatus \
|
|
636
758
|
--jq '"\(.state) \(.mergeStateStatus)"' 2>&1)" || rc=$?
|
|
637
|
-
if [[ "$rc" -ne 0 ]]; then tag gh "$rc" "post-push gh pr view failed: $state_line"; exit 4; fi
|
|
638
|
-
tag state 0 "post-sync state: $state_line"
|
|
759
|
+
if [[ "$rc" -ne 0 ]]; then tag gh "$rc" "post-push gh pr view failed: $(printf '%s' "$state_line" | head -c 200 | qb_clean)"; exit 4; fi
|
|
760
|
+
tag state 0 "post-sync state: $(printf '%s' "$state_line" | head -c 200 | qb_clean)"
|
|
639
761
|
|
|
640
762
|
if [[ "$state_line" != *BEHIND* ]]; then
|
|
641
763
|
tag resolved 0 "BEHIND resolved: branch caught up to main"
|
|
@@ -133,6 +133,16 @@ if [[ "$1 $2" != "pr view" ]]; then
|
|
|
133
133
|
fi
|
|
134
134
|
# The standalone loop first checks the PR's head branch (kind=wrong_branch, exit 12).
|
|
135
135
|
# Answer it with the fixture branch; it is not a state read, so it is not counted.
|
|
136
|
+
# The head read is request-shaped: a plain `--json headRefName` gets the bare head; a read that also asks for baseRefName
|
|
137
|
+
# (`--json headRefName,baseRefName --jq <program>`) gets the raw JSON, run through the --jq the SUT passed (the PR's base is `main`).
|
|
138
|
+
hj=""; hq=""; hp=""
|
|
139
|
+
for a in "$@"; do
|
|
140
|
+
case "$hp" in --json) hj="$a" ;; --jq) hq="$a" ;; esac
|
|
141
|
+
hp="$a"
|
|
142
|
+
done
|
|
143
|
+
case "$hj" in
|
|
144
|
+
headRefName,baseRefName) printf '%s' '{"headRefName":"feature","baseRefName":"main"}' | jq -r "$hq"; exit $? ;;
|
|
145
|
+
esac
|
|
136
146
|
for a in "$@"; do [[ "$a" == "headRefName" ]] && { echo "feature"; exit 0; }; done
|
|
137
147
|
for a in "$@"; do [[ "$a" == "state,mergeStateStatus" ]] && found=1; done
|
|
138
148
|
if [[ -z "${found:-}" ]]; then
|
|
@@ -4,4 +4,4 @@ The Queue mode paragraph below was moved out of `ship/SKILL.md` Phase 7 to stay
|
|
|
4
4
|
|
|
5
5
|
**Queue mode (#9710).** When `main` has a `merge_queue` rule (read once at loop entry by `.type == "merge_queue"`, never by position; this reads `main`'s rules, as the required-check read already does) and the required-check set is non-empty, AND auto-merge is armed (read each BEHIND tick), a BEHIND reading that GitHub itself reported is not a reason to push: each push restarts the whole required-check set, and the queue builds every candidate against the projected `main`, so an armed PR is made current by the queue. GitHub enqueues an armed PR whose head is behind `main` on its own (measured, ADR-270 canary addendum 2026-10-07), so the poll prints `[ship.phase7.queue_wait]` once and keeps polling (informational: take no action, and never sync, update-branch or merge it by hand until `[ship.phase7.queue_wait_expired]`, a push line, MERGED, a dequeue or any poll exit), prints `[ship.phase7.queued]` once, at the first every-5th-tick read that finds the PR in the queue (a queued reading also restarts the idle count, so while each 5th-tick read answers queued the PR does not expire), and stops on a dequeue as above. The wait is bounded two ways. More than 5 consecutive wait ticks (the 6th) with no pending REQUIRED check (a required check that does not exist yet, such as the `test` aggregate before its shards finish, counts as pending while any check is still running) print `[ship.phase7.queue_wait_expired]` and fall back to the BEHIND auto-sync for the rest of that poll (this poll's last queue read did not show the PR queued: keep the Monitor running, diagnose with the dequeue reference and the PR timeline, record the strict up-to-date question in the final report, and do not change the ruleset; the fallback `--step` itself skips a PR that is in the queue and fails closed on an unreadable queue read). `MAX_POLL_MIN` caps a PR whose required checks never settle or whose state keeps flapping (any tick that is not a wait tick restarts the idle count). Every unreadable answer falls toward today's sync (in the fence; the standalone script's rules read is the one new exception, see Standalone guard below): a failed rules read or an empty required-check set leaves queue mode off for the poll, a failed armed read ends the wait for that tick (that tick syncs as today), and a failed checks read counts as idle. A DIRTY-derived BEHIND, a repo with no queue rule and a poll with auto-sync disabled behave exactly as before. Waiting does not consume `MAX_BEHIND_SYNCS`. Accepted residuals (ADR-270 amendment 2026-10-07): some required contexts (`tenant-integration-required`, `vendor-pin-required`) post a PASS on `merge_group` without re-running their suites, so in queue mode their only real run is the PR-time one against the PR-time base (the sync used to re-run the PR-event versions on a fresher base); and a dequeue during the wait is found by a current removal event on the next 5th-tick read, because the seen-queued marker is only written by `--step`.
|
|
6
6
|
|
|
7
|
-
**Standalone guard (2026-10-09, PR 9839).** `sync-pr-behind.sh <PR>` (the standalone loop) now enforces the rule above itself: when GitHub reports the PR BEHIND (not DIRTY), auto-merge is armed and
|
|
7
|
+
**Standalone guard (2026-10-09, PR 9839).** `sync-pr-behind.sh <PR>` (the standalone loop) now enforces the rule above itself: when GitHub reports the PR BEHIND (not DIRTY), auto-merge is armed and the PR's base branch has a `merge_queue` rule (`main` for a main-based PR; boundary (2) covers another base; selected by `.type`, one read of up to 100 rules), it prints `kind=queue_wait rc=0` and exits 0 with nothing fetched, merged or pushed. A rules read that still fails after `PR_QUEUE_ATTEMPTS` tries (default 2, as for the queue read) or answers non-numeric is `kind=gh` (exit 4) with the cause in the line. This is the one place the script FAILS CLOSED on an unreadable rules answer: the fence above falls toward sync, but a standalone run has no poll behind it and an unknown answer is not a yes (the cost is a visible, named stop on a host whose token cannot read repository rules; for a main-based PR the sanctioned sync is then the Phase 7 poll's own sync; for another base, a hand sync against that base). The incident: an agent hand-wrote a poll loop that treated BEHIND as an error and ran the script after `gh pr merge --auto` and before the enqueue (one push landed after the arm, 12 minutes in), restarting PR CI for nothing; the old prose scoped the ban to a poll that had already emitted `[ship.phase7.queue_wait]`, a marker a hand-written loop never emits, so the executable now refuses on the facts. Boundaries, stated so they are not rediscovered: (1) `--step` and the pre-merge hook are guarded too since 2026-10-20 (#9869): see the ADR-270 addendum of that date (a flagless `--step` exits 14 `kind=queue_wait`, the fences' own call opts out, the hook asks the read-only `--queue-wait` verdict). (2) The rules read uses the PR's own base branch (`baseRefName`) since 2026-10-24; while the PR is armed and BEHIND (or UNKNOWN at the flagless step and in the read-only `--queue-wait` verdict only), a non-`main` base with no merge queue, or a base name outside the script's allowlist (`badbase`, which also refuses a git-legal name such as `rel+1` even when that base has a queue), is refused (`kind=gh`, exit 4 at the loop and the flagless step) and not synced, because the sync itself still merges `origin/main`; the pre-merge hook's `--queue-wait` answer for the same PR is `queue_wait`, which its `queue_wait` arm turns into a skip, not a sync (see the ADR-270 addendum of that date). (3) The script does not read required checks: the fence sets `QUEUE_RULE=0` on a repo with no required checks and exits on a red required check, but the script answers `queue_wait` for any armed BEHIND PR; the refusal text therefore says to push a fix for a red check and routes to the sibling reference merge-queue-dequeue.md ("Armed and green but never enqueued") instead of promising a merge. (4) A DIRTY that is only GitHub's recompute lag after `main` moved still syncs. (5) The standalone answer has no expiry: the bound is re-arming the Phase 7 poll, whose fallback sync is the sanctioned one for a main-based PR only. The text surfaces say the same thing in one phrase: "when `main` has a merge queue and the PR is armed (the Phase 7 poll prints `[ship.phase7.queue_wait]`)" — a fact, not a marker only the Phase 7 fence prints; it holds for a BEHIND reading only. Surfaces not edited because they sit in the byte-ceilinged fences or outside the armed-BEHIND class: the fence `behind_no_sync` line (its standalone call now answers `queue_wait` on an armed PR, which is correct: fix the poll precondition and re-arm), `monitor-pr-checks.sh`, and `review/SKILL.md`'s DIRTY recovery.
|