feat: add OpenAI account request overrides and proxy-based admin/group controls#1462
feat: add OpenAI account request overrides and proxy-based admin/group controls#1462is7Qin wants to merge 12 commits intoWei-Shaw:mainfrom
Conversation
Add the group-level proxy_bucket_load_balance_enabled toggle and wire it through backend and frontend scheduling paths. This makes sticky routing keep priority, then narrows eligible accounts by the lower-load proxy bucket before reusing the existing account-level selector, while falling back cleanly when no proxy-backed candidates exist.
Support filtering admin accounts by proxy_id across the API and UI so large proxy pools can be searched precisely without stale cached list responses.
Keep proxy bucket scheduling visible across gateway modes while leaving OpenAI Messages dispatch settings scoped to OpenAI groups only.
Treat OpenAI account_deactivated responses as permanent account failures so OAuth accounts are marked error instead of only being cooled down temporarily.
Spread requests across equally healthy proxy buckets and prefer buckets with more available accounts so low-concurrency traffic no longer sticks to smaller proxy IDs.
Remove a no-op proxy bucket call in mixed scheduling and keep AI Studio endpoint bucket selection stable instead of random when no session hash is available.
There was a problem hiding this comment.
Pull request overview
This PR adds account-level OpenAI request override support, introduces optional proxy-bucket load balancing at the group level, and adds proxy-based filtering for the admin account list.
Changes:
- Add per-account OpenAI request override parsing/validation in frontend and apply sanitized overrides in gateway forwarding (excluding top-level
model). - Introduce group flag
proxy_bucket_load_balance_enabledand apply proxy-bucket narrowing in schedulers (OpenAI/Gateway/Gemini compat), plus wire it through admin group UI/API and persistence. - Add
proxy_idfiltering to admin accounts list across frontend/API/backend, including ETag variation.
Reviewed changes
Copilot reviewed 59 out of 59 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/views/admin/GroupsView.vue | Adds UI toggle to enable/disable proxy-bucket load balancing for groups. |
| frontend/src/views/admin/AccountsView.vue | Adds proxy_id to filter params and passes proxy list into filters component. |
| frontend/src/components/admin/account/AccountTableFilters.vue | Implements proxy dropdown filter UI and emits proxy_id updates. |
| frontend/src/utils/openaiRequestOverrides.ts | Adds JSON parse/stringify helpers with top-level model disallow. |
| frontend/src/utils/tests/openaiRequestOverrides.spec.ts | Adds unit tests for override parsing rules. |
| frontend/src/components/account/CreateAccountModal.vue | Adds OpenAI request override textarea and validation on submit. |
| frontend/src/components/account/EditAccountModal.vue | Adds OpenAI request override textarea and persistence via extra. |
| frontend/src/components/account/BulkEditAccountModal.vue | Adds bulk edit support for OpenAI request overrides and tests. |
| frontend/src/components/account/tests/BulkEditAccountModal.spec.ts | Verifies bulk update payload includes openai_request_overrides. |
| frontend/src/types/index.ts | Wires new fields into TS types for groups and requests. |
| frontend/src/i18n/locales/en.ts / zh.ts | Adds strings for proxy bucket toggle, proxy filter, and request overrides. |
| frontend/src/api/admin/accounts.ts | Adds proxy_id to list/listWithEtag query shape. |
| backend/migrations/081_add_group_proxy_bucket_load_balance.sql | Adds groups.proxy_bucket_load_balance_enabled column. |
| backend/internal/service/openai_request_overrides*.go | Implements override extraction/sanitization/merge and adds tests + forward tests. |
| backend/internal/service/openai_gateway_service.go | Applies overrides before extracting request metadata and clears parsed-body cache when modified. |
| backend/internal/service/openai_gateway_messages.go | Applies overrides for compat path and propagates derived metadata. |
| backend/internal/service/gateway_service.go | Adds proxy-bucket selection helpers and integrates them into scheduling paths. |
| backend/internal/service/openai_account_scheduler.go | Applies proxy-bucket narrowing in OpenAI load-balance scheduler. |
| backend/internal/service/gemini_messages_compat_service.go | Adds concurrency-aware proxy-bucket narrowing in Gemini compat scheduling and updates constructor wiring. |
| backend/internal/service/*_test.go | Updates repository interface signatures for new proxyID parameter and adds new scheduling tests. |
| backend/internal/service/admin_service.go + handler/admin/account_handler.go | Adds proxy_id filter support end-to-end and updates ETag inputs. |
| backend/internal/repository/account_repo.go | Implements proxy filter predicate in query. |
| backend/internal/repository/group_repo.go + ent/* | Persists and exposes new group flag through Ent schema/runtime/migrations. |
| backend/cmd/server/wire_gen.go | Wires ConcurrencyService into Gemini compat service constructor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <<<<<<< HEAD | ||
| result, err := svc.SelectAccountWithLoadAwareness(testCtx, &groupID, "", "claude-3-5-sonnet-20241022", nil, "") | ||
| require.NoError(t, err) | ||
| require.NotNil(t, result) | ||
| require.NotNil(t, result.Account) | ||
| require.Equal(t, int64(12), result.Account.ID) | ||
| require.Equal(t, 1, concurrencyCache.loadBatchCalls) | ||
| ======= | ||
| result, err := svc.SelectAccountWithLoadAwareness(ctx, nil, "", "claude-3-5-sonnet-20241022", nil, "", int64(0)) | ||
| require.Error(t, err) | ||
| require.Nil(t, result) | ||
| require.ErrorIs(t, err, ErrNoAvailableAccounts) | ||
| >>>>>>> upstream/main |
There was a problem hiding this comment.
This test file still contains unresolved Git merge-conflict markers (<<<<<<< / ======= / >>>>>>>), which will break compilation and prevent tests from running. Resolve the conflict and keep a single intended assertion path for this new proxy-bucket test case.
| accountsLoaded = true | ||
|
|
||
| // 提前预取窗口费用+RPM 计数,确保 routing 段内的调度检查调用能命中缓存 | ||
| ctx = s.withWindowCostPrefetch(ctx, accounts) | ||
| ctx = s.withRPMPrefetch(ctx, accounts) | ||
| accounts = s.selectProxyBucketForCurrentGroup(ctx, accounts, sessionHash) | ||
|
|
There was a problem hiding this comment.
In the model-routing selection path, window-cost/RPM prefetch (used to avoid per-account cache/DB lookups) was removed. The selection loop still calls isAccountSchedulableForWindowCost/isAccountSchedulableForRPM for candidates, which can reintroduce N+1 cache/DB reads on misses. Consider re-adding the prefetch (ideally after proxy-bucket narrowing) before iterating routed candidates.
Summary
This PR mainly introduces three feature areas:
feat: add OpenAI account request overridesfeat(group): add proxy-bucket load balancingfeat(admin): add proxy filter for account listChanges
OpenAI account request overrides
Group-level proxy-bucket load balancing
proxy_bucket_load_balance_enabledtoggleproxy_idbucketAdmin account list proxy filter
proxy_idVerification
go test ./... -run TestDoesNotExist -count=0pnpm typecheck