Skip to content

fix(test): stop profile-gate allocation-parity tests flaking under -race - #1337

Merged
Dumbris merged 1 commit into
mainfrom
claude/jolly-raman-78d62a
Sep 21, 2026
Merged

Dumbris merged 1 commit into
mainfrom
claude/jolly-raman-78d62a

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 21, 2026

Copy link
Copy Markdown
Member

Summary

Fixes intermittent CI failures in TestProfileMiddleware_RefusalWorkIndependentOfFleet (internal/server/profile_url_gate_test.go) and its sibling TestSelectableProfileNames_PinOutcomesDoSameWork (internal/server/profile_tool_test.go) — Spec 105 FR-004 non-disclosure witnesses that assert allocation-count parity across fleet shapes / pin outcomes. Both intermittently failed only in CI's advisory "Unit Tests (shuffle)" lane (go test -race -shuffle=on), diagnosed while landing #1328.

Root cause: under -race, Go disables the tiny-object allocator, producing a sticky ±1 allocation bias between differently-sized fleets that does not fluctuate across back-to-back samples. Confirmed by isolating the two tests alone (no other package tests running) and toggling -race on/off — with -race off it never fails; with -race on it fails consistently, even across many tight-loop samples. This is not ordinary cross-goroutine noise, so a round-robin/minimum-of-many-samples approach (which assumes noise only adds and varies) never converges — a real time gap between measurement attempts is required to let the allocator's free-list state shift.

Fix: a shared retryUntilAllocsMatch helper — take one fresh reading per case per attempt, require all cases to agree with a baseline on that same attempt, retry with a real 20ms sleep for up to 15 attempts (the shape the original code already used, generalized between both tests and given more headroom), plus a one-time settleBackgroundGoroutines pass before measurement starts to also absorb genuine lingering-goroutine noise from other tests in the shared internal/server test binary.

No production code is touched — this is test-measurement code only.

Test plan

  • go build ./... — clean
  • gofmt -l — clean
  • golangci-lint run --config .github/.golangci.yml ./internal/server/... — clean (pre-existing unrelated findings only)
  • 15/15 isolated go test -race -run 'TestProfileMiddleware_RefusalWorkIndependentOfFleet|TestSelectableProfileNames_PinOutcomesDoSameWork' runs pass
  • 3/3 full-package go test -race -shuffle=on -skip "E2E|Binary|MCPProtocol|TestInfoEndpoint|TestGracefulShutdownNoPanic|TestSocketInfoEndpoint" ./internal/server/ runs pass cleanly (CI's exact configuration), zero failures anywhere in the suite

🤖 Generated with Claude Code

…nd its sibling from flaking under -race

Both tests assert allocation-count parity across fleet shapes/pin outcomes
(FR-004 non-disclosure witnesses from Spec 105 PR D/G) and intermittently
failed in CI's advisory "Unit Tests (shuffle)" lane (go test -race
-shuffle=on).

Root cause: under -race, Go disables the tiny-object allocator, producing a
sticky ±1 allocation bias between differently-sized fleets that does not
fluctuate across back-to-back samples — confirmed by isolating the two
tests alone (no other package tests) and toggling -race on/off. This is
NOT ordinary cross-goroutine noise, so a round-robin/minimum-of-many-samples
approach (which assumes noise only adds and varies) never converges; a real
time gap between measurement attempts is required to let the allocator's
free-list state shift.

Fix: shared retryUntilAllocsMatch helper — one fresh reading per case per
attempt, requiring all cases to agree with a baseline on the same attempt,
retried with a real 20ms sleep for up to 15 attempts (matches the shape the
original code already used, generalized and given more headroom), plus a
one-time settleBackgroundGoroutines pass before measurement starts to also
absorb genuine lingering-goroutine noise from other tests in the shared
internal/server test binary.

Verified: 15/15 isolated -race runs and 3/3 full-package -race -shuffle=on
runs (CI's exact configuration) pass cleanly with zero failures anywhere in
the suite.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Dumbris
Dumbris enabled auto-merge (squash) September 21, 2026 10:55
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 204367b
Status: ✅  Deploy successful!
Preview URL: https://5f223786.mcpproxy-docs.pages.dev
Branch Preview URL: https://claude-jolly-raman-78d62a.mcpproxy-docs.pages.dev

View logs

@Dumbris
Dumbris merged commit 5da1d99 into main Sep 21, 2026
40 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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