fix(wake): #942 follow-up — whole-string knob validation; grep line anchors admit multi-line values
ci/woodpecker/pr/ci Pipeline was successful

mos-dt's post-verdict residual (non-blocking, comments 19484/19487): grep is
LINE-oriented, so ^[0-9]{1,9}$ binds per line and a knob with an embedded
newline ($'300\n8', $'300\nabc') passes the regex whole yet is FATAL inside
$((...)) under set -u — the same poll-killing class #942 fixed, reachable only
via the env-config operand (snap_ts is immune: jq's number type-check cannot
emit an embedded newline).

Fix (mos-dt-verified pattern): replace grep with a whole-string case pattern —
'' and *[!0-9]* reject, length <= 9 — identical accept/reject to the regex on
every single-line value, rejects both multi-line cases. 10# radix force
unchanged. Two new D13 sub-cases (SHA-CC2/SHA-CC3) cover exactly the repros;
det_seq assertion 6 -> 8. Manifest states the string-extent rule: the validator
and the consumer must agree on STRING EXTENT, not just shape and radix.

Suite: 13 groups, D13 green 4/4 local runs; sole intermittent failure is the
known pre-existing D4 fd-9 flake (carried separately by mos-dt).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NsKce8iZuSuRnu3gVMCBKB
This commit is contained in:
Jason Woltje
2026-07-30 06:28:19 -05:00
co-authored by Claude Fable 5
parent 3e47fc076f
commit 2621335e77
3 changed files with 46 additions and 12 deletions
@@ -295,16 +295,24 @@ _poll_source() {
# is interpolated into $((...)) under set -u, so a non-numeric value
# ('300s', '5m', 'abc') would be FATAL to the poll — the one thing this
# block must never be. Resolve it ONCE, validate, fall back loudly.
local now_s slack
local now_s slack slack_ok
slack="${WAKE_SNAPSHOT_TS_FUTURE_SLACK:-300}"
if ! printf '%s' "$slack" | grep -Eq '^[0-9]{1,9}$'; then
echo "detector.sh: WAKE_SNAPSHOT_TS_FUTURE_SLACK='$slack' is not a plain non-negative integer (seconds) — falling back to 300, poll continues (#940)." >&2
# NOT grep: grep is LINE-oriented, so ^...$ anchors bind per line and a
# multi-line value ($'300\n8') passes the regex yet is FATAL in $((...)).
# The case pattern matches the WHOLE string, newlines included. (snap_ts
# is immune: jq's number type-check above cannot emit an embedded newline.)
case "$slack" in
'' | *[!0-9]*) slack_ok=1 ;;
*) [ "${#slack}" -le 9 ] && slack_ok=0 || slack_ok=1 ;;
esac
if [ "$slack_ok" -ne 0 ]; then
echo "detector.sh: WAKE_SNAPSHOT_TS_FUTURE_SLACK='$slack' is not a plain non-negative integer of at most 9 digits (seconds) — falling back to 300, poll continues (#940)." >&2
slack=300
fi
# Shape validation is not radix validation: bash reads a leading zero as
# OCTAL, so '08'/'09' pass the regex yet are FATAL in $((...)), and
# OCTAL, so '08'/'09' pass the shape check yet are FATAL in $((...)), and
# '0300' silently means 192. Force base-10 so the knob means what the
# operator wrote (safe: the regex above guarantees pure digits).
# operator wrote (safe: the case pattern above guarantees pure digits).
slack=$((10#$slack))
now_s="$(date +%s)"
if [ "$snap_ts" -gt $((now_s + slack)) ]; then