Skip to content

fix(bin): avoid bash 5.2 sibling $() in recovery mint and delivery log - #5773

Merged
kunchenguid merged 5 commits into
kunchenguid:mainfrom
Lakescape:fm/fm-wake-lib-sibling-subst-bash52-2
Sep 26, 2026
Merged

kunchenguid merged 5 commits into
kunchenguid:mainfrom
Lakescape:fm/fm-wake-lib-sibling-subst-bash52-2

Conversation

@Lakescape

Copy link
Copy Markdown
Contributor

Intent

Remove the Bash 5.2 sibling $() hazard from recovery-generation mint and wake-delivery logging while preserving nonempty generations and the prior mint failure semantics (grammar-valid token and durable wake row on pid/date miss). Keep the accepted post-review fix that drops the refuse/grammar-guard paths.

What Changed

  • _fm_recovery_marker_write_locked in bin/fm-wake-lib.sh no longer builds the recovery generation from two sibling $() substitutions on one line. It now gets the pid through fm_current_pid's output-variable form, stores date +%s in its own assignment, and then builds pid.epoch.suffix. As before, a failed pid or date lookup is not checked, so the mint still produces a grammar-valid token and the durable wake row still appends.
  • watch_delivery_publish in bin/fm-push-transition-lib.sh now runs the identity and reason cleaners as separate assignments before a single printf. It no longer passes them to printf as sibling $() arguments. This avoids the bash 5.2 parse error that sibling substitutions can trigger when a CHLD trap is set.
  • Adds test_recovery_mint_and_delivery_log_avoid_sibling_subst to tests/fm-wake-queue.test.sh. The test checks that:
    • the minted marker has a nonempty, grammar-valid generation in pid.epoch.suffix form;
    • the delivery log line keeps its pid, identity and reason fields;
    • under bash ≥ 5 with trap : CHLD, fm_recovery_marker_publish still writes a valid generation without a parse error.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change only splits sibling $() into sequential assignments in two helpers. The earlier refusal paths and grammar guard are gone. Pid and date misses still produce the old .epoch.suffix / pid..suffix token, and every caller already runs the write inside an if ! context, so errexit behavior is unchanged.

Testing

Called the wake-queue and delivery-log libraries directly under /bin/bash 3.2, with isolated FM_STATE_OVERRIDE dirs, on both base and target. Four scenarios ran: normal mint, a date miss, a pid miss injected at mint, and a delivery-log line. The target matched base's observable state in all four: grammar-valid nonempty generations, durable rows appended, and a 3-field log line. The focused regression-test run is recorded as untested here because the prior payload did not mark it as a live product run. An earlier pid-miss attempt that shadowed sh hung in lock acquisition on both base and target: the lock needs a pid before mint runs, so this hang is pre-existing and unrelated to the change. The injection was then narrowed to the mint call site. The Bash 5.2 CHLD-trap scenario is untested because no Bash 5.2 binary is available. No UI surface is involved.

  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Normal durable wake append mints a nonempty pid.epoch.suffix recovery generation and appends the queue row ✅ pass live mint-and-delivery-base-vs-target.txt S1: target marker pending:downtime:5053.1790415196.1FMkjo, 1 queue row; base shape identical
Adversarial: date(1) fails during mint; a grammar-valid token is still minted and the durable wake row is still appended, same as base ✅ pass live mint-and-delivery-base-vs-target.txt S2: target marker pending:downtime:5581..RKm4iM, rc=0, row appended; base pending:downtime:8039..tlJql7, rc=0, row appended
Adversarial: pid lookup fails at mint; a grammar-valid token is still minted and the durable wake row is still appended (no refuse path), same as base ✅ pass live mint-and-delivery-base-vs-target.txt S3: target marker pending:downtime:.1790415196.T8r9uX, rc=0, row appended; base pending:downtime:.1790415197.gU2xlg, rc=0, row appended
Wake-delivery log records one 3-field pid/identity/reason line with tabs and newlines cleaned, same as base ✅ pass live mint-and-delivery-base-vs-target.txt S4: log '4242<TAB>pane id<TAB>signal: line1 line2', fields=3 on both base and target
New regression test and neighboring recovery-generation tests pass ⏸️ untested no The prior payload recorded this as a unit-test run (live=false), not a live product run, so it did not establish a live result. Driving it live would need these recovery-generation paths exercised aga…
Under Bash 5.2 with a CHLD trap set, recovery mint and delivery logging run without the sibling-$() parse error ⏸️ untested no No Bash 5.2 binary on this host (only /bin/bash 3.2.57), and installing packages is out of bounds here. To cover this, run tests/fm-wake-queue.test.sh on a CI runner or host with bash 5.2 on PATH; the…
Evidence: Mint and delivery-log scenarios, base 72b63ee vs target bca1f0d (bash 3.2)

Source: Mint and delivery-log scenarios, base 72b63ee vs target bca1f0d (bash 3.2)

=== [TARGET bca1f0d] bash 3.2.57(1)-release  root=~/.no-mistakes/worktrees/90205a2052fe/01M3EGFQE4MDH1YFXVM1RP7KH8
-- S1 normal durable wake append
  append rc=0
  marker(.watcher-down)=[pending:downtime:5053.1790415196.1FMkjo]
  queue rows=1
    row: 1790415196<TAB>1<TAB>check<TAB>task<TAB>check: normal
  generation grammar: valid [5053.1790415196.1FMkjo]
-- S2 date(1) failure during mint (fake date exits 1, no output)
  append rc=0
  marker(.watcher-down)=[pending:downtime:5581..RKm4iM]
  queue rows=1
    row: <TAB>1<TAB>signal<TAB>k<TAB>signal: date-miss
  generation grammar: valid [5581..RKm4iM]
-- S3 pid failure at mint only (fm_current_pid wrapped to fail only when called from _fm_recovery_marker_write_locked; locks still get a pid)
  append rc=0
  marker(.watcher-down)=[pending:downtime:.1790415196.T8r9uX]
  queue rows=1
    row: 1790415196<TAB>1<TAB>stale<TAB>k<TAB>stale: pid-miss
  generation grammar: valid [.1790415196.T8r9uX]
  stderr:   (fault) pid miss injected in _fm_recovery_marker_write_locked
-- S4 wake-delivery log line (identity with TAB, reason with newline)
  publish rc=0
    log: 4242<TAB>pane id<TAB>signal: line1 line2
  fields=3

=== [BASE 72b63ee] bash 3.2.57(1)-release  root=/var/folders/k7/pv977h6550z7pncjygnj7xn80000gn/T//fm-mint.kMc649/base
-- S1 normal durable wake append
  append rc=0
  marker(.watcher-down)=[pending:downtime:7114.1790415197.pYExGP]
  queue rows=1
    row: 1790415197<TAB>1<TAB>check<TAB>task<TAB>check: normal
  generation grammar: valid [7114.1790415197.pYExGP]
-- S2 date(1) failure during mint (fake date exits 1, no output)
  append rc=0
  marker(.watcher-down)=[pending:downtime:8039..tlJql7]
  queue rows=1
    row: <TAB>1<TAB>signal<TAB>k<TAB>signal: date-miss
  generation grammar: valid [8039..tlJql7]
-- S3 pid failure at mint only (fm_current_pid wrapped to fail only when called from _fm_recovery_marker_write_locked; locks still get a pid)
  append rc=0
  marker(.watcher-down)=[pending:downtime:.1790415197.gU2xlg]
  queue rows=1
    row: 1790415197<TAB>1<TAB>stale<TAB>k<TAB>stale: pid-miss
  generation grammar: valid [.1790415197.gU2xlg]
  stderr:   (fault) pid miss injected in _fm_recovery_marker_write_locked
-- S4 wake-delivery log line (identity with TAB, reason with newline)
  publish rc=0
    log: 4242<TAB>pane id<TAB>signal: line1 line2
  fields=3
Evidence: Focused wake-queue test run including new sibling-subst regression test

Source: Focused wake-queue test run including new sibling-subst regression test

ok - a leftover row that survives a proven-idle ring still surfaces as a genuine stall
ok - secondmate stall markers reject symlinks without touching their targets
ok - stall publication acknowledgement closes the pre-marker crash window
ok - empty prefix mate cleanup preserves another mate's stall receipt
ok - self-announced appends suppress only their own bytes and fail toward waking
ok - separate self-announced answers after a fold stay owned; worker decisions and later lines still wake
ok - an unreadable status still reads as unreported, with or without owned growth
ok - a worker resolved in fold lag still wakes after this home's close
ok - owned growth suppresses the wake without hiding the turn-ended annotation
ok - historical annotations replay nothing already announced and keep everything new
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation existing
ok - wake append publishes atomic recovery evidence before durable rows
ok - recovery mint and delivery log avoid sibling $()
ok - wake drain: generation-less legacy wakes are adopted and acknowledged
ok - wake drain: a stale acknowledgement cannot retire or consume a newer recovery episode

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Normal durable wake append mints a nonempty pid.epoch.suffix recovery generation and appends the queue row ✅ pass live mint-and-delivery-base-vs-target.txt S1: target marker pending:downtime:5053.1790415196.1FMkjo, 1 queue row; base shape identical
Adversarial: date(1) fails during mint; a grammar-valid token is still minted and the durable wake row is still appended, same as base ✅ pass live mint-and-delivery-base-vs-target.txt S2: target marker pending:downtime:5581..RKm4iM, rc=0, row appended; base pending:downtime:8039..tlJql7, rc=0, row appended
Adversarial: pid lookup fails at mint; a grammar-valid token is still minted and the durable wake row is still appended (no refuse path), same as base ✅ pass live mint-and-delivery-base-vs-target.txt S3: target marker pending:downtime:.1790415196.T8r9uX, rc=0, row appended; base pending:downtime:.1790415197.gU2xlg, rc=0, row appended
Wake-delivery log records one 3-field pid/identity/reason line with tabs and newlines cleaned, same as base ✅ pass live mint-and-delivery-base-vs-target.txt S4: log '4242<TAB>pane id<TAB>signal: line1 line2', fields=3 on both base and target
New regression test and neighboring recovery-generation tests pass ⏸️ untested no The prior payload recorded this as a unit-test run (live=false), not a live product run, so it did not establish a live result. Driving it live would need these recovery-generation paths exercised aga…
Under Bash 5.2 with a CHLD trap set, recovery mint and delivery logging run without the sibling-$() parse error ⏸️ untested no No Bash 5.2 binary on this host (only /bin/bash 3.2.57), and installing packages is out of bounds here. To cover this, run tests/fm-wake-queue.test.sh on a CI runner or host with bash 5.2 on PATH; the…
  • Base-vs-target driver (git archive 72b63ee bin into a temp dir) running real fm_wake_append for a normal check wake, with marker and queue state captured
  • Fake failing date put first on PATH during fm_wake_append: marker token grammar and queue row compared, base vs target
  • fm_current_pid wrapped to fail only when called from _fm_recovery_marker_write_locked (locks still get a pid) during fm_wake_append: marker token and queue row compared, base vs target
  • watch_delivery_publish with a TAB in the identity and a newline in the reason: .watch-deliveries.log line and field count compared, base vs target
  • Focused run of tests/fm-wake-queue.test.sh helpers plus test_wake_publish_requires_atomic_recovery_evidence, test_recovery_mint_and_delivery_log_avoid_sibling_subst, test_legacy_generationless_wake_is_adopted, test_stale_recovery_generation_cannot_touch_a_newer_episode (exit 0, no failures)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Lakescape and others added 5 commits September 26, 2026 02:36
Sibling command substitutions on one line can empty a recovery generation
under bash 5.2 when a CHLD trap is set. Mint pid/epoch sequentially, refuse
empty tokens before write, and clean delivery fields before printf.

Co-authored-by: Cursor <[email protected]>
Sibling command substitutions on one line can empty a recovery generation
under bash 5.2 when a CHLD trap is set. Mint pid/epoch sequentially, refuse
empty tokens before write, and clean delivery fields before printf.

Co-authored-by: Cursor <[email protected]>
Remove the new pid/date refusal and grammar guard so a mint miss still
yields a grammar-valid token and a durable wake row, matching accepted
review intent. Drop the fake-failing-date case that locked in the refuse.

Co-authored-by: Cursor <[email protected]>
Keep the superseded pre-rebase tip reachable so private-mirror
reconciliation can proceed after the rewritten history and follow-up
mint-semantics fix. Tree unchanged (ours strategy).
@kunchenguid
kunchenguid merged commit d1a332c into kunchenguid:main Sep 26, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @Lakescape — really appreciate you taking the time on this.

contract-class: restore — removes the Bash 5.2 sibling $() landmine from recovery-generation mint and wake-delivery logging while keeping the prior mint/append semantics. HEAD ea9da8e9e7428a6aa444af6f083dd41936f65b3f, attestation MATCH, CI green, MERGEABLE/CLEAN. Squash merge d1a332cdd4b9483ae0c43e9cf33684fadce28869.