Repository navigation
[PR] fix(#5666): unref cache-keepalive timer so short-lived processes exit - #5672
ranxianglei wants to merge 6 commits into
Conversation
…can exit The armed cadence timer was a plain setTimeout without unref(), holding the Node event loop open. In an inline-lane short-lived process (pi -p, sub-agents) that timer is the only live handle left once the turn finishes, so the process lingered until maxDurationMs (default 24h) instead of exiting. Route both the default scheduler and its test-reset through a single realSchedule() helper that unrefs every handle. Interactive hosts stay alive for their own reasons and the pings still fire on schedule; print-mode hosts now exit cleanly when their work is done. Regression: tests/cache-keepalive.test.ts spawns a child that arms a keepalive through the real scheduler and asserts the process exits on its own (hangs / times out without the fix).
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.9008-pr.5672.0553403This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5672.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复 —— 检索了 open+closed 的 issue 与 PR(关键词 cache-keepalive / unref / timer / process exit / short-lived),无同机制条目;本 PR 的来源 issue 是 #5666,未见过其他针对 keepalive 定时器持有事件循环的修复。 标签: 开始审核:已取 PR head( |
|
(ai: vllm-qwen/qwen3.8-27b) APPROVE (self-review — GitHub blocks formal self-approval) Clean root-cause fix. The recurring cadence timer was the only live handle left after a short-lived inline-lane turn completed; unref-ing it via a single
|
tests/cache-keepalive.test.ts now spawns a child (node --import tsx) for the #5666 process-liveness regression, which trips the SPAWN_RE guard in scripts/run-ci-tests.mjs: every process-spawning suite must be listed in LIVE_FILES or the runner bails with exit 1 before any test runs (all 11 CI shards failed on this pre-flight tripwire). Append it at the end of the table (slot = index drives each file's zone port band, so mid-list inserts are forbidden); the child runs under a per-run mkdtemp XDG sandbox with no ports bound, so no zone band is needed — the entry is for the tripwire alone, like #3890/#5114.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) PR #5672 review complete: APPROVE.
Ready for merge. |
(ai: vllm-qwen/qwen3.8-27b) CI 红了不是测试挂了,是 CI 的前置守卫把整个 job 拦下来了。已定位并按最小机械修法修好、additive push 到 PR 分支。 根因:PR 新增的 修复:在 结构化八问
收工判定:无需决策、无需立项(明确的机械缺陷,非设计取舍)。已 additive fast-forward push 到 PR 分支 |
(ai: vllm-qwen/qwen3.8-27b) 审核结论(结构化八问)1. 是什么问题:inline 车道(proxy 嵌在宿主进程内)下,显式开启 cacheKeepalive 的短命宿主( 2. 什么原因导致的: 3. 影响范围与严重程度:仅「显式开启 cacheKeepalive(默认关闭)+ 短命 inline-lane 进程」两类条件同时满足的用户;交互会话与独立 proxy daemon 不受影响(各有自己的存活 handle)。对命中者:单次调用挂死最长 24h(CI/自动化场景会被卡住),面窄但命中即严重。 4. 怎么修复的:把默认调度器与测试重置路径收敛到单一 5. 是否有回归问题:逐项审过既有行为——ping 时机与内容不变(delay/callback 完全相同);交互/长命宿主不变(进程寿命由自身 handle 决定,ping 照常按点发);disarm/并发上限/fail-streak/session-gone 判定零改动;测试重置路径同步改为恢复 realSchedule,与生产默认严格一致(比原来更一致);无 fail-fast→吞错、阈值/时序/输出格式漂移。未发现回归。 6. 是否破坏缓存:不涉及。keepalive 功能本身就是为了维持上游 prompt-cache 热度;unref 只改进程寿命,不改进程存活期内的 ping 行为;缓存/重试/增量游标/去重键策略均不受影响。 7. 是否改了设计方向:不涉及。 8. 是否引入新配置:不涉及(无新 env/config/CLI)。 验证证据(本地定向,非全量)
diff 与质量2 个文件、每行都与本 PR 目的相关;无空行重排、无 lockfile/version 变动;命名达意( 判定:可合(建议先补一次 ci:full 全套绿信号,或接受 guard+本地定向证据直接合)。 |
(ai: vllm-qwen/qwen3.8-27b) 本轮没有改任何代码——剩下的唯一红检查不是这个 PR 的测试挂掉,而是一个早已存在、代码里就标注过的 flaky 测试在负载高的 Windows runner 上偶发超时。我做了根因定位 + 只重跑失败的那个 job。 结构化结论(八问)
诚实边界:诊断依据是抓下来的 job 日志 + 读该测试源码(确认了 3000ms 预算和那条 flake 注释),我没有在本地复现 windows-latest 的高负载(不可确定性复现),所以「flake」是强证据推断而非本地实测。若这次重跑仍红,证据就变弱,我会深挖并按规则升级(要么 🔶 需要决策,要么把「持久 flake 加固」作为独立事项归到 CI 总控 #4599,而不是塞进本 PR)。 判定:重跑已在途(HTTP 201),head 不变,无需合并动作。 |
…' into 2026-11-04_keepalive-timer-unref
(ai: vllm-qwen/qwen3.8-27b) Resolved the base-conflict on this PR and pushed it back to What happened this run
Verified before pushing
Structured 八问
Note / next step: the full-suite verdict comes from remote CI on the pushed head (per §7.2 my local runs were targeted — guard + syntax only). One file beyond #5666 rides along transiently — 判定:冲突已解、分支已更新到包含最新 master 的状态、熔断守卫本地通过——等 CI 在推送后的 head 上重跑即可,无需再人工干预。 |
…e-lane hosts can exit (#5672) The recurring keepalive setTimeout had no .unref(), so on an inline lane (proxy inside host process) a short-lived host (pi -p / sub-agent print-json run) kept living until maxDurationMs (default 24h), pinging upstream the whole time — the armed timer was typically the only live handle left after the turn ended. Default scheduler and test-reset now route through one realSchedule() helper calling t.unref?.() at every arm/reschedule site (initial arm, busy-reschedule, post-ping reschedule), matching the existing repo idiom (~49 other unref call sites). Picked up from PR #5672.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Resolved the base-conflict on this PR and pushed the sync to What I did this run
Verified in this run
Honest boundary (status freshness): the local check-state cache still reflects the pre-push head ( Structured 八问
Note for owner: because the net diff vs master is 0, this PR is effectively superseded — the keepalive-unref behavior change (#5666/#5672) is already live on master. I've left the PR open (closing is owner-only); once CI on the synced head confirms green you may close it as superseded. 判定:基线冲突已解、分支已同步到包含最新 master 的状态、熔断守卫本地通过——等远端 CI 在推送后的 head 上出结果即可,无需再人工干预。 |
|
(ai: vllm-qwen/qwen3.8-27b) APPROVE (self-review — GitHub blocks formal self-approval) Re-review at new head 2336764 (was 3333582): the only new change is commit 2e99a66 which registers tests/cache-keepalive.test.ts in scripts/live-files.mjs — a mechanical CI requirement (the SPAWN_RE guard in run-ci-tests.mjs bails all shards if a process-spawning suite is unlisted). Correctly appended at end of table with a comment explaining no zone band is needed. No semantic changes. Note: the PR tree now matches master exactly (diff is empty) — all three files (realSchedule in src/cache-keepalive.ts, the regression test, and the LIVE_FILES entry) are already present on master. This PR can be merged as a no-op or closed directly; either way the fix is live. CI at 2336764: 30 checks, 0 failed, 1 still running. |
Summary
The idle prompt-cache keepalive (
src/cache-keepalive.ts) arms one recurring cadencesetTimeoutper active session. That timer was created without.unref(), so it keeps the Node event loop alive.In an inline lane the proxy runs inside the host process. For a short-lived host (
pi -p, or any sub-agent run in print/json mode), once the turn finishes the armed keepalive timer is typically the only live handle left — so the process never exits by itself; it keeps pinging upstream every few minutes untilmaxDurationMs(default 24 h). Interactive sessions were unaffected because the host stays alive for its own reasons.Fix
Both the default scheduler and its test-reset now go through a single
realSchedule()helper that calls.unref?.()on every timer it creates. That covers all three arm/reschedule sites (initial arm, busy-reschedule, post-ping reschedule) in one place, and matches the existing repo idiom (t.unref?.()already appears ~49× elsewhere, e.g.src/web/blog-refresh.ts:119).The only other timer in the module is the transient 60 s ping
AbortSignal.timeout, which is bounded, non-recurring, and cannot be unref'd — not the cause of this bug.Behavior change (old → new)
pi -p, sub-agent)maxDurationMs(default 24 h), pinging upstream the whole timeScope of impact: only users who explicitly enabled
cacheKeepalive(disabled by default). No config-surface, wire-shape, persistence-format, or kernel changes.Verification
tests/cache-keepalive.test.ts→ "arm: the real scheduler unrefs its timer, so short-lived processes exit ([Bug] cache keepalive timer keeps short lived processes (pi -p, sub-agents) alive until maxDurationMs #5666)" spawns a child that arms a keepalive through the real (non-injected) scheduler and asserts the process exits on its own. Confirmed locally: passes with the fix (~0.5 s); hangs/times out without it (10 s window).tests/cache-keepalive.test.ts: 35/35 pass.tsc --noEmitclean. Full-suite verdict deferred to CI.Fixes #5666