Skip to content

feat(broker): expose RELAY_AGENT_NAME to PTY children even when skip_relay_prompt#1018

Open
khaliqgant wants to merge 5 commits into
mainfrom
feat/expose-relay-agent-name-to-launchers
Open

feat(broker): expose RELAY_AGENT_NAME to PTY children even when skip_relay_prompt#1018
khaliqgant wants to merge 5 commits into
mainfrom
feat/expose-relay-agent-name-to-launchers

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented May 31, 2026

Why

This is the broker half of giving Agent Relay personas the ability to message the team. (Workforce half: AgentWorkforce/workforce#170.)

When the broker spawns a regular harness (claude/codex/…), it recognizes the CLI and auto-wires the relaycast MCP. But a persona is launched via the agentworkforce CLI, which is a wrapper: the broker's PTY child is agentworkforce, and the real harness (claude) is a grandchild the broker never sees. So the broker can't wire relaycast for it — the agentworkforce CLI has to, by injecting a relaycast MCP server into the harness spec it builds.

To do that under the same identity the broker routes to, the launcher needs the broker-assigned worker name. The broker already passes RELAY_API_KEY / RELAY_BASE_URL / RELAY_DEFAULT_WORKSPACE to every child via worker_env, but RELAY_AGENT_NAME was set only when !skip_relay_prompt — and persona spawns use skip_relay_prompt: true. So the launcher had no way to know its assigned name.

What changed

crates/broker/src/worker.rs: set RELAY_AGENT_NAME for every PTY child. The token / type / strict-name vars stay gated behind !skip_relay_prompt — those configure the broker's own injected MCP, which is exactly what skip_relay_prompt opts out of; a launcher that wires its own relaycast server supplies them itself (the workforce side sets RELAY_AGENT_TYPE / RELAY_STRICT_AGENT_NAME in the MCP server's env block it injects).

Behavior is unchanged for the !skip_relay_prompt path (all four vars still set) and for headless agents (PTY-only via the matches! guard). The only delta: skip_relay_prompt PTY children now also get RELAY_AGENT_NAME (an identity hint a normal harness ignores; a wrapper launcher uses).

Testing

  • cargo check -p agent-relay-broker — clean
  • cargo test -p agent-relay-broker --lib worker:: — 39 passed, 0 failed

🤖 Generated with Claude Code

…relay_prompt

A wrapper launcher that the broker spawns as a PTY child — e.g. the
`agentworkforce` CLI, which then spawns the real harness itself rather
than being the harness — needs the broker-assigned worker name to wire
the relaycast MCP for that harness under the SAME identity the broker
routes messages to. Otherwise a persona launched this way registers
under a different (or no) name and can't exchange messages with the team.

Previously RELAY_AGENT_NAME was set only when `!skip_relay_prompt`, and
persona spawns use skip_relay_prompt. Set RELAY_AGENT_NAME for every PTY
child; keep RELAY_AGENT_TOKEN / RELAY_AGENT_TYPE / RELAY_STRICT_AGENT_NAME
gated behind `!skip_relay_prompt` since those configure the broker's own
injected MCP — exactly what skip_relay_prompt opts out of. A launcher
that wires its own relaycast server supplies them itself.

Pairs with AgentWorkforce/workforce, where the agentworkforce CLL reads
RELAY_AGENT_NAME + RELAY_API_KEY and injects the relaycast MCP into the
persona's harness spec.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@khaliqgant khaliqgant requested a review from willwashburn as a code owner May 31, 2026 16:51
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 803ec964-aff1-4ee7-b66e-c7ee4eadd2e7

📥 Commits

Reviewing files that changed from the base of the PR and between dc98e12 and 8705d3e.

📒 Files selected for processing (6)
  • .agentworkforce/trajectories/completed/2026-05/traj_g4s1nlhpccd5/summary.md
  • .agentworkforce/trajectories/completed/2026-05/traj_g4s1nlhpccd5/trajectory.json
  • .agentworkforce/trajectories/completed/2026-05/traj_j846cp13mg9k/summary.md
  • .agentworkforce/trajectories/completed/2026-05/traj_j846cp13mg9k/trajectory.json
  • .github/workflows/pullfrog.yml
  • crates/broker/src/worker.rs
✅ Files skipped from review due to trivial changes (5)
  • .agentworkforce/trajectories/completed/2026-05/traj_j846cp13mg9k/trajectory.json
  • .agentworkforce/trajectories/completed/2026-05/traj_j846cp13mg9k/summary.md
  • .agentworkforce/trajectories/completed/2026-05/traj_g4s1nlhpccd5/trajectory.json
  • .agentworkforce/trajectories/completed/2026-05/traj_g4s1nlhpccd5/summary.md
  • .github/workflows/pullfrog.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/broker/src/worker.rs

📝 Walkthrough

Walkthrough

The change refactors environment variable injection for PTY workers in the broker's worker registry. RELAY_AGENT_NAME is now always set to expose the broker-assigned worker identity, while relaycast MCP-related environment variables (RELAY_AGENT_TOKEN, RELAY_AGENT_TYPE, RELAY_STRICT_AGENT_NAME) are conditionally set only when relaycast prompt/MCP injection is enabled.

Changes

PTY Worker Identity Environment Setup

Layer / File(s) Summary
Constants and env override helpers
crates/broker/src/worker.rs
Adds RELAY_AGENT_CHILD_ENV_KEYS and implements pty_relay_agent_env_overrides and apply_pty_relay_agent_env to compute and apply PTY child env: always expose RELAY_AGENT_NAME, optionally include token/type/strict-name when injecting prompt/MCP, and remove inherited relay-agent env keys before applying overrides.
Spawn usage update and unit tests
crates/broker/src/worker.rs
Replaces inline PTY env gating in WorkerRegistry::spawn with apply_pty_relay_agent_env and adds tests verifying behavior for skip_relay_prompt true/false and removal of inherited registration env vars.
Trajectory, workflow formatting, and changelog
.agentworkforce/trajectories/completed/..., .github/workflows/pullfrog.yml, CHANGELOG.md
Adds trajectory completion metadata and a changelog entry noting that PTY spawns with skip_relay_prompt still receive RELAY_AGENT_NAME; reformats a workflow env block entry.

Sequence Diagram(s)

sequenceDiagram
  participant WorkerRegistry
  participant apply_pty_relay_agent_env
  participant ChildProcess
  WorkerRegistry->>apply_pty_relay_agent_env: call(assigned_name, skip_relay_prompt, Command)
  apply_pty_relay_agent_env->>ChildProcess: unset RELAY_AGENT_CHILD_ENV_KEYS
  apply_pty_relay_agent_env->>ChildProcess: set RELAY_AGENT_NAME (always)
  apply_pty_relay_agent_env->>ChildProcess: optionally set RELAY_AGENT_TOKEN / RELAY_AGENT_TYPE / RELAY_STRICT_AGENT_NAME
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • AgentWorkforce/relay#927: Adjusts Relaycast MCP/PTY worker setup so broker-provided relay identity is applied for Claude PTY workers instead of being skipped when relaycast prompt/registration is suppressed.

Suggested reviewers

  • willwashburn

Poem

🐰 A rabbit peeks at envs in flight,
broker name set clear and bright,
tokens sleep when prompts are skipped,
the child's vars are neatly stripped,
so launches start with names just right.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description provides comprehensive context (Why section explains the motivation), details the code changes (What changed section), and includes testing results. However, the provided template requires explicit checkbox items under 'Test Plan' which are missing from the author's description. Add explicit 'Test Plan' section with checkbox items for 'Tests added/updated' and 'Manual testing completed' to match the repository template structure.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly describes the main change: exposing RELAY_AGENT_NAME to PTY child processes even when skip_relay_prompt is true, which matches the core logic change in worker.rs.
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.

✏️ 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 feat/expose-relay-agent-name-to-launchers

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.

Copy link
Copy Markdown

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

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 modifies crates/broker/src/worker.rs to ensure that the broker-assigned worker name (RELAY_AGENT_NAME) is always exposed to PTY child processes, even when skip_relay_prompt is enabled. Other environment variables, such as RELAY_AGENT_TOKEN, RELAY_AGENT_TYPE, and RELAY_STRICT_AGENT_NAME, remain gated behind the skip_relay_prompt check. There are no review comments, and I have no feedback to provide.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

No issues found across 1 file

You’re at about 92% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Re-trigger cubic

@khaliqgant khaliqgant closed this May 31, 2026
@khaliqgant khaliqgant reopened this May 31, 2026
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