Skip to content

mcpx tests: de-flake the two races that reddened the switch build (#2609) - #2612

Merged
dezren39 merged 1 commit into
mainfrom
fix/mcpx-2609-red-main
Oct 30, 2026
Merged

dezren39 merged 1 commit into
mainfrom
fix/mcpx-2609-red-main

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #2609. Unblocks the NixOS deploy switch.

Verdict: two test-side races, not a product regression

The switch build (primary at 819889b) failed mcpx checkPhase on two tests. Both were green at efeea69 (PR #2587's verification). Between that commit and 819889b the only mcpx changes are the #1910 TypeScript plugin commits (33eda5c, 81d4b41, merges 52bfa5f/f9268e24) — the Go code in internal/hooks and internal/mcpclient is byte-identical to the green state. f9268e2 did not cause these; they are load-dependent flakes that surfaced under the full-system build's parallelism.

Proof of nondeterminism: a re-run of the identical mcpx derivation (/nix/store/a0nzf2m5b1kpr4w4a3hlhrm1sbmgq6y1-mcpx-0.1.0.drv, same inputs, same output path as the failed switch build) passed checkPhase — ok internal/hooks, ok internal/mcpclient in its nix log.

Root causes

  1. TestDeclaredHookFiresOnMatchingKindsOnly (internal/hooks) — the test waited for the marker file to exist, then read it. The hook command is cat > <marker>: cat creates the file before it writes the stdin payload, so under CPU starvation the test reads the just-created empty file. The switch failure was literally hook stdin payload wrong: (empty). The production runner is not involved in the race: it feeds the full JSON via cmd.Stdin and cmd.Run() waits for cat to finish.
    Fix: the wait now polls the payload content itself ("kind":"server.stopped" present) — the same pattern the sibling python-hook test in this file already uses. Assertions unchanged.

  2. TestSupervisedPumpDetachReattach (internal/mcpclient) — the test reattached immediately after Close(). Close() returns once the local connection is closed; the supervisor clears its attach slot when it notices the disconnect, in its own loop — asynchronously. Under load the immediate reattach arrived first and got the by-design already attached refusal.
    Fix: the test polls the reattach, retrying only on the already attached refusal, with a 10s deadline. Production semantics are unchanged — including the refusal a genuinely-attached second client still receives (covered by the neighboring test).

No production code changed; #1910's feature is untouched.

Verification

  • Both packages: 5/5 consecutive green full-package runs (go test ./internal/hooks/ ./internal/mcpclient/ -count=1).
  • The two tests under stress: hooks -count=100 green, pump -count=60 green.
  • gofmt clean, go vet clean on both packages.
  • nix build .#mcpx from this worktree: run after this PR opened; result in a follow-up comment. (Baseline note: the unmodified tree's identical derivation already re-ran green once, per above.)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

)

Both failures from the 2026-10-30 switch build are test-side races,
not product regressions: the Go code in internal/hooks and
internal/mcpclient is byte-identical to the last green verification
(efeea69, PR #2587) - the only mcpx change since is the #1910
TypeScript plugin work - and a re-run of the identical mcpx
derivation (a0nzf2m5) passes both packages.

1. TestDeclaredHookFiresOnMatchingKindsOnly waited for the marker
   file to EXIST, then read it. The hook command is "cat > marker":
   cat creates the file before it writes the stdin payload, so under
   build load the test could read the just-created empty file - the
   observed failure was exactly an empty payload. The wait now polls
   the payload content itself, the same pattern the sibling
   python-hook test in this file already uses.

2. TestSupervisedPumpDetachReattach reattached immediately after
   Close(). Close returns when the local connection closes; the
   supervisor clears its attach slot when it notices the disconnect,
   asynchronously - so under load the reattach hit the (by-design)
   "already attached" refusal. The test now polls the reattach until
   the slot frees (10s deadline, refusal-only retries); production
   semantics are unchanged, including the refusal a genuinely
   attached second client still gets.

Verified: both packages 5/5 consecutive green; the two tests at
-count=100 / -count=60 green; gofmt + go vet clean.
@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 07:13
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f99f5ab9-a34a-40ed-9aa3-26acf7278bad
Commits

Reviewing files that changed from the base of the PR and between 541578a and 11643b1.

Files selected for processing: 2
  • pkgs/mcpx/internal/hooks/runner_test.go
  • pkgs/mcpx/internal/mcpclient/supervised_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

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 ✅ Completed 2026-10-30T07:16:18.704520Z 11643b1 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.

@dezren39

Copy link
Copy Markdown
Member Author

Gate proof: nix build .#mcpx green on this branch

  • Patched derivation /nix/store/a594qcpnqypwpzb91xggar7xvh3g3nb0-mcpx-0.1.0.drv built from this worktree: nix build .#mcpx exit 0; its checkPhase log shows all 50 packages ok, no FAIL lines.
  • Baseline for contrast: the unmodified tree's derivation (a0nzf2m5…, the one that failed in the switch build) also passed on re-run with both target packages ok — same inputs, different outcome, confirming the two failures are nondeterministic test races rather than a code regression.
  • Codex review of 11643b1: completed, no findings (has_any_findings: false).

@dezren39
dezren39 merged commit fee1312 into main Oct 30, 2026
7 of 8 checks passed
@dezren39
dezren39 deleted the fix/mcpx-2609-red-main branch October 30, 2026 07:23
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 main red after #1910 (f9268e24): TestDeclaredHookFiresOnMatchingKindsOnly + TestSupervisedPumpDetachReattach fail in nix build

1 participant