Repository navigation
Description
来源: #5807 分析「上游首字节空闲沿用 12 分钟默认值 → 卡死白等」时发现
查重: 无(open+closed 全文检索 TTFB / idle budget / header timeout / "not retried";无同机制条目。相关历史: #1706/#1714 退役 BILI_STREAM_STALL_MS、#551 undici 上限、#1688 主路径 transport 重试、#3148 熔断器)
要拍板什么
fetchWithTimeout 用同一个空闲预算(network.upstreamTimeoutMs,默认 12 分钟)管两个阶段——首字节(TTFB)与收流中途静默——且两个阶段超时都归为同一个失败类 upstream-timeout(刻意不可重试)。网关「保持连接但一直静默」时,整个请求被挂住最多 12 分钟,失败后宿主还要重传完整 prompt(报告者实测 51.3 MiB)。修复方向全部触及重试语义和/或配置面,按 Configuration Surface Discipline 与 §7.4(默认值变更属产品决策)需要 owner 签字。
已核实事实(master @ daa082e,bili 0.1.212,与 #5807 描述逐条对照成立)
src/fetch-util.ts:24UPSTREAM_TIMEOUT_MS = 12*60*1000;fetchWithTimeout(L169-271)初始 arm 覆盖 TTFB、每个 body chunk rearm,两阶段共用同一个effective(L180-202)。src/upstream-fail.ts:236-238isFailFastUpstreamKind不含upstream-timeout→ 无内部重放;hint 写明 "not retried by design"。fetchWithRetry文档注释(fetch-util.ts L396-401):不重试是刻意的——"to avoid stacking the 12-min idle budget across attempts"。- 代码注释(fetch-util.ts L60-70):长预算存在的原因 = 本地模型会合法地静默数分钟(thinking、长 prefill),并明确写 "Do not re-add a shorter timer here"——该指令针对 body 阶段,但单计时器结构使任何全局缩短都会连带打到 TTFB/prefill。
- 分类层无法区分 header 阶段与 body 阶段的超时(都表现为 AbortError →
upstream-timeout);知道是哪个计时器触发的是fetchWithTimeout自己,但它没有把阶段信息记到 error 上(方案 A 需要补这条接线)。 upstream-timeout不在ALERT_KINDS(upstream-alerts.ts L46-54,注释:连接已建立,说 "cannot reach" 是谎话)→ 永久卡死的上游不会触发 [bug] 上游在会话中途不可用时,bili 把一次故障放大成四重代价:固定节奏 20 连击全部冷发、输出预算被静默钳制 83 次(最狠 65536→1360)、紧急收缩与 nudge 停摆均不可见 #3148 熔断器快速失败。
选项
A — 只拆失败类型(零配置面)
header 阶段超时 → 新类 upstream-headers-timeout 加入 isFailFastUpstreamKind(代理内部重放,1.5s/3s 退避,≤3 次);body 阶段维持截断不重放。
- 收益:零配置变更;已把
upstreamTimeoutMs调小的人立刻从「宿主重传」变成「代理内重放」。 - 代价:默认 12 分钟预算下,彻底死掉的端点最终失败时间从 12 分钟变 3×12≈36 分钟(且该类不进 ALERT_KINDS,熔断器救不了);默认场景(卡住但连接活着)仍要先白等 12 分钟才进入第一次重放。
- 结论:单独不够,与 C 组合后才成立。
B — 硬编码 120 s TTFB 上限(零配置面)
headerBudget = Math.min(effective, 120_000),body 不变。
- 回归风险:直接打断文档化的部署形态——prefill 超过 120 s 才出首 token 的本地模型(这正是 12 分钟默认值存在的理由,fetch-util.ts L62-63);且属 §7.4「默认值变更=产品决策」、无逃生阀的硬编码常量。另注意:按 [bug][fetch] Upstream TTFB idle inherits the 12-min default → hangs with a pointless 35 s wait; suggest splitting header | [bug][fetch] 上游首字节空闲沿用 12 分钟默认值 → 卡死白等 35 s;建议拆分 headers/body 预算并让 header 超时可重放 #5807 给出的映射,prefill 窗口(收到 headers → 首个 chunk)也会落在这个 120 s 帽下。
- 结论:不建议。
C — 新增 network.headerIdleTimeoutMs + A(推荐)
unset = 沿用现有 upstreamTimeoutMs 预算 ⇒ 所有存量部署逐字节零行为变化;显式设置(如 30–60 s)⇒ TTFB 有独立短预算,且(配合 A)以可重放的 pre-response 失败收尾。
- 四层映射按 [bug][fetch] Upstream TTFB idle inherits the 12-min default → hangs with a pointless 35 s wait; suggest splitting header | [bug][fetch] 上游首字节空闲沿用 12 分钟默认值 → 卡死白等 35 s;建议拆分 headers/body 预算并让 header 超时可重放 #5807 所给(knobs.ts
headerIdleTimeoutMs():envBILI_UPSTREAM_HEADERS_TIMEOUT_MS> 文件 > undefined;config.tsnetwork.headerIdleTimeoutMs?;fetch-util.tsarmTimer(ms)显式预算;upstream-fail.ts 新 kind + hint 行 + 分类覆盖门测试行),另加两处精修:- prefill 交接点:在
fetch()resolve(headers 到达)时即切到 body 预算重新计时,而不是等首个 chunk——否则用户设了 30 s header 预算会把 >30 s 的正常长 prefill 杀掉。这样 header 预算只真正约束 connect+headers。 - undici 对齐:
directDispatcher目前 headersTimeout=bodyTimeout=同一值(上游长时间 prefill(首 token 前无输出)被 undici 默认 bodyTimeout=300s 掐断,UPSTREAM_TIMEOUT_MS=10min 配置形同虚设,大上下文请求必超时 #551);拆分后映射为 headersTimeout=headerBudget、bodyTimeout=bodyBudget,传输层与看门狗一致。
- prefill 交接点:在
- 代价:一个新配置字段(需 owner 签字、CONFIGURATION.md 中英同步);默认路径不动。
- 诚实边界:默认部署遇到卡死网关仍会等到 12 分钟(直到有人显式 opt-in)——改默认值是另一个独立产品决策(见 D)。
- 实现细节留白(不影响拍板方向):新 kind 是否计入 ALERT_KINDS 让熔断器兜底,建议先不计入、保留最小语义,有数据再议。
D(本轮不做,后续单议)— 移动默认值
例如不设字段时 TTFB 默认 60–120 s。本轮否决:会改变长 prefill 本地模型用户的默认行为;若要做,应在 C 落地、字段成为逃生阀之后。
推荐
C + A 一个 PR 闭环:拆 kind + 新字段,字段 unset = 现状逐字节一致。机制先落地,默认值留给后续单独决策。B 有回归否决;A 单独有 3× 最坏代价否决;D 顺延。
请拍板
A) 批准 C+A(新字段在此记录签字)· B) 只批 A · C) 其他(请说明)。决定前不动手实现(配置面 + 重试语义均属 owner 领域)。
Activity
ranxianglei commentedon Nov 6, 2026
(ai: vllm-qwen/qwen3.8-27b)
🔶 需要决策
背景一句话:上游网关「保持连接但一直静默」时,一个请求被同一个 12 分钟空闲预算挂到死,失败后归为不可重试的
upstream-timeout,宿主被迫重传完整 prompt(#5807 实测 51.3 MiB)。根因是「首字节 TTFB」和「收流中途静默」两个阶段共用一个预算、一个失败类。查重:issue 已声明无同机制条目(open+closed 全文检索 TTFB/idle budget/header timeout);我复核当前 master(c3dfbe6b2)确认无在途 [PR]/issue 触及 TTFB/header-idle——不重复。
我已把 issue 里每条代码事实对当前 master 逐条独立复核,全部成立:
src/fetch-util.ts:24UPSTREAM_TIMEOUT_MS = 12*60*1000;:180单一effective管两阶段、:191初始 arm 覆盖 TTFB、:192-202每个 chunk rearm(rearm 只在 chunk 上触发,不在 fetch() resolve)。src/upstream-fail.ts:236-238isFailFastUpstreamKind不含upstream-timeout→ 无内部重放;:244hint 写明 "not retried by design"。src/fetch-util.ts:393-401fetchWithRetry 注释:不重试是刻意的,避免「12 分钟预算叠乘」。src/upstream-alerts.ts:46-54ALERT_KINDS不含upstream-timeout(注释:连接已建立,说 cannot reach 是谎话)→ 卡死端点不会触发 [bug] 上游在会话中途不可用时,bili 把一次故障放大成四重代价:固定节奏 20 连击全部冷发、输出预算被静默钳制 83 次(最狠 65536→1360)、紧急收缩与 nudge 停摆均不可见 #3148 熔断快速失败。src/upstream-fail.ts:82AbortError、:86UND_ERR_*_TIMEOUT → upstream-timeout),只有 fetchWithTimeout 知道是哪个阶段 → 方案 A 需补这条「阶段」接线。src/knobs.ts:80-84/src/config.ts:2220的 network 块支持按既有约定加headerIdleTimeoutMs()(envBILI_UPSTREAM_HEADERS_TIMEOUT_MS> 文件 > undefined)。待决问题:拆成「header 短预算 + body 维持 12 分钟 + 新可重放失败类」,字段 unset = 现状逐字节一致——是否批准?这同时动配置面和重试语义,属你签字范围,决定前我不动手。
选项各带代价:
我的三处独立判断(不只是复述 issue):
另两处与 issue 一致:新 kind 先不进 ALERT_KINDS(最小语义,避免卡死端点误触 #3148 熔断,有数据再议);undici directDispatcher 现 headersTimeout=bodyTimeout=同值(fetch-util.ts:89),拆分后须映射 headersTimeout=headerBudget / bodyTimeout=bodyBudget,否则传输层先于看门狗触发(#551 老坑)。
八问:
upstream-headers-timeout(pre-response,不双送);新字段 unset=沿用现状。network.headerIdleTimeoutMs(envBILI_UPSTREAM_HEADERS_TIMEOUT_MS),默认 unset=沿用upstreamTimeoutMs;需 CONFIGURATION.md 中英同步 + web 配置页。这是本次要签字的配置面新增。不决定的默认行为:我不碰任何代码(配置面+重试语义是你的领域);线程保持打开等你在 A/B/C 里拍板。拍板后我再按「一个线程一个修复 PR」规则核对在途 PR 并落地实现。
标签(本镜像 shim 未实现 label 接口,POST /labels 返回 404 'endpoint not implemented in ework shim',无法程序化打标,故在此文字声明):
bug·scope/wiring·p2(核心传输层缺陷,非会话丢失/缓存泄露类,且有绕行)。ranxianglei commentedon Nov 8, 2026
决策记录(2026-11-08):owner 拍板按"两阶段拆分"推进。分两半落地:
BILI_UPSTREAM_FIRST_BYTE_MS,unset=逐字节零变化,跟随解析后的 upstreamTimeoutMs)。upstream-headers-timeout进 fail-fast 可重放)+ 选项 C 的旋钮,已实现于 PR [PR] Fix #5807: Classify TTFB timeout separately on gateway hang and replay within the proxy | 修 #5807:网关装死时,首字节超时单独分类并在代理内重放 #5947(修 [bug][fetch] Upstream TTFB idle inherits the 12-min default → hangs with a pointless 35 s wait; suggest splitting header | [bug][fetch] 上游首字节空闲沿用 12 分钟默认值 → 卡死白等 35 s;建议拆分 headers/body 预算并让 header 超时可重放 #5807)。采纳的关键取舍:首字节超时仅在运维显式把首字节预算收紧到低于空闲预算时才变为可重放新类——这样默认部署(12 分钟)行为逐字节不变,也避开了选项 A 单独使用时"死端点 12 分钟 ×3 ≈ 36 分钟"的代价(只有显式收紧后才存在重放,且此时预算小)。流中途(body)超时维持
upstream-timeout不重试,#1706/#1714 长静默保证不动。#5807 已链接 #5947 为 Closes;本决策 issue 留待 owner 关闭。
ranxianglei commentedon Nov 8, 2026
(ai: vllm-qwen/qwen3.8-27b)
收到,决策与推荐方向一致(C+A);而且「条件化重放」这个取舍比我在 issue 里给的原始 C+A 更干净——采纳它是对的:
BILI_UPSTREAM_FIRST_BYTE_MSunset 时跟随解析后的 upstreamTimeoutMs(12 分钟),首字节超时仍归upstream-timeout不可重放 → 逐字节不变。upstream-timeout不重试,Opencode failed to send message with error: upstream stream ended before a completion event; this turn may be incomplete #1706/配置面收敛:移除全部 BILI_*/ACP_* 行为类环境变量,统一迁入 config.json #1714「不重新加更短计时器」的语义完整保留(与 KDD feat: release CI (npm auto-publish on release branch) #8 一致)。分工清楚:预算拆分半已由 #5917 合并;分类 + 代理内重放半在 #5947(挂 #5807)。这两半的实现正确性由各自线程的 review/CI 把关,我不在本决策线程重复审。本 issue 为纯决策记录,按你的说明留待你关闭——我这边不再动代码。
ranxianglei commentedon Nov 8, 2026
(ai: vllm-qwen/qwen3.8-27b)
收口确认:本决策线程到此结束。owner 已拍板「两阶段拆分」——预算拆分半由 #5917 交付并合并(新增
BILI_UPSTREAM_FIRST_BYTE_MS,unset = 逐字节零变化),分类 + 代理内重放半在 #5947(Closes #5807)。两半的实现正确性由各自线程的 review/CI 把关。默认部署行为不变,body 中途超时长静默保证(#1706/#1714)保持不动。本 issue 为纯决策记录,按你的说明留待你关闭;我这边不再动代码,也不在本线程重复 review。
ranxianglei commentedon Nov 8, 2026
(ai: vllm-qwen/qwen3.8-27b)
Superseded — the owner decided in the #5807 thread (2026-11-08) and shipped the implementation directly:
network.upstreamFirstByteMs/BILI_UPSTREAM_FIRST_BYTE_MS; unset = the RESOLVEDupstreamTimeoutMs, so the default stays byte-identical (including deployments that raise the idle budget above 12 min).upstream-headers-timeout(fail-fast, replayed in-proxy withinBILI_REPLAY_RETRY_MAX) — only when the first-byte budget is tightened below the idle budget; body-phase timeouts stayupstream-timeoutand non-retried (Opencode failed to send message with error: upstream stream ended before a completion event; this turn may be incomplete #1706/配置面收敛:移除全部 BILI_*/ACP_* 行为类环境变量,统一迁入 config.json #1714 guarantee intact).That is the recommended C+A shape plus a refinement that removes the residual risk flagged for A-alone: with the default (unsplit) budgets no marker is ever stamped, so the 3×12-min stacking case cannot occur unless an operator explicitly tightens the knob — and then each attempt is bounded by the tightened budget.
Nothing left to decide here. Labels updated (p1 removed, superseded added); closing is yours.
ranxianglei commentedon Nov 8, 2026
(ai: vllm-qwen/qwen3.8-27b)
收到,确认本决策线程已收口:决策在 #5807 线程拍板,实现由 #5917(已合并)与 #5947(开放、CI 绿、已独立 review)承接;标签 p1→superseded 合理——问题已解决并落地,不再占用高优先级。我这边无任何后续动作:不关闭(留给你)、不动代码、不重复 review。
fix: give a tightened first-byte timeout its own replayable kind (ran…
Merge upstream/master (f1a4af4): adopt first-byte replay, log-mask sc…
ranxianglei commentedon Nov 12, 2026
(已收)本单已归入根因聚合 issue(token 见聚合单 body),机器人已停止在本单上的工作,修复走聚合 issue 统一出 PR;本单保留不关,修复验证后统一关闭。(聚合单:[Root Cause] config-knobs (3 items),GitHub #6443)
ranxianglei commentedon Nov 21, 2026
(ai: vllm-qwen/qwen3.8-27b)
Merge conflict resolved and force-pushed. PR #5833 is now
mergeable: true(the conflict is gone); CI is re-running on the new head.What I did this run
2026-11-01_offloop-owner-reap, headffbcf96e846) was 94 commits behindmaster(98fa9575f10). Agit merge-treedry-run showed exactly one real conflict:scripts/live-files.mjs— both sides added a differentLIVE_FILESentry at the same spot (master addedtests/storage-backup-repair.test.tsfor [Bug][storage] Takeover spawns before reclaim: old and new sidecars simultaneously hold index.db, causing corruption; em | [Bug][storage] 接管时先 spawn 后回收:新旧侧车同时持有 index.db 引发损坏;空 payload_json 又让历史会话静默变 0 #7156; this PR addedtests/issue5449-offloop-owner-reap.test.tsfor [Bug] 0.1.209 dsh/Windows: an orphaned proxy outlives its dead owner (33 min, ~51% CPU, write lock held) and is never reaped → the replacement drifts 18789→18790 while the caller stalls 826 s with 0 bytes #5449).reference/architecture.mdauto-merged cleanly; the other 5 files had no overlap.origin/masteris now an ancestor of the new head; diff vs master is exactly the PR's original 7 files (no accidental changes); no conflict markers remain anywhere in the tree;node --check scripts/live-files.mjspasses andLIVE_FILESloads with both entries present (73 total). (TS tests can't run locally —node_modulesisn't installed in this environment — so the full-suite verdict is the CI re-run.)ffbcf96e846→ef645463596with--force-with-lease, after re-fetching and confirming the remote head was unchanged (no concurrent push to fight).Live state (verified this run, not from memory)
ef645463596, base98fa9575f10(master).mergeable: true— conflict resolved.mergeable_state: blockednow only because the fresh CI run on the new head is still in progress (41 check-runs: 31 completed/skipped, 8 queued, 2 in-progress; combined statuspending) — not because of a conflict.八问(中文,供人工审阅)
scripts/live-files.mjs的LIVE_FILES数组同一位置(storage-integrity-cache.test.ts之后)各自新增了一个不同条目——master 加 [Bug][storage] Takeover spawns before reclaim: old and new sidecars simultaneously hold index.db, causing corruption; em | [Bug][storage] 接管时先 spawn 后回收:新旧侧车同时持有 index.db 引发损坏;空 payload_json 又让历史会话静默变 0 #7156 的storage-backup-repair.test.ts,本 PR 加 [Bug] 0.1.209 dsh/Windows: an orphaned proxy outlives its dead owner (33 min, ~51% CPU, write lock held) and is never reaped → the replacement drifts 18789→18790 while the caller stalls 826 s with 0 bytes #5449 的issue5449-offloop-owner-reap.test.ts,git 无法自动合并同位置的两段新增。reference/architecture.md自动合并无需干预。LIVE_FILES两个条目都在。本次只动了冲突解决,未改任何 PR 原有逻辑。LIVE_FILES条目是 PR 自带的,非本次新增配置面)。收工判定:冲突已消解并 force-push(新 head
ef645463596),PR 现为 mergeable,CI 正在新 head 上重跑(本次唯一一次完整 CI pass)。无需决策、无需后续动作——等 CI 绿即可由 owner 合并。