A process that carries RELAY_BROKER_API_KEY for its own broker (i.e. any relay agent) cannot attach to another repo's broker: the connection resolver pairs its own env key with the target repo's URL, the resulting 401 hits the isNativeHarness preflight, and the probe failure aborts the whole attach.
Root causes (two, both needed)
-
URL and API key resolve independently — packages/cli/src/cli/lib/broker-connection.ts:94 picks explicit ?? env ?? file for the URL and :100 picks explicit ?? env ?? file for the key, separately. With RELAY_BROKER_API_KEY in env and the URL coming from the target's connection.json, the pair is cross-wired and can never authenticate. URL + key should resolve as an atomic pair from a single source (explicit flags > env pair > connection-file pair), never mixed.
-
A capability probe aborts on error — isNativeHarness (packages/cli/src/cli/lib/attach-native.ts:295-309) calls listAgents() and lets any rejection (including the 401) propagate, killing the attach. A probe answering "is this agent native?" should degrade to false/fallback on failure, never abort the operation it gates.
Repro
From a shell where a relay agent session exported RELAY_BROKER_API_KEY (own broker), run agent-relay node agent attach <name> against another repo's broker (state dir of the target repo). The preflight 401s and the attach aborts. (Rendered as [object Object] until the error-rendering fix — separate issue.)
Deployed workaround to delete once fixed
Chief's orgchart tool unsets both RELAY_BROKER_API_KEY and RELAY_BROKER_URL before attaching; the fix should make that unnecessary.
🤖 Generated with Claude Code
A process that carries
RELAY_BROKER_API_KEYfor its own broker (i.e. any relay agent) cannot attach to another repo's broker: the connection resolver pairs its own env key with the target repo's URL, the resulting 401 hits theisNativeHarnesspreflight, and the probe failure aborts the whole attach.Root causes (two, both needed)
URL and API key resolve independently —
packages/cli/src/cli/lib/broker-connection.ts:94picksexplicit ?? env ?? filefor the URL and:100picksexplicit ?? env ?? filefor the key, separately. WithRELAY_BROKER_API_KEYin env and the URL coming from the target'sconnection.json, the pair is cross-wired and can never authenticate. URL + key should resolve as an atomic pair from a single source (explicit flags > env pair > connection-file pair), never mixed.A capability probe aborts on error —
isNativeHarness(packages/cli/src/cli/lib/attach-native.ts:295-309) callslistAgents()and lets any rejection (including the 401) propagate, killing the attach. A probe answering "is this agent native?" should degrade tofalse/fallback on failure, never abort the operation it gates.Repro
From a shell where a relay agent session exported
RELAY_BROKER_API_KEY(own broker), runagent-relay node agent attach <name>against another repo's broker (state dir of the target repo). The preflight 401s and the attach aborts. (Rendered as[object Object]until the error-rendering fix — separate issue.)Deployed workaround to delete once fixed
Chief's orgchart tool unsets both
RELAY_BROKER_API_KEYandRELAY_BROKER_URLbefore attaching; the fix should make that unnecessary.🤖 Generated with Claude Code