Repository navigation
[PR] fix(keepalive): arm cache keepalive when cache_control has no ttl (#5667) - #5669
ranxianglei wants to merge 0 commit into
Conversation
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.8128-pr.5669.95dc39bThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5669.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 查重:不重复 —— 本 PR 正是对原始 bug 报告(#5665,marcantoinepelletier 报的「cache keepalive never arms when cache_control has no ttl」,镜像 #5667)的修复。相关但不重复的条目:镜像 #5668(keepalive timer 让 pi -p/sub-agent 短命进程活到 maxDurationMs)——同功能域但症状与机制都不同(事件循环被 timer 拖住 vs 层级检测漏判),属独立问题;#4233 是全局 cacheKeepalive 块的配置校验,无关。 标签: bug / scope/wiring / p2 —— opt-in 功能在默认断点形态下静默完全失效、有绕行(显式 ttl / assumeTtl / intervalMs),定 p2;缺陷在宿主侧请求管道(src/cache-keepalive.ts),非 kernel。 状态: 识别为 agent 提交的 PR(ework-agent-pr 标记)→ 不重做,进入核验流程:
正在本地对 PR head 跑定向测试 |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) 核验完成(识别为 agent 提交的 PR,未重做)。结构化八问:
核验证据:
判定:可合 —— 满足 §7.4 自动合入门槛(单模块纯 fix、红/绿回归钉、rebased head 上 CI 全绿、无配置/持久化/wire/kernel 变更、干净 diff、引用 issue)。合并留给 owner:#5669 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
判定:APPROVE —— 单点修复,把代码对齐到既有文档行为;回归测试有牙(本地 red 验证过);既有行为无回归。无需要顺手修的小问题。
结构化八问
- 是什么问题:
cacheKeepalive.enabled: true时,Anthropic 线上断点用默认形态cache_control: {"type":"ephemeral"}(不带显式ttl)的会话,保活永远不武装——静默 no-op,连[keepalive] armed日志都没有。而 no-ttl 恰是最常见的断点形态,所以大多数开了保活的用户这个功能实际不生效。 - 什么原因导致的:
detectKeepaliveTier只认显式ttl:"5m"/"1h";不带 ttl 的断点返回undefined,armInternal落到末尾 return。而 Anthropic API 默认 ephemeral TTL 就是 5 分钟——这些本来就是 5 分钟档断点,被检测漏掉。代码与文档声明的节奏规则矛盾(CONFIGURATION.md:705:“tier is1hwhen any breakpoint declaresttl: \"1h\", else5m”)。 - 影响范围与严重程度:opt-in 功能(默认关),无数据丢失、无安全面。受影响面 = 开了保活且宿主发 no-ttl 断点的用户——对他们功能完全失效(静默);有绕行(
assumeTtl/intervalMs/显式 ttl)。p2 级。 - 怎么修复的:
detectKeepaliveTier中,任何不带显式 ttl 的断点按 5m 档处理;保留显式"1h"的提前返回,1h 优先语义不变。一行逻辑改动 + 引 #5667 的解释注释(src/cache-keepalive.tsdetectKeepaliveTier,:119-144)。 - 是否有回归问题:逐项审过既有行为——显式 5m→5m 不变;显式 1h→1h 且优先级保持(新增子断言
oneHourAmongNoTtl钉住,tests/cache-keepalive.test.ts:232-236);零断点 body 仍返回 undefined、仍需assumeTtl/armWithoutBreakpoints(既有负门 :346-349 不变);intervalMs > assumeTtl > breakpointTier阶梯未动(:365-371);武装门(non-anthropic/GET/passthrough/resign/buffer,:332-344)与 ping 生命周期代码全部未动。一处小的可观测漂移(披露):带 no-ttl 断点且armWithoutBreakpoints:true的 body,tierLabel 从5m(no-breakpoints)变为5m(节奏同为 270s)——语义上更准确,仅外观。Red 验证:换回修复前源码恰好两条新断言失败(33/35),修复后 35/35。 - 是否破坏缓存:否。ping 重放逐字一致的前缀(只改缓存区之外的 max_tokens=1/stream=false);新武装的会话多出的周期性 TTL 刷新 ping 正是该功能的目的;解除规则(cache_read=0 / 429 / 连续 3 错 / 时长上限)未变。
- 是否改了设计方向:否。代码向既有文档契约对齐;CONFIGURATION.md en+zh 已在 head 核对一致,无需文档改动(文档一直是对的,坏的是代码)。
- 是否引入新配置:无(无新 env/config/默认值)。
验证记录
- 本地定向跑(head e661032):
tests/cache-keepalive.test.ts35/35 通过。 - Red check:换入 master(23a826d) 版 src/cache-keepalive.ts → 恰好两条新断言失败(
detectKeepaliveTier: 5m / 1h / mixed / nested / none:216、arm: no-ttl breakpoints arm at the default 5m tier:323),跑完还原——回归测试抓得住原 bug。 - CI(镜像缓存):failed 0 / pending 0;guards 全绿(kernel-guard/docs-sync/docs-coverage/config-surface-guard 等);base = master head,无需 rebase。
- 调用面:
detectKeepaliveTier唯一调用点在 armInternal(src/cache-keepalive.ts:282);仓内其他 “breakpoint” 提及属 bili 自己的 cache_control stamping 机制,与本改动无关。
非阻塞观察(无需动作)
- 递归 walk 会把 body 任意位置名为
cache_control的对象键(包括用户内容里嵌入的同名 JSON)计为断点——这是修复前就有的 naive-walk 固有属性;修复后误报面略宽(任何 cache_control 对象 vs 之前需精确 ttl 匹配),但后果更轻(误武装 5m 档 vs 之前可能误武装 1h 档),且 ping 有上游验证、miss 即解除,成本有界。
结论:可合。
…tier so keepalive actually arms (#5665) detectKeepaliveTier only armed when a breakpoint carried an explicit ttl of 1h/5m; the default form cache_control:{type:ephemeral} (no ttl) returned undefined and armInternal exited silently — contradicting CONFIGURATION.md (which said: 1h when any breakpoint declares ttl:1h, else 5m). Now any breakpoint without explicit ttl is 5m-tier; explicit ttl:1h still lifts to 1h; intervalMs still wins. Picked up from PR #5669 (issue #5665).
e661032 to
58a8796
Compare
Problem
With
cacheKeepalive.enabled: true, keepalive never armed for sessions whose Anthropic-wire breakpoints use the default formcache_control: { type: "ephemeral" }(no explicitttl). No[keepalive] armedline appeared at all.Root cause
detectKeepaliveTier(src/cache-keepalive.ts) only set a tier when acache_controlbreakpoint carried an explicitttlof"1h"or"5m". A breakpoint withoutttlreturnedundefined, soarmInternalreached its finalreturnand exited silently. On the Anthropic API an ephemeralcache_controldefaults to a 5-minute TTL, so such breakpoints are 5m-tier breakpoints — the detection was simply missing them. This contradicts the documented cadence (CONFIGURATION.md: "tier is1hwhen any breakpoint declaresttl: \"1h\", else5m").Fix
Treat any
cache_controlbreakpoint without an explicitttlas the 5m tier; only an explicitttl: "1h"lifts the tier. One-line logic change indetectKeepaliveTier.Behavior change (old -> new)
ttlNEVER armed the keepalive (silent no-op), even withcacheKeepalive.enabled: true.ttlFactor0.9 ~= 270s).cache_controlbreakpoints still requireassumeTtl/armWithoutBreakpointsto arm; an explicitttl: "1h"still yields the 1h tier;intervalMsstill wins over everything.This aligns the code with the already-documented behavior; no CONFIGURATION.md edit is required (the docs were correct, the code was the defect).
Tests
Added regression coverage in
tests/cache-keepalive.test.ts:detectKeepaliveTier: no-ttl ->"5m"; no-ttl mixed with an explicit 5m ->"5m"; no-ttl alongside an explicit 1h ->"1h"; a zero-breakpoint body is stillundefined.cadenceMs=270000,tierLabel="5m".Verified red against the pre-fix source (both new assertions fail) and green after the fix (35/35 pass in the file).
npm run typecheckandnpm run buildare clean on this head. Full-suite verdict comes from remote CI.Closes #5665