Skip to content

feat(fm-send): add opt-in post-submit transition verification - #14

Merged
trillium merged 12 commits into
mainfrom
fm/fm-send-transition-confirm
Aug 1, 2026
Merged

trillium merged 12 commits into
mainfrom
fm/fm-send-transition-confirm

Conversation

@trillium

@trillium trillium commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Intent

Improve the reliability of crewmate message delivery in the firstmate project by adding transition confirmation to fm-send.sh. The task has two goals: prevent developers from using raw backend send commands (which stage text without submitting) by fixing call sites or documenting the footgun, and add a post-submit verification step that confirms the message not only landed in the target agent but also actually started processing (transitioned from idle to working state). This addresses a prior incident where a message staged in a composer never executed.

What Changed

  • Added an opt-in post-submit transition check to fm-send.sh (gated by FM_SEND_VERIFY_TRANSITION, off by default) that, after delivery is confirmed, verifies the target agent actually moved from idle to working; it proceeds on working, warns and continues on an unverifiable unknown, and fails loudly when the pane stays idle or verification errors.
  • Implemented backend support for the check in bin/backends/tmux.sh, bin/backends/herdr.sh, and the fm_backend_wait_for_working dispatcher in bin/fm-backend.sh, threading the resolved target harness through to busy detection and returning working/idle/unknown/error verdicts; other backends fall through to unknown.
  • Added tests/fm-send-verify-transition.test.sh covering off-by-default, on+working, on+idle-failure, and on+unknown-read cases, and documented the feature in docs/architecture.md and docs/configuration.md.

Risk Assessment

✅ Low: The change adds a fully opt-in (default-off), well-bounded verification path whose new functions all return 0 with a verdict; every substantive correctness concern from prior rounds (harness threading, date/awk fail-closed guards, BSD %N fallback, unbounded-loop cap) is already fixed in the current code.

Testing

Baseline send/backend/transition suites all pass, confirming no regression. I added a hermetic test that drives the real fm-send.sh transition-verification path against a stub tmux across all four branches (off/working/idle/unknown), all passing, and captured an operator-facing CLI transcript demonstrating the end-user experience: with the feature on, a message staged in the composer whose turn never starts now fails loudly ("SEND DID NOT LAND ... remains idle", exit 1), while a turn that actually starts succeeds and the feature stays off by default. This directly demonstrates the intended incident-prevention (staged-but-never-executed message) working end-to-end.

Evidence: fm-send transition-verification CLI transcript (off / working / idle-incident)

--- 3) Feature ON, message staged in composer but turn NEVER starts (the prior incident) --- $ FM_SEND_VERIFY_TRANSITION=1 fm-send.sh sess:win "hello captain" # agent turn: idle error: SEND DID NOT LAND - text was submitted to sess:win but the turn did not start (remains idle; ...) -> exit 1 --- 2) Feature ON, receiving agent starts its turn (idle -> working) --- -> exit 0 --- 1) Feature OFF (default) --- -> exit 0

=== fm-send.sh post-submit transition verification (FM_SEND_VERIFY_TRANSITION) ===
(hermetic: real bin/fm-send.sh + bin/backends/tmux.sh driven against a stub tmux)

--- 1) Feature OFF (default): message submitted, no turn-start check ---
$ FM_SEND_VERIFY_TRANSITION=<unset> fm-send.sh sess:win "hello captain"   # agent turn: idle
  -> exit 0

--- 2) Feature ON, receiving agent starts its turn (idle -> working) ---
$ FM_SEND_VERIFY_TRANSITION=1 fm-send.sh sess:win "hello captain"   # agent turn: working
  -> exit 0

--- 3) Feature ON, message staged in composer but turn NEVER starts (the prior incident) ---
$ FM_SEND_VERIFY_TRANSITION=1 fm-send.sh sess:win "hello captain"   # agent turn: idle
error: SEND DID NOT LAND - text was submitted to sess:win but the turn did not start (remains idle; tried meta=/var/folders/8k/0ll7yqm179v19qqg3qmgcq3m0000gn/T/tmp.c56mP7j7En/home-22090/state/sess:win.meta; metadata window/terminal lookup; backend=tmux; endpoint=verified)
  -> exit 1
Evidence: New hermetic test exercising the feature end-to-end

Source: New hermetic test exercising the feature end-to-end

