fix(cli): capture orchestrator harness for the detached broker#1075
fix(cli): capture orchestrator harness for the detached broker#1075willwashburn wants to merge 2 commits into
Conversation
relay#1069 made the broker forward its detected harness to the relaycast backend, but server telemetry still records harness="unknown" for 100% of Rust-broker traffic. Root cause: the broker is launched detached (its own session via setsid), so by the time it runs `detect_orchestrator_harness` its parent is the init process and the process-tree walk finds no claude-code / codex / cursor ancestor. The forwarding works — it just forwards "unknown". The `agent-relay` CLI, however, is still in-process under the harness when `up` runs. Detect the harness there and stamp `AGENT_RELAY_ORCHESTRATOR_HARNESS` into the env passed to the broker (the established pattern for handing values to the broker — see AGENT_RELAY_STATE_DIR). The detached broker reads env before walking the process tree, so it now forwards the real harness as the `X-Relaycast-Harness` header / `?harness=` query, and the agents it spawns inherit it too. An explicit value already in the env wins — including the re-invoked detached `up` inheriting ours, so detection runs once. Extracted as `ensureOrchestratorHarnessEnv(env, detect?)` with an injectable detector so the behavior is unit-tested without depending on the real process tree (+4 tests). CLI tsc + eslint clean; broker-lifecycle suite green (17 tests). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds ensureOrchestratorHarnessEnv to detect and stamp the orchestrator harness into process env; runUpCommand invokes it at startup so the detached broker inherits the harness. Tests cover stamping, unknown handling, preserving existing env, and detector access to env-derived keys. ChangesOrchestrator Harness Propagation
Sequence DiagramsequenceDiagram
participant runUpCommand
participant ensureFunc as ensureOrchestratorHarnessEnv
participant detectFunc as detectOrchestratorHarness
participant env as ProcessEnv
runUpCommand->>ensureFunc: ensureOrchestratorHarnessEnv(deps.env)
ensureFunc->>detectFunc: detect(env)
detectFunc-->>ensureFunc: orchestrator harness
alt harness !== UNKNOWN and env key not set
ensureFunc->>env: env[ORCHESTRATOR_HARNESS_ENV] = harness
else harness === UNKNOWN or env key already set
ensureFunc-->>env: no change
end
ensureFunc-->>runUpCommand: return
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
Your free trial PR review limit of 300 PRs has been reached. Please upgrade your plan to continue using CodeAnt AI. |
|
Closing as redundant. |
Problem
relay#1069 made the broker forward its detected harness to the relaycast backend, but server telemetry (PostHog 296966) still records
harness: "unknown"for ~100% of Rust-broker traffic — verified on v8.3.2/v8.3.3 brokers (@relaycast/sdk-rust 2.3.0).Root cause: the broker is launched detached (its own session via
setsid—broker-lifecycle.tsspawns it withdetached: true). By the time the broker runsdetect_orchestrator_harness, its parent is the init process, so the parent-PID walk finds noclaude-code/codex/cursorancestor. #1069's forwarding works correctly — it just forwards"unknown".The asymmetry this explains:
@relaycast/sdk)claude-code,codex✅launchd/init ✗unknown❌Fix
The
agent-relayCLI is still in-process under the harness whenupis invoked. Detect the harness there and stampAGENT_RELAY_ORCHESTRATOR_HARNESSinto the env handed to the broker — the established pattern for passing values to the broker (cf.AGENT_RELAY_STATE_DIR). The detached broker checks env before walking the process tree (detect_orchestrator_harnessincrates/broker/src/telemetry.rs), so it now forwards the real harness, and the agents it spawns inherit it too.ensureOrchestratorHarnessEnv(env, detect?)helper, called at the top ofrunUpCommandso both the background (detached re-invoke) and foreground paths inherit it.upinheriting ours, so detection runs once and isn't clobbered.detectis injectable → unit-tested without depending on the real process tree.Tests
broker-lifecycle.test.ts: +4 cases (stamps detected harness; ignoresunknown; respects explicit value; threads env to the real detector viaRELAYCAST_HARNESS). Suite green (17 tests).tsc --noEmitclean;eslintclean (the 6 pre-existing warnings are unrelated, inrefreshDashboardAssetsIfStale).Rollout
Ships in the next
agent-relayrelease. After adoption,sdk-rustrows in 296966 should flip fromunknownto the real harness. This is the second half of the harness fix (forwarding plumbing #1069 + this detection capture).🤖 Generated with Claude Code