Skip to content

fix(mcpx): honour a cancelled context in EnsureDaemon (#284) - #285

Merged
dezren39 merged 1 commit into
mainfrom
creator/284-ensure-daemon-cancel
Oct 18, 2026
Merged

dezren39 merged 1 commit into
mainfrom
creator/284-ensure-daemon-cancel

Conversation

@dezren39

@dezren39 dezren39 commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Fixes #284.

What

EnsureDaemon (pkgs/mcpx/internal/cli/client.go) ignored a cancelled context: a Ping that failed because the context was cancelled was read as "no daemon", so it spawned a daemon the caller no longer wanted, and the readiness poll (which never selected on ctx.Done()) waited out the full autostart.connectTimeout — 20s by default — before failing with daemon did not become ready instead of context.Canceled.

  • Check ctx.Err() at the top of EnsureDaemon and after each failed Ping, before treating the failure as absence.
  • The poll loop now selects on ctx.Done() alongside the poll interval and returns ctx.Err().

Verification

  • Reproduced on main 228019a1 before the fix: already-cancelled context → fake daemon spawned, 3.03s waited (the configured timeout), wrong error.
  • New regression tests in internal/cli/ensuredaemon_test.go:
    • TestEnsureDaemonAlreadyCancelledContext — prompt context.Canceled, no spawn.
    • TestEnsureDaemonCancelledWhileWaiting — cancel at 200ms against a 30s timeout returns promptly (ablation: pre-fix this took 30.03s and returned the timeout error).
    • TestEnsureDaemonNeverReadyStillTimesOut — uncancelled behaviour unchanged: spawns, waits the timeout, same error.
  • Full go test ./internal/cli/ passes; go build ./... clean; go vet clean; changed files gofmt-clean (pre-existing consumer.go formatting drift on main left untouched).

Same defect is tracked for the dezren39/nix copy as dezren39/darwin-nix#233; the fix here follows that issue's suggested approach.

Summary by CodeRabbit

  • Bug Fixes
    • Daemon startup now responds promptly when an operation is cancelled, including while waiting for the daemon to become ready.
    • Existing startup timeout behavior remains in place when the daemon does not become ready.

EnsureDaemon never checked ctx.Err(): a ping that failed because the
caller's context was cancelled was read as 'no daemon', so it spawned
a daemon anyway and the readiness poll waited out the full
autostart.connectTimeout (20s by default) before failing with
'daemon did not become ready'.

Check ctx.Err() up front and after each failed ping, and select on
ctx.Done() in the poll loop. Regression tests cover the
already-cancelled case, cancellation while waiting, and the unchanged
never-ready timeout.
@dezren39
dezren39 requested a review from a team as a code owner October 18, 2026 12:59
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-18T12:59:23.539857Z 39d5944 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 49cf4586-59ac-4f09-b185-0894e3d9c032
📥 Commits

Reviewing files that changed from the base of the PR and between 9f3aee8 and 39d5944.

📒 Files selected for processing: 2
  • pkgs/mcpx/internal/cli/client.go
  • pkgs/mcpx/internal/cli/ensuredaemon_test.go
+-----------------------------+
| I wish to make a complaint. |
+-----------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@dezren39
dezren39 merged commit 62ec68b into main Oct 18, 2026
15 of 16 checks passed
@dezren39
dezren39 deleted the creator/284-ensure-daemon-cancel branch October 18, 2026 13:03
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.

mcpx: EnsureDaemon ignores a cancelled context — spawns a daemon and waits out the full 20s autostart timeout

1 participant