Repository navigation
Fix: Use a pool-free log handler in the A2A and MCP allocation tests - #1712
Conversation
TestParseRequest_DebugOffDoesNotSanitizeParts (a2a) and TestParseRequest_DebugOffDoesNotSanitizeBody (mcp) compare two testing.AllocsPerRun counts. Both tests set a slog TextHandler. The TextHandler uses a sync.Pool for its buffers. Under -race, sync.Pool drops items at random, so one log call can allocate one more buffer. The two counts then differ by 1 and the test fails. CI runs the core tests only with -race. Before this change, the mcp test failed 13 of 30 runs and the a2a test failed 17 of 30 runs (go test -race -count=30). After this change, both fail 0 of 30. The fix is the same one that rossoctl#1703 used in core/parse/inference: an infoOnly wrapper on slog.DiscardHandler. Info stays on and Debug stays off, so a guard on the wrong level still fails the test. Check that the tests still find the bug: with the Debug guard removed from mcp.go and a2a.go, both tests fail 5 of 5 runs under -race. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Hai Huang <huang195@gmail.com>
|
Warning Review limit reachedYou'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 50 minutes. View limit details
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. |
clawgenti
left a comment
There was a problem hiding this comment.
Summary
This change only touches tests. The TextHandler in the a2a and mcp Debug-off allocation tests is swapped for the same infoOnly{slog.DiscardHandler} wrapper that core/parse/inference and core/plugins/inferenceparser already use. That takes sync.Pool out of the measured path, so -race can no longer move the alloc count by one. Enabled still reports Info on and Debug off, so the slog.Info call in both parsers runs through the real handler path, just as it does in production.
What I checked locally on the head commit (go1.26):
go test -race -count=30 -run 'DebugOffDoesNotSanitize|DebugOnLogs' ./parse/mcp/ ./parse/a2a/: all pass.- Debug guard forced on (
if true || …) ina2a.goandmcp.go: both Debug-off tests fail in 10 of 10 runs, so the tests still catch the bug. infoOnlychanged to enable Debug: both tests fail, so a guard on the wrong level is still caught.go veton both packages: clean.
No findings.
Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing
Summary
Two allocation tests on
mainfail at random inGo CI (core):core/parse/a2a:TestParseRequest_DebugOffDoesNotSanitizePartscore/parse/mcp:TestParseRequest_DebugOffDoesNotSanitizeBodyBoth tests came in with commit
44cb1862b. Each test compares twotesting.AllocsPerRuncounts with a slogTextHandlerset. TheTextHandlerkeeps its buffers in async.Pool. Under-race,sync.Pooldrops items at random, so the two counts can differ by 1. CI runs the core tests only with-race.This PR uses the fix that #1703 used in
core/parse/inference: aninfoOnlywrapper onslog.DiscardHandler. Info stays on and Debug stays off, so a guard on the wrong level still fails the test. No production code changes.Example failure (on #1710):
allocs with a control rune = 23, without = 24; want equal with Debug off.Test
mcp.goanda2a.go, both tests still fail 5 of 5 runs. The tests still find the bug they guard.golangci-lint run ./parse/a2a/ ./parse/mcp/: 0 issues.Assisted-By: Claude (Anthropic AI) noreply@anthropic.com