@chrono-meta/fh-gate 3.30.0 → 3.31.0

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.
@@ -19,7 +19,27 @@ set -u
19
19
  ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
20
20
  CAL="$ROOT/scripts/sidecar_calibrate.sh"
21
21
  pass=0; fail=0
22
- PORT="${FH_LANE_PORT:-18011}"
22
+ # PORT — asked of the OS, not hardcoded (2026-10-26). It was `${FH_LANE_PORT:-18011}`, and 18011
23
+ # is machine-global: a TCP port is not scoped to a checkout. Two copies of this suite running in
24
+ # DIFFERENT trees on one machine both try to bind it; the loser's stub dies with "Address already in
25
+ # use", every lane in the losing run then talks to the WINNER's stub, and the verdicts come back as
26
+ # an unreproducible mix that reads exactly like a flake — measured 2026-10-26, when this suite and
27
+ # three others only ever went red under concurrent load and passed 3/3 standalone in both trees.
28
+ # The lesson generalizes past this file: a fixture keyed on a machine-global name (a port, a
29
+ # /proc-wide process pattern, a fixed /tmp path) is not hermetic however hermetic its logic is.
30
+ # FH_LANE_PORT still wins when set — an operator pinning a port has a reason, and overriding them
31
+ # would trade one surprise for another.
32
+ _free_port() { # a port the OS says is free right now: bind :0, read it back, release it
33
+ python3 -c 'import socket
34
+ s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
35
+ s.bind(("127.0.0.1", 0)); print(s.getsockname()[1]); s.close()'
36
+ }
37
+ # A released ephemeral port can be taken in the window before the stub binds it — rare, and the
38
+ # honest answer to rare is a retry that NAMES itself, not a lane failure that looks like a defect
39
+ # in the subject. start_stub re-picks on each attempt when the port was not pinned.
40
+ PORT="${FH_LANE_PORT:-}"
41
+ [ -n "$PORT" ] || PORT="$(_free_port)"
42
+ PORT_PINNED=0; [ -n "${FH_LANE_PORT:-}" ] && PORT_PINNED=1
23
43
  SRV_PID=""
24
44
 
25
45
  # `wait` after the kill, so bash reaps the child quietly instead of printing "Terminated: 15" into
@@ -97,15 +117,24 @@ HTTPServer(("127.0.0.1", PORT), H).serve_forever()
97
117
  PY
98
118
  # shellcheck disable=SC2016
99
119
  start_stub() {
100
- stop_stub
101
- python3 "$STUB" "$PORT" "$1" >/dev/null 2>&1 &
102
- SRV_PID=$!
103
- for _ in $(seq 1 40); do
104
- # Ready = ANY HTTP answer, not a 2xx: the notollama mode answers /api/version with a 404 on
105
- # purpose, and `-f` would read that as "stub never came up".
106
- _c="$(curl -s -o /dev/null --max-time 1 -w '%{http_code}' "http://127.0.0.1:$PORT/api/version" 2>/dev/null)"
107
- [ "${_c:-000}" != "000" ] && return 0
108
- sleep 0.25
120
+ local _try
121
+ for _try in 1 2 3; do
122
+ stop_stub
123
+ [ "$_try" -eq 1 ] || [ "$PORT_PINNED" -eq 1 ] || PORT="$(_free_port)"
124
+ python3 "$STUB" "$PORT" "$1" >/dev/null 2>&1 &
125
+ SRV_PID=$!
126
+ for _ in $(seq 1 40); do
127
+ # Ready = ANY HTTP answer, not a 2xx: the notollama mode answers /api/version with a 404 on
128
+ # purpose, and `-f` would read that as "stub never came up".
129
+ _c="$(curl -s -o /dev/null --max-time 1 -w '%{http_code}' "http://127.0.0.1:$PORT/api/version" 2>/dev/null)"
130
+ [ "${_c:-000}" != "000" ] && return 0
131
+ # The stub process being GONE is a different fact from "not ready yet", and waiting out the
132
+ # remaining 10 s on a dead process is how a bind collision used to present as a timeout.
133
+ kill -0 "$SRV_PID" 2>/dev/null || break
134
+ sleep 0.25
135
+ done
136
+ [ "$PORT_PINNED" -eq 1 ] && break
137
+ echo " ⚠️ stub did not come up on port $PORT (attempt $_try/3) — re-picking a free port" >&2
109
138
  done
110
139
  return 1
111
140
  }
@@ -163,13 +192,80 @@ MODELS=" stub-model:1b , " \
163
192
  expect "S14 padding around commas is trimmed" ok YES "PIN-OK(envelope)" "INPUT-ERROR"
164
193
 
165
194
  # S6 — absence must be MEASURED, never assumed. No server at the host at all.
166
- out=$( FH_OLLAMA_HOST="http://127.0.0.1:$((PORT+7))" bash "$CAL" --only ollama --quiet 2>&1 )
195
+ # The dead host used to be `$((PORT+7))`, which is arithmetic on an assumption: PORT+7 is free
196
+ # because nobody is expected to be there. On a busy machine somebody is, and then this lane asserts
197
+ # ABSENT against a host that answers and goes red for a reason that has nothing to do with the
198
+ # subject. Ask the OS for a port and then CHECK it is silent — the lane's own premise, measured.
199
+ _dead_port=""
200
+ for _ in 1 2 3; do
201
+ _p="$(_free_port)"
202
+ [ "$(curl -s -o /dev/null --max-time 1 -w '%{http_code}' "http://127.0.0.1:$_p/api/version" 2>/dev/null)" = "000" ] \
203
+ && { _dead_port="$_p"; break; }
204
+ done
205
+ if [ -z "$_dead_port" ]; then
206
+ # UNMEASURED, not a pass and not a failure of the subject: three ports in a row answered, so this
207
+ # lane never got the silent host its premise needs. Counted as a failure because an unmeasured
208
+ # known pair proves nothing — the same rule the suites around this one already follow.
209
+ printf ' ❌ %-44s UNMEASURED: could not obtain a silent port (3 tries)\n' "S6 no server at host"
210
+ fail=$((fail+1))
211
+ else
212
+ out=$( FH_OLLAMA_HOST="http://127.0.0.1:$_dead_port" bash "$CAL" --only ollama --quiet 2>&1 )
167
213
  if printf '%s' "$out" | grep -q 'ABSENT — no server at the configured host'; then
168
214
  printf ' ✅ %-44s reported ABSENT\n' "S6 no server at host"; pass=$((pass+1))
169
215
  else
170
216
  printf ' ❌ %-44s (expected a measured ABSENT line)\n' "S6 no server at host"
171
217
  printf ' out: %s\n' "$(printf '%s' "$out" | head -3)"; fail=$((fail+1))
172
218
  fi
219
+ fi
220
+
221
+ # ── S20 (2026-10-26) — the known pair for the port repair itself ───────────────────────────────
222
+ # The defect this suite shipped with was not in its logic: PORT was the fixed 18011, so two copies
223
+ # running in different trees on one machine fought over one socket. That is only a repair if the
224
+ # collision is REAL and the repair survives it, so this lane holds a port open and asks both
225
+ # questions against the live code rather than against my description of it.
226
+ echo "── S20 port is not machine-global ──"
227
+ _hold_out="$(mktemp)"; _held=""
228
+ python3 -c 'import socket,sys,time
229
+ s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
230
+ s.bind(("127.0.0.1", 0)); s.listen(1)
231
+ print(s.getsockname()[1], flush=True)
232
+ time.sleep(45)' > "$_hold_out" 2>/dev/null &
233
+ _hold_pid=$!
234
+ for _ in $(seq 1 40); do _held="$(head -1 "$_hold_out" 2>/dev/null)"; [ -n "$_held" ] && break; sleep 0.25; done
235
+ _saved_port="$PORT"; _saved_pinned="$PORT_PINNED"
236
+ if [ -z "$_held" ]; then
237
+ # UNMEASURED: no holder, so neither arm below means anything. Counted, for the same reason S6's
238
+ # unmeasured arm is counted — a known pair that did not run is not a known pair that passed.
239
+ printf ' ❌ %-44s UNMEASURED: could not hold a port open\n' "S20 occupied-port known pair"
240
+ fail=$((fail+1))
241
+ else
242
+ # known-POSITIVE: the collision is real. Pin the stub to the held port and the stub cannot come
243
+ # up. If this arm ever passes, binding a busy port stopped failing and the lane below proves
244
+ # nothing — so the positive control is what keeps the negative one honest.
245
+ PORT="$_held"; PORT_PINNED=1
246
+ if start_stub ok 2>/dev/null; then
247
+ printf ' ❌ %-44s a stub came up on an OCCUPIED port — the control is broken\n' "S20a known-positive"
248
+ fail=$((fail+1))
249
+ else
250
+ printf ' ✅ %-44s a pinned, occupied port really does stop the stub\n' "S20a known-positive"
251
+ pass=$((pass+1))
252
+ fi
253
+ stop_stub
254
+ # known-NEGATIVE: with the port NOT pinned, the same occupied port is simply not chosen — which
255
+ # is the whole repair. The old `${FH_LANE_PORT:-18011}` form had no way to express this.
256
+ PORT_PINNED=0; PORT="$_held"
257
+ if start_stub ok && [ "$PORT" != "$_held" ]; then
258
+ printf ' ✅ %-44s unpinned: picked %s instead of the occupied port\n' "S20b known-negative" "$PORT"
259
+ pass=$((pass+1))
260
+ else
261
+ printf ' ❌ %-44s unpinned run did not route around the occupied port (port=%s)\n' "S20b known-negative" "$PORT"
262
+ fail=$((fail+1))
263
+ fi
264
+ stop_stub
265
+ fi
266
+ kill "$_hold_pid" 2>/dev/null; wait "$_hold_pid" 2>/dev/null
267
+ rm -f "$_hold_out"
268
+ PORT="$_saved_port"; PORT_PINNED="$_saved_pinned"
173
269
 
174
270
  echo
175
271
  if [ "$fail" -eq 0 ]; then
@@ -474,7 +474,79 @@ else
474
474
  # The loop must route through the function — a lifted function with no caller is decoration.
475
475
  # Uncommented line only (codex review 2026-10-19: a commented-out call passed the first form).
476
476
  # Still a text check — it cannot prove the line is reached; that residual is named, not closed.
477
- grep -qE '^[[:space:]]+_pair_rc_verdict "\$_lbl" "\$_subj" "\$_rc" \|\| fail=1' "$SELFCHECK"; chk $? "pair loop calls _pair_rc_verdict (uncommented) and sets fail on it"
477
+ grep -qE '^[[:space:]]+_pair_rc_verdict "\$_lbl" "\$_subj" "\$_rc" "\$_bud" \|\| fail=1' "$SELFCHECK"; chk $? "pair loop calls _pair_rc_verdict (uncommented, with the budget) and sets fail on it"
478
+ # The TIMEOUT line must name the budget the run actually used. Before 2026-10-26 it printed a
479
+ # hardcoded "limit 300 s"; once budgets differ per suite, that line is a wrong fact in the one
480
+ # place a reader greps. Known pair: a non-default budget must appear, and the default must not.
481
+ _o=$(_pair_rc_verdict lane_x.sh subj_x 124 600)
482
+ printf '%s' "$_o" | grep -q 'budget 600 s' && ! printf '%s' "$_o" | grep -q 'budget 300 s'
483
+ chk $? "rc=124 with a 600 s budget → the line names 600, not the default"
484
+ _o=$(_pair_rc_verdict lane_x.sh subj_x 124)
485
+ printf '%s' "$_o" | grep -q 'budget 300 s'; chk $? "rc=124 with no budget argument → falls back to the default, still named"
486
+ fi
487
+
488
+ # ── Per-suite lane budget (2026-10-26) ────────────────────────────────────────
489
+ # fh_signal_2026-10-26_mutation-probe-budget-cliff: test_mutation_probe_lanes.sh takes 318–322 s
490
+ # standalone and the loop's single global `timeout 300` killed it, so 122 known-pair lanes reported
491
+ # as one TIMEOUT line and went UNMEASURED. Nothing in the suite or its subject had changed. The
492
+ # repair is a per-suite budget plus an advisory margin line; these lanes pin BOTH halves, because a
493
+ # budget with no margin warning reproduces the same blindness one host-slowdown later.
494
+ echo ""
495
+ echo "── per-suite lane budget (_lane_budget · _lane_margin_note) ──"
496
+ _BUDFN=$(sed -n '/^_lane_budget() {/,/^}/p' "$SELFCHECK")
497
+ _MARGINFN=$(sed -n '/^_lane_margin_note() {/,/^}/p' "$SELFCHECK")
498
+ # `grep -m1 FILE` rather than `grep … | head -1`: under `set -o pipefail` (line 23) an early-exit
499
+ # consumer SIGPIPEs the producer and the residual rc becomes the pipeline's — the defect class
500
+ # scripts/pipefail_earlyexit_scan.sh locks at zero NEW sites. Measured here: the first draft of
501
+ # these lanes added three such sites and selfcheck's class-lock lane went red on my own commit.
502
+ _BUDDEF=$(grep -m1 -E '^_LANE_BUDGET_DEFAULT=[0-9]+$' "$SELFCHECK")
503
+ if [ -z "$_BUDFN" ] || [ -z "$_MARGINFN" ] || [ -z "$_BUDDEF" ]; then
504
+ chk 1 "_lane_budget / _lane_margin_note / _LANE_BUDGET_DEFAULT found in selfcheck.sh (lane would test nothing)"
505
+ else
506
+ eval "$_BUDDEF"; eval "$_BUDFN"; eval "$_MARGINFN"
507
+ _WARNLINE=$(grep -m1 -E '^_LANE_BUDGET_WARN_PCT=[0-9]+' "$SELFCHECK")
508
+ _WARNPCT=$(sed -E 's/[^0-9]*([0-9]*).*/\1/' <<<"$_WARNLINE")
509
+ [ -n "$_WARNPCT" ] && eval "_LANE_BUDGET_WARN_PCT=$_WARNPCT"
510
+
511
+ [ "$(_lane_budget some_other_suite.sh)" = "$_LANE_BUDGET_DEFAULT" ]
512
+ chk $? "an undeclared suite gets the default budget ($_LANE_BUDGET_DEFAULT s) — the table is an exception list, not a rewrite"
513
+ # known-POSITIVE for the defect: the measured suite's budget must EXCEED its measured cost, or
514
+ # the repair changed nothing. 322 s is the slowest of the three reps taken on 2026-10-26.
515
+ [ "$(_lane_budget test_mutation_probe_lanes.sh)" -gt 322 ]
516
+ chk $? "test_mutation_probe_lanes.sh's budget exceeds its measured 322 s — the kill that started this cannot recur at the same cost"
517
+ # known-NEGATIVE: the default does NOT, which is why the suite died. If someone "fixes" this by
518
+ # raising the default instead, this lane goes red and says so.
519
+ [ "$_LANE_BUDGET_DEFAULT" -lt 322 ]
520
+ chk $? "known-NEGATIVE: the default budget is still below that cost (the repair is per-suite, not a global raise)"
521
+ # A budget with no bound is the other wrong repair: it turns a killed suite into a hung CI job.
522
+ [ "$(_lane_budget test_mutation_probe_lanes.sh)" -gt 0 ] && [ "$(_lane_budget test_mutation_probe_lanes.sh)" -le 1800 ]
523
+ chk $? "the raised budget is still a BOUND (>0 and ≤1800 s), not an absent timeout"
524
+
525
+ # The margin note: fires close to the budget, silent well inside it, and says PASSED either way.
526
+ _o=$(_lane_margin_note lane_x.sh 290 300)
527
+ printf '%s' "$_o" | grep -q '^NOTE ' && printf '%s' "$_o" | grep -q 'PASSED'
528
+ chk $? "known-POSITIVE: 290 s of a 300 s budget → an advisory NOTE that says the suite passed"
529
+ _o=$(_lane_margin_note lane_x.sh 290 300)
530
+ ! printf '%s' "$_o" | grep -qE '^(FAIL|TIMEOUT|HARNESS ERROR|❌)'
531
+ chk $? "the advisory is not a verdict — no FAIL/TIMEOUT/HARNESS ERROR vocabulary in it"
532
+ _o=$(_lane_margin_note lane_x.sh 30 300); [ -z "$_o" ]
533
+ chk $? "known-NEGATIVE: 30 s of a 300 s budget → silent (a note on every suite is a note nobody reads)"
534
+ _lane_margin_note lane_x.sh 290 300 >/dev/null; chk $? "the advisory returns 0 — it can never set fail"
535
+ _o=$(_lane_margin_note lane_x.sh 5 0); [ -z "$_o" ]
536
+ chk $? "a zero budget → silent, no division by zero"
537
+ # It must be WIRED into the loop. A margin function nobody calls is the decoration this repo
538
+ # names built-but-not-wired; text check only, same residual as the _pair_rc_verdict grep above.
539
+ grep -qE '^[[:space:]]+\[ "\$_t0" -gt 0 \].*_lane_margin_note "\$_lbl"' "$SELFCHECK"
540
+ chk $? "the pair loop calls _lane_margin_note (uncommented)"
541
+ grep -qE '^[[:space:]]+_lane_to=""; command -v timeout' "$SELFCHECK"
542
+ chk $? "the loop installs a PER-SUITE timeout var (not reassigning the shared \$_LANE_TO)"
543
+ # Why that last lane exists: $_LANE_TO is read again by two dispatches hundreds of lines below the
544
+ # loop. Reassigning it per suite would hand one suite's budget to unrelated blocks, silently.
545
+ # Ends in `wc -l`, which reads to EOF: `| grep -q .` here would kill awk mid-stream and hand the
546
+ # pipeline a SIGPIPE rc under pipefail. Same reason as the two greps above.
547
+ _lto_below=$(grep -n '\$_LANE_TO' "$SELFCHECK" | awk -F: '$1>1200' | wc -l)
548
+ [ "$_lto_below" -ge 1 ]
549
+ chk $? "known-POSITIVE for that risk: \$_LANE_TO really is still read below the loop ($_lto_below sites)"
478
550
  fi
479
551
 
480
552
  echo ""
@@ -79,6 +79,22 @@ When persisting new assets (memory · feedback · patterns · rules) during a se
79
79
 
80
80
  When the judgment is ambiguous, the AI **states synergy potential first** then delegates the location decision to the user.
81
81
 
82
+ ## When this file and the code disagree
83
+
84
+ - When this file states a convention (naming, structure, error types, module style) that the existing code does not follow, follow the established convention of the code nearest to your change (the same package or module) and say that you found the conflict. Do not rewrite unrelated existing code to match this file; changes the requested task needs are fine. A rule this file explicitly scopes to new or changed code (a migration, or "new X must ...") wins within that scope, and its security, privacy, safety and gate rules always win, whatever form they take.
85
+
86
+ <!-- Measured 2026-10-24, Sonnet 5.5, small synthetic fixtures, 4 runs per cell (arXiv:2610.30571 shape). Three batches:
87
+ (1) 3 stale-convention fixtures, no line: the stale file line was followed in 10/12 runs, existing definitions rewritten
88
+ to match it in 4/12. An early wording without the "scoped to new code" exception then overrode an explicit
89
+ migration line 4/4. Keep that exception.
90
+ (2) 8 fixtures (the 3 above + migration + 4 written later: rule for new code, security rule phrased as an error rule,
91
+ monorepo nearest package, unseen stale rule), no line vs a near-final wording: right 24/32 vs 32/32, detected
92
+ definition rewrites 2 runs vs 0. On the 4 later fixtures both arms were right 16/16, so no regression was observed
93
+ there and no benefit was shown either.
94
+ (3) This wording ("wins within that scope"), 4 core fixtures: right 16/16, 0 rewrites. Every diff in (2)-(3) read by hand.
95
+ Not measured: a stale convention dressed as a gate rule ("gate: reject camelCase") would now always win. -->
96
+
97
+
82
98
  ## Knowledge Hub (forge-harness)
83
99
 
84
100
  Persistent knowledge for this project is stored at `~/projects/forge-harness/`.