Skip to content

feat: add OpenAI account request overrides and proxy-based admin/group controls#1462

Open
is7Qin wants to merge 12 commits intoWei-Shaw:mainfrom
is7Qin:feat/openai-overrides-proxy-routing
Open

feat: add OpenAI account request overrides and proxy-based admin/group controls#1462
is7Qin wants to merge 12 commits intoWei-Shaw:mainfrom
is7Qin:feat/openai-overrides-proxy-routing

Conversation

@is7Qin
Copy link
Copy Markdown

@is7Qin is7Qin commented Apr 5, 2026

Summary

This PR mainly introduces three feature areas:

  • feat: add OpenAI account request overrides
  • feat(group): add proxy-bucket load balancing
  • feat(admin): add proxy filter for account list

Changes

OpenAI account request overrides

  • add account-level request overrides for OpenAI accounts
  • allow admins to define custom request parameters that override client-supplied values before forwarding upstream
  • support configuring these overrides in account management flows

Group-level proxy-bucket load balancing

  • add the group-level proxy_bucket_load_balance_enabled toggle
  • wire the flag through backend and frontend group management
  • update scheduling so sticky routing keeps highest priority first
  • after sticky miss, narrow eligible accounts by lower-load proxy_id bucket
  • reuse the existing account-level selector after bucket narrowing
  • fall back cleanly to the original scheduling path when no proxy-backed candidates exist

Admin account list proxy filter

  • support filtering admin account lists by proxy_id
  • expose the filter through API and UI
  • make large proxy pools easier to inspect without relying on stale cached list results

Verification

  • go test ./... -run TestDoesNotExist -count=0
  • pnpm typecheck

throwaway-people and others added 12 commits March 28, 2026 16:01
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.
Copilot AI review requested due to automatic review settings April 5, 2026 09:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_enabled and apply proxy-bucket narrowing in schedulers (OpenAI/Gateway/Gemini compat), plus wire it through admin group UI/API and persistence.
  • Add proxy_id filtering 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.

Comment on lines +2314 to +2326
<<<<<<< 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
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 3097 to 3100
accountsLoaded = true

// 提前预取窗口费用+RPM 计数,确保 routing 段内的调度检查调用能命中缓存
ctx = s.withWindowCostPrefetch(ctx, accounts)
ctx = s.withRPMPrefetch(ctx, accounts)
accounts = s.selectProxyBucketForCurrentGroup(ctx, accounts, sessionHash)

Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
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.

3 participants