Skip to content

perf: harden gateway, billing, and ops paths under high concurrency - #4337

Open
DR-lin-eng wants to merge 280 commits into
Wei-Shaw:mainfrom
DR-lin-eng:main
Open

perf: harden gateway, billing, and ops paths under high concurrency#4337
DR-lin-eng wants to merge 280 commits into
Wei-Shaw:mainfrom
DR-lin-eng:main

Conversation

@DR-lin-eng

Copy link
Copy Markdown

Summary

  • bound OpenAI request and response buffering while improving channel-aware failover behavior
  • make usage billing durable under load with queued persistence, bounded fallback, and mutation-version cache guards
  • consolidate dashboard reads and add Redis-backed operational and runtime controls

Key changes

  • add durable usage billing queueing with synchronous fallback when critical work cannot be enqueued
  • prevent stale cache repopulation after billing and balance mutations
  • bound request bodies, SSE scanning, session state, OAuth refresh locks, and account runtime state
  • improve channel-aware scheduling, retry handling, and temporary account exclusion
  • add shared dashboard snapshots and merged usage aggregations
  • add Redis-only system logs, runtime retention overrides, user usage statistics, and explicit clear-all operations
  • add a global temporary-unschedulable switch with cross-layer cleanup
  • expose the new scheduling, logging, retention, and usage controls in the admin UI

Testing

  • go test ./...
  • golangci-lint v2.9.0 run --timeout=30m ./...
  • make test-frontend
  • pnpm --dir frontend run build

I have read the CLA Document and I hereby sign the CLA

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, we need you all to sign our Contributor License Agreement (CLA).

To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.


I have read the CLA Document and I hereby sign the CLA


14 out of 15 committers have signed the CLA.
✅ (DR-lin-eng)[https://github.com/DR-lin-eng]
✅ (BenjaminAaron196)[https://github.com/BenjaminAaron196]
✅ (yardbirds0)[https://github.com/yardbirds0]
✅ (Eyre921)[https://github.com/Eyre921]
✅ (dftian478)[https://github.com/dftian478]
✅ (SatellaPoi)[https://github.com/SatellaPoi]
✅ (wucm667)[https://github.com/wucm667]
✅ (aomsir)[https://github.com/aomsir]
✅ (adamglin0)[https://github.com/adamglin0]
✅ (feitianbubu)[https://github.com/feitianbubu]
✅ (DylanChiang-Dev)[https://github.com/DylanChiang-Dev]
✅ (AixLau)[https://github.com/AixLau]
✅ (heathermhuang)[https://github.com/heathermhuang]
✅ (mark-ly-wang)[https://github.com/mark-ly-wang]
@CRAZYShimakaze
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@DR-lin-eng

Copy link
Copy Markdown
Author

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.

I have read the CLA Document and I hereby sign the CLA

You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

I have read the CLA Document and I hereby sign the CLA

@DR-lin-eng

Copy link
Copy Markdown
Author

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).
To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.
I have read the CLA Document and I hereby sign the CLA
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

I have read the CLA Document and I hereby sign the CLA

recheck

@DR-lin-eng

Copy link
Copy Markdown
Author

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.

I have read the CLA Document and I hereby sign the CLA

You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

recheck

@DR-lin-eng

Copy link
Copy Markdown
Author

recheck

@DR-lin-eng

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@DR-lin-eng

Copy link
Copy Markdown
Author

recheck

DR-lin-eng and others added 15 commits July 18, 2026 11:39
…index drift

Close open text parts before late reasoning/tool items, and only stop matching Anthropic content-block types so finalize cannot close tool_use with a spurious output_text.done.

Co-authored-by: Cursor <cursoragent@cursor.com>
Opus 4.8/4.7、Sonnet 5、Fable 5 上 thinking.display 默认为 "omitted":
模型照常思考、照常计费,但返回的 thinking block 文本为空,客户端无从
展示,终端用户会误以为上游不支持思考。

新增系统级三态开关 RectifierSettings.ThinkingDisplayMode:

- display_only(默认):只为已带 thinking.type=adaptive 的请求补
  display=summarized。思考本来就在发生并计费,补齐不增加任何 token,
  也不影响 messages 层 prompt 缓存。
- force:额外为完全未携带 thinking 的请求注入思考。这会真正开启思考,
  故同时抬高 max_tokens——max_tokens 是思考+正文的总上限,在低预算请求
  上强开思考会让正文被截断且上游不报错。
- off:完全不干预。

顺带修复:客户端发 thinking.type="enabled" / budget_tokens 给这些模型
必定 400,而既有的 RectifyThinkingBudget 400 重试救不了它——它只调整
budget_tokens 的取值,而这些模型是整个拒绝该字段,重试照样 400。现归一
化为 adaptive。

注入点有两处:主转发链路与 Anthropic API-key 直通链路(后者在
gateway_forward.go 提前 return,不经过整流链)。只做一处会让同一用户因
调度到的账号不同而时有时无,比一直没有更像故障。

GetThinkingDisplayMode 带 nil 接收者守卫:GetRectifierSettings 直接
解引用 settingRepo,而本方法在网关热路径上调用。
DR-lin-eng and others added 30 commits August 1, 2026 22:21
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.