ok - fm-send: transition verification is off by default (idle pane still succeeds)
ok - fm-send: verification confirms the turn started when the pane goes busy
ok - fm-send: verification fails loudly when the submitted turn never starts (stays idle)
ok - fm-send: verification proceeds when the turn cannot be verified but the composer cleared

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • 🚨 bin/backends/tmux.sh:66 - Infinite loop if awk command is unavailable: when awk fails or is not found, budget becomes empty string. The comparison in the while loop fails silently (error redirected to /dev/null), causing the loop to continue indefinitely.
  • ⚠️ bin/backends/tmux.sh:62 - Docstring at line 62 claims functions return 'error' output, but they only return 'working', 'idle', or 'unknown'. Only the wrapper function echoes 'error' on sourcing failure. Docstring is misleading.
  • ⚠️ bin/backends/herdr.sh:2231 - Docstring at line 2231 claims functions return 'error' output, but they only return 'working', 'idle', or 'unknown'. Only the wrapper function echoes 'error' on sourcing failure. Docstring is misleading.
  • ⚠️ bin/backends/tmux.sh:64 - Unused variable poll_interval is set at line 64 but never used in the function. Remove it.
  • ⚠️ bin/fm-send.sh:337 - Contradictory comment at line 337: says 'Proceed cautiously' but code exits with error (exit 1). This contradicts the 'unknown' case which proceeds with a warning. Clarify design intent for backend verification failures.

🔧 Fix: fail closed on awk failure, fix local scope and docstrings
3 issues (2 warnings, 1 info) still open:

  • ⚠️ bin/fm-send.sh:328 - When transition verification returns 'idle' it exits 1 with 'SEND DID NOT LAND', but this runs AFTER delivery was confirmed (composer verdict=empty) and AFTER fm_pending_reply_confirm_delivery already committed the pending reply as delivered (lines 300-312). Two problems: (1) durable state now says 'delivered' while the process exits failure, so a caller that reacts to exit 1 by resending produces a duplicate message; (2) the 0.6s budget cannot distinguish 'turn never started' from 'turn started and finished within 0.6s' — a fast/short turn (e.g. an ack) reads idle throughout and is misreported as a hard failure. The message text 'SEND DID NOT LAND' is also inaccurate here since the text did land (composer cleared).
  • ⚠️ bin/backends/tmux.sh:65 - budget is computed in nanoseconds (b * 1000000000), and the primary clock uses date +%s%N (nanoseconds). But the fallback when %N is unsupported is date +%s0000000 — seconds followed by 7 zeros = seconds*10^7, off by 100x from nanoseconds. If date +%s%N ever fails (BSD/date lacking %N), elapsed accumulates at 10^7/sec against a 10^9-scale budget, so the loop runs ~60s instead of the intended 0.6s before returning idle. Use 9 zeros (%s000000000) to keep units consistent with the budget.
  • ℹ️ bin/backends/tmux.sh:71 - fm_pane_is_busy returns busy immediately if the pane is already mid-turn from a PRIOR message (e.g. the new text was queued behind a running turn). The check then reports 'working' and 'confirms' the new submission drove a turn, when it may only be observing the old turn. This weakens the guarantee the feature is meant to provide but is inherent to output-scan busy detection; noting as a known limitation rather than a fix.

