Skip to content

Fix dropped Claude handbacks with healthy successors - #41

Merged
twilwa merged 2 commits into
mainfrom
fm/fm-claude-rewake-intermittent-gap
Oct 23, 2026
Merged

twilwa merged 2 commits into
mainfrom
fm/fm-claude-rewake-intermittent-gap

Conversation

@twilwa

@twilwa twilwa commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

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 arming and 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

  • The final regression fails against the clean base hook at 3b2c073283dbc9ee44d2ce3319900367fba57121: expected exit 2, got 0, with outcome=arming.
  • The same regression passes with this fix: exit 2, terminal failed claim, original queued event presented to the primary, and generation-bound acknowledgement succeeds.
  • Complete tests/fm-claude-stop-autoarm.test.sh passes through bin/fm-test-run.sh.
  • Nine selected real host/hook handoff scenarios pass, including healthy and closed successors, pending and announced handling markers, main-only transitions, and budget handoffs.
  • Focused canonical lint passes for both changed shell files with pinned ShellCheck 0.11.0 and extended analysis. Shell syntax, diff checks, and documentation audience/link checks pass.

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_removed fails 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.sh run passes 48 cases, including this regression and the relevant hook handoffs, then fails in test_undelivered_dialog_is_fed_again_on_the_next_turn waiting 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:

  • Ensure actionable Claude handbacks are delivered to the primary even when a healthy successor is handling later events.
  • Allow delivery to proceed when failure-notice marker storage is unavailable, while retaining ownership checks and repeat-notice behavior.

Enhancements:

  • Document the healthy-successor handback delivery guarantee and failure-notice behavior.

Documentation:

  • Document that healthy successors cannot substitute for delivery of an already-returned actionable wake and that notices may repeat when suppression markers are unwritable.

Tests:

  • Add integration coverage for healthy-successor handbacks, including unwritable failure-notice markers and end-to-end acknowledgement of the original queued event.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The 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 delivery

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Make uncommitted actionable handbacks terminal failures regardless of successor health.
  • Remove the healthy-successor exemption from the handling-marker failure fallback.
  • Preserve ownership, generation, marker, notice-suppression, and successful-rewake behavior while returning exit 2 and retaining the queued wake for primary delivery.
  • Document that a healthy successor only watches later events and cannot confirm delivery of the returned wake.
bin/fm-claude-stop-autoarm.sh
docs/watcher-continuity.md
Add a deterministic end-to-end regression for live-successor handback delivery.
  • Coordinate the real hook, host, arm, watcher, queue, primary drain, and acknowledgement using an optional FIFO at the node boundary.
  • Verify the successor remains healthy while the hook records terminal failure, emits recovery notice, leaves the original wake queued, and allows generation-bound acknowledgement.
  • Harden the node shim to delegate to the real executable without recursive interception.
tests/fm-supervision-host.test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T20:04:30.917608Z 626cdbc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread bin/fm-claude-stop-autoarm.sh Resolved
@twilwa

twilwa commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Addressed the Medium notice-write finding in 507fcd745c27e07dbc65e111fd27db955498c4c4.

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 failed but the hook exits 0, reproducing the review finding.

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:

  • Complete tests/fm-claude-stop-autoarm.test.sh passes through the canonical runner.
  • Ten selected real host/hook handoff cases pass, including both writable and unwritable notice paths.
  • Focused canonical ShellCheck, syntax, diff checks, and documentation audience/link checks pass.

The previously disclosed broader test limitations remain. No no-mistakes run or merge performed.

@twilwa

twilwa commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Final disposition for head 507fcd74 (firstmate review ledger, low stakes): the Sourcery notice-write finding is addressed with a markerless failure-commit fallback and a regression. All required CI checks green; the 'PR must be raised via no-mistakes' template gate is waived under the fork's captain-approved direct-PR delivery for firstmate fixes. Merging.

@twilwa
twilwa merged commit d161786 into main Oct 23, 2026
21 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant