Repository navigation
fix(cmux): route label-gated ops through the id resolver for renamed secondmate workspaces - #23
Merged
Merged
Conversation
…secondmate workspaces A captain-renamed secondmate workspace broke every label-gated operation (fm-send, fm-peek, fm-crew-state, and the bootstrap liveness sweep's agent_alive probe): fm_backend_cmux_target_ready required the workspace or surface title to equal the generated scoped title, but PR #22 made secondmate workspace titles free-form, and the agent's own terminal-title updates overwrite the scoped tab title too, so both title rungs missed even though fm_backend_cmux_secondmate_resolve returned the correct endpoint. target_ready now detects a kind=secondmate meta behind the expected label and delegates identity to the resolver (recorded ids, synced recorded title, scoped tab title, home-cwd fingerprint, loud ambiguity refusal), adopting only the resolved endpoint - never the caller's unverified target. Ordinary task targets keep the scoped-title gate unchanged. Verified live 2026-07-28 against cmux 0.64.20 (build 100) and the fleet's two renamed mates, read-only with scratch meta copies: unpatched target_ready rc 1 / agent_alive unknown; patched target_ready resolves the recorded endpoint, agent_alive reads alive, capture returns real pane content. Full real-app smoke suite passes on the patched adapter. Claude-Session: https://claude.ai/code/session_016YqtswHeV9YSLAJVLyk5gs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix a live-found bug in the cmux secondmate support merged in PR #22 (commit d17bf3c): a captain-renamed secondmate workspace broke every label-gated operation. fm-send, fm-peek, fm-crew-state, and the bootstrap secondmate liveness sweep's agent_alive probe all pass the expected label fm- into fm_backend_cmux_target_ready, which required the workspace title (or a surface title) to equal the generated scoped title fm--. PR #22 made SECONDMATE workspace titles free-form (captain may retitle at will) with id-primary identity plus synced-title recovery, but did not thread that through target_ready - and in the live fleet the agents' own terminal-title escape sequences had overwritten the scoped TAB titles too, so both title rungs missed and every op refused the mate's own live endpoint even though fm_backend_cmux_secondmate_resolve returned it correctly (rc 0). The fix, per the task brief: for secondmate targets, trust the identity the resolver establishes instead of the scoped-title gate. target_ready now detects a kind=secondmate meta behind the expected label via a new helper fm_backend_cmux_secondmate_meta_for_label (same state-dir resolution as the callers: FM_STATE_OVERRIDE, else FM_HOME/state) and delegates to fm_backend_cmux_secondmate_resolve, adopting ONLY the resolved endpoint - never the caller's unverified target - preserving the anti-misroute property, loud ambiguity refusal (rc 3), and the resolver's designed meta title re-sync side effect on every liveness touch. Ordinary task targets keep the existing scoped-title gate completely unchanged; a non-secondmate meta never relaxes it. Deliberate choices: the fix is at the single target_ready funnel point so one change covers send/peek/capture/crew-state/agent_alive and the bootstrap sweep; the brief explicitly required keeping it minimal and not redesigning the resolver or touching other backends. The helper reads the task meta with fm_meta_get, an existing dependency of this file (fm_backend_cmux_secondmate_resolve already uses it). Comment updates: target_ready and create_secondmate headers document the secondmate delegation. Tests: 5 new colocated regression tests in tests/fm-backend-cmux.test.sh using the existing stateful fake cmux CLI (renamed-workspace send+capture routing by id, relaunch-stale target re-resolve with meta re-record, confident alive AND dead agent_alive for a renamed mate, ambiguity still refusing loudly with unknown liveness, and ordinary-task gating unchanged even when a kind=crew meta exists). All were confirmed to fail on the unpatched adapter. docs/cmux-backend.md gained a dated live-verification record (2026-07-28, cmux 0.64.20 build 100): read-only evidence against the fleet's two real renamed mates using scratch meta copies (unpatched: target_ready rc 1, agent_alive unknown; patched: resolves the recorded endpoint, alive, real pane content), plus the full real-app smoke suite passing. Known pre-existing unrelated failure: tests/fm-bootstrap.test.sh's 'treehouse --lease support is accepted silently' fails identically on clean HEAD in this environment (MISSING: cmux line) - not introduced by this change. Repo rules followed: firstmate-coding-guidelines loaded (one sentence per line in markdown, plain dashes, no agent co-author, shellcheck via bin/fm-lint.sh clean, colocated tests extending the existing suite).
What Changed
fm_backend_cmux_target_readynow detects akind=secondmatemeta behind the expectedfm-<id>label (via a newfm_backend_cmux_secondmate_meta_for_labelhelper using the sameFM_STATE_OVERRIDE/FM_HOME/stateresolution as callers) and delegates tofm_backend_cmux_secondmate_resolve, adopting only the resolved endpoint — so send, peek, capture, crew-state, and the bootstrap liveness sweep's agent_alive probe reach a captain-renamed mate's live endpoint instead of refusing when the scoped-title gate misses; ordinary task targets keep the existing scoped-title gate unchanged and ambiguity still refuses loudly (rc 3).target_readyandcreate_secondmateheaders, and added a dated live-verification record (2026-07-28, cmux 0.64.20) todocs/cmux-backend.md.tests/fm-backend-cmux.test.shcovering renamed-workspace routing by id, stale-target re-resolution with meta re-record, confident alive/dead agent_alive for a renamed mate, loud ambiguity refusal, and the unchanged ordinary-task gate — all confirmed to fail against the unpatched adapter.Risk Assessment
✅ Low: The change is a tightly-scoped, single-funnel fix that faithfully implements the stated intent with matching state-dir resolution, preserved anti-misroute/ambiguity semantics, and colocated regression tests; the only note is a benign scope-delta on two additional funnel callers.
Testing
Baseline full-file run of tests/fm-backend-cmux.test.sh aborts on a pre-existing composer-ghost failure that is unrelated to this change (the diff touches no composer code; it fails identically on base d17bf3c), so I exercised the 5 new secondmate regression tests in isolation and ran them differentially against both the patched (9862158) and unpatched (d17bf3c) cmux adapters. The 4 renamed-mate routing tests fail on the unpatched adapter and pass on the patched one, while the ordinary-task-gate negative control passes on both — demonstrating, at the CLI-adapter product surface, that send/capture/agent_alive now route to a captain-renamed secondmate's own resolved endpoint via the id-primary resolver while the scoped-title gate for ordinary tasks stays intact. This is a shell/CLI backend change with no rendered UI, so the reviewer-visible artifact is the before/after adapter-behavior transcript rather than a screenshot. Worktree left clean; temporary driver files removed.
Evidence: cmux secondmate routing — patched vs unpatched before/after transcript
########## PATCHED (target 9862158) adapter ########## PASS>> test_secondmate_send_peek_route_by_id_after_rename PASS>> test_secondmate_send_recovers_stale_target_after_rename PASS>> test_secondmate_agent_alive_confident_after_rename PASS>> test_secondmate_ops_ambiguous_still_refuses PASS>> test_ordinary_task_gate_unchanged_by_meta_presence ########## UNPATCHED (base d17bf3c) adapter ########## FAIL>> test_secondmate_send_peek_route_by_id_after_rename FAIL>> test_secondmate_send_recovers_stale_target_after_rename FAIL>> test_secondmate_agent_alive_confident_after_rename FAIL>> test_secondmate_ops_ambiguous_still_refuses PASS>> test_ordinary_task_gate_unchanged_by_meta_presence Reading: the 4 renamed-mate routing tests FAIL on the unpatched adapter and PASS on the patched one. The ordinary-task-gate test PASSES on both (negative control): the scoped-title gate is unchanged.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/backends/cmux.sh:771- The secondmate delegation is placed at the shared fm_backend_cmux_target_ready funnel, but that funnel is also called with an expected label by fm_backend_cmux_kill (bin/backends/cmux.sh:1160, reached from fm-teardown.sh:1023 for cmux secondmate children) and fm_backend_cmux_current_path (bin/backends/cmux.sh:871). The intent states the fix 'covers send/peek/capture/crew-state/agent_alive and the bootstrap sweep' and does not mention these two. Concrete effect: forced teardown of a renamed, live secondmate now resolves the endpoint and the generic kill closes the mate's agent tab plus adds a throwaway surface (task_owned=0 because the free-form title never matches the scoped title), whereas before the scoped-title gate missed and kill was a no-op. This appears neutral-to-beneficial (teardown actually kills the agent now; the whole workspace still isn't closed in either case), and current_path delegation is benign, so this is not a proven regression - but the behavior of these unlisted paths did change and is worth confirming as intended.tests/fm-backend-cmux.test.sh:801- Running the whole tests/fm-backend-cmux.test.sh aborts early because fail() calls exit 1 and the unrelated pre-existing test 'test_composer_state_ghost_placeholder_is_empty' fails (reads 'pending' instead of 'empty'). It fails identically on the base commit d17bf3c and this change touches no composer code, so it does not affect the new secondmate tests, which I ran in isolation. Flagging so a full-file run's red result is not mistaken for a regression from this change.bash tests/fm-backend-cmux.test.sh— full file (aborts early on a pre-existing, unrelated composer-ghost failure)Isolated run of the 5 new tests against the PATCHED adapter (9862158): all 5 PASS (test_secondmate_send_peek_route_by_id_after_rename,test_secondmate_send_recovers_stale_target_after_rename,test_secondmate_agent_alive_confident_after_rename,test_secondmate_ops_ambiguous_still_refuses,test_ordinary_task_gate_unchanged_by_meta_presence)Same 5 tests against the UNPATCHED adapter (base d17bf3c swapped in): the 4 renamed-mate routing tests FAIL, the ordinary-task-gate control PASSES — confirming the bug and the fixConfirmed the composer-ghost placeholder failure is pre-existing (fails identically on base) and untouched by this diff✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.