perf(tmux): prove endpoint existence in one tmux round-trip, not two - #109
Open
ruby-dlee wants to merge 2 commits into
Open
perf(tmux): prove endpoint existence in one tmux round-trip, not two#109ruby-dlee wants to merge 2 commits into
ruby-dlee wants to merge 2 commits into
Conversation
fm_backend_target_exists ran the identity guard and then probed existence
again, so a labelled check cost two tmux invocations where the previous
display-message probe cost one:
before display-message -p -t S:fm-task-x1 '#{pane_id}'
after has-session -t '=S:=fm-task-x1' AND has-session -t S:fm-task-x1
The second probe re-asks a question the first already answered. When the caller
supplies an expectation, the guard RESOLVES the target to prove identity -
exactly for a session:window, and by reading the id back for a @window-id - so
its success is itself the existence proof. With no expectation there is nothing
to verify and the probe is the whole check. Either way it is now one round-trip.
This is a hot path, not an incidental one: fm-teardown.sh's
managed_endpoint_is_gone calls it in a bounded retry loop of up to ten
iterations, so the redundant probe was a doubled process spawn per iteration.
Measured with a counting tmux shim on a live server, labelled session:window
target: 1 invocation before this branch's parent, 2 on it, 1 again with this
change. Behaviour is unchanged - the closed-window/bogus-target control passes
with no failures and tests/fm-backend-tmux-target-exists.test.sh stays 14/14.
Dropping the redundant second probe means a labelled existence check is now
proven ONLY by the identity guard's exact-match resolve ("=session:=window").
Real tmux treats that spelling and the plain one identically - both fail once
the window is killed - but two fixtures were distinguishing them, so they
reported a killed endpoint as still alive and secondmate teardown refused with
"endpoint is still alive; refusing child cleanup".
tests/secondmate-helpers.sh matches the probe target literally against its
kill-window log, so it now normalises the "=" markers before comparing.
fm-teardown-suite.sh's dotted-id registry-lock case modelled a LIVE endpoint
while asserting that teardown succeeds. It only passed because the stub's
list-windows answers with a hardcoded fm-task-x1, which never matched that
task's fm-foo.bar window, so the bare-name lookup missed it whatever the live
marker said. The case is about registry locking and a secondmate teardown
legitimately requires a quiesced endpoint, so it now models one with the same
`rm -f fakebin/.tmux-live` idiom the rest of the suite uses.
Verified: fm-secondmate-lifecycle-e2e 6, fm-secondmate-safety 70,
fm-backlog-handoff 9, and the isolated dotted-id case all pass.
ruby-dlee
force-pushed
the
fm/tmux-probe-single-roundtrip
branch
from
August 8, 2026 13:37
3c1f4a0 to
aa71d59
Compare
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.
Single-purpose follow-up to #108. One function, one behaviour-neutral change.
What
fm_backend_target_existsran the identity guard and then probed existence again, so a labelled check cost two tmux invocations where the olddisplay-messageprobe cost one. Measured with a countingtmuxshim against a live server, for a labelledsession:windowtarget:fm_backend_target_existsdisplay-message -p -t S:fm-task-x1 '#{pane_id}'has-session -t '=S:=fm-task-x1'andhas-session -t S:fm-task-x1has-session -t '=S:=fm-task-x1'The second probe re-asks a question the first already answered. When the caller supplies an expectation, the guard resolves the target in order to prove identity — exactly for a
session:window, and by reading the id back for a@window-id— so its success is the existence proof. With no expectation there is nothing to verify and the probe is the whole check. Either way it is now one round-trip.Why this is worth a PR rather than a footnote
This is a hot path.
bin/fm-teardown.sh'smanaged_endpoint_is_gonecalls it in a bounded retry loop of up to ten iterations, so the redundant probe was a doubled process spawn per iteration, per task, on every teardown.Process count on this path is not a theoretical cost right now. A separate
fm_run_boundeddefect had been leaking its perl supervisor — 345 orphaned processes were cleared tonight, the oldest over thirty hours — and that leak was breakinggh-axiandfm-crosscheckoutright by pushing a process-argv inventory past its bound. Spawn pressure on the existence path is the same resource that took three tools down. Halving it in a retry loop is worth more than the diff size suggests.Behaviour is unchanged
The point of #108 was that a gone window must be detected as gone. That contract is re-verified here, not assumed:
session:window,session:window.pane,@window-id,%pane-idand bare selectors) passes with 0 failures.tests/fm-backend-tmux-target-exists.test.shstays 14/14, including the closed-window lifecycle, exact-vs-prefix resolution, agent liveness, kill idempotency, and the assertion that the existence primitive never usesdisplay-message.fm-crew-state63,fm-secondmate-liveness16,fm-session-start17,fm-send-strict23,fm-fleet-snapshot-view13 — all green locally.bin/fm-lint.shclean.tests/fm-backend.test.shstops locally atfm-spawn.sh should succeed for a project reached through a symlinked prefix…withcheckout-refresh LaunchAgent namespaces cannot be safely enumerated. That reproduces identically on unmodifiedorigin/mainon this host and is a host LaunchAgent-plist condition, not this change.How the redundancy was found
Not by reading the diff — it is invisible there. It surfaced while investigating a timing-sensitive teardown test, by counting actual tmux invocations at runtime with a shim. Worth noting for anyone reviewing similar guard/probe pairs.
PR must be raised via no-mistakesfails by construction and is not a gate for this repo's own work per the repo owner.