fix(control-plane): negotiate stale daemons safely#354
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
Warning Review limit reached
Next review available in: 34 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR makes ChangesControl-plane negotiation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant RelayfileControlPlaneClient
participant RelayfileDaemon
participant DaemonProcess
RelayfileControlPlaneClient->>RelayfileDaemon: hello without API-version header
RelayfileDaemon-->>RelayfileControlPlaneClient: current and supported API versions
RelayfileControlPlaneClient->>DaemonProcess: stop stale daemon and spawn replacement
DaemonProcess-->>RelayfileControlPlaneClient: readiness through repeated hello calls
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
Relayfile Eval ReviewRun: Passed: 4 | Needs human: 0 | Reviewable: 0 | Missing output: 0 | Failed: 0 | Skipped: 0 Human Review CasesNo reviewable human-review cases captured Relayfile output. |
There was a problem hiding this comment.
Code Review
This pull request implements unversioned discovery for the control-plane API via the GET /v1/hello endpoint, enabling clients to negotiate compatibility and automatically replace stale daemons when a newer local binary is available. Feedback on the changes suggests improving error handling in the stale-daemon detection logic to gracefully handle environments where lsof is missing or fails to execute, such as on Windows or minimal Docker containers, by throwing a more descriptive error.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const result = await this.runCommand('lsof', ['-t', '--', this.socketPath], 1000); | ||
| const pids = [ | ||
| ...new Set( | ||
| (result?.code === 0 ? result.stdout : '') | ||
| .split(/\s+/) | ||
| .map((value) => Number.parseInt(value, 10)) | ||
| .filter((pid) => Number.isSafeInteger(pid) && pid > 1 && pid !== process.pid) | ||
| ), | ||
| ]; |
There was a problem hiding this comment.
If the lsof command is not installed or fails to execute (which is common in minimal Docker environments or on Windows), runCommand will return undefined. Currently, this results in an empty pids array, throwing a generic and potentially misleading error: could not identify the process serving ....
Checking if result is undefined allows us to throw a much more descriptive error, explaining that lsof failed to execute and noting that automatic stale-daemon replacement is not supported on Windows.
const result = await this.runCommand('lsof', ['-t', '--', this.socketPath], 1000);
if (result === undefined) {
throw new Error(
'failed to execute lsof to detect stale daemons. If you are on Windows, automatic stale-daemon replacement is not supported. Otherwise, please ensure lsof is installed and available in your PATH.'
);
}
const pids = [
...new Set(
(result.code === 0 ? result.stdout : '')
.split(/\s+/)
.map((value) => Number.parseInt(value, 10))
.filter((pid) => Number.isSafeInteger(pid) && pid > 1 && pid !== process.pid)
),
];There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c5f57f8867
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| private async stopStaleDaemon(): Promise<void> { | ||
| const result = await this.runCommand('lsof', ['-t', '--', this.socketPath], 1000); |
There was a problem hiding this comment.
Avoid requiring an undeclared lsof executable
In supported Linux environments where lsof is not installed (including the reviewed container), runCommand resolves undefined, so this produces an empty PID list and every otherwise-eligible stale-daemon replacement fails with VERSION_INCOMPATIBLE. Because the package declares only a Node version requirement and does not provision or document lsof, use a process-identification mechanism that is available by default or provide a fallback before advertising automatic replacement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
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 `@openapi/relayfile-control-plane-v1.openapi.yaml`:
- Around line 18-23: Remove the ApiVersionHeader and ApiVersionQuery references
from the unversioned discovery GET operation so requests with any version remain
unconstrained and valid, while preserving the endpoint’s existing discovery
behavior.
In `@packages/client/src/client.ts`:
- Around line 149-153: Update TRANSIENT_CONNECTION_CODES, used by
isTransientConnectionCode(), to include ECONNRESET and EPIPE so startup
readiness polling retries both socket errors. Add regression coverage for these
codes in both request-error and response-stream error paths.
🪄 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: 50caf4a7-942d-436a-8611-c328e41f6650
⛔ Files ignored due to path filters (1)
packages/client/src/generated/control-plane.tsis excluded by!**/generated/**
📒 Files selected for processing (6)
cmd/relayfile-cli/control_plane.gocmd/relayfile-cli/control_plane_test.goopenapi/relayfile-control-plane-v1.openapi.yamlpackages/client/CHANGELOG.mdpackages/client/src/client.test.tspackages/client/src/client.ts
Summary
Validation
go test ./... -count=1go test ./cmd/relayfile-cli -run TestControlPlane -count=1npm run typecheck --workspace=@relayfile/clientnpm run test --workspace=@relayfile/clientRELAYFILE_BIN=$PWD/bin/relayfile-cli npm run test --workspace=@relayfile/client(19/19, including real-daemon contracts)npm run build --workspace=@relayfile/clientmake build LDFLAGS="-s -w -X main.relayfileVersion=0.10.26"