Skip to content

mcpx: EnsureDaemon poll-loop exit drops a cancellation — no post-loop ctx.Err() check (nix copy has it) #328

Closed

Description

@dezren39

Finding

The two mcpx copies have diverged in Client.EnsureDaemon's poll loop exit path (pkgs/mcpx/internal/cli/client.go):

The in-loop select catches a cancellation that lands while the loop is waiting. It does not catch one that becomes visible only as the loop exits on the connect deadline — e.g. a context whose Done channel has not fired (or fires in the same instant the deadline passes) but whose Err() is already set when the deadline expires. In that window this copy reports:

daemon did not become ready; see <state>/daemon.log

for a caller who cancelled, instead of context.Canceled. Callers that branch on errors.Is(err, context.Canceled) (prompt-exit paths, shutdown) misread a cancellation as a daemon failure.

Evidence

  • nix: sed -n '395,410p' pkgs/mcpx/internal/cli/client.go in dezren39/nix @ 295b70d shows the post-loop check between the loop and the tail, _ := os.ReadFile(logPath) line.
  • code: the same range in this repo @ 2e9cf19 goes straight from the loop's closing brace to tail, _ := os.ReadFile(logPath).
  • A normalized cross-copy diff of pkgs/mcpx (issue numbers and whitespace stripped) shows this is the only remaining behavioural divergence in EnsureDaemon; internal/cli/connect.go (inlineDaemon, opencode: enable web-search backends + experimental feature flags #430 set) is byte-identical.

Acceptance criteria

  • Code's EnsureDaemon re-checks ctx.Err() after the poll loop and returns it when set, mirroring dezren39/nix client.go:403-405.
  • A regression test in BOTH copies pins the exit path deterministically: a context that reports context.Canceled from Err() only after the entry checks (its Done channel never fires) with a short connect timeout must yield context.Canceled, not "daemon did not become ready". The test must fail on this repo's current code and pass in nix both before and after (nix already has the check but no test pinning this exit path — the same gap code mcpx: inlineDaemon's cancel-during-poll path (PR #320) has no regression test — ablating it leaves the suite green #323 records for inlineDaemon's poll).
  • Existing EnsureDaemon tests (already-cancelled, cancel-while-polling, remote-cancelled, never-ready timeout) stay green in both copies.

Cross-repo: one issue here (the defect is only in this copy); the nix side is test-only and is solved as part of this set with a PR referencing this issue.

Activity

  1. added a commit that references this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions