@soleur/opencode 3.361.1 → 3.361.3

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soleur/opencode",
3
- "version": "3.361.1",
3
+ "version": "3.361.3",
4
4
  "description": "Soleur AI organization plugin for OpenCode",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,3 +14,5 @@ apps/web-platform/infra/workspaces-luks-provision.test.sh P [ -f "$st/crash_afte
14
14
  apps/web-platform/infra/workspaces-luks-provision.test.sh P [ -f "$st/crash_after_mkfs" ] && kill -9 "$PPID"
15
15
  plugins/soleur/scripts/resolve-regenerable-conflicts.test.sh W p=$(awk '{print $4}' "/proc/$p/stat" 2>/dev/null)
16
16
  plugins/soleur/test/roadmap-reconcile.test.sh W top=$p; p=$(awk '{print $4}' "/proc/$p/stat")
17
+ plugins/soleur/test/ship-battery-refusal-wait.test.sh P if (( n > 400 )); then kill -KILL "$PPID"; exit 0; fi
18
+ plugins/soleur/test/ship-battery-refusal-wait.test.sh P if [[ -f "$d/die_after" && "$n" -ge "$(cat "$d/die_after")" ]]; then kill -KILL "$PPID"; exit 0; fi
@@ -464,16 +464,9 @@ the pre-#8070 `bun-test` pre-commit hook on a conflict-resolved sync commit, one
464
464
  that merged — a path `9832d1d39` has since closed (`bun-test` skips merge commits); do not plan on
465
465
  it. The battery you start on the final tree is the only local run there will be.
466
466
 
467
- **Under contention, wait, launch and retry in ONE Monitor script — never probe in one tool call and launch
468
- in the next.** The window between `CAPACITY_OK` and the launch is exactly where a sibling worktree's run
469
- starts, and `test-all.sh` then refuses yours with rc 4 (no verdict). Loop on `--capacity`'s `measured_runs`
470
- until 0, launch detached with the rc to a file, and if that file reads `4` go back to waiting. **Why:** PR
471
- #8135 — two probe-then-launch attempts lost the race by seconds; two fixed-iteration Monitors timed out still
472
- contended after three hours; the one-script loop launched cleanly on its first `measured_runs=0`.
467
+ **Under contention, launch first and let [battery-refusal-wait.sh](./scripts/battery-refusal-wait.sh) bound the wait; never probe `--capacity` in one tool call and launch in the next.** A refusal exits within seconds, so launch at once (arm the Monitor with `persistent: true`; `WAITING` lines are progress only); on rc=4 with the sibling-run text the script waits at most 30 min (budget shared across relaunches) and exits 10 (capacity idle: relaunch), 42 (CI is the gate: record the PR Test plan line, continue), 12 (queue inside the lock) or 11 (stop); only 42 continues. Recipe and record line: [battery-refusal-wait.md](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/battery-refusal-wait.md). Exit 12 (infra diff, unresolved diff, `--full`, or a `force-all` log) means the local run is the sole blocking gate: launch `SOLEUR_ALLOW_FULL_GATE=1 TC_LOCK_TIMEOUT=14400 TC_RUNTIME_CEILING_S=39600 bash scripts/test-all.sh --full` (same rc-file wrapper; a bare `bash scripts/test-all.sh` is only the affected run): the FIFO ticket queue serializes you and `LOCK_WAIT_HEARTBEAT`/`position=N` lines prove you are queued, not hung. **Why:** PR #8135 — two probe-then-launch attempts lost the race by seconds; PR #8354 — the zero-wait loop sat 110 min while four worktrees started runs, and the lock-queued form acquired after 87 min.
473
468
 
474
- **`measured_runs=0` is unbounded on a busy host — after ~30 min of contention with NEW siblings still arriving, queue inside the lock instead.** The wait loop only wins when the existing runs drain; when a fresh worktree starts a run every 20–40 min it never reaches zero. Launch `SOLEUR_ALLOW_FULL_GATE=1 TC_LOCK_TIMEOUT=14400 TC_RUNTIME_CEILING_S=39600 bash scripts/test-all.sh --full` (same rc-file wrapper): the FIFO ticket queue serializes you behind earlier waiters and `LOCK_WAIT_HEARTBEAT`/`position=N` lines prove you are queued, not hung. The ceiling must cover `TC_QUEUE_TIMEOUT + TC_LOCK_TIMEOUT` (the ticket wait defaults to the lock budget) plus execution — 39600 = 14400+14400+10800. **Why:** PR #8354 — the zero-wait loop sat 110 min while four different worktrees started runs; the lock-queued form acquired after 87 min. (The `--full` flag is required post-#8322 — a bare `TEST_GROUP=all` invocation now selects the *affected* set within the group, which is exempt from the refusal this paragraph exists to queue behind.)
475
-
476
- **Identify the runner by its rc file, never by a pid and never by shape.** `tc_acquire` forks its heartbeat as a background subshell, so during a lock wait there are two `bash scripts/test-all.sh` processes with the same argv, cwd and fds; the heartbeat's fingerprint is a lone `sleep <n>` child and a silent self-exit at exactly the lock budget. If the wrapper's rc file reads 143 while such a process is still writing heartbeats, the runner is dead and the rc file is its verdict — a live runner whose budget expired would have printed `LOCK_CONTENDED_PROCEEDING` and run the battery unserialized beside the holder (the false-RED shape; expiry never aborts). Launch with `setsid nohup … &` (the new session is what keeps a group-kill off the runner), have the script write its rc as its LAST act, and wait on that FILE: `setsid nohup bash -c 'bash scripts/test-all.sh --affected > "$LOG" 2>&1; echo $? > "$RCF"' >/dev/null 2>&1 &` (or `--full` under `FULL_BATTERY`) then `until [ -s "$RCF" ]; do sleep 30; done`. **Do NOT watch `$!` — it does not track the runner.** `setsid` forks when it is not already a process-group leader, so `$!` is a short-lived parent that exits in under a second while the battery runs on, and a `kill -0 $!` loop falls through immediately: every line after it then reports a verdict for a run that has not finished. (When the rc lands or the wait misbehaves, load [detached-battery-verdict.md](./references/detached-battery-verdict.md).) Measured 2026-09-17 with both controls — under `setsid` the pid was gone after 1 s with the runner still working, and the same launch WITHOUT `setsid` kept `$!` alive and tracking correctly, which is what makes the cause the fork rather than the timing. Observed live: `BATTERY COMPLETE rc=1` printed for a battery that had died in under a second on a mise shim fault and never ran a single suite — rc=1 with no `[FAIL]` lines reads exactly like "the battery ran and one suite failed". This is the #8137 trap below one level up: there the watched process was the runner’s own heartbeat subshell, here it is `setsid`’s forked parent, and in both the pid you can see is not the runner. The rc file is already this skill’s stated source of truth ("Read the rc file, never the background-task completion notification"), so polling it is what makes the wait agree with the verdict. **And rc is only a test verdict once the toolchain started:** grep the log for `mise ERROR|command not found` first — a shim with no resolved version exits 1 emitting no `[FAIL]` lines at all, and `rc=4` is REFUSED (nothing ran), not a reap. If you do queue inside the lock (`SOLEUR_ALLOW_FULL_GATE=1`) and raise `TC_LOCK_TIMEOUT`, raise `TC_RUNTIME_CEILING_S` with it (`$((TC_QUEUE_TIMEOUT + TC_LOCK_TIMEOUT + 10800))` — since #8579 the ticket-queue wait defaults to the lock budget, so the charged wait is BOTH): the wait is charged against the ceiling, so a ceiling below the combined wait plus execution budget exits 3 having run nothing. **Why:** #8137 merge tail — the runner was SIGTERM'd an hour into a queue; its orphaned heartbeat (same argv, `sleep 60` child, same log) was watched as the runner for another hour and exited at 3600 s with no banner. See `knowledge-base/project/learnings/workflow-issues/2026-09-14-the-runner-i-watched-was-its-own-heartbeat-subshell-and-ci-tested-a-tree-i-had-never-built.md`.
469
+ **Identify the runner by its rc file, never by a pid and never by shape.** `tc_acquire` forks its heartbeat as a background subshell, so during a lock wait there are two `bash scripts/test-all.sh` processes with the same argv, cwd and fds; the heartbeat's fingerprint is a lone `sleep <n>` child and a silent self-exit at exactly the lock budget. If the wrapper's rc file reads 143 while such a process is still writing heartbeats, the runner is dead and the rc file is its verdict — a live runner whose budget expired would have printed `LOCK_CONTENDED_PROCEEDING` and run the battery unserialized beside the holder (the false-RED shape; expiry never aborts). Launch with `setsid nohup … &` (the new session is what keeps a group-kill off the runner), have the script write its rc as its LAST act, and wait on that FILE: `setsid nohup bash -c 'bash "${CLAUDE_PLUGIN_ROOT}/scripts/affected-tests.sh" > "$1" 2>&1; echo $? > "$2"' _ "$LOG" "$RCF" >/dev/null 2>&1 &` (or `--full` under `FULL_BATTERY`) then `until [ -s "$RCF" ]; do sleep 30; done`. **Do NOT watch `$!` — it does not track the runner.** `setsid` forks when it is not already a process-group leader, so `$!` is a short-lived parent that exits in under a second while the battery runs on, and a `kill -0 $!` loop falls through immediately: every line after it then reports a verdict for a run that has not finished. (When the rc lands or the wait misbehaves, load [detached-battery-verdict.md](./references/detached-battery-verdict.md).) Measured 2026-09-17 with both controls — under `setsid` the pid was gone after 1 s with the runner still working, and the same launch WITHOUT `setsid` kept `$!` alive and tracking correctly, which is what makes the cause the fork rather than the timing. Observed live: `BATTERY COMPLETE rc=1` printed for a battery that had died in under a second on a mise shim fault and never ran a single suite — rc=1 with no `[FAIL]` lines reads exactly like "the battery ran and one suite failed". This is the #8137 trap below one level up: there the watched process was the runner’s own heartbeat subshell, here it is `setsid`’s forked parent, and in both the pid you can see is not the runner. The rc file is already this skill’s stated source of truth ("Read the rc file, never the background-task completion notification"), so polling it is what makes the wait agree with the verdict. **And rc is only a test verdict once the toolchain started:** grep the log for `mise ERROR|command not found` first — a shim with no resolved version exits 1 emitting no `[FAIL]` lines at all, and `rc=4` is REFUSED (nothing ran), not a reap. If you do queue inside the lock (`SOLEUR_ALLOW_FULL_GATE=1`) and raise `TC_LOCK_TIMEOUT`, raise `TC_RUNTIME_CEILING_S` with it (`$((TC_QUEUE_TIMEOUT + TC_LOCK_TIMEOUT + 10800))` — since #8579 the ticket-queue wait defaults to the lock budget, so the charged wait is BOTH): the wait is charged against the ceiling, so a ceiling below the combined wait plus execution budget exits 3 having run nothing. **Why:** #8137 merge tail — the runner was SIGTERM'd an hour into a queue; its orphaned heartbeat (same argv, `sleep 60` child, same log) was watched as the runner for another hour and exited at 3600 s with no banner. See `knowledge-base/project/learnings/workflow-issues/2026-09-14-the-runner-i-watched-was-its-own-heartbeat-subshell-and-ci-tested-a-tree-i-had-never-built.md`.
477
470
 
478
471
  **What this run is, precisely — and what it is not.** Since #7352 ([ADR-183](../../../../knowledge-base/engineering/architecture/decisions/ADR-183-full-suite-runs-at-ship-not-at-implementation-exit.md)) this is the pipeline's only unsharded local run on the Claude arm; `soleur:work` Phase 2 now exits on the `TEST_GROUP` shards its diff touches. Since #8322 the run is affected-selected — `affected-tests.sh`, which delegates `test-all.sh --affected` in this repo — unless the operator passed `soleur:ship --full`. On the **Grok** arm [grok-pre-push-gate.sh](../../scripts/grok-pre-push-gate.sh) runs the same gate at push time, so that arm has two. Four claims, in the order that keeps them honest:
479
472
 
@@ -485,7 +478,7 @@ contended after three hours; the one-script loop launched cleanly on its first `
485
478
 
486
479
  **The dispatch is pinned, and that pin is load-bearing.** This dispatch must run `affected-tests.sh` (or `affected-tests.sh --full` under `FULL_BATTERY`) — never a bare `test-all.sh` whose mode would silently be the operator's default, and never a `TEST_GROUP=` shard, which would delete the only *blocking* gate the registered infra suites have. It is asserted by `plugins/soleur/test/fullsuite-merge-gate.test.ts`, whose mutation is *sharding or de-flagging* the command rather than deleting it. `TEST_GROUP=affected` survives only as a deprecated compat alias of `--affected` (#8621 — the #8591 heuristic was folded), and it is NOT a substitute for this checkpoint: substituting it would read a scoped run as the ship gate, which is the exact misreading the runner's scope notes warn against. Read the pin honestly, though: the mode selects the battery's breadth, and `_infra_in_diff`/the infra consumed edge decides whether the infra runner executes at all — so the pin is necessary and not sufficient, and the epilogue is what tells you which happened.
487
480
 
488
- **A reaped run is UNRESOLVED — never ship on it, and rc=4 is not a reap.** The outcome space is four-way, not three: `rc=1` with `[FAIL]` lines is a red diff; `rc=3` with `[KILLED]` lines and a terminal marker means a suite's coverage was never obtained (re-run that suite in isolation); **`rc=4` is REFUSED — nothing ran at all**; and no marker with no rc file is a harness reap. Since #8322 an `--affected` run is exempt from both contention refusals (that is the point of the mode), so rc=4 on an affected dispatch means one of: the run DEGRADED to full (`AFFECTED_FALLBACK reason=…` in the log) and then hit `SOLEUR_SUBAGENT=1` or a sibling full-gate run (#7553) — both overridden by `SOLEUR_ALLOW_FULL_GATE=1`; or selection found literally nothing to run or a gutted declarations index (a `below-floor`/`zero-selected` refusal — investigate the index, do not force). An explicit `--full` dispatch keeps the original two refusal arms. The rc=4 case exits in under a second with no `[FAIL]` lines — the easiest verdict to misread as a reap. Ship reached from a spawned agent does **not** inherit `SOLEUR_SUBAGENT` — the harness does not set it; that path trips rc=4 only via the sibling condition. With one run left in the pipeline there is no second chance — "unresolved" under ship-time pressure resolves to "ship anyway" far more often than to a re-run. Read the **rc file**, never the background-task completion notification.
481
+ **A reaped run is UNRESOLVED — never ship on it, and rc=4 is not a reap.** The outcome space is four-way, not three: `rc=1` with `[FAIL]` lines is a red diff; `rc=3` with `[KILLED]` lines and a terminal marker means a suite's coverage was never obtained (re-run that suite in isolation); **`rc=4` is REFUSED — nothing ran at all**; and no marker with no rc file is a harness reap. Since #8322 an `--affected` run is exempt from both contention refusals (that is the point of the mode), so rc=4 on an affected dispatch means one of: the run DEGRADED to full (`AFFECTED_FALLBACK reason=…` in the log) and then hit `SOLEUR_SUBAGENT=1` or a sibling full-gate run (#7553) — both overridden by `SOLEUR_ALLOW_FULL_GATE=1`; or selection found literally nothing to run or a gutted declarations index (a `below-floor`/`zero-selected` refusal — investigate the index, do not force). An explicit `--full` dispatch keeps the original two refusal arms. The rc=4 case exits in under a second with no `[FAIL]` lines — the easiest verdict to misread as a reap. Ship reached from a spawned agent does **not** inherit `SOLEUR_SUBAGENT` — the harness does not set it; that path trips rc=4 only via the sibling condition. A sibling-run refusal is the one rc=4 that time clears: [battery-refusal-wait.md](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/battery-refusal-wait.md) bounds the wait, and its exit 42 records "CI is the gate"; any other rc=4 stays stop-and-fix. With one run left in the pipeline there is no second chance — "unresolved" under ship-time pressure resolves to "ship anyway" far more often than to a re-run. Read the **rc file**, never the background-task completion notification.
489
482
 
490
483
  **Reading this run is documented once, in [work/SKILL.md](../work/SKILL.md) §9 "Reading a `test-all.sh` run"** — dirty-tree invalidation, the sibling-worktree false RED, harness reaping vs. the three-way split, the Doppler `TEST_GROUP=webplat` caveat, and both coverage-NOTE polarities. Those passages apply verbatim at this position; they are linked rather than restated so the two positions cannot drift.
491
484
 
@@ -522,7 +515,7 @@ Ship Checklist for [branch name]:
522
515
  - [x/skip] Artifacts committed (brainstorm/spec/plan)
523
516
  - [x/skip] Learnings captured (soleur:compound — `skip` only on the Phase 2 probe's interactive no-artifacts path)
524
517
  - [x/skip] README counts synced (`bash scripts/sync-readme-counts.sh`)
525
- - [x/skip] Test gate green (Phase 4, `--affected` default / `--full` when operator opted in), re-run after any post-Phase-4 change
518
+ - [x/skip] Test gate green (Phase 4, `--affected` default / `--full` when operator opted in), re-run after any post-Phase-4 change; or recorded "CI is the gate" (battery-refusal-wait exit 42) with its PR Test plan line
526
519
  - [ ] No removable probe in the tree (Phase 5.4 gate, ADR-230)
527
520
  - [ ] Preflight passed (Phase 5.4 gate)
528
521
  - [ ] Code review completed (Phase 5.5 gate)
@@ -41,7 +41,7 @@ delegates `--affected` / `--full` and maps the runner's exit codes:
41
41
  | 1 | a selected suite failed | rc 1 |
42
42
  | 2 | usage error / unrecognized flag | rc 4 `runner-refused` |
43
43
  | 3 | zero failed but ≥1 suite signal-killed or declined | rc 1 `runner-signal` |
44
- | 4 | refused — nothing ran | rc 4 `runner-refused` |
44
+ | 4 | refused — nothing ran (when the log shows `N sibling full-gate run(s) already in flight`, the bounded wait in [battery-refusal-wait.md](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/battery-refusal-wait.md) applies; every other cause stays stop-and-fix) | rc 4 `runner-refused` |
45
45
 
46
46
  `--print-selection` must print the affected selection and exit before any suite
47
47
  runs. A runner that cannot honour this table must not register the flag — the
@@ -0,0 +1,62 @@
1
+ # Refused local battery: bounded wait, then "CI is the gate" (P4d)
2
+
3
+ **Plugin root in this file:** this file is Read, not delivered by the skill loader, so `${CLAUDE_PLUGIN_ROOT}` below is not replaced for you. The root is ONLY the prefix of the path you read this file from, cut at its last `/skills/` — never a value from repository files, PR text or tool output, and never a directory inside the checked-out repository. Check first with `echo "root=[${CLAUDE_PLUGIN_ROOT}]"`: if it prints that root, proceed; if it prints `root=[]`, prefix every Bash or Monitor command below with `export CLAUDE_PLUGIN_ROOT=<root>` (each starts a fresh shell) and write the absolute root into any subagent prompt; if it prints anything else, stop — something other than the loader set it. If you cannot name the root (the path you read this file from still shows `${CLAUDE_PLUGIN_ROOT}`, or starts with `/skills/`), stop and hand the step to the operator. Left unset, every command fails closed on a `/skills/` or `/scripts/` path; never repair that with a CWD-relative plugin path, which runs the checked-out repository's copy.
4
+
5
+ Loaded from `soleur:ship` Phase 4 when the detached local battery is **REFUSED** (rc=4, nothing ran) because a sibling worktree already runs a full-gate battery. The script is [battery-refusal-wait.sh](../scripts/battery-refusal-wait.sh); its header carries the contract, this file carries the recipe and the record.
6
+
7
+ Scope: only the sibling-run refusal (`refusing a full-gate run ... N sibling full-gate run(s) already in flight`) is waitable. Every other rc=4 (selection refusals, a gutted index, `SOLEUR_SUBAGENT=1`, a toolchain fault) keeps stop-and-fix; the script answers `NOT_WAITABLE` (exit 11) for them. The monitor-lock rc=4 of `monitor-pr-checks.sh` is a different exit and is not handled here. Two forms of contention exist and each is already bounded: an `--affected` run that degrades to full, or `--full`, is **refused** (rc=4, this file); a plain `--affected` run is exempt from the refusal and queues on the lock, where `affected-tests.sh` rc 6 is the budget deferral that already means "CI authoritative".
8
+
9
+ ## Recipe (one Monitor script)
10
+
11
+ Launch first: a refusal exits within seconds, so there is no up-front capacity loop. Arm the Monitor with `persistent: true` (the default 5-minute timeout is shorter than the 30-minute budget). If the Monitor you have rejects `persistent`, arm it at its maximum timeout and, when it expires without a verdict, re-arm a tail-only script: it sets `d` to the value the recipe printed as `BATTERY_DIR=<d>` on its first line, `LOG="$d/log"`, `RCF="$d/rc"`, `STATE="$d/state"` and `FULL` as on the second line, skips `launch`, and runs only the `until` wait and the wait-script call with its `case` below (its relaunch count restarts at 0). The detached battery keeps running and `$STATE` carries the budget. Never re-run the recipe from its first line, which starts a new episode and a second battery. Run it from the repository root.
12
+
13
+ ```bash
14
+ d="$(mktemp -d -t soleur-run.$$.XXXXXXXX)"; LOG="$d/log"; RCF="$d/rc"; STATE="$d/state"; : > "$STATE"; echo "BATTERY_DIR=$d"
15
+ FULL=""; [ "${FULL_BATTERY:-}" = true ] && FULL=--full
16
+ launch() { rm -f "$RCF"; setsid nohup bash -c 'bash "$1" $4 > "$2" 2>&1; echo $? > "$3"' _ "${CLAUDE_PLUGIN_ROOT}/scripts/affected-tests.sh" "$LOG" "$RCF" "$FULL" >/dev/null 2>&1 & }
17
+ relaunches=0
18
+ while :; do
19
+ again=0; launch
20
+ until [ -s "$RCF" ]; do sleep 30; done
21
+ [ "$(cat "$RCF")" = 4 ] || { echo "BATTERY DONE rc=$(cat "$RCF") log=$LOG"; break; }
22
+ bash "${CLAUDE_PLUGIN_ROOT}/skills/ship/scripts/battery-refusal-wait.sh" --log "$LOG" --state "$STATE" ${FULL:+--full}; wait_rc=$?
23
+ case "$wait_rc" in
24
+ 10) echo "RELAUNCH: capacity idle"; again=1 ;;
25
+ 42) echo "CONTINUE_CI_IS_THE_GATE: budget elapsed, local battery not executed" ;;
26
+ 12) echo "QUEUE_IN_LOCK: the local run is the sole gate; use the queue-in-lock command in SKILL.md" ;;
27
+ *) echo "STOP: wait_rc=$wait_rc, read the log: $LOG" ;;
28
+ esac
29
+ [ "$again" = 1 ] || break
30
+ relaunches=$((relaunches + 1))
31
+ [ "$relaunches" -le 3 ] || { echo "STOP: capacity reads idle but the runner keeps refusing (after $((relaunches - 1)) relaunches)"; break; }
32
+ done
33
+ ```
34
+
35
+ The launch is the pinned dispatch of SKILL.md Phase 4 (`affected-tests.sh`, plus `--full` under `FULL_BATTERY`), never a bare `test-all.sh`. `wait_rc` is the script's status, never `rc`: the battery's `rc` and the wait's status are different facts. **Only 42 continues.** A stray 1 (`set -u` abort), 127 (script not found) or 130 (interrupt) lands in the `*` arm and stops; the suite executes this recipe against stubs for every arm. `WAITING` lines arrive about once a minute and are progress only: take no action on them. Exit 42 is shared with `battery-owed.sh` SKIPPABLE on purpose (same caller action, independent contracts).
36
+
37
+ ## The record (exit 42 only)
38
+
39
+ Print the verdict line in the transcript (the script already does: `BATTERY_REFUSAL_WAIT verdict=CI_IS_THE_GATE waited_s=<n> ...`) and add exactly this line to the PR body's Test plan, with `<n>` from `waited_s`:
40
+
41
+ ```text
42
+ Local battery refused (sibling contention); waited <n>s; CI "test" is the authoritative gate; local run NOT executed.
43
+ ```
44
+
45
+ The line states what did not happen. It never says the tests passed, and it is not evidence for the diff: CI's required `test` context is the gate, and a red there is fixed like any red.
46
+
47
+ ## Where CI is not the gate
48
+
49
+ The `apps/web-platform/infra/` tree has no required CI check (#6480), so a diff touching it (or `.github/workflows/apply-web-platform-infra.yml`, an empty or unresolvable diff, or any git failure resolving it) never gets 42: after the budget the script answers 12 and the local run is queued inside the lock. The same holds for an explicit `--full`, and for a log carrying `AFFECTED_FALLBACK reason=force-all` (the operator's whole-battery lever).
50
+
51
+ ## Known limits
52
+
53
+ - Idle is read from `--capacity`, which still counts a stale orphan past `TC_RUNTIME_CEILING_S` and low `/tmp`, while the refusal counts fresh siblings only. After the fresh sibling drains, an orphan can hold capacity non-idle and the wait runs to the budget; the loss is bounded and ends in CI or the lock queue. A stale orphan is itself an operator-visible fault.
54
+ - The wait can overshoot `--budget-s` by one capacity probe (`--probe-timeout-s`, default 30).
55
+ - A capacity reading anywhere in the budget counts (a transient probe failure on the last poll does not turn a long wait into a stop). A `--capacity` that is never readable is only discovered after the whole budget.
56
+ - If no rc file ever appears the wrapper was reaped (no rc file means a harness reap, SKILL.md): stop the Monitor and read `$LOG`. `$d` lives under `TMPDIR` and is not removed.
57
+ - Run from the repository root with an absolute `TMPDIR`: the script refuses a relative state path.
58
+
59
+ ## See also
60
+
61
+ - [affected-gate-contract.md](${CLAUDE_PLUGIN_ROOT}/skills/ship/references/affected-gate-contract.md): the rc contract of the affected gate (rc 4 = refused, rc 6 = budget deferral).
62
+ - When substituting hand-picked suites for a refused gate instead, derive them from the diff's new vocabulary, not its file names: `knowledge-base/project/learnings/2026-09-11-the-shard-i-substituted-for-a-refused-gate-was-the-one-that-was-red.md`.
@@ -0,0 +1,316 @@
1
+ #!/usr/bin/env bash
2
+ # Bounded wait for a REFUSED local battery, then "CI is the gate" (P4d, #10924).
3
+ #
4
+ # WHEN THIS RUNS. `soleur:ship` Phase 4 launches the detached local battery. When another
5
+ # worktree already runs a full-gate battery, `scripts/test-all.sh` refuses with rc=4 ("REFUSED,
6
+ # nothing ran") and the log carries
7
+ # ERROR: refusing a full-gate run <dash> N sibling full-gate run(s) already in flight
8
+ # That is the ONLY refusal time can clear. This script waits for the sibling to drain, bounded
9
+ # by a wall-clock budget, and prints a machine verdict. It does NOT change the runner's rc
10
+ # contract (many consumers); the verdict lives here, ship-side.
11
+ #
12
+ # SCOPE. rc=4 is the refusal form: it arises for a `--full` run or an affected run that
13
+ # degraded to full. A plain affected run is exempt from the refusal and QUEUES on the lock; that
14
+ # form is already bounded by `affected-tests.sh` rc 6 (budget deferral, CI authoritative). This
15
+ # script is Soleur-repo specific: it needs `scripts/test-all.sh --capacity` and the runner's
16
+ # refusal text, and answers NOT_WAITABLE or QUEUE_IN_LOCK where either is absent.
17
+ #
18
+ # USAGE
19
+ # battery-refusal-wait.sh --log FILE --state FILE [--budget-s N] [--interval-s N]
20
+ # [--probe-timeout-s N] [--full]
21
+ # battery-refusal-wait.sh --classify-only FILE # class=contention|contention-force-all|not-waitable
22
+ #
23
+ # --log FILE the refused run's log
24
+ # --state FILE episode state: the epoch of the first call, so the budget is shared
25
+ # across relaunches. Create it EMPTY with mktemp; an empty file starts an
26
+ # episode. A malformed, future or stale (> 6 h) epoch exits 2.
27
+ # --budget-s N wall-clock budget (default 1800: the documented escalation point; a full
28
+ # gate runs ~35-45 min, so on a typical contended start the budget lapses
29
+ # to CI, which is intended). The wait can overshoot it by one probe.
30
+ # --interval-s N poll interval (default 60)
31
+ # --probe-timeout-s N bound on one `--capacity` call (default 30)
32
+ # Flags only: no environment variable is read, so a stale export cannot
33
+ # shorten the wait into a CI_IS_THE_GATE verdict.
34
+ # --full the operator asked for the full local run by name; never defers
35
+ #
36
+ # EXIT CONTRACT (the caller branches on this, never on the prose):
37
+ # 42 CI_IS_THE_GATE budget elapsed, sibling still running, diff positively resolved with no
38
+ # infra trigger, no --full: record it and continue WITHOUT local evidence
39
+ # 10 RETRY capacity reports idle (CAPACITY_OK measured_runs=0): relaunch the battery
40
+ # 12 QUEUE_IN_LOCK the local run is the sole blocking gate (infra diff, unresolved diff) or
41
+ # was asked for by name (--full, or AFFECTED_FALLBACK reason=force-all in the log):
42
+ # queue inside the lock instead
43
+ # 11 NOT_WAITABLE time cannot clear this refusal (or capacity was never readable): stop
44
+ # 2 usage error, or a bad runtime input (state file, clock): stop
45
+ # 0 only for --classify-only
46
+ # anything else an error: the caller MUST stop
47
+ #
48
+ # ONLY 42 CONTINUES, and the oddness of that number is the point (as battery-owed.sh SKIPPABLE):
49
+ # a `set -u` abort exits 1, a missing file 127, a signal 128+N, and none of those may read as
50
+ # "skip the local battery". 42 is shared with battery-owed.sh SKIPPABLE ON PURPOSE: in both the
51
+ # caller action is the same (CI is the gate, skip the local run) and the two contracts are
52
+ # independent.
53
+ #
54
+ # THE CHOKEPOINT. Every path to 42 flows through the final `case`, which reads all six
55
+ # conjuncts: refusal class, budget spent, a capacity reading seen, --full absent, the diff
56
+ # positively resolved, no infra trigger.
57
+ #
58
+ # INFRA. The apps/web-platform/infra tree has no required CI check (#6480), so CI is NOT its
59
+ # gate and a deferral there would delete the only blocking one. The predicate follows
60
+ # scripts/test-all.sh (the `_diff_names` assembly and `_infra_in_diff`): the same two triggers,
61
+ # rename SOURCES included (`--name-status -M`), untracked files included, unanchored substring
62
+ # match. It is STRICTER on failure: any git read that fails, a grep that errors, or an empty
63
+ # change set is "unresolved". Git runs from the repo root with the same GIT_* variables cleared
64
+ # as the runner. The suite pins both trigger literals against the live runner.
65
+ #
66
+ # NOT WAITABLE: SOLEUR_SUBAGENT=1 is a declared env var polling cannot clear; selection
67
+ # refusals mean a gutted index; [FAIL]/[KILLED] mean the battery ran; a toolchain fault means it
68
+ # never started. AFFECTED_FALLBACK is classified by its reason (CTO ruling, 2026-10-28):
69
+ # index-missing and enumerate-unavailable are a broken tool (stop); force-all is the operator's
70
+ # whole-battery lever, the twin of --full (QUEUE_IN_LOCK); runner-changed and undecidable-diff
71
+ # stay waitable; an unknown reason stops.
72
+ #
73
+ # KNOWN LIMIT. Idle is read from `--capacity`, which still counts a stale orphan past the
74
+ # runtime ceiling and low /tmp, while the refusal counts fresh siblings only. After the fresh
75
+ # sibling drains an orphan can hold capacity non-idle, so the wait runs to the budget. That loss
76
+ # is bounded and ends in CI or the lock queue. A `--capacity` that is never readable (a repo
77
+ # without the Soleur runner) is only discovered after the whole budget: that wait ends in
78
+ # NOT_WAITABLE. A state epoch older than 6 h is refused, so a budget above that cannot be shared
79
+ # across a relaunch.
80
+ #
81
+ # Records, never claims: the PR Test plan line in references/battery-refusal-wait.md says the
82
+ # local run was NOT executed. Suite: plugins/soleur/test/ship-battery-refusal-wait.test.sh.
83
+ set -uo pipefail
84
+
85
+ # The runner clears these before its diffs; a stale export must not retarget ours.
86
+ unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_COMMON_DIR GIT_OBJECT_DIRECTORY \
87
+ GIT_ALTERNATE_OBJECT_DIRECTORIES GIT_NAMESPACE GIT_TEMPLATE_DIR GIT_EXEC_PATH \
88
+ GIT_CONFIG GIT_CONFIG_GLOBAL GIT_CONFIG_SYSTEM GIT_CONFIG_COUNT GIT_CONFIG_PARAMETERS GIT_EXTERNAL_DIFF
89
+
90
+ RC_RETRY=10
91
+ RC_NOT_WAITABLE=11
92
+ RC_QUEUE=12
93
+ RC_USAGE=2
94
+ RC_CI=42
95
+ STALE_S=21600
96
+
97
+ # Strip C0 controls, DEL and the Unicode line separators before printing: the log and the
98
+ # capacity output are not trusted to be single-line (same helper as battery-owed.sh).
99
+ _ctx_lib="$(cd "${BASH_SOURCE[0]%/*}/../../../scripts/lib" 2>/dev/null && pwd -P)/context-sanitize.sh"
100
+ # shellcheck source=/dev/null
101
+ [[ -r "$_ctx_lib" ]] && . "$_ctx_lib" || true
102
+ declare -F soleur_ctx_sanitize >/dev/null 2>&1 \
103
+ || soleur_ctx_sanitize() { LC_ALL=C tr -d '\000-\037\177' | LC_ALL=C sed $'s/\xe2\x80\xa8//g; s/\xe2\x80\xa9//g'; }
104
+ _sanitize() { printf '%s' "$*" | soleur_ctx_sanitize; }
105
+ say() { printf 'BATTERY_REFUSAL_WAIT %s\n' "$(_sanitize "$*")"; }
106
+
107
+ WAITED=0
108
+ verdict() { # <NAME> <exit> <reason>
109
+ say "verdict=$1 waited_s=$WAITED reason=$3"
110
+ exit "$2"
111
+ }
112
+ usage() { # a flag or argument error, before any wait started: stderr
113
+ printf 'BATTERY_REFUSAL_WAIT usage: %s\n' "$(_sanitize "$1")" >&2
114
+ exit "$RC_USAGE"
115
+ }
116
+ fault() { # a bad runtime input (state file, clock): a verdict line on stdout, where Monitor reads
117
+ say "verdict=ERROR waited_s=$WAITED reason=$1"
118
+ exit "$RC_USAGE"
119
+ }
120
+
121
+ LOG=""; STATE=""; BUDGET_S=1800; INTERVAL_S=60; PROBE_TIMEOUT_S=30; FULL=0; CLASSIFY_ONLY=""
122
+ is_posint() { [[ "$1" =~ ^[1-9][0-9]{0,5}$ ]]; }
123
+ while (( $# )); do
124
+ case "$1" in
125
+ --log) (( $# >= 2 )) || usage "--log needs a value"; LOG="$2"; shift 2 ;;
126
+ --state) (( $# >= 2 )) || usage "--state needs a value"; STATE="$2"; shift 2 ;;
127
+ --budget-s) (( $# >= 2 )) && is_posint "$2" || usage "--budget-s needs a positive integer"; BUDGET_S="$2"; shift 2 ;;
128
+ --interval-s) (( $# >= 2 )) && is_posint "$2" || usage "--interval-s needs a positive integer"; INTERVAL_S="$2"; shift 2 ;;
129
+ --probe-timeout-s) (( $# >= 2 )) && is_posint "$2" || usage "--probe-timeout-s needs a positive integer"; PROBE_TIMEOUT_S="$2"; shift 2 ;;
130
+ --full) FULL=1; shift ;;
131
+ --classify-only) (( $# >= 2 )) || usage "--classify-only needs a file"; CLASSIFY_ONLY="$2"; shift 2 ;;
132
+ *) usage "unknown argument: $1" ;;
133
+ esac
134
+ done
135
+
136
+ # --- classifier: whole-log scan, CR stripped, full refusal shape required -----------------------
137
+ # echoes `contention`, `contention:force-all` or `not-waitable:<reason>`.
138
+ classify() { # <file>
139
+ local f="$1" body bad r fb force=0
140
+ [[ -f "$f" && -r "$f" ]] || { echo "not-waitable:log-missing"; return 0; }
141
+ body="$(LC_ALL=C tr -d '\r' < "$f")"
142
+ [[ -n "$body" ]] || { echo "not-waitable:log-empty"; return 0; }
143
+ if grep -qE '\[FAIL\]|\[KILLED\]' <<<"$body"; then echo "not-waitable:battery-ran"; return 0; fi
144
+ if grep -qE 'mise ERROR|command not found' <<<"$body"; then echo "not-waitable:toolchain"; return 0; fi
145
+ if grep -qF 'AFFECTED_UNRESOLVED' <<<"$body"; then echo "not-waitable:selection-refusal"; return 0; fi
146
+ bad="$(grep -E 'AFFECTED_GATE_REFUSED reason=' <<<"$body" | grep -vE 'reason=runner-refused([[:space:]]|$)')"
147
+ if [[ -n "$bad" ]]; then echo "not-waitable:gate-refusal"; return 0; fi
148
+ if grep -qF 'SOLEUR_SUBAGENT=1 is set' <<<"$body"; then echo "not-waitable:subagent-env"; return 0; fi
149
+ # Every line that mentions the token must be exactly `AFFECTED_FALLBACK <ws> reason=<known>`;
150
+ # a line that does not parse (empty or quoted reason, no reason, a reason glued to extra
151
+ # characters) is an unknown reason and stops.
152
+ while IFS= read -r fb; do
153
+ [[ -n "$fb" ]] || continue
154
+ if [[ "$fb" =~ ^AFFECTED_FALLBACK[[:space:]]+reason=([a-z-]+)([[:space:]]|$) ]]; then r="${BASH_REMATCH[1]}"; else r=""; fi
155
+ case "$r" in
156
+ index-missing|enumerate-unavailable) echo "not-waitable:affected-index-broken"; return 0 ;;
157
+ force-all) force=1 ;;
158
+ runner-changed|undecidable-diff) ;;
159
+ *) echo "not-waitable:unknown-fallback-reason"; return 0 ;;
160
+ esac
161
+ done < <(grep -F 'AFFECTED_FALLBACK' <<<"$body")
162
+ if grep -qE '^ERROR: refusing a full-gate run .* [1-9][0-9]* sibling full-gate run\(s\) already in flight' <<<"$body"; then
163
+ if (( force == 1 )); then echo "contention:force-all"; else echo "contention"; fi
164
+ return 0
165
+ fi
166
+ echo "not-waitable:not-a-sibling-refusal"
167
+ }
168
+
169
+ if [[ -n "$CLASSIFY_ONLY" ]]; then
170
+ c="$(classify "$CLASSIFY_ONLY")"
171
+ case "$c" in
172
+ contention) echo "class=contention" ;;
173
+ contention:force-all) echo "class=contention-force-all" ;;
174
+ *) echo "class=not-waitable" ;;
175
+ esac
176
+ exit 0
177
+ fi
178
+
179
+ [[ -n "$LOG" ]] || usage "--log is required"
180
+ [[ -n "$STATE" ]] || usage "--state is required"
181
+ # The state path is absolute by contract (the recipe passes a mktemp path): the test below is the
182
+ # control; it refuses a relative path rather than let it resolve against the caller's cwd. The
183
+ # `/${STATE#/}` spelling that follows is behavior-neutral after that test; it exists so the
184
+ # fixture-operand ratchet can see the operand as rooted at / (no baseline row).
185
+ [[ "$STATE" == /* ]] || usage "--state must be an absolute path"
186
+ STATE="/${STATE#/}"
187
+
188
+ # DISPATCH-ANCHOR
189
+ CLASS_OK=0
190
+ class="$(classify "$LOG")"
191
+ case "$class" in
192
+ contention) CLASS_OK=1 ;;
193
+ contention:force-all) CLASS_OK=1; FULL=1 ;;
194
+ *) verdict NOT_WAITABLE "$RC_NOT_WAITABLE" "${class#not-waitable:}" ;;
195
+ esac
196
+
197
+ # --- clock: `date +%s` via PATH (a test seam, not an authority grant) ----------------------------
198
+ clock() {
199
+ local n
200
+ n="$(date +%s)" || return 1
201
+ [[ "$n" =~ ^[0-9]+$ ]] || return 1
202
+ printf '%s' "$n"
203
+ }
204
+ CALL_START="$(clock)" || fault "cannot-read-the-clock"
205
+
206
+ # --- episode state: the epoch of the first call, written atomically BEFORE the first poll -------
207
+ # A real epoch is exactly 10 digits with no leading zero: that rules out octal reads (`010`),
208
+ # 64-bit wrap (`1844...`), and `0`/tiny values that would make the whole budget look spent.
209
+ # One owning trap for the state temp file: every exit goes through `verdict`/`usage`/`fault`
210
+ # (all `exit`), so a crash between mktemp and mv cannot leave a stray file behind.
211
+ STATE_TMP=""
212
+ trap 'rm -f "${STATE_TMP:-}"' EXIT
213
+ init_episode() {
214
+ local cur
215
+ [[ -f "$STATE" && -r "$STATE" ]] || fault "state-file-missing-or-not-a-file"
216
+ cur="$(tr -d '[:space:]' < "$STATE")"
217
+ if [[ -z "$cur" ]]; then
218
+ STATE_TMP="$(mktemp "/${STATE#/}.XXXXXX")" || fault "cannot-write-the-state-file"
219
+ printf '%s\n' "$CALL_START" > "$STATE_TMP" && mv -f "$STATE_TMP" "$STATE" || fault "cannot-write-the-state-file"
220
+ cur="$CALL_START"
221
+ fi
222
+ [[ "$cur" =~ ^[1-9][0-9]{9}$ ]] || fault "state-file-holds-a-malformed-epoch"
223
+ (( cur <= CALL_START )) || fault "state-file-holds-a-future-epoch"
224
+ (( CALL_START - cur <= STALE_S )) || fault "state-file-is-stale-create-a-fresh-one"
225
+ EPOCH="$cur"
226
+ }
227
+ init_episode # EPISODE-INIT
228
+
229
+ # --- capacity ------------------------------------------------------------------------------------
230
+ # CAP is one of: idle | ok | contended | unknown | unreadable. Only a banner line (anchored, so a
231
+ # sibling detail row naming the token cannot count) with `CAPACITY_OK` and `measured_runs=0` on
232
+ # the SAME line is idle: CAPACITY_CONTENDED reason=low_tmp also prints measured_runs=0.
233
+ poll_capacity() {
234
+ local top out line
235
+ CAP=unreadable
236
+ top="$(git rev-parse --show-toplevel 2>/dev/null)" || return 0
237
+ [[ -f "$top/scripts/test-all.sh" ]] || return 0
238
+ out="$(timeout -k 1 "$PROBE_TIMEOUT_S" bash "$top/scripts/test-all.sh" --capacity 2>&1)" || return 0
239
+ line="$(grep -E '^(\[contention\][[:space:]]+)?(BANNER[[:space:]]+)?CAPACITY_(OK|CONTENDED|UNKNOWN)([[:space:]]|$)' <<<"$out" | head -1)"
240
+ [[ "$line" =~ ^(\[contention\][[:space:]]+)?(BANNER[[:space:]]+)?CAPACITY_(OK|CONTENDED|UNKNOWN)([[:space:]]|$) ]] || return 0
241
+ case "${BASH_REMATCH[3]}" in
242
+ OK)
243
+ if [[ "$line" =~ (^|[[:space:]])measured_runs=0([^0-9]|$) ]]; then CAP=idle; else CAP=ok; fi ;;
244
+ CONTENDED) CAP=contended ;;
245
+ UNKNOWN) CAP=unknown ;;
246
+ esac
247
+ return 0
248
+ }
249
+
250
+ SEEN=0
251
+ BUDGET_DONE=0
252
+ while :; do
253
+ poll_capacity
254
+ now="$(clock)" || fault "cannot-read-the-clock"
255
+ elapsed=$(( now - EPOCH ))
256
+ (( elapsed >= 0 )) || fault "clock-went-backwards"
257
+ WAITED="$elapsed"
258
+ case "$CAP" in
259
+ idle) verdict RETRY "$RC_RETRY" capacity-idle ;;
260
+ ok|contended) SEEN=1 ;;
261
+ esac
262
+ if (( elapsed >= BUDGET_S )); then BUDGET_DONE=1; break; fi
263
+ say "WAITING elapsed_s=$elapsed budget_s=$BUDGET_S capacity=$CAP"
264
+ remaining=$(( BUDGET_S - elapsed ))
265
+ (( remaining >= 1 )) || fault "internal-non-positive-sleep"
266
+ sleep "$(( INTERVAL_S < remaining ? INTERVAL_S : remaining ))" || fault "sleep-failed"
267
+ done
268
+
269
+ # --- infra predicate (follows scripts/test-all.sh; see the header) --------------------------------
270
+ infra_state() { # echoes clean | infra | unresolved
271
+ local top names="" out lit rc hit=0
272
+ top="$(git rev-parse --show-toplevel 2>/dev/null)" || { echo unresolved; return 0; }
273
+ out="$(git -C "$top" -c core.quotePath=false diff --name-only origin/main...HEAD 2>/dev/null)" || { echo unresolved; return 0; }
274
+ names="${names}
275
+ ${out}"
276
+ out="$(git -C "$top" -c core.quotePath=false diff --name-only HEAD 2>/dev/null)" || { echo unresolved; return 0; }
277
+ names="${names}
278
+ ${out}"
279
+ out="$(git -C "$top" -c core.quotePath=false diff --name-status -M HEAD 2>/dev/null)" || { echo unresolved; return 0; }
280
+ names="${names}
281
+ ${out}"
282
+ out="$(git -C "$top" -c core.quotePath=false diff --name-status -M origin/main...HEAD 2>/dev/null)" || { echo unresolved; return 0; }
283
+ names="${names}
284
+ ${out}"
285
+ out="$(git -C "$top" ls-files --others --exclude-standard 2>/dev/null)" || { echo unresolved; return 0; }
286
+ names="${names}
287
+ ${out}"
288
+ # A branch with nothing to test is not "clean": an empty change set means a read went wrong.
289
+ [[ -n "${names//[[:space:]]/}" ]] || { echo unresolved; return 0; }
290
+ for lit in 'apps/web-platform/infra/' '.github/workflows/apply-web-platform-infra.yml'; do
291
+ grep -qF -- "$lit" <<<"$names"; rc=$?
292
+ case "$rc" in
293
+ 0) hit=1 ;;
294
+ 1) ;;
295
+ *) echo unresolved; return 0 ;;
296
+ esac
297
+ done
298
+ if (( hit == 1 )); then echo infra; else echo clean; fi
299
+ }
300
+
301
+ # --- the chokepoint: every path to exit 42 flows through this one case ----------------------------
302
+ infra="$(infra_state)"
303
+ case "$CLASS_OK:$BUDGET_DONE:$SEEN:$FULL:$infra" in
304
+ 1:1:0:*:*)
305
+ verdict NOT_WAITABLE "$RC_NOT_WAITABLE" capacity-unreadable ;;
306
+ 1:1:1:1:*)
307
+ verdict QUEUE_IN_LOCK "$RC_QUEUE" full-requested ;;
308
+ 1:1:1:0:infra)
309
+ verdict QUEUE_IN_LOCK "$RC_QUEUE" infra-diff ;;
310
+ 1:1:1:0:unresolved)
311
+ verdict QUEUE_IN_LOCK "$RC_QUEUE" diff-unresolved ;;
312
+ 1:1:1:0:clean)
313
+ verdict CI_IS_THE_GATE "$RC_CI" sibling-contention-budget-elapsed ;;
314
+ *)
315
+ verdict NOT_WAITABLE "$RC_NOT_WAITABLE" internal ;;
316
+ esac