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(muse): a refused launch says why, instead of exiting in silence

0xken157f9cd23212f8
diff --git a/cli/src/lib/duplicateAgent.spec.ts b/cli/src/lib/duplicateAgent.spec.ts
index f1daf9312..b2e4a53e8 100644
--- a/cli/src/lib/duplicateAgent.spec.ts
+++ b/cli/src/lib/duplicateAgent.spec.ts
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
import { mkdtempSync, rmSync, symlinkSync } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
-import { refuseDuplicateAgent, sameDirSync } from './duplicateAgent.js'
+import { refusalMessage, refuseDuplicateAgent, sameDirSync } from './duplicateAgent.js'
/**
* The rule exists because muse gives repair nothing to tell two agents in one directory apart, so the
@@ -56,6 +56,21 @@ describe('one agent per directory', () => {
expect(refuseDuplicateAgent([agent('agent-1', 'muse', null)], 'muse', CWD, all)).toBeNull()
})
+ it('tells the person in the pane what happened and what to do', () => {
+ // A refusal that prints nothing reads as a broken CLI — which is exactly what shipped first: the
+ // launcher exited 0 in silence, because the daemon closes the socket ~2ms after the `exit` frame and
+ // the close path ended the process before the post-ack check could run.
+ const reason = refuseDuplicateAgent([agent('agent-1', 'muse')], 'muse', CWD, all)
+ const lines = refusalMessage(reason ?? undefined)
+ expect(lines[0]).toContain(CWD) // what, and where
+ expect(lines.join('\n')).toMatch(/different directory/) // and the way out
+ expect(lines).toHaveLength(3)
+ })
+
+ it('still says something useful when the daemon sends no reason', () => {
+ expect(refusalMessage(undefined)[0]).toMatch(/refused/)
+ })
+
it('sees through a symlink, so one directory under two names is still one directory', () => {
// `/tmp` is itself a symlink to `/private/tmp` on macOS, which is why string equality is not enough.
const real = mkdtempSync(join(tmpdir(), 'dup-'))
diff --git a/cli/src/lib/duplicateAgent.ts b/cli/src/lib/duplicateAgent.ts
index 9ce25514c..54d145c2c 100644
--- a/cli/src/lib/duplicateAgent.ts
+++ b/cli/src/lib/duplicateAgent.ts
@@ -30,6 +30,21 @@ export function sameDirSync(a: string, b: string): boolean {
return real(a) === real(b)
}
+/**
+ * What the person in the pane reads when their launch is turned away.
+ *
+ * The REASON comes from the daemon (it owns the rule); the launcher only adds what to do about it. Three
+ * lines, because a bare refusal reads like a broken CLI: what happened, why it has to be that way, and
+ * the way forward.
+ */
+export function refusalMessage(reason: string | undefined): string[] {
+ return [
+ `harness: ${reason || 'this agent was refused by the machine'}`,
+ ' Two agents in one directory cannot be told apart, so only one can run here.',
+ ' Close the other one, or start this agent in a different directory.',
+ ]
+}
+
export interface AgentLocation { agentId: string; engine: string; cwd?: string | null }
export interface DuplicateCheck {
diff --git a/cli/src/lib/launch.ts b/cli/src/lib/launch.ts
index 1af89c297..96af30ede 100644
--- a/cli/src/lib/launch.ts
+++ b/cli/src/lib/launch.ts
@@ -17,6 +17,7 @@
*/
import { execFile, spawn } from 'child_process'
+import { refusalMessage } from './duplicateAgent.js'
import { randomUUID } from 'crypto'
import { WebSocket } from 'ws'
import { env } from '../config/env.js'
@@ -404,6 +405,13 @@ export async function launchEngine(engine: AgentEngine, argv: string[]): Promise
paneNotice(pane, `harness updated to v${daemonVersion} (this agent runs v${VERSION}) · exit and re-run: harness ${engineCommand(engine)}`)
}
+ // A refusal has to be acted on the INSTANT it lands, not after the ack wait: the daemon closes the
+ // socket ~2ms behind the `exit` frame, and the close path ends this process — measured, the launcher
+ // exited 0 in silence with the check below never reached. Nothing has spawned yet at this point, so
+ // saying so and leaving IS the whole handling; once the engine exists, line ~478 takes this over with
+ // the teardown that stops it.
+ link.onExitRequested = (reason: string | undefined): never => fail(refusalMessage(reason))
+
link.connect()
// ── Let the DAEMON decide the two things that change between builds: which binary an engine maps to,
@@ -416,10 +424,7 @@ export async function launchEngine(engine: AgentEngine, argv: string[]): Promise
// there is no `opened` and `waitForAck` simply times out. Bail HERE, in the gap before the spawn: the
// engine has not started, so the pane returns to the shell instead of flashing a CLI that something
// else kills a moment later (which is what an older launcher, acting on this only after spawning, does).
- if (link.exitRequested !== false) {
- console.error(`harness: ${link.exitRequested || 'this agent was refused by the machine'}`)
- process.exit(1)
- }
+ if (link.exitRequested !== false) fail(refusalMessage(link.exitRequested || undefined))
const bin = ack?.bin || engineBin(engine)
if (!ack?.hooksReady && !env.DISABLE_HOOK_INSTALL) {
// Fallback only. The installers narrate to stdout, which here is the user's pane — a stray