Skip to content

fix: refuse Rex spawns when server locality is unproven - #7810

Merged
kunchenguid merged 2 commits into
mainfrom
fm/fm-rex-remote-server-refuse-p1
Oct 26, 2026
Merged

kunchenguid merged 2 commits into
mainfrom
fm/fm-rex-remote-server-refuse-p1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix 1 from the triage of a user bug report: when firstmate’s Rex backend is pointed at a Rex server running on another machine, refuse right at spawn with a clear message pointing to remote second mates, instead of waiting 60 seconds and failing with a misleading isolated-worktree error.

The user’s report (pasted verbatim): "Setup: Firstmate on a Mac, second mates on a Linux Box, and Rex (rex 0.0.1792878257-g758aab, API 7) running on both. ... Worker spawn on a Linux Rex server fails the worktree check. With REX_SERVER pointed at the Linux host, the Rex adapter opens the tab fine, then fm-spawn.sh#L5599 refuses with "treehouse get did not enter an isolated worktree within 60s"."

Context from the triage: the Rex backend assumes the Rex server runs on the same machine as firstmate. It compares the block’s foreground cwd against local filesystem paths, and bin/backends/rex.sh reads the local process table to find harness processes below a shell foreground, so a Rex server on another host can never give a correct spawn or liveness answer even if the worktree check passed. The supported way to run workers on another machine is a remote second mate (docs/remote-secondmates.md).

What Changed

  • Require a unix:// Rex endpoint for new spawns, rejecting unreadable endpoints and other transports before leasing a worktree or opening a tab.
  • Explain the same-machine requirement and direct users to remote second mates in errors and documentation.
  • Add regression coverage for TCP endpoint rejection and Unix-socket acceptance.

Risk Assessment

✅ Low: The change adds a bounded, conservative spawn check before endpoint creation or worktree leasing, with actionable guidance and no substantiated material defects.

Testing

Targeted adapter tests passed, and live checks demonstrated prompt refusal, actionable guidance, no leftover sessions or task state, and Unix-socket acceptance. The installed API-5 Rex CLI required explicit endpoint forwarding through a wrapper invoking the real CLI; no server responses were mocked. CLI transcripts were captured.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Spawn through a non-Unix endpoint refuses before creating workers ✅ pass live Live transcript: HTTP spawn exited 1 in 0.399 seconds, named the endpoint, and pointed to docs/remote-secondmates.md.
An unreachable endpoint fails closed with useful guidance ✅ pass live Live transcript: unreachable endpoint exited 1 in 0.460 seconds with same-machine and remote-secondmate guidance.
A local Unix socket passes the locality guard ✅ pass live Live transcript: production locality guard returned 0 against the disposable server's Unix socket.
Evidence: Live Rex endpoint validation transcript

Source: Live Rex endpoint validation transcript

## HTTP endpoint refused at spawn
$ bin/fm-spawn.sh rex-remote-proof ~/.no-mistakes/worktrees/016d88035d58/01M5X0Z51MFKRP1AVCTY2K5TEV --scout --harness claude --backend rex
endpoint=http://127.0.0.1:18723
exit=1; elapsed=0.399s
fm-gate-refuse: gate agent lifecycle permitted only against lab home ~/.no-mistakes/worktrees/016d88035d58/01M5X0Z51MFKRP1AVCTY2K5TEV/.live-rex/lab
error: Rex server endpoint 'http://127.0.0.1:18723' is not proven to be on this machine; Rex workers need a Rex server on this machine. For work on another host, use remote second mates (docs/remote-secondmates.md)

## Unreachable endpoint fails closed
$ bin/fm-spawn.sh rex-remote-proof ~/.no-mistakes/worktrees/016d88035d58/01M5X0Z51MFKRP1AVCTY2K5TEV --scout --harness claude --backend rex
endpoint=http://127.0.0.1:18724
exit=1; elapsed=0.460s
fm-gate-refuse: gate agent lifecycle permitted only against lab home ~/.no-mistakes/worktrees/016d88035d58/01M5X0Z51MFKRP1AVCTY2K5TEV/.live-rex/lab
error: could not determine the Rex server endpoint; Rex workers need a Rex server on this machine. For work on another host, use remote second mates (docs/remote-secondmates.md)

## Local Unix endpoint accepted by actual spawn guard
$ bash -c . bin/backends/rex.sh; fm_backend_rex_local_server_ensure; rc=$?; echo "locality guard exit=$rc"; exit "$rc"
endpoint=unix://~/.no-mistakes/worktrees/016d88035d58/01M5X0Z51MFKRP1AVCTY2K5TEV/.live-rex/rex.sock
exit=0; elapsed=0.065s
locality guard exit=0

## Rex inventory after refused spawns
$ ~/.no-mistakes/worktrees/016d88035d58/01M5X0Z51MFKRP1AVCTY2K5TEV/.live-rex/rex ls --json
endpoint=http://127.0.0.1:18723
exit=0; elapsed=0.032s
{
  "sessions": []
}

Lab state entries: []
Lab project entries: []

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Spawn through a non-Unix endpoint refuses before creating workers ✅ pass live Live transcript: HTTP spawn exited 1 in 0.399 seconds, named the endpoint, and pointed to docs/remote-secondmates.md.
An unreachable endpoint fails closed with useful guidance ✅ pass live Live transcript: unreachable endpoint exited 1 in 0.460 seconds with same-machine and remote-secondmate guidance.
A local Unix socket passes the locality guard ✅ pass live Live transcript: production locality guard returned 0 against the disposable server's Unix socket.
  • bash tests/fm-backend-rex.test.sh passed. An initial run with worktree-local TMPDIR hit the existing secondmate-removal safety guard; rerunning with normal temporary storage resolved that setup issue.
  • python3 .live-rex/validate.py drove actual fm-spawn against a disposable Rex HTTP server and an unreachable endpoint, checked refusal timing and cleanup, and exercised the locality guard against its Unix socket.
  • Stopped the disposable Rex server, removed lab files, and confirmed a clean worktree.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid
kunchenguid merged commit 46df160 into main Oct 26, 2026
18 of 19 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-rex-remote-server-refuse-p1 branch October 26, 2026 23:50
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