feat: sync imagine quota from upstream after generation - #886
Merged
chenyme merged 5 commits intoAug 13, 2026
Conversation
Imagine image/video quotas (image_pro/image_edit/video/video_720p) were read-only snapshots that never refreshed after generation, so the "Accounts > Grok Web" view showed stale quotas despite real consumption. The post-generation refresh path was blocked end-to-end: imagine models had empty catalog Mode, QueueQuotaRefresh rejected imagine modes, runQuotaRefresh force-switched non-console modes back to weekly, and SyncQuotaMode only supported weekly and /rest/rate-limits. Wire imagine models into the per-generation refresh pipeline: - catalog: assign image_pro/image_edit/video Mode to imagine models so QuotaMode() returns the imagine mode for routing/finalize - SyncQuotaMode: add imagine branch calling syncImagineQuota and picking the requested mode's window - QueueQuotaRefresh: accept imagine modes via new isWebImagineQuotaMode (reuses imagineQuotaBlockModels keys) - runQuotaRefresh: skip the force-weekly override for imagine modes - refreshQuotaMode: apply imagine cooldown after persisting the window - image/video gateways: pass the catalog imagine mode (image_pro/video) to QueueQuotaRefresh instead of the always-weekly effectiveQuotaMode Also surface imagine quota windows in the accounts UI with a dedicated row (remaining/total, exhaustion, reset tooltip) and i18n labels, and extend full SyncQuota to retain imagine windows alongside the weekly snapshot. Routing is unchanged: getRoutingQuotaWindows keeps weekly first, so candidate.QuotaWindow and effectiveQuotaMode stay weekly.
# Conflicts: # backend/internal/application/gateway/video.go # backend/internal/domain/audit/pricing.go # backend/internal/infra/provider/web/catalog.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Imagine image/video quotas (
image_pro/image_edit/video/video_720p) were read-only snapshots that never refreshed after generation, so Accounts → Grok Web showed stale quotas even though real consumption was happening. The per-generation refresh path was blocked end-to-end:Mode, soQuotaMode()returned"";QueueQuotaRefreshrejected imagine modes (whitelist of console/weekly/chat only);runQuotaRefreshforce-switched every non-console mode back toweekly;SyncQuotaModeonly supportedweeklyand/rest/rate-limits, not/rest/media/imagine/quota_info;effectiveQuotaMode(alwaysweeklyfor web) intoQueueQuotaRefresh, so imagine modes never reached the refresh queue.This PR wires imagine models into the per-generation refresh pipeline so a successful imagine generation triggers an upstream
/rest/media/imagine/quota_infosync for that account.Changes
catalog.go— assignimage_pro/image_edit/videoModeto imagine models soQuotaMode()returns the imagine mode. (grok-imagine-image-litekeepsfast— it uses the chat endpoint.)quota.go—SyncQuotaModegains an imagine branch that callssyncImagineQuotaand returns the requested mode's window; fullSyncQuotanow retains imagine windows alongside the weekly snapshot instead of dropping them.service.go— newisWebImagineQuotaMode(reusesimagineQuotaBlockModelskeys);QueueQuotaRefreshaccepts imagine modes;runQuotaRefreshskips the force-weeklyoverride for imagine modes;refreshQuotaModeappliesapplyImagineQuotaCooldownafter persisting imagine windows.image.go/video.go— pass the catalog imagine mode (image_pro/video) toQueueQuotaRefreshinstead of the always-weeklyeffectiveQuotaMode/lease.QuotaMode.pricing.go— extend the official image-cost estimator toimagine-x-1.model_repository.go— addimagine-x-1route defaults.account_repository.go/repository/account.go—OverwriteModelQuotaBlockto align cooldown to the upstream authoritativenextAvailableAt.account-quota.tsx/i18n— surface imagine quota windows in the Accounts UI as a dedicated row (remaining/total, exhaustion + cooldown state, reset tooltip) with localized labels.Routing is unchanged:
getRoutingQuotaWindowskeepsweeklyfirst in its ORDER BY and the per-account map keeps the first row, socandidate.QuotaWindowandeffectiveQuotaModestayweeklyand selection is unaffected. The catalogModeonly feedsQuotaMode()for the finalize refresh call.Verification
Deployed and tested end-to-end against a live Grok Web pool (
imagine-x-1):image_prosynced_atadvanced18:21:49 → 18:55:12(≈1–2s after generation).image_pro8/8 → 6/6,synced_at18:21:49 → 19:00:09, reflecting the two upstream consumption events.POST /rest/media/imagine/quota_infofired after each generation andquota_refresh_eventsreportedoutcome=success.go build ./...andgo vetclean; affected package tests pass (internal/infra/provider/web,internal/application/account,internal/application/gateway); frontendpnpm typecheckclean.Test plan
go test ./internal/infra/provider/web/... ./internal/application/account/... ./internal/application/gateway/...imagine-x-1and confirm the used account'simage_prowindowsynced_atadvances andremainingreflects the upstream value in Accounts → Grok Web.grok-imagine-image-lite(fast mode) and confirm the existing fast-quota decrement path is unaffected.image_pro(remaining 0) and confirm aModelQuotaBlockcooldown is written forimagine-x-1/grok-imagine-image-quality.