Repository navigation
Fix dropped Claude handbacks with healthy successors - #41
Conversation
Reviewer's GuideThe PR fixes dropped actionable Claude handbacks by treating a refused rewake as a terminal failure even when a successor is healthy, documents the delivery guarantee, and adds a deterministic real-component regression proving the original wake reaches and is acknowledged by the primary. Sequence diagram for healthy-successor Claude handback deliverysequenceDiagram
participant Hook as Claude stop hook
participant Queue as Wake queue
participant Successor as Healthy successor
participant Primary as Idle primary
Hook->>Hook: fm_autoarm_still_owner
Hook->>Hook: fm_recovery_marker_snapshot
alt Handling marker rejects rewake commit
Hook->>Queue: [retain original actionable wake]
Hook->>Queue: [enqueue recovery notice]
Hook->>Hook: exit 2
Successor->>Queue: [watch later events]
Queue->>Primary: [present original wake and recovery notice]
Primary->>Queue: [generation-bound acknowledgement]
else Successful rewake commit
Hook->>Hook: exit 0
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="bin/fm-claude-stop-autoarm.sh" line_range="544" />
<code_context>
&& fm_recovery_marker_snapshot "$STATE/.watcher-down" \
- && [[ "$FM_RECOVERY_MARKER_TOKEN" == pending:handling:* || "$FM_RECOVERY_MARKER_TOKEN" == announced:handling:* ]] \
- && ! fm_watcher_healthy "$STATE" "$SCRIPT_DIR/fm-watch.sh" "$GRACE" "$FM_HOME"; then
+ && [[ "$FM_RECOVERY_MARKER_TOKEN" == pending:handling:* || "$FM_RECOVERY_MARKER_TOKEN" == announced:handling:* ]]; then
LOST_HANDBACK_COMMITTED=0
if [ ! -e "$FAILURE_NOTICE" ]; then
</code_context>
<issue_to_address>
**Wake stays stranded on notice-write failure**
When the epoch write succeeds but creating the failure-notice marker fails, `fm_autoarm_write_owned` can rename the epoch to `failed` and then fail to create the notice marker; the fallback treats that as an uncommitted failure and exits 0. The original wake remains queued without a delivered recovery notice, leaving the primary unwoken.
Make this fallback recoverably deliver the failure when the notice-marker write fails, rather than silently exiting after the terminal ledger write.
</issue_to_address>|
Addressed the Medium notice-write finding in The new real hook/host/arm regression makes the failure-notice path a dangling symlink inside its temporary home. Before the fix, the epoch becomes The handback fallback now attempts a separate ownership-checked, markerless failure commit when the marker-backed commit fails. It delivers the original wake with exit 2 only if that second commit succeeds. A superseded owner still cannot deliver. The warning explicitly says that the notice could not be recorded and may repeat until its marker is writable; the code does not pretend notice suppression was persisted. The same regression now passes while the marker remains unrecordable and the successor stays live. The primary receives and acknowledges the original queued event. Ordinary non-actionable marker-write refusal and once-per-episode suppression remain unchanged, and their existing tests pass. Validation on this head:
The previously disclosed broader test limitations remain. No no-mistakes run or merge performed. |
|
Final disposition for head |
Fix
An actionable host handback can remain undelivered while its handling successor is healthy. The successful-rewake commit rejects the handling marker, as intended, but the existing failure fallback also rejects a healthy successor. The hook then exits 0 with its claim still
armingand the original event still queued. An idle primary receives nothing.Remove that health exemption from the existing failure fallback. A healthy successor watches future events; it cannot deliver the handback that already returned. The hook now commits a terminal failure and exits 2 with the original wake and recovery notice. Generation ownership, marker checks, notice suppression, and successful-rewake semantics remain unchanged. No host, shared arm, turn-end guard, or other adapter code changes.
The new regression uses the real hook, host, arm, watcher, queue, primary drain, and acknowledgement. An optional FIFO at the existing external node boundary makes the overlapping-arm handoff deterministic. The test confirms that the successor stays live while the primary receives and acknowledges the original event.
Evidence
3b2c073283dbc9ee44d2ce3319900367fba57121: expected exit 2, got 0, withoutcome=arming.tests/fm-claude-stop-autoarm.test.shpasses throughbin/fm-test-run.sh.This reproduces a real drop mechanism consistent with the reported symptoms. It does not prove every historical gap had this cause. No credentialed live Claude test was run.
Known validation failures
tests/fm-watch-arm.test.sh::test_watcher_exits_when_its_state_directory_is_removedfails both in the suite and alone in the working copy. The failing run invokes the unchanged base arm/watcher/test code, not the modified hook. A further isolated run from a clean detached base copy passes, so this is not a consistently reproducible base failure. It is left unchanged and tracked separately.The complete
tests/fm-supervision-host.test.shrun passes 48 cases, including this regression and the relevant hook handoffs, then fails intest_undelivered_dialog_is_fed_again_on_the_next_turnwaiting for a downtime resurface. That host-only case does not invoke the modified hook. It is also left unchanged. The complete host script is not claimed green.Scope and structure
The existing hook remains the owner. No new production function or file is added. The new integration test is one cohesive scenario in the existing handoff suite. Splitting the pre-existing large test file or changing host token plumbing is outside this fix. Documentation changes only the healthy-successor delivery guarantee.
No full repository suite, no-mistakes run, or merge, as requested.
Summary by Sourcery
Deliver uncommitted actionable handbacks to the primary instead of suppressing them when a healthy successor is present.
Bug Fixes:
Enhancements:
Documentation:
Tests: