Skip to content

Commit 1301a31

Browse files
authored
Add explicit broker workspace join options
1 parent d67f6de commit 1301a31

11 files changed

Lines changed: 694 additions & 134 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Trajectory: Review and fix PR 1055
2+
3+
> **Status:** ✅ Completed
4+
> **Confidence:** 86%
5+
> **Started:** June 6, 2026 at 01:49 PM
6+
> **Completed:** June 6, 2026 at 02:05 PM
7+
8+
---
9+
10+
## Summary
11+
12+
Reviewed PR 1055, removed accidental rust_out artifact, restored emptied trajectory data, and fixed CLI env-var test cleanup. Verified harness-driver typecheck/build and focused broker CLI/auth tests.
13+
14+
**Approach:** Standard approach
15+
16+
---
17+
18+
## Key Decisions
19+
20+
### Removed accidental binary artifact and restored emptied trajectory
21+
22+
- **Chose:** Removed accidental binary artifact and restored emptied trajectory
23+
- **Reasoning:** PR diff added rust_out and emptied an active tracked trajectory; AGENTS.md requires trajectories to remain tracked, and generated binaries do not belong in the PR.
24+
25+
### Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop
26+
27+
- **Chose:** Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop
28+
- **Reasoning:** The new tests cleared the shared env var before each test but leaked it after the final test, which can affect later tests in the same process.
29+
30+
---
31+
32+
## Chapters
33+
34+
### 1. Work
35+
36+
_Agent: default_
37+
38+
- Removed accidental binary artifact and restored emptied trajectory: Removed accidental binary artifact and restored emptied trajectory
39+
- Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop: Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"id": "traj_1llfpjvd9m7k",
3+
"version": 1,
4+
"task": {
5+
"title": "Review and fix PR 1055"
6+
},
7+
"status": "completed",
8+
"startedAt": "2026-06-06T13:49:15.971Z",
9+
"completedAt": "2026-06-06T14:05:43.957Z",
10+
"agents": [
11+
{
12+
"name": "default",
13+
"role": "lead",
14+
"joinedAt": "2026-06-06T14:05:29.768Z"
15+
}
16+
],
17+
"chapters": [
18+
{
19+
"id": "chap_4iax8jv8u74r",
20+
"title": "Work",
21+
"agentName": "default",
22+
"startedAt": "2026-06-06T14:05:29.768Z",
23+
"endedAt": "2026-06-06T14:05:43.957Z",
24+
"events": [
25+
{
26+
"ts": 1780754729769,
27+
"type": "decision",
28+
"content": "Removed accidental binary artifact and restored emptied trajectory: Removed accidental binary artifact and restored emptied trajectory",
29+
"raw": {
30+
"question": "Removed accidental binary artifact and restored emptied trajectory",
31+
"chosen": "Removed accidental binary artifact and restored emptied trajectory",
32+
"alternatives": [],
33+
"reasoning": "PR diff added rust_out and emptied an active tracked trajectory; AGENTS.md requires trajectories to remain tracked, and generated binaries do not belong in the PR."
34+
},
35+
"significance": "high"
36+
},
37+
{
38+
"ts": 1780754730821,
39+
"type": "decision",
40+
"content": "Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop: Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop",
41+
"raw": {
42+
"question": "Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop",
43+
"chosen": "Made CLI env-var test guard clear AGENT_RELAY_BROKER_NAME on drop",
44+
"alternatives": [],
45+
"reasoning": "The new tests cleared the shared env var before each test but leaked it after the final test, which can affect later tests in the same process."
46+
},
47+
"significance": "high"
48+
}
49+
]
50+
}
51+
],
52+
"retrospective": {
53+
"summary": "Reviewed PR 1055, removed accidental rust_out artifact, restored emptied trajectory data, and fixed CLI env-var test cleanup. Verified harness-driver typecheck/build and focused broker CLI/auth tests.",
54+
"approach": "Standard approach",
55+
"confidence": 0.86
56+
},
57+
"commits": [],
58+
"filesChanged": [],
59+
"projectId": "AgentWorkforce/relay",
60+
"tags": [],
61+
"_trace": {
62+
"startRef": "d5f7fee457c2d7a991bdb9167ad2c896aa0987e4",
63+
"endRef": "d5f7fee457c2d7a991bdb9167ad2c896aa0987e4"
64+
}
65+
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `agent-relay-broker` and `@agent-relay/harness-driver` accept explicit workspace keys and broker instance names, so local and cloud brokers can join the same Relay workspace with stable, addressable names.
1213
- `@agent-relay/harnesses` adds a `grok` PTY harness for the Grok CLI, including Relaycast MCP support for spawned agents.
1314
- `@agent-relay/harnesses` is now published to npm, so SDK consumers can install the prebuilt PTY harnesses and harness-authoring helpers.
1415
- `agent-relay drive` and `agent-relay passthrough` add adaptive predictive echo so typing stays responsive when driving a high-latency or remote agent, and stays invisible on fast local links.

crates/broker/src/cli/mod.rs

