Skip to content

fix(broker): confirm fleet spawn success - #1431

Draft
khaliqgant wants to merge 5 commits into
mainfrom
fix/1430-fleet-spawn-confirmation
Draft

fix(broker): confirm fleet spawn success#1431
khaliqgant wants to merge 5 commits into
mainfrom
fix/1430-fleet-spawn-confirmation

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

  • propagate the verified WorkerRegistry::spawn result out of spawn_worker_from_request
  • resolve fleet spawn:<harness> invocations from that result instead of bare registry-key presence
  • return spawn_failed: <detail> with the startup exit status and worker log path from fix(broker): verify worker process before spawn success #1429's confirmation path
  • cover both a real native sidecar that exits during the stability window and a dead-but-still-registered worker

Dependency

Depends on #1429 and must not merge before #1429. This branch is stacked directly on #1429's head commit because it reuses the process-stability confirmation introduced there.

Fixes #1430.

Validation

  • env -u AGENT_RELAY_MCP_COMMAND cargo test --package agent-relay-broker — 855 passed, 0 failed, 4 ignored; integration targets also passed
  • env -u AGENT_RELAY_MCP_COMMAND cargo clippy --package agent-relay-broker --lib -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

Note: the inherited worker environment sets AGENT_RELAY_MCP_COMMAND; leaving it set makes 12 existing tests expect npx but observe the injected local Node command. Unsetting that development override gives the repository's neutral test environment and the full green result above.

Review in cubic

claude and others added 5 commits August 4, 2026 10:46
`agent-relay up` / `node up` hand-rolled a narrower workspace chain than the
SDK: flag -> env -> repository pin -> give up, with a `RELAY_NODE_TOKEN`
short-circuit at the top. Two failures fell out of it.

A Cloud enrollment set `RELAY_NODE_TOKEN` and no workspace key, so the pin was
skipped and the broker, left with no key candidates, minted a fresh workspace —
re-homing an enrolled node out of its repository's workspace. And a fresh
directory never consulted the machine-global store, so a first start minted a
new workspace even when the machine already had an active one selected.

Both now resolve through one ladder, documented in `resolveWorkspaceSelection`
and in the CLI README:

  1. --workspace-key / --wk
  2. RELAY_WORKSPACE_KEY > AGENT_RELAY_WORKSPACE_KEY > RELAY_API_KEY
  3. <project>/.agentworkforce/relay/workspace-key.json
  4. the active entry in ~/.agentworkforce/relay/workspaces.json
  5. create a workspace — only when nothing above resolves

The repository pin always outranks the machine-global entry, and a node token
selects node identity only, so it no longer suppresses steps 1-4. Startup
prints the winning source (flag name, variable, or path — never key material)
and says explicitly when it created a workspace rather than joined one.

Each start now records the resolved workspace id on the pin, so a later start
can detect a stored enrollment pointing at a different workspace and stop with
both source paths named instead of silently choosing one.

Fixes #1406
Fixes #1378

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P5FD3oEnWbMbAhjsdtmmiP
agent-relay node agent spawn could report success while the spawned
worker process had already exited (e.g. a wrapper that fails to
launch its harness) — Command::spawn only proves the wrapper was
created, not that it survived. Add a brief stability window after
spawn that non-blockingly checks the child is still alive before
reporting success; if it already exited, remove the stale registry
entry and return the real error (exit status + log path) instead of
letting node agent list briefly advertise a dead process.

Verified:
- cargo test --package agent-relay-broker worker:: (62/62, 4 consecutive
  clean runs, plus 5 isolated runs of the specific new tests)
- Real integration test: RELAY_INTEGRATION_REAL_CLI=1 node --test
  tests/integration/broker/dist/cli-spawn.test.js (missing-CLI
  rejection path, 21.5s, real broker)
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 54926a21-e7c7-4f59-9036-8e34fe3b2380

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

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.

fleet spawn:<harness> action reports {spawned:true} without confirming the worker actually survived

2 participants