Skip to content

fix(bin): re-raise unanswered decisions and stop reporting decision waits as inactive outcomes - #6523

Closed
maruthiprithivi wants to merge 6 commits into
kunchenguid:mainfrom
maruthiprithivi:fm/fm-decision-age
Closed

maruthiprithivi wants to merge 6 commits into
kunchenguid:mainfrom
maruthiprithivi:fm/fm-decision-age

Conversation

@maruthiprithivi

@maruthiprithivi maruthiprithivi commented Oct 3, 2026 •

Copy link
Copy Markdown

Intent

Ask: "there are still these kind of issues, please address them and make them permanent and proper fixes". The issue: a Control Zero docs worker on the Optimus secondmate opened a keyed needs-decision (dlp-clean-behind-active-run) and waited. Its supervisor never answered it, so the lane looked dead and was reported as an inactive terminal outcome, while four captain-approved PRs sat unmerged for hours. The decision surfaced only when the primary asked why the lane had stopped. The same pattern appeared earlier in the session (a step-2 worker blocked on an unseen publication question; a secondmate implementer lane that never started).

What Changed

  • bin/fm-watch.sh adds a decision_age_tick that runs on every watcher cycle. It reads the authoritative open-decision set, so a needs-decision is still found after later status lines bury it. Once a decision is older than FM_DECISION_AGE_SECS (default 900), the tick raises a check: decision unanswered <age>s wake. It re-raises with backoff (15, 45, 105... minutes), and per-opener marker files keep that schedule across watcher restarts. In a secondmate home, the second re-raise also posts one needs-decision [key=decision-unanswered-<id>] line to the parent channel. A matching resolved line follows once the opener is no longer open. Before a marker is closed, the tick re-checks the task's full status log.

  • bin/fm-inactive-reconcile.sh no longer reports a child with an open needs-decision as a terminal done/failed outcome. In a secondmate home it posts a blocked [key=decision-waiting-<fp>] line to the parent channel once per opener, and waiting_close_pass closes it with a resolved line when the decision is answered or the child goes away. bin/fm-classify-lib.sh adds the shared status_open_decision_origin (the opener's time and line position) and fm_decision_age_threshold helpers.

  • bin/fm-wake-drain.sh changes the OPEN DECISIONS section:

    • Each row shows [age=…], and rows past the age threshold are tagged [actionable: unanswered].
    • Live tasks are listed first, newest first. Decisions from torn-down tasks collapse into a single count.
    • The 4 KB byte cap is replaced by FM_OPEN_DECISIONS_MAX_ROWS (default 10000). Any rows it drops are flagged loudly.
    • A new read-only --list-open-decisions flag prints every open decision.

    The branch prompt, the supervision-protocol docs, docs/configuration.md and docs/secondmate-parent-channel.md are updated to match. New and extended shell tests cover decision age, inactive reconcile, teardown and wake-drain.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: The core re-raise and the inactive-outcome guard look correct, but the drain now auto-writes resolutions into status logs beyond what the intent asked for, and an ignoring supervisor still never escalates to the primary, so the intent's failure can partly recur.

Testing

I ran the 5 targeted test files; all passed. I then drove the real scripts end-to-end in disposable fm-lab-home homes: a main (parent) home and a secondmate home, with no FM_*_OVERRIDE variables. These runs reproduced the Control Zero dlp-clean incident. The buried decision re-woke the supervisor, was marked [actionable: unanswered], and escalated to the parent exactly once at the second re-raise and not at the first. Answering it published one matching resolved line, removed the age marker, emptied the parent's open set, and stopped the wakes. The reconcile path published blocked [key=decision-waiting-...] once, deduplicated on a repeat scan, queued no inactive-outcome row, and closed with resolved once the decision was answered. In the main home, torn-down decisions were folded into a count, --list-open-decisions changed no state file, and the watcher re-raised only the live overdue decision. The labs were removed afterwards and the worktree is clean. There is no UI, so there are no screenshots; the evidence is CLI transcripts. One caveat: the real crew-state reported unknown, not done. The case where crew-state says done and the decision guard still blocks the terminal report is covered only by the test that uses a fake crew-state. The failed-fold case is likewise covered only by a test that injects a fake mv.

  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Secondmate child keyed decision buried under routine appends re-wakes the secondmate supervisor with task+key ✅ pass live live-secondmate-dlp-clean.txt: 'check: decision unanswered 23s: docs dlp-clean-behind-active-run'
Parent escalation fires only at the second re-raise, exactly once ✅ pass live live-secondmate-dlp-clean.txt: parent channel empty after the first re-raise; one needs-decision [key=decision-unanswered-e408fa26ee1e] after the second
Answering the child decision closes the parent escalation once, removes the age marker, and stops the wakes ✅ pass live live-secondmate-dlp-clean.txt: one resolved line, no .decision-age-* marker left, parent open list empty, later watcher idle (rc=124)
Idle child waiting on a decision is reported upstream as a blocked decision-wait, not an inactive terminal outcome; deduplicated; closed when answered ✅ pass live live-reconcile-decision-wait.txt: blocked [key=decision-waiting-bf76fef470fa] once across 2 scans, 0 inactive-outcome rows, resolved once after the answer
Adversarial: crew-state reports 'done' for a child with an open decision, and no terminal outcome is created ⏸️ untested no The prior payload did not establish a live result. Only the stub test (fake crew-state=done) in tests/fm-inactive-reconcile.test.sh covered it, because the real bin/fm-crew-state.sh reported 'unknown'…
Drain marks overdue decisions [age=..] [actionable: unanswered], folds torn-down tasks into a count, and --list-open-decisions is read-only ✅ pass live live-main-drain-open-decisions.txt: live rows with age markers, '3 terminal decisions folded', full list shows gone1-3, state/ shasum diff empty
Adversarial: stale decisions of torn-down tasks and fresh decisions below the threshold do not trigger age wakes ✅ pass live live-main-drain-open-decisions.txt: the only age row queued is 'check: decision unanswered 3616s: live-old publication'
Adversarial: a failed per-task fold neither falsely closes the escalation of a still-open decision nor blocks closing an answered one ⏸️ untested no The prior payload did not establish a live result. Only tests/fm-decision-age.test.sh covered it, using a fake mv injected on PATH to make the cursor write fail. A live run would need a real filesyste…
Evidence: Live secondmate dlp-clean scenario: re-raise, parent escalation once, resolution closes

Source: Live secondmate dlp-clean scenario: re-raise, parent escalation once, resolution closes

\### Lab homes via bin/fm-lab-home.sh: MAIN (parent) + MATE (secondmate, local parent route)
\### MATE/state/docs.status:
working [at=1791067131]: drafting docs
needs-decision [key=dlp-clean-behind-active-run] [at=1791067141]: clean DLP behind active run?
working [at=1791067151]: routine append 1
working [at=1791067151]: routine append 2
working [at=1791067151]: routine append 3

\### Watcher tick 1 (real bin/fm-watch.sh, FM_HOME=MATE, FM_DECISION_AGE_SECS=3)
signal: /var/folders/w8/cxsknptj3dx0k7s2501vcnt80000gn/T//fm-lab.x6MBlA/mate/state/docs.status
[watcher exit rc=0 at decision age 22s]
parent channel (MAIN/state/mate.status):
  (empty)
[acked seq=2]

\### Watcher tick 2 (real bin/fm-watch.sh, FM_HOME=MATE, FM_DECISION_AGE_SECS=3)
check: decision unanswered 23s: docs dlp-clean-behind-active-run
[watcher exit rc=0 at decision age 24s]
parent channel (MAIN/state/mate.status):
  (empty)
[acked seq=3]

\### Watcher tick 3 (real bin/fm-watch.sh, FM_HOME=MATE, FM_DECISION_AGE_SECS=3)
check: decision unanswered 30s: docs dlp-clean-behind-active-run
[watcher exit rc=0 at decision age 30s]
parent channel (MAIN/state/mate.status):
needs-decision [key=decision-unanswered-e408fa26ee1e] [at=1791067171]: decision unanswered 29s: docs dlp-clean-behind-active-run
[acked seq=4]

\### Supervisor drain view in MATE:
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
docs [key=dlp-clean-behind-active-run] [age=31s] [actionable: unanswered] needs-decision: clean DLP behind active run?
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'

\### Parent (MAIN) OPEN DECISIONS via bin/fm-wake-drain.sh --list-open-decisions:
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
mate [key=decision-unanswered-e408fa26ee1e] [age=2s] needs-decision: decision unanswered 29s: docs dlp-clean-behind-active-run
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'

\### Supervisor answers the child:
resolved [key=dlp-clean-behind-active-run] [at=1791067173]: yes, clean it
signal: /var/folders/w8/cxsknptj3dx0k7s2501vcnt80000gn/T//fm-lab.x6MBlA/mate/state/docs.status
[watcher exit rc=0 at decision age 34s]
[acked seq=6]
[watcher exit rc=124 at decision age 43s]
parent channel (MAIN/state/mate.status):
needs-decision [key=decision-unanswered-e408fa26ee1e] [at=1791067171]: decision unanswered 29s: docs dlp-clean-behind-active-run
resolved [key=decision-unanswered-e408fa26ee1e] [at=1791067176]: decision no longer open
MATE age markers:
  (none)

\### Parent OPEN DECISIONS after resolution:
(rc=0; empty output = nothing open)
Evidence: Live inactive-reconcile: decision wait published as blocked, deduped, closed on answer

Source: Live inactive-reconcile: decision wait published as blocked, deduped, closed on answer

\### MATE child cz-docs (idle 300s, unanswered keyed decision); real bin/fm-crew-state.sh says:
state: unknown · source: none · backend target gone: firstmate:fm-cz-docs

\### Reconcile scan --startup #1 (real bin/fm-inactive-reconcile.sh in MATE home):
waiting on decision dlp-clean-behind-active-run for 500s: child=cz-docs
[reconcile rc=0]
parent channel:
blocked [key=decision-waiting-bf76fef470fa] [at=1791067208]: waiting on decision dlp-clean-behind-active-run for 500s: child=cz-docs
MATE wake queue inactive-outcome rows: 0
0

\### Reconcile scan --startup #2 (dedupe):
waiting on decision dlp-clean-behind-active-run for 501s: child=cz-docs
[reconcile rc=0]
parent channel:
blocked [key=decision-waiting-bf76fef470fa] [at=1791067208]: waiting on decision dlp-clean-behind-active-run for 500s: child=cz-docs

\### Parent OPEN DECISIONS:
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
mate [key=decision-waiting-bf76fef470fa] [age=1s] blocked: waiting on decision dlp-clean-behind-active-run for 500s: child=cz-docs
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'

\### Child decision answered; reconcile scan:
[reconcile rc=0]
[reconcile rc=0]
parent channel:
blocked [key=decision-waiting-bf76fef470fa] [at=1791067208]: waiting on decision dlp-clean-behind-active-run for 500s: child=cz-docs
resolved [key=decision-waiting-bf76fef470fa] [at=1791067209]: child=cz-docs decision no longer open

\### Parent OPEN DECISIONS after answer:
(empty = none open)
Evidence: Live main-home drain: age/actionable markers, torn-down fold, read-only full list, watcher wakes only the live aged key

Source: Live main-home drain: age/actionable markers, torn-down fold, read-only full list, watcher wakes only the live aged key

\### Home: 2 live tasks (1h-old and 60s-old decisions), 3 torn-down tasks (no meta) with stale decisions; FM_DECISION_AGE_SECS default 900

\### Ordinary drain OPEN DECISIONS section:
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
live-new [key=scope] [age=61s] needs-decision: widen scope?
live-old [key=publication] [age=3601s] [actionable: unanswered] needs-decision: publish step-2?
OPEN DECISIONS: 3 terminal decisions folded; list: bin/fm-wake-drain.sh --list-open-decisions
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'

\### bin/fm-wake-drain.sh --list-open-decisions:
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
live-new [key=scope] [age=62s] needs-decision: widen scope?
live-old [key=publication] [age=3602s] [actionable: unanswered] needs-decision: publish step-2?
gone1 [key=old1] [age=90002s] [actionable: unanswered] needs-decision: stale torn-down question
gone2 [key=old2] [age=90002s] [actionable: unanswered] needs-decision: stale torn-down question
gone3 [key=old3] [age=90002s] [actionable: unanswered] needs-decision: stale torn-down question
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
[rc=0]

\### state/ file diff across --list-open-decisions (empty = read-only):
(no state file changed)

\### Watcher tick in this home (FM_DECISION_AGE_SECS=900): wakes only for the live aged decision
signal: /var/folders/w8/cxsknptj3dx0k7s2501vcnt80000gn/T//fm-lab.x6MBlA/solo/state/gone1.status /var/folders/w8/cxsknptj3dx0k7s2501vcnt80000gn/T//fm-lab.x6MBlA/solo/state/gone2.status /var/folders/w8/cxsknptj3dx0k7s2501vcnt80000gn/T//fm-lab.x6MBlA/solo/state/gone3.status /var/folders/w8/cxsknptj3dx0k7s2501vcnt80000gn/T//fm-lab.x6MBlA/solo/state/live-new.status /var/folders/w8/cxsknptj3dx0k7s2501vcnt80000gn/T//fm-lab.x6MBlA/solo/state/live-old.status
[watcher rc=0]
decision-age queue rows:
[signal wake acked seq=10]
\### Watcher tick 2:
check: decision unanswered 3616s: live-old publication
[watcher rc=0]
decision-age queue rows:
check: decision unanswered 3616s: live-old publication
Evidence: fm-decision-age test log

Source: fm-decision-age test log

ok - aged decisions re-wake with backoff, deduplicate, close, and reset for a new generation
ok - a secondmate child decision wakes the secondmate home
ok - the second unanswered re-raise escalates to the parent once and resolution closes it there once
ok - a bad age marker skips only its own key
ok - a torn-down task's stale decision does not flood the age queue
Evidence: fm-inactive-reconcile test log

Source: fm-inactive-reconcile test log

actionable: inactive terminal outcome awaiting captain presentation: child=child state=done pr=https://example.test/owner/repo/pull/1
ok - main direct terminal presentation has a durable receipt
actionable: inactive terminal outcome awaiting captain presentation: child=child state=done pr=https://example.test/owner/repo/pull/1
ok - a branch-actor acknowledgement retires the inactive-outcome receipt and later scans stay quiet
ok - unpushed CI-ready ship done: is not published upstream
ok - a delivered ship done: skips the git gate on later polls
ok - secondmate delivers a child's terminal ledger line once, on the next poll, from the ledger alone
ok - multiline terminal outcomes are reported once before or during a state read
ok - an unterminated continuation line does not withhold a proven child outcome
ok - later status prose does not change the inactive terminal receipt identity
ok - busy child locks do not starve later ledger outcomes
ok - ledger delivery carries the report pointer, the failed verb, and each new terminal line
ok - pr= requires the recorded PR or a ready-signal terminal line, whatever its stamp, and never a scout
ok - terminal lines arriving during state reads remain ledger-owned
ok - inactive and ledger paths reconcile one raced completion without hiding later events
ok - progress after an inactive fallback starts a distinct terminal event
ok - complete long ledger lines retain distinct receipt identities
ok - a ledger line still being appended waits for its newline
ok - the remote route carries a child's ledger line once
ok - report delivers a child's final line, owes nothing twice, and refuses only an unwritable channel
actionable: child outcome needs parent report: child=child state=done (missing or unreadable parent binding .fm-secondmate-parent)
ok - a pending ship done: is delivered by report after teardown removed the worktree
ok - report preserves teardown's metadata-before-scan lock order
actionable: child outcome needs parent report: child=child state=failed (missing or unreadable parent binding .fm-secondmate-parent)
ok - relative local parent homes fail closed
ok - invalid secondmate markers block routing and surface the obligation
ok - remote parent-replies mirror input is durable and idempotent
ok - reused task ids retain per-incarnation terminal receipts
ok - legacy metadata rewrites preserve terminal receipt identity
ok - relaunch cannot replace metadata during terminal snapshot
actionable: inactive terminal outcome awaiting captain presentation: child=child state=done pr=https://example.test/owner/repo/pull/1
ok - terminal reconciliation ignores heartbeat backoff state
actionable: inactive terminal outcome awaiting captain presentation: child=child state=done pr=https://example.test/owner/repo/pull/1
ok - scan marker replaces a symlink without overwriting its target
ok - nonterminal and captain-held workers remain outside inactive terminal reporting
ok - watcher hook wakes for terminal loss and preserves idle secondmate exemption
ok - the real watcher poll delivers a child's terminal ledger line to the parent channel
actionable: inactive terminal outcome awaiting captain presentation: child=b state=done pr=https://example.test/owner/repo/pull/1
ok - stalled state reads are bounded without starving later children
ok - aggregate scan budget includes durable wake operations
actionable: inactive terminal outcome needs parent report: child=child state=failed (missing or unreadable parent binding .fm-secondmate-parent)
ok - notice recovery remains idempotent across queue acknowledgement
ok - a secondmate home with no parent binding names the missing binding instead of failing quietly
actionable: inactive terminal outcome awaiting captain presentation: child=child state=done pr=https://example.test/owner/repo/pull/1
ok - reconciliation makes zero forge or PR API calls
actionable: inactive terminal outcome awaiting captain presentation: child=child state=done pr=https://example.test/owner/repo/pull/1
ok - reconciliation state reads set no-forge mode
ok - an open keyed decision prevents an inactive terminal report
ok - a secondmate child's decision wait reaches the parent once and closes there once when answered
all inactive reconciliation tests passed
Evidence: Parent escalation excerpt
tick 2: check: decision unanswered 23s: docs dlp-clean-behind-active-run (parent channel empty)
tick 3: check: decision unanswered 30s: docs dlp-clean-behind-active-run
parent: needs-decision [key=decision-unanswered-e408fa26ee1e] [at=1791067171]: decision unanswered 29s: docs dlp-clean-behind-active-run
after answer: resolved [key=decision-unanswered-e408fa26ee1e] [at=1791067176]: decision no longer open
parent --list-open-decisions: (empty)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-inactive-reconcile.sh:532 - The re-raise only reaches the supervisor that already failed to answer. If that supervisor (here, the secondmate) drains and acknowledges the decision-age wake without answering, the watcher keeps backing off (15/30/60/60 min) at that same supervisor indefinitely. Nothing goes to the parent/primary. In the intent's exact scenario, reconcile_direct_child_locked also now swaps the old parent-visible 'inactive terminal outcome' for a stderr-only 'waiting on decision ...' line, so the primary gets no signal at all that the lane is blocked. That is the 'surfaced only when the primary asked' failure the intent says to fix permanently. The secondmate wake-stall ring (bin/fm-watch.sh:1017-1022) helps only when the secondmate stops draining, not when it drains and ignores. Related sites: bin/fm-watch.sh:1113 (append targets only the local queue), bin/fm-watch.sh:1115-1116 (backoff caps with no escalation step). The fix would be new escalation machinery (e.g. publish an aged needs-decision on the parent channel after N re-raises), so the remedy needs authorization.
  • ⚠️ bin/fm-wake-drain.sh:464 - Simplification, beyond intent: close_torn_down_decision auto-writes durable 'resolved [key=...]: moot: task metadata absent after teardown' lines into torn-down tasks' status logs. It runs from the ordinary drain's presentation path (print_open_decisions_section, while holding the status-presentation lock, after the snapshot was taken). It comes with a new MOOT DECISIONS section (print_moot_decisions_section, line 578) and the --list-open-decisions mode. The intent asks for re-raising unanswered live decisions and keeping them visible. Folding torn-down rows into a count (display only) already does that, without a read path mutating status records. Seven existing tests needed new mark_live/meta fixtures just to keep their decisions from being auto-closed, which shows how far the behavior change reaches. Recommend removing the auto-close write (and the MOOT section that exists only to list those writes), keeping only the terminal-count fold.
  • ℹ️ bin/fm-watch.sh:1083 - Failures in decision_age_tick are now fatal to the watcher cycle ('exit 1' at line 3080). These include a symlinked .decision-age-* marker (line 1084 'return 1') and a mktemp/mv failure (lines 1118-1122), which now kill every watcher cycle for an auxiliary re-raise feature. A persistent marker problem would take supervision down repeatedly. The per task|key .decision-age-<hash> markers are also never removed after the decision resolves or the task is torn down, so they accumulate in state/. Consider logging and skipping the key instead of exiting, and deleting the marker when the key is no longer open.

🔧 Fix applied.
3 issues (1 warning, 2 infos) still open:

  • ℹ️ bin/fm-watch.sh:1083 - Failures in decision_age_tick are now fatal to the watcher cycle ('exit 1' at line 3080). These include a symlinked .decision-age-* marker (line 1084 'return 1') and a mktemp/mv failure (lines 1118-1122), which now kill every watcher cycle for an auxiliary re-raise feature. A persistent marker problem would take supervision down repeatedly. The per task|key .decision-age-<hash> markers are also never removed after the decision resolves or the task is torn down, so they accumulate in state/. Consider logging and skipping the key instead of exiting, and deleting the marker when the key is no longer open.
  • ⚠️ bin/fm-watch.sh:1142 - The parent-channel lines the fix round added are opened on the parent but nothing ever closes them. Round-1 F1's fix publishes needs-decision [key=decision-unanswered-&lt;id&gt;] (bin/fm-watch.sh:1142-1143) and blocked [key=decision-waiting-&lt;fp12&gt;] (bin/fm-inactive-reconcile.sh:550). No code path appends a matching resolved [key=...] (grep finds no other writer of either key). The fold (fm-classify-lib.sh:861-869) only drops a key on resolved/held, and secondmate kind is exempt from the done:ship clear. Failing sequence: the mate's child opens dlp-clean. At the second re-raise the escalation lands in parent state/mate.status (local route, or the remote parent-replies mirror). The secondmate then answers the child (resolved [key=dlp-clean]), and its own marker and wakes stop. In the main home, mate.status still holds an open needs-decision decision-unanswered-&lt;id&gt; while mate.meta exists. So main's decision_age_tick re-raises 'check: decision unanswered ...: mate decision-unanswered-<id>' every 15/30/60/60 min for as long as the mate lives, and main's OPEN DECISIONS keeps listing it as actionable. Every decision-waiting blocked line also stays in main's OPEN DECISIONS (one per opener fingerprint) after the child's decision resolves. The user's instruction 'stop when the resolved line lands' is met only in the secondmate's own home. Fix at the same publishers: when decision_age_tick drops a live-key marker whose count>=2 (the cleanup loop at ~1083-1086 must read the marker identity before rm), publish resolved [key=decision-unanswered-&lt;identity12&gt;]: child decision answered via fm_parent_channel_report. When reconcile_direct_child_locked finds a child with a reported decision-waiting receipt but no open needs-decision, publish resolved [key=decision-waiting-&lt;fp12&gt;]. Add a test: escalate, resolve the child, then assert main's open set no longer has the key.
  • ℹ️ tests/fm-teardown.test.sh:4299 - Round-1 F2 asked for teardown to append 'resolved [key=..]: moot: task torn down'. bin/fm-teardown.sh was not changed. The invariant still holds because teardown already deletes state/<id>.status and its cursor via status_retire_presentation_task (fm-classify-lib.sh ~1808), and the new test checks that outcome through --list-open-decisions. So the instruction was not followed literally, but no torn-down task's decision can stay open. Drain auto-close and the MOOT section are gone, so the drain is read-only again.

🔧 Fix applied.
4 issues (1 warning, 3 infos) still open:

  • ℹ️ bin/fm-watch.sh:1083 - Failures in decision_age_tick are now fatal to the watcher cycle ('exit 1' at line 3080). These include a symlinked .decision-age-* marker (line 1084 'return 1') and a mktemp/mv failure (lines 1118-1122), which now kill every watcher cycle for an auxiliary re-raise feature. A persistent marker problem would take supervision down repeatedly. The per task|key .decision-age-<hash> markers are also never removed after the decision resolves or the task is torn down, so they accumulate in state/. Consider logging and skipping the key instead of exiting, and deleting the marker when the key is no longer open.
  • ⚠️ bin/fm-watch.sh:1142 - The parent-channel lines the fix round added are opened on the parent but nothing ever closes them. Round-1 F1's fix publishes needs-decision [key=decision-unanswered-&lt;id&gt;] (bin/fm-watch.sh:1142-1143) and blocked [key=decision-waiting-&lt;fp12&gt;] (bin/fm-inactive-reconcile.sh:550). No code path appends a matching resolved [key=...] (grep finds no other writer of either key). The fold (fm-classify-lib.sh:861-869) only drops a key on resolved/held, and secondmate kind is exempt from the done:ship clear. Failing sequence: the mate's child opens dlp-clean. At the second re-raise the escalation lands in parent state/mate.status (local route, or the remote parent-replies mirror). The secondmate then answers the child (resolved [key=dlp-clean]), and its own marker and wakes stop. In the main home, mate.status still holds an open needs-decision decision-unanswered-&lt;id&gt; while mate.meta exists. So main's decision_age_tick re-raises 'check: decision unanswered ...: mate decision-unanswered-<id>' every 15/30/60/60 min for as long as the mate lives, and main's OPEN DECISIONS keeps listing it as actionable. Every decision-waiting blocked line also stays in main's OPEN DECISIONS (one per opener fingerprint) after the child's decision resolves. The user's instruction 'stop when the resolved line lands' is met only in the secondmate's own home. Fix at the same publishers: when decision_age_tick drops a live-key marker whose count>=2 (the cleanup loop at ~1083-1086 must read the marker identity before rm), publish resolved [key=decision-unanswered-&lt;identity12&gt;]: child decision answered via fm_parent_channel_report. When reconcile_direct_child_locked finds a child with a reported decision-waiting receipt but no open needs-decision, publish resolved [key=decision-waiting-&lt;fp12&gt;]. Add a test: escalate, resolve the child, then assert main's open set no longer has the key.
  • ℹ️ tests/fm-teardown.test.sh:4299 - Round-1 F2 asked for teardown to append 'resolved [key=..]: moot: task torn down'. bin/fm-teardown.sh was not changed. The invariant still holds because teardown already deletes state/<id>.status and its cursor via status_retire_presentation_task (fm-classify-lib.sh ~1808), and the new test checks that outcome through --list-open-decisions. So the instruction was not followed literally, but no torn-down task's decision can stay open. Drain auto-close and the MOOT section are gone, so the drain is read-only again.
  • ℹ️ bin/fm-watch.sh:1104 - Added in round 2 (R2-1/F3 fix). The marker cleanup loop treats every marker missing from the live set as resolved: it publishes resolved [key=decision-unanswered-..] to the parent, then deletes the marker. But live is built from scan_open_decisions_incremental (fm-classify-lib.sh:1427), which silently skips a status file whose per-file fold returned non-zero (cursor tmp write or mv failure, e.g. disk full or a permission problem on state/) and still returns 0. Failing sequence: an escalated (count=2) decision is still open, and the cursor write for that task's status file fails for one tick. The parent then receives a resolved line for an unanswered decision and the age marker is reset. The next successful tick re-escalates under a new due-time line, so this heals itself, but the parent briefly loses the open decision. Remedy: have the tick learn whether any per-file fold failed (e.g. a strict variant, or comparing the task list against $STATE/*.status), and skip the close/remove pass for that tick when one did.

🔧 Fix applied.
6 issues (2 warnings, 4 infos) still open:

  • ℹ️ bin/fm-watch.sh:1083 - Failures in decision_age_tick are now fatal to the watcher cycle ('exit 1' at line 3080). These include a symlinked .decision-age-* marker (line 1084 'return 1') and a mktemp/mv failure (lines 1118-1122), which now kill every watcher cycle for an auxiliary re-raise feature. A persistent marker problem would take supervision down repeatedly. The per task|key .decision-age-<hash> markers are also never removed after the decision resolves or the task is torn down, so they accumulate in state/. Consider logging and skipping the key instead of exiting, and deleting the marker when the key is no longer open.
  • ⚠️ bin/fm-watch.sh:1142 - The parent-channel lines the fix round added are opened on the parent but nothing ever closes them. Round-1 F1's fix publishes needs-decision [key=decision-unanswered-&lt;id&gt;] (bin/fm-watch.sh:1142-1143) and blocked [key=decision-waiting-&lt;fp12&gt;] (bin/fm-inactive-reconcile.sh:550). No code path appends a matching resolved [key=...] (grep finds no other writer of either key). The fold (fm-classify-lib.sh:861-869) only drops a key on resolved/held, and secondmate kind is exempt from the done:ship clear. Failing sequence: the mate's child opens dlp-clean. At the second re-raise the escalation lands in parent state/mate.status (local route, or the remote parent-replies mirror). The secondmate then answers the child (resolved [key=dlp-clean]), and its own marker and wakes stop. In the main home, mate.status still holds an open needs-decision decision-unanswered-&lt;id&gt; while mate.meta exists. So main's decision_age_tick re-raises 'check: decision unanswered ...: mate decision-unanswered-<id>' every 15/30/60/60 min for as long as the mate lives, and main's OPEN DECISIONS keeps listing it as actionable. Every decision-waiting blocked line also stays in main's OPEN DECISIONS (one per opener fingerprint) after the child's decision resolves. The user's instruction 'stop when the resolved line lands' is met only in the secondmate's own home. Fix at the same publishers: when decision_age_tick drops a live-key marker whose count>=2 (the cleanup loop at ~1083-1086 must read the marker identity before rm), publish resolved [key=decision-unanswered-&lt;identity12&gt;]: child decision answered via fm_parent_channel_report. When reconcile_direct_child_locked finds a child with a reported decision-waiting receipt but no open needs-decision, publish resolved [key=decision-waiting-&lt;fp12&gt;]. Add a test: escalate, resolve the child, then assert main's open set no longer has the key.
  • ℹ️ tests/fm-teardown.test.sh:4299 - Round-1 F2 asked for teardown to append 'resolved [key=..]: moot: task torn down'. bin/fm-teardown.sh was not changed. The invariant still holds because teardown already deletes state/<id>.status and its cursor via status_retire_presentation_task (fm-classify-lib.sh ~1808), and the new test checks that outcome through --list-open-decisions. So the instruction was not followed literally, but no torn-down task's decision can stay open. Drain auto-close and the MOOT section are gone, so the drain is read-only again.
  • ℹ️ bin/fm-watch.sh:1104 - Added in round 2 (R2-1/F3 fix). The marker cleanup loop treats every marker missing from the live set as resolved: it publishes resolved [key=decision-unanswered-..] to the parent, then deletes the marker. But live is built from scan_open_decisions_incremental (fm-classify-lib.sh:1427), which silently skips a status file whose per-file fold returned non-zero (cursor tmp write or mv failure, e.g. disk full or a permission problem on state/) and still returns 0. Failing sequence: an escalated (count=2) decision is still open, and the cursor write for that task's status file fails for one tick. The parent then receives a resolved line for an unanswered decision and the age marker is reset. The next successful tick re-escalates under a new due-time line, so this heals itself, but the parent briefly loses the open decision. Remedy: have the tick learn whether any per-file fold failed (e.g. a strict variant, or comparing the task list against $STATE/*.status), and skip the close/remove pass for that tick when one did.
  • ⚠️ bin/fm-watch.sh:1142 - Firstmate authorized parent escalation after the SECOND re-raise of the same unanswered key at about 45 minutes by default. The first fix agent reported its implementation escalates at about 30 minutes. Align the age/backoff schedule and parent escalation threshold with the authorized timing, and assert the boundary behavior in an executable test: no parent escalation before that second re-raise, one escalation at or after it.
  • ℹ️ bin/fm-watch.sh:1112 - This was added by the round-3 R3-1 fix. When any single status log fails to fold (scan_open_decisions_incremental --strict returns 3), the tick skips the close/remove pass for every task's markers, not just the failed task's. Failing sequence: task A's open-decisions cursor mv keeps failing (for example, the cursor path is unwritable or replaced by a directory). Meanwhile mate child B's escalated decision (count>=2) is answered. While A's failure lasts, B's parent decision-unanswered-&lt;id&gt; is never closed, and B's marker stays, so the parent keeps re-raising an answered decision. That is the R2-1 symptom, now gated on an unrelated file's health. The only signal is a repeating triage-log line. Narrower remedy, no new state: keep the strict signal, but also have the walk report which task files failed, then skip closing only the markers whose task|key hash belongs to those tasks. The live-set loop already computes the hashes per task. Sibling paths in the same class, where status_open_decisions_incremental (bin/fm-classify-lib.sh ~1304, ~1372-1380) returns an empty set with rc 0 rather than signalling failure: an unreadable status file ([ -r ] fails), and a span read or chunk write failure when the trusted cursor set is empty (cursor version or ident reset). Both would still let the tick publish a false resolved.

🔧 Fix applied.
1 info still open:

  • ℹ️ tests/fm-teardown.test.sh:4299 - Round-1 F2 asked for teardown to append 'resolved [key=..]: moot: task torn down'. bin/fm-teardown.sh was not changed. The invariant still holds because teardown already deletes state/<id>.status and its cursor via status_retire_presentation_task (fm-classify-lib.sh ~1808), and the new test checks that outcome through --list-open-decisions. So the instruction was not followed literally, but no torn-down task's decision can stay open. Drain auto-close and the MOOT section are gone, so the drain is read-only again.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Secondmate child keyed decision buried under routine appends re-wakes the secondmate supervisor with task+key ✅ pass live live-secondmate-dlp-clean.txt: 'check: decision unanswered 23s: docs dlp-clean-behind-active-run'
Parent escalation fires only at the second re-raise, exactly once ✅ pass live live-secondmate-dlp-clean.txt: parent channel empty after the first re-raise; one needs-decision [key=decision-unanswered-e408fa26ee1e] after the second
Answering the child decision closes the parent escalation once, removes the age marker, and stops the wakes ✅ pass live live-secondmate-dlp-clean.txt: one resolved line, no .decision-age-* marker left, parent open list empty, later watcher idle (rc=124)
Idle child waiting on a decision is reported upstream as a blocked decision-wait, not an inactive terminal outcome; deduplicated; closed when answered ✅ pass live live-reconcile-decision-wait.txt: blocked [key=decision-waiting-bf76fef470fa] once across 2 scans, 0 inactive-outcome rows, resolved once after the answer
Adversarial: crew-state reports 'done' for a child with an open decision, and no terminal outcome is created ⏸️ untested no The prior payload did not establish a live result. Only the stub test (fake crew-state=done) in tests/fm-inactive-reconcile.test.sh covered it, because the real bin/fm-crew-state.sh reported 'unknown'…
Drain marks overdue decisions [age=..] [actionable: unanswered], folds torn-down tasks into a count, and --list-open-decisions is read-only ✅ pass live live-main-drain-open-decisions.txt: live rows with age markers, '3 terminal decisions folded', full list shows gone1-3, state/ shasum diff empty
Adversarial: stale decisions of torn-down tasks and fresh decisions below the threshold do not trigger age wakes ✅ pass live live-main-drain-open-decisions.txt: the only age row queued is 'check: decision unanswered 3616s: live-old publication'
Adversarial: a failed per-task fold neither falsely closes the escalation of a still-open decision nor blocks closing an answered one ⏸️ untested no The prior payload did not establish a live result. Only tests/fm-decision-age.test.sh covered it, using a fake mv injected on PATH to make the cursor write fail. A live run would need a real filesyste…
  • bash tests/fm-decision-age.test.sh (5 ok)
  • bash tests/fm-inactive-reconcile.test.sh (39 ok, incl. 2 new decision-wait cases)
  • bash tests/fm-wake-drain-open-decisions.test.sh
  • bash tests/fm-wake-drain-open-decisions-cursor.test.sh
  • bash tests/fm-classify-decision-key.test.sh
  • Live: bin/fm-lab-home.sh main+secondmate homes (local parent route); real bin/fm-watch.sh ticks with FM_DECISION_AGE_SECS=3 on dlp-clean-behind-active-run buried under routine appends; real drain ack between ticks; resolve and re-tick; parent --list-open-decisions before and after
  • Live: real bin/fm-inactive-reconcile.sh scan --startup x2 in the secondmate home with the real bin/fm-crew-state.sh; then answer the decision and re-scan
  • Live: main-home drain with live and torn-down decisions; --list-open-decisions with a state/ shasum diff before and after; real watcher tick at the default 900s threshold
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)

🔧 No changes applied.
1 warning still open:

  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

Tracking: #6517

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 3/5

[High risk] Adds decision-age tracking and re-raise logic to the task supervision system.

The PR should not merge until parent waits remain accurate when a child has multiple decisions or its status file is temporarily unavailable.

Reviews (1) · Last reviewed commit: "no-mistakes(document): Document decision..."

while IFS=$'\t' read -r key decision_verb _; do
[ "$decision_verb" = needs-decision ] || continue
decision_key=$key
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Other decisions go unreported When a secondmate child has two open needs-decision keys, this break publishes a parent-channel wait for only the first. If that key is answered while the child keeps appending activity, the inactivity check can prevent a later scan from publishing the remaining key. The parent may never learn that the child is still waiting for a decision.

still=0
if [ -f "$meta" ] && [ ! -L "$meta" ]; then
incarnation=$(meta_incarnation "$meta")
open=$(status_open_decisions "$STATE/$id.status" "$(meta_field "$meta" kind)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Unavailable status falsely closes waits If a child's metadata remains present but its status file is temporarily missing or unreadable, status_open_decisions returns an empty set. This pass then sends the parent a resolved line and permanently marks the wait closed, even if the child still needs an answer. Restoring the status file does not undo the false resolution.

Comment thread bin/fm-wake-drain.sh
continue
fi
epoch=0
origin=$(status_open_decision_origin "$STATE/$task.status" "$key") || origin=''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Decision ages slow every drain This origin lookup scans the task's entire status history for each open decision on every ordinary drain, even though the open-decision fold reads only new appends. Long-lived logs with several unanswered keys will make routine drains progressively slower. FM_OPEN_DECISIONS_MAX_ROWS limits output only after all these scans have run.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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