Commit Graph
7872 Commits
Author SHA1 Message Date
shaw e6c19082f2 chore: update sponsors 2026-11-07 09:49:12 +08:00
Wesley Liddick 0eee80ba87 Merge pull request #8518 from StarryKira/codex/json-hotpath-performance
perf(gateway): reduce JSON copies and repeated request parsing
2026-11-06 18:49:10 +08:00
harukaandClaude Opus 5.5 1c83bb825a test(repository): assert the auth projection carries require_privacy_set
OpenAI scheduling now reads the privacy gate from the auth snapshot; cover
the GetByKeyForAuth projection so a dropped column fails here instead of
admitting accounts without privacy set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 f654c23eb7 perf(gateway): decide thinking-block filtering without decoding the body
FilterThinkingBlocks runs on every Anthropic forward. Its substring fast path
matches any request with top-level thinking config or signed thinking
history, which is nearly all Claude Code traffic, so it decoded the whole body
into a map even when nothing would be filtered.

Mirror the filter decision on borrowed gjson views, applying encoding/json's
last-wins rule for duplicate keys, and return the body untouched when no block
would be dropped. Bodies that need filtering still take the original decode
and marshal path, so output bytes are unchanged; a differential test and fuzz
target compare both paths.

On a 450 KB signed history: 1.29 ms, 904 KB, 10,629 allocs -> 0.67 ms, 0 B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 4ca1a2097c perf(openai): skip full-body decodes for Codex bootstrap and compaction
Every /v1/responses request ran the automation and delegation bootstrap
normalizers, each a json.Decoder token scan plus a full map decode, and
NormalizeCompactionTriggerInputOrder decoded the whole body on each HTTP
request and WebSocket turn, although almost none of them can change it.

- Bootstrap normalizers return early unless the raw body contains
  function_call_output and one of their tool names, or any \u escape that
  could spell them.
- The compaction normalizer returns early when the body has neither
  compaction_trigger nor a \u escape and is a valid JSON object, so invalid
  or non-object bodies still report the original decode error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 00660a227a perf(gemini): stop copying the emitted prefix on every stream delta
computeGeminiTextDelta returned seen+incoming for each incremental chunk, so
a long thinking, text or tool-argument block copied its whole prefix per
chunk and grew quadratically.

Keep the emitted text in a strings.Builder per block. Only storage changes:
the cumulative, duplicate/rewind and delta decisions and the returned deltas
are identical, verified against the previous implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 d446c4a6bb fix(gemini): bound upstream SSE lines and antigravity non-stream reads
The Gemini native, Claude-compat, Chat Completions-compat and stream collector
paths read upstream SSE with bufio.Reader.ReadString, so a custom base_url
upstream that never sends a newline could grow one line without limit.

- Read these streams through boundedSSELineReader, which keeps line endings
  and EOF semantics and enforces the configured line and event limits. An
  overflow is a stream read error; no truncated prefix is forwarded.
- Thread cfg into collectGeminiSSE/collectGeminiSSEObserved.
- Antigravity ForwardUpstream reads non-stream responses with
  ReadUpstreamResponseBody instead of an unlimited io.ReadAll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 9bb073d0d1 perf(openai): read the group privacy gate from the auth snapshot
Each OpenAI account selection read the group row twice: once to resolve
require_privacy_set into the request, and again in selectByLoadBalance,
which ignored that result.

- Project require_privacy_set into the auth snapshot (v27) and resolve it
  from the ctx group when it is the scheduled group; composite members and
  other mismatches still read the repository.
- selectByLoadBalance filters on the already-resolved req.RequirePrivacySet,
  so a failed group read is handled once, fail-closed, as in Select.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 76221c9cb0 perf(billing): stop querying the RPM override on every request
The auth snapshot stored "no override" and "lookup failed" both as nil, so
checkRPM fell back to SELECT rpm_override on nearly every gateway request.

Record the group whose override lookup succeeded (snapshot v26). checkRPM
trusts a nil override only for that group; lookup failures and other groups,
such as composite members, still query the database. Admin override writes
already invalidate the auth cache by group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 a0b058a9e9 fix(bedrock): validate EventStream frame lengths before allocating
The decoder allocated total_length bytes straight from the upstream prelude
(up to ~4 GiB) and sliced headers by an unchecked headers_length, which could
panic in the decode goroutine outside gin's recovery and crash the process.

Reject frames whose headers exceed 128 KiB or the frame, or whose payload
exceeds 16 MiB (the AWS EventStream protocol limits), before allocating.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 0853d16036 fix(images): give async image tasks their own body memory reservation
Async tasks inherited the ingress reservation through context.WithoutCancel,
but RequestBodyLimit releases and closes it when Submit returns. The task's
request body was a plain reader, so the gateway's read reserved against the
closed reservation and every task failed with a 503 budget error.

- Add httputil.DetachRequestBodyMemory: a reservation on the same budget that
  the handler's release does not close. It takes over the retained body's
  existing charge from the request and reserves only the remainder, so the
  body is never counted twice; the caller releases it when the work ends.
- Submit reserves the retained body before creating the task, returning 503
  with Retry-After on exhaustion instead of accepting a task that cannot run;
  the task releases it when execution finishes.
- Back the task request with PrereadBody so the body is not buffered again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
harukaandClaude Opus 5.5 957a83f32e fix(gateway): settle patch budget per attempt and keep map fallback reachable
- ApplyPatches reserves the input size before editing on every strategy
  (batched Doc, single edit, sequential sjson), settles to the exact output
  length, and refunds on failure, so batching no longer adds a rejection
  that the unoptimized paths bypass.
- Forward holds patched outputs in a WithRequestBodyMemoryScope: a newer
  output releases the superseded one and the last is returned when the
  attempt ends, instead of accumulating across failovers until the handler
  returns.
- A Doc edit error retries with sequential sjson; when raw edits cannot
  express the patch set, Forward replays it onto the decoded map rather than
  re-running ApplyPatches and failing the request.
- Snapshot reuse in CloneForBody/ReplaceBody also checks a maphash content
  fingerprint, so in-place edits of shared storage reparse.
- Reuse openAIWSPayloadStringView for borrowed views and split batch path
  eligibility into isOpenAIBatchPatchPath with an O(P^2) ancestor check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 03:00:03 -05:00
haruka 6c140b8976 perf(gateway): reduce JSON copies and repeated request parsing 2026-11-06 03:00:02 -05:00
Wesley Liddick c5ca149a3d Merge pull request #8543 from wucm667/feat/issue-8541-openai-transport-cooldown
feat(openai): allow disabling transport error cooldown
2026-11-06 10:45:17 +08:00
Wesley Liddick 9432aa05fc Merge pull request #8549 from Wei-Shaw/fix/issue-8519-cyber-transcript-overflow
fix(openai): 按已屏蔽前缀长度精确匹配 cyber transcript,修复长会话误拦 (#8519)
2026-11-06 10:29:20 +08:00
shaw b6c0ca4256 chore(deps): 升级 brotli v1.2.7 与 klauspost/compress v1.20.2 修复 govulncheck 告警
GO-2026-6888 (brotli 解压过量内存分配) 与 GO-2026-6865 (zstd 双块帧 panic)
均有可达调用路径,backend-security 扫描因此失败。
2026-11-06 09:33:04 +08:00
wucm667 489cfd5f4f feat(openai): allow disabling transport error cooldown 2026-11-05 21:55:07 +08:00
shaw 7e3b6c72fa fix(openai): 按已屏蔽前缀长度精确匹配 cyber transcript,修复长会话误拦 (#8519)
同一来源触发 cyber 屏蔽后,scope 激活期间任何历史超过 256 个 item 的
会话都会因 lookup 截断被 fail-closed 判为 transcript_lookup_limit_exceeded,
即使与被屏蔽会话毫无关系、且带有不同的显式 session_id。

改为在命中时记录 transcript 屏蔽 key 覆盖的历史长度(按 API Key 建 Redis
SET 索引,随 scope 同 TTL),查询时仅在这些长度处重算前缀哈希:
- 无关长会话不再被误拦,历史长度本身不再决定屏蔽
- 追加任意数量 item 仍能命中被屏蔽前缀,防逃逸能力不降
- 查询 MGET 由最多 256 key 降为记录长度数,遍历在最长记录长度处提前终止
- scope 门控、API Key 命名空间与 cyber-transcript:v3 哈希格式均不变
2026-11-05 21:51:26 +08:00
shaw 25608d216b chore: update sponsors 2026-11-05 17:55:19 +08:00
Wesley Liddick 8e92c892b4 Merge pull request #8495 from FeeiCN/patch-1
fix: GPT-5.5已不提供服务,默认导出模型改为GPT5.6-SOL
2026-11-05 09:34:43 +08:00
Wesley Liddick 503617a82f Merge pull request #8484 from StarryKira/codex/backend-resource-safety
fix(backend): bound gateway resources and background work
2026-11-05 09:15:13 +08:00
haruka 457602c8fc fix(backend): bound gateway resources and background work 2026-11-04 23:54:03 +08:00
shaw 876b96d204 chore: update sponsors 2026-11-04 22:31:07 +08:00
shaw 2510944363 chore: update sponsors 2026-11-04 21:06:20 +08:00
shaw e353c83226 chore: update sponsors 2026-11-04 21:04:17 +08:00
Wesley Liddick b9d6ff5ca2 Merge pull request #8504 from feeeei/feat/registration-email-blacklist
feat(auth): 注册邮箱精确黑名单,保存时可批量禁用命中的已注册用户
2026-11-04 21:01:00 +08:00
feeeei 721dfb282e feat(auth): 注册邮箱精确黑名单,保存时可批量禁用命中的已注册用户
- 系统设置 → 注册设置新增「邮箱黑名单(精确匹配)」,弹窗编辑、批量粘贴,上限 20000 条,
  名单存于 settings 键 registration_email_blacklist,由专用接口整体读写;运行时读 60s TTL
  进程内缓存,保存后本实例立即生效
- 按收件箱身份匹配(复用 NormalizeEmailForAliasDedup):Gmail 点号、googlemail.com 与 +后缀
  变体视为同一邮箱
- 邮箱注册、发验证码、第三方登录补建账号、绑定/换绑邮箱命中时返回 EMAIL_BLOCKED;
  已验证邮箱的 OAuth 登录只在新建账号时拦截,已有账号是否可用由账号状态决定
- 保存后对新增项查找仍启用的普通用户并弹窗确认批量禁用(跳过管理员、已禁用与已删除用户),
  与单个禁用一样在同一事务内吊销 MCP 授权,禁用后清理认证缓存;也可随时对整份名单手动检查
2026-11-04 17:52:05 +08:00
Wesley Liddick 6f92090d7f Merge pull request #8462 from feeeei/feat/openai-image-size-tier-routing
feat(openai): 生图账号按 1K/2K/4K 尺寸档位分流
2026-11-04 17:11:58 +08:00
Wesley Liddick ee74473e03 Merge pull request #8499 from feeeei/fix/openai-passthrough-instructions-echo
fix(openai): 透传放行空 instructions,响应回显按客户端原值还原
2026-11-04 17:11:47 +08:00
Wesley Liddick e320a1500b Merge pull request #8318 from wucm667/fix/issue-8313-antigravity-system-identity
fix(antigravity): neutralize stale system identities on forwarding
2026-11-04 17:11:35 +08:00
Wesley Liddick 393167ea9a Merge pull request #8436 from feeeei/fix/usage-export-rate-limit
fix(usage): 用户导出 CSV 每页取 1000 条,遇面板限流 429 按 Retry-After 等待后重试
2026-11-04 17:11:23 +08:00
Wesley Liddick ccc2c161b5 Merge pull request #8503 from wucm667/fix/issue-8502-kimi-concurrency-cooldown
fix(kimi): use short cooldown for concurrency-limit 403
2026-11-04 17:11:12 +08:00
Wesley Liddick 45b51a8ac4 Merge pull request #8465 from wucm667/fix/issue-8461-grok-message-input
fix(grok): normalize delegated message input for Responses
2026-11-04 17:11:00 +08:00
wucm667 17772947bd fix(kimi): use short cooldown for concurrency-limit 403 2026-11-04 00:43:51 +08:00
feeeei 6b565e45a6 fix(openai): 生图尺寸溢出选号后按首轮前的绑定处理会话粘性
未指定尺寸的生图请求逐层选号时:

- 较早轮次只拿到排队结果后,后续轮次选号不写会话粘性绑定;
- 溢出轮次抢到槽位时,会话仍绑定在首轮选号前的账号上则保留该绑定,
  否则(首轮前没有绑定,或绑定在选号中被清除、改写)绑定实际服务的账号;
- 各轮都只能排队时,绑定保持首轮选号后的状态。

旧调度器顺序模式在抢槽前写绑定,此前会让首轮前没有可用绑定的会话在溢出后仍绑定在排队账号上。
2026-11-03 23:56:39 +08:00
feeeei a699c2baed fix(openai): 透传放行空 instructions,响应回显按客户端原值还原
- OAuth 透传不再对 codex 模型的空串、空白或非字符串 instructions 本地返回 403,原样转发给上游(官方 Codex 接口已不要求 instructions 必传)。
- 网关补写、追加或搬运 instructions 后,response.instructions 回显按客户端请求里的原始取值还原,客户端未传时还原为 null;覆盖原生与透传两条 HTTP 路径的流式、非流式与 SSE 转 JSON 出口。还原值压缩成单行,写回 SSE data 行不会拆帧。
2026-11-03 23:01:12 +08:00
Feei e97a48d84b fix: GPT-5.5已不提供服务,默认导出模型改为GPT5.6-SOL 2026-11-03 15:35:48 +08:00
feeeei e452e41e40 feat(openai): 生图账号按 1K/2K/4K 尺寸档位分流
账号 extra 新增 openai_image_size_tiers,限定账号承接的生图尺寸档位;档位口径与
计费 ClassifyImageBillingTier 一致(最长边 ≤1024=1K、≤2048=2K、更大=4K)。
缺省、空列表或三档齐全表示不限,存量账号行为不变。

- 请求尺寸可识别:只调度到允许该档位的账号,切号也只在这些账号之间进行。
- 未传 size / auto / 无法识别:不过滤,按偏好层级逐层选号——不限档位 → 允许 4K →
  允许 2K → 仅 1K;跳过没有账号的层级;较早层级只能排队时继续尝试后续层级,都抢不到
  槽位时返回最早的排队结果,且溢出选中的账号不改写会话已有的粘性绑定;会话粘性与
  previous_response_id 绑定的账号不受偏好约束。
- 档位轮次包在代理隔离 fail-open 之内:先不绕过隔离跑完全部档位,再整体绕过重跑。
- 覆盖 /v1/images/generations、/v1/images/edits(含异步图片任务)与 /v1/responses
  显式 image_generation 工具(tools[].size);判定挂在高级调度与旧调度/DB 复检的共用
  兼容检查上;调度快照 extra 白名单加入该键。
- 分组内持久可调度、支持该模型且具备所需能力的账号都不允许该档位时返回 400
  invalid_request_error,临时不可用仍为 503。
- 测试连接:受限账号按最低允许档位发送代表尺寸(1024x1024 / 1536x1024 / 3840x2160)。
- 前端:创建/编辑账号弹窗(OpenAI 全部类型)与批量编辑加入档位多选,至少保留一档;
  批量编辑全选时提交空列表表示不限。
2026-11-03 13:18:50 +08:00
Wesley Liddick 4a4a83ee5e Merge pull request #8476 from lyen1688/fix/admin-key-permissions-8473
完善管理员 API Key 权限并新增需确认的全权兼容模式
2026-11-02 11:17:44 +08:00
lyen1688 b0db521ceb 修复权限国际化编码的 ES2020 类型兼容错误 2026-11-02 00:19:57 +08:00
lyen1688 ff04296510 补齐管理员密钥中英文权限展示并修复依赖安全扫描 2026-11-02 00:11:17 +08:00
lyen1688 194d69e636 完善管理员密钥权限并新增需确认的全权兼容模式 2026-11-01 23:52:35 +08:00
wucm667 522f1fb999 fix(grok): normalize delegated message input for Responses 2026-10-31 23:49:02 +08:00
feeeei e47abd8f9b fix(usage): 用户导出 CSV 每页取 1000 条,遇面板限流 429 按 Retry-After 等待后重试
用户使用记录导出按 100 条/页连续请求 GET /api/v1/usage,该路由计入按用户的
重查询限流(默认 heavy_rpm=60,固定 60 秒窗口)。数据量超过约 5,000 行时,
导出在第 50~60 页收到 429,任一页失败即整体报「导出失败」。

- 导出页大小改为 1000(后端分页上限),请求数降为原来的 1/10。
- API 客户端结构化错误携带 retry_after_seconds(解析整数秒的 Retry-After)。
- 导出遇 429 时提示并按 Retry-After 等待(读不到时按 60 秒,夹在 1~60 秒)
  后重试同一页,每页最多重试 3 次。
2026-10-30 13:53:18 +08:00
shaw d851a38477 fix(frontend): upgrade vue-i18n to v11 and patch decode-uri-component
Fixes frontend-security on main for two new high advisories:
- GHSA-83rm-6c8r-g728 (vue-i18n / @intlify/* srcdoc XSS): v9 and v10
  are end of life and will not be patched, so move vue-i18n and
  @intlify/message-compiler to 11.4.16.
- GHSA-qr28-fpjm-wq7f (decode-uri-component quadratic DoS): add a
  pnpm override to >=0.5.1; its API and types are unchanged.

vue-i18n 11 requires Node >= 22, so CI and release workflows move from
Node 20 to Node 24, matching the Docker build image.

JIT message compilation is always on since v10, so the obsolete
__INTLIFY_JIT_COMPILATION__ define is removed; the build still has no
new Function. SubscriptionPlanCard spec asserted raw keys that v9's
runtime build returned; it now asserts the rendered test messages.
2026-10-30 10:44:47 +08:00
Wesley Liddick 7386bc6ae0 Merge pull request #8389 from StarryKira/codex/management-mcp
feat: add OAuth-authenticated management MCP
2026-10-30 09:49:16 +08:00
shaw fb22c92126 fix(backend): bump MCP go-sdk to v1.4.1 for GO-2026-4770/4773
go-sdk v1.4.1 fixes GO-2026-4773 (cross-site tool execution) and
GO-2026-4770 (null Unicode JSON parsing), which fail govulncheck.

v1.4.1 also adds transport-level cross-origin and Content-Type checks
that would reject requests Authenticate already accepts:
- trust the same allowed origins in the SDK's CrossOriginProtection so
  CORS-allowlisted browser clients are not refused with 403;
- accept application/json with parameters (e.g. charset) by normalizing
  the header, while still refusing non-JSON bodies with 415.
2026-10-30 09:36:53 +08:00
shaw f532737de2 Merge branch 'main' into codex/management-mcp
# Conflicts:
#	backend/go.mod
#	backend/go.sum
2026-10-30 09:21:24 +08:00
harukaandClaude Opus 5.5 b3eb7194c2 fix(frontend): truncate long MCP client IDs
Signed client IDs are now about 200 characters. Show them on one line on
the consent page and in the connection list, with the full value in the
title. The random part leads, so truncated IDs still differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 14:46:08 -04:00
harukaandClaude Opus 5.5 575dd9bc2b fix(backend): make MCP client registration stateless
Registration was capped at 1000 pending clients site-wide while the limit
per IP was 10 per minute, so one address could exhaust the cap and block
every new MCP client.

- Issue client IDs as HMAC-signed tokens carrying the client name,
  redirect URI digests and grant types. Registration writes nothing;
  rows are created only when a user approves a client, so there is no
  shared capacity to exhaust.
- Persist the signing key in security_secrets via the existing
  get-or-create helper, cached lock-free, so instances share it.
- Drop mcp_oauth_clients from migration 249 and keep the client name on
  each grant. Prune expired grants on authorization, before the owner
  row is locked.
- Fix an unchecked type assertion in managementmcp tests flagged by
  golangci-lint v2.14.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 14:46:08 -04:00