Skip to content

Fix: Use a pool-free log handler in the A2A and MCP allocation tests - #1712

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/debuglog-allocs-race-flake
Nov 7, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
huang195:fix/debuglog-allocs-race-flake

Conversation

@huang195

@huang195 huang195 commented Nov 7, 2026

Copy link
Copy Markdown
Member

Summary

Two allocation tests on main fail at random in Go CI (core):

  • core/parse/a2a: TestParseRequest_DebugOffDoesNotSanitizeParts
  • core/parse/mcp: TestParseRequest_DebugOffDoesNotSanitizeBody

Both tests came in with commit 44cb1862b. Each test compares two testing.AllocsPerRun counts with a slog TextHandler set. The TextHandler keeps its buffers in a sync.Pool. Under -race, sync.Pool drops 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: an infoOnly wrapper on slog.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

cd core
go test -race -count=30 -run 'DebugOffDoesNotSanitize|DebugOnLogs' ./parse/mcp/ ./parse/a2a/
  • Before: mcp failed 13 of 30 runs, a2a failed 17 of 30 runs.
  • After: both pass 30 of 30.
  • With the Debug guard removed from mcp.go and a2a.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

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>
@huang195
huang195 requested a review from a team as a code owner November 7, 2026 16:35
@coderabbitai

coderabbitai Bot commented Nov 7, 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 50 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: e5b189c6-f6d9-4e0d-9cdb-7e3098ddd035
Commits

Reviewing files that changed from the base of the PR and between 134816b and 0fecb01.

Files selected for processing: 2

  • core/parse/a2a/debuglog_test.go
  • core/parse/mcp/debuglog_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

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 || …) in a2a.go and mcp.go: both Debug-off tests fail in 10 of 10 runs, so the tests still catch the bug.
  • infoOnly changed to enable Debug: both tests fail, so a guard on the wrong level is still caught.
  • go vet on 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

@huang195
huang195 merged commit 14935cb into rossoctl:main Nov 7, 2026
41 checks passed
@huang195
huang195 deleted the fix/debuglog-allocs-race-flake branch November 7, 2026 16:42
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants