Repository navigation
fix(subscription): let bound users see and use their dedicated group (HQ-Task T261106-01) - #10
Merged
Merged
Conversation
…(HQ-Task T261106-01) Since request-scoped routing (#9) a bound user stays in their own group, and the dedicated group (claude-ch<id> / codex-ch<id> / legacy oauth-ch<id>) is deliberately not in UserUsableGroups. So the token page no longer listed it, and TokenAuth rejected every existing token whose group is the dedicated group with 403 "no permission to access group". - service.GetUserUsableGroupsForUser(userId, userGroup): the usable groups plus the dedicated group of the user's active binding (through the binding cache), described as "Subscription account (bound channel models only)". - Use it in GetUserGroups (marks the group subscription_bound), token create/update group validation (new; update only checks a changed group), TokenAuth, the playground group check, GetUserModels and GetPricing. - Auto lists still reject the dedicated group (shared-pool semantics). - A token in a dedicated group the owner no longer holds gets auth.token_subscription_group_inactive; a model the dedicated group cannot serve gets distributor.subscription_group_no_model. - Token drawer: the dedicated group shows its description, a bound-models hint when selected, and is left out of the Auto order options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ask T261106-01)
Scope change requested by the user on 2026-11-06, replacing "Auto lists do
not accept the dedicated group".
- service.GetUserAutoGroupForUser(userId, userGroup): GetUserAutoGroup with
the user's active binding group in front; identical without a binding.
- GetRequestAutoGroups puts that group first for both the global Auto list
and a token's snapshot, so Auto tries dedicated -> rest; a model the bound
channel does not serve finds no channel there and Auto moves on.
- The group is implicit: setTokenAutoGroups silently drops it before the
limit check, so it is never stored and never counted.
- Token auto-groups endpoint, pricing auto_groups and GetUserModels(auto)
use the per-user list.
- Token drawer: the group is a locked first row in the Auto order editor
("Subscription account · Auto first"), not removable or draggable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
HQ-Task: T261106-01
Agent
Links
User request
Out of scope — refuse
fork-main, not upstream)Open gate — do not open unless all are satisfied
go buildor tests passed: yesKind
Issue facts
claude-ch<id>/codex-ch<id>/ legacyoauth-ch<id>) is intentionally not inUserUsableGroups, soGET /api/user/self/groupsno longer lists it, andTokenAuthanswers 403无权访问 claude-ch<id> 分组for every token whose group is the dedicated group.new-api-fork:fork-main-fe07a0240(production build) with a mock upstream, see Verification.Change
New in
service/group.go:GetUserUsableGroupsForUser(userId, userGroup)=GetUserUsableGroups(userGroup)plus theBoundGroupof the user's active binding, read withmodel.GetUserSubscriptionRouteBinding(existing Redis / in-process cache, invalidated by bind/unbind/invalidate/delete; the stored end time ends it on expiry). Description:Subscription account (bound channel models only)(English source, translated by the web console).GetUserSubscriptionGroup(userId)= that group alone.GetUserAutoGroupForUser(userId, userGroup)=GetUserAutoGroup(userGroup)with that group in front; identical without an active binding.Call sites switched to the per-user version:
controller/group.goGetUserGroupssubscription_bound: truecontroller/token.goAddToken/UpdateToken(newvalidateTokenGroup)autokeep their existing rules.middleware/auth.goTokenAuthmiddleware/distributor.goplayground group checkcontroller/user.goGetUserModels,controller/pricing.goGetPricinggroup=autoandauto_groupsuse the per-user Auto listcontroller/token.goGetTokenAutoGroupsservice.GetRequestAutoGroupsAuto (changed at the user's request, see "Later constraints"): the owner's dedicated group is an implicit, fixed first Auto group.
setTokenAutoGroupssilently drops it before the limit check, so it is never stored inauto_groupsand never counted againstMaxTokenAutoGroups; another user's dedicated group is still rejected. At request timeCacheGetRandomSatisfiedChanneltries it first; for a model it has no channel for, the existing loop (channel == nil → continue) moves to the next Auto group. Bound models already reach it through #9's request routing. It leaves every Auto list when the binding ends. No billing code is changed.Error messages (backend i18n, en / zh-CN / zh-TW):
auth.token_subscription_group_inactive(403, token group is a dedicated-group name the owner no longer holds an active binding for):The subscription dedicated group {{.Group}} of this token is no longer available: the subscription binding has expired, been cancelled or been removed. Switch the token to another group该令牌使用的订阅专属分组 {{.Group}} 已失效:订阅绑定已过期、作废或解绑,请把令牌改为其他分组distributor.subscription_group_no_model(no channel in a dedicated group for the model):The subscription dedicated group {{.Group}} only serves models supported by the bound subscription account; no available channel for model {{.Model}} (distributor)订阅专属分组 {{.Group}} 只能调用绑定的订阅账号支持的模型,模型 {{.Model}} 无可用渠道(distributor)Frontend (
web/src/features/keys): group option carriessubscriptionBound; selecting it as the token group showsThis API key can only call models supported by your bound subscription account.. In the Auto order editor it is a locked first row with aSubscription account · Auto firstbadge (订阅专属账号 · 自动优先) and a lock icon, without drag / move / remove controls, in both inherit and custom mode; inherited chips are numbered after it; it is not an "Add Auto group" candidate and never sent inauto_groups. New web keys (7 locales, inserted line by line, no existing key re-escaped):Group {{group}} is unavailable or unauthorized,Subscription account (bound channel models only), the hint above,Subscription account · Auto first,Always tried first in Auto. It cannot be removed or reordered..Component reuse: existing
ApiKeyGroupCombobox(already rendersdesc),FormDescription,Badge. The locked row is a static element next to theReorder.Groupinstead of anAutoGroupOrderItem: that component is aReorder.Item(must be draggable inside the group) and always renders move/remove controls, which the locked group must not have.Research
Duplicate / prior art
gh pr view); no existing per-user usable-groups helper inservice/.Docs and code
AGENTS.md,web/AGENTS.md.model/subscription_route_binding.go(binding cache and expiry),model/subscription_channel_binding.go(IsSubscriptionBoundGroup,ensureSubscriptionBoundGroupRatiokeeps the group out ofUserUsableGroups),service/group.go,middleware/auth.go,middleware/distributor.go.Alternatives considered
UserUsableGroupson bind — every user would see every dedicated group.GetUserUsableGroups(userGroup)— it has no user id and many callers that are not user-specific.auto_groups— it would outlive the binding and use up the per-token limit; the user asked for it to be implicit.Files
service/group.gocontroller/group.go,controller/token.go,controller/user.go,controller/pricing.gomiddleware/auth.go,middleware/distributor.goi18n/keys.go,i18n/locales/*.yamlweb/src/lib/api.ts,web/src/features/keys/components/*subscription_boundflag, hint, locked first Auto rowweb/src/i18n/locales/*.jsonmiddleware/subscription_group_test.go(new),controller/token_auto_groups_test.go,web/.../__tests__/api-keys-mutate-drawer.test.tsx,web/.../__tests__/auto-group-order-editor.test.tsxBehavior
无权访问 claude-chN 分组.claude-chNwith the description and can create keys in it; old keys work again; bound models are served from it, other models get the dedicated-group message; Auto lists start withclaude-chN(locked in the UI, never stored); after unbind/expiry/cancel the group disappears everywhere and its keys get the "no longer available" message. Other users never see or use it.middleware/distributor.go).Verification
Local (Windows 10, go1.26.10, Bun 1.4.0), on 2ba1212 (da62416 only reformats a test file):
GOWORK=off go build ./...(afterbun run build) → ok;cd relaykit && GOWORK=off go build ./...→ ok;cd tokenkit && GOWORK=off go build ./...→ ok (run on 9a161b8; neither module is touched).GOWORK=off go vet ./service/ ./controller/ ./middleware/→ exit 0;gofmt -l controller middleware service→ empty.GOWORK=off go test ./model/ ./service/ ./middleware/ ./i18n/ -count=1→ model, service, i18n ok; middleware onlyTestAccessAndPanicLogsFollowLogRotation(WindowsTempDir RemoveAll cleanupof a rotated log file; fails the same way withmiddleware/at fe07a02).GOWORK=off go test ./controller/ -count=1→ 110 top-level FAIL, allTempDir RemoveAll cleanup … audit.db(268 lines, 0 non-audit, 0Error Trace, 0 panics). The new controller cases pass when run alone (-run 'TestSubscriptionBoundGroupIsUsableOnlyByItsOwner|AutoGroups' -v).middleware/auth.gochange reverted, 6 sub-cases ofTestTokenAuthAcceptsTokensInTheOwnersSubscriptionGroupandTestTokenAuthRejectsTheSubscriptionGroupOnceTheBindingIsRemovedfail; with the drawer change reverted the drawer tests fail.TestSubscriptionGroupLeadsTheOwnersAutoGroups(dedicated group first for active / legacyoauth-chbindings, absent for none / expired / cancelled; global list and token snapshot),TestAutoTokenTriesTheSubscriptionGroupFirstAndSkipsItForOtherModels(Auto token:claude-x→claude-ch1/channel 1;gpt-x→ Auto groupdefaultat index 1, i.e. index 0 = dedicated group was tried and skipped; after unbinding →defaultat index 0), controller: auto-groups endpoint["claude-ch7","default","vip"], saving["claude-ch7","vip"]with limit 1 succeeds and stores["vip"], another user's["claude-ch7"]is rejected.bun x --package @typescript/native-preview tsgo -b→ exit 0;bun x oxlint+bun x oxfmt --checkon the touched TSX files → clean;bun run test→ 211 files, 2527 passed;bun run build→ ok.Docker on the tailnet test host (container
new-api-t09@ 39687, mock upstream, fake OAuth key JSON, no real tokens; data dirC:\Docker\new-api-t261106-01\data; no other container touched):new-api-fork:fork-main-fe07a0240(production build): admin binds channel chore: merge upstream main (72f3dc7da) into fork-main #2 (type 64) to user 2's subscription →claude-ch2. User's/api/user/self/groups=default,viponly. Tokenlegacy-dedicated(groupclaude-ch2, created on this image) +claude-y→ HTTP 403无权访问 claude-ch2 分组(bug reproduced).new-api-fork:t261106-01:/api/user/self/groups→"claude-ch2":{"desc":"Subscription account (bound channel models only)","ratio":1,"subscription_bound":true}plus default, vip;/api/user/models?group=claude-ch2→["claude-y"].legacy-dedicated+claude-y→ HTTP 200 (mock claude); +gpt-x→ HTTP 503订阅专属分组 claude-ch2 只能调用绑定的订阅账号支持的模型,模型 gpt-x 无可用渠道(distributor). Default token:claude-y/gpt-x→ 200.claude-ch2token → success. Admin (no binding): groups lackclaude-ch2; creating aclaude-ch2token →Group claude-ch2 is unavailable or unauthorized.claude-ch2;legacy-dedicated→ HTTP 403该令牌使用的订阅专属分组 claude-ch2 已失效:订阅绑定已过期、作废或解绑,请把令牌改为其他分组. Rebind → 200 again.AutoGroups=["default","vip"],autoadded toUserUsableGroups):/api/token/auto-groups→{"groups":["claude-ch2","default","vip"],"max_count":5};/api/pricingauto_groups→ same;/api/user/models?group=auto→["claude-y","gpt-x"].auto_groups: ["claude-ch2","vip"]→ success, stored["vip"].claude-y→ 200, log groupclaude-ch2channel 2;gpt-x→ 200, log groupdefaultchannel 1 (dedicated group skipped)./api/token/auto-groups→["default","vip"]; the Auto token keeps working (gpt-x→ default/1,claude-y→ default/2). Rebind →["claude-ch2","default","vip"]again.auto_groupsexcludes it).middleware/subscription_group_test.go(new), cases incontroller/token_auto_groups_test.go,api-keys-mutate-drawer.test.tsx,auto-group-order-editor.test.tsx.codex-ch) bindings end to end (same code path, covered only by name matching), the token drawer in a real browser, real OAuth tokens.Risks
SyncFrequency) bounds how long a changed binding can be seen stale in another instance; bind/unbind invalidate it directly (same cache as fix(subscription): route bound users per request instead of switching their group (HQ-Task T261105-13) #9 routing).Scope check
🤖 Generated with Claude Code