Skip to content

[PR] fix: detect and self-heal stale MCP session bindings (#4661) - #4691

Open
ranxianglei wants to merge 17 commits into
masterfrom
2026-10-25_stale-binding-self-heal
Open

ranxianglei wants to merge 17 commits into
masterfrom
2026-10-25_stale-binding-self-heal

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #4661. Complements #4168 (witness-conflict self-rebind) with its missing half: the no-witness stale shape, which never 409s and silently answers from the frozen old ledger.

Problem

ZCode injects no session id into its MCP child; the shim binds to the static BILI_CONVERSATION_ID pin in ~/.zcode/cli/config.json. The pin goes stale on every new host session / host restart, and every MCP tool then answers from the frozen old session — all-zero CONTEXT BREAKDOWN, Nudge: idle — while the real session's ledger stays healthy in GET /__bili/sessions. Zero diagnostics anywhere made it look like a proxy fault or protocol incompatibility.

Fix (evidence-based, no guessing)

The proxy proves staleness with runtime traffic evidence instead of recency guesses: a new in-memory-only Session.lastModelRequestAt is stamped by the request pipeline only (tool calls and disk reloads cannot refresh it), so "bound session quiet >15 min while another non-restored session has strictly newer model traffic" is honest evidence of a stale pin.

Behavior changes (old → new)

Path Old New
Stale-bound tool call, no matching witness silent answer from frozen ledger same answer + ⚠️ advisory prefix + staleBinding field + warn log
Status poll on direct-bound stale conversation plain status + additive staleBinding field
Static-pin shim startup silent stderr warning naming the failure mode + rebind recipe
Proxy-proven staleness (any global binding kind) manual rebind only shim auto-adopts the proxy-named candidate, retries once; opt-out below
409 conflict adoption arming identity bindings only also static pins (via #4168 recency facts)

Fresh bindings, nativeCaller authority (#2024), fail-closed semantics, and lastModelRequestAt non-persistence are unchanged. After a proxy restart, no diagnosis fires until both sessions have in-process evidence (safe default).

Config surface

New env var BILI_MCP_NO_STALE_ADOPT (=1 disables the shim auto-rebind):

  • Why existing surface cannot express it: it is a per-process spawn channel read by the MCP shim process at spawn (the proxy never sees it) — the same category as the existing BILI_MCP_NO_ORPHAN_ADOPT precedent it mirrors. No config-file key added.
  • Default: adopt (opt-out semantics, like its sibling). Documented in LIFECYCLE.md §2.6, CONFIGURATION.md en+zh, CLIENTS.md zcode section.

Tests

Local: typecheck clean, build clean, targeted suites green.

ci-check added 2 commits October 25, 2026 19:36
ZCode pins a static BILI_CONVERSATION_ID into its MCP shim; the pin goes stale on every new host session / restart and every tool then answers from the frozen old ledger with zero diagnostics (all-zero CONTEXT BREAKDOWN while the real session is healthy). Complements #4168's witness-conflict self-rebind with its missing half: the NO-witness shape, which never 409s.

- Session.lastModelRequestAt (in-memory only): stamped by the request pipeline only, so it stays honest evidence of live model traffic
- handlePluginTool: bound session quiet >15 min while another non-restored session has strictly newer traffic -> warning prefix on the result + additive staleBinding field naming the live candidate + rate-limited warn log; #4168's witness-conflict 409 unchanged
- handlePluginStatus: same additive staleBinding field for direct-bound polls
- mcp.ts shim: startup warning for static pins; adopts the proxy-named candidate on proxy-proven staleness (retries once when the answered call ran on the old session); #4168's 409 adoption now armed for static pins too
- opt-out: BILI_MCP_NO_STALE_ADOPT=1 (mirrors BILI_MCP_NO_ORPHAN_ADOPT)

Tests: tests/issue4661-stale-binding.test.ts (13 rows incl. the negative cases required by #3617); adjacent tool-ring / mcp-native-thread suites green.
…O_STALE_ADOPT

- CLIENTS.md zcode section: session binding & stale pins bullet (pin mechanics, symptom signature, evidence-based auto-detection/recovery, manual rebind recipe, opt-out)
- LIFECYCLE.md env table: BILI_MCP_NO_STALE_ADOPT row
- env-only.yaml seed entry + regenerated CONFIGURATION.md / CONFIGURATION.zh-CN.md tables
@ranxianglei ranxianglei changed the title fix: detect and self-heal stale MCP session bindings (#4661) [PR] fix: detect and self-heal stale MCP session bindings (#4661) Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-25_stale-binding-self-heal (b773d1a)

Latest build — install this exact version

npm install -g billion-context@0.0.10294-pr.4691.38b07fd

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
b773d1a billion-context@0.0.10294-pr.4691.38b07fd build
00d61c5 billion-context@0.0.9592-pr.4691.dac1ba0 build
6f18fb9 billion-context@0.0.9586-pr.4691.9859e64 build
59e0053 billion-context@0.0.9564-pr.4691.8a8ae23 build
085a6b6 billion-context@0.0.6155-pr.4691.c3333c9 build
b64d123 billion-context@0.0.6070-pr.4691.86b19e2 build
2f3c20c billion-context@0.0.5968-pr.4691.eb4e125 build
05b1f1f billion-context@0.0.5890-pr.4691.769a43d build
dcf25be billion-context@0.0.5822-pr.4691.7a348f0 build
7ad14f2 billion-context@0.0.5751-pr.4691.5d438be build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr4691.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

(ai: opencode/qwen3.8-27b)

查重:不重复。本 PR 是 #4661(ZCode MCP 静态 pin 失步后工具调用静默答自冻结旧会话)的修复,与 #4168(witness-conflict 409 self-rebind)是同机制家族的互补面——#4168 管「有 witness 冲突」的 stale 形状,本 PR 管「无 witness、永不 409」的 no-witness 形状;两者症状同源但触发路径不同,PR 描述里已明确互补关系,不构成重复立项。检索 open+closed issue/PR 未发现同失败签名(MCP tool 答自冻结 ledger + all-zero breakdown)的其他条目。

开始按 PR Review 规范独立审查(原 issue 方向 → 回归清点 → 代码 → 测试有效性 → diff 整洁度),结论稍后按八问体例给出。

ci-check added 3 commits October 25, 2026 19:56
…4661)

CI auto-fix lane for PR #4691 head cdd8731: the gate flags the PR's
new type as INTERNAL_ONLY — it is referenced only inside src/plugin.ts
(staleBindingDiagnosis() return type + the tool-route binding site), so
drop the leading export. Type-only change, zero runtime impact.
Local: gate clean (6 waived), typecheck clean,
tests/issue4661-stale-binding.test.ts 13/13.
tests/issue4661-stale-binding.test.ts spawns real MCP shim children over
stdio, so the #1248 SPAWN_RE tripwire in scripts/run-ci-tests.mjs aborts
every shard at pretest until it is registered. Appended (not inserted —
slot = index drives each file's zone port band); its mock proxy is
listen(0), so no zone band is needed — the entry is for the tripwire.
Two pre-existing lines under 'Plugin-mode stamping' were re-indented from
the file-wide 2-space continuation style to 3 spaces; renders identically
but needlessly churns the diff.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: opencode/qwen3.8-27b)

Review update — found and fixed the CI blocker in-branch; final verdict follows the re-run.

Why all 11 test shards were red (not inherited master reds): the new tests/issue4661-stale-binding.test.ts spawns real MCP shim children over stdio, so the SPAWN_RE tripwire in scripts/run-ci-tests.mjs (#1248) aborted every shard at pretest with:

process-spawning test files missing from LIVE_FILES in scripts/run-ci-tests.mjs: tests/issue4661-stale-binding.test.ts

No test actually ran on head b2b459f2a. Fixed with two labeled commits pushed to this branch (head now 33da90db2):

Code review status: full independent pass done (stamp site, candidate invariant, #4168 byte-stability, #2024/#760 authority, shim retry bounds, all 13 test rows, docs/env-var surface). Local targeted verification green: the 5 adjacent suites incl. the new file = 76/76, typecheck clean. Expectation for the re-run: static gates green; residual test-shard failures, if any, should be exactly the known master born-red set tracked in #4599 (storage lane 7 + plugin-fork flake) — I'll verify shard-by-shard before issuing the structured verdict.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 —— 本条是该 PR 自身的 CI 自动修复车道(attempt 1/2)。两处红均为 PR 自带的门禁缺陷,与既有 issue/PR 无关;残余测试红属 master born-red 名册,已在 #4599 留结论评论,未另开条目。

修复(最终 head 33da90db2,分支 2026-10-25_stale-binding-self-heal)

  1. b2b459f2a(本车道):StaleBindingDiagnosis 去掉 export(src/plugin.ts:313)——该类型仅文件内使用(staleBindingDiagnosis() 返回类型 + 工具路由绑定处),de-export 后 unused-exports 门禁通过,零行为变化。
  2. fb36a674c(并行 worker 先推、本车道核对后采用):把新套件 tests/issue4661-stale-binding.test.ts 登记进 LIVE_FILES(追加在表尾;该套件用 listen(0) mock + stdio 拉起 shim,无固定端口,不需要 zone band,登记只为过 tripwire)。此前 tripwire 让全部 11 个测试分片在跑任何用例前整体中止。我本地同一修法提交因远端已含等价修复而丢弃(冗余,不重复 push)。
  3. 33da90db2(并行 worker):CLIENTS.md zcode 节恢复 2 空格续行缩进。

验证:CI 上 unused-exports 转绿、静态门全绿、测试分片真实执行;本地 typecheck、门禁双向复现脚本、issue4661 定向套件 13/13 全绿。

八问

  1. 是什么问题:PR 自己引入的两处门禁遗漏——新类型被导出却无外部消费者,触发 unused-exports 门;新增进程派生套件未登记 LIVE_FILES,触发 tripwire 使全部测试分片空转中止。
  2. 什么原因导致的:编写期遗漏(未按仓库两条门禁契约自查),非基建缺陷。
  3. 影响范围与严重程度:仅影响本 PR 的 CI(gate 红 → fail-fast 跳过测试层;tripwire → 11 分片跑前中止);对用户运行时零影响(type 可见性 + 测试基建登记)。严重度:CI 阻塞级,无外部影响。
  4. 怎么修复的:内部类型去导出(行为不变);LIVE_FILES 表尾追加登记(append-only,不动既有项、不移动任何现有 zone band)。本地双向验证 + CI 实证生效。
  5. 是否有回归问题:无。触碰路径既有行为逐项审过:类型无外部引用(grep 钉死);LIVE_FILES 表尾追加不改变任何既有条目的 slot/端口带。残余 8 个红分片与 master 自身 run(40189242801 @ ac844fa)逐日志比对:14 个失败子测试中 13 个与 master born-red 名册逐字节一致(存储车道 7 项[待 A/B/C 裁决]、plugin-fork[[PR] test: plugin-fork assertions branch by storage mode (runners without sqlite engine are no longer born-red) | test: plugin-fork 断言按存储模式分支(无 sqlite 引擎的 runner 不再 born-red) #4652 待合]、storage-render golden ×4、web-blogfeed probing);唯一差异是 #2954 …registry marker…clobbered proxy-origin——纯分片调度噪声:本 PR 的新测试文件(+445 行)触发 LPT 重排,把该套件挪到一条 windows 腿上,同腿并发进程占着默认端口 18787(日志原文 "port 18787 is held by a different process (pid 8028)"),该套件注入假 spawn(tripwire 扫不到)、握手探测直接打 18787、无 zone band 保护;PR diff 不触碰 launcher/instance/端口任何路径。PR 自身代码零致红。
  6. 是否破坏缓存:不涉及(修复面为类型可见性与测试登记,不碰缓存/重试/游标逻辑)。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:本修复不引入。(PR 本体含 BILI_MCP_NO_STALE_ADOPT=1 opt-out env,已在 CONFIGURATION.md en+zh 文档化——属 PR 原设计,非本轮修复新增。)

判定:PR 专属的两处 CI 缺陷已闭环,本分支无需再动;残余红全部是 master 自带 born-red 名册,master 收敛后(#4599 存储车道裁决落地 + #4652 合并)预期转绿。

ci-check added 2 commits November 13, 2026 09:18
…conflict

# Conflicts:
#	CLIENTS.md
#	CONFIGURATION.md
#	CONFIGURATION.zh-CN.md
#	LIFECYCLE.md
#	scripts/live-files.mjs
#	src/mcp.ts
#	src/plugin.ts
#	src/server/handle.ts
…t async

Merging master into the #4691 branch brought in 8ba5c03 (#4942), which
turned handlePluginStatus from a sync void function into an async
Promise<void>. The #4661 status-route test called it without await and
asserted on the mock response synchronously — the response is now written
on a later tick, so the assertion saw status 0. Await the three call
sites (the it() callbacks were already async). No production code change.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

Merge-conflict resolution done — branch pushed, CI will judge the new head.

The PR branch 2026-10-25_stale-binding-self-heal was 18 days / 2860 commits behind master, so I merged gh/master (259cd87) into the branch (merge, not rebase — no history rewrite, no force-push). 8 files conflicted, one hunk each, all resolved as union-of-intent:

One merge-induced test break, fixed as a separate labeled commit (4dd44f9): master's #4942 (8ba5c03) turned handlePluginStatus from sync void into async Promise<void>; the PR's status-route test called it without await and asserted on the mock response on the same tick (saw status 0). Added await to the three call sites — the it() callbacks were already async. No production code change.

Verification: npm run typecheck clean; targeted tests/issue4661-stale-binding.test.ts 13/13 pass. Full-suite verdict is the remote CI on the pushed head (not run locally, not asserted here — the mirror cache had no cached checks at check time). Pushed: 085a6b67..4dd44f9d70 (remote head was unchanged at fetch time, no concurrent work). If a shard goes red, the residual master born-red roster tracked in #4599 (storage lane 7, plugin-fork #4652) is the first thing to check.

八问(中文结论)

  1. 是什么问题:PR 分支落后 master 18 天(2860 个提交),与目标分支冲突(merge state dirty),无法合并。
  2. 什么原因导致的:PR 于 2026-10-25 从当时的 master 切出;期间 master 大量演进——四份根目录文档迁到 docs/([PR] docs: batch-migrate 14 root-level documents into docs/ (consolidation + master index + redirect placeholders) | docs: 14 个根级文档一次性迁入 docs/(集中 + 总目录 + 重定向占位) #5920 布局裁定)、handlePluginStatus 改 async(MySQL-backed storage loses all sessions after a restart when JSON envelopes are off (no synchronous read facade) #4942)、plugin 路由重写([bug] Claude Code Task subagents: bili MCP tools run against the root session (process-wide CLAUDE_CODE_SESSION_ID) → 409 witness conflicts, phantom range errors, and a subagent fold applied to the parent | Claude Code 子代理的 MCP 压缩落到父会话 #4580)等——与 PR 改动的 8 个文件重叠。
  3. 影响范围与严重程度:仅影响本 PR 的可合并性;对用户行为零影响。
  4. 怎么修复的:把 master merge 进 PR 分支(不 rebase,避免重写 11 个 PR 提交的历史),8 处冲突逐一「双方意图并集」解决;PR 的文档增量按 master 的新 docs/ 布局重新落位;master 使 handlePluginStatus 变 async 导致的测试断言时序问题,加 await 修复(独立标注 commit)。
  5. 是否有回归问题:无。冲突全部为增量并集,双方行为语义均未漂移;测试 await 修复只改断言时机、不改断言内容;文档迁移是 master 自身裁定([PR] docs: batch-migrate 14 root-level documents into docs/ (consolidation + master index + redirect placeholders) | docs: 14 个根级文档一次性迁入 docs/(集中 + 总目录 + 重定向占位) #5920),PR 内容原样跟随。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:无。PR 的 [ZCode host] MCP shim cannot auto-discover session ID — after CLAUDE_CODE_SESSION_ID expires, acp_status/compress resolv | [ZCode host] MCP shim 无法自动发现会话 id —— CLAUDE_CODE_SESSION_ID 过期后 acp_status/compress 查到冻结旧会话(表现为可压缩范围索引为空) #4661 过期绑定自愈设计原样保留,只是基线更新。
  8. 是否引入了新的配置:无(BILI_MCP_NO_STALE_ADOPT 是 PR 自身的配置,非本次 merge 引入;已按新文档布局登记到 docs/configuration.md / docs/configuration.zh-CN.md / docs/lifecycle.md)。

判定:冲突已清零、基线已对齐,可合并性待 CI 在新 head(4dd44f9d70)上确认;CI 红则先查 #4599 的 master 继承红清单。

…conflict

# Conflicts:
#	website/config-reference/env-only.yaml
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

Second conflict sweep done — branch re-synced with the newest master and pushed.

The blocker trigger arrived after my first merge; live check this run: master had moved on again (259cd87 → a007974, +53 commits, mostly the ja-translation parity pass over website/config-reference/env-only.yaml plus docs/handle.ts churn). I merged current master into the branch again — this time exactly one conflicted file:

  • website/config-reference/env-only.yaml — master added a desc_ja line to the existing BILI_MCP_NO_ORPHAN_ADOPT entry while the PR added the new BILI_MCP_NO_STALE_ADOPT entry at the same spot. Resolved as union: kept master's desc_ja line AND the PR's entry, and gave the new entry its own desc_ja line so it matches the file's now-trilingual shape (en/zh/ja) — a 4-line mechanical addition, no semantic change.

Everything else auto-merged clean and I verified the PR content stayed intact: docs/configuration.md:450, docs/configuration.zh-CN.md:450, docs/lifecycle.md:172 (the env row) and src/server/handle.ts:1738 (the lastModelRequestAt stamp). No conflict markers remain.

Verification on the new head: npm run typecheck clean; targeted tests/issue4661-stale-binding.test.ts 13/13 pass. Pushed 4dd44f9d70..59e0053c57 (remote head was unchanged at fetch time — no concurrent work, no force-push).

CI state: verified live against the mirror cache — it still shows the PREVIOUS head (4dd44f9, fetched 12:44 UTC) with no check entries yet; the poller refreshes ~60s, so the new head's checks are not readable yet and I am not asserting green/red. Full-suite verdict is the remote CI on 59e0053; if a shard goes red, #4599's master born-red roster (storage lane 7, plugin-fork #4652) is the first thing to check.

八问(中文结论)

  1. 是什么问题:上一轮 merge 后 master 又前进了 53 个提交(主要是 env-only.yaml 的日文翻译补齐),PR 分支与目标分支再次冲突。
  2. 什么原因导致的:同一机制——PR 切出后 master 持续演进;这次 master 的 ja 翻译 pass 恰好改在 PR 新增 BILI_MCP_NO_STALE_ADOPT 条目的同一位置。
  3. 影响范围与严重程度:仅影响本 PR 的可合并性;对用户行为零影响。
  4. 怎么修复的:再次把当前 master merge 进 PR 分支;唯一冲突文件 website/config-reference/env-only.yaml 按「双方并集」解决——保留 master 给 BILI_MCP_NO_ORPHAN_ADOPT 加的 desc_ja 行,保留 PR 的新条目,并按文件现在三语(en/zh/ja)的格式给新条目补了一行 desc_ja。
  5. 是否有回归问题:无。冲突为纯增量并集,双方语义均未漂移;其余文件自动合并后逐项核实 PR 内容仍在(docs 三处 env 行 + handle.ts 的 stamp)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:无。
  8. 是否引入了新的配置:无(BILI_MCP_NO_STALE_ADOPT 是 PR 自身配置,本次仅按新格式补了日文描述行)。

判定:冲突已清零(对 a007974 基线),新 head 59e0053 已推送;CI 尚未出结果(镜像缓存还停在旧 head),可合并性待 CI 确认。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

ci-check added 2 commits November 13, 2026 22:53
The floor-19 merge added desc_ja to the BILI_MCP_NO_STALE_ADOPT seed entry
in website/config-reference/env-only.yaml but did not regenerate the
Japanese config doc, so the docs-sync gate (gen-config-docs generate +
git diff --exit-code) failed and cascaded a skip to every test/static-gates
leg. Applying the generator's own output closes the gap; EN/ZH docs and the
seed already carried the row.
The PR's new process-global warnedStaleBindings Set was not cleared by the
test-state reset, unlike its sibling warnedNoModelRequests. Tests use random
conversation ids so this is latent, but the reset should clear every
warn-Set it manages for isolation consistency.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

CI engineer run (attempt 1/3) — outcome: no merge conflict exists (stale trigger); the real blocker was a red docs-sync CI job, now fixed in-branch and pushed.

1. The "merge conflict" trigger was stale — there is no conflict.
Live verification this run (single GET /pulls/4691 + git ls-remote, no gh-polling):

  • PR: open, mergeable: true, mergeable_state: "blocked" (blocked = waiting on CI/approval, not dirty/conflict).
  • base master = a007974683; head (before my push) = 59e0053c57.
  • master is already an ancestor of the PR head (git merge-base --is-ancestor = true; 0 commits on master not on head). A merge would be a no-op.
  • ⇒ Nothing to rebase or merge. The "dirty" flag in the trigger was a stale snapshot.

2. The real blocker was a red CI job — docs-sync — which I fixed.

  • The run on head 59e0053c57 had exactly ONE failing job: docs-sync (job 131917929012). All guards/gates/build-artifact/mysql-contract/plan + all e2e lanes were green or skipped.
  • docs-sync runs node tools/gen-config-docs.mjs generate then git diff --exit-code over the generated docs. It failed on ONE missing row in docs/configuration.ja.md: the BILI_MCP_NO_STALE_ADOPT table row (between BILI_MCP_NO_ORPHAN_ADOPT and BILI_MITM_HOSTS).
  • Root cause: the floor-19 master merge added a desc_ja to the BILI_MCP_NO_STALE_ADOPT seed entry in website/config-reference/env-only.yaml but never regenerated the ja doc. EN (docs/configuration.md:450) and ZH (docs/configuration.zh-CN.md:450) already carried the row; only JA was missing.
  • Cascade: docs-sync is a needs: prerequisite for the test and static-gates jobs (ci.yml), so its failure fail-fast-skipped every test leg — that's why the whole run read as red.

Fix (committed + pushed):

3. CI status — I am NOT asserting green.

八问:

  1. 是什么问题: 触发器报「与基线分支冲突(dirty)」,但实测无冲突;真正的阻塞是 CI 的 docs-sync job 红。
  2. 什么原因导致的: floor-19 合 master 时给 BILI_MCP_NO_STALE_ADOPT 的 seed 加了 desc_ja,但没重新生成 docs/configuration.ja.md,导致 ja 文档缺这一行;docs-sync 门禁对生成物做 git diff --exit-code 因而失败,并 fail-fast 跳过全部 test/static-gates 腿。
  3. 影响范围与严重程度: 仅本 PR 的 CI 信号(docs-sync 红 + 连带跳过),无用户侧功能影响;非功能回归。
  4. 怎么修复的: 用 CI 同款生成器 node tools/gen-config-docs.mjs generate 本地重新生成,只产生 1 行插入(ja 缺的那行,与 CI 期望逐字节一致),提交并推送。
  5. 是否有回归问题: 无。纯文档重新生成(仅 ja 文档加一行表格),无代码/行为变更;EN/ZH 文档本就有该行,只缺 JA。
  6. 是否破坏缓存: 不涉及。
  7. 是否改了设计方向: 不涉及。
  8. 是否引入了新的配置: 无新配置(BILI_MCP_NO_STALE_ADOPT 环境变量是前几轮 PR 已加的,本轮只同步它的 ja 文档行)。

Conclusion: no merge conflict existed (stale trigger); the red CI was a PR-specific docs-sync gap, now fixed in-branch and pushed (head 6f18fb92a6). Awaiting the new run's CI result — not asserting green until it's read live.

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: posted as a COMMENT review because GitHub forbids approving one's own PR. Verdict below is APPROVE.

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

APPROVE — clean, correct, well-tested. No blocking issues, no kernel/ or pi-subagents/ touch (no authorization gate).

What I verified (independently of the issue text):

  1. Diagnosis (src/plugin.ts:379 staleBindingDiagnosis): bound session quiet > STALE_BINDING_QUIET_MS (15 min) while another non-restored session has strictly newer lastModelRequestAt → suspected stale. Never-seen sessions measure quiet from STALE_BINDING_PROCESS_START_MS (evidence floor, not epoch); restored sessions never candidates; most-recent candidate picked.
  2. Stamp placement (src/server/handle.ts:1738): session.lastModelRequestAt = Date.now() sits in the model-request path (handleRequest) only — tool calls (handlePluginTool) and disk reloads don't reach it. In-memory only (type decl at src/session.ts:760; absent from buildRecord/persistence).
  3. #4168 409 byte-for-byte unchanged: only a comment added; the forkReply(res, 409, …) body is untouched. The no-witness stale shape is diagnosed on the success path and never reaches the 409 branch.
  4. Success path additive (src/plugin.ts:2573–2590): ⚠️ STALE BINDING SUSPECTED prefix + staleBinding body field (absent when fresh). stale is declared at function level (line 2291) so it is in scope at the success path — no scope bug.
  5. Shim self-heal (src/mcp.ts): adopts the proxy-named candidate (prefers candidateConversationId over candidateSessionId), retries once (if (attempt === 0) continue). resolveForkConversation resolves both session ids and conversation ids, so the candidate fallback is safe. Per-call routes (conversationIdOverride/nativeCaller) never consume the adoption (#760/#2024 preserved); #4168 409 adoption extended to static pins (STATIC_PIN && STALE_ADOPT).
  6. Tests (tests/issue4661-stale-binding.test.ts, 13 rows): 8 proxy rows (2 positive + 6 negative per #3617) + 5 shim rows driving the REAL src/mcp.ts over stdio. Assertions have teeth (exact status codes, body fields, execution targets, retry counts, stderr logs). Ran the file locally: 13/13 pass.
  7. Config surface: new env BILI_MCP_NO_STALE_ADOPT (per-process spawn channel, mirrors BILI_MCP_NO_ORPHAN_ADOPT); documented in docs/configuration.md en+zh, docs/lifecycle.md, docs/clients.md (zcode), website/config-reference/env-only.yaml (en/zh/ja).

已顺手修:_resetPluginStateForTest 补上 warnedStaleBindings.clear()(PR 新增的进程级 warn-Set 未随兄弟 warnedNoModelRequests 一起重置;测试用随机 id 故为潜伏项,但重置应覆盖它管理的每个 warn-Set)+ commit 00d61c5


八问

  1. 是什么问题:ZCode 宿主把静态 session id 钉进 MCP shim(BILI_CONVERSATION_ID 配置钉);宿主开新会话或重启后,所有 MCP 工具都从冻结的旧账本静默回答(全零 breakdown、idle nudge),而真实会话健康——零诊断。
  2. 什么原因导致的:静态绑定缺少运行时流量证据来检测失步。shim 钉的 id 在宿主开新会话/重启后失效,但 proxy 没有任何机制检测"所绑会话已静默而另一会话在活跃"。
  3. 影响范围与严重程度:影响 ZCode 用户(静态绑定 MCP shim 的宿主)。严重度:能用但体验毁灭——所有 MCP 工具从冻结旧账本回答,用户看到全零 breakdown 与 idle nudge,真实会话健康,且无从诊断。
  4. 怎么修复的:三层——(1) proxy 用运行时流量证据(session.lastModelRequestAt,仅请求管道盖章)检测失步;(2) 工具路由:疑似失步仍按原样执行但大声(⚠️ 前缀 + 加性 staleBinding 字段 + 限流 warn 日志),#4168 409 字节级不变;(3) shim 自愈:采纳 proxy 命名候选、重试一次、静态钉启动 stderr 警告、#4168 409 采纳扩展到静态钉。
  5. 是否有回归问题:逐项审过既有行为——(a) #4168 409 路径字节级不变(仅加注释);(b) 成功路径加性(新前缀+新字段);(c) 状态路由加性;(d) lastModelRequestAt 仅内存、不持久化;(e) 每次调用路由不写回全局绑定(#760/#2024 保留);(f) nativeCaller 不被诊断(#2024 保留)。无回归。
  6. 是否破坏缓存:不涉及(不触碰缓存/重试/增量游标/去重键)。
  7. 是否改了设计方向:不涉及(#4168 的补充,不改架构/边界/数据流)。
  8. 是否引入了新的配置:是。新 env BILI_MCP_NO_STALE_ADOPT(=1 禁用 shim 自动重绑;默认采纳)。类别:每进程 spawn 通道(镜像 BILI_MCP_NO_ORPHAN_ADOPT 先例)。已文档化(en+zh+ja)。

判定:APPROVE。 无阻断项;一处测试隔离小修已就地修掉(commit 00d61c5)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Reviewed PR #4691 (stale MCP session bindings, #4661): verdict APPROVE — posted as a COMMENT review since GitHub forbids approving one's own PR (verdict is in the review body). Independently verified the diagnosis logic, stamp placement (handleRequest-only), #4168 409 byte-stability, shim self-heal (candidate adoption + one retry), and the 13-row test file (ran locally: 13/13 pass). One small finding fixed on the spot: _resetPluginStateForTest now clears the PR's new warnedStaleBindings warn-Set (was only clearing the sibling warnedNoModelRequests) — commit 00d61c5, pushed, PR head now 00d61c5. No kernel/ or pi-subagents/ touch → no authorization gate. Review: #4691 (review)

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] auto-fix stalled: test (windows-latest, 22, 4), test (ubuntu-latest, 24, 1), test (windows-latest, 22, 2), test (windows-latest, 22, 3), test (ubuntu-latest, 22, 1) — stopping for human review

…4661)

The 5 red test shards were inherited from the stale base a007974
(~432 commits behind master), not caused by this PR:
- visibleNotices x2 -> #6547 (8a082c2): BILI_STORAGE_UNIFIED=legacy
  baseline pin conflicts with sqlite-default announcement visibility
- Windows EBUSY x3 -> 7c152dc: closeQuietly sidecar before rmrf teardown

Master carries both fixes; merging brings them in. Single conflict in
scripts/live-files.mjs resolved by union (kept the #4661 test entry plus
master's web-logs-query + content-encoding-zstd entries).

Verified locally: typecheck clean; notice-registry 5/5 (was red);
issue4661-stale-binding 13/13.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

Inherited red CI — cleared by merging master.

The "merge state: dirty" trigger was stale — the live state was behind, not a conflict. The real blocker was 5 red test shards, and they are inherited, not caused by this PR:

Fix: merged origin/master (e0d63bf8c8) into the branch. One conflict, in scripts/live-files.mjs (the live-test manifest) — resolved by union (kept the #4661 test entry plus master's web-logs-query + content-encoding-zstd entries). Regular push, no force-push. New head b773d1a542.

Verified locally: typecheck clean; notice-registry 5/5 (the previously-red suite); issue4661-stale-binding 13/13 (the PR's own suite).

Current CI: new run in progress — 6 success / 0 failed / 10 running; behind cleared to blocked (awaiting checks + human approval). I can't assert full green until the run completes; the lane will re-check.


八问

  1. 是什么问题:PR 的 CI 有 5 个 test 分片红,触发了「merge state: dirty」告警。
  2. 什么原因导致的:这 5 个红不是本 PR 引入的,是继承性失败——分支 base 停在 a007974683(落后 master 约 432 提交),master 侧后来修了两组测试:visibleNotices ×2([bug][tests] #6480 makes two legacy-envelope suites red on every shard: notice-registry inherits the legacy pin, persist suites hold index.db past rmrf #6547,8a082c24c6,全局 CI 基线钉 BILI_STORAGE_UNIFIED=legacy 与 sqlite-default 公告可见性冲突)+ Windows EBUSY ×3(7c152dc08a,teardown 前 closeQuietly sidecar)。本 PR 的 5 个红分片正好命中这两组。
  3. 影响范围与严重程度:仅阻塞本 PR 的 CI 绿灯(进而阻塞合并),不影响运行时行为;PR 的功能代码本身无问题。
  4. 怎么修复的:把 origin/master(e0d63bf8c8)merge 进 PR 分支,带入 master 侧的这两组修复;唯一冲突在 scripts/live-files.mjs(测试清单),按并集保留([ZCode host] MCP shim cannot auto-discover session ID — after CLAUDE_CODE_SESSION_ID expires, acp_status/compress resolv | [ZCode host] MCP shim 无法自动发现会话 id —— CLAUDE_CODE_SESSION_ID 过期后 acp_status/compress 查到冻结旧会话(表现为可压缩范围索引为空) #4661 条目 + master 的 web-logs-query + content-encoding-zstd)。普通 push,未 force-push。
  5. 是否有回归问题:merge 是机械并集,未改任何 PR 功能代码;typecheck 干净;本地定向验证 notice-registry 5/5(原红)、issue4661-stale-binding 13/13 全绿。无回归。
  6. 是否破坏缓存:不涉及(纯 CI 合并,无缓存/重试/游标逻辑变更)。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

收工判定:fix 已推送(00d61c5a13..b773d1a542),新 CI 运行中(6 绿 0 红 10 运行中),「behind」已消除转「blocked」(等待检查 + 人工审批)。等该 run 全绿即可合并;若个别分片仍红,下一轮 lane 接力。

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Note: posted as a COMMENT review because GitHub forbids approving one's own PR. Verdict below is APPROVE.

Re-review of new head b773d1a54 — the only new commit since my last review (00d61c5a) is a merge of origin/master (e0d63bf8c8) to clear inherited red CI on a stale base. I verified the merge is clean and the PR's stale-binding fix is byte-identical to what I previously approved:

  • No conflict resolution altered the PR logic. Across all 8 overlap files (touched by both master and the PR — src/plugin.ts, src/server/handle.ts, src/session.ts, src/mcp.ts, scripts/live-files.mjs, website/config-reference/env-only.yaml, docs/configuration{,.zh-CN,.ja}.md), the diff 00d61c5a → b773d1a54 shows zero stale-binding-related line changes — only line-number shifts from master's unrelated additions.
  • Test file byte-identical (tests/issue4661-stale-binding.test.ts, 452 lines, 0 diff).
  • All PR symbols intact at the new head: staleBindingDiagnosis, STALE_BINDING_QUIET_MS, warnedStaleBindings, lastModelRequestAt stamp (src/server/handle.ts:1775), type decl (src/session.ts:764), shim adoption (src/mcp.ts:222/263), and my prior fix warnedStaleBindings.clear() (src/plugin.ts:5497) all survived the merge.
  • No semantic conflict: master did not change any function the PR's logic depends on (listSessions, resolveForkConversation, the restored field) — staleBindingDiagnosis still reads s.restored/listSessions() correctly.

The PR's content (diagnosis, loud-flag, shim self-heal, #4168 409 byte-stability, config surface) is unchanged from my prior review, which verified all of it end-to-end (13/13 tests pass locally). No kernel/ or pi-subagents/ touch → no authorization gate.

CI at this head: 0 failed, 8 test shards still in progress (mirror cache; the static-gates / mysql-contract / gate lanes already green).

已顺手修:无新增小修——本次仅 master 合并,PR 自身代码零改动,无新发现。


八问

  1. 是什么问题:ZCode 宿主把静态 session id 钉进 MCP shim(BILI_CONVERSATION_ID 配置钉);宿主开新会话或重启后,所有 MCP 工具都从冻结的旧账本静默回答(全零 breakdown、idle nudge),而真实会话健康——零诊断。
  2. 什么原因导致的:静态绑定缺少运行时流量证据来检测失步。shim 钉的 id 在宿主开新会话/重启后失效,但 proxy 没有任何机制检测"所绑会话已静默而另一会话在活跃"。
  3. 影响范围与严重程度:影响 ZCode 用户(静态绑定 MCP shim 的宿主)。严重度:能用但体验毁灭——所有 MCP 工具从冻结旧账本回答,用户看到全零 breakdown 与 idle nudge,真实会话健康,且无从诊断。
  4. 怎么修复的:三层——(1) proxy 用运行时流量证据(session.lastModelRequestAt,仅请求管道盖章)检测失步;(2) 工具路由:疑似失步仍按原样执行但大声(⚠️ 前缀 + 加性 staleBinding 字段 + 限流 warn 日志),#4168 409 字节级不变;(3) shim 自愈:采纳 proxy 命名候选、重试一次、静态钉启动 stderr 警告、#4168 409 采纳扩展到静态钉。
  5. 是否有回归问题:逐项审过既有行为——(a) #4168 409 路径字节级不变(仅加注释);(b) 成功路径加性(新前缀+新字段);(c) 状态路由加性;(d) lastModelRequestAt 仅内存、不持久化;(e) 每次调用路由不写回全局绑定(#760/#2024 保留);(f) nativeCaller 不被诊断(#2024 保留)。本次 master 合并未触碰任何 PR 逻辑行(零改动),无新增回归。
  6. 是否破坏缓存:不涉及(不触碰缓存/重试/增量游标/去重键)。
  7. 是否改了设计方向:不涉及(#4168 的补充,不改架构/边界/数据流)。
  8. 是否引入了新的配置:是。新 env BILI_MCP_NO_STALE_ADOPT(=1 禁用 shim 自动重绑;默认采纳)。类别:每进程 spawn 通道(镜像 BILI_MCP_NO_ORPHAN_ADOPT 先例)。已文档化(en+zh+ja)。

判定:APPROVE。 本次仅 master 合并(清继承红 CI),PR 自身代码零改动、逻辑与我上轮 APPROVE 时字节级一致,无新发现、无阻断项。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Re-reviewed PR #4691 at new head b773d1a (the only new commit since my last review is a master merge to clear inherited red CI on a stale base): verdict APPROVE — posted as a COMMENT review since GitHub forbids approving one's own PR (verdict in body). Verified the merge is clean: zero stale-binding line changes across all 8 overlap files, test file byte-identical (452 lines), all PR symbols + my prior fix (warnedStaleBindings.clear(), plugin.ts:5497) intact, and master didn't touch any function the PR depends on (listSessions/resolveForkConversation/restored). PR logic is byte-identical to my prior APPROVE; no new findings, no small fixes needed. CI at this head: 0 failed, 8 test shards still in progress (static-gates / mysql-contract / gate already green). Review: #4691 (review)

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

This branch has not been deployed

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

Labels

None yet

Projects

None yet

1 participant