Skip to content

Cross-repo attach breaks when the caller is itself a relay agent: broker URL and API key resolve from different sources #1382

Description

@willwashburn

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)

  1. URL and API key resolve independentlypackages/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.

  2. A capability probe aborts on errorisNativeHarness (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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions