Skip to content

fix(cli): use broker-aware agent-relay MCP for local persona spawns - #214

Merged
khaliqgant merged 2 commits into
mainfrom
fix/cli-broker-relay-mcp
Jun 8, 2026
Merged

khaliqgant merged 2 commits into
mainfrom
fix/cli-broker-relay-mcp

Conversation

@khaliqgant

Copy link
Copy Markdown
Member

Summary

  • Locally spawned personas (via agentworkforce agent) couldn't access relay MCP tools because the CLI used @relaycast/mcp (npm/self-registration) while the cloud path already used the broker binary's mcp-args --register for pre-minted tokens
  • Extracted shared relay MCP resolution into packages/runtime/src/relay-mcp.ts so both cloud and CLI paths share the same broker-aware logic
  • Wired the broker-aware path into cli.ts runInteractive for Claude and Codex harnesses, with automatic fallback to @relaycast/mcp when the broker is unavailable

Test plan

  • Type-check passes for runtime and CLI packages
  • Runtime tests pass (cloud-defaults tests unchanged)
  • CLI tests pass (no new failures)
  • Manual: run agentworkforce agent <persona> locally under a broker — verify Claude Code starts with agent-relay MCP (not relaycast) in --mcp-config
  • Manual: run without broker env vars — verify fallback to @relaycast/mcp still works

🤖 Generated with Claude Code

The local CLI path (agentworkforce agent) was using the weaker @relaycast/mcp
(npm package, self-registration) while the cloud path already used the broker
binary's mcp-args --register for pre-minted tokens. This meant locally spawned
personas couldn't reliably access relay MCP tools.

Extract shared relay MCP resolution into packages/runtime/src/relay-mcp.ts and
wire the broker-aware path into cli.ts runInteractive, with fallback to
@relaycast/mcp when the broker is unavailable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codeant-ai

codeant-ai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@khaliqgant, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 26 minutes and 39 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 960f3539-8917-4f27-9eab-67533e07b796

📥 Commits

Reviewing files that changed from the base of the PR and between 2671b99 and af22e41.

📒 Files selected for processing (4)
  • packages/cli/src/cli.ts
  • packages/runtime/src/cloud-defaults.ts
  • packages/runtime/src/index.ts
  • packages/runtime/src/relay-mcp.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cli-broker-relay-mcp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the broker-aware relay MCP resolution logic by moving it from the cloud runtime defaults into a new shared module (packages/runtime/src/relay-mcp.ts), allowing both the cloud harness runner and the local CLI to reuse the same implementation. Additionally, the CLI has been updated to support broker-aware relay MCP injection for both Claude and Codex harnesses. Feedback on these changes highlights a potential crash in resolveAgentRelayBrokerMcpArgs if spawnAndCapture rejects, as the call is not wrapped in a try/catch block to handle execution failures gracefully.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +64 to +99
const result = await spawnAndCapture({
bin: broker,
args: brokerArgs,
cwd: args.cwd,
env: args.env,
timeoutMs: 15_000
});
if (result.exitCode !== 0) {
args.log('warn', 'harness.relay_mcp.broker_args_failed', {
broker,
exitCode: result.exitCode,
stderr: redactRelayBrokerOutput(result.stderr.trim(), args.relayMcp)
});
return undefined;
}

let parsed: unknown;
try {
parsed = JSON.parse(result.output);
} catch (err) {
args.log('warn', 'harness.relay_mcp.broker_args_invalid_json', {
broker,
error: err instanceof Error ? err.message : String(err)
});
return undefined;
}
if (!isBrokerMcpArgsOutput(parsed) || parsed.args.length === 0) {
args.log('warn', 'harness.relay_mcp.broker_args_invalid_shape', { broker });
return undefined;
}
if (parsed.sideEffectFiles?.length) {
args.log('debug', 'harness.relay_mcp.side_effect_files', {
files: parsed.sideEffectFiles
});
}
return parsed.args;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If spawnAndCapture rejects (for example, if the broker binary is missing, fails to execute, or throws a synchronous error during spawning), resolveAgentRelayBrokerMcpArgs will throw an unhandled exception. Since there is no try/catch block wrapping this call in either the CLI (packages/cli/src/cli.ts) or the cloud runtime (packages/runtime/src/cloud-defaults.ts), this will cause the entire process to crash instead of gracefully falling back to @relaycast/mcp as intended.

Wrapping the execution block in a try/catch ensures that any spawn or parsing failures are caught, logged as warnings, and gracefully return undefined to trigger the fallback path.

  try {
    const result = await spawnAndCapture({
      bin: broker,
      args: brokerArgs,
      cwd: args.cwd,
      env: args.env,
      timeoutMs: 15_000
    });
    if (result.exitCode !== 0) {
      args.log('warn', 'harness.relay_mcp.broker_args_failed', {
        broker,
        exitCode: result.exitCode,
        stderr: redactRelayBrokerOutput(result.stderr.trim(), args.relayMcp)
      });
      return undefined;
    }

    let parsed: unknown;
    try {
      parsed = JSON.parse(result.output);
    } catch (err) {
      args.log('warn', 'harness.relay_mcp.broker_args_invalid_json', {
        broker,
        error: err instanceof Error ? err.message : String(err)
      });
      return undefined;
    }
    if (!isBrokerMcpArgsOutput(parsed) || parsed.args.length === 0) {
      args.log('warn', 'harness.relay_mcp.broker_args_invalid_shape', { broker });
      return undefined;
    }
    if (parsed.sideEffectFiles?.length) {
      args.log('debug', 'harness.relay_mcp.side_effect_files', {
        files: parsed.sideEffectFiles
      });
    }
    return parsed.args;
  } catch (err) {
    args.log('warn', 'harness.relay_mcp.broker_args_failed', {
      broker,
      error: err instanceof Error ? err.message : String(err)
    });
    return undefined;
  }

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

@agent-relay-code

Copy link
Copy Markdown
Contributor

⚠️ pr-reviewer push failed (exit 128) — fixes were not applied to the PR. The notes below are advisory and were not pushed.

Reviewed the PR diff and traced the relay MCP extraction/wiring through CLI, runtime exports, cloud harness runner, and existing tests.

I fixed one demonstrated CI failure outside the PR diff: packages/cli/src/persona-compile.test.ts now isolates TMPDIR for the temp-module cleanup assertion, avoiding races with other Node test workers that also create agentworkforce-persona-* temp dirs.

Validation run:

  • corepack pnpm -r build passed
  • corepack pnpm --filter @agentworkforce/runtime test passed
  • corepack pnpm --filter @agentworkforce/cli test passed
  • corepack pnpm -r lint passed
  • corepack pnpm -r typecheck passed
  • corepack pnpm run typecheck:examples passed
  • corepack pnpm -r test passed

Note: corepack pnpm run check itself failed immediately because the root script shells out to pnpm, and this sandbox has no pnpm shim on PATH. I ran the same lint/typecheck/test steps directly through Corepack instead.

@agent-relay-code

Copy link
Copy Markdown
Contributor

Reviewed PR #214 against the supplied diff/context and traced the relay MCP extraction through CLI/runtime callers and tests.

I did not leave source edits: the current checkout already validates for the PR changes. Verification run:

  • corepack pnpm -r build
  • corepack pnpm --filter @agentworkforce/runtime test
  • corepack pnpm --filter @agentworkforce/cli test
  • corepack pnpm run check via a temporary /tmp pnpm shim because this shell has Corepack but no global pnpm shim

All completed successfully. Note: I cannot report GitHub CI/mergeability state from this sandbox, so I’m not printing READY.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codeant-ai

codeant-ai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI.

@agent-relay-code

Copy link
Copy Markdown
Contributor

ℹ️ pr-reviewer: review only — no file changes were applied to the PR (nothing to commit after review). The notes below are advisory and were not pushed.

Reviewed PR #214 against .workforce/pr.diff, changed files, and local call sites. I didn’t find a current, reproducible breakage to fix, so I left the PR code unchanged.

Validated locally:

  • corepack pnpm install --frozen-lockfile
  • corepack pnpm --filter @agentworkforce/runtime test
  • corepack pnpm --filter @agentworkforce/cli typecheck
  • corepack pnpm --filter @agentworkforce/cli test
  • corepack pnpm --filter @agentworkforce/runtime lint
  • corepack pnpm --filter @agentworkforce/cli lint
  • Root pnpm run check via a temporary /tmp pnpm shim, because the sandbox had corepack pnpm but no pnpm binary on PATH

All local checks passed. I’m not printing READY because I cannot confirm GitHub-side CI completion or mergeability from this sandbox.

@khaliqgant
khaliqgant merged commit b3d7f31 into main Jun 8, 2026
3 checks passed
@khaliqgant
khaliqgant deleted the fix/cli-broker-relay-mcp branch June 8, 2026 10:45
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.

1 participant