From 8ed290c1c4505e8bafcc2f62deeb6a5153fa5a15 Mon Sep 17 00:00:00 2001 From: sususu98 Date: Sun, 12 Apr 2026 00:48:19 +0800 Subject: [PATCH] fix(antigravity): reduce bypass mode log noise Keep cache-disable visibility at info level while suppressing duplicate state-change logs and moving strict-mode chatter down to debug. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- internal/api/server.go | 3 - internal/cache/signature_cache.go | 16 +++-- internal/cache/signature_cache_test.go | 91 ++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 8 deletions(-) diff --git a/internal/api/server.go b/internal/api/server.go index c4cd79b01..eaaf71b17 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -1074,20 +1074,17 @@ func applySignatureCacheConfig(oldCfg, cfg *config.Config) { if oldCfg == nil { cache.SetSignatureCacheEnabled(newVal) cache.SetSignatureBypassStrictMode(newStrict) - log.Debugf("antigravity_signature_cache_enabled toggled to %t", newVal) return } oldVal := configuredSignatureCacheEnabled(oldCfg) if oldVal != newVal { cache.SetSignatureCacheEnabled(newVal) - log.Debugf("antigravity_signature_cache_enabled updated from %t to %t", oldVal, newVal) } oldStrict := configuredSignatureBypassStrict(oldCfg) if oldStrict != newStrict { cache.SetSignatureBypassStrictMode(newStrict) - log.Debugf("antigravity_signature_bypass_strict updated from %t to %t", oldStrict, newStrict) } } diff --git a/internal/cache/signature_cache.go b/internal/cache/signature_cache.go index 95fede4dd..fd2ccab7c 100644 --- a/internal/cache/signature_cache.go +++ b/internal/cache/signature_cache.go @@ -207,9 +207,12 @@ func init() { // SetSignatureCacheEnabled switches Antigravity signature handling between cache mode and bypass mode. func SetSignatureCacheEnabled(enabled bool) { - signatureCacheEnabled.Store(enabled) + previous := signatureCacheEnabled.Swap(enabled) + if previous == enabled { + return + } if !enabled { - log.Warn("antigravity signature cache DISABLED - bypass mode active, cached signatures will not be used for request translation") + log.Info("antigravity signature cache DISABLED - bypass mode active, cached signatures will not be used for request translation") } } @@ -220,11 +223,14 @@ func SignatureCacheEnabled() bool { // SetSignatureBypassStrictMode controls whether bypass mode uses strict protobuf-tree validation. func SetSignatureBypassStrictMode(strict bool) { - signatureBypassStrictMode.Store(strict) + previous := signatureBypassStrictMode.Swap(strict) + if previous == strict { + return + } if strict { - log.Info("antigravity bypass signature validation: strict mode (protobuf tree)") + log.Debug("antigravity bypass signature validation: strict mode (protobuf tree)") } else { - log.Info("antigravity bypass signature validation: basic mode (R/E + 0x12)") + log.Debug("antigravity bypass signature validation: basic mode (R/E + 0x12)") } } diff --git a/internal/cache/signature_cache_test.go b/internal/cache/signature_cache_test.go index 834081593..82a8a19df 100644 --- a/internal/cache/signature_cache_test.go +++ b/internal/cache/signature_cache_test.go @@ -1,8 +1,12 @@ package cache import ( + "bytes" + "strings" "testing" "time" + + log "github.com/sirupsen/logrus" ) const testModelName = "claude-sonnet-4-5" @@ -208,3 +212,90 @@ func TestCacheSignature_ExpirationLogic(t *testing.T) { // but the logic is verified by the implementation _ = time.Now() // Acknowledge we're not testing time passage } + +func TestSignatureModeSetters_LogAtInfoLevel(t *testing.T) { + logger := log.StandardLogger() + previousOutput := logger.Out + previousLevel := logger.Level + previousCache := SignatureCacheEnabled() + previousStrict := SignatureBypassStrictMode() + SetSignatureCacheEnabled(true) + SetSignatureBypassStrictMode(false) + buffer := &bytes.Buffer{} + log.SetOutput(buffer) + log.SetLevel(log.InfoLevel) + t.Cleanup(func() { + log.SetOutput(previousOutput) + log.SetLevel(previousLevel) + SetSignatureCacheEnabled(previousCache) + SetSignatureBypassStrictMode(previousStrict) + }) + + SetSignatureCacheEnabled(false) + SetSignatureBypassStrictMode(true) + SetSignatureBypassStrictMode(false) + + output := buffer.String() + if !strings.Contains(output, "antigravity signature cache DISABLED") { + t.Fatalf("expected info output for disabling signature cache, got: %q", output) + } + if strings.Contains(output, "strict mode (protobuf tree)") { + t.Fatalf("expected strict bypass mode log to stay below info level, got: %q", output) + } + if strings.Contains(output, "basic mode (R/E + 0x12)") { + t.Fatalf("expected basic bypass mode log to stay below info level, got: %q", output) + } +} + +func TestSignatureModeSetters_DoNotRepeatSameStateLogs(t *testing.T) { + logger := log.StandardLogger() + previousOutput := logger.Out + previousLevel := logger.Level + previousCache := SignatureCacheEnabled() + previousStrict := SignatureBypassStrictMode() + SetSignatureCacheEnabled(false) + SetSignatureBypassStrictMode(true) + buffer := &bytes.Buffer{} + log.SetOutput(buffer) + log.SetLevel(log.InfoLevel) + t.Cleanup(func() { + log.SetOutput(previousOutput) + log.SetLevel(previousLevel) + SetSignatureCacheEnabled(previousCache) + SetSignatureBypassStrictMode(previousStrict) + }) + + SetSignatureCacheEnabled(false) + SetSignatureBypassStrictMode(true) + + if buffer.Len() != 0 { + t.Fatalf("expected repeated setter calls with unchanged state to stay silent, got: %q", buffer.String()) + } +} + +func TestSignatureBypassStrictMode_LogsAtDebugLevel(t *testing.T) { + logger := log.StandardLogger() + previousOutput := logger.Out + previousLevel := logger.Level + previousStrict := SignatureBypassStrictMode() + SetSignatureBypassStrictMode(false) + buffer := &bytes.Buffer{} + log.SetOutput(buffer) + log.SetLevel(log.DebugLevel) + t.Cleanup(func() { + log.SetOutput(previousOutput) + log.SetLevel(previousLevel) + SetSignatureBypassStrictMode(previousStrict) + }) + + SetSignatureBypassStrictMode(true) + SetSignatureBypassStrictMode(false) + + output := buffer.String() + if !strings.Contains(output, "strict mode (protobuf tree)") { + t.Fatalf("expected debug output for strict bypass mode, got: %q", output) + } + if !strings.Contains(output, "basic mode (R/E + 0x12)") { + t.Fatalf("expected debug output for basic bypass mode, got: %q", output) + } +}