alfadb
4a53d49717
fix(ollama): narrow the gpt-oss pricing exclusion and unblock legacy account updates
...
三处独立小修(来自 T0 评审):
1. gpt-oss 排除收窄为冒号命名空间(pricing_service.go GetModelPricing)。
此前的全局前缀排除误伤 Antigravity 默认模型映射目标名 gpt-oss-120b-medium
(连字符形态):它被拦在 OpenAI 回退链外 → GetModelPricing 返回 unavailable
→ 非 Ollama 路径 fail-open 成 0 元记账。收窄后 ollama 侧(gpt-oss:120b /
gpt-oss:20b / gpt-oss:120b-cloud)照修不误,Antigravity 恢复既有行为
(OpenAI catch-all → gpt-5.4 价卡,与 main 一致)。
2. 保存期无价门禁改为只在会改变「可出站模型集合」或影响调度准入时重验
(AccountService.Update / adminServiceImpl.UpdateAccount):platform、
model_mapping、allowed_models 集合实际变化,或从不可调度改为可调度时校验;
name、notes、并发数、状态等维护性更新放行——存量 legacy 账号(无 mapping/
清单)此前连改 name 都被 MODEL_PRICING_MISSING 拒绝。全对象 PUT 原样带回
credentials/extra 时集合未变同样放行。Create 与 BulkUpdate/Duplicate/
SetAccountSchedulable 三条写路径门禁不变。
3. respondOpenAIStatelessFieldError 补 MarkResponseCommitted(照 bcfef18ae 给
定价预检 400 的先例):conversation 400 的错误消息不在
openAIForwardErrorAlreadyCommunicated 识别的前缀内,不置位时 handler 会向
完整 400 JSON body 尾部追加 SSE 终止帧。三入站路径实测:仅 Responses 入站
可触发该 400(CC/Messages 转换不透传 conversation 字段)。
2026-10-08 15:24:05 +08:00
alfadb
e5f75b7b02
fix(ollama): enforce the ollama cloud model whitelist at runtime
2026-10-08 15:24:05 +08:00
alfadb
625f7b0d23
fix(billing): reject unpriced ollama cloud requests before upstream I/O
...
ollama_cloud 的定价门禁此前位于 RecordUsage 成本计算(openai_gateway_usage.go
B2-④ 分支)——那是异步记账阶段:上游已被调用、响应已写给客户端,拒绝只会让
usage 整条不落账,形成「请求成功但不计费」的静默漏损。
本 commit 把门禁前移到上游 I/O 之前(预检是主门,未定价直接 400、上游零调用):
- buildUpstreamRequest(原生 Responses 出站;三条入站路径的转换分支都经过)
- sendCCUpstreamRequest(raw CC 出站;三条入站路径的回退分支都经过)
- buildNativeAnthropicUpstreamRequest(api_protocol=anthropic 独立构造器)
判定与计费同源:复用 RecordUsage → CalculateCostUnified → ModelPricingResolver
同一条解析链(Group → Channel → LiteLLM → Fallback);无价判定取
calculateTokenCost 的失败条件(token 模式下 GetIntervalPricing 无价可取),
按次/图片/视频模式从不因缺价报错故不视为未定价——预检不比计费更严格,
「只有渠道价」的合法流量不会被误拒(含测试)。
400 照抄 conversation 显式拒绝范式:类型化错误 + 服务层写 400
invalid_request_error(写前 MarkResponseCommitted,同 cyber_policy 先例),
handler 检测响应已提交不追加 fallback;错误非 UpstreamFailoverError ⇒
不换号、不写账号处置。
同时撤销异步阶段的 ollama_cloud 显式拒绝,未定价请求回到既有的零成本落账 +
pricing_missing_record_zero_cost 告警路径——该告警是放量观察断言的观测依据,
不能被记账阶段的拒绝吃掉;相应改写 usageRepo.calls==0 的两个用例为
「兜底观测保持可用」的回归。
2026-10-08 15:24:05 +08:00
alfadb
df0199fbdd
feat(scheduling): suspend exhausted legacy ollama cloud accounts
...
增量 4a(③ 组 A6+C25+E9 + ⑤ 组 A2 + F4,同批落地):
- A2: 新增 AccountModeOllamaLegacy/OllamaCredits 常量与
Account.GetOllamaCloudAccountMode 解析器(非 ollama_cloud/非 apikey
返回空串;未设置或值不认识默认 legacy,存量账号保持受阈值保护)
- A6: AllowedSchedulingThresholdPlatforms 纳入 ollama_cloud(4 个消费点
同步生效:评估器门禁、设置校验、存储解析、设置审计 diff)
- C25: 评估器新增 ollama 分支 + ollamaCloudThresholdCandidates,仅 legacy
产生 5h/weekly 停调候选(credits 型月度信用池候选恒空);快照缺失/
status!=ok/无窗口数据不停调;取最晚 reset(与 openai/anthropic 同类)
- E9: 前端 SchedulingThresholdPlatformType union 与
SCHEDULING_THRESHOLD_PLATFORMS 数组加 ollama_cloud(与后端白名单两侧同步)
- F4: 评估器表驱动用例(legacy 停/credits 不停/默认 legacy/坏快照不停)、
ApplyAccountSchedulingThreshold 端到端(temp_unschedulable 落库断言)、
mode 解析器用例、设置校验 ollama_cloud 往返用例
无迁移、无 DTO 变更(account_mode 为自由 JSONB,无 CHECK 约束)。
2026-10-08 15:24:05 +08:00
alfadb
6995a6226d
feat(billing): gate unpriced ollama cloud models at save and request time
...
- save-time gate on admin account create/update (and AccountService, which has
no production consumers but is the spec-mandated location): non-empty
model_mapping values and empty-mapping allowed_models lists must all resolve
via GetModelPricing, otherwise 400 MODEL_PRICING_MISSING
- request-time gate: ollama_cloud accounts no longer fall into the global
zero-cost path when pricing is unavailable; explicit 4xx instead
- operational preflight SQL documented as comments (not a migration)
- include ollama_cloud in the billing model candidate filter (S1) so claude-*
names can no longer be priced at Anthropic rates for this platform
- keep ollama_cloud out of the LiteLLM platform map on purpose (comment only)
- refresh a stale comment in upstream_billing_probe.go
2026-10-08 15:24:05 +08:00
alfadb
a6f83e9d04
fix(billing): keep gpt-oss names out of the OpenAI pricing fallback chain
...
复现:动态目录含 gpt-5.4 时,gpt-oss:120b/20b 经 matchOpenAIModel 末端
catch-all 落到 DefaultTestModel(gpt-5.4) 价卡($2.5/$15 per MTok,实测
日志 "OpenAI fallback to default model gpt-oss:120b -> gpt-5.4"),绕过
fallbackPrices 的 ollama 价卡($0.15/$0.60 与 $0.07/$0.30),输入价
静默多收约 17~36 倍。
修复:GetModelPricing 第 5 步排除 gpt-oss 前缀进 OpenAI 回退链(返回 nil
交还 BillingService 走 fallbackPrices 的 ollama 价卡);不动任何其它匹配
规则与价格数值。gpt-oss-120b-medium(Antigravity 白名单同名族,仓库无其
定价条目)由误计 gpt-5.4 价转为 fail-closed,与无目录时行为一致。
回归护栏:ollama_cloud_dynamic_catalog_pricing_test.go 表驱动钉死 8 个
ollama 独占模型在目录已加载形态下的实际解析价,并钉住真实 OpenAI 名
(gpt-5.4 目录精确命中 / gpt-4o catch-all / gpt-5.5 静态兜底)不受影响。
2026-10-08 15:24:05 +08:00
alfadb
c42b758372
feat(billing): price ollama cloud models and resolve tagged model names
...
B2-②: add fallbackPrices entries for the 8 ollama-exclusive cloud models
(gpt-oss:120b/20b, gemma4:31b, mistral-large-3:675b, qwen3.5:397b,
nemotron-3-super/nano:30b/ultra) with official per-token rates, plus
exact/prefix family rules in getFallbackPricing. gpt-oss tiers and the
three nemotron tiers are matched precisely (no bare gpt-oss/nemotron
prefix); models without a published cached-input tier bill cached input
at the input rate instead of 0.
B2-①: two-level pricing lookup for ":tag" model names. Shared helper
normalizePricingModelNameForLookup yields the stripped candidate; wired
into getModelPricingAt (full chain rerun, pricingAt preserved),
matchGroupModelPricing (exact retry) and lookupChannelPricingNormalized
(third retry after the codex normalization; applyChannelOverrides
inherits it). Literal name always wins, so bedrock canonical keys like
us.anthropic.claude-sonnet-4-5-20250929-v1:0 are never destructively
stripped; normalizeChannelPricingModelName stays untouched.
Tests: full /v1/models listing pinned with hit paths, tag-strip and
fail-closed behavior, bedrock double-key regression at base/channel/
group layers.
2026-10-08 15:24:05 +08:00
alfadb
361e584bcf
feat(ollama): make responses and max_tokens hooks platform-aware
...
- C31: include ollama_cloud in SupportsNativeCNResponses so /v1/responses
ingress routes to the platform-native endpoint instead of degrading to
raw CC, and the stateless normalize hook (store=false + strip
previous_response_id) now applies to ollama accounts
- D2/C37': reject the stateful conversation field with an explicit 400
invalid_request_error on native Responses accounts instead of silently
dropping context; normalizeDeepSeekResponsesRequestBody now returns
([]byte, error) with all three production call sites propagating the
typed error as a client-visible 400
- D1': clamp max_tokens for non-DeepSeek models too on ollama.com
upstreams (raw CC, native Responses, Anthropic Messages); the host
check is the boundary, the >65535 upstream 400 is model-independent;
delete the now-dead isOllamaCloudRawChatCompletionsAccount predicate
- C39: mark ollama_cloud accounts force_responses in the Responses
probe (per-protocol, no network probe) and let the admin handler
schedule the probe for ollama_cloud accounts
2026-10-08 15:24:05 +08:00
alfadb
551797e24f
feat(ollama): platform-ize ollama_cloud usage service
...
- D1(u): usage platform whitelist now admits platform=ollama_cloud via
authoritative OllamaCloudUsagePlatforms (ollama_cloud + legacy host
platforms); host gate (official ollama.com) untouched
- D3(u): repository SQL platform whitelist derived from the service list
(const -> var via ollamaCloudPlatformsSQLLiteral) instead of a hand
mirrored literal - drift now structurally impossible
- D4(u)+F3: TestOllamaCloudUsagePlatformsMirror locks the derivation
(parse count, ElementsMatch, eligible SQL contains every platform);
existing predicate test covers ollama_cloud and dynamically sized list
- D2(u): ErrOllamaCloudUsageAccountInvalid message derived from the
whitelist (code unchanged - external contract)
- D6(u): doc comment on IsOllamaCloudUsageAccount (three conditions,
reverse-proxy eligible=false is expected)
- D8(u): decision record on ollamaCloudUsageSettingsURL (hardcoded
official settings page, not configurable - host gate / SSRF surface)
- D9(u): OllamaCloudUsageState.EligibleReason distinguishes
platform_not_eligible / wrong_account_type / unsupported_base_url
- F5: service usage tests cover ollama_cloud platform (official host
pass, reverse-proxy fail, oauth reject) and reason codes
2026-10-08 15:24:04 +08:00
alfadb
b868e94c15
feat(platform): align ollama_cloud platform lists for composite routing and pricing
...
- C11: matchingPlatforms composite branch includes ollama_cloud so channel
pricing/mapping cache lookups stay consistent with isConcreteRequestPlatform
- C20: openAICompatibleTextTargetAllowed allows ollama_cloud resolved targets
- C21: compositeAvailableModels aggregates ollama_cloud account mapping keys
(claude default-list fallback already gated off by IsMultiProtocolAPIKeyProvider)
- test sync: composite matchingPlatforms expectation, bulk account event
rebuild coverage for the ollama_cloud bucket, ollama_cloud text-target case
2026-10-08 15:24:04 +08:00
alfadb
3b0e4f792c
feat(platform): admit ollama_cloud to scheduling pool and composite routes
2026-10-08 15:24:04 +08:00
alfadb
0d22f90e04
feat(platform): wire ollama_cloud into scheduling and routing
...
增量 2(⑥ 组 + ⑨ 组,严格同批):
⑥ adaptive 准入 / 协议路由 / base 守卫:
- A9/A13: IsOllamaCloud 谓词 + Account.IsOllamaCloud();
IsMultiProtocolAPIKeyProvider 纳入 ollama_cloud(adaptive 总开关)
- A11: GetAPIProtocol 缺省档扩为 opencode_go || ollama_cloud → adaptive
- A7/A10 + C30/Q2-3: DefaultOllamaCloudBaseURL(https://ollama.com/v1 ) /
DefaultOllamaCloudAnthropicBaseURL(https://ollama.com ),并补
GetOpenAIBaseURL 与 defaultCNProtocolBaseURL 的平台分支
- C33/Q2-4 + S6 层 1: GetOpenAIBaseURL 平台守卫纳入 ollama_cloud;
多协议账号缺省端点不再回落 https://api.openai.com
- C32: shouldForwardOpenAIResponsesViaRawChatCompletions 新增 ollama_cloud
分支(不复用 opencode 的恒 false)
- S5: nativeAnthropicTargetURL 改用版本感知 buildOpenAIEndpointURL,
删除 opencode_go 特判(消灭 /v1/v1/messages)
- S6 层 2: CC / Responses / passthrough 三处 OpenAI 官方域名兜底
对多协议账号改为显式报错(防凭据外泄)
⑨ count_tokens(必须与 C40 同批):
- findings B1: openai_gateway_count_tokens.go 本地估算分支加入
IsOllamaCloud()(命中时不产生任何出站请求)
- C40: routes/gateway.go 的 responses 兼容白名单与 count_tokens
分派白名单加入 service.PlatformOllamaCloud
新增单测 ollama_cloud_platform_routing_test.go:
默认协议/base、nativeAnthropicTargetURL 带与不带 /v1 双向、C32 分流、
count_tokens 本地估算零出站。
2026-10-08 15:24:04 +08:00
alfadb
3182f6d1cc
fix(ollama): clamp DeepSeek max_output_tokens on all native Responses paths
2026-10-08 15:24:04 +08:00
alfadb
fb8408029d
fix(ollama): apply DeepSeek reasoning/max_tokens adapter on CC bridge paths
2026-10-08 15:24:04 +08:00
alfadb
0ec37bd26b
fix(ollama): normalize DeepSeek reasoning by upstream endpoint, not platform
2026-10-08 15:24:04 +08:00
alfadb
110958f77a
feat(platform): add ollama_cloud platform skeleton
...
- 新增 PlatformOllamaCloud 常量与 AllowedQuotaPlatforms 白名单
- 同步 ent schema 平台校验(user_platform_quota / channel_monitor /
channel_monitor_request_template)及生成物
- 新增迁移 239:4 类 CHECK 放宽至 238 的超集(含 ollama_cloud),零 DML 回填
- 新增迁移测试断言 239 为 238 严格超集
- 前端:平台目录、类型联合、配色、图标、i18n 文案
2026-10-08 15:24:04 +08:00
alfadb
7ff8fd3458
feat(composite): serve cross-family pools via per-account protocol dispatch
...
解除 composite 候选池的协议族限制:入站任意协议族端点可服务池内任意
平台账号,厂商多协议时优先与入站相同的协议族(零转换),否则协议转换。
- routes:混族/全原生族池不再 400,落 generic 网关按选中账号分发;
全 OpenAI 族池仍走 OpenAI handler(不变)
- generic 调度器放行池:跨平台候选合并选号、池感知平台/模型门、
sticky 复检防塌缩(镜像 OpenAI 族池调度)
- generic 转发 base 协议化:多协议账号打 GetAnthropicProtocolBaseURL
的 {base}/v1/messages(无 ?beta=true、认证/clamp 同源),classic
anthropic 不回归
- generic Messages/Responses/ChatCompletions 循环池化:per-attempt
配额与渠道策略(复用 OpenAI 池策略)、attempt ctx + platform 作用域
渠道映射;纯 OpenAI 族账号按端点委派 OpenAI 网关同族链,usage 适配
进既有计费流;count_tokens 不可计数账号排除重选
- 谓词能力驱动(IsAnthropicProtocol/adaptive/GetAnthropicProtocolBaseURL),
不引入平台硬编码清单,后续多协议平台合入后零改动继承
2026-10-08 15:24:04 +08:00
alfadb
16612cd6a7
test(composite): align empty-mapping deepseek fixtures with official model whitelist
...
组合 fix/deepseek-model-name-validation 后,DeepSeek 空 mapping 账号的
IsModelSupported 改按官方白名单判定,deepseek-chat 已不在白名单。composite
规则B(空 mapping native claim)语义不变,测试夹具从已退役的 deepseek-chat
换成白名单名 deepseek-flash / deepseek-v4-pro。
2026-10-08 15:24:04 +08:00
alfadb
006ed5af25
fix(composite): handle unavailable sticky accounts without panic
2026-10-08 15:24:04 +08:00
alfadb
d1f65572c1
feat(composite): balance compatible providers with sticky sessions
...
composite 路由改为按兼容平台候选池跨平台调度:调度状态归属候选池并支持 previous_response_id sticky 绑定,per-attempt 策略按渠道限制、平台/渠道配额与 RPM 准入筛选,出站记录仅记实际选中的 upstream。
2026-10-08 15:24:04 +08:00
Wesley Liddick
5fc0e486c3
Merge pull request #7916 from wucm667/fix/issue-7914-monitor-request-sample
...
fix(channel-monitor): require request samples before health scoring
2026-10-08 13:52:34 +08:00
Wesley Liddick
2eb7ccb6d2
Merge pull request #7703 from wucm667/fix/issue-7700-thinking-signature
...
fix(openai): recover rejected encrypted reasoning signatures
2026-10-08 13:48:33 +08:00
Wesley Liddick
745ff1d3ca
Merge pull request #7911 from lyy0709/codex/usage-output-tps
...
feat(usage): add output TPS to usage logs and ops dashboard
2026-10-08 11:40:15 +08:00
Wesley Liddick
8e2c4fad32
Merge pull request #7793 from wucm667/fix/issue-7784-composite-route-model-list
...
fix(models): list composite exact route aliases
2026-10-08 11:39:51 +08:00
Wesley Liddick
7ff5cff1bb
Merge pull request #7822 from neotan/fix/issue-7670-bare-api-alias-bypass
...
fix(web): bypass bare API aliases from embedded frontend fallback
2026-10-08 11:33:58 +08:00
Wesley Liddick
bc63bd2874
Merge pull request #7782 from lyy0709/codex/fix-remote-model-catalog
...
fix(models): enforce account mappings for remote Codex discovery
2026-10-08 11:33:27 +08:00
Wesley Liddick
458865ed1b
Merge pull request #7878 from Achordchan/fix/account-test-log-context
...
fix(accounts): attribute connectivity test failure logs
2026-10-08 11:33:14 +08:00
Wesley Liddick
3a7fd4ae78
Merge pull request #7837 from yJader/fix/antigravity-account-test-models
...
fix: use account mapping keys for Antigravity connectivity tests
2026-10-08 11:32:59 +08:00
Wesley Liddick
4b8c557705
Merge pull request #7877 from hezhaoqian1/fix/upstream-channel-monitor-zhipu-path
...
fix(channel-monitor): build zhipu probe URL from the configured endpoint
2026-10-08 11:32:38 +08:00
Wesley Liddick
bb0d4a53c9
Merge pull request #7887 from whhphd/fix/grok-sso-consent
...
fix(grok): include consent token and origin in SSO device approval
2026-10-08 11:32:25 +08:00
Wesley Liddick
3c274768c1
Merge pull request #7889 from aishangwuji/fix/opencode-zen-routing-and-unsupported-models
...
fix(opencode): correct Zen qwen3.8-max endpoint and reject unsupported models
2026-10-08 11:32:11 +08:00
Wesley Liddick
bbf1d37783
Merge pull request #7891 from aishangwuji/fix/opencode-go-usage-retry-after-and-403
...
fix(opencode): cap Retry-After backoff at 24h and report neutral 403
2026-10-08 11:31:40 +08:00
Wesley Liddick
90afaf120e
Merge pull request #7854 from wucm667/fix/issue-7852-chat-stream-heartbeats
...
fix(streaming): preserve chat stream heartbeat comments
2026-10-08 11:28:38 +08:00
Wesley Liddick
6cacccc767
Merge pull request #7775 from YahooYuan666/fix/grok-empty-completed-silent-refusal
...
fix(grok): fail over silent-refusal empty response.completed on Grok Responses streams
2026-10-08 11:28:22 +08:00
Wesley Liddick
2afe7d4577
Merge pull request #7910 from liuyh06/codex/fix-responses-namespace-noop
...
perf(openai): lazily rebuild input when stripping namespaces
2026-10-08 11:28:02 +08:00
Wesley Liddick
129369204e
Merge pull request #7827 from Achordchan/fix/anthropic-tool-change-betas
...
fix(anthropic): preserve requested tool change beta headers
2026-10-08 11:27:45 +08:00
Wesley Liddick
f19cd4fdea
Merge pull request #7844 from cyhhao/fix/anthropic-cache-ttl-order
...
fix(anthropic): keep cache TTL order valid on the mimic path
2026-10-08 11:27:27 +08:00
Wesley Liddick
e473fba99c
Merge pull request #7869 from 3219378872/fix/thinking-signature-key
...
fix(apicompat): always include `signature` on Anthropic thinking blocks
2026-10-08 11:27:14 +08:00
Wesley Liddick
cc4a1e3f61
Merge pull request #7789 from SPHINX998/fix/anthropic-buffered-negative-block-index
...
fix(gateway): ignore negative content block index in buffered Anthropic paths
2026-10-08 11:26:47 +08:00
Wesley Liddick
9d49d275f3
Merge pull request #7788 from SPHINX998/fix/apicompat-responses-refusal-to-chat
...
fix(apicompat): preserve refusals when converting Responses to Chat
2026-10-08 11:26:28 +08:00
Wesley Liddick
8d50466809
Merge pull request #7787 from SPHINX998/fix/apicompat-chat-legacy-function-call
...
fix(apicompat): pair legacy chat function calls with their results
2026-10-08 11:26:15 +08:00
Wesley Liddick
f9bd97cc15
Merge pull request #7786 from SPHINX998/fix/apicompat-chat-developer-role
...
fix(apicompat): keep chat developer messages as developer role
2026-10-08 11:26:03 +08:00
Wesley Liddick
f087fdb205
Merge pull request #7785 from SPHINX998/fix/apicompat-chat-named-tool-choice
...
fix(apicompat): flatten named chat tool_choice for Responses
2026-10-08 11:25:46 +08:00
Wesley Liddick
ef16f8a3d1
Merge pull request #7792 from SPHINX998/fix/ws-passthrough-image-usage
...
fix(openai): account image input usage on WS passthrough
2026-10-08 11:25:31 +08:00
Wesley Liddick
6db4171cfb
Merge pull request #7779 from SPHINX998/fix/ws-turn-group-pricing
...
fix(openai-ws): bill each later turn with the current group pricing
2026-10-08 11:25:10 +08:00
Wesley Liddick
db29b3a773
Merge pull request #7811 from kingsleydon/fix/codex-service-tiers-null-fallback
...
fix(codex): never advertise null service_tiers in models manifest
2026-10-08 11:23:47 +08:00
wucm667
7cd3dc85c3
fix(channel-monitor): require request samples before health scoring
2026-10-08 10:41:20 +08:00
lyy0709
1817a8428a
feat(ops): show per-request output TPS percentiles
2026-10-07 13:06:19 -07:00
liuyh06
61e1afdd49
perf(openai): lazily rebuild input when stripping namespaces
2026-10-08 01:11:23 +08:00
shaw
6e315616ed
fix(setup): stop shipping guessable admin credentials on fresh installs ( fixes #7850 )
...
Fresh Docker installs created the admin as admin@sub2api.local and accepted
any ADMIN_PASSWORD (e.g. "123456"), making them easy brute-force targets.
- Generate a random admin-<12 hex>@sub2api.local login email when
ADMIN_EMAIL is empty; drop the fixed default from .env.example and the
compose files, and have docker-deploy.sh write a random ADMIN_EMAIL.
- Validate user-supplied ADMIN_PASSWORD (8-72 bytes) and ADMIN_EMAIL on the
auto-setup path, only when an admin is actually about to be created, so
existing deployments are never blocked at startup.
- Align validateEmail with the login endpoint's email binding so setup can no
longer create an admin that can never log in (e.g. "a@b", "Name <a@b.com >").
- Cap validatePassword at bcrypt's 72-byte limit; the CLI reuses it and now
defaults to a random admin email instead of admin@example.com .
- Update READMEs/deploy docs to stop suggesting guessable credentials.
2026-10-07 09:27:36 +08:00