Skip to content

fix(tmux): re-anchor composer state off the agent input row so the away-mode daemon delivers escalations - #980

Closed
sandersjdd3 wants to merge 2 commits into
kunchenguid:mainfrom
sandersjdd3:fm/afk-daemon-composer-wedge-fix
Closed

sandersjdd3 wants to merge 2 commits into
kunchenguid:mainfrom
sandersjdd3:fm/afk-daemon-composer-wedge-fix

Conversation

@sandersjdd3

Copy link
Copy Markdown

Intent

Fix an away-mode supervision daemon bug: while the captain was afk ~15h (2026-07-23 19:50 to 2026-07-24 05:41), the daemon buffered every escalation and delivered none (2471 deferred injects, zero deliveries), leaving the captain blind to a review decision. Root cause: fm_tmux_composer_state (bin/fm-tmux-lib.sh) reads composer emptiness off tmux's single #{cursor_y} row. A pristine, never-typed-into claude/codex composer renders its input row inside a rule-bordered box (top rule / bare prompt-glyph row / bottom rule), and tmux's cursor_y points one row BELOW the prompt-glyph input row, at the box's bottom rule. Reading only that single cursor row, the box-drawing rule glyphs classified as pending, so the injector read firstmate's OWN idle composer as pending input and deferred 100% of escalations. This is the 'Residual gap, tmux-only' cursor-row off-by-one previously documented as unfixed in the harness-adapters skill. Fix: when the cursor row is a pure horizontal rule (only light or heavy rule glyphs, detected by new helper fm_tmux_row_is_rule), widen to a small row window around cursor_y and re-anchor on the adjacent genuine agent-composer input row (a row whose trimmed content starts with the agent prompt glyph). Deliberate safety decisions: re-anchoring is agent-prompt-glyph-only and never latches a bare shell prompt, so injection is never forced into a dead shell; if no agent input row is found the cursor row is kept and the verdict defers safely; the fix only ever turns a rule-masked EMPTY composer back into empty while real unsubmitted text still reads pending and a dead shell / unreadable pane still reads unknown. The injection safety guard was deliberately NOT weakened (unknown is never treated as empty) and target auto-discovery was deliberately left unchanged (firstmate:0 fallback was correct; the bug was purely composer misclassification). Refactored the classification body into fm_tmux_classify_raw_row so the re-anchor path can reuse it; the change is in the shared tmux owner so the away-mode injector, fm-send, and the always-on watcher all benefit. The shared content classifier (bin/fm-composer-lib.sh) was intentionally untouched because the bug was row SELECTION, not content classification. Verified tmux-path-scoped: herdr locates its composer structurally (not by cursor_y), orca/cmux/zellij have no cursor-row composer primitive. Added 5 regression cases to tests/fm-composer-ghost.test.sh (a multi-row box fixture), including the wedge repro that fails against the pre-fix single-row classifier and passes after; updated docs/tmux-backend.md with dated repro plus fix evidence; marked the harness-adapters residual-gap note fixed. bin/fm-lint.sh and shellcheck are clean.

What Changed

  • Reworked fm_tmux_composer_state in bin/fm-tmux-lib.sh so a pristine, rule-bordered claude/codex composer box no longer reads as pending input: the classification body was extracted into fm_tmux_classify_raw_row, and when tmux's cursor_y row is a pure horizontal rule (detected by the new fm_tmux_row_is_rule helper), it widens to a small clamped row window and re-anchors on the adjacent genuine agent-composer input row before classifying. Re-anchoring is agent-prompt-glyph-only (never latches a bare shell), operates on the ANSI-stripped row so de-emphasized glyphs still match, and falls back to the original cursor row when no agent input row is found, keeping the injection safety guard intact (unknown is never treated as empty).
  • Added a multi-row box fixture plus 6 re-anchor regression cases to tests/fm-composer-ghost.test.sh, including the wedge repro that fails against the pre-fix single-row classifier and passes after (18/18).
  • Documented the dated repro and fix evidence in docs/tmux-backend.md and marked the previously-unfixed tmux cursor-row residual-gap note as resolved in .agents/skills/harness-adapters/SKILL.md.

Risk Assessment

✅ Low: Well-bounded, tmux-path-scoped composer row-selection fix with a preserved fail-safe (defer/unknown on any doubt), both prior-round findings correctly addressed, and regression tests pinning the fix and its safety envelope.

Testing

Ran the existing colocated regression suite (18/18 pass, 6 new cases pin the fix and its safety envelope) and built a from-scratch end-to-end reproduction that drives the shared tmux classifier through a fake tmux serving the exact overnight-wedge fixture — a pristine agent composer box with cursor_y landing on the box's bottom rule. Against the base commit the idle composer classifies as pending (the injector's defer condition, i.e. the 2471-deferred/0-delivered wedge), and against the fix commit it classifies as empty (safe to inject → escalation delivered), while real unsubmitted text still reads pending and a bare shell prompt near a rule row is never latched. Traced the injector to confirm delivery is gated on this exact verdict. Working tree left clean; all transient repro copies live only in the dedicated evidence directory.

Evidence: End-to-end wedge reproduction transcript (pre-fix vs post-fix + safety scenarios)

Scenario A cursor_y=3 (overnight-wedge shape): PRE-FIX base 10ee779: composer_state = pending -> injector reads OWN idle composer as pending -> DEFERS (15h, 0 delivered) POST-FIX fix af8b591: composer_state = empty -> re-anchors on the input row -> reads empty -> DELIVERS escalation Scenario B cursor_y=2 (on input row): PRE empty / POST empty (no regression) Scenario C real unsubmitted text, cursor_y=3: POST pending (never forced empty) Scenario D rule row above bare shell prompt: POST pending (never latches a dead shell) VERDICT: bug reproduced on base, cured by fix, safety envelope intact.

==================================================================
 Away-mode supervision wedge: end-to-end reproduction + fix proof
 incident afk-daemon-composer-wedge-fix
==================================================================

Fixture rows served by fake tmux (pristine, never-typed claude composer box):
  row 1: ────────   (top rule)
  row 2: ❯          (bare prompt-glyph INPUT row)
  row 3: ────────   (bottom rule)  <-- tmux #{cursor_y} lands HERE (off-by-one)

--- Scenario A: cursor_y=3 (the real overnight-wedge shape) ---
  PRE-FIX  base 10ee779: composer_state = pending  -> injector reads OWN idle composer as pending -> DEFERS (15h, 0 delivered)
  POST-FIX fix  af8b591: composer_state = empty    -> re-anchors on ❯ input row -> reads empty -> DELIVERS escalation

--- Scenario B: cursor_y=2 (correctly on ❯ input row) — no regression ---
  PRE-FIX : empty
  POST-FIX: empty

--- Scenario C: SAFETY — real unsubmitted text in the box, cursor_y=3 ---
  POST-FIX: composer_state = pending  -> real text still reads pending; fix never forces a busy pane empty

--- Scenario D: SAFETY — rule cursor row above a BARE shell prompt ---
  POST-FIX: composer_state = pending  -> ❯-only re-anchor never latches a dead shell; safe defer, no forced inject

==================================================================
VERDICT: bug reproduced on base, cured by fix, safety envelope intact.
==================================================================
Evidence: Regression suite result (fm-composer-ghost.test.sh)
ok - fm_tmux_row_is_rule: only pure horizontal-rule rows are rules
ok - fm_tmux_composer_state: pristine composer box, cursor_y on the bottom rule, reads empty (wedge fix)
ok - fm_tmux_composer_state: composer box, cursor_y on the input row, reads empty (no regression)
ok - fm_tmux_composer_state: real text in a composer box stays pending (cursor on rule OR input row)
ok - fm_tmux_composer_state: pristine composer box, de-emphasised input glyph, re-anchors empty
ok - fm_tmux_composer_state: a rule cursor row never re-anchors onto a bare shell prompt
(18/18 total ok)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-tmux-lib.sh:183 - Re-anchor detects the composer input row by ghost-stripping (fm_composer_strip_ghost, line 183) then requiring a literal ❯/› (line 196), which is STRICTER than the shared classifier it delegates to. fm_composer_classify_content already has a plain_content fallback that treats a de-emphasized (dim SGR-2 or dark-truecolor) ❯/› glyph — ghost-stripped to empty but visible on the ANSI-stripped row — as empty. If any harness renders the pristine input-row glyph de-emphasized (grok draws borders/placeholder as dark truecolor; incident fix(composer): handle ANSI ghost text safely #429 documents claude dimming composer text), the re-anchor's glyph test misses it, the pure-rule cursor row is kept, and the injector defers — reproducing exactly the ~15h escalation blindness this change fixes. Latent, not active: claude/codex glyphs are currently bright (fixture and live repro both use a bright glyph). Suggest matching plain/plain_content by detecting the glyph off the ANSI-stripped (ghost-kept) row; classify_raw_row still makes the final empty/pending decision, so no new over-inject risk beyond the existing 'the glyph never appears in transcript' assumption already relied on.
  • ℹ️ bin/fm-tmux-lib.sh:180 - The re-anchor window start '-S "$((cy - 2))"' goes negative when cursor_y is 0 or 1, which makes tmux capture-pane read scrollback history rows into the anchor window. Harmless in practice — the re-anchor only fires when the cursor row is a pure horizontal rule, which sits at the composer box near the pane bottom (cursor_y large), so a negative start is effectively unreachable — but the start is unclamped.

🔧 Fix: fix(tmux): re-anchor on ANSI-stripped row, clamp window start
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-composer-ghost.test.sh — 18/18 pass including 6 new re-anchor regression cases (fm_tmux_row_is_rule, pristine box cursor-on-bottom-rule reads empty, cursor-on-input-row no regression, real text stays pending, dim/dark-truecolor glyph re-anchors, rule-cursor never latches a bare shell)
  • End-to-end wedge repro: fake tmux serving a pristine claude/codex composer box (top rule / bare ❯ input row / bottom rule) with cursor_y=3; classified with pre-fix (10ee779) and post-fix (af8b591) copies of bin/fm-tmux-lib.sh sourcing the unchanged bin/fm-composer-lib.sh
  • Verified inject_msg in bin/fm-supervise-daemon.sh gates delivery on fm_backend_composer_state == empty (step 3b), confirming the classifier verdict is the actual defer/deliver switch
  • Confirmed bin/fm-composer-lib.sh has no change in the commit range (content classifier intentionally untouched; bug was row selection)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A pristine, never-typed-into claude/codex composer renders its input row
inside a rule-bordered box (─────/❯/─────), and tmux's own #{cursor_y}
points one row below the ❯ input row, at the box's bottom rule. Reading
only that single cursor row, fm_tmux_composer_state saw the box-drawing
rule glyphs as real text and returned pending, so the away-mode escalation
injector read firstmate's OWN idle composer as pending input and deferred
100% of escalations. Incident afk-daemon-composer-wedge-fix: the daemon
ran ~15h (2026-07-23 19:50 → 2026-07-24 05:41), logged 2471 deferred
injects with zero deliveries, and the captain was blind to a review
decision the whole time (escalations were preserved and drained on return).

When the cursor row is a pure horizontal rule (only ─/━ glyphs), widen to
a small row window around cursor_y and re-anchor on the adjacent genuine
agent-composer input row (a row starting with ❯ or ›, which appears only on
the live composer input row). Re-anchoring is ❯/›-only and never latches a
bare shell prompt, so injection is never forced into a dead shell; if no
agent input row is found the cursor row is kept and the verdict defers
safely. The fix only ever turns a rule-masked empty composer back into
empty: real text still reads pending, a dead shell still reads unknown.

The change is in the shared tmux owner (bin/fm-tmux-lib.sh), so the
away-mode injector, fm-send, and the always-on watcher all benefit. The
shared content classifier (bin/fm-composer-lib.sh) is untouched: the bug
was row selection, not content classification. herdr locates its composer
structurally rather than by cursor_y, so the fix is tmux-path-scoped;
orca/cmux/zellij have no cursor-row composer primitive.

- bin/fm-tmux-lib.sh: add fm_tmux_row_is_rule and fm_tmux_classify_raw_row,
  re-anchor in fm_tmux_composer_state.
- tests/fm-composer-ghost.test.sh: multi-row box fixture + 5 cases (wedge
  repro, aligned no-regression, real-text-stays-pending, shell-prompt
  never re-anchored, pure-rule helper). Wedge case fails pre-fix.
- docs/tmux-backend.md: dated repro + fix evidence, cross-backend scope.
- harness-adapters skill: mark the "Residual gap, tmux-only" note fixed.
@sandersjdd3
sandersjdd3 force-pushed the fm/afk-daemon-composer-wedge-fix branch from dd4ca19 to 92cff16 Compare July 24, 2026 19:27
@kunchenguid

kunchenguid commented Jul 26, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#980 at 92cff16f.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: this PR still looks blocked on a rebase or merge conflict fix.

If you are still interested, please rebase onto the current base branch, resolve the conflict, and push.

If I do not hear back, I may close this as inactive.

@kunchenguid kunchenguid removed the wheelhouse:pending-contributor-action Managed by Wheelhouse label Aug 11, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: closing this as stale. It has been waiting on a contributor update for 14+ days with no author push or comment. Reopen if you want to pick it back up.

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.

2 participants