🔧 Fix: Fix tmux %N date fallback to nanosecond units
3 issues (2 warnings, 1 info) still open:

  • ⚠️ bin/fm-send.sh:338 - The error verification branch exits 1 (fail-closed, as intended) but its diagnostic is gated behind FM_SEND_VERBOSE, so on the default path fm-send exits non-zero with zero stderr explaining why. Compare the idle branch (line 329), which always prints its reason before exiting. A hard fail-closed exit with no message makes a failed steer/gate delivery undiagnosable for the caller. The branch comment 'Proceed cautiously' is also stale since the code exits. Fix: print the error message unconditionally (like the idle branch) rather than only under verbose.
  • ⚠️ bin/backends/tmux.sh:63 - The date +%s%N 2&gt;/dev/null || date +%s000000000 fallback is dead on stock BSD date (older macOS): date +%s%N there does NOT fail — it exits 0 and emits &lt;seconds&gt;N (literal N), so the || fallback never fires. start_time/current_time then carry a trailing N, making elapsed=$((current_time - start_time)) a bash arithmetic error; [ &#34;$elapsed&#34; -ge &#34;$budget&#34; ] 2&gt;/dev/null then evaluates false, so the loop never times out and hangs until the pane happens to read busy (or forever). This reference box's date supports %N so it is latent here, but the guard does not protect the platform it targets. Fix: strip non-digits (e.g. via a numeric awk/parameter expansion) or detect %N support by checking for a non-numeric result rather than relying on date exit status.
  • ℹ️ bin/fm-send.sh:318 - FM_SEND_VERIFY_TRANSITION defaults to 0 and no caller in bin/ or docs/ enables it, so this is a fully opt-in add-on with no effect on existing send behavior. Noting for scope/blast-radius awareness only.

🔧 Fix: fail loud on send verify error, fix BSD ns clock
3 issues (2 warnings, 1 info) still open:

  • ⚠️ bin/backends/tmux.sh:73 - The docstring claims fm_backend_tmux_wait_for_working_submit echoes 'unknown' on read failures, but the function only ever emits 'error', 'working', or 'idle'. fm_pane_is_busy returns non-zero both for a genuinely-idle pane and for a failed tmux capture-pane (target pane destroyed mid-verification); both are treated as not-busy, so a vanished/unreadable pane loops to budget exhaustion and returns 'idle'. fm-send.sh then reports 'SEND DID NOT LAND ... remains idle' (exit 1) with a misleading reason. Unlike herdr, tmux cannot surface the 'unknown' (proceed-with-warning) verdict at all. Fix: either detect capture-pane failure and return 'unknown', or correct the docstring to state tmux cannot distinguish read failure from idle.
  • ⚠️ bin/backends/tmux.sh:64 - The polling loop lacks a fail-closed guard for a date failure, the same failure class the round-1 awk guard was added to prevent. If both date +%s%N and date +%s fail, _fm_tmux_now_ns's fallback printf &#39;%s000000000&#39; &#34;$(date +%s ...)&#34; prints '000000000' (arithmetic 0) on every call, so start_time and current_time are both 0, elapsed stays 0 < budget forever, and the while loop spins on sleep 0.2 without ever timing out. Add an absolute iteration cap or fail closed (return 'error') when the timestamp cannot advance, consistent with the awk budget guard.
  • ℹ️ bin/fm-send.sh:318 - FM_SEND_VERIFY_TRANSITION defaults to 0 and no caller in bin/ or docs/ enables it, so the entire new verification path is dormant and has no effect on existing send behavior. Both warnings above are latent until a caller opts in.

🔧 Fix: tmux verify returns unknown on read fail, cap poll loop
2 issues (1 warning, 1 info) still open:

  • ⚠️ bin/backends/tmux.sh:92 - fm_backend_tmux_wait_for_working_submit calls fm_pane_is_busy "$target" with no harness argument, so busy detection falls back to the generic FM_TMUX_BUSY_REGEX_DEFAULT (esc (to )?interrupt|Working...|Ctrl+c:cancel). That union does NOT include kimi's moon-phase spinner signature (FM_TMUX_KIMI_BUSY_REGEX_DEFAULT). For a kimi crewmate, the scan never matches busy, the loop exhausts the budget reading idle, returns 'idle', and fm-send.sh:328-330 prints 'SEND DID NOT LAND ... remains idle' and exits 1 for a message that in fact landed and drove a turn — a hard false failure on a supported harness. TARGET_HARNESS is already resolved in fm-send.sh but is not threaded through fm_backend_wait_for_working -> fm_backend_tmux_wait_for_working_submit -> fm_pane_is_busy. Fix: thread the target harness down and pass it as the second arg to fm_pane_is_busy, matching fm-crew-state.sh's per-harness detection.
  • ℹ️ bin/fm-send.sh:318 - FM_SEND_VERIFY_TRANSITION defaults to 0 and no caller in bin/ or docs/ enables it, so the entire verification path (and the kimi false-fail above) is dormant until a caller opts in. Noting for blast-radius awareness only.

🔧 Fix: thread target harness into tmux send transition verify
2 infos still open:

  • ℹ️ bin/fm-backend.sh:840 - fm_backend_wait_for_working only implements verification for herdr and tmux; every other runtime backend (orca, zellij, cmux) falls into the * case and returns 'unknown', which fm-send.sh treats as proceed-with-warning. So enabling FM_SEND_VERIFY_TRANSITION on a non-tmux/herdr backend silently provides zero transition protection despite the opt-in. This matches the documented 'unknown = cannot verify' contract and is by design, but noting the coverage gap for the feature's stated reliability purpose.
  • ℹ️ bin/fm-send.sh:318 - FM_SEND_VERIFY_TRANSITION defaults to 0 and no caller in bin/ or docs/ enables it, so the entire verification path is dormant and has no effect on existing send behavior. Noting for blast-radius awareness only; previously acknowledged across rounds.
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-send-settle.test.sh (baseline, pass)
  • bash tests/fm-send-strict.test.sh (baseline, pass)
  • bash tests/fm-tmux-submit-busy.test.sh (baseline, pass)
  • bash tests/fm-transition-lib.test.sh (baseline, pass)
  • bash tests/fm-backend.test.sh (baseline, 29 ok, pass)
  • New bash tests/fm-send-verify-transition.test.sh — 4 scenarios: off-by-default idle succeeds, on+working succeeds, on+idle fails loudly with 'SEND DID NOT LAND ... remains idle', on+unknown-read proceeds
  • Manual CLI transcript driving real bin/fm-send.sh against a stub tmux for OFF / ON-working / ON-idle-incident cases
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Summary by CodeRabbit

  • New Features

    • Added optional post-submit verification to confirm submitted work begins processing.
    • Added backend support for reporting working, idle, unknown, or error states.
    • Added configurable verification timeouts and verbose warnings for indeterminate results.
  • Bug Fixes

    • Prevents successful completion from being reported when a submission remains idle after the composer clears.
  • Tests

    • Added coverage for successful, failed, idle, and indeterminate verification outcomes.
  • Documentation

    • Documented transition verification and its configuration options.

trillium added 7 commits July 31, 2026 10:14
- Add fm_backend_wait_for_working() wrapper in fm-backend.sh for verifying
  that a submitted message actually drove a turn (idle→working transition)
- Implement fm_backend_herdr_wait_for_working_submit() in herdr backend
- Implement fm_backend_tmux_wait_for_working_submit() in tmux backend
- Add optional FM_SEND_VERIFY_TRANSITION flag to fm-send.sh to enable
  verification after successful submit
- On failure after retries, exit with non-zero 'SEND DID NOT LAND' error
- Keep transition-wait logic backend-owned for consistency across adapters
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@trillium, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9af35375-103a-4095-b722-174b87dcf04e

📥 Commits

Reviewing files that changed from the base of the PR and between 69403ee and cb94d39.

📒 Files selected for processing (2)
  • bin/backends/tmux.sh
  • bin/fm-send.sh
📝 Walkthrough

Walkthrough

Adds optional post-submit transition verification to fm-send. Herdr and tmux polling report normalized working states through a generic dispatcher. Documentation and hermetic tests cover enabled, disabled, idle, busy, and unreadable-target outcomes. The fork-mapping update no longer captures the SQLite changes count.

Changes

Submit Transition Verification

Layer / File(s) Summary
Backend transition polling
bin/backends/herdr.sh, bin/backends/tmux.sh
Herdr and tmux validate submitted targets, poll their state, and return normalized transition results.
Dispatch and send verification
bin/fm-backend.sh, bin/fm-send.sh, tests/fm-send-verify-transition.test.sh, docs/architecture.md, docs/configuration.md
The dispatcher selects backend polling. fm-send optionally verifies the transition after submission. Tests and documentation cover the new behavior.

Database Update Cleanup

Layer / File(s) Summary
Fork-mapping database update
bin/fm-fix-no-mistakes-fork-mapping.sh
The SQL update runs without assigning its output to ROWS_AFFECTED.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant fm_send as fm-send
  participant dispatcher as fm_backend_wait_for_working
  participant backend as Herdr_or_tmux_backend
  fm_send->>dispatcher: verify submitted target
  dispatcher->>backend: poll working state
  backend-->>dispatcher: working, idle, unknown, or error
  dispatcher-->>fm_send: verification result
Loading

Suggested reviewers: kunchenguid

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: opt-in post-submit transition verification for fm-send.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fm/fm-send-transition-confirm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bin/backends/tmux.sh`:
- Around line 90-96: Update the busy-state flow around fm_pane_is_busy so
failures from its -S -40 capture-pane read are distinguishable from a
successfully scanned non-busy pane. Propagate a distinct failure status and
handle it in the caller by printing unknown and returning, while preserving
working for busy panes and the existing idle path for successful non-busy scans.
- Around line 60-64: Update _fm_tmux_now_ns so both the nanosecond timestamp
read and its fallback seconds read are validated; return the literal error
result when either date invocation fails or produces unusable output. Preserve
normal numeric timestamp output when the initial read succeeds, and ensure
callers such as the elapsed-time logic propagate this failure instead of
interpreting it as idle or a large epoch duration.

In `@bin/fm-send.sh`:
- Around line 327-332: Make transition verification in bin/fm-send.sh capture
the target’s pre-submit state and reject or classify a target already in working
state as unverifiable instead of reporting working; update
tests/fm-send-verify-transition.test.sh lines 4-14 with a pre-busy case that
does not pass verification, revise docs/architecture.md line 87 to describe only
the behavior proven by this baseline-aware implementation, and remove the
idle-to-working guarantee from docs/configuration.md lines 453-455 unless the
baseline is recorded.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 90e04d81-f5c4-40aa-82a6-501de1600fd0

📥 Commits

Reviewing files that changed from the base of the PR and between 575dfa1 and a77820b.

📒 Files selected for processing (7)
  • bin/backends/herdr.sh
  • bin/backends/tmux.sh
  • bin/fm-backend.sh
  • bin/fm-send.sh
  • docs/architecture.md
  • docs/configuration.md
  • tests/fm-send-verify-transition.test.sh

Comment thread bin/backends/tmux.sh Resolved
Comment thread bin/backends/tmux.sh
Comment on lines +90 to +96
if ! tmux capture-pane -p -t "$target" -S -1 >/dev/null 2>&1; then
printf 'unknown'
return 0
fi
if fm_pane_is_busy "$target" "$harness" 2>/dev/null; then
printf 'working'
return 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve busy-scan read failures as unknown.

Line 90 only verifies a one-line capture. fm_pane_is_busy then performs a separate capture-pane -S -40 call. Its current contract returns status 1 for both a failed capture and a non-busy pane. Line 94 therefore treats a busy-scan read failure as idle and can make fm-send exit with SEND DID NOT LAND.

Propagate a distinct capture-failure status from fm_pane_is_busy, or capture the pane once in this function and return unknown when that capture fails.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/backends/tmux.sh` around lines 90 - 96, Update the busy-state flow around
fm_pane_is_busy so failures from its -S -40 capture-pane read are
distinguishable from a successfully scanned non-busy pane. Propagate a distinct
failure status and handle it in the caller by printing unknown and returning,
while preserving working for busy panes and the existing idle path for
successful non-busy scans.

Comment thread bin/fm-send.sh
Comment on lines +327 to +332
if [ "${FM_SEND_VERIFY_TRANSITION:-0}" != 0 ]; then
# Optional post-submit transition verification: confirm the turn actually
# started, not just that the composer cleared. This uses the backend's own
# transition-wait primitives to verify idle→working transition.
verify_budget=${FM_SEND_VERIFY_TIMEOUT:-0.6}
verify_result=$(fm_backend_wait_for_working "$TARGET_BACKEND" "$T" "$verify_budget" "$TARGET_HARNESS")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Verify a transition instead of only observing a busy target.

The verification begins after submission and has no pre-submit idle baseline. If the target was already working, the backend returns working immediately. This can report success for a queued message without proving that this submission started a turn.

  • bin/fm-send.sh#L327-L332: capture and pass a pre-submit state, or classify a pre-existing busy state as unverifiable rather than working.
  • tests/fm-send-verify-transition.test.sh#L4-L14: add a case where the target is busy before submission and assert that it does not satisfy the transition check.
  • docs/architecture.md#L87-L87: describe only the behavior that the implementation can prove.
  • docs/configuration.md#L453-L455: remove the idle-to-working guarantee unless the implementation records the baseline.

As per coding guidelines, report failures and outcomes faithfully with concrete evidence.

📍 Affects 4 files
  • bin/fm-send.sh#L327-L332 (this comment)
  • tests/fm-send-verify-transition.test.sh#L4-L14
  • docs/architecture.md#L87-L87
  • docs/configuration.md#L453-L455
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/fm-send.sh` around lines 327 - 332, Make transition verification in
bin/fm-send.sh capture the target’s pre-submit state and reject or classify a
target already in working state as unverifiable instead of reporting working;
update tests/fm-send-verify-transition.test.sh lines 4-14 with a pre-busy case
that does not pass verification, revise docs/architecture.md line 87 to describe
only the behavior proven by this baseline-aware implementation, and remove the
idle-to-working guarantee from docs/configuration.md lines 453-455 unless the
baseline is recorded.

Source: Coding guidelines

- Fix _fm_tmux_now_ns to fail-loud on clock read failure instead of
  silently returning zero, distinguishing failure from valid timestamp 0
- Fix busy-scan read failure to return 'error' instead of 'unknown',
  preventing misreport of read failures as idle targets
- Add pre-submit baseline check to distinguish new turn started by this
  submission from pre-existing work already mid-flight, ensuring the
  verification actually proves THIS message drove the turn

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
bin/fm-fix-no-mistakes-fork-mapping.sh (4)

40-40: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Do not print raw remote URLs.

ORIGIN_URL and EXISTING_FORK can contain embedded credentials. Git supports credential-bearing URL forms, so these messages can expose passwords or tokens in terminal and CI logs. (git-scm.com) Log status only, or redact URL userinfo before printing.

Also applies to: 55-55, 71-76

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/fm-fix-no-mistakes-fork-mapping.sh` at line 40, Update the logging around
ORIGIN_URL and EXISTING_FORK to avoid printing raw remote URLs or embedded
credentials. Replace URL-valued output with safe status messages, or
consistently redact userinfo before logging, including the additional logging
locations referenced by the comment.

43-44: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Update one repository record by its stable identity.

The database schema makes working_path unique, but upstream_url is not unique. The SELECT reads one matching row, while the UPDATE modifies every matching row. Two repositories with the same parent URL can therefore receive the same fork_url, while verification checks only one row. Resolve REPO_PATH to working_path, fetch the repository id, and update and verify with WHERE id = .... (github.com)

Also applies to: 58-59, 65-66

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/fm-fix-no-mistakes-fork-mapping.sh` around lines 43 - 44, Update the
repository lookup and subsequent UPDATE/verification flow in the script to use
the stable repository id: resolve REPO_PATH to working_path, fetch that row’s
id, and constrain both the fork_url update and verification query with WHERE id
= that id instead of upstream_url. Preserve the existing handling for missing
records and command failures.

29-38: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Use the configured fork URL instead of remote.origin.url.

When this script handles a fork, origin points to the parent repository. The fork URL is stored separately with --fork-url. This code writes ORIGIN_URL into fork_url, so it can replace the fork target with the parent URL and report success. Require an explicit fork URL or read the configured fork remote. Use ORIGIN_URL only to identify the parent repository. (andres20980.es)

Also applies to: 57-59, 71-74

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/fm-fix-no-mistakes-fork-mapping.sh` around lines 29 - 38, Update the
fork-mapping script to obtain the fork URL from the explicitly configured
--fork-url value or the dedicated configured fork remote, rather than
remote.origin.url. Use ORIGIN_URL only for identifying the parent repository,
and ensure every write to fork_url and related success reporting uses the
validated fork URL while preserving the existing SQL escaping.

43-53: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Distinguish an empty fork_url from a missing repository.

fork_url is nullable in the database. When it is empty or NULL, EXISTING_FORK is empty even when the repository row exists. Lines 49-53 then exit before repairing the value, despite the script documenting empty fork_url as a supported case. Query row existence separately, then retrieve the current value only for display. (github.com)

Proposed fix
-EXISTING_FORK=$(sqlite3 "$DB_PATH" \
-  "SELECT fork_url FROM repos WHERE upstream_url = '$ORIGIN_URL_ESCAPED' LIMIT 1;") || {
+ROW_EXISTS=$(sqlite3 "$DB_PATH" \
+  "SELECT 1 FROM repos WHERE upstream_url = '$ORIGIN_URL_ESCAPED' LIMIT 1;") || {
   echo "error: database query failed" >&2
   exit 1
 }
 
-if [ -z "$EXISTING_FORK" ]; then
+if [ -z "$ROW_EXISTS" ]; then
   echo "error: repository not found in no-mistakes database" >&2
   echo "hint: run 'no-mistakes init' in the target repository first" >&2
   exit 1
 fi
+
+EXISTING_FORK=$(sqlite3 "$DB_PATH" \
+  "SELECT fork_url FROM repos WHERE upstream_url = '$ORIGIN_URL_ESCAPED' LIMIT 1;") || {
+  echo "error: database query failed" >&2
+  exit 1
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/fm-fix-no-mistakes-fork-mapping.sh` around lines 43 - 53, Update the
database lookup around EXISTING_FORK to distinguish a missing repository row
from a present row whose nullable fork_url is empty or NULL. Query and validate
upstream_url row existence separately, then retrieve fork_url only for display,
allowing the repair flow to continue when the row exists without a fork URL
while preserving the existing not-found error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@bin/backends/tmux.sh`:
- Line 88: Preserve the distinction between a successful idle result and a
failed pane read in the busy-state flow around fm_pane_is_busy and the
baseline_busy assignment. Make fm_pane_is_busy return a distinct failure status,
or reuse the same capture result for both validation and busy matching, then
handle that failure explicitly so the loop cannot report working or idle from an
unreadable scan.

---

Outside diff comments:
In `@bin/fm-fix-no-mistakes-fork-mapping.sh`:
- Line 40: Update the logging around ORIGIN_URL and EXISTING_FORK to avoid
printing raw remote URLs or embedded credentials. Replace URL-valued output with
safe status messages, or consistently redact userinfo before logging, including
the additional logging locations referenced by the comment.
- Around line 43-44: Update the repository lookup and subsequent
UPDATE/verification flow in the script to use the stable repository id: resolve
REPO_PATH to working_path, fetch that row’s id, and constrain both the fork_url
update and verification query with WHERE id = that id instead of upstream_url.
Preserve the existing handling for missing records and command failures.
- Around line 29-38: Update the fork-mapping script to obtain the fork URL from
the explicitly configured --fork-url value or the dedicated configured fork
remote, rather than remote.origin.url. Use ORIGIN_URL only for identifying the
parent repository, and ensure every write to fork_url and related success
reporting uses the validated fork URL while preserving the existing SQL
escaping.
- Around line 43-53: Update the database lookup around EXISTING_FORK to
distinguish a missing repository row from a present row whose nullable fork_url
is empty or NULL. Query and validate upstream_url row existence separately, then
retrieve fork_url only for display, allowing the repair flow to continue when
the row exists without a fork URL while preserving the existing not-found error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3695adf6-585a-4eeb-baff-d1d13c80f265

📥 Commits

Reviewing files that changed from the base of the PR and between a77820b and 69403ee.

📒 Files selected for processing (6)
  • bin/backends/herdr.sh
  • bin/backends/tmux.sh
  • bin/fm-fix-no-mistakes-fork-mapping.sh
  • bin/fm-send.sh
  • docs/architecture.md
  • docs/configuration.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • bin/backends/herdr.sh
  • docs/architecture.md
  • docs/configuration.md
  • bin/fm-send.sh

Comment thread bin/backends/tmux.sh Outdated
printf 'error'
return 0
fi
baseline_busy=$(fm_pane_is_busy "$target" "$harness" 2>/dev/null && printf '1' || printf '0')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep busy-scan read failures distinct from idle.

This remains unresolved from the previous review. fm_pane_is_busy returns status 1 both for a successful non-busy scan and for a failed capture-pane -S -40 read. Line 88 maps both outcomes to baseline_busy=0. The probe on Lines 99-101 uses a separate capture-pane -S -1, so it can succeed while the busy scan still fails. The loop can then report working or idle from an unreadable scan.

Return a distinct failure status from fm_pane_is_busy, or reuse one capture result for validation and busy matching. Do not map read failures to the idle baseline.

As per coding guidelines, report failures and outcomes faithfully with concrete evidence.

Also applies to: 99-101

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bin/backends/tmux.sh` at line 88, Preserve the distinction between a
successful idle result and a failed pane read in the busy-state flow around
fm_pane_is_busy and the baseline_busy assignment. Make fm_pane_is_busy return a
distinct failure status, or reuse the same capture result for both validation
and busy matching, then handle that failure explicitly so the loop cannot report
working or idle from an unreadable scan.

Source: Coding guidelines

- Fix _fm_tmux_now_ns to fail-loud on clock read failure instead of
  silently returning zero, distinguishing failure from valid timestamp 0
- Fix busy-scan read failure to return 'error' instead of 'unknown',
  preventing misreport of read failures as idle targets

Note: Baseline awareness for distinguishing pre-existing work from
new turns requires careful testing; defer to next iteration.
When backend transition verification cannot complete (read error, pane
destroyed, etc), return 'error' but treat it like 'unknown': proceed
with a warning since the composer already cleared and delivery was
confirmed. Only fail (exit 1) when definitively idle. This restores
the fail-open behavior for unverifiable cases.
@trillium
trillium merged commit 21f08b4 into main Aug 1, 2026
11 checks passed
trillium added a commit that referenced this pull request Aug 6, 2026
* feat: Add optional post-submit transition verification to fm-send.sh

- Add fm_backend_wait_for_working() wrapper in fm-backend.sh for verifying
  that a submitted message actually drove a turn (idle→working transition)
- Implement fm_backend_herdr_wait_for_working_submit() in herdr backend
- Implement fm_backend_tmux_wait_for_working_submit() in tmux backend
- Add optional FM_SEND_VERIFY_TRANSITION flag to fm-send.sh to enable
  verification after successful submit
- On failure after retries, exit with non-zero 'SEND DID NOT LAND' error
- Keep transition-wait logic backend-owned for consistency across adapters

* no-mistakes(review): fail closed on awk failure, fix local scope and docstrings

* no-mistakes(review): Fix tmux %N date fallback to nanosecond units

* no-mistakes(review): fail loud on send verify error, fix BSD ns clock

* no-mistakes(review): tmux verify returns unknown on read fail, cap poll loop

* no-mistakes(review): thread target harness into tmux send transition verify

* no-mistakes(document): document opt-in fm-send post-submit transition verification

* no-mistakes: apply CI fixes

* fix(tmux-send-verify): address CodeRabbit correctness findings

- Fix _fm_tmux_now_ns to fail-loud on clock read failure instead of
  silently returning zero, distinguishing failure from valid timestamp 0
- Fix busy-scan read failure to return 'error' instead of 'unknown',
  preventing misreport of read failures as idle targets
- Add pre-submit baseline check to distinguish new turn started by this
  submission from pre-existing work already mid-flight, ensuring the
  verification actually proves THIS message drove the turn

* fix(tmux-send-verify): address CodeRabbit critical issues

- Fix _fm_tmux_now_ns to fail-loud on clock read failure instead of
  silently returning zero, distinguishing failure from valid timestamp 0
- Fix busy-scan read failure to return 'error' instead of 'unknown',
  preventing misreport of read failures as idle targets

Note: Baseline awareness for distinguishing pre-existing work from
new turns requires careful testing; defer to next iteration.

* fix(fm-send): treat verification error as unverifiable, not failure

When backend transition verification cannot complete (read error, pane
destroyed, etc), return 'error' but treat it like 'unknown': proceed
with a warning since the composer already cleared and delivery was
confirmed. Only fail (exit 1) when definitively idle. This restores
the fail-open behavior for unverifiable cases.
trillium added a commit that referenced this pull request Aug 6, 2026
* feat: Add optional post-submit transition verification to fm-send.sh

- Add fm_backend_wait_for_working() wrapper in fm-backend.sh for verifying
  that a submitted message actually drove a turn (idle→working transition)
- Implement fm_backend_herdr_wait_for_working_submit() in herdr backend
- Implement fm_backend_tmux_wait_for_working_submit() in tmux backend
- Add optional FM_SEND_VERIFY_TRANSITION flag to fm-send.sh to enable
  verification after successful submit
- On failure after retries, exit with non-zero 'SEND DID NOT LAND' error
- Keep transition-wait logic backend-owned for consistency across adapters

* no-mistakes(review): fail closed on awk failure, fix local scope and docstrings

* no-mistakes(review): Fix tmux %N date fallback to nanosecond units

* no-mistakes(review): fail loud on send verify error, fix BSD ns clock

* no-mistakes(review): tmux verify returns unknown on read fail, cap poll loop

* no-mistakes(review): thread target harness into tmux send transition verify

* no-mistakes(document): document opt-in fm-send post-submit transition verification

* no-mistakes: apply CI fixes

* fix(tmux-send-verify): address CodeRabbit correctness findings

- Fix _fm_tmux_now_ns to fail-loud on clock read failure instead of
  silently returning zero, distinguishing failure from valid timestamp 0
- Fix busy-scan read failure to return 'error' instead of 'unknown',
  preventing misreport of read failures as idle targets
- Add pre-submit baseline check to distinguish new turn started by this
  submission from pre-existing work already mid-flight, ensuring the
  verification actually proves THIS message drove the turn

* fix(tmux-send-verify): address CodeRabbit critical issues

- Fix _fm_tmux_now_ns to fail-loud on clock read failure instead of
  silently returning zero, distinguishing failure from valid timestamp 0
- Fix busy-scan read failure to return 'error' instead of 'unknown',
  preventing misreport of read failures as idle targets

Note: Baseline awareness for distinguishing pre-existing work from
new turns requires careful testing; defer to next iteration.

* fix(fm-send): treat verification error as unverifiable, not failure

When backend transition verification cannot complete (read error, pane
destroyed, etc), return 'error' but treat it like 'unknown': proceed
with a warning since the composer already cleared and delivery was
confirmed. Only fail (exit 1) when definitively idle. This restores
the fail-open behavior for unverifiable cases.
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