Skip to content

fix(spawn): pin tmux session targets with exact-match form - #184

Closed
staneja15 wants to merge 4 commits into
kunchenguid:mainfrom
staneja15:fm/fm-spawn-numeric-session-r3
Closed

staneja15 wants to merge 4 commits into
kunchenguid:mainfrom
staneja15:fm/fm-spawn-numeric-session-r3

Conversation

@staneja15

@staneja15 staneja15 commented Jul 2, 2026 •

Copy link
Copy Markdown

Intent

Fix a tmux target-ambiguity bug: a numeric tmux session name (e.g. a session literally named 7) passed as a bare -t target resolves as a window index of the current session, landing the crewmate window in an unrelated session or colliding with an occupied index. Pin session targets with tmux's exact-match form (=SES: / =firstmate) in the tmux backend, and add an end-to-end regression test with a numeric session so spawns land in the intended session with no collision.

What Changed

  • Pin tmux session targets to the exact-match form (=firstmate in container-ensure, =<session>: in create-task's list-windows/new-window) in bin/backends/tmux.sh, so a numeric session name (a session literally named 7) is no longer misread by -t as a window index of the current session — which previously landed the crewmate window in an unrelated session or failed on an occupied index.
  • Add explanatory comments in bin/fm-spawn.sh and the tmux backend documenting the exact-match targeting rationale.
  • Add an end-to-end regression test (tests/fm-spawn-tmux-target.test.sh) covering a spawn into a session named 7 with an occupied index 7 and no leak into a decoy session, plus the outside-tmux path still targeting firstmate; extend tests/fm-backend.test.sh, pin an rc-free bash and pane PATH for CI, and list the new test in CONTRIBUTING.md.

Risk Assessment

✅ Low: A tightly-scoped, correct fix that pins only the two bare session-target tmux calls that were misparsing numeric session names, backed by an end-to-end regression test and documentation, with no other unpinned session targets and no functional risk to the safe colon-qualified pane targets.

Testing

The configured baseline suite already ran green; I ran the smallest relevant set for this change — the new e2e regression test tests/fm-spawn-tmux-target.test.sh and the two touched backend suites — all pass. I also captured a manual before/after transcript on a live tmux server showing the bare numeric target failing with index 7 in use while the exact-match =7: form correctly lands the window in the session named 7. The full 25-test e2e suite exceeded the 2-minute tool timeout but is unrelated to this change and covered by the baseline. This is a CLI/tooling change with no UI surface, so CLI transcripts are the appropriate reviewer-visible evidence.

Evidence: tmux target ambiguity: before/after demo on live tmux server

Current session: 7 (indices 0-7 in use) OLD: bare '-t 7' -> FAILED: create window failed: index 7 in use NEW: exact '=7:' -> SUCCESS: window created in session 7, 0 leak into decoy 'other'

### Reproducing the tmux target-ambiguity bug and the exact-match fix ###
tmux 3.4

Current session on server: 7  (window indices in use: 0 1 2 3 4 5 6 7 )

--- OLD behavior: bare '-t 7' (session name misread as window index of current session) ---
FAILED as expected: create window failed: index 7 in use

--- NEW behavior: exact-match '=7:' pins the session named 7 ---
SUCCESS: window 'newexact' created in session 7
session 7 windows now: bash bash bash bash bash bash bash bash newexact 
did it leak into decoy 'other'? -> 0 matches
Evidence: end-to-end regression test transcript

ok - raw tmux: bare numeric -t collides with a window index; exact form '=7:' pins the session ok - fm-spawn in a session named '7' lands its window in session 7 despite occupied index 7 ok - fm-spawn outside tmux still creates and targets the dedicated 'firstmate' session all fm-spawn tmux target tests passed

### End-to-end regression test: tests/fm-spawn-tmux-target.test.sh ###
(fm-spawn run against a real tmux server whose current session is literally named '7' with index 7 occupied)

ok - raw tmux: bare numeric -t collides with a window index; exact form '=7:' pins the session
ok - fm-spawn in a session named '7' lands its window in session 7 despite occupied index 7
ok - fm-spawn outside tmux still creates and targets the dedicated 'firstmate' session
all fm-spawn tmux target tests passed
EXIT=0
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (16m28s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"

🔧 Fix: test(backend): pin rc-free bash for tmux smoke test
✅ Re-checked - no issues remain.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • bash tests/fm-spawn-tmux-target.test.sh — e2e: fm-spawn lands in a session literally named 7 (index 7 occupied) with no leak into decoy session; outside-tmux path still targets firstmate
  • bash tests/fm-backend.test.sh — backend selector/send/spawn/teardown byte-identical old vs new
  • bash tests/fm-backend-tmux-smoke.test.sh — real-tmux create_task/send/capture/kill
  • Manual live-tmux demo: bare -t 7 fails with index 7 in use; exact =7: form lands the window in session 7 with no decoy leak
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@staneja15 staneja15 closed this Jul 2, 2026
@staneja15 staneja15 reopened this Jul 2, 2026
@staneja15
staneja15 force-pushed the fm/fm-spawn-numeric-session-r3 branch from c1e5999 to 2a07372 Compare July 2, 2026 05:11
@kunchenguid

Copy link
Copy Markdown
Owner

Thanks for the PR! It looks like this branch has a merge conflict with the base branch right now. When you get a chance, could you rebase onto (or merge in) the latest base branch, resolve the conflict, and push? Once GitHub shows the PR as mergeable again, it'll be picked back up for review.

Noted for firstmate#184 at 2a073728.

staneja15 added 4 commits July 3, 2026 10:00
tmux parses a bare token passed to -t ambiguously: a numeric session
name (a captain session literally named "7") resolves as a window INDEX
of the current session, so `new-window -t "$SES"` landed the crewmate
window in an unrelated session or failed on an occupied index
(observed 2026-07-01, tmux 3.4; worked around at the call site with
`env -u TMUX`).

fm-spawn now targets sessions with tmux's exact-match form: `-t "=$SES:"`
('=' pins exact-name matching, trailing ':' pins session interpretation)
for list-windows and new-window, and `has-session -t '=firstmate'`.
Both forms verified against tmux 3.4.

Audit of every other `tmux ... -t` in bin/ (fm-send, fm-peek,
fm-crew-state, fm-teardown, fm-watch, fm-tmux-lib, fm-supervise-daemon):
all receive session:window strings from meta window= (or pane ids), and
the ':' already forces session interpretation of the left part with
exact-name match winning, so they are unambiguous and unchanged. The
recorded window= meta format is unchanged.

Regression test runs fm-spawn end to end on a private tmux server with
a session named "7" whose window index 7 is occupied: the window must
land in session 7 with no collision, the outside-tmux dedicated-session
path must keep working, and the raw bare-target ambiguity is documented
so a future tmux behavior change surfaces loudly.
The numeric-session e2e test drove fm-spawn against a real tmux server
and relied on the tmux server inheriting PANEBIN through its environment
so a typed `treehouse get` would hit the fake. That is fragile: it
passed locally only because a real `treehouse` on PATH masked the
missing fake, and failed in CI (no treehouse installed) with fm-spawn
timing out after 60s waiting for a worktree handoff that never happened.

Pin PANEBIN onto every pane's PATH explicitly via tmux default-command
instead of inheriting it, and add a fail-fast probe that verifies a pane
resolves the fake treehouse before the spawn cases run, so a
misconfigured world reports a clear message instead of a 60s timeout.
Verified passing both with a real treehouse present and with it hidden
from PATH (the CI condition).
@staneja15
staneja15 force-pushed the fm/fm-spawn-numeric-session-r3 branch from 2a07372 to 4ef6702 Compare July 3, 2026 00:04
@staneja15

Copy link
Copy Markdown
Author

Rebased onto the latest base branch and resolved the conflict (main had refactored the tmux calls into bin/backends/tmux.sh and added the runtime-backend interface; the exact-match session-target fix now lives in that adapter, with the calling-side comment taken from main). Force-pushed the rebased branch. The full test suite passes locally against the current base. Should be mergeable again shortly.

@kunchenguid

kunchenguid commented Jul 10, 2026 •

Copy link
Copy Markdown
Owner

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#184 at 4ef67020.

@staneja15 staneja15 closed this Jul 16, 2026
fritznoff pushed a commit to fritznoff/starship that referenced this pull request Nov 2, 2026
…ding (kunchenguid#184)

* test(fixtures): add a stand-in portal for browser staging proofs

Browser staging work needs a target that can prove the negative property:
a staging run fills and verifies a device configuration form but never
submits it. Doing that against a real portal is not possible - it would
mean a live device interaction - and a mock inside a test cannot exercise
real browser mechanics.

This fixture is a deliberately generic stand-in. Field names are opaque
(device id, setting A, setting B); it describes no vendor's actual form,
wire format, units, or device rules, and is not a source for any of them.
It exposes window.__readback() so a run can verify the page really holds
the values it believes it set, and keeps window.__submitted false with
#submit-state reading not-submitted so "never submitted" is checkable
rather than asserted.

* test(fixtures): model preset/textarea/send shape in the stand-in portal

Passive inspection of a real device-command surface found a control shape
the first fixture did not model: preset buttons that populate one shared
command textarea, with a separate send control alongside them.

That shape carries the hazard worth testing. A preset button is safe only
if its handler does nothing but fill the textarea, and nothing about the
label, the position, or the element type reveals which kind it is - only
the handler does. So a staging path has to determine that before clicking,
and refuse when it cannot.

The fixture now carries both variants, identical except for the handler:
one fills only, one fills and sends. The unsafe one exists so the refusal
branch can be tested against a control that really does send, rather than
only against controls that happen to be harmless. window.__sendCount makes
a duplicate send visible instead of merely absent.

Names and payloads stay opaque: no real form, wire format, unit, command
or device rule is described here.

* test(fixtures): drop the fixture's tells and take the target from context

Passive observation of a real device-command surface settled two details
the fixture had guessed at, and it was guessing in its own favour.

Presets there are type="button" with no title, aria-label, aria-description
or aria-describedby, and button type alone establishes nothing about
behaviour. The fixture's unsafe preset had a danger class that a staging
run could have keyed on, which would have let an implementation pass here
and fail on a surface that offers no such tell. Both presets now carry the
same attributes as each other and as the real ones.

The real surface also adds the device identifier automatically rather than
carrying it in the payload, so a wrong target is a navigation error and not
a payload error. The fixture now takes its target from page context so that
failure mode can actually be exercised.

* test(fixtures): separate a preset's static default from reported state

Evidence from a real surface: a preset filled two configuration fields on
a device whose model does not expose those fields at all. A value cannot
be read back from a field that does not exist, so what a preset writes is
a static default belonging to the preset - written identically whether or
not the target supports it - and not a readback of the target's state.

That makes a specific mistake available: reading the box after a fill and
reporting it as what the target currently holds. On a device that lacks
the fields, that report is simply false.

The fixture now carries a reported state that differs from the preset
default and may be absent, and __readback() returns command, reported
state and preset default as three distinct values, so a test can assert an
implementation never conflates them.

* test(fixtures): give reported telemetry an age and an unavailable state

A configured setting and a reported measurement are different quantities
with different encodings, and a measurement can undershoot the setting it
relates to. Treating a configured bound as evidence about physical state
is a mistake this fixture should be able to catch.

Reported telemetry here now carries a timestamp, because a measurement
without its age is not evidence. Unavailable is modelled as a third state
distinct from present-and-empty, so an absent measurement cannot be
rendered as though it were a reading - the preview prints an explicit
"not a reading" instead of a blank.

__readback() exposes the measurement, its age and its availability as
separate values, so a test can assert a preview never shows a reading
without its age and never turns unknown into a value.

* test(fixtures): publish navigation readiness apart from the payload

A real navigation command timed out after 10s while the tab it created was
already sitting at the requested URL. The acknowledgement failed; the
navigation had not. Recovering from that by navigating again produces two
tabs, and the same reflex applied one phase later produces two commands.

So readiness is now published as its own marker rather than inferred from
the navigation call returning, and ?slow=<ms> delays it so an ambiguous
load can be exercised deliberately. An implementation that answers a slow
load with a second navigation fails here; one that inspects for the marker
succeeds.

This is the distinction the fixture existed to support and did not yet
model: navigation ambiguity is resolvable by inspection because a tab at a
URL is the same artifact however many navigations produced it. Effect
ambiguity is not, and keeps its own rule.

* feat(bin): stage and verify device configuration commands without sending

Preparing a device configuration change is the part worth doing carefully:
resolving the target, encoding values correctly, rendering the exact
payload, and proving the form holds what was intended. None of that has to
risk anything. Only the final send does, and it stays with a person.

So this delivers preparation as its own capability, stopping one step
short of any outward effect.

fm-fota-stage.py turns an adapter definition plus requested values into a
reviewable plan. Encodings are declared per key and refused unless also
confirmed, because a wrong encoding yields a plausible number that means
something else. Every emitted value carries the name of the rule that
produced it, so a setting rule and a measurement rule cannot be silently
interchanged on one device. Eligibility comes from observed rows for that
specific target: a model prefix is necessary at most, and a control being
offered in a portal is no evidence at all. Policy validation stays
separate from physical safety, and no plan claims the latter.

Operation identity is computed apart from the gateway digest. The digest
binds one approval to one preview and includes a nonce, so re-preparing
one intent yields a different digest - which makes it the wrong thing to
deduplicate on. Identity covers what makes two requests the same
operation, with a deliberate retry raising a visible attempt ordinal.

fm-fota-stage-run.sh runs preparation in the background and settles one of
four states. ready requires an independent readback matching the plan; a
result asserting success with nothing read back settles unknown. unknown
is not failure - it means the outcome was not observed, which differs from
observing that nothing happened, so it directs a person to verify rather
than retrying anything.

The generated request asks for one authoritative readback. A redundant
second check can time out on its own and turn a completed preparation into
a misleading failure, manufacturing exactly the ambiguity this avoids.

Gateway changes are confined to two corrections this relies on: every
device.* kind now carries a non-graduatable device ceiling, so a device
action cannot be graduated out of per-change approval and device.config.push
stops reporting the messaging ceiling it was mislabelled with; and
expires_at is capped per severity, since a caller-chosen expiry could mint
an approval window that never went stale.

Execution stays unwired. Nothing here sends, approves, or retries a send.

* feat(bin): surface device staging runs on the existing Action Deck

Preparation that only exists in a plan file and a run record is not
exposed to the person who has to act on it. The deck is where work
waiting on the captain already lives, so staging belongs there rather
than behind a second surface.

Each state renders in the section that already owns it. A ready run is
waiting on his approval, so it is staged. A pending run is moving and
waiting on nobody, so it is under way. An error or unknown run needs a
person to look, so it is a need - and unknown is placed there precisely
because it is not a failure: the outcome was never observed, so the row
says to verify at the portal before retrying anything.

No new section, no new page, no new endpoint. The collector gains one
source and the renderer routes it through the builders it already has.

Two things the pane must not do. It must not report nothing staged above
a staged row, so the counts strip includes staging runs. And it must not
let unverified eligibility live only in a plan file nobody opens, so a
staged run says so on the pane itself.

A home with no staging runs emits no such section and renders exactly as
before; an unreadable section costs only itself and invents no row.

* no-mistakes(review): wire queue transport and fix staging run defects

* no-mistakes(review): bind acknowledgement to its outcome; harden queue start

* no-mistakes(review): dedent generated request; pin run-id clock for tests

* no-mistakes(test): register new FOTA staging suites in CI lanes and fork surface

* no-mistakes(test): refuse undeclared telemetry encodings and unresolvable staging origins

* fix(fork-surface): record the staging surface as pre-merge

The entry pinned a branch commit, and rebasing onto main rewrote that
SHA, so the declared-surface check failed with the commit no longer an
ancestor of the checked-out history.

Pinning a SHA for work that has not landed is fragile by construction:
every rebase orphans it again. The file already has a convention for
this case, used by the other unlanded entries, and the check's own error
message points at it. Use that instead, and the entry stays correct
until there is a real merge commit to record.

* fix(tests): detect the stat flavour by platform, and classify the new doc

Two CI failures, both from this branch.

The request-permission test picked its stat flavour by trying the BSD
form and falling back on failure. That fallback never fires on GNU
coreutils, where -f means filesystem status, accepts a file argument
quite happily, and succeeds - so the mode variable captured filesystem
output and the assertion compared a File: line against 600. Switch on
uname instead, which is what the rest of the repo already does, so the
flavour is chosen rather than guessed from an exit status that does not
distinguish the two.

The new staging contract was missing from the documentation audience
inventory. It is classified alongside the gateway architecture doc it
complements and links to, rather than as a setup target, since README
does not route setup through it.

* fix(fork-surface): restore both entries after the rebase collision

Main and this branch each added a new capability entry at the same
place, so the merge fused them: the second entry lost its [capability]
header and read as duplicate keys in the first, and the shared trailing
context carried the first entry's topology line onto the second.

Both entries are independent additions, so both are kept, with the
header and the topology line put back where they belong.

This branch also no longer modifies the shared test runner - the earlier
rebase adopted main's version, which enumerates the test directory
directly - so that declaration is dropped rather than left asserting a
change the branch does not make.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants