Skip to content

[PR] fix: v0.1.202 review leftovers — zcode watchdog hot-retry, Responses pck ablation, pck-probe bounds, diagnostics single-read - #3825

Merged
ranxianglei merged 6 commits into
masterfrom
2026-10-19_v01202-release-review-leftovers
Oct 19, 2026
Merged

ranxianglei merged 6 commits into
masterfrom
2026-10-19_v01202-release-review-leftovers

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Host-side fixes for four of the six non-blocking leftovers flagged in the v0.1.202 release review (#3781), tracked in #3813. Each is an independent commit plus a targeted regression test.

Items 3 and 4 are kernel changes (message identity + nudge cadence) that require owner sign-off before implementation per the Kernel Boundary. They are analyzed and presented as a decision request in the #3813 thread, not included here.

Changes (old -> new)

1. zcode watchdog: cool the failure counter only after a completed recovery (src/zcode/mcp-entry.ts)

  • Before: state.failures = 0 ran before await ensure(). A throwing ensure (transient spawn failure / EADDRINUSE) cleared the counter, so the next recovery needed ~90s of re-accumulation (3 x 30s ticks).
  • After: the reset runs only after a successful recovery (self-spawned / lane-owned branch) or after the externally-owned wait log. A throwing ensure leaves the counter hot (limit-1), so the next tick retries immediately (~30s). Restores the v0.1.201 hot-retry behavior and re-aligns with claude-mcp-entry.ts, whose "(zcode parity)" comment is now accurate again.
  • Behavior change: degraded-path recovery latency on a transient ensure failure drops from ~90s to ~30s. No effect on the healthy path or the externally-owned wait posture.

2. Responses lane honors the #2645 prompt_cache_key ablation memory (src/server/prepare-responses.ts)

  • Before: the Responses lane forwarded prompt_cache_key verbatim even after an egress origin+model was A/B-confirmed hostile, re-paying a 400 + probe retry every turn (the client still saw a final 200).
  • After: consults pckKeyAbated() like the OpenAI chat lane and drops the key (client-supplied or injected) once ablated.
  • Behavior change: no more wasted RTT per turn against an ablated destination on the Responses lane. Non-ablated destinations are untouched.

3. Bound the pck-probe ablation maps (src/pck-probe.ts)

  • Before: MAX_SESSIONS_TRACKED=8 capped only the display array; the underlying per-pair sessionCounts Map and the pair table grew unbounded under an untrusted tunnel client.
  • After: the per-pair session map evicts lowest-count entries beyond 32; the pair table evicts least-recently-confirmed pairs beyond 64. The display array is still capped at 8. A test-only accessor _pckProbeSessionCountForTest exposes the previously-unobservable map size.
  • Behavior change: memory growth is now bounded (a restart still resets). Eviction is LRU-by-lastAt, so actively-reconfirmed hostile destinations survive a flood of new ones.

4. Diagnostics reads the rotated log pair once per report (src/web/diagnostics.ts)

  • Before: a conflict-banner request set both the storage tail and the conflict banner; each called candidateLogLines(), doing two full synchronous readFileSync of the rotated pair (hundreds of MB possible) and stalling the event loop.
  • After: the candidate lines are fetched once and shared by both tails. Output is byte-identical.
  • Behavior change: conflict-banner diagnostics do 1 full log read instead of 2. No output change.

Tests

Targeted suites (run locally, green):

  • tests/zcode-mcp-entry.test.ts — 9 pass (incl. new: a throwing ensure leaves the counter hot)
  • tests/issue3813-responses-pck-ablation.test.ts — new, 2 pass (positive drop + negative forward)
  • tests/issue2645-pck-probe.test.ts — 8 pass (incl. new: pair-flood + session-flood bounds)
  • tests/web-diagnostics-enrichment.test.ts — 5 pass (incl. new: single-read, no cross-leak between tails)

Full-suite verdict comes from CI on the pushed head. tsc --noEmit is clean project-wide.

Not in this PR

Refs #3813

awork added 4 commits October 19, 2026 19:20
#3813 item 1: state.failures was reset before await ensure(), so a throwing ensure (transient spawn/EADDRINUSE) cleared the counter and forced ~90s of re-accumulation before the next recovery attempt. The reset now runs only after a successful recovery (self-spawned/lane-owned branch) or after the externally-owned wait log, restoring the v0.1.201 hot-retry behavior and re-aligning with claude-mcp-entry's "(zcode parity)" path.
#3813 item 2: the Responses lane forwarded prompt_cache_key verbatim even after an egress origin+model was A/B-confirmed hostile, re-paying a 400 + probe retry every turn. It now consults pckKeyAbated() like the OpenAI chat lane and drops the key (client-supplied or injected) once ablated.
#3813 item 5: MAX_SESSIONS_TRACKED capped only the display array; the underlying per-pair sessionCounts Map and the pair table grew unbounded under an untrusted tunnel client. Both axes are now capped (per-pair session map evicts lowest-count beyond 32; pair table evicts least-recently-confirmed beyond 64).
#3813 item 6: buildDiagnostics("conflict-banner") set both the storage tail and the conflict banner, each calling candidateLogLines() — two full synchronous readFileSync of the rotated pair (hundreds of MB possible), stalling the event loop. The candidate lines are now fetched once and shared by both tails; output is unchanged.
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-19_v01202-release-review-leftovers (c487883)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4547-pr.3825.7de30a1

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-pr3825.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: v0.1.202 review leftovers — zcode watchdog hot-retry, Responses pck ablation, pck-probe bounds, diagnostics single-read [PR] fix: v0.1.202 review leftovers — zcode watchdog hot-retry, Responses pck ablation, pck-probe bounds, diagnostics single-read Oct 19, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 与 #3813 相关但不同。 本 PR 实现 #3813 清单中的 4 个 host 侧小项(#1 zcode 看门狗、#2 Responses pck 消融记忆、#5 pck-probe 无界增长、#6 diagnostics 双读),并明确把 #3/#4 两个 kernel 项排除在外(等你在 #3813 线程拍板)。按失败签名(zcode watchdog counter / responses prompt_cache_key / pck sessionCounts / candidateLogLines)检索了 open+closed 的 issue 与 PR,没有其他条目覆盖这四项。

标签: bug · zcode · codex · scope/wiring · p3 —— 四个已确认缺陷的修复包,涉及 zcode 与 codex 两条通道,主体改动在客户端接入层/协议接线,全部为非阻塞遗留小项、不影响可用性。

审核进行中:已独立核对四项改动的 diff、既有行为清单与测试有效性,结构化八问结论随后单独给出。

@ranxianglei ranxianglei added bug Something isn't working codex p3 scope/wiring zcode 改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签 labels Oct 19, 2026
The #3813 enrichment test pinned the shared-candidate behavior (identical
output, no cross-tail leak) but not the IO property that is the point of
item 6: a regression back to per-tail reads would stay green. Count full
pair scans in candidateLogLines (test-only accessor + reset) and assert
exactly one read for a conflict-banner report (was two), one per further
report, and zero for unregistered topics.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Review complete. I pulled the branch and read all four source diffs against pre-change master, verified each claimed behavior against the actual code paths (watchdog scheduler error handling, claude-lane parity, v0.1.201 tag archaeology, pck record/lookup origin matching, sessionCounts display-only usage, diagnostics topic registration), ran the four targeted suites locally (24 pass), and waited for remote CI on the head to go fully green.

独立核查(既有行为清单,逐项):

  1. zcode 看门狗 — "恢复 v0.1.201 行为"的说法成立:git tag --contains 证实 reset-before-ensure 是 v0.1.202 的看门狗重写(Hook-model clients (claude/zcode) have no mid-session self-heal when the proxy dies — ECONNREFUSED until next session #1821)引入的,重写前代码正是在恢复完成后复位。调度器对每次 tick 有 .catch(log).finally(busy=false) 包裹,热计数器导致的立即重试只会产生带日志的 watchdog error,不会变成未处理 rejection。修复后 claude 侧 "(zcode parity)" 注释重新准确(claude 只在完整拉起后才冷却)。路由失败(config 改写抛错)现在也保持计数器热——与"仅在恢复完成时冷却"语义一致,属有意为之。新测试有牙:pre-fix 会失败(计数器会是 0 而非 limit-1)。
  2. Responses pck ablation — 与上方 resolvePromptCacheKey 不重复(那个函数根本不查 registry);drop 发生在注入键与客户自带键都落位之后,两个来源都覆盖,与 OpenAI lane(resolveRelayAffinityPck)语义对齐。origin 身份用模块统一的 billingUpstream ?? upstreamOrigin,记录侧存的是归一化后的 egress URL,匹配成立。已知 caveat(与 OpenAI lane 相同、非新增):lookup 用入站 model、record 用出站 model——若中途改模型则漏判,回落到现状。正反向双测走真实 startServer(Test Blind Spot Retrospective: Reinforcing Negative Assertion Discipline, Tightening Fake Upstream Strictness, Thin Inst | 测试盲区复盘:补反向断言纪律、假上游严格化、薄安装冒烟、形态矩阵与生命周期覆盖 #3617 门禁纪律满足)。
  3. pck-probe 限界 — sessionCounts 纯展示用(pckAblations() 序列化前已剥掉),min-count 驱逐不可能污染 ablation 判定;pair 表驱逐只在插入时跑,≤64 的界按构造成立;LRU-by-lastAt 让持续被再确认的恶意目标在洪泛中存活。pair-flood 断言 <= 128 是刻意放宽——钉的是"有界"而非精确上限(实际洪泛后恰好 64),可接受的防御性宽松。
  4. diagnostics 单次读 — 新读条件与旧的两个惰性调用条件完全等价(两 tail 都在且仅在其 topic 注册时读;conflict-banner 同时注册两者),输出逐字节相同(同一数组上的纯过滤)。附带收益:消除了同一次请求内两次读之间的日志轮转竞态。def || t === "conflict-banner" 第二子句是死条件(conflict-banner 已注册)但无害、防御性。

发现一处测试缺口,已直接修掉: #3813 的新 enrichment 测试只钉了共享读的输出属性(无交叉泄漏),没钉读次数——将来谁把双读改回去,测试照样绿。已在 PR 分支补一个标注 commit:test(diagnostics): pin the single-read-per-report contract (#3813)(head 现为 27289a8dc)——给 candidateLogLines 加扫描计数(test-only accessor + reset),断言 conflict-banner 恰好 1 次读(修复前是 2)、后续每份报告 1 次、未注册 topic 0 次。本地 typecheck 干净 + 该套件 5/5。

八问:

  1. 是什么问题:v0.1.202 发版审核遗留的四个不阻塞项——zcode 降级路径在瞬时故障后恢复要 ~90s 而非 ~30s;Responses lane 对已确认恶意的目的地每回合白白多付一次 400+重试 RTT;pck-probe 内存可被隧道客户端洪泛无限增长;conflict-banner 诊断请求做两次全量同步日志对读取、卡事件循环。
  2. 什么原因:①v0.1.202 看门狗重写时把复位挪到了 await 之前;②Responses lane 先于 openai wire: prompt_cache_key stamped unconditionally — breaks strict-schema upstreams (NVIDIA NIM 400), no config escape #2645 ablation registry 存在,registry 落地时没给它补上查询调用;③展示上限实现时没管底层 Map 的界;④每个 tail 各自惰性取候选行,没有共享一次取数。
  3. 影响范围与严重程度:全部在降级路径或对抗性输入面,健康流量不受影响。zcode 仅降级模式下的瞬时 spawn 失败(一次性多等 ~60s);Responses 仅对 A/B 确认恶意的 origin+model 的回合(浪费 RTT,客户端仍见 200);pck-probe 仅限不受信隧道客户端洪泛;diagnostics 仅限大轮转日志下点 conflict-banner 的面板用户。均 p3 级。
  4. 怎么修复的:计数器只在恢复完成后冷却(对齐 claude lane 语义);Responses lane 补上与 OpenAI lane 相同的 ablation 查询;两个 probe 结构加 LRU/min-count 驱逐界、展示上限不动;候选日志行每份报告取一次、两 tail 共享。
  5. 回归风险:未发现。逐项清点过——健康路径时序、外部托管等待姿态、非 ablated 目的地的 key 透传、ablation 判定内容(被驱逐的是展示专用 map)、诊断输出字节,全部保持。有意行为变更(旧→新+原因):zcode 瞬时故障恢复延迟 90s→30s(恢复 v0.1.201 语义);Responses lane 对 ablated 目的地丢 prompt_cache_key(停止白付 400);probe map 超 32 session/pair、64 pair 开始驱逐(重启仍重置);conflict-banner 诊断 1 次全量读替代 2 次(输出不变)。
  6. 是否破坏缓存:不。前缀缓存/重试/去重策略均未触碰;对 ablated 目的地丢 prompt_cache_key 本身就是缓存修复(不再重付 400)。
  7. 设计方向:未变——四项全部落在既有机制内(看门狗状态机、openai wire: prompt_cache_key stamped unconditionally — breaks strict-schema upstreams (NVIDIA NIM 400), no config escape #2645 registry、probe 结构、diagnostics builder)。
  8. 新配置:无。没有新增 env、config 字段或默认值。

判定:可合并。 远端 CI 在 head 27289a8dc 全绿(15 success / 15 skipped / 0 failures),PR mergeable。内核两项(#3 URL 图片 id churn、#4 nudge low-water ratchet)不在本 PR,仍在 #3813 线程等你 A/B 拍板。

@ranxianglei
ranxianglei merged commit d4d8acf into master Oct 19, 2026
27 of 28 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.612-master.d4d8acf (rolling master tag).

npm install -g billion-context@0.0.612-master.d4d8acf  # 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codex p3 scope/wiring zcode 改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant