Skip to content

fix(bin): make tmux target_exists answer from exact membership, not the active window - #2903

Open
harmeet-1337 wants to merge 4 commits into
kunchenguid:mainfrom
harmeet-1337:fm/fm-fix-tmuxexists
Open

fix(bin): make tmux target_exists answer from exact membership, not the active window#2903
harmeet-1337 wants to merge 4 commits into
kunchenguid:mainfrom
harmeet-1337:fm/fm-fix-tmuxexists

Conversation

@harmeet-1337

Copy link
Copy Markdown

Summary

Fixes audit finding F-S02-1 (P0, reproduced defect): fm_backend_target_exists reported ABSENT tmux windows and sessions as present. Its tmux display-message -p -t <target> probe answers from the client's active window whenever any tmux server is running, so every consumer that treats the result as authoritative (session-start fleet digest, fm-busy-lib, fm-fleet-snapshot, the away-mode daemon's %N supervisor-target validation, fm-control, fm-send) could read a dead endpoint as alive.

Change

  • fm_backend_target_exists is now a pure per-backend dispatcher, matching its fm_backend_composer_state / fm_backend_agent_state siblings, so no presence answer is derived inline.
  • tmux: new fm_backend_tmux_target_exists using exact-match tmux list-panes. A session:window endpoint is anchored =sess:=win so a prefix cannot match (firstmate:fm-task never matches fm-task-2); bare %N/@N pane/window ids are queried directly. Never starts a server.
  • herdr: the former inline arm, moved verbatim into fm_backend_herdr_target_exists (direct pane read, no server-ensure side effect).
  • zellij/cmux: thin aliases over their existing target_ready; orca: a one-line capture probe.
  • fm_backend_tmux_agent_state's three-way missing/unreadable/present membership check is deliberately left untouched.
  • No call-site changes.
  • Remote-secondmate digest guard: because remote secondmate records use window=remote:<id> with no backend= key (defaulting to tmux), the corrected exact-match probe would otherwise flip their session-start digest line from falsely "alive" to falsely "dead". The fleet digest now special-cases window=remote:* and prints a distinct non-locally-probed line instead of running a local existence probe, since a remote:<id> window can never match a local backend's shape.

Tests

  • Real-tmux smoke test gains absent-window, absent-session, absent-%N, and prefix-collision cases.
  • Session-start and the shared daemon/watcher fakes model list-panes at parity with the old presence read; the fm-send-strict tmux stub is updated likewise.
  • bin/fm-lint.sh is clean (ShellCheck 0.11.0 + actionlint 1.7.12, both pinned).

Delivery note

The account has read-only access to the upstream repository, so the branch is delivered from the fork harmeet-1337/firstmate. Every commit on the branch is in scope — the original fix plus the pipeline's own in-scope review/test/document gate-fix commits (the approved remote-secondmate guard, the fm-send-strict stub update, and documentation/comment corrections). No out-of-scope tooling commit was injected, so none was excluded.

…he active window

fm_backend_target_exists reported an absent tmux window or session as present:
its `tmux display-message -p -t <target>` probe answers from the client's
active window whenever any tmux server is running, so every consumer that
treats the result as authoritative (the session-start fleet digest, fm-busy-lib,
fm-fleet-snapshot, the away-mode daemon's supervisor-target validation,
fm-control, fm-send) could read a dead endpoint as alive.

Make fm_backend_target_exists a pure per-backend dispatcher, like its
composer_state/agent_state siblings, and give each adapter its own
fm_backend_<backend>_target_exists:

- tmux: an exact-match `tmux list-panes` probe. A session:window endpoint is
  anchored `=sess:=win` so a prefix cannot match (firstmate:fm-task never
  matches fm-task-2); bare %N/@n pane/window ids are queried directly. Never
  starts a server.
- herdr: the former inline arm, moved verbatim (direct pane read, no
  server-ensure side effect).
- zellij/cmux: thin aliases over their existing target_ready.
- orca: a one-line capture probe.

No call sites change. Tests: the session-start fake tmux now models list-panes;
the tmux smoke test gains absent-window, absent-session, absent-%N, and
prefix-collision cases against a real server; shared daemon/watcher fakes gain a
list-panes case at parity with their old display-message presence read.
@greptile-apps

greptile-apps Bot commented Aug 23, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code failure identified.

The new dispatcher preserves prior non-tmux backend behavior, while tmux now checks exact target membership and the remote digest guard follows the repository’s established remote-endpoint contract.

Reviews (1): Last reviewed commit: "no-mistakes(document): document exact-me..." | Re-trigger Greptile

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