Skip to content

Add explicit broker workspace join options#1055

Merged
kjgbot merged 7 commits into
mainfrom
fix/explicit-workspace-broker-instance
Jun 8, 2026
Merged

Add explicit broker workspace join options#1055
kjgbot merged 7 commits into
mainfrom
fix/explicit-workspace-broker-instance

Conversation

@kjgbot
Copy link
Copy Markdown
Contributor

@kjgbot kjgbot commented Jun 6, 2026

Summary

  • Brokers can JOIN an existing workspace via --workspace-key / AGENT_RELAY_WORKSPACE_KEY (fail-loud on rejected/rate-limited keys — never silently create) with canonical > legacy env precedence
  • Named broker instances via --instance-name / AGENT_RELAY_BROKER_NAME
  • @agent-relay/harness-driver RuntimeSpawnOptions gains workspaceKey?; spawn forwards flags + envs

Underpins AgentWorkforce/pear#125. Reviewed (no blockers); cargo + harness-driver checks green.

🛑 DRAFT — merge hold per Khaliq pending discussion with Will.

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds explicit workspace-key and instance-name support across the broker and harness-driver, enabling them to join existing Relay workspaces with stable identifiers. CLI flags, environment-variable resolution, auth registration logic, env propagation, and harness-driver spawn configuration are all updated to prefer canonical variables while preserving legacy fallbacks.

Changes

Workspace-key and Instance-name Support

Layer / File(s) Summary
CLI struct, fields, and resolution methods
crates/broker/src/cli/mod.rs
InitCommand gains instance_name and workspace_key fields and CLI flags; legacy --name/--broker-name is retained. New methods resolved_instance_name() and resolved_workspace_key() implement ordered resolution (explicit input → env var → fallback) with trimming; log_identifier updated to use resolved name. Unit tests validate priority and trimming behavior with environment cleanup.
Auth workspace-key validation and registration flow
crates/broker/src/relaycast/auth.rs
Introduces EnvWorkspaceKey struct to track env-var source and explicit-flag status. New env_workspace_key() helper prefers canonical AGENT_RELAY_WORKSPACE_KEY and RELAY_WORKSPACE_KEY over legacy RELAY_API_KEY. Refactored startup_single_session_set_from_sources builds a candidate list and attempts registration per-candidate; explicit-key auth rejections (401/403/429) immediately error without fallback, while legacy keys may retry. Test cleanup and coverage extended for new env vars and explicit-key rejection behavior.
Broker init and spawn env propagation
crates/broker/src/runtime/init.rs, crates/broker/src/spawner.rs
run_init derives a default instance name from working directory and uses resolved_instance_name() for broker identity; conditionally stamps workspace and API keys into worker env when resolved_workspace_key() returns a value. spawn_env_vars includes AGENT_RELAY_WORKSPACE_KEY alongside RELAY_WORKSPACE_KEY for spawned agents.
Harness driver spawn config and tests
packages/harness-driver/src/spawn-config.ts, packages/harness-driver/src/spawn-config.test.ts, packages/harness-driver/src/client.ts
New spawn-config.ts module introduces BrokerInitArgs, RuntimeSpawnOptions, and BrokerSpawnConfig types; helpers buildBrokerInitArgs and nonEmptyString normalize inputs; main export buildBrokerSpawnConfig resolves broker identity, workspace key, and channels from options/env and builds spawn args and environment. client.ts refactored to delegate spawn configuration to the new module and re-export types. Vitest tests cover canonical env-var precedence, legacy key exclusion, and env rewriting behavior.
Changelog and trajectory records
CHANGELOG.md, .agentworkforce/trajectories/completed/2026-06/traj_*
CHANGELOG entry documents workspace-key and instance-name support. Trajectory summary and JSON record completion of PR review/fix work with decision events and metadata.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

Poem

🐰 A workspace key unlocked the door,
Instance names now stable, no more
Legacy guesses—brokers align
Canonical envs shine bright and fine,
Join any relay, your choice to explore!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.23% 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 'Add explicit broker workspace join options' clearly summarizes the main change: adding workspace-key and instance-name flags/env-vars for broker workspace joining and identification.
Description check ✅ Passed The pull request description covers the key changes (workspace-key, instance-name, harness-driver updates) and includes a test plan checkbox section, but lacks detail on what tests were added/modified and no manual testing completion is indicated.
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 fix/explicit-workspace-broker-instance

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 introduces support for explicit workspace keys and broker instance names across the broker and harness driver, allowing local and cloud brokers to join the same Relay workspace with stable, addressable names. It adds new CLI flags and environment variables, updates the authentication client to handle explicit joins, and updates the harness driver to support these options. A critical issue was identified in crates/broker/src/runtime/init.rs where std::env::set_var is called without an unsafe block, which will cause a compilation error in Rust 1.79+.

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 +17 to +21
if let Some(workspace_key) = cmd.resolved_workspace_key() {
std::env::set_var("AGENT_RELAY_WORKSPACE_KEY", &workspace_key);
std::env::set_var("RELAY_WORKSPACE_KEY", &workspace_key);
std::env::set_var("RELAY_API_KEY", &workspace_key);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

In Rust 1.79+, std::env::set_var is an unsafe function. Calling it without an unsafe block will cause a compilation error (error[E0133]: call to unsafe function is unsafe and requires unsafe function or block). Since this codebase uses a Rust version where set_var is unsafe (as seen in the test suite), these calls must be wrapped in an unsafe block.

    if let Some(workspace_key) = cmd.resolved_workspace_key() {
        unsafe {
            std::env::set_var("AGENT_RELAY_WORKSPACE_KEY", &workspace_key);
            std::env::set_var("RELAY_WORKSPACE_KEY", &workspace_key);
            std::env::set_var("RELAY_API_KEY", &workspace_key);
        }
    }

@kjgbot kjgbot marked this pull request as ready for review June 6, 2026 13:25
@kjgbot
Copy link
Copy Markdown
Contributor Author

kjgbot commented Jun 6, 2026

Consumer-side review (cloud-lead, T4 lane) — no blockers; cloud's env-injection contract is satisfied exactly. Two observations:

  1. Instance-name precedence works for cloud's existing start command (verified, good): cloud's ensureBrokerReady execs init --name <displayName> (legacy flag) while exporting AGENT_RELAY_BROKER_NAME from provisioning. resolved_instance_name() puts the env above legacy --name, so pear's brokerName wins when sent and behavior is unchanged when absent. No cloud-side change needed — this precedence order is the load-bearing detail; please don't reorder it later without a major-version note.

  2. HarnessDriverClient.spawn() promotes legacy RELAY_API_KEY into an explicit --workspace-key join (resolution chain ends at process.env.RELAY_API_KEY, then passes it as the explicit flag). That converts the historically lenient fallback-to-create behavior into fail-loud for any existing harness-driver consumer with a stale RELAY_API_KEY in env — they'll now get a hard startup failure where they used to silently self-heal into a fresh workspace. If intentional, suggest a CHANGELOG line calling it out; otherwise consider leaving RELAY_API_KEY out of the explicit-flag chain (env passthrough only, letting the broker's own legacy-lenient path handle it).

Also confirmed from the cloud/pear assumption side: error contexts explicit workspace key from <SOURCE> was rejected|was rate-limited match pear's classifier substrings, 401/403 vs 429 distinguishable via preserved status, and the env-only sandbox path (no flags) activates strict join with zero clap unknown-arg risk on old-vs-new binary skew.

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.

3 issues found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/harness-driver/src/client.ts">

<violation number="1" location="packages/harness-driver/src/client.ts:490">
P2: Workspace key is passed as a CLI argument, which exposes the secret via process args and startup error logging.</violation>
</file>

<file name="crates/broker/src/cli/mod.rs">

<violation number="1" location="crates/broker/src/cli/mod.rs:262">
P2: `resolved_instance_name` lets blank `--instance-name` override fallback/default naming because it trims after precedence resolution.</violation>

<violation number="2" location="crates/broker/src/cli/mod.rs:280">
P2: Blank `--workspace-key` values are treated as present too early, which can suppress env fallback and silently fall back to workspace creation.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/harness-driver/src/client.ts Outdated
Comment on lines +490 to +491
...(workspaceKey ? ['--workspace-key', workspaceKey] : []),
'--channels',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Workspace key is passed as a CLI argument, which exposes the secret via process args and startup error logging.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/harness-driver/src/client.ts, line 490:

<comment>Workspace key is passed as a CLI argument, which exposes the secret via process args and startup error logging.</comment>

<file context>
@@ -454,9 +473,25 @@ export class HarnessDriverClient {
+      'init',
+      '--instance-name',
+      brokerName,
+      ...(workspaceKey ? ['--workspace-key', workspaceKey] : []),
+      '--channels',
+      channels.join(','),
</file context>
Suggested change
...(workspaceKey ? ['--workspace-key', workspaceKey] : []),
'--channels',
'--channels',

Comment thread crates/broker/src/cli/mod.rs Outdated
Comment on lines +280 to +284
self.workspace_key
.clone()
.or_else(|| std::env::var("AGENT_RELAY_WORKSPACE_KEY").ok())
.map(|key| key.trim().to_string())
.filter(|key| !key.is_empty())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Blank --workspace-key values are treated as present too early, which can suppress env fallback and silently fall back to workspace creation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/broker/src/cli/mod.rs, line 280:

<comment>Blank `--workspace-key` values are treated as present too early, which can suppress env fallback and silently fall back to workspace creation.</comment>

<file context>
@@ -248,6 +257,34 @@ pub(crate) struct InitCommand {
+    }
+
+    pub(crate) fn resolved_workspace_key(&self) -> Option<String> {
+        self.workspace_key
+            .clone()
+            .or_else(|| std::env::var("AGENT_RELAY_WORKSPACE_KEY").ok())
</file context>
Suggested change
self.workspace_key
.clone()
.or_else(|| std::env::var("AGENT_RELAY_WORKSPACE_KEY").ok())
.map(|key| key.trim().to_string())
.filter(|key| !key.is_empty())
self.workspace_key
.as_deref()
.map(str::trim)
.filter(|key| !key.is_empty())
.map(ToOwned::to_owned)
.or_else(|| {
std::env::var("AGENT_RELAY_WORKSPACE_KEY")
.ok()
.map(|key| key.trim().to_string())
.filter(|key| !key.is_empty())
})

@agent-relay-code
Copy link
Copy Markdown
Contributor

Fixed a broker CLI precedence bug in crates/broker/src/cli/mod.rs: explicit --instance-name and legacy --name now override the AGENT_RELAY_BROKER_NAME environment default. Added focused unit tests for instance-name, legacy-name, env, and fallback resolution.

Validated locally:

  • cargo fmt -p agent-relay-broker --check
  • cargo check -p agent-relay-broker
  • cargo test -p agent-relay-broker cli::tests --lib
  • cargo test -p agent-relay-broker relaycast::auth --lib
  • Earlier TypeScript validation before cleanup: npm run build:sdk && npm --prefix packages/harness-driver run check, plus harness-driver nearby Vitest tests.

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 6, 2026

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 applied fixes — committed and pushed d5f7fee to this PR. The notes below describe what changed.

Fixed a broker CLI precedence bug in crates/broker/src/cli/mod.rs: explicit --instance-name and legacy --name now override the AGENT_RELAY_BROKER_NAME environment default. Added focused unit tests for instance-name, legacy-name, env, and fallback resolution.

Validated locally:

  • cargo fmt -p agent-relay-broker --check
  • cargo check -p agent-relay-broker
  • cargo test -p agent-relay-broker cli::tests --lib
  • cargo test -p agent-relay-broker relaycast::auth --lib
  • Earlier TypeScript validation before cleanup: npm run build:sdk && npm --prefix packages/harness-driver run check, plus harness-driver nearby Vitest tests.

@agent-relay-code
Copy link
Copy Markdown
Contributor

Fixed the PR issues I found:

  • Updated CLI broker process matching to recognize --instance-name and --broker-name, not just legacy --name.
  • Updated doctor broker detection for the new --instance-name process form.
  • Propagated AGENT_RELAY_WORKSPACE_KEY alongside RELAY_WORKSPACE_KEY and RELAY_API_KEY for CLI up --workspace-key and dashboard env setup.
  • Added/updated tests for orphan cleanup and workspace-key env propagation.

Verification run:

  • npx vitest run packages/cli/src/cli/commands/core.test.ts packages/cli/src/cli/commands/doctor.test.ts passed.
  • npx prettier --check ... passed.
  • npm --prefix packages/harness-driver run check passed after building SDK output.
  • npm --prefix packages/cli run build passed after building required workspace package outputs.
  • Rust focused test attempt was blocked by sandbox resources: cargo test -p agent-relay-broker relaycast::auth::tests:: -- --nocapture compile was killed with SIGKILL during rustc.

@agent-relay-code
Copy link
Copy Markdown
Contributor

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

Fixed the PR issues I found:

  • Updated CLI broker process matching to recognize --instance-name and --broker-name, not just legacy --name.
  • Updated doctor broker detection for the new --instance-name process form.
  • Propagated AGENT_RELAY_WORKSPACE_KEY alongside RELAY_WORKSPACE_KEY and RELAY_API_KEY for CLI up --workspace-key and dashboard env setup.
  • Added/updated tests for orphan cleanup and workspace-key env propagation.

Verification run:

  • npx vitest run packages/cli/src/cli/commands/core.test.ts packages/cli/src/cli/commands/doctor.test.ts passed.
  • npx prettier --check ... passed.
  • npm --prefix packages/harness-driver run check passed after building SDK output.
  • npm --prefix packages/cli run build passed after building required workspace package outputs.
  • Rust focused test attempt was blocked by sandbox resources: cargo test -p agent-relay-broker relaycast::auth::tests:: -- --nocapture compile was killed with SIGKILL during rustc.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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/cli/mod.rs`:
- Around line 261-277: The resolved_instance_name function currently treats
whitespace-only values (from self.instance_name or AGENT_RELAY_BROKER_NAME) as
present and short-circuits fallback; change the chaining to normalize and filter
out empty/whitespace-only strings before fallback. Specifically, in
resolved_instance_name, map self.instance_name and the env var
(std::env::var("AGENT_RELAY_BROKER_NAME")) to trimmed strings and .filter(|s|
!s.is_empty()) so they become None when blank, then fall back to fallback and
finally unwrap_or_default(), returning the trimmed final result; use the
function name resolved_instance_name to locate the change.

In `@packages/harness-driver/src/client.ts`:
- Around line 456-463: The code is incorrectly treating legacy RELAY_API_KEY as
an explicit --workspace-key by chaining all sources into workspaceKey via
nonEmptyString; split the resolution into two distinct variables (e.g.,
explicitWorkspaceKey = first non-empty of options?.workspaceKey,
options?.env?.AGENT_RELAY_WORKSPACE_KEY, options?.env?.RELAY_WORKSPACE_KEY,
process.env.AGENT_RELAY_WORKSPACE_KEY, process.env.RELAY_WORKSPACE_KEY using
nonEmptyString) and legacyApiKey = first non-empty of
options?.env?.RELAY_API_KEY and process.env.RELAY_API_KEY using nonEmptyString,
then use explicitWorkspaceKey wherever an explicit join is required and only
fall back to legacyApiKey where legacy API-key behavior is intended; apply the
same change to the other resolution sites that use nonEmptyString chains (the
occurrences around the current workspaceKey usage and the similar chains at the
other noted blocks).
🪄 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: 603dfd16-c9bc-433e-a06b-81b00e82f98e

📥 Commits

Reviewing files that changed from the base of the PR and between d67f6de and d5f7fee.

📒 Files selected for processing (8)
  • .agentworkforce/trajectories/active/traj_b1jrutolckfb/trajectory.json
  • CHANGELOG.md
  • crates/broker/src/cli/mod.rs
  • crates/broker/src/relaycast/auth.rs
  • crates/broker/src/runtime/init.rs
  • crates/broker/src/spawner.rs
  • packages/harness-driver/src/client.ts
  • rust_out
💤 Files with no reviewable changes (1)
  • .agentworkforce/trajectories/active/traj_b1jrutolckfb/trajectory.json

Comment thread crates/broker/src/cli/mod.rs
Comment thread packages/harness-driver/src/client.ts Outdated
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.

2 issues found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/harness-driver/src/client.ts">

<violation number="1" location="packages/harness-driver/src/client.ts:490">
P2: Workspace key is passed as a CLI argument, which exposes the secret via process args and startup error logging.</violation>
</file>

<file name="crates/broker/src/cli/mod.rs">

<violation number="1" location="crates/broker/src/cli/mod.rs:280">
P2: Blank `--workspace-key` values are treated as present too early, which can suppress env fallback and silently fall back to workspace creation.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/broker/src/cli/mod.rs Outdated
Comment thread crates/broker/src/cli/mod.rs
@agent-relay-code
Copy link
Copy Markdown
Contributor

Reviewed and fixed PR #1055.

Changes made:

  • Removed accidental rust_out binary artifact.
  • Restored the emptied tracked trajectory JSON.
  • Fixed the new CLI tests so AGENT_RELAY_BROKER_NAME is cleared when the env guard drops, preventing test-order leakage.

Validation run:

  • npm run check --workspace=@agent-relay/harness-driver
  • npm run build --workspace=@agent-relay/harness-driver
  • cargo test -p agent-relay-broker cli::tests
  • cargo test -p agent-relay-broker relaycast::auth::tests

No bot review artifacts were present under .workforce, so there were no external review comments to resolve from the checkout.

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 6, 2026

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 applied fixes — committed and pushed 95b1eb8 to this PR. The notes below describe what changed.

Reviewed and fixed PR #1055.

Changes made:

  • Removed accidental rust_out binary artifact.
  • Restored the emptied tracked trajectory JSON.
  • Fixed the new CLI tests so AGENT_RELAY_BROKER_NAME is cleared when the env guard drops, preventing test-order leakage.

Validation run:

  • npm run check --workspace=@agent-relay/harness-driver
  • npm run build --workspace=@agent-relay/harness-driver
  • cargo test -p agent-relay-broker cli::tests
  • cargo test -p agent-relay-broker relaycast::auth::tests

No bot review artifacts were present under .workforce, so there were no external review comments to resolve from the checkout.

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 6, 2026

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

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 8, 2026

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

@codeant-ai
Copy link
Copy Markdown

codeant-ai Bot commented Jun 8, 2026

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/harness-driver/src/spawn-config.test.ts (1)

6-42: ⚡ Quick win

Consider adding test case for parentEnv.RELAY_API_KEY preservation.

The existing tests cover options.env.RELAY_API_KEY, but a test verifying that parentEnv.RELAY_API_KEY (e.g., from process.env) is also preserved without promotion would provide more complete coverage of the legacy-key behavior.

🧪 Suggested test case
it('preserves parentEnv.RELAY_API_KEY without promoting to workspace-key argv', () => {
  const config = buildBrokerSpawnConfig(
    {
      cwd: '/tmp/my-project',
    },
    'br_test',
    {
      RELAY_API_KEY: 'rk_live_from_process_env',
    }
  );

  expect(config.workspaceKey).toBeUndefined();
  expect(config.args).not.toContain('--workspace-key');
  expect(config.env.RELAY_API_KEY).toBe('rk_live_from_process_env');
});
🤖 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 `@packages/harness-driver/src/spawn-config.test.ts` around lines 6 - 42, Add a
unit test to ensure buildBrokerSpawnConfig preserves parentEnv.RELAY_API_KEY
without promoting it to a workspace-key argv: call buildBrokerSpawnConfig with
no options.env but with a parentEnv object containing RELAY_API_KEY (e.g.,
'rk_live_from_process_env'), then assert config.workspaceKey is undefined,
config.args does not contain '--workspace-key', and config.env.RELAY_API_KEY
equals the parentEnv value; place this alongside the existing tests that
reference buildBrokerSpawnConfig so it verifies legacy key preservation from
parentEnv/process.env.
packages/harness-driver/src/spawn-config.ts (1)

93-98: ⚡ Quick win

Consider documenting RELAY_API_KEY exclusion for clarity.

The workspaceKey resolution chain intentionally excludes RELAY_API_KEY (from both options?.env and parentEnv) to preserve legacy lenient fallback-to-create behavior, while canonical keys (AGENT_RELAY_WORKSPACE_KEY, RELAY_WORKSPACE_KEY) trigger strict explicit-join mode. This design prevents stale legacy keys from causing hard startup failures. A brief inline comment explaining this exclusion would help future maintainers understand the rationale.

📝 Suggested documentation improvement
+  // Resolve workspace key from canonical sources only. RELAY_API_KEY is
+  // intentionally excluded to preserve legacy lenient behavior (fallback-to-create)
+  // while canonical keys trigger strict explicit-join mode (fail on reject/rate-limit).
   const workspaceKey =
     nonEmptyString(options?.workspaceKey) ??
     nonEmptyString(options?.env?.AGENT_RELAY_WORKSPACE_KEY) ??
🤖 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 `@packages/harness-driver/src/spawn-config.ts` around lines 93 - 98, The
workspaceKey resolution intentionally omits RELAY_API_KEY (from options?.env and
parentEnv) to preserve legacy lenient fallback-to-create behavior; add a concise
inline comment next to the workspaceKey assignment (referencing the workspaceKey
constant and the resolution chain using AGENT_RELAY_WORKSPACE_KEY and
RELAY_WORKSPACE_KEY) explaining that RELAY_API_KEY is deliberately excluded so
old/stale legacy keys do not force strict explicit-join mode and cause hard
startup failures.
🤖 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.

Nitpick comments:
In `@packages/harness-driver/src/spawn-config.test.ts`:
- Around line 6-42: Add a unit test to ensure buildBrokerSpawnConfig preserves
parentEnv.RELAY_API_KEY without promoting it to a workspace-key argv: call
buildBrokerSpawnConfig with no options.env but with a parentEnv object
containing RELAY_API_KEY (e.g., 'rk_live_from_process_env'), then assert
config.workspaceKey is undefined, config.args does not contain
'--workspace-key', and config.env.RELAY_API_KEY equals the parentEnv value;
place this alongside the existing tests that reference buildBrokerSpawnConfig so
it verifies legacy key preservation from parentEnv/process.env.

In `@packages/harness-driver/src/spawn-config.ts`:
- Around line 93-98: The workspaceKey resolution intentionally omits
RELAY_API_KEY (from options?.env and parentEnv) to preserve legacy lenient
fallback-to-create behavior; add a concise inline comment next to the
workspaceKey assignment (referencing the workspaceKey constant and the
resolution chain using AGENT_RELAY_WORKSPACE_KEY and RELAY_WORKSPACE_KEY)
explaining that RELAY_API_KEY is deliberately excluded so old/stale legacy keys
do not force strict explicit-join mode and cause hard startup failures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9885000b-cfcd-4dc6-af14-98612eef28a0

📥 Commits

Reviewing files that changed from the base of the PR and between b374792 and 01449d0.

📒 Files selected for processing (3)
  • packages/harness-driver/src/client.ts
  • packages/harness-driver/src/spawn-config.test.ts
  • packages/harness-driver/src/spawn-config.ts

@kjgbot kjgbot merged commit 1301a31 into main Jun 8, 2026
42 checks passed
@kjgbot kjgbot deleted the fix/explicit-workspace-broker-instance branch June 8, 2026 06:11
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