Repository navigation
release v0.9.6 #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
release v0.9.6 #1489
Changes from 16 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0baad07
fix(proxy): prioritize TTFB when stream gate is not enforced
ding113 705742b
fix(proxy): record routing trace events during legacy hedge racing (#…
ding113 2b9a20f
fix(proxy): strip stale content encoding after reserialization (#1464)
ROOOO 13649bb
fix(providers): auto-attach x-opencode-session and support regex capt…
ding113 01b3625
fix(proxy): use undici fetch with ProxyAgent on Node 24 (#1476)
kexichan 8c2507c
fix(logs): prevent session ID suggestion query timeouts (#1479)
sususu98 9af35d1
feat(langfuse): reconstruct streamed outputs and enrich traces (#1478)
kexichan f08bd66
fix(proxy): 修复首内容串行排队并按可用内存分配预算 (#1474)
tesgth032 2d9ae9a
fix(logs): preserve UUID case and validate PostgreSQL indexes (#1479)
ding113 7e5124f
fix(langfuse): preserve streamed output and redact original headers (…
ding113 e83df23
fix(proxy): coordinate memory growth and pause local admission deadli…
ding113 20265ad
feat(providers): header templates and OpenCode Go adapter (#1480)
kexichan b40c7a2
fix(custom-headers): return null for unrecognized template expressions
99b87a4
fix(memory): stop MemoryGovernor 429 lockups from leaked leases and a…
kexichan 87e0761
chore(deps): bump next in the npm_and_yarn group across 1 directory (…
dependabot[bot] 01ba8af
fix(responses-ws): fall back to HTTP for oversized upstream requests …
ROOOO 7fa4ff4
fix(migrations): create session prefix indexes outside runMigrations
dd35081
fix(providers): stop sending the raw session ID to OpenCode
d9b6fa6
fix(proxy): bound pre-auth capacity rejection attribution
8429453
fix(proxy): write redirected Gemini model names into the path literally
2a685e9
fix(langfuse): do not flag reconstructed streams as missing a response
ce01266
fix(langfuse): finalize parameterless tools and data-only Anthropic s…
e234254
fix(langfuse): send Responses usage as exclusive Langfuse buckets
a81bc76
fix(multicore): keep four database connections per auto-mode worker
256ecfe
test: cover the IPC callback retry path and assert the held gate lease
f5300b2
fix(migrations): refuse blocking prefix index builds on large tables
c6bc798
fix(migrations): scope the 0122 guard per table and list concurrent s…
a906155
fix(logs): preserve upstream errors in routing decision chains (#1490)
ding113 71278c9
fix(logs): match decision-chain entries to routing attempts exactly
17215e1
feat(providers): 供应商管理页展示上游余额 (#1492)
ding113 47a915f
fix(proxy): treat Anthropic refusal as a deliverable result, not an e…
Lynricsy 926db2b
fix(providers): 正确识别 Sub2API 余额,支持用 New API 系统访问令牌查询账户余额 (#1496)
ding113 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # 首内容排队与内存感知准入 | ||
|
|
||
| 关联 #1473,部分涉及 #1466。v0.9.5 的门控按每请求 40 MiB 预留,默认四个 worker 各分到 64 MiB,因此每个 worker 同时只有一个请求能等待首内容。慢上游占住这个位置,其他请求即使上游很快也会被本地队列阻塞。 | ||
|
|
||
| ## 请求与门控 | ||
|
|
||
| - 门控从 128 KiB 工作集开始,随自有字节块和解析堆栈实际增长。扩容不持有部分正文排队,不能立即取得容量就把前缀逐块暂存到磁盘。首内容之后按原顺序回放。 | ||
| - 增量 JSON/SSE 分类只保存协议路径事实和有界错误预览,不为大工具参数、图片或回显帧创建完整对象。重复 JSON 键、错误优先级、compaction、终止帧和合法深层 JSON 保持既有语义。 | ||
| - 入站正文只有一个流消费者;压缩输入和解压输出逐块检查大小、必要时暂存。JSON 物化前按字节和对象结构估算容量,密集小对象的预算高于同样长度的长文本。 | ||
| - 过滤、重试和 multipart 仍保留完整语义。日志视图改为按需生成;未启用调试正文或 Langfuse 时不长期保存出站序列化副本。 | ||
| - 首次向上游发请求前取得门控基础容量。本地准入最多等待 20 秒,容量不足返回本地 `429`、`local_capacity_exceeded`、`Retry-After: 1`;不触发供应商 failover、健康扣分或熔断。 | ||
|
|
||
| 当前 dev 已在高并发模式跳过提交前门控,本变更保留这一行为。评估本变更时应分别测试高并发开关;从 v0.9.5 升级后的延迟下降不能全部归因于本变更。 | ||
|
|
||
| 配置了门控子限额时,先等待该子限额,再申请全局额度,两个阶段共用 20 秒期限。排队中的门控请求不预占其他正文处理所需的全局容量。 | ||
|
|
||
| Discovery 保留原有 1 MiB 前缀边界及完整帧解析语义,解析前按正文结构估算 JSON 工作集,并计入自有前缀块容量。增长失败立即返回本地 429;候选就绪后丢弃解析器,只保留实际前缀额度,直到赢家回放或输家计费消费者完成才归还。其完整帧解析工作集仍需要物理内存。 | ||
|
|
||
| ## 自动预算 | ||
|
|
||
| 令 R 为当前可用 RAM,S 为可用 swap: | ||
|
|
||
| ```text | ||
| H = R + 0.5 * S | ||
| reserve = max(256 MiB, 0.1 * R) | ||
| autoBudget = floor(0.6 * max(0, H - reserve)) | ||
| headroom = floor(max(0, R - reserve)) | ||
| hotBudget = min(autoBudget, headroom) | ||
| ``` | ||
|
|
||
| hotBudget 只在启动(多进程为全部 worker 就绪)时计算一次,作为固定上限。运行期每秒的收紧条件是 `limit = min(启动上限, 在用量 + headroom)`:0.6 折扣已体现在启动上限里,不再对剩余内存重复折扣。否则进程自身常驻内存(Next.js 基础堆等非受管分配)增长会在零租约时持续压低正文额度;只有真实物理余量低于启动上限或出现内存压力时才收紧。 | ||
|
|
||
| Linux 使用 MemAvailable、SwapFree,同时检查可见 cgroup v2/v1 的成员和祖先限制,遵守 memory.high、swap 禁用及 v1 memory+swap 联合限额。无法确认容器 swap 额度时不增加 swap 容量;非 Linux 以可用物理内存保守估计。 | ||
|
|
||
| `CCH_MEMORY_BUDGET_BYTES` 可明确指定受管分配预算,替代自动比例;显式模式保留 10% 当前 RAM 余量并遵守热点物理容量。该值约束正文物化与门控工作集,并非进程 RSS 硬上限;需要硬上限时应使用容器/cgroup 内存限制。DB、Replay、detached drain 和异步写队列继续使用原有独立限额,尚未全部迁入同一个分配器。 | ||
|
|
||
| cluster primary 只协调字节授权,worker 按 MiB 小批量借用,无正文 IPC。worker 退出后才回收其授权;IPC 断开停止新授权。每秒检查实际内存和压力,恢复有滞回且不超过固定启动基线,已在使用的租约不会被强行撤销。有 cgroup 内存控制器时只读取当前成员的 memory.pressure,不使用宿主机全局 PSI/swap I/O 作为本地压力,避免其他服务换页持续压缩本服务额度;无控制器时才回退到宿主机压力。可用容量始终考虑宿主机及可见 cgroup 祖先限制。 | ||
|
|
||
| 授权回复丢失时每秒重发同一申请 ID,primary 幂等返回原结果;归还采用累计值心跳,丢包与重复消息不会重复发放或永久占用额度。剩余容量不足一个 MiB 时仍可部分授权。 | ||
|
|
||
| 多进程冷启动期间 targetBytes 保持为零,周期采样不会提前恢复准入。全部计划 worker 就绪后,才按基础堆加载后的剩余容量建立唯一基线并发放额度;启动时等待的请求仍受 20 秒上限约束。admissionReady 标识基线是否已建立,启动前的历史换页计数不作为新压力事件。 | ||
|
|
||
| cgroup v1 缺少可直接轮询的组内 PSI,不启用宿主机压力回退;仍根据组内 limit/usage、memsw 联合余量及 MemAvailable 动态收缩容量。本地 pressure_level 事件订阅不在当前实现范围。 | ||
|
|
||
| 入站暂存租约在文件操作结束时显式归还;已解析请求通过 AsyncLocalStorage 绑定请求生命周期,在响应 EOF、读错、取消或无正文返回后显式释放。AsyncTaskManager、竞速候选、输家计费与快照等后台消费者分别持有带标签的引用,直到实际完成才归还;发出 abort 不等于任务已经退出。后台持有有上限:响应结束后若后台所有者在 `REQUEST_MEMORY_BACKGROUND_GRACE_MS`(默认 150 秒,且不短于输家引流超时 + 30 秒)内既未结束也无进展(流式任务每个 chunk 都会刷新),请求作用域被强制结束——归还全部租约、丢弃会话上的正文引用,并以 warn 日志记录卡住的所有者标签。永不 settle 的 Redis/DB Promise 因此不能永久占用额度。响应仍在传输时不计时。FinalizationRegistry 仅兜底被遗弃的响应流和独立调用,不再承担正常请求回收。连续大正文请求即使未触发 GC,也不会积累已完成请求的额度。 | ||
|
|
||
| 门控租约同时挂到请求作用域作为兜底:显式 release 仍是主路径,但已提交前缀流若被丢弃(既未读完也未取消),作用域结束时仍会归还额度并清理落盘前缀。 | ||
|
|
||
| 诊断:`worker_memory_stats` 的 `leases` 按标签(body_read/body_decode/body_materialize/gate/langfuse_spool)给出在账租约数、字节和最长持有时间;`requestMemory` 给出响应已结束但仍被后台占用的请求数、最长时间、所有者标签分布和累计强制结束次数。 | ||
|
|
||
| 门控额度在最终请求过滤与序列化后、上游计时与发送前申请,仅适用于实际请求流式响应且需要内容门控的端点。非流式与原始透传路径不因识别到供应商协议而占用门控额度;收到无需门控的响应时立即归还。 | ||
|
|
||
| worker 自动上限为 32,仍按 floor(vCPU/2)、实际可用物理内存、数据库连接和既有共享预算取更小值。提高上限不代表低内存或默认连接预算环境一定会启动 32 个 worker。 | ||
|
|
||
| ## 磁盘暂存与故障 | ||
|
|
||
| `CCH_MEMORY_SPILL_DIR` 默认是系统临时目录下的 cch-spool,必须位于真实磁盘,拒绝 tmpfs/ramfs。每个部署使用独立目录。文件权限为 0600;目录包含 PID 与 Linux 进程启动标识,启动及定期扫描只删除已确认退出或 PID 被复用的自有目录。 | ||
|
|
||
| `CCH_MEMORY_SPILL_MAX_BYTES` 默认 8 GiB;配置上限和可用磁盘的 10% 均按 worker 分摊,每 worker 最多 256 个文件。写入逐块等待完成,不积累后台写队列。单次暂存操作最长等待 20 秒,取消立即结束请求等待;内核 I/O 不能强行取消时保留租约和文件所有权,直到操作结束后清理。删除失败保留磁盘额度并每秒重试,确认删除后才归还。配额、文件系统或磁盘操作失败均按本地容量不足处理;tmpfs/ramfs 配置错误每目录警告一次并提示设置真实磁盘路径。 | ||
|
|
||
| ## 观测与验证 | ||
|
|
||
| `memory_plan_resolved`、`worker_memory_ready`、每 30 秒的 `worker_memory_stats` 提供预算来源、在用/峰值额度、等待者、拒绝数、进程 RSS/heap/external/ArrayBuffer,以及 admission、正文读取/解压/物化、gate 阶段的次数、累计/最大耗时和字节数。指标不记录请求内容。 | ||
|
|
||
| 专项验证: | ||
|
|
||
| ```sh | ||
| bunx vitest run --config tests/configs/memory-aware.config.mts --coverage | ||
| ``` | ||
|
|
||
| 包含 cgroup/资源公式、IPC 与退出回收、20 秒本地 429、SSE 差分、大正文六种解码路径、磁盘配额/取消/超时/遗留文件回收,以及一个上游延迟 60 秒时另 100 个小流仍能通过的回归。#1466 中其他响应体、缓存、独立队列或运行时内存增长仍需要独立诊断,本变更不宣称完全解决该 issue。 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- Session identity prefix indexes are installed by the concurrent index preflight. | ||
| -- This migration records the schema revision without running a blocking CREATE INDEX. | ||
| SELECT 1; | ||
|
ding113 marked this conversation as resolved.
Resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.