From 177c7619b681b0ab97bccbac0931493f0419bbe5 Mon Sep 17 00:00:00 2001 From: sususu Date: Mon, 10 Aug 2026 19:51:46 +0800 Subject: [PATCH] test(antigravity): clear credits state in place to fix a cleanup data race resetAntigravityCreditsRetryState assigned a fresh sync.Map to each package-level credits variable. Credits hint refreshes run on background goroutines that outlive the request, so they can still be writing those maps when a test's cleanup runs. Replacing the variable is an unsynchronized write to the same memory the goroutine is mutating, which made `go test -race ./internal/runtime/executor` fail with two data races in TestAntigravityExecute_NoCreditsWithoutConductorFlag. Empty each map in place with sync.Map.Clear instead. Clear is safe against concurrent users, and the reset semantics are unchanged. The races were pre-existing and reproduce identically on b921b5d0; only test code changes here. Production code never assigned these variables, so it was never affected. before go test -race ./internal/runtime/executor FAIL, 2 data races after go test -race ./internal/runtime/executor ok, 0 data races --- .../executor/antigravity_executor_credits_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/runtime/executor/antigravity_executor_credits_test.go b/internal/runtime/executor/antigravity_executor_credits_test.go index cc9a897b..a763d19f 100644 --- a/internal/runtime/executor/antigravity_executor_credits_test.go +++ b/internal/runtime/executor/antigravity_executor_credits_test.go @@ -21,11 +21,16 @@ import ( sdktranslator "github.com/router-for-me/CLIProxyAPI/v7/sdk/translator" ) +// resetAntigravityCreditsRetryState clears the package-level credits state +// between tests. It empties each map in place instead of assigning a fresh +// sync.Map, because credits hint refreshes run on background goroutines that +// may still be writing these maps when a test's cleanup runs. Replacing the +// variable is an unsynchronized write and races with them; Clear is not. func resetAntigravityCreditsRetryState() { - antigravityCreditsFailureByAuth = sync.Map{} - antigravityShortCooldownByAuth = sync.Map{} - antigravityCreditsBalanceByAuth = sync.Map{} - antigravityCreditsHintRefreshByID = sync.Map{} + antigravityCreditsFailureByAuth.Clear() + antigravityShortCooldownByAuth.Clear() + antigravityCreditsBalanceByAuth.Clear() + antigravityCreditsHintRefreshByID.Clear() } type closeSignalReadCloser struct { -- 2.51.2