Skip to content

fix(broker): verify worker process before spawn success - #1429

Draft
khaliqgant wants to merge 4 commits into
mainfrom
fix/node-up-enrollment-precedence-and-spawn-reliability
Draft

fix(broker): verify worker process before spawn success#1429
khaliqgant wants to merge 4 commits into
mainfrom
fix/node-up-enrollment-precedence-and-spawn-reliability

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Aug 4, 2026

Copy link
Copy Markdown
Member

Fixes the silent `node agent spawn` failure hit repeatedly today across 3 machines: the CLI reports "Spawned X (codex, pty)." success while the spawned worker process has already exited (e.g. a wrapper that can't launch its harness) — `Command::spawn` only proves the wrapper was created, not that it survived.

Adds a brief (250ms) stability window after spawn that non-blockingly checks the child is still alive via `try_wait()` before reporting success. If it already exited, the stale registry entry is removed and the real error (exit status + log path) is returned instead of letting `node agent list` briefly advertise a dead process.

Companion fix for Bug A (workspace-enrollment precedence overriding an explicit `RELAY_WORKSPACE_KEY`) is being worked separately.

Test plan

  • `cargo test --package agent-relay-broker worker::` — 62/62, 4 consecutive clean runs
  • 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, confirms no stale agent is listed

Review in cubic

claude and others added 4 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 4, 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: dada0ea1-8808-4546-8547-7b4b2c0992d1

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.

2 participants