Finding
PR #320 (port of dezren39/darwin-nix#430, merge 355caf1) made inlineDaemon honour context cancellation in three places in pkgs/mcpx/internal/cli/connect.go (current main ca1abca):
- entry
ctx.Err() check — connect.go:216
- the answer poll now selects on
ctx.Done() vs the poll interval — connect.go:261-269
- a post-loop
ctx.Err() check before reporting the generic timeout — connect.go:271-274
Only (1) is pinned by a test. The two tests the PR added in pkgs/mcpx/internal/cli/inlinedaemon_test.go are TestInlineDaemonAlreadyCancelledContext (entry check only — it returns before any daemon starts) and TestInlineDaemonStartsWithLiveContext (the empty-config daemon answers the first Ping, so the poll wait is never meaningfully entered). Neither test cancels a context while the poll is waiting, and neither exercises the genuine-timeout path.
Ablation-verified in this review: in a scratch worktree of current main, replacing the poll select with a plain time.Sleep and deleting the post-loop check (entry check kept) leaves both new tests green:
--- PASS: TestInlineDaemonAlreadyCancelledContext (0.00s)
--- PASS: TestInlineDaemonStartsWithLiveContext (0.01s)
So the headline behaviour of the fix — a caller who cancels during the up-to-5s inline start wait gets a prompt context.Canceled and the in-process daemon is stopped, instead of burning the full daemon.inlineStartTimeout and reporting the in-process daemon did not answer — can regress silently.
The sibling fix in the same package sets the bar: EnsureDaemon has TestEnsureDaemonCancelledWhileWaiting (ensuredaemon_test.go:62) alongside its already-cancelled and never-ready tests, using a fake daemon binary, a 30s connect timeout, and a cancel at 200ms. inlineDaemon has no equivalent. (A deterministic mid-poll test here needs Ping to keep failing while the context is live — the empty-config daemon answers at once — so it may need a minimal seam: a daemon whose health endpoint never answers, a blocked/slow ServeInline, or an extracted poll helper.)
Affected repos (one set — mcpx lives in both)
Why it matters
This is the same unpinned-wait pattern this repo already treated as worth an issue once (#319, fixed by PR #322): a wait/cancellation branch whose removal leaves the suite green. Cancellation during startup is the common real-world case (user hits Ctrl-C while mcpx is starting), not the already-cancelled one.
Acceptance criteria
- A test in
inlinedaemon_test.go cancels the context while inlineDaemon is waiting for the daemon to answer, and asserts: prompt return (well under the inline start timeout), errors.Is(err, context.Canceled), and the in-process daemon is stopped.
- The test is ablation-verified: reverting the poll
select to time.Sleep (or removing the post-loop check, for the path it covers) makes it fail.
- The same test lands in dezren39/nix's mcpx copy in the same pass (cross-repo set; this issue is the single tracker).
Found by the pr-diff-review job reviewing PR #320.