Skip to content

fix(console): use ScopeConsole for quota/session sync and stop retrying permanent quota refresh errors - #1109

Open
jun9100 wants to merge 2 commits into
chenyme:mainfrom
jun9100:fix/console-egress-scope-and-quota-retry
Open

jun9100 wants to merge 2 commits into
chenyme:mainfrom
jun9100:fix/console-egress-scope-and-quota-retry

Conversation

@jun9100

@jun9100 jun9100 commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Fixes a retry storm and queue overflow (quota_refresh_queue_full) affecting deployments with dedicated grok_console-scoped egress nodes:

  1. Use ScopeConsole for Console quota and session identity sync

    • console.Adapter.syncConsoleQuotas (backend/internal/infra/provider/console/quota.go) and sessionidentity.Fetch (backend/internal/infra/provider/sessionidentity/session.go) previously requested egress.ScopeWeb even for grok_console accounts bound to grok_console-scoped egress nodes.
    • Because egress.SupportsScope(ScopeConsole, ScopeWeb) is false (while SupportsScope(ScopeWeb, ScopeConsole) is true), every Console account bound to a dedicated grok_console node failed immediately with 绑定出口节点 <id> 与 grok_web 作用域不兼容.
    • Acquiring ScopeConsole for grok_console credentials works directly with bound grok_console nodes, continues to accept grok_web nodes via SupportsScope / fallbackScopes, and preserves identical browser fingerprint & Clearance handling via isGrokWebScope(ScopeConsole).
    • sessionidentity.FetchWithLease now reports egress feedback using lease.Scope (defaulting to ScopeWeb).
  2. Stop infinite retries and queue flooding on non-self-healing quota refresh errors

    • Export egress.ErrBoundNodeUnavailable and classify non-self-healing bound-node configuration failures in infra/egress.Manager.acquireUnavailableFallback (missing node, incompatible scope, disabled node, empty proxy URL) when no fallback can transiently recover them — preserving exact error strings, keeping primary cooldowns / transient DB errors retryable, and keeping transient fallback failures (e.g. a cooling fixed fallback node) retryable.
    • In account.Service.runQuotaRefresh, drop entries on permanent errors (ErrNotFound, provider.ErrUnauthorized, egress.ErrBoundNodeUnavailable) and clear shared dirty state (logging clear errors and resetting failures if a newer generation arrived concurrently) instead of re-queuing indefinitely at 1-minute backoff.
    • In account.Service.ReconcileRateLimit, skip queuing QueueQuotaRefresh on permanent errors.
    • In account.Service.syncConsoleQuotaAccounts, avoid double-scheduling periodic console_usage_migration failures into quotaRefreshQueue (migration already retries on its own periodic schedule) and skip queuing permanent errors or provider.ErrEgressBlocked on catch-up batches.

Test Plan

  • Added TestAcquireCredentialBoundNodeUnavailableClassification in backend/internal/infra/egress/manager_test.go covering missing/incompatible/disabled/empty-proxy bound nodes, transient DB/cooldown errors, and cooling vs disabled fixed fallbacks.
  • Added TestFetchSelectsScopeByProviderAndReportsLeaseScope in backend/internal/infra/provider/sessionidentity/session_test.go.
  • Added TestSyncQuotaAndIdentityUseBoundConsoleScopedEgressNode in backend/internal/infra/provider/console/console_protocol_test.go.
  • Added TestQuotaRefreshDropsPermanentErrorsWithoutRetrying in backend/internal/application/account/quota_refresh_test.go covering permanent error dropping, concurrent generation failure reset, ReconcileRateLimit, and syncConsoleQuotaAccounts queue policy.
  • Ran gofmt, go vet ./..., and go test -race -count=1 ./internal/domain/egress ./internal/infra/egress ./internal/infra/provider/console ./internal/infra/provider/sessionidentity ./internal/application/account ./internal/app — all pass.
  • Verified on a production deployment with 5,488 grok_console accounts bound to grok_console nodes: 作用域不兼容 errors and quota_refresh_queue_full dropped to 0.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant