Skip to content

fix(control-plane): negotiate stale daemons safely#354

Merged
khaliqgant merged 3 commits into
mainfrom
fix/control-plane-hello-negotiation
Jul 17, 2026
Merged

fix(control-plane): negotiate stale daemons safely#354
khaliqgant merged 3 commits into
mainfrom
fix/control-plane-hello-negotiation

Conversation

@khaliqgant

@khaliqgant khaliqgant commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

  • make GET /v1/hello unconditional discovery and keep version gating on every other control-plane endpoint
  • omit the version header on client hello, classify startup failures so API incompatibility fails immediately, and include actionable daemon/binary/restart details
  • conservatively stop the exact stale socket owner and start a newer API-compatible installed binary only when autoStart permits lifecycle management
  • keep the OpenAPI contract, generated types, changelog, and Go/TypeScript regression coverage aligned

Validation

  • go test ./... -count=1
  • go test ./cmd/relayfile-cli -run TestControlPlane -count=1
  • npm run typecheck --workspace=@relayfile/client
  • npm run test --workspace=@relayfile/client
  • RELAYFILE_BIN=$PWD/bin/relayfile-cli npm run test --workspace=@relayfile/client (19/19, including real-daemon contracts)
  • npm run build --workspace=@relayfile/client
  • make build LDFLAGS="-s -w -X main.relayfileVersion=0.10.26"
  • manual v0.10.19/API-v1 daemon to v0.10.26/API-v3 managed-restart E2E passed
  • Prettier check and control-plane OpenAPI codegen passed

Review in cubic

@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@khaliqgant, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a2fb8fab-7d9d-47c0-9383-e5240501a9a4

📥 Commits

Reviewing files that changed from the base of the PR and between f3c5801 and 7c70068.

⛔ Files ignored due to path filters (1)
  • packages/client/src/generated/control-plane.ts is excluded by !**/generated/**
📒 Files selected for processing (3)
  • openapi/relayfile-control-plane-v1.openapi.yaml
  • packages/client/src/client.test.ts
  • packages/client/src/client.ts
📝 Walkthrough

Walkthrough

The PR makes /v1/hello unversioned, updates client discovery and error classification, adds transient retry handling, enables replacement of eligible stale daemons, and bumps packages to 0.10.27-rc.0.

Changes

Control-plane negotiation

Layer / File(s) Summary
Unversioned discovery contract
cmd/relayfile-cli/control_plane.go, cmd/relayfile-cli/control_plane_test.go, openapi/relayfile-control-plane-v1.openapi.yaml
GET hello ignores API-version inputs and no longer reports version incompatibility; tests and OpenAPI documentation reflect the contract.
Discovery transport and typed errors
packages/client/src/client.ts
Client hello requests omit the API-version header and use a fresh connection; transport errors now identify transient failures.
Negotiation, retries, and daemon replacement
packages/client/src/client.ts, packages/client/src/client.test.ts, packages/client/CHANGELOG.md
Startup polling distinguishes incompatible and transient failures, reports detailed version errors, replaces eligible stale daemons, and validates lifecycle behavior.
Release candidate metadata
package.json, packages/*/package.json
Package versions and related SDK dependencies are updated to 0.10.27-rc.0.

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
Loading

Poem

I’m a rabbit with a socket to tend,
Hello hops first, before versions can bend.
Old daemons make way, new ones arise,
Transient bumps get retrying replies.
The control plane now greets clear skies!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly reflects the main control-plane/client changes around safe stale-daemon negotiation.
Description check ✅ Passed The description matches the changeset and summarizes the control-plane, client, docs, and test updates accurately.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/control-plane-hello-negotiation

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.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

Relayfile Eval Review

Run: .relayfile/evals/runs/2026-07-17T09-20-28-386Z-HEAD-provider
Mode: provider
Git SHA: 15eceed

Passed: 4 | Needs human: 0 | Reviewable: 0 | Missing output: 0 | Failed: 0 | Skipped: 0

Human Review Cases

No reviewable human-review cases captured Relayfile output.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/client/src/client.ts Outdated
Comment on lines +448 to +456
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)
),
];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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)
      ),
    ];

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/client/src/client.ts Outdated
}

private async stopStaleDaemon(): Promise<void> {
const result = await this.runCommand('lsof', ['-t', '--', this.socketPath], 1000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@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

📥 Commits

Reviewing files that changed from the base of the PR and between a29bc00 and c5f57f8.

⛔ Files ignored due to path filters (1)
  • packages/client/src/generated/control-plane.ts is excluded by !**/generated/**
📒 Files selected for processing (6)
  • cmd/relayfile-cli/control_plane.go
  • cmd/relayfile-cli/control_plane_test.go
  • openapi/relayfile-control-plane-v1.openapi.yaml
  • packages/client/CHANGELOG.md
  • packages/client/src/client.test.ts
  • packages/client/src/client.ts

Comment thread openapi/relayfile-control-plane-v1.openapi.yaml Outdated
Comment thread packages/client/src/client.ts Outdated
@khaliqgant
khaliqgant merged commit 889df50 into main Jul 17, 2026
10 checks passed
@khaliqgant
khaliqgant deleted the fix/control-plane-hello-negotiation branch July 17, 2026 09:22
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