Lines changed: 141 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ impl Commands {
7272
let pid = std::process::id();
7373
match self {
7474
Commands::Init(cmd) => {
75-
let name = cmd.name.trim();
75+
let name = cmd.resolved_instance_name(None);
7676
if !name.is_empty() {
77-
return name.to_string();
77+
return name;
7878
}
7979
std::env::current_dir()
8080
.ok()
@@ -215,9 +215,18 @@ pub(crate) struct McpArgsCommand {
215215

216216
#[derive(Debug, clap::Args)]
217217
pub(crate) struct InitCommand {
218-
#[arg(long, default_value = "")]
218+
/// Legacy broker instance name flag. Prefer --instance-name.
219+
#[arg(long, default_value = "", alias = "broker-name")]
219220
pub(crate) name: String,
220221

222+
/// Stable broker instance name within the Relay workspace.
223+
#[arg(long = "instance-name")]
224+
pub(crate) instance_name: Option<String>,
225+
226+
/// Join an existing Relay workspace instead of creating a fresh one.
227+
#[arg(long = "workspace-key")]
228+
pub(crate) workspace_key: Option<String>,
229+
221230
#[arg(long, default_value = "general")]
222231
pub(crate) channels: String,
223232

@@ -248,6 +257,135 @@ pub(crate) struct InitCommand {
248257
pub(crate) state_dir: Option<String>,
249258
}
250259

260+
impl InitCommand {
261+
pub(crate) fn resolved_instance_name(&self, fallback: Option<&str>) -> String {
262+
fn non_empty_trimmed(value: &str) -> Option<String> {
263+
let trimmed = value.trim();
264+
if trimmed.is_empty() {
265+
None
266+
} else {
267+
Some(trimmed.to_string())
268+
}
269+
}
270+
271+
self.instance_name
272+
.as_deref()
273+
.and_then(non_empty_trimmed)
274+
.or_else(|| non_empty_trimmed(&self.name))
275+
.or_else(|| {
276+
std::env::var("AGENT_RELAY_BROKER_NAME")
277+
.ok()
278+
.and_then(|name| non_empty_trimmed(&name))
279+
})
280+
.or_else(|| fallback.and_then(non_empty_trimmed))
281+
.unwrap_or_default()
282+
}
283+
284+
pub(crate) fn resolved_workspace_key(&self) -> Option<String> {
285+
self.workspace_key
286+
.clone()
287+
.or_else(|| std::env::var("AGENT_RELAY_WORKSPACE_KEY").ok())
288+
.map(|key| key.trim().to_string())
289+
.filter(|key| !key.is_empty())
290+
}
291+
}
292+
293+
#[cfg(test)]
294+
mod tests {
295+
use super::*;
296+
use std::sync::Mutex;
297+
298+
static BROKER_NAME_ENV_MUTEX: Mutex<()> = Mutex::new(());
299+
300+
struct BrokerNameEnvGuard {
301+
_guard: std::sync::MutexGuard<'static, ()>,
302+
}
303+
304+
impl Drop for BrokerNameEnvGuard {
305+
fn drop(&mut self) {
306+
std::env::remove_var("AGENT_RELAY_BROKER_NAME");
307+
}
308+
}
309+
310+
fn broker_name_env_guard() -> BrokerNameEnvGuard {
311+
let guard = BROKER_NAME_ENV_MUTEX.lock().unwrap();
312+
std::env::remove_var("AGENT_RELAY_BROKER_NAME");
313+
BrokerNameEnvGuard { _guard: guard }
314+
}
315+
316+
fn init_command(name: &str, instance_name: Option<&str>) -> InitCommand {
317+
InitCommand {
318+
name: name.to_string(),
319+
instance_name: instance_name.map(ToOwned::to_owned),
320+
workspace_key: None,
321+
channels: "general".to_string(),
322+
api_port: 0,
323+
api_bind: "127.0.0.1".to_string(),
324+
persist: false,
325+
state_dir: None,
326+
}
327+
}
328+
329+
#[test]
330+
fn instance_name_flag_overrides_legacy_name_and_env() {
331+
let _guard = broker_name_env_guard();
332+
std::env::set_var("AGENT_RELAY_BROKER_NAME", "env-name");
333+
334+
let command = init_command("legacy-name", Some("instance-name"));
335+
336+
assert_eq!(
337+
command.resolved_instance_name(Some("fallback")),
338+
"instance-name"
339+
);
340+
}
341+
342+
#[test]
343+
fn legacy_name_flag_overrides_env_default() {
344+
let _guard = broker_name_env_guard();
345+
std::env::set_var("AGENT_RELAY_BROKER_NAME", "env-name");
346+
347+
let command = init_command("legacy-name", None);
348+
349+
assert_eq!(
350+
command.resolved_instance_name(Some("fallback")),
351+
"legacy-name"
352+
);
353+
}
354+
355+
#[test]
356+
fn env_broker_name_overrides_fallback_only() {
357+
let _guard = broker_name_env_guard();
358+
std::env::set_var("AGENT_RELAY_BROKER_NAME", "env-name");
359+
360+
let command = init_command("", None);
361+
362+
assert_eq!(command.resolved_instance_name(Some("fallback")), "env-name");
363+
}
364+
365+
#[test]
366+
fn blank_instance_name_falls_through_to_legacy_name() {
367+
let _guard = broker_name_env_guard();
368+
std::env::set_var("AGENT_RELAY_BROKER_NAME", "env-name");
369+
370+
let command = init_command("legacy-name", Some(" "));
371+
372+
assert_eq!(
373+
command.resolved_instance_name(Some("fallback")),
374+
"legacy-name"
375+
);
376+
}
377+
378+
#[test]
379+
fn empty_instance_name_and_blank_env_fall_through_to_fallback() {
380+
let _guard = broker_name_env_guard();
381+
std::env::set_var("AGENT_RELAY_BROKER_NAME", " ");
382+
383+
let command = init_command("", Some(""));
384+
385+
assert_eq!(command.resolved_instance_name(Some("fallback")), "fallback");
386+
}
387+
}
388+
251389
#[derive(Debug, clap::Args, Clone)]
252390
pub(crate) struct PtyCommand {
253391
pub(crate) cli: String,

0 commit comments

Comments
 (0)