Skip to content

fix: bundle Rust broker binary for SDK programmatic usage#440

Merged
khaliqgant merged 1 commit intomainfrom
fix/bundle-rust-broker
Feb 18, 2026
Merged

fix: bundle Rust broker binary for SDK programmatic usage#440
khaliqgant merged 1 commit intomainfrom
fix/bundle-rust-broker

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Feb 18, 2026

Summary

  • The SDK's AgentRelayClient spawns agent-relay init --name broker --channels <channel> which requires the Rust broker binary, not the Bun-compiled Node.js CLI
  • The publish workflow was uploading the CLI as agent-relay-{platform}-{arch} and postinstall.js was downloading it into sdk-ts/bin/, causing "broker exited (code=1)" for all workflow runs
  • Additionally, the Rust broker requires a Relaycast workspace API key but there was no auto-provisioning, requiring manual RELAY_API_KEY setup

Changes

CI: Add build-broker job (publish.yml)

  • Builds the Rust broker from src/main.rs via cargo build --release for all 4 platforms
  • Uploads as agent-relay-broker-{platform}-{arch} (distinct from CLI's agent-relay-{platform}-{arch})
  • Adds broker binaries to GitHub release assets

Postinstall: Download correct binary (postinstall.js)

  • getBrokerBinaryName() now returns agent-relay-broker-{platform}-{arch} instead of agent-relay-{platform}-{arch}
  • Adds validation to distinguish the Rust broker from the Bun CLI (checks for --name flag in init --help)
  • Checks target/release before target/debug in dev fallback

WorkflowRunner: Auto-provision Relaycast (runner.ts)

  • ensureRelaycastApiKey() runs before broker startup
  • Resolution order: RELAY_API_KEY env var → cached ~/.agent-relay/relaycast.json → auto-create workspace
  • Auto-created workspaces use unique names (relay-{channel}-{hex}) to avoid 409 conflicts

Test plan

  • Verify npm run build passes (sdk-ts compiles cleanly)
  • Verify postinstall detects wrong binary and reinstalls
  • Run agent-relay run workflows/example.yaml — broker should start without manual API key setup
  • Verify CI build-broker job produces valid Rust binaries for all platforms

🤖 Generated with Claude Code


Open with Devin

Comment thread packages/broker-sdk/src/workflows/runner.ts Fixed
Comment thread packages/broker-sdk/src/workflows/runner.ts Fixed
devin-ai-integration[bot]

This comment was marked as resolved.

@khaliqgant khaliqgant force-pushed the fix/bundle-rust-broker branch from 4c481e0 to 30ad64a Compare February 18, 2026 21:05
Comment on lines +165 to +174
await writeFile(
cachePath,
JSON.stringify({
workspace_id: workspaceId,
api_key: apiKey,
agent_id: '',
agent_name: null,
updated_at: new Date().toISOString(),
}),
);

Check failure

Code scanning / CodeQL

Potential file system race condition High

The file may have changed since it
was checked
.
Comment on lines +167 to +173
JSON.stringify({
workspace_id: workspaceId,
api_key: apiKey,
agent_id: '',
agent_name: null,
updated_at: new Date().toISOString(),
}),

Check warning

Code scanning / CodeQL

Network data written to file Medium

Write to file system depends on
Untrusted data
.
The SDK's AgentRelayClient spawns `agent-relay init --name broker
--channels <channel>` which requires the Rust broker binary, not
the Bun-compiled Node.js CLI. The publish workflow was uploading
the CLI as `agent-relay-{platform}-{arch}` and postinstall was
downloading it into sdk-ts/bin/, causing "broker exited (code=1)"
errors for all workflow runs.

Changes:
- Add `build-broker` CI job that compiles src/main.rs (Rust) for
  all platforms as `agent-relay-broker-{platform}-{arch}`
- Update postinstall.js to download broker-specific release assets
- Add validation to detect wrong binary (CLI vs Rust broker)
- Check target/release before target/debug in dev fallback
- Add Relaycast auto-provisioning to WorkflowRunner so workflows
  run without manual RELAY_API_KEY setup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@khaliqgant khaliqgant force-pushed the fix/bundle-rust-broker branch from 30ad64a to fa5a41f Compare February 18, 2026 21:11
@khaliqgant khaliqgant merged commit d0f3dd5 into main Feb 18, 2026
36 of 37 checks passed
@khaliqgant khaliqgant deleted the fix/bundle-rust-broker branch February 18, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants