Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cli): stop discarding a dial that connected, and find tmux on a bash machine

0xdiego258c16fe9a1df9
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index 7457f9310..e821456da 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -274,7 +274,10 @@ describe('cable session', () => {
return new LoopbackPort(onData, onClosed)
})
session.start()
- await vi.advanceTimersByTimeAsync(20_000)
+ // Comfortably past OPEN_TIMEOUT_MS plus the reopen tick. It used to advance exactly 20s, which was
+ // fine while the budget was 8s and became a coin toss the moment the budget itself became 20 —
+ // the retry lands after the deadline, not on it.
+ await vi.advanceTimersByTimeAsync(35_000)
expect(attempts).toBeGreaterThan(1)
await session.stop()
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index 5351df7a5..db2dbeb40 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -43,7 +43,25 @@ const REOPEN_EVERY_MS = 2_000
// `stty` against a device that may have just re-enumerated mid-flash; if that call hangs, the dial is
// gone until the daemon is restarted — no error, no retry, no log line saying why. Observed once: the
// link closed at 14:14 and nothing tried again for twelve minutes.
-const OPEN_TIMEOUT_MS = 8_000
+//
+// TWENTY SECONDS, RAISED FROM EIGHT, because eight was under the cost of the thing it was timing.
+// Measured on a dial that had just re-enumerated after a flash — the whole reason this budget mentions
+// re-enumeration in the first place:
+//
+// 22:26:28.077 cannot open the dial: open timed out after 8000ms ← gave up
+// 22:26:29.660 dial 28:84:85:90:5F:78 on fw 0.0.58 proto 3 ← opened, 1.58s late
+// 22:26:29.661 machines → 3 · agents → 8 (attach) ← FULL handshake, succeeded
+// 22:26:29.662 closed (abandoned — open timed out) ← and thrown away
+//
+// The open costs about 9.6s there, every time, so the deadline never once let a working link live: the
+// cycle repeated on an exact 8-second beat for as long as anyone watched, and the dial sat on "Not
+// connected" while the daemon greeted it successfully every eight seconds and hung up on it. That is
+// the worst shape a timeout can take — not a slow failure, a discarded success.
+//
+// The stall this guards against is a `stty` that never returns, which twenty seconds catches as surely
+// as eight. What it costs is the wait after a replug, and the honest number for that is the ~10s the
+// open actually takes, not the 8 it was being given.
+const OPEN_TIMEOUT_MS = 20_000
/** What this dial must call itself. A greeting that does not say exactly this is another product's. */
const CABLE_PRODUCT = 'harness'
diff --git a/cli/src/lib/tmuxOnPath.spec.ts b/cli/src/lib/tmuxOnPath.spec.ts
index 8d4754f05..6ccb24297 100644
--- a/cli/src/lib/tmuxOnPath.spec.ts
+++ b/cli/src/lib/tmuxOnPath.spec.ts
@@ -33,6 +33,23 @@ PATH="${binDir}" exec /bin/sh -c "$@"
return shell
}
+/** A shell that answers ONLY when asked as a login shell — a bash user with PATH in ~/.bash_profile. */
+function loginOnlyShell(binDir: string): string {
+ const dir = scratch('tmux-onpath-login-')
+ const shell = join(dir, 'bash')
+ writeFileSync(shell, `#!/bin/sh
+# The daemon asks bash with '-ic'; only '-lic' reads the file this user's PATH lives in.
+case "$1" in
+ -lic) ;;
+ *) exit 0 ;;
+esac
+shift
+PATH="${binDir}" exec /bin/sh -c "$@"
+`)
+ chmodSync(shell, 0o700)
+ return shell
+}
+
function fakeTmux(): string {
const dir = scratch('tmux-onpath-bin-')
const tmux = join(dir, 'tmux')
@@ -56,6 +73,19 @@ describe('ensureTmuxOnPath', () => {
expect(env.PATH).toContain('/nonexistent-for-this-test')
})
+ it('asks again as a login shell when the interactive one comes back empty', async () => {
+ // A bash machine, measured here: `bash -ic` resolved nothing and `bash -lic` returned
+ // /usr/local/bin/tmux, so the daemon logged "tmux: unavailable (spawn tmux ENOENT)" and served
+ // ZERO agents while nine tmux sessions were running. zsh keeps PATH in .zshrc, which `-i` reads;
+ // bash keeps it in .bash_profile, which only `-l` does.
+ const binDir = fakeTmux()
+ const env: NodeJS.ProcessEnv = { PATH: '/nonexistent' }
+ const outcome = await ensureTmuxOnPath(env, loginOnlyShell(binDir))
+
+ expect(outcome.state).toBe('adopted')
+ expect(env.PATH?.split(delimiter)[0]).toBe(binDir)
+ })
+
it('leaves an already-working PATH untouched', async () => {
const binDir = fakeTmux()
const env: NodeJS.ProcessEnv = { PATH: binDir }
diff --git a/cli/src/lib/tmuxOnPath.ts b/cli/src/lib/tmuxOnPath.ts
index 04b1de681..97a885c0d 100644
--- a/cli/src/lib/tmuxOnPath.ts
+++ b/cli/src/lib/tmuxOnPath.ts
@@ -36,10 +36,34 @@ export async function resolveViaLoginShell(
): Promise<string | null> {
const interactive = interactiveEngineShell(shell)
if (!interactive) return null
- return await new Promise<string | null>((resolve) => {
+ const found = await probe(interactive.path, interactive.args, command)
+ if (found) return found
+ // ASK AGAIN AS A LOGIN SHELL, because for bash the first ask reads the wrong file.
+ //
+ // interactiveEngineShell gives zsh `-lic` and bash `-ic`, and that asymmetry is deliberate: a
+ // deliberate test pins bash to interactive-only startup files. It is right for LAUNCHING an engine
+ // and wrong for ASKING WHERE A BINARY IS, because the two conventions differ — a zsh user's PATH is
+ // in .zshrc, which `-i` reads, and a bash user's is conventionally in .bash_profile, which only `-l`
+ // reads (.bashrc runs for every subshell, so a PATH built there compounds).
+ //
+ // Measured on a bash machine here: `bash -ic` resolved nothing, `bash -lic` returned
+ // /usr/local/bin/tmux. The daemon therefore logged "tmux: unavailable (spawn tmux ENOENT)" and served
+ // ZERO agents while nine tmux sessions were running — the dial showed an empty wheel and nothing said
+ // why. Terminal.app runs a login shell on macOS, so this second ask is also the one that matches what
+ // the user sees in their own terminal.
+ //
+ // Only ever a FALLBACK: the first ask stands when it answers, so nothing changes for the shells that
+ // already worked, and this costs one extra spawn only on a machine that was about to fail anyway.
+ if (interactive.args.includes('-lic')) return null
+ return await probe(interactive.path, ['-lic'], command)
+}
+
+/** One question to one shell: where is `command`? Null unless it answers with an absolute path. */
+function probe(shellPath: string, args: readonly string[], command: string): Promise<string | null> {
+ return new Promise<string | null>((resolve) => {
execFile(
- interactive.path,
- [...interactive.args, RESOLVE_SCRIPT, 'harness-tmux-probe', command],
+ shellPath,
+ [...args, RESOLVE_SCRIPT, 'harness-tmux-probe', command],
{ timeout: 5_000 },
(error, stdout) => {
const first = String(stdout ?? '').trim().split('\n')[0]?.trim() ?? ''