Skip to content

[PR] fix(agent): a single-flight-blocked turn must not burn its msgIds - #4863

Merged
ranxianglei merged 3 commits into
masterfrom
2026-10-26_msgid-claim-after-guard
Oct 27, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-10-26_msgid-claim-after-guard

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

这是啥问题

增量车道在"同 URL 还有一笔未确认(ack)请求"时会拦下后续请求(single-flight 守卫,#3370/#3378)。但三条原生车道(dsh、omp、opencode)都是先规划、后拦截:规划动作会顺带在客户端认领这批消息的 msgIds(#4491,全有全无)。被守卫拦下的回合,计划体被丢弃、已认领的 id 却永远不释放——宿主一重试,同一批 id 撞上残留认领,msgIds 字段整体静默消失,服务端只能按内容 hash 铸身份,这批消息的 host/server 身份从此分叉。这正是 #4834 刚根治的改写抖动家族,这里是客户端自伤入口。

不受影响的客户端:Claude Code 走服务端 anthropic 车道(无宿主侧规划、anthropic wire 本身不带逐消息 id);pi 车道的 pending 表按 sid 记、先对账后规划且结果立即使用,无丢弃路径——均已核对。

根因(代码坐标)

  • src/agent/dsh-native.ts / src/agent/omp-native.ts / src/agent/opencode-native.ts:planIncrementalTurn(内部经 incremental-client.ts claimableDeltaMsgIds 的 claims.add)跑在守卫扫描之前
  • 认领集 incremental-client.ts msgidClaims:只在下次 seed/resync 整组覆盖或 __reset 时清,被丢弃的计划没有回收路径

改动

守卫只依赖 url + 未 ack 表,与计划无关——把守卫整体提到 planIncrementalTurn 之前(三条车道各一块移动,守卫行为零变化);规划只对真正会发出的回合发生。opencode 的 alignedMsgIdsForWire() 是纯读取,留在(现位于守卫之后的)计划调用里不变。

验证

  • dsh 回归测试(tests/dsh-msgids.test.ts):守卫拦截带 msgIds 的 delta → seed ack → 重试仍带 msgIds: ["u-2"];stash 复核:改动前失败(actual: undefined)
  • opencode 回归测试(tests/opencode-msgids.test.ts):同场景,重试仍带 ["msg_a1","msg_u2"];stash 复核:改动前失败(actual: undefined)
  • tests/dsh-msgids、tests/opencode-msgids 全绿;msgid-lane-flow、msgid-algebra 全绿;tests/omp-native、tests/opencode-native 仅剩改动前就存在的环境性失败(与本次无关);typecheck 干净

关联

#4491(msgIds 机制)#3370/#3378(单飞守卫)#4834(同族身份分叉的根治)

@ranxianglei ranxianglei added the ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR label Oct 26, 2026
@ranxianglei ranxianglei changed the title fix(agent): a single-flight-blocked turn must not burn its msgIds [PR] fix(agent): a single-flight-blocked turn must not burn its msgIds Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-26_msgid-claim-after-guard (e456884)

Latest build — install this exact version

npm install -g billion-context@0.0.6308-pr.4863.1ec411c

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
e456884 billion-context@0.0.6308-pr.4863.1ec411c build
8457807 billion-context@0.0.6303-pr.4863.9ef96da build
17f0ed9 billion-context@0.0.6291-pr.4863.02bcab0 build
c728952 billion-context@0.0.6288-pr.4863.c7728e8 build

Download artifact

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

Install instructions are refreshed on each push.

…he turn

A turn that the guard discards had already claimed its msgIds
client-side (all-or-nothing, #4491). The burned ids were never
released, so the host's retry of the same turn lost the whole
msgIds field and the server pinned those rows to content-derived
identity — the exact host/server divergence #4834 just fixed,
self-inflicted here by the client lanes themselves.

Hoist the #3370/#3378 single-flight guard above planIncrementalTurn
in both native lanes (dsh, omp). The guard only reads the pending-ack
table, so the reorder changes nothing for the guard itself; planning
now only happens for turns that will actually be dispatched.

Regression test: a guard-blocked delta attempt must not burn its ids
— after the seed acks, the retry still pins msgIds (pre-fix: the
field is silently dropped).
opencode-native.ts had the same claim-before-guard order as dsh/omp
(planIncrementalTurn with the harvested msgIds at :979, the #3378
single-flight guard below it). A guard-blocked turn burned its
harvested ids the same way; hoist the guard above the planning call.
alignedMsgIdsForWire() is a pure read of the harvest map, so it is
safe to keep inline in the (now post-guard) plan call.

Regression test mirrors the dsh one: blocked attempt must not burn
the ids; after the seed acks, the retry still pins them
(pre-fix: actual undefined).
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复——与 #4834 同族(host/server 身份分叉),但机制不同:#4834 根治的是服务端改写抖动,本 PR 修的是客户端自伤入口(plan-before-guard 烧掉已认领的 msgIds)。无重复条目。

标签: bug + dsh/opencode/omp(三条被改车道)+ scope/wiring(协议接线/请求管道)+ p2(静默身份降级、窄触发窗口、无数据丢失)。

独立审核过程(不照抄 issue 结论):我在 master @ 24e71f6 上逐条复核了根因坐标——incremental-client.ts 的 msgidClaims(只在 seed/resync 整组覆盖或 __reset 时清,无回收路径)、claimableDeltaMsgIds 的碰撞即整体丢弃语义、dsh/omp 两车道 plan 先于守卫的旧顺序,全部属实。审核中发现 opencode 车道(maybeIncrementalOpencode)存在完全相同的 plan-before-guard 缺陷且原 diff 未覆盖——你随后推的 17f0ed9 正好补齐了它并附回归测试,我已核对该 commit:守卫整体上提到 planIncrementalTurn 之前,与另两条车道的移动同形。我未推送任何 commit(缺口已由你本人关闭)。

结构化八问

  1. 是什么问题:单飞守卫拦下的回合,规划动作已经认领了这批消息的 msgIds,计划被丢弃后认领永不释放;宿主一重试,同一批 id 撞上残留认领,msgIds 字段整体静默消失,这批消息的 host/server 身份从此按内容 hash 各铸一套。
  2. 什么原因导致的:dsh/omp/opencode 三车道都是「先 planIncrementalTurn(顺带 claims.add)、后守卫扫描」,而认领集没有任何单计划回收路径——守卫依赖的只是 url + 未 ack 表,与计划无关,顺序纯属历史遗留。
  3. 影响范围与严重程度:特定条件下有问题——同一 URL 还有一笔未 ack 请求时宿主重试(增量车道正常推进中的常见竞态);后果是受影响回合的 msgIds 静默降级为内容 hash 身份(缓存前缀仍可命中,但身份分叉是 [PR] fix(pi-msgids): model-switch rewrite no longer drops client message ids (pairing proof preserved) | fix(pi-msgids): 切模型改写不再丢客户端消息 id(配对证明保留) #4834 家族的病理),无数据丢失、会话可用 → p2。
  4. 怎么修复的:把守卫整块提到规划之前(三车道各一块移动,守卫条件与返回零变化),让规划只对真正会发出的回合发生——从源头消灭「丢弃的计划」,而不是给认领加回收路径。
  5. 是否有回归问题:逐项审过被触碰路径的既有行为——①被拦回合现在提前返回,跳过的 parse/probe/plan 全部无副作用或走 TTL 缓存(probeCache 读时校验,跳过不会延长任何条目);②未拦路径的执行序列逐字节不变;③skip-check 与守卫的顺序交换不可观测(两者都是静默返回、请求照常走普通管道);④sweep→守卫之间没有新增 await,竞态窗口只收窄不放宽。结论:无回归。
  6. 是否破坏缓存:不涉及——不碰缓存键、游标、去重策略;probeCache 行为不变。
  7. 是否改了设计方向:不涉及——架构/边界/数据流不变,只是同一函数内两个步骤的先后互换。
  8. 是否引入了新的配置:不涉及——零新 env/config/默认值。

行为变更披露(Deliverables 第 4 条):被拦回合现在少跑 parse/probe/plan 三步——可观测行为零变化(这些产物本来就会被丢弃),特此声明。

验证证据

判定:PR 自身无阻塞项,方向正确、修法打到根因(源头消灭而非补丁回收)、三车道覆盖完整;等继承红消解(e2e 重跑/哨兵收敛)即可合入。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

补一行 CI 终态(head 17f0ed9,59/59 check runs 全部完成):除已证实的 4 条继承性 real-client e2e 红(见上条与 #4599 报告)外,其余全绿——包括此前在跑的那个单元 test shard。即本 PR 自身相关的每条 lane 均通过,剩余红全部是 #4823 schema 变更遗留的 master 级问题,等哨兵收敛后重跑即可合入。

yanhuojiyusheng pushed a commit to yanhuojiyusheng/billion-context that referenced this pull request Oct 27, 2026
…glei#4491/ranxianglei#4834)

The doctrine said stable client ids may only ever be join hints. That was
written before the plugin lanes started shipping host msgids in a bili-private
envelope (msgIds on the incremental turn / biliMsgIds stripped at ingress)
and before ranxianglei#4834 made resolution id-first. Agents reading the docs concluded
'we have no msgids' — true on the model wire, false on the plugin lanes.

- AGENTS.md KDD ranxianglei#11 retitled to the full hierarchy: msgid first where the
  envelope carries it (plugin lanes only, never forwarded upstream), order
  still primary on id-less resend reconciliation, hash stays the per-cell
  gate. Three-part PK (session_id, msg_id, content_hash) noted as safety belt.
- AGENTS.md KDD ranxianglei#13 evolution updated to four stages (hash -> order ->
  msgid pinning -> snapshot render).
- MESSAGE-IDENTITY.md: new section 'The msgid envelope' documenting the
  channel, all-or-nothing semantics, resync re-claim, ranxianglei#4834 id-first,
  ranxianglei#4863 claim-after-guard, and the boundary (model wire unchanged,
  tool-call ids are pairing keys, proxy-mode resends keep the ladder);
  Future-direction paragraph refreshed.
@ranxianglei
ranxianglei merged commit dd630f1 into master Oct 27, 2026
98 of 157 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.866-master.dd630f1 (rolling master tag).

npm install -g billion-context@0.0.866-master.dd630f1  # 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 ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR dsh omp opencode p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant