feat(broker): node-only delivery for relaycast v5.0.1

Merged
WI
5mo ago
+2644-2038

✅ Fully validated end-to-end on prod (cast.agentrelay.com, v5.0.1)

The complete chain was exercised live against the deployed v5.0.1 engine with this branch's broker: enroll as a role:broker node → spawn an agent (node-bound to the fleet node) → DM from another agent → engine delivered it over /v1/node/ws → broker injected it into the agent's PTY → acked. The delivered event_id matched the sent DM. This is the exact scenario that was broken ("messages never inject between broker-spawned agents") — now working.

What this does

Migrates agent-relay-broker to relaycast v5.0.1's node-only delivery model. In v5.0.1 the workspace firehose (/v1/ws) is observer-only; realtime delivery happens exclusively over the node channel (/v1/node/ws). The broker now:

  • Enrolls as a node at startup — node id derived from machine-id + hash(cwd) (so multiple brokers/workspaces on one host don't collide on create_node); mints + persists a workspace-scoped node token (create_node); connects /v1/node/ws unconditionally and sends node.register. A missing token is a loud hard-fault; a node-WS 401 invalidates the cached token and re-mints (bounded).
  • Binds every spawned agent to the broker's node (both /api/spawn and engine action.invoke spawns) so the engine routes their messages back.
  • Delivers over /v1/node/ws — deliver frames (route by agent_id, branch on payload.type: inject messages + action.completed/action.failed/action.denied results, ack-only for reactions/receipts), cumulative delivery.ack {up_to_seq}, bounded dedup, seq:0 fan-out surfaced.
  • Runs spawn/release as action.invoke → action.result.
  • Removes the firehose — fleet-mode drop, fleet_mode_enabled, and the rejected /v1/ws workspace-stream connection are gone (HTTP client retained for registration/API).

How it was built & validated

  • Implement (3 increments) → per-increment adversarial review + fix → comprehensive review + fixes → /v1/ws teardown → workspace-scoped token cache + re-mint-on-401 + cwd-scoped node id + agent.register reply correlation (robustness bugs the review and prod test surfaced).
  • 785+ unit tests pass, clippy clean. Runtime-validated end-to-end on prod (above).

Architecture

The node / broker / broker-pty-engine / @agent-relay/harness-driver / action-runner vocabulary + delivery model is documented in agentrelay.com docs PR #9 (architecture.mdx).

🤖 Generated with Claude Code