fix(test): stop profile-gate allocation-parity tests flaking under -race - #1337
Merged
Merged
Conversation
…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
enabled auto-merge (squash)
September 21, 2026 10:55
Deploying mcpproxy-docs with
|
| 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 |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes intermittent CI failures in
TestProfileMiddleware_RefusalWorkIndependentOfFleet(internal/server/profile_url_gate_test.go) and its siblingTestSelectableProfileNames_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-raceon/off — with-raceoff it never fails; with-raceon 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
retryUntilAllocsMatchhelper — 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-timesettleBackgroundGoroutinespass before measurement starts to also absorb genuine lingering-goroutine noise from other tests in the sharedinternal/servertest binary.No production code is touched — this is test-measurement code only.
Test plan
go build ./...— cleangofmt -l— cleangolangci-lint run --config .github/.golangci.yml ./internal/server/...— clean (pre-existing unrelated findings only)go test -race -run 'TestProfileMiddleware_RefusalWorkIndependentOfFleet|TestSelectableProfileNames_PinOutcomesDoSameWork'runs passgo 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