Repository navigation
fix(bin): re-raise unanswered decisions and stop reporting decision waits as inactive outcomes - #6523
maruthiprithivi wants to merge 6 commits into
Conversation
Track decision age with bounded wake backoff, retain active decisions in inactive reconciliation, and surface aged decisions ahead of stale terminal keys. Fixes kunchenguid#6517
…alate at 45 minutes
…ion, and config knobs
|
| while IFS=$'\t' read -r key decision_verb _; do | ||
| [ "$decision_verb" = needs-decision ] || continue | ||
| decision_key=$key | ||
| break |
There was a problem hiding this comment.
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)") |
There was a problem hiding this comment.
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.
| continue | ||
| fi | ||
| epoch=0 | ||
| origin=$(status_open_decision_origin "$STATE/$task.status" "$key") || origin='' |
There was a problem hiding this comment.
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!
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.shadds adecision_age_tickthat runs on every watcher cycle. It reads the authoritative open-decision set, so aneeds-decisionis still found after later status lines bury it. Once a decision is older thanFM_DECISION_AGE_SECS(default 900), the tick raises acheck: decision unanswered <age>swake. 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 oneneeds-decision [key=decision-unanswered-<id>]line to the parent channel. A matchingresolvedline 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.shno longer reports a child with an openneeds-decisionas a terminal done/failed outcome. In a secondmate home it posts ablocked [key=decision-waiting-<fp>]line to the parent channel once per opener, andwaiting_close_passcloses it with aresolvedline when the decision is answered or the child goes away.bin/fm-classify-lib.shadds the sharedstatus_open_decision_origin(the opener's time and line position) andfm_decision_age_thresholdhelpers.bin/fm-wake-drain.shchanges the OPEN DECISIONS section:[age=…], and rows past the age threshold are tagged[actionable: unanswered].FM_OPEN_DECISIONS_MAX_ROWS(default 10000). Any rows it drops are flagged loudly.--list-open-decisionsflag prints every open decision.The branch prompt, the supervision-protocol docs,
docs/configuration.mdanddocs/secondmate-parent-channel.mdare updated to match. New and extended shell tests cover decision age, inactive reconcile, teardown and wake-drain.🤖 Generated with Claude Code
Risk Assessment
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.
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
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
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
Evidence: fm-decision-age test log
Source: fm-decision-age test log
Evidence: fm-inactive-reconcile test log
Source: fm-inactive-reconcile test log
Evidence: Parent escalation excerpt
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
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 publishesneeds-decision [key=decision-unanswered-<id>](bin/fm-watch.sh:1142-1143) andblocked [key=decision-waiting-<fp12>](bin/fm-inactive-reconcile.sh:550). No code path appends a matchingresolved [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-decisiondecision-unanswered-<id>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), publishresolved [key=decision-unanswered-<identity12>]: child decision answeredvia fm_parent_channel_report. When reconcile_direct_child_locked finds a child with a reported decision-waiting receipt but no open needs-decision, publishresolved [key=decision-waiting-<fp12>]. 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 publishesneeds-decision [key=decision-unanswered-<id>](bin/fm-watch.sh:1142-1143) andblocked [key=decision-waiting-<fp12>](bin/fm-inactive-reconcile.sh:550). No code path appends a matchingresolved [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-decisiondecision-unanswered-<id>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), publishresolved [key=decision-unanswered-<identity12>]: child decision answeredvia fm_parent_channel_report. When reconcile_direct_child_locked finds a child with a reported decision-waiting receipt but no open needs-decision, publishresolved [key=decision-waiting-<fp12>]. 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 theliveset as resolved: it publishesresolved [key=decision-unanswered-..]to the parent, then deletes the marker. Butliveis 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 publishesneeds-decision [key=decision-unanswered-<id>](bin/fm-watch.sh:1142-1143) andblocked [key=decision-waiting-<fp12>](bin/fm-inactive-reconcile.sh:550). No code path appends a matchingresolved [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-decisiondecision-unanswered-<id>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), publishresolved [key=decision-unanswered-<identity12>]: child decision answeredvia fm_parent_channel_report. When reconcile_direct_child_locked finds a child with a reported decision-waiting receipt but no open needs-decision, publishresolved [key=decision-waiting-<fp12>]. 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 theliveset as resolved: it publishesresolved [key=decision-unanswered-..]to the parent, then deletes the marker. Butliveis 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 parentdecision-unanswered-<id>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 whosetask|keyhash 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 falseresolved.🔧 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.
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.shbash tests/fm-wake-drain-open-decisions-cursor.test.shbash tests/fm-classify-decision-key.test.shLive: 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 afterLive: 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-scanLive: 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.
🔧 No changes applied.
1 warning still open:
✅ **Push** - passed
✅ No issues found.
Tracking: #6517