Skip to content

fix(procevent): separate clean-false, transient, and permanent when-condition outcomes - #122

Merged
Ivory2024 merged 3 commits into
mainfrom
fm/procevent-when-condition-error-20261010
Oct 12, 2026
Merged

Ivory2024 merged 3 commits into
mainfrom
fm/procevent-when-condition-error-20261010

Conversation

@Ivory2024

@Ivory2024 Ivory2024 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Intent

Separate clean-false, transient, and permanent outcomes of a when-watch condition in bin/fm-procevent-when.sh. Exit 0 = true (fires action after --stable consecutive trues); 1 = clean false (keeps waiting at cadence); 2 = permanent error (wakes firstmate on the first observation, action never runs); any other nonzero or the per-poll timeout = transient error (bounded backoff doubling capped at 8x the interval, wakes once --error-budget consecutive transient errors accumulate). Permanent break and exhausted transient budget both end in the terminal condition-error outcome, which never runs the action and does not re-arm the watch. A failure is never treated as a false. Motivation: the 2026-10-08 when-pr107-nm-resume incident (transient provider-unreadable window burned the shared error budget and retired the watch). Includes docs/configuration.md and tests/fm-procevent-when.test.sh. Rebase conflicts with main: keep main's behavior and re-apply only this change.

What Changed

  • Classify a when-watch condition's exit status into four outcomes: 0 true, 1 clean false that keeps waiting at the registered cadence, 2 permanent error that wakes firstmate on its first observation, and any other nonzero exit or per-poll timeout as a transient error.
  • Add bounded transient backoff that doubles per consecutive error and caps at 8x the interval; a permanent error and an exhausted --error-budget both emit the terminal condition-error outcome that never runs the action and is not re-armed.
  • Document the exit-status contract in docs/configuration.md and docs/verification/process-event-sources.md, and extend tests/fm-procevent-when.test.sh to cover clean false, transient retry/backoff, permanent first-poll wake, and watcher confirmation/retirement.

Risk Assessment

✅ Low: Change is a well-bounded, self-contained fix to bin/fm-procevent-when.sh's exit-code handling with matching docs and new tests that exercise real condition scripts and assert durable outcomes, not source text; logic traced for exit 0/1/2/other/timeout and backoff math checks out against the stated intent.

Testing

Drove all four condition outcomes (true, clean false, permanent exit 2, transient exit 3) plus the per-poll-timeout path against the real adapter and generic process-event runner in disposable isolated FM_HOMEs, reading the captured outcome documents and the durable wake queue. Permanent wakes on poll 1 with the budget untouched, transient retries and fires on recovery, an exhausted budget wakes at exactly N polls, clean false ends only at the deadline as never-true, errors back off 0.5/1/2/4/4/4/4s (doubling capped at 8x the interval), timeout 124 is transient, and a terminal condition-error publishes a wake and does not re-arm. The action never ran on any failure path and ran exactly once on the stable true. The new scenarios also fail against the base adapter, reproducing the fix. The docs/configuration.md contract was read and matches the observed behavior. No visual surface exists, so no screenshots; evidence is CLI transcripts and outcome documents.

  • Live validation: ✅ go - 10 of 10 scenarios driven live against the product
Scenario Result Live Evidence
A clean-false condition (exit 1) keeps waiting at cadence and ends only at its deadline as never-true, never as a condition error, and never runs the action ✅ pass live live-outcomes.txt when-cleanfalse (status: never-true, condition_polls: 3, no invocation) and tests/fm-procevent-when.test.sh 'a clean-false condition ... never errors and never fires'
A condition that becomes true after clean falses fires the action exactly once (exit 0 still fires after --stable consecutive trues) ✅ pass live live-outcomes.txt when-recover (status: fired, action_exit: 0, 1 invocation) and tests/fm-procevent-when.test.sh 'a stable true fires the action exactly once and wakes with the outcome'
A permanent error (exit 2) wakes firstmate on its FIRST observation, leaving a large error budget unused, and never runs the action ✅ pass live live-outcomes.txt when-permanent (status: condition-error, condition_polls: 1 with --error-budget 5, action never ran) and tests/fm-procevent-when.test.sh 'a permanent condition failure wakes on its f…
A transient error (exit 3) within the budget is retried rather than retiring the watch, and a later stable true fires exactly once ✅ pass live live-outcomes.txt when-recover (first two polls exit 3, then exit 0 -> status: fired, 1 invocation) and tests/fm-procevent-when.test.sh 'a transient condition error is retried and never mistaken for a…
Consecutive transient errors that exhaust --error-budget wake with condition-error at exactly that many polls, and the action never runs ✅ pass live live-outcomes.txt when-transient (exit 3, budget 3 -> status: condition-error, condition_polls: 3, action never ran) and base live-backoff.txt bo run (budget 8 -> condition_polls: 8)
Transient-error poll waits back off by doubling and are capped at 8x the registered interval ✅ pass live live-backoff.txt measured gaps 0.645/1.122/2.198/4.167/4.092/4.066/4.149s for interval 0.5 (cap 8x = 4s) and tests/fm-procevent-when.test.sh 'consecutive transient errors back off before the budget wa…
A per-poll condition timeout is a transient error (exit 124), never a clean false and never an immediate permanent wake ✅ pass live live-backoff.txt timeout section (condition sleeping 3s with --condition-timeout 1 -> status: condition-error detail 'errored (exit 124) on 2 consecutive polls' after --error-budget 2, action never ra…
A terminal condition-error (permanent break or exhausted budget) wakes firstmate through the durable wake queue and leaves the watch un-re-armed, so reconcile cannot fire the action later ✅ pass live live-wake-no-rearm.txt (reconcile #1 started=1; #2/#3 published=1 started=0; one result; action never ran) and live-wake-queue.txt ('check: procevent when when-permwake 1')
Adversarial: a permanent break must be terminal even when the very next poll would have been true - the condition is never retried into a fire, is polled exactly once, and claims no fired marker ✅ pass live live-adversarial-permanent.txt (exit 2 on poll 1, exit 0 thereafter, budget 9 -> status: condition-error, condition_polls: 1, condition polled exactly 1 time, action never ran, fired marker absent)
Regression reproduction: the new condition-contract scenarios fail against the pre-change adapter and pass against the target adapter ✅ pass live base-before-fix-test-suite.txt ends with 'not ok - a permanent failure wakes on its FIRST poll, not after the transient budget' while target-test-suite.txt ends with 'all fm-procevent-when tests passe…
Evidence: Target test suite (all pass)

Source: Target test suite (all pass)

ok - arm binds, refuses duplicates, and retire cleans up
ok - concurrent arms publish exactly one complete watch
ok - a stable true fires the action exactly once and wakes with the outcome
ok - a flapping condition never reaches the action
ok - an action failure wakes with the captured error
ok - a repeatedly erroring condition wakes firstmate instead of firing
ok - an expired deadline wakes with never-true
ok - a late true poll cannot fire after its deadline
ok - action timeouts terminate the complete process group
ok - command output staging stays within its byte bound
ok - a restart after a claimed fire reports ambiguity instead of double-firing
ok - a mutated spec is refused without executing anything
ok - mutated action bytes are refused before claiming the fire
ok - rebind-all refreshes an in-repo watch's trust binding after a self-update and leaves an out-of-repo one alone
ok - rebind-all matches FM_ROOT through a symlinked checkout path
ok - rebind-all reaches a watch whose run process was already polling when the self-update landed
ok - the fire-time reload never observes rebind_one's spec/trust publish mid-rename
ok - a clean-false condition (the stall-monitor shape) never errors and never fires
ok - a transient condition error is retried and never mistaken for a false
ok - a transient error below the budget waits instead of waking
ok - a permanent condition failure wakes on its first poll despite a large error budget
ok - consecutive transient errors back off before the budget wakes
ok - the watcher cycle confirms a healthy when-watch and retires it after its terminal outcome
all fm-procevent-when tests passed
Evidence: Base (pre-fix) test suite reproduces the regression

Source: Base (pre-fix) test suite reproduces the regression

ok - arm binds, refuses duplicates, and retire cleans up
ok - concurrent arms publish exactly one complete watch
ok - a stable true fires the action exactly once and wakes with the outcome
ok - a flapping condition never reaches the action
ok - an action failure wakes with the captured error
ok - a repeatedly erroring condition wakes firstmate instead of firing
ok - an expired deadline wakes with never-true
ok - a late true poll cannot fire after its deadline
ok - action timeouts terminate the complete process group
ok - command output staging stays within its byte bound
ok - a restart after a claimed fire reports ambiguity instead of double-firing
ok - a mutated spec is refused without executing anything
ok - mutated action bytes are refused before claiming the fire
ok - rebind-all refreshes an in-repo watch's trust binding after a self-update and leaves an out-of-repo one alone
ok - rebind-all matches FM_ROOT through a symlinked checkout path
ok - rebind-all reaches a watch whose run process was already polling when the self-update landed
ok - the fire-time reload never observes rebind_one's spec/trust publish mid-rename
ok - a clean-false condition (the stall-monitor shape) never errors and never fires
ok - a transient condition error is retried and never mistaken for a false
ok - a transient error below the budget waits instead of waking
not ok - a permanent failure wakes on its FIRST poll, not after the transient budget
Evidence: Live outcome documents: clean-false, permanent, transient, recover

Source: Live outcome documents: clean-false, permanent, transient, recover

when-permanent: status: condition-error / detail: the condition reported a permanent failure (exit 2) on poll 1; the action was not run / condition_polls: 1 (budget 5 unused, action never ran) when-transient: status: condition-error / detail: the condition errored (exit 3) on 3 consecutive polls; the action was not run / condition_polls: 3 when-cleanfalse: status: never-true (deadline) / action never ran when-recover: status: fired / action_exit: 0 / exactly 1 invocation

=== arm + reconcile ===
reconciled: published=0 started=4 stopped=0 uncertain=0 failed=0

=== waiting for terminal outcomes ===
----- when-cleanfalse -----
classify: never-true
when: when-cleanfalse
status: never-true
detail: the condition never held for 1 consecutive polls within 3s of arming
condition_polls: 3
output:
output-tail:

----- when-permanent -----
classify: condition-error
when: when-permanent
status: condition-error
detail: the condition reported a permanent failure (exit 2) on poll 1; the action was not run
condition_polls: 1
output:
output-tail:
    worktree missing at /nonexistent

----- when-transient -----
classify: condition-error
when: when-transient
status: condition-error
detail: the condition errored (exit 3) on 3 consecutive polls; the action was not run
condition_polls: 3
output:
output-tail:
    service unreachable

----- when-recover -----
classify: fired
when: when-recover
status: fired
detail: the condition held and the action exited 0
condition_polls: 3
action_exit: 0
output:
output-tail:

=== action side effects (exactly-once proof) ===
cleanfalse: no invocation (action never ran)
permanent: no invocation (action never ran)
transient: no invocation (action never ran)
recover: 1 invocation(s)
=== end ===
Evidence: Live transient backoff shape and per-poll-timeout transient path

Source: Live transient backoff shape and per-poll-timeout transient path

interval 0.5, budget 8 gaps: 0.645s, 1.122s, 2.198s, 4.167s, 4.092s, 4.066s, 4.149s (doubling capped at 8x=4s); timeout path: exit 124 counted as transient, wake after budget 2, action never ran

=== per-poll gaps (interval 0.5, cap 8x=4s) ===
poll 1 -> 2 gap: 0.645s
poll 2 -> 3 gap: 1.122s
poll 3 -> 4 gap: 2.198s
poll 4 -> 5 gap: 4.167s
poll 5 -> 6 gap: 4.092s
poll 6 -> 7 gap: 4.066s
poll 7 -> 8 gap: 4.149s
classify: condition-error
status: condition-error
detail: the condition errored (exit 3) on 8 consecutive polls; the action was not run
condition_polls: 8
action: never ran

=== per-poll timeout treated as transient (not a false) ===
classify: condition-error
status: condition-error
detail: the condition errored (exit 124) on 2 consecutive polls; the action was not run
condition_polls: 2
action: never ran
=== end ===
Evidence: Terminal condition-error publishes a wake and does not re-arm

Source: Terminal condition-error publishes a wake and does not re-arm

reconcile #1: started=1; reconcile #2/#3: published=1 started=0; action never ran; exactly one captured result

=== first reconcile ===
reconciled: published=0 started=1 stopped=0 uncertain=0 failed=0

=== durable wake queue ===
  (no .wake-queue)

=== pe list after terminal ===
  SOURCE                       ADAPTER      OWNER      PENDING
  when-permwake                when         live       1

=== second reconcile (must not re-arm/re-run) ===
reconciled: published=1 started=0 stopped=0 uncertain=0 failed=0
=== third reconcile ===
reconciled: published=1 started=0 stopped=0 uncertain=0 failed=0
action log: never ran
result count: 1
=== end ===
Evidence: Durable wake queue rows for the condition-error

Source: Durable wake queue rows for the condition-error

check: procevent when when-permwake 1

home: /var/folders/pg/_5jy7w915bv_qt8hkrnpxm6w0000gn/T//when-live-wake.SHtrOi
=== pe list after terminal condition-error (no re-arm) ===
  (see live-wake-no-rearm.txt: reconcile #2/#3 -> started=0, published=1)

=== durable wake queue rows (kind | seq | payload) ===
1791815502 | check | check: procevent when when-permwake 1
1791815502 | check | check: procevent when when-permwake 1
1791815502 | check | check: procevent when when-permwake 1
Evidence: Adversarial permanent break is terminal even if the next poll would be true

Source: Adversarial permanent break is terminal even if the next poll would be true

status: condition-error, condition_polls: 1, condition polled exactly 1 time, action never ran, fired marker absent

classify: condition-error
status: condition-error
detail: the condition reported a permanent failure (exit 2) on poll 1; the action was not run
condition_polls: 1
condition was polled 1 time(s) (a retry would exceed 1)
action: never ran
fired marker: absent
=== end ===

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 - 10 of 10 scenarios driven live against the product
Scenario Result Live Evidence
A clean-false condition (exit 1) keeps waiting at cadence and ends only at its deadline as never-true, never as a condition error, and never runs the action ✅ pass live live-outcomes.txt when-cleanfalse (status: never-true, condition_polls: 3, no invocation) and tests/fm-procevent-when.test.sh 'a clean-false condition ... never errors and never fires'
A condition that becomes true after clean falses fires the action exactly once (exit 0 still fires after --stable consecutive trues) ✅ pass live live-outcomes.txt when-recover (status: fired, action_exit: 0, 1 invocation) and tests/fm-procevent-when.test.sh 'a stable true fires the action exactly once and wakes with the outcome'
A permanent error (exit 2) wakes firstmate on its FIRST observation, leaving a large error budget unused, and never runs the action ✅ pass live live-outcomes.txt when-permanent (status: condition-error, condition_polls: 1 with --error-budget 5, action never ran) and tests/fm-procevent-when.test.sh 'a permanent condition failure wakes on its f…
A transient error (exit 3) within the budget is retried rather than retiring the watch, and a later stable true fires exactly once ✅ pass live live-outcomes.txt when-recover (first two polls exit 3, then exit 0 -> status: fired, 1 invocation) and tests/fm-procevent-when.test.sh 'a transient condition error is retried and never mistaken for a…
Consecutive transient errors that exhaust --error-budget wake with condition-error at exactly that many polls, and the action never runs ✅ pass live live-outcomes.txt when-transient (exit 3, budget 3 -> status: condition-error, condition_polls: 3, action never ran) and base live-backoff.txt bo run (budget 8 -> condition_polls: 8)
Transient-error poll waits back off by doubling and are capped at 8x the registered interval ✅ pass live live-backoff.txt measured gaps 0.645/1.122/2.198/4.167/4.092/4.066/4.149s for interval 0.5 (cap 8x = 4s) and tests/fm-procevent-when.test.sh 'consecutive transient errors back off before the budget wa…
A per-poll condition timeout is a transient error (exit 124), never a clean false and never an immediate permanent wake ✅ pass live live-backoff.txt timeout section (condition sleeping 3s with --condition-timeout 1 -> status: condition-error detail 'errored (exit 124) on 2 consecutive polls' after --error-budget 2, action never ra…
A terminal condition-error (permanent break or exhausted budget) wakes firstmate through the durable wake queue and leaves the watch un-re-armed, so reconcile cannot fire the action later ✅ pass live live-wake-no-rearm.txt (reconcile #1 started=1; #2/#3 published=1 started=0; one result; action never ran) and live-wake-queue.txt ('check: procevent when when-permwake 1')
Adversarial: a permanent break must be terminal even when the very next poll would have been true - the condition is never retried into a fire, is polled exactly once, and claims no fired marker ✅ pass live live-adversarial-permanent.txt (exit 2 on poll 1, exit 0 thereafter, budget 9 -> status: condition-error, condition_polls: 1, condition polled exactly 1 time, action never ran, fired marker absent)
Regression reproduction: the new condition-contract scenarios fail against the pre-change adapter and pass against the target adapter ✅ pass live base-before-fix-test-suite.txt ends with 'not ok - a permanent failure wakes on its FIRST poll, not after the transient budget' while target-test-suite.txt ends with 'all fm-procevent-when tests passe…
  • bash tests/fm-procevent-when.test.sh in the change worktree (full targeted suite, 25 checks, all ok)
  • git show 6141982b:bin/fm-procevent-when.sh swapped into a disposable bin/tests copy, then bash tests/fm-procevent-when.test.sh to reproduce the pre-fix failure
  • Manual live driver of bin/fm-procevent-when.sh arm + bin/fm-procevent.sh reconcile in a disposable FM_HOME for clean-false, permanent (exit 2), transient (exit 3), and transient-then-true conditions; read the captured condition-error/never-true/fired outcome documents and action-invocation logs
  • Manual live backoff measurement with --interval 0.5 --error-budget 8 and per-poll timestamping, and a --condition-timeout 1 condition sleeping 3s to confirm exit 124 is transient
  • Manual live adversarial run: exit 2 on poll 1, exit 0 on any later poll, budget 9, asserting exactly one poll, no fire, no fired marker
  • Manual live durable-wake/retire check: bin/fm-procevent.sh reconcile then pe list, repeated reconcile to confirm started=0 and the check: procevent when when-permwake 1 row in state/.wake-queue
  • bin/fm-procevent-when.sh --help to confirm the documented exit-status contract is emitted
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ondition outcomes

A when-watch condition could only signal true, a clean false, or "some error",
so a transient window burned the shared error budget while a permanent break
could hide as an ordinary wait.

The condition's exit status now carries four outcomes: 0 true, 1 clean false,
2 a permanent error that wakes on its first observation, and any other exit or
a per-poll timeout as a transient error that waits with bounded backoff before
the budget wakes.

A permanent error never runs the action, and the terminal condition-error
outcome leaves the watch for firstmate to decide on rather than re-arming it.
@Ivory2024
Ivory2024 force-pushed the fm/procevent-when-condition-error-20261010 branch from ddb82dd to 25004c5 Compare October 12, 2026 14:38
…. The failure was not in the procevent-when change under review: tests/fm-backend-herdr-presentation-e2e.test.sh failed at its concurrent cross-home recovery case with "error: herdr presentation recovery could not acquire its session lock; refusing a concurrent resume". Invariant: the two exact-resume spawns that the test intentionally runs concurrently must serialize on the single Herdr presentation session lock and both succeed; neither may race a short bounded acquire window. Cause: exact resume defaults to a bounded lock acquire (50 x 0.1s, ~5s) and hard-refuses under contention. The winning recovery holds that lock through its Herdr reclaim, restart-binding validation, and launch staging; on the loaded CI runner the hold exceeded ~5s, so the other resume refused and the case failed. Fix (smallest, test-only): both concurrent resume spawns now pass the existing --herdr-resume-lock-wait opt-in, so the loser genuinely waits out the holder instead of racing the bounded window; the production default of refusing under contention is unchanged and remains covered by the separate lock-refuse case below it. I checked the other concurrent projected operations in the suite for the same invariant: fresh creates deliberately degrade to the ordinary flat layout under the same contention (there is no wait opt-in for them by design) and the exact-resume hard-refusal is the only path that aborts the run, so no other site needed this correction. Verified: shellcheck --norc --external-sources passes on the file; the full real-Herdr presentation suite passes locally end-to-end (exit 0), including the "concurrent cross-home recoveries replace exact husks under one session lock with no focus drift" assertion
@Ivory2024
Ivory2024 merged commit e2908db into main Oct 12, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant