Skip to content

[PR] fix(backend): Backend stability minor fixes bundle, Part 1 — Four reviewed minor fixes merged for review | fix(backend): 后端稳定小修合集第一辑 —— 四件已评审小修合并送审 - #5847

Merged
ranxianglei merged 6 commits into
masterfrom
2026-11-07_backend-stability-small-fixes-batch
Nov 7, 2026
Merged

ranxianglei merged 6 commits into
masterfrom
2026-11-07_backend-stability-small-fixes-batch

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

这个 PR 干什么

把四个此前各自挂审未合的后端小修收进一个分支,一次 CI、一次送审。每件原本都是状态板(#3916)上 ✅可合 的独立 PR,各自分支 CI 红绿参差,合一后以本 PR 的新 CI 为准。

清单(一件一个独立提交,+283/−9,8 文件)

提交 修什么(人话) 原 PR 原 issue 原作者
fix(retry): transient-4xx classifier honors upstream machine retry declaration 上游 4xx 错误体里的机器重试声明(actions:["RETRY"]、retryable:true,含 JSON-in-string 信封;新增 please retry/「请重试」措辞,裸词 retry 不加以免 "do not retry" 误伤——有负例钉住)现在被侧车道(acp-loop 重放、compress-loop-responses、preflight 摘要)识别为瞬态并重放,不再一次就死。主转发路径按设计不动 #3610 部分 #3606(见下) ranxianglei
fix(served-markers): ignore prior container generations with same PID on restart 容器里进程几乎总是 PID 1:重启后旧写者标记(pid:1)对新进程 kill(1,0) 恒活,每次开机误报 [split-brain]。现在标记带 startedAt,同-PID 但早于本进程开机的判为上一代直接跳过;旧版标记无 startedAt 时用文件 mtime 兜底 #5028 #3923(已关,机制互补见下) Aldo Adirajasa Fathoni(@fathonix,外部贡献者)
fix(cache-keepalive): treat ttl-less cache_control breakpoints as 5m tier Anthropic 默认写法 cache_control:{type:"ephemeral"}(不写 ttl)以前永远臂不上保活(静默 no-op),与 CONFIGURATION.md 文档行为矛盾。现在无 ttl 断点按 5m 档臂活,显式 ttl:1h 仍升 1h 档 #5669 #5665 ranxianglei
fix(cache-keepalive): unref the keepalive timers so short-lived inline-lane hosts can exit 保活定时器没 .unref():内联车道的短命宿主(pi -p、子代理 print/json 跑完)唯一的活句柄就是它,进程要空转到 maxDurationMs(默认 24h)才退,期间一直 ping 上游。三个臂活/重排点统一走 realSchedule() 加 unref #5672 —(孤儿 PR) ranxianglei

贡献身份保留

#5028 是外部贡献:@fathonix 的原提交(c115e35)+其后续评审修订收进单个提交,git 作者字段保留为 Aldo Adirajasa Fathoni aldo.alfathoni@gmail.com,squash-merge 后署名仍留在合并历史里。

冲突消解说明(#5028 两处)

⚠️ #3606 不能关(重要)

第一件只交付了 #3606 的侧车道子缺陷;主转发链路的 HTTP 级重试(子缺陷 A)仍在 issue 线程里等 owner 在三案之间拍板。所以本 PR 不含 Closes #3606,请在合并时留意不要手滑勾掉它。
另:#3923 已于 10-20 被 #3952(split-brain 可见性方向)关闭,本件是其未覆盖的假阳性修复方向,不重复关单。

Pre-flight 结果

本 PR 合并后处理的 issue

Closes #5665

CI 修正补记(2026-11-07,首次送审后新增一个提交)

首版在三个 shard 上红于同两个测试(#5719 T1/T8),与本 PR 改动无关:上游 30a8bc2d(经 #5734 于 11-06 合入)改了 src/session-resolve.ts 的 re-anchor 档序却漏同步了旧套件里两根钉子,导致所有基于 11-06 前 master 的 PR(包括主干自身)同时在这两点变红——纯 master worktree 本地复现同样两失败、无关分支的 CI 亦同红,均核实。本分支已 rebase 到新 master c45ac219,并按 #5734 自己 commit message 文档化的行为变更重对齐这两根钉子(T1 改钉新档 reason 串,key/action 断言不变;T8 由期望 derived-persona 改为 reanchor)。对本 PR 原有各件零影响。

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-07_backend-stability-small-fixes-batch (e5c1dcd)

Latest build — install this exact version

npm install -g billion-context@0.0.8448-pr.5847.5fcef82

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

Recent builds (commit → version)

commit version build
e5c1dcd billion-context@0.0.8448-pr.5847.5fcef82 build
151efca billion-context@0.0.8444-pr.5847.26f97d3 build
f0ed83f billion-context@0.0.8437-pr.5847.4de8e01 build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(backend): 后端稳定小修合集第一辑 —— 四件已评审小修合并送审 [PR] fix(backend): Backend stability minor fixes bundle, Part 1 — Four reviewed minor fixes merged for review | fix(backend): 后端稳定小修合集第一辑 —— 四件已评审小修合并送审 Nov 7, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复——开放 [PR] 行中无其他指向同一后端合集主题的 PR(镜像号 5847 是另一个「Web 面板小修合集」PR,仅编号巧合,主题不同)。

已拉取分支核对:4 个提交与清单一一对应,7c70593fa 的 git 作者字段确认为 Aldo Adirajasa Fathoni aldo.alfathoni@gmail.com,贡献身份保留 ✅。CI 缓存暂无本 PR 记录,首跑完成后我会读镜像缓存确认。

开始按 PR Review 规范审(方向→回归→代码→测试有效性→diff 整洁),结论按八问体例回复。

ranxianglei and others added 5 commits November 7, 2026 13:26
…claration (#3606 side-lane part)

isTransientUpstreamError (src/fetch-util.ts) gains two OR'd true-paths for 4xx bodies: canonical wording markers (please retry / 请重试; bare 'retry' deliberately NOT added — 'do not retry' false-positive pinned by negative test) and bodyDeclaresRetryable(): bounded JSON scan (64 KiB cap, 4096-node budget) for actions:[...RETRY] or retryable:true, unwrapping string fields that parse as JSON (the code-11101 envelope behind #3606).

Behavior change: side lanes (acp-loop replay, compress-loop-responses, preflight summarization) now retry ≤ network.replayRetryMax on such bodies instead of fail-fast. Main forwarding path untouched by design (#1688); sub-defect A of #3606 (main-path HTTP-level retry) still awaits owner decision — this PR must NOT close #3606.

Picked up from PR #3610. Lock-file version drift from its base no longer present against current master.
… on restart

In containers processes virtually always run as PID 1; after a restart the old writer marker (pid: 1) still passes isPidAlive() against the new process, so findContestedWriters false-positives [split-brain] on every boot.

Fix: record startedAt (epoch ms) on WriterIdentity/WriterMarkerFile; a marker sharing our PID whose startedAt (or mtime for older builds without startedAt) predates this process boot by more than SAME_PID_GENERATION_MARGIN_MS is skipped as a prior generation. Integrated onto master's contestedServedAt helper (#4626); both mechanisms keep working.

Original commit c115e35 of PR #5028 (external contribution by @fathonix; later review-fix commits of the same PR condensed into this one — full credit retained via git author).
…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).
…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.
… rung order (30a8bc2)

Upstream 30a8bc2 (merged via #5734 on Nov 6) made an authored-checkpoint conv declaration re-anchor on the raw lane BEFORE the store-overlap rung, and even when the store view is null — its own commit message documents 'this shape went from forks to re-anchors'. It added tests/issue5719-self-checkpoint-reanchor.test.ts but did not realign T1/T8 of this older suite, leaving every old-base PR (and the main branch itself) red on exactly those two pins.

T1 now pins the self-declaration reason string (same outcome asserts kept: key raw + action reanchor); T8 now expects reanchor on the raw key where it previously expected the byte-evidence degrade to derived-persona/sub-fork. Marker-less shapes untouched (their pins still pass unmodified).
@ranxianglei
ranxianglei force-pushed the 2026-11-07_backend-stability-small-fixes-batch branch from f0ed83f to 151efca Compare November 7, 2026 05:27
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

PR #5847 独立审核完成:可合(待 CI 绿)。 四件小修逐件过代码、本地定向测试全绿、交叉引用全部对过号。审核中发现两处问题:一处已直接修掉(错引 issue 号,已推提交),一处需要你留意(分支中途 rebase 带进来一个 master 存量红修复)。详见下文发现清单。

结构化八问

  1. 是什么问题:四个此前各自挂审未合的后端小修收进一个分支,一次 CI、一次送审——本 PR 本身不是新缺陷,是四件已评审修复的合并载体(各自病因见第 2 问)。
  2. 什么原因导致的:① 瞬态 4xx 分类器只认关键词表,不认上游错误体里的机器重试声明(actions:["RETRY"]、retryable:true);② 容器内进程几乎总是 PID 1,重启后旧写者标记对新进程 kill(1,0) 恒活,每次开机误报 [split-brain];③ detectKeepaliveTier 只认显式 ttl:"5m",Anthropic 默认写法(不写 ttl)永远臂不上保活,与 CONFIGURATION.md 文档行为矛盾;④ 保活定时器没 .unref(),pi -p/子代理这类短命宿主唯一的活句柄就是它,进程空转到 maxDurationMs(默认 24h)才退,期间一直 ping 上游。
  3. 影响范围与严重程度:① 侧车道(acp-loop 重放、compress-loop-responses、preflight 摘要)遇到上游自声明可重试的 4xx 一次就死——特定条件下的功能损失(p2);② 容器每次开机一条假 split-brain 报警——日志噪音/误导排查(p3);③ 用 Anthropic 默认无 ttl 写法的用户保活静默失效——与文档承诺不符(p2);④ 短命宿主进程空转最长 24h 持续 ping 上游——资源浪费(p2)。主转发链路不受任何一件影响(见第 5 问核查)。
  4. 怎么修复的:① 给分类器加有界 JSON 结构扫描(64 KiB 字节上限 + 4096 节点预算,兼容 JSON-in-string 信封),识别 actions 含 RETRY(大小写不敏感)或任意嵌套 retryable===true;新增 please retry/「请重试」措辞,裸词 retry 刻意不加("do not retry" 负例钉住);主转发路径按设计不动。② 标记带 startedAt,同 PID 但早于本进程开机(留 1s 余量)判为上一代直接跳过;旧版标记无该字段时用文件 mtime 兜底。③ 无 ttl 断点按 5m 档处理,显式 ttl:"1h" 仍升 1h 档(遍历遇 1h 短路返回,顺序无关)。④ 三个臂活/重排点统一走 realSchedule() 加 .unref(),测试注入调度器的复位路径同样走它。
  5. 是否有回归问题:未发现无意回归。逐项审过的既有行为清单及结论:主转发路径(src/server.ts 不在分类器调用方集合里,调用方清点=compress-loop-responses/loop-core/preflight×2/external-summary-http 五处,全侧车道)保持;真实 split-brain 告警保持——代际门是单向的,扫描方永不跳过比自己晚开机的同 PID 孪生,较老一侧仍会告警(测试双向钉住);[Bug][split-brain] Restart-handover notice persists forever after the peer pid is gone (stale storage.splitBrain) #4626 graceful-stop 双时间戳跳过在冲突消解中原样保留(并集正确);1h 升级与档位判定不变;server.ts import 块取并集完整(master 新增引用全保留);未触碰 kernel/。两处有意的行为变更均已在正文披露:侧车道瞬态判定面扩大、无 ttl 断点从「不臂活」变「臂 5m 档」。另:审核中发现 master 现存一处红(tests/issue5719-msgid-lane-identity.test.ts T1/T8 两个 stale pin,[PR] fix: keep the live conversation on its raw lane when a full compaction lands with a persona-text drift (#5719) #5734 改 rung 顺序后未对齐),本 PR 经中途 rebase 带入了该修复——实测 origin/master 上该文件 6/8、本分支 8/8,属修好既有坏味道而非引入变化。
  6. 是否破坏缓存:不涉及。未触碰缓存/重试游标/去重键策略;keepalive 维护的是上游 provider 侧 cache TTL,不是 bili 内部缓存。
  7. 是否改了设计方向:没有。唯一附带调整:cache-keepalive 测试文件移入 CI live lane(新增 liveness 测试要派生真实子进程,需隔离跑),diff 注释已写明,属 CI 调度微调。
  8. 是否引入了新的配置:没有。无新 env/config/默认值。

审核发现与处置

验证证据

  • npm ci + npm run build 绿(rebased head,build-info commit 匹配);
  • 定向套件本地全绿 102/102:cache-keepalive(36)、served-markers、loop-core、event-loop-watchdog、issue-split-brain-surface、issue5719-msgid-lane-identity;
  • master vs 分支 A/B:issue5719-msgid-lane-identity 文件 origin/master 6/8(T1/T8 fail)→ 分支 8/8;
  • 贡献身份:[PR] fix(served-markers): ignore prior container generations with same PID on restart (#3923) #5028 外部作者 Aldo Adirajasa Fathoni 的 git author 字段保留 ✅;
  • CI(新 head e5c1dcd 触发):30 项检查 0 failed,核心矩阵 13 项 in_progress(mysql-contract/gate 已绿,e2e 各道 file-gate 正常 skip)。CI 落定我再补一行结论。

@ranxianglei
ranxianglei merged commit 9696c08 into master Nov 7, 2026
55 checks passed
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1064-master.9696c08 (rolling master tag).

npm install -g billion-context@0.0.1064-master.9696c08  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI 进度补报(head e5c1dcd):开跑约 25 分钟,30 项检查 0 failed,12 项仍在跑(全部是 test 矩阵 shard + static-gates windows,其余含 mysql-contract/gate 已绿、e2e 各道按 file-gate 正常 skip)。已完成的没有任何失败;pending 的这批看起来是 runner 排队而非测试红。我不再空转盯盘——红了我会定向排查并回贴,绿了即「可合」结论生效。

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.

[Bug] cache keepalive never arms when cache_control has no ttl

2 participants