Skip to content

Pass spawn model through MCP, SDK, and broker to the launched CLI#1076

Merged
khaliqgant merged 3 commits into
mainfrom
fix/spawn-model-passthrough
Jun 10, 2026
Merged

Pass spawn model through MCP, SDK, and broker to the launched CLI#1076
khaliqgant merged 3 commits into
mainfrom
fix/spawn-model-passthrough

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jun 10, 2026

Copy link
Copy Markdown
Member

Problem

The add_agent MCP model arg was cosmetic. It was stuffed into agent metadata and never reached the broker, so relay-spawned workers always booted with the session default (e.g. Opus) regardless of the requested model. Verified 2026-06-10: spawning with model: "haiku" (and the full id) still booted Opus.

Change

  • agent-relay-mcp.ts — pass model as a first-class spawn field instead of burying it in metadata.
  • sdk/messaging (types + normalize) — carry model on the agentSpawnRequested event so TS consumers see it.
  • broker/runtime/relaycast_events.rs — build AgentSpec with the event's model (blank treated as unset) instead of hardcoding model: None. worker.rs already renders --model from spec.model, so this closes the last gap.
  • dep bump@relaycast/sdk^2.6.0 (packages/cli) and the relaycast crate → =2.4.0 (broker), the published versions that carry model.

Companion / dependency (now landed)

Gating change AgentWorkforce/relaycast#180 is merged + published:

  • npm @relaycast/types + @relaycast/sdk at 2.6.0
  • relaycast crate at 2.4.0
  • relaycast engine deployed.

Verified

  • packages/cli tsc --noEmit clean — the prior TS2353: 'model' does not exist is gone now that @relaycast/sdk@2.6.0 is resolved.
  • cargo check -p agent-relay-broker builds against relaycast 2.4.0.

Note

Main-process/broker change — takes effect after the broker is rebuilt. Post-merge sanity: spawn a worker via add_agent with model set and confirm --model reaches the launched CLI.

🤖 Generated with Claude Code

The add_agent MCP `model` arg was cosmetic: it was stuffed into agent
metadata and never reached the broker, so relay-spawned workers always
booted with the session default regardless of the requested model.

- agent-relay-mcp.ts: pass `model` as a first-class spawn field instead
  of burying it in metadata.
- sdk messaging types/normalize: carry `model` on the agentSpawnRequested
  event so TS consumers see it.
- broker relaycast_events.rs: build AgentSpec with the event's `model`
  (blank treated as unset) instead of hardcoding `None`. worker.rs
  already renders `--model` from spec.model, so this is the last gap.

BLOCKED ON: a relaycast release. relay consumes the published
@relaycast/sdk (^2.5.1) and the `relaycast` crate, whose spawn types do
not yet carry `model`. The companion change is AgentWorkforce/relaycast
PR (branch fix/spawn-model-passthrough). Once relaycast is published with
`model`, bump @relaycast/sdk + the `relaycast` crate pin here; the CLI
typecheck and broker build pass after that. Draft until then.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR threads an optional model parameter through the agent spawn request flow. SDK types and normalization are updated to include model, the CLI tool wires it as an explicit argument, and the broker handler extracts and forwards it to the spawned agent.

Changes

Agent spawn model parameter threading

Layer / File(s) Summary
SDK type contract and event normalization
packages/sdk/src/messaging/types.ts, packages/sdk/src/messaging/normalize.ts, packages/cli/package.json
RelayAgentSpawnRequestedEvent type extends agent payload with optional model?: string field; normalizeMessagingEvent maps agent.model when present; SDK dependency version bumped to ^2.6.0.
CLI agent spawn tool wiring
packages/cli/src/cli/agent-relay-mcp.ts
add_agent tool handler forwards model as explicit first-class parameter to agents.spawn() (with model ?? undefined), replacing previous metadata-based approach.
Broker spawn handler and dependency
crates/broker/Cargo.toml, crates/broker/src/runtime/relaycast_events.rs
Handler extracts event.agent.model, filters blank/whitespace values, and wires into AgentSpec construction; relaycast dependency updated to =2.4.0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • willwashburn

Poem

🐰 A model passes through the relay,
From SDK types to CLI's way,
Through broker spawn it flows so free,
Each layer threads it carefully! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: passing the spawn model parameter through the full stack (MCP, SDK, and broker) to the launched CLI.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description comprehensively explains the problem, changes across all affected files, dependency blocking requirements, and verification steps completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/spawn-model-passthrough

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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 updates the agent relay and broker to propagate the requested model as a first-class field from the CLI and SDK through to the launched CLI. Feedback points out that the JSON fallback path for agent.spawn_requested in the broker runtime still hardcodes model: None and needs to be updated to extract and propagate the model consistently.

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.

model,
cwd: None,
team: None,
shadow_of: None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this primary path now correctly propagates the model field to AgentSpec, the JSON fallback path for agent.spawn_requested (around line 494) still hardcodes model: None and does not extract the model from the raw JSON. To ensure consistency and prevent the requested model from being lost when the fallback path is triggered, we should also extract model from agent_obj in the fallback block and pass it to AgentSpec.

relaycast shipped the spawn `model` passthrough:
- npm @relaycast/sdk + @relaycast/types at 2.6.0
- relaycast crate at 2.4.0

Bump packages/cli to @relaycast/sdk ^2.6.0 and the broker crate pin to
=2.4.0 so `model` is available end-to-end. Verified: packages/cli tsc
clean (the prior `TS2353: 'model' does not exist` is gone) and
`cargo check -p agent-relay-broker` builds against relaycast 2.4.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@khaliqgant khaliqgant marked this pull request as ready for review June 10, 2026 09:42
@khaliqgant khaliqgant requested a review from willwashburn as a code owner June 10, 2026 09:42

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/broker/src/runtime/relaycast_events.rs`:
- Around line 207-210: The fallback path for agent.spawn_requested currently
drops the requested model and the primary path doesn't trim whitespace; ensure
the model is normalized (trim whitespace and treat empty/blank as None) and
propagated into AgentSpec on both paths. Specifically, compute a single
normalized model value from event.agent.model (e.g., map to trimmed string then
filter out empty strings) and use that normalized value when constructing
AgentSpec in the normal branch and in the raw JSON fallback branch so the model
is not lost; update the code that builds AgentSpec (the AgentSpec.model field)
to use this shared normalized model. Also apply the same fix to the other
occurrence around the 484-492 region.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fe884e55-a4af-48d2-b3ca-5c3a4fa7875b

📥 Commits

Reviewing files that changed from the base of the PR and between c3c772c and 2d28ab5.

⛔ Files ignored due to path filters (2)
  • Cargo.lock is excluded by !**/*.lock
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • crates/broker/Cargo.toml
  • crates/broker/src/runtime/relaycast_events.rs
  • packages/cli/package.json
  • packages/cli/src/cli/agent-relay-mcp.ts
  • packages/sdk/src/messaging/normalize.ts
  • packages/sdk/src/messaging/types.ts

Comment on lines +207 to +210
// Carry the requested model through so the launched CLI is
// started with `--model` (see worker.rs). An empty/blank
// model is treated as unset.
let model = event.agent.model.filter(|value| !value.trim().is_empty());

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fallback spawn path drops model, and model values are not normalized consistently.

When agent.spawn_requested falls back to raw JSON parsing, AgentSpec is still built with model: None, so the requested model is lost on that path. Also, the primary path only checks blankness but does not trim whitespace before forwarding. This breaks model pass-through for fallback events and can pass malformed model args.

Suggested fix
-                    let model = event.agent.model.filter(|value| !value.trim().is_empty());
+                    let model = event
+                        .agent
+                        .model
+                        .and_then(|value| {
+                            let trimmed = value.trim();
+                            (!trimmed.is_empty()).then(|| trimmed.to_string())
+                        });
...
             let channel = agent_obj
                 .and_then(|a| a.get("channel"))
                 .and_then(Value::as_str)
                 .map(String::from);
+            let model = agent_obj
+                .and_then(|a| a.get("model"))
+                .and_then(Value::as_str)
+                .map(str::trim)
+                .filter(|value| !value.is_empty())
+                .map(String::from);
...
-                            model: None,
+                            model,

Also applies to: 484-492

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/broker/src/runtime/relaycast_events.rs` around lines 207 - 210, The
fallback path for agent.spawn_requested currently drops the requested model and
the primary path doesn't trim whitespace; ensure the model is normalized (trim
whitespace and treat empty/blank as None) and propagated into AgentSpec on both
paths. Specifically, compute a single normalized model value from
event.agent.model (e.g., map to trimmed string then filter out empty strings)
and use that normalized value when constructing AgentSpec in the normal branch
and in the raw JSON fallback branch so the model is not lost; update the code
that builds AgentSpec (the AgentSpec.model field) to use this shared normalized
model. Also apply the same fix to the other occurrence around the 484-492
region.

@khaliqgant khaliqgant merged commit 040da37 into main Jun 10, 2026
45 checks passed
@khaliqgant khaliqgant deleted the fix/spawn-model-passthrough branch June 10, 2026 10:16
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