Skip to content

fix(#1706): retire the BILI_STREAM_STALL_MS stall guard - #1715

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-30_issue1714-stall-config-file
Sep 30, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-30_issue1714-stall-config-file

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

#1706: a stale export BILI_STREAM_STALL_MS=400 on the reporter's machine turned every thinking-phase wire silence into a false truncation (upstream stream ended before a completion event). The #1452 opt-in stall guard measured silence after the first byte with any positive integer as a valid threshold — and local-model deployments legitimately go silent for minutes mid-stream (thinking phases, long prefills; the reporter's local model prefill runs ~500s). No finite sub-budget is safe for everyone, so per owner direction in #1706 the detector is retired entirely rather than relocated.

First step of #1714 (env-var surface convergence).

Changes

  • src/fetch-util.ts: removed streamStallMs() and its arm/re-arm/abort block from fetchWithTimeout; body chunks now re-arm only the idle watchdog. Doc note pins the design decision: the idle budget is the SOLE silence bound, do not re-add a shorter timer.
  • src/server.ts: at startup, if BILI_STREAM_STALL_MS is set (any value) bili logs one warn naming it — stale shell exports announce themselves instead of silently dying ([config] BILI_STREAM_STALL_MS=400 is no longer read (#1714) …).
  • tests/issue1452-socket-hardening.test.ts: parse test and per-byte re-arm test deleted (feature gone); the fire test becomes the retirement regression — stale 400 export + 3s idle budget: asserts the startup notice, that the cut happens at the idle budget (~3s, proving 400ms never fired), and the unchanged Plugin mode: upstream stream truncated before terminal event → client gets bare cut-off SSE (no completion/error event) #721 wire shape; the default-off test now sets the stale export and proves a 2s mid-stream silence survives it untouched.
  • CONFIGURATION.md / CONFIGURATION.zh-CN.md: row converted to the stricken Removed format (precedent: BILI_HOST_USAGE_CREDIT).

Behavior changes (old → new)

old new
Mid-stream silence bound opt-in BILI_STREAM_STALL_MS could cut at ANY positive integer ms (e.g. stale 400 broke every thinking turn — #1706); default off → 12 min knob gone; all upstream silence (prefill + mid-stream) bounded solely by BILI_UPSTREAM_TIMEOUT_MS idle budget (default 720s, tunable up/down)
Dead-stream detection worst case N seconds when guard enabled up to the full idle budget (12 min default) — the price of "indefinite"
Stale env exports silently effective (the incident) ignored + named once at startup
Wire shape on truncation unchanged (#721 in-band frame + terminal event) unchanged

No config-file field is added (nothing replaces the knob). No other behavior touched.

Gate

typecheck clean · npm test 3279 pass / 0 fail / 17 skip · build OK (dist-import-annotations OK). Based on current master 75c1e75c.

Review note

Capability-surface removal → human-merge territory (§7.4). References #1706 (incident) and #1714 (convergence plan, step P1 pivoted from "migrate to file" to "retire").

A stale BILI_STREAM_STALL_MS=400 export turned every thinking-phase silence into a false truncation (#1706). Local-model deployments legitimately go silent for minutes mid-stream, so no finite sub-budget is safe for everyone. Retire the guard entirely: upstream silence (prefill and mid-stream) is bounded solely by the always-on BILI_UPSTREAM_TIMEOUT_MS idle budget. Stale exports are ignored and named once at startup.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-30_issue1714-stall-config-file (7c53696)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1669-pr.1715.b8a61f3

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1715.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,正在按 PR Review 规范审查本 PR(方向 / 回归 / 代码 / 测试有效性 / diff 整洁度)。先核对分支与 master 的关系,再逐项过。稍后给出完整结论 + 中文摘要。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — mergeable. Full walkthrough below.

① Direction (original issues). Verified against #1706's thread: incident root cause was the stale BILI_STREAM_STALL_MS=400 export tripping the #1452 guard on thinking-phase silence (log line upstream stalled: no bytes for 400ms after first byte). Owner direction landed in two steps — floor 17 "移除环境变量 用配置文件", then floor 25 "设置为无限期吧 本地小模型 prefill 干 500s 很正常" — and floor 27 records the executed decision: retire entirely, no replacement config field, all silence bounded by BILI_UPSTREAM_TIMEOUT_MS, cost disclosed (worst-case dead-stream detection degrades from N s to up to 12 min). The PR implements exactly that decision, and #1714 P1's pivot ("migrate to file" → "retire") is noted. Root cause handled at the source (capability removed + doc pin), not masked.

② Regression audit — existing behaviors on touched paths, each checked:

  1. Idle watchdog semantics (TTFB + inter-chunk, BILI_UPSTREAM_TIMEOUT_MS, default 720s) — preserved: armIdleBody(raw.body, rearm) keeps identical re-arm wiring; pinned green by tests/fix-551-upstream-timeout.test.ts and tests/fix-806-request-watchdog.test.ts:138.
  2. Default (env unset) behavior — zero change: old code with stallBudget=0 made the stall timer a structural no-op, so removing it changes nothing for the default case.
  3. Env-set behavior (deliberate opt-in users) — intentional change, disclosed: value ignored + named once at startup. This is the retirement itself; old→new table in the PR body is accurate (I re-derived it from the code).
  4. Wire shape on truncation (Plugin mode: upstream stream truncated before terminal event → client gets bare cut-off SSE (no completion/error event) #721 upstream_stream_truncated frame + terminal event) — unchanged: src/stream-error.ts untouched; the rewritten fire test still pins frame + [DONE].
  5. Timer-leak ledger (liveUpstreamTimers) — consistent: stall-timer bookkeeping removed with its timer; cleanup() updated; fire test asserts 0 leaks post-abort.
  6. undici transport alignment (directDispatcher(upstreamTimeoutMs())) — untouched.
  7. Startup log surface — additive only: one new warn, gated on non-empty value, no existing lines altered.
  8. Docs — en/zh rows converted to the stricken format matching the BILI_HOST_USAGE_CREDIT precedent (CONFIGURATION.md:696); full-repo grep confirms no other doc/code references survive (only the intentional ones: doc pin in src/fetch-util.ts:33, the warn in src/server.ts:488-490, the tests).

③ Code. Clean removal at the decision point; the doc pin on upstreamTimeoutMs() ("SOLE silence bound … Do not re-add a shorter timer here") codifies the decision where a future edit would live — correct layer, not a transit filter. server.ts warn: upstreamTimeoutMs import already present (line 17), placement beside the other startup [config]/[conn] lines, empty/whitespace values correctly not warned. Nit (non-blocking, cosmetic): with a small custom budget (the test's 3000ms) the message renders "0-minute idle budget" — harmless log wording.

④ Test validity — real teeth, verified:

  • Fire test: stale 400 + 3s idle budget. elapsed > 2000 fails under the OLD code (~400ms cut) — this is a genuine Opencode failed to send message with error: upstream stream ended before a completion event; this turn may be incomplete #1706-shape regression pin, not a tautology. < 10s + 15s hard-abort guard keep it deterministic and hang-free.
  • Survival test: stale 400 + 60s budget, 2s mid-stream silence must survive. I checked the assertion strings against the actual wire text: the truncation frame's message carries upstream stream error: <err> (src/loop/core.ts:896-899), so !includes("stream error") matches real output — and [DONE] independently pins it. Old code fails both assertions within ~400ms.
  • Deleted tests: parse test (function gone — correct to delete); per-byte re-arm tested the stall timer only (idle budget was 60s in that test, far beyond its duration), so deleting it loses no idle-watchdog coverage — that property stays pinned in fix-806.

⑤ Diff & process. 5 files, every line on-purpose, no whitespace/lockfile churn, single linear commit on current master 75c1e75c (verified base == master tip; mergeable: true). Hot-file check across the 27 open PRs: none rewrite src/fetch-util.ts or the server startup-config region; sibling #1706-PR #1709 touches src/plugin.ts + a new test file — complementary, no overlap. No version bump, no config-file field added (config-surface discipline holds; removal was owner-signed off before implementation).

Gates (re-run locally on head 7c536961, not taken on faith): typecheck clean · npm test 3279 pass / 0 fail / 17 skip · build OK (dist-import-annotations OK) — matches the PR claim exactly. CI on the same commit: 13/13 green, including the real-client e2e job, hermetic registry e2e, and all four OS/node test matrices.

One observation, not a blocker: the body says "References #1706 / #1714" rather than Fixes. That's defensible as-is — #1706 is intentionally held open until you confirm your box runs stable on the new build, and #1714 is a multi-step plan this PR only completes P1 of. If you want auto-close, flip it to Fixes #1706 before merging and close #1714's P1 tracking manually.

Per §7.4 this is human-merge territory (capability removal + fallback-semantics change) — ready when you are. Suggested order: merge #1715, then #1709 (independent), then confirm stability on your machine and close #1706.


中文摘要:审查了退役 BILI_STREAM_STALL_MS 停滞守卫的 PR——方向与 #1706 里你的「无限期」决定一致,既有行为逐项清点(空闲看门狗、默认路径、截断线上形状、定时器台账、文档)均无回归,两个新测试对旧代码确实会挂(真回归测试非恒真),diff 干净、基于最新 master,本地门禁复跑与 CI 13/13 全绿一致,可以合并。

@ranxianglei
ranxianglei merged commit 9cd4273 into master Sep 30, 2026
13 checks passed
ranxianglei pushed a commit that referenced this pull request Sep 30, 2026
Every behavior-class BILI_*/ACP_* env var (~70 names) is removed from bili's
read surface and now lives only in config.json (canonical mapping + one-time
boot warning in src/retired-env.ts). Transport/identity overrides, launcher IPC
channels, secret material, and default-invariant test seams stay env-based by
design.

Also fixed on the way (disclosed per #1714 rule 4):
- 24+ config.json fields were dead code in production (configure* setters never
  called): startServer + both live-reload paths now forward every knob from
  ProxyOptions, so file values actually take effect.
- sessionsDir config field wired at startup + reloads (was env-only before).
- -F flag: overrides.cliUpstreamProxy applied post-loadOptions instead of the
  retired BILI_UPSTREAM_PROXY env name (old path silently no-op'd).
- attach evidence-grace / health-deadline and chain skew/recent-window knobs:
  env fallbacks replaced by programmatic opts/configure* setters (no new
  config fields — code knobs, not user surface).
- BILI_STREAM_STALL_MS left out of RETIRED_ENV: master's #1715 dedicated boot
  warning already names it (avoid double warn).
ranxianglei pushed a commit that referenced this pull request Sep 30, 2026
Every behavior-class BILI_*/ACP_* env var (~70 names) is removed from bili's
read surface and now lives only in config.json (canonical mapping + one-time
boot warning in src/retired-env.ts). Transport/identity overrides, launcher IPC
channels, secret material, and default-invariant test seams stay env-based by
design.

Also fixed on the way (disclosed per #1714 rule 4):
- 24+ config.json fields were dead code in production (configure* setters never
  called): startServer + both live-reload paths now forward every knob from
  ProxyOptions, so file values actually take effect.
- sessionsDir config field wired at startup + reloads (was env-only before).
- -F flag: overrides.cliUpstreamProxy applied post-loadOptions instead of the
  retired BILI_UPSTREAM_PROXY env name (old path silently no-op'd).
- attach evidence-grace / health-deadline and chain skew/recent-window knobs:
  env fallbacks replaced by programmatic opts/configure* setters (no new
  config fields — code knobs, not user surface).
- BILI_STREAM_STALL_MS left out of RETIRED_ENV: master's #1715 dedicated boot
  warning already names it (avoid double warn).
ranxianglei pushed a commit that referenced this pull request Sep 30, 2026
Every behavior-class BILI_*/ACP_* env var (~70 names) is removed from bili's
read surface and now lives only in config.json (canonical mapping + one-time
boot warning in src/retired-env.ts). Transport/identity overrides, launcher IPC
channels, secret material, and default-invariant test seams stay env-based by
design.

Also fixed on the way (disclosed per #1714 rule 4):
- 24+ config.json fields were dead code in production (configure* setters never
  called): startServer + both live-reload paths now forward every knob from
  ProxyOptions, so file values actually take effect.
- sessionsDir config field wired at startup + reloads (was env-only before).
- -F flag: overrides.cliUpstreamProxy applied post-loadOptions instead of the
  retired BILI_UPSTREAM_PROXY env name (old path silently no-op'd).
- attach evidence-grace / health-deadline and chain skew/recent-window knobs:
  env fallbacks replaced by programmatic opts/configure* setters (no new
  config fields — code knobs, not user surface).
- BILI_STREAM_STALL_MS left out of RETIRED_ENV: master's #1715 dedicated boot
  warning already names it (avoid double warn).
@ranxianglei
ranxianglei deleted the 2026-09-30_issue1714-stall-config-file branch October 15, 2026 05:32
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.

1 participant