Skip to content

Fix headless broker readiness#855

Merged
khaliqgant merged 3 commits into
mainfrom
codex/fix-broker-headless-reliability-doc
May 15, 2026
Merged

Fix headless broker readiness#855
khaliqgant merged 3 commits into
mainfrom
codex/fix-broker-headless-reliability-doc

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

Summary

  • make agent-relay up --no-dashboard detach by default but return success only after broker API readiness
  • add truthful status --wait-for semantics for RUNNING, STARTING, and STOPPED timeout cases
  • add focused CLI tests for readiness success, timeout, spawn failure, arg preservation, and broker PID diagnostics
  • keep the rationale in trail trajectories instead of a standalone reliability doc

Verification

  • npm exec tsc -- --noEmit --pretty false
  • npm exec vitest -- run src/cli/commands/core.test.ts
  • npm exec eslint -- src/cli/lib/broker-lifecycle.ts src/cli/commands/core.ts src/cli/commands/core.test.ts (0 errors; existing warnings only)
  • git diff --check

@khaliqgant khaliqgant requested a review from willwashburn as a code owner May 15, 2026 10:07
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c909ed13-a89b-49e1-802d-dd17f28a2150

📥 Commits

Reviewing files that changed from the base of the PR and between fc4344a and 5e3424c.

📒 Files selected for processing (5)
  • .trajectories/completed/2026-05/traj_f3arvbmmlomn.json
  • .trajectories/completed/2026-05/traj_f3arvbmmlomn.md
  • .trajectories/index.json
  • src/cli/commands/core.test.ts
  • src/cli/lib/broker-lifecycle.ts
✅ Files skipped from review due to trivial changes (3)
  • .trajectories/completed/2026-05/traj_f3arvbmmlomn.json
  • .trajectories/completed/2026-05/traj_f3arvbmmlomn.md
  • .trajectories/index.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/commands/core.test.ts

📝 Walkthrough
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.15% 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 'Fix headless broker readiness' is concise and clearly summarizes the main change: fixing broker readiness semantics for headless mode.
Description check ✅ Passed The description provides a clear summary of changes and verification steps, matching the template structure with all required sections present and substantively filled.
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 codex/fix-broker-headless-reliability-doc

Comment @coderabbitai help to get the list of available commands and usage tips.

@khaliqgant khaliqgant force-pushed the codex/fix-broker-headless-reliability-doc branch 2 times, most recently from 28234d3 to ccd3440 Compare May 15, 2026 10:43
@khaliqgant khaliqgant force-pushed the codex/fix-broker-headless-reliability-doc branch from ccd3440 to 4da9b34 Compare May 15, 2026 11:12
Copy link
Copy Markdown

@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: 3

🤖 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 @.trajectories/index.json:
- Around line 406-453: The index currently records machine-local absolute paths
for trajectory entries (e.g., the "path" values under keys traj_v1wexlfur5zr,
traj_6sjeohtm3php, traj_4vucir4qvqa2, traj_erzd7j9nto9r, traj_7uznwzoxbao6,
traj_9fdv7hxm0b60, traj_0o6gb2wvk59t); change each "path" value to a
repo-relative path (for example
".trajectories/completed/2026-05/traj_v1wexlfur5zr.json") preserving the
filename and directory structure, and update all similar new entries in this
block to use the same normalization so no absolute /Users/... paths are
committed.

In `@src/cli/lib/broker-lifecycle.ts`:
- Around line 393-411: In childUpArgsForDetachedStart, detect if the original
CLI args (from cliUserArgs(deps)) contain both the background and foreground
flags (using matchesCliOption or hasCliOption) and fail fast instead of silently
preferring one: if both are present throw a clear error (e.g., throw new
Error('Cannot specify both --background and --foreground')) or otherwise return
a failure to the caller, before stripping flags and rebuilding the child argv;
reference the function childUpArgsForDetachedStart and helper functions
matchesCliOption/hasCliOption when adding this validation.
- Around line 1509-1510: The current logic silently coerces invalid or partial
`--wait-for` values (options?.waitFor) into 0 via Number.parseFloat, so update
the validation: before computing waitSeconds/waitMs, verify the raw string is a
valid non-negative decimal number (e.g. trim then match against a regex like
/^\d+(\.\d+)?$/ or similar) and reject anything with extra characters or a
negative sign; if invalid, emit a clear error and exit/fail instead of
continuing. Only call Number.parseFloat and compute waitMs (waitSeconds * 1000)
after the string passes this validation; update the code paths around the
existing waitSeconds and waitMs variables to use the validated value.
🪄 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: 8d990823-71de-4847-a689-b24dda0de924

📥 Commits

Reviewing files that changed from the base of the PR and between a7ef2fc and 4da9b34.

📒 Files selected for processing (19)
  • .trajectories/completed/2026-05/traj_0o6gb2wvk59t.json
  • .trajectories/completed/2026-05/traj_0o6gb2wvk59t.md
  • .trajectories/completed/2026-05/traj_4vucir4qvqa2.json
  • .trajectories/completed/2026-05/traj_4vucir4qvqa2.md
  • .trajectories/completed/2026-05/traj_6sjeohtm3php.json
  • .trajectories/completed/2026-05/traj_6sjeohtm3php.md
  • .trajectories/completed/2026-05/traj_7uznwzoxbao6.json
  • .trajectories/completed/2026-05/traj_7uznwzoxbao6.md
  • .trajectories/completed/2026-05/traj_9fdv7hxm0b60.json
  • .trajectories/completed/2026-05/traj_9fdv7hxm0b60.md
  • .trajectories/completed/2026-05/traj_erzd7j9nto9r.json
  • .trajectories/completed/2026-05/traj_erzd7j9nto9r.md
  • .trajectories/completed/2026-05/traj_v1wexlfur5zr.json
  • .trajectories/completed/2026-05/traj_v1wexlfur5zr.md
  • .trajectories/index.json
  • src/cli/commands/core.test.ts
  • src/cli/commands/core.ts
  • src/cli/lib/broker-lifecycle.ts
  • tests/integration/broker/utils/broker-harness.ts

Comment thread .trajectories/index.json Outdated
Comment thread src/cli/lib/broker-lifecycle.ts
Comment thread src/cli/lib/broker-lifecycle.ts Outdated
Copy link
Copy Markdown

@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 `@src/cli/lib/broker-lifecycle.ts`:
- Around line 1584-1597: The readiness check currently treats a broker as
STARTING when readBrokerStatusDetails returns null because getSession failed,
but readiness should be decided from getStatus() alone; change
readBrokerStatusDetails (or its callers) so it returns status even if session
lookup fails (i.e., make session optional), and update the logic around
statusDetails (and the similar block at 1601-1606) to consider the broker UP
when status exists regardless of session, only attempting to log session
information if session !== undefined; reference getStatus(), getSession(),
readBrokerStatusDetails, and the readiness.statusDetails variable when making
this change.
- Around line 335-356: The orphan-matching is too fuzzy: using
path.basename(projectRoot) via brokerName and the fallback
process.command.includes(projectRoot) can match unrelated repos; tighten
matching in the broker detection logic (around brokerName, candidates,
deps.execCommand, parsePsAuxLine, isBrokerExecutableCommand,
commandHasBrokerName) so we only pick processes whose executable or
working-directory path exactly corresponds to the project root. Replace the
basename fuzzy check with a stricter check that compares the resolved
projectRoot path (path.resolve(projectRoot)) against the process command or the
command's executable path (the first token from process.command) using path
separators or an exact suffix match (e.g., endsWith or contains
`${resolvedProjectRoot}${path.sep}`) and in the fallback avoid simple
.includes(projectRoot) in favor of the same boundary-aware comparison to prevent
matching sibling directories before sending SIGTERM.
🪄 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: c288e147-4ed9-420c-976d-d32f2fe540db

📥 Commits

Reviewing files that changed from the base of the PR and between 4da9b34 and fc4344a.

📒 Files selected for processing (5)
  • .trajectories/completed/2026-05/traj_4chzkm724ufo.json
  • .trajectories/completed/2026-05/traj_4chzkm724ufo.md
  • .trajectories/index.json
  • src/cli/commands/core.test.ts
  • src/cli/lib/broker-lifecycle.ts
✅ Files skipped from review due to trivial changes (2)
  • .trajectories/completed/2026-05/traj_4chzkm724ufo.json
  • .trajectories/index.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cli/commands/core.test.ts

Comment thread src/cli/lib/broker-lifecycle.ts Outdated
Comment thread src/cli/lib/broker-lifecycle.ts
@khaliqgant khaliqgant merged commit cbc70b0 into main May 15, 2026
45 checks passed
@khaliqgant khaliqgant deleted the codex/fix-broker-headless-reliability-doc branch May 15, 2026 12:38
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.

1 participant