You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: prevent supervision stale-ack and ghost-report loops - #3604
For the refused-ack loop and other errors in the supervision transcript, hand the report to a Fable crewmate and do 1, 2, 3, 7 in one PR.
What Changed
Restrict branch reports to wake-scoped live tasks, verify spawn generations before storing outcomes, and reserve fleet for supervision reports.
Make stale no-op acknowledgements identify the current wake and exact remedy while giving branch actors grant-aware guard guidance.
Synchronize teardown with outcome storage, remove retired-task indexes, and prevent index rebuilds from resurrecting them.
Risk Assessment
✅ Low: The wake-scoping, spawn-generation validation, reserved fleet identifier, and serialized retirement paths consistently enforce the intended durable invariants across inspected sibling paths.
Testing
The changed spawn reservation, wake-scoped report authorization, generation-map safety, branch guard guidance, stale-ack recovery, outcome-index retirement, and teardown lock boundaries passed focused tests. An end-user-style transcript confirms replaying a stale acknowledgement preserves the current wake, prints its exact remedy, and that remedy empties the queue; broader suite attempts were blocked by unrelated unchanged or host-sensitive cases.
$ fm-wake-drain.sh # current wake presentation
1788429787 2 check second check: second wake
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 2 --recovery-generation 89589.1788429787.s0J80J
$ bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 88625.1788429786.7IeeHG # stale prior command
wake drain: nothing was acknowledged through 1 (none of your presented wake rows is at or below it); the current wake is row 2: run bin/fm-wake-drain.sh --ack-through 2 --recovery-generation 89589.1788429787.s0J80J after handling it
$ queue remains after stale acknowledgement:
1788429787 2 check second check: second wake
$ bin/fm-wake-drain.sh --ack-through 2 --recovery-generation 89589.1788429787.s0J80J # printed remedy
queue state: empty (current wake acknowledged)
🚨 bin/fm-branch-outcome.sh:274 - Recommendation 7 remains incomplete: the rebuild skips retired tasks, but append still unconditionally calls write_outcome_index. In the normal branch workflow, fm-teardown.sh removes a task's index, then the required post-handling fm_branch_report appends the teardown outcome and recreates that same index despite the task having no meta or status file. Apply the retired-task check at the append/index-write boundary (and coordinate teardown/index mutation if concurrent teardown must also preserve the invariant) before publishing the ready marker.
🔧 Fix: Prevent retired outcome indexes from being recreated
✅ Re-checked - no issues remain.
🚨 bin/fm-branch-outcome.sh:471 - A retired-task ghost report remains reachable. If a wake scope captures task A, teardown completes while the branch prompt is running, and the model then reports A, wakeScopeRefusal accepts the captured task and append stores and delivers the outcome; this condition merely skips A's index when both meta and status are gone. Reject non-fleet appends lacking both live records while holding the shared outcome lock, rather than storing them without an index.
🚨 bin/fm-teardown.sh:2924 - The bounded outcome-lock refusal occurs after destructive cleanup. For an ordinary Orca ship, teardown can remove the terminal/worktree at line 2794, time out here, retain the meta, and then every non-forced retry refuses because the recorded Orca worktree is no longer inspectable (line 2697). Acquire the outcome lock before the first destructive task cleanup so contention leaves the operation genuinely retryable.
🔧 Fix: Reject ghost reports and lock teardown early
1 warning still open:
⚠️bin/fm-teardown.sh:2769 - The earlier outcome-lock acquisition creates a lock-order inversion with wake presentation. fm-wake-drain.sh holds .status-presentation-lock before acquiring .branch-outcomes.lock, while teardown now holds the outcome lock before status_retire_presentation_task acquires the presentation lock. A concurrent drain and teardown therefore stall each other until the drain's default 10-second timeout, causing the drain to skip the outcome backstop and delaying teardown. Establish one lock order at this boundary, for example by acquiring the presentation lock before the outcome lock and retiring status under the already-held lock.
🔧 Fix: Order teardown presentation and outcome locks safely
1 error still open:
🚨 bin/fm-teardown.sh:727 - The durable retirement fix still misses remote secondmates. remote_secondmate_teardown removes status and meta without the outcome lock and never removes .$ID.branch-outcome-index. A concurrent append can verify the still-live meta under .branch-outcomes.lock, then this path retires the records, after which the append stores a ghost outcome and may recreate/leave the index. Acquire presentation then outcome locks before remote retirement becomes destructive, and remove the index within the same locked retirement boundary.
🔧 Fix: Serialize remote retirement with outcome indexes
1 error still open:
🚨 bin/fm-teardown.sh:2612 - Forced secondmate descendant cleanup still retires child status/meta/index without the child home's outcome lock. A concurrent child branch append can acquire that lock and validate the live meta, then cleanup removes the records/index, after which append stores and delivers the retired child's ghost outcome and recreates its index. If later child cleanup fails, the partially retired home persists in that state. Acquire each descendant home's presentation lock and then outcome lock before its first destructive cleanup, using the same shared retirement boundary as ordinary teardown.
🔧 Fix: Lock descendant outcome stores during forced retirement
1 error still open:
🚨 .pi/extensions/fm-branch-supervision.ts:524 - Wake authorization tracks only the reusable task ID, despite task metadata providing spawn_gen specifically to distinguish incarnations. Concrete path: scope captures task A, old A is torn down, a new A is spawned, then the still-open prompt reports A. The scope accepts it and fm-branch-outcome.sh append sees the replacement's live records, stores the stale outcome, and indexes it against the replacement status file, potentially suppressing new-worker status as handled. Capture the task's spawn_gen with the wake scope and verify that generation under the outcome lock before append.
🔧 Fix: Bind branch reports to task spawn generations
2 issues (1 error, 1 warning) still open:
🚨 .pi/extensions/fm-branch-supervision.ts:935 - The durable incarnation check is bypassed for the valid task ID fleet (task creation currently permits it). Concrete path: a wake captures task fleet, teardown retires it, and the open prompt reports task=fleet; this unconditional exception accepts it, omits --spawn-gen, and fm-branch-outcome.sh also exempts fleet from live-record checks, so the retired ghost outcome is stored and delivered. Resolving the collision requires authorization: either reserve/migrate the fleet task ID at task creation or disambiguate fleet-wide reports in the report protocol.
⚠️.pi/extensions/lib/fm-branch-dispatch.ts:142 - taskGenerations is a normal JavaScript object, but task IDs permit __proto__. Assigning that valid ID invokes the prototype setter instead of storing its generation; the wake scope then receives an object rather than the spawn token and reporting that task fails before append. Use a null-prototype object or a Map for task-keyed generations.
🔧 Fix: Reserve fleet task ID and harden generation maps
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-wake-queue.test.sh and focused execution of test_stale_ack_that_consumes_nothing_names_the_current_wake plus test_branch_stale_ack_that_consumes_nothing_names_its_granted_wake
Focused execution of test_branch_report_refuses_a_task_the_wake_did_not_name from tests/fm-pi-branch-extension.test.sh
bash tests/fm-guard-stale-banner.test.sh
bash tests/fm-teardown.test.sh
bash tests/fm-wake-drain-outcome-backstop.test.sh
Manual real-CLI reproduction: presented a second wake, replayed the previous acknowledgement, followed the newly printed corrective command, and verified the queue emptied and recovery marker became acknowledged
✅ No issues found.
tests/fm-spawn-batch.test.sh — verified the reserved fleet task ID through single and batch spawn interfaces.
Focused tests/fm-pi-branch-extension.test.sh selectors: test_branch_dispatch_classifies_main_only_rows_and_writes_the_eligible_snapshot and test_branch_report_refuses_a_task_the_wake_did_not_name.
Focused tests/fm-wake-queue.test.sh selectors: test_stale_ack_that_consumes_nothing_names_the_current_wake and test_branch_stale_ack_that_consumes_nothing_names_its_granted_wake.
tests/fm-guard-stale-banner.test.sh — verified branch guidance names granted rows rather than instructing another drain.
tests/fm-wake-drain-outcome-backstop.test.sh — verified retired outcome indexes are not resurrected.
Focused tests/fm-teardown.test.sh selectors: test_local_only_fork_remote_allows, test_forced_secondmate_teardown_holds_descendant_lifecycle_locks, and test_live_outcome_lock_refuses_after_deadline.
Manual end-to-end invocation of bin/fm-wake-drain.sh: presented a second wake, replayed the first wake's stale acknowledgement, followed the printed replacement command, and inspected persisted queue state.
Broader monolithic test attempts were also made; unchanged/environment-sensitive cases stopped fm-wake-queue.test.sh, fm-pi-branch-extension.test.sh, fm-teardown.test.sh, and fm-remote-secondmate-lifecycle-e2e.test.sh before completion, so changed scenarios were rerun through focused selectors.
✅ **Document** - passed
✅ No issues found.
✅ No issues found.
⚠️ **Lint** - 0 issues
✅ No issues found.
⚠️ linter found issues (exit code 1)
🔧 Fix: Remove unused descendant lock index variable
✅ Re-checked - no issues remain.
Intent
For the refused-ack loop and other errors in the supervision transcript, hand the report to a Fable crewmate and do 1, 2, 3, 7 in one PR.
What Changed
fleetfor supervision reports.Risk Assessment
✅ Low: The wake-scoping, spawn-generation validation, reserved fleet identifier, and serialized retirement paths consistently enforce the intended durable invariants across inspected sibling paths.
Testing
The changed spawn reservation, wake-scoped report authorization, generation-map safety, branch guard guidance, stale-ack recovery, outcome-index retirement, and teardown lock boundaries passed focused tests. An end-user-style transcript confirms replaying a stale acknowledgement preserves the current wake, prints its exact remedy, and that remedy empties the queue; broader suite attempts were blocked by unrelated unchanged or host-sensitive cases.
Evidence: End-to-end refused-ack loop recovery transcript
Source: End-to-end refused-ack loop recovery transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (7) ✅
bin/fm-branch-outcome.sh:274- Recommendation 7 remains incomplete: the rebuild skips retired tasks, butappendstill unconditionally callswrite_outcome_index. In the normal branch workflow,fm-teardown.shremoves a task's index, then the required post-handlingfm_branch_reportappends the teardown outcome and recreates that same index despite the task having no meta or status file. Apply the retired-task check at the append/index-write boundary (and coordinate teardown/index mutation if concurrent teardown must also preserve the invariant) before publishing the ready marker.🔧 Fix: Prevent retired outcome indexes from being recreated
✅ Re-checked - no issues remain.
bin/fm-branch-outcome.sh:471- A retired-task ghost report remains reachable. If a wake scope captures task A, teardown completes while the branch prompt is running, and the model then reports A,wakeScopeRefusalaccepts the captured task andappendstores and delivers the outcome; this condition merely skips A's index when both meta and status are gone. Reject non-fleet appends lacking both live records while holding the shared outcome lock, rather than storing them without an index.bin/fm-teardown.sh:2924- The bounded outcome-lock refusal occurs after destructive cleanup. For an ordinary Orca ship, teardown can remove the terminal/worktree at line 2794, time out here, retain the meta, and then every non-forced retry refuses because the recorded Orca worktree is no longer inspectable (line 2697). Acquire the outcome lock before the first destructive task cleanup so contention leaves the operation genuinely retryable.🔧 Fix: Reject ghost reports and lock teardown early
1 warning still open:
bin/fm-teardown.sh:2769- The earlier outcome-lock acquisition creates a lock-order inversion with wake presentation.fm-wake-drain.shholds.status-presentation-lockbefore acquiring.branch-outcomes.lock, while teardown now holds the outcome lock beforestatus_retire_presentation_taskacquires the presentation lock. A concurrent drain and teardown therefore stall each other until the drain's default 10-second timeout, causing the drain to skip the outcome backstop and delaying teardown. Establish one lock order at this boundary, for example by acquiring the presentation lock before the outcome lock and retiring status under the already-held lock.🔧 Fix: Order teardown presentation and outcome locks safely
1 error still open:
bin/fm-teardown.sh:727- The durable retirement fix still misses remote secondmates.remote_secondmate_teardownremoves status and meta without the outcome lock and never removes.$ID.branch-outcome-index. A concurrentappendcan verify the still-live meta under.branch-outcomes.lock, then this path retires the records, after which the append stores a ghost outcome and may recreate/leave the index. Acquire presentation then outcome locks before remote retirement becomes destructive, and remove the index within the same locked retirement boundary.🔧 Fix: Serialize remote retirement with outcome indexes
1 error still open:
bin/fm-teardown.sh:2612- Forced secondmate descendant cleanup still retires child status/meta/index without the child home's outcome lock. A concurrent child branch append can acquire that lock and validate the live meta, then cleanup removes the records/index, after which append stores and delivers the retired child's ghost outcome and recreates its index. If later child cleanup fails, the partially retired home persists in that state. Acquire each descendant home's presentation lock and then outcome lock before its first destructive cleanup, using the same shared retirement boundary as ordinary teardown.🔧 Fix: Lock descendant outcome stores during forced retirement
1 error still open:
.pi/extensions/fm-branch-supervision.ts:524- Wake authorization tracks only the reusable task ID, despite task metadata providingspawn_genspecifically to distinguish incarnations. Concrete path: scope captures task A, old A is torn down, a new A is spawned, then the still-open prompt reports A. The scope accepts it andfm-branch-outcome.sh appendsees the replacement's live records, stores the stale outcome, and indexes it against the replacement status file, potentially suppressing new-worker status as handled. Capture the task'sspawn_genwith the wake scope and verify that generation under the outcome lock before append.🔧 Fix: Bind branch reports to task spawn generations
2 issues (1 error, 1 warning) still open:
.pi/extensions/fm-branch-supervision.ts:935- The durable incarnation check is bypassed for the valid task IDfleet(task creation currently permits it). Concrete path: a wake captures taskfleet, teardown retires it, and the open prompt reportstask=fleet; this unconditional exception accepts it, omits--spawn-gen, andfm-branch-outcome.shalso exemptsfleetfrom live-record checks, so the retired ghost outcome is stored and delivered. Resolving the collision requires authorization: either reserve/migrate thefleettask ID at task creation or disambiguate fleet-wide reports in the report protocol..pi/extensions/lib/fm-branch-dispatch.ts:142-taskGenerationsis a normal JavaScript object, but task IDs permit__proto__. Assigning that valid ID invokes the prototype setter instead of storing its generation; the wake scope then receives an object rather than the spawn token and reporting that task fails before append. Use a null-prototype object or aMapfor task-keyed generations.🔧 Fix: Reserve fleet task ID and harden generation maps
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-wake-queue.test.shand focused execution oftest_stale_ack_that_consumes_nothing_names_the_current_wakeplustest_branch_stale_ack_that_consumes_nothing_names_its_granted_wakeFocused execution oftest_branch_report_refuses_a_task_the_wake_did_not_namefromtests/fm-pi-branch-extension.test.shbash tests/fm-guard-stale-banner.test.shbash tests/fm-teardown.test.shbash tests/fm-wake-drain-outcome-backstop.test.shManual real-CLI reproduction: presented a second wake, replayed the previous acknowledgement, followed the newly printed corrective command, and verified the queue emptied and recovery marker became acknowledged✅ No issues found.
tests/fm-spawn-batch.test.sh— verified the reservedfleettask ID through single and batch spawn interfaces.Focusedtests/fm-pi-branch-extension.test.shselectors:test_branch_dispatch_classifies_main_only_rows_and_writes_the_eligible_snapshotandtest_branch_report_refuses_a_task_the_wake_did_not_name.Focusedtests/fm-wake-queue.test.shselectors:test_stale_ack_that_consumes_nothing_names_the_current_wakeandtest_branch_stale_ack_that_consumes_nothing_names_its_granted_wake.tests/fm-guard-stale-banner.test.sh— verified branch guidance names granted rows rather than instructing another drain.tests/fm-wake-drain-outcome-backstop.test.sh— verified retired outcome indexes are not resurrected.Focusedtests/fm-teardown.test.shselectors:test_local_only_fork_remote_allows,test_forced_secondmate_teardown_holds_descendant_lifecycle_locks, andtest_live_outcome_lock_refuses_after_deadline.Manual end-to-end invocation ofbin/fm-wake-drain.sh: presented a second wake, replayed the first wake's stale acknowledgement, followed the printed replacement command, and inspected persisted queue state.Broader monolithic test attempts were also made; unchanged/environment-sensitive cases stoppedfm-wake-queue.test.sh,fm-pi-branch-extension.test.sh,fm-teardown.test.sh, andfm-remote-secondmate-lifecycle-e2e.test.shbefore completion, so changed scenarios were rerun through focused selectors.✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ No issues found.
🔧 Fix: Remove unused descendant lock index variable
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.