Skip to content

fix: dsh attach — superseded recovery flights must not revert the registered origin - #3618

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-18_dsh-attach-origin-generation
Oct 17, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-18_dsh-attach-origin-generation

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3616

Problem

The dsh attach-mode test apply() attach mode: registers manifest tools verbatim… flakes on Windows CI: the tool call is answered by the previous test's still-alive mock (calls empty in the deepStrictEqual while the response text matched).

Root cause

verifyAttachAndRecover()'s healthy-attach branch binds state.origin / register.base unconditionally from the origin captured at flight start. The flight is armed by apply(), but nothing invalidates it when the world moves on: _resetRegisterForTest() (test isolation) — or a fresh apply() (cordis deactivate/reactivate) — can run while the probe is still in flight. On a slow machine the late landing reverts register.base to the stale origin, and every tool execute reads the LIVE base (#983), so later calls follow it there.

The test-isolation instance of this race is exactly the CI failure; the same mechanism exists in production for a re-activation that lands mid-recovery (late writes from the previous context into the new one's register).

Fix — origin-plane generation token

  • New module-level originGen counter in src/agent/dsh-native.ts.
  • Bumped by every non-off apply() and by _resetRegisterForTest().
  • verifyAttachAndRecover() captures the generation at entry and re-checks it after each await; a superseded flight returns without writing register/state.
  • Same gate in bootstrap() after ensureProxyRunning (a superseded spawn reports its landing but binds nothing).
  • Existing landingOwnsRegister guards kept — they cover a different domain (same-world maybeRetry self-heal moving the register); the generation covers world changes.

Behavior change (intended)

Old: an in-flight attach verify/spawn from a PREVIOUS activation could clobber the new activation's registered origin with the stale one when it landed late.
New: only the newest activation's recoveries may write the origin plane; superseded flights become no-ops (they still report their landing value to their own consumers).
Happy path unchanged: with a single activation and no concurrent recovery the generation never changes mid-flight.

Tests

  • New deterministic regression #3616 apply() attach mode: a superseded verify landing must not revert the registered origin: holds mock A's manifest (the version probe and the registration source share the URL) so world 1's verify stays IN FLIGHT across the reset + second apply, then releases it after world 2 owns the register. Verified to FAIL on pre-fix code (AssertionError — the call answered by the stale mock) and pass with the fix. No timing luck: the hold makes the ordering exact.
  • Targeted local runs: dsh-native.test.ts 56/56; issue2082 / issue2101 / issue3380 / issue2187 + dsh-settings-ui + dsh-admin-relay 35/35; typecheck clean; build clean. Full-suite verdict = CI.

No config surface change. No kernel change. No version bump.

@ranxianglei

Copy link
Copy Markdown
Owner Author

chon冲突

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

收到,开始 review PR #3618(修 #3616 dsh attach 竞态)。

查重:不重复 —— 检索 open/closed issue+PR 无同机制条目。注意 master 上已有相邻机制:#3544/#3562 的 register.giveUpSeq(onGiveUp 时使在途 attach 链失效,防「复活已清空的 base」),本 PR 的 originGen 覆盖的是另一域(apply()/reset 的世界切换,防「回退到旧 origin」),两者互补、正交;但本 PR 基于 #3562 合入前的 master,rebase 后两处 guard 会在同一批 commit 点共存,我会重点核对 rebase 后所有写入点是否都被两个 gate 之一盖住。

当前状态:PR head 与 master 冲突(dirty),conflict-worker 已被转发做 rebase(floor 3)。我这边并行做代码审查 + 本地定向测试(dsh-native.test.ts 及相关 dsh 套件),rebase 落地后再核对 CI。结论按八问体例回复。

@ranxianglei
ranxianglei force-pushed the 2026-10-18_dsh-attach-origin-generation branch from 0b093bf to 1e591c0 Compare October 17, 2026 17:56
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-18_dsh-attach-origin-generation (1e591c0)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4263-pr.3618.056b285

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-pr3618.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: vllm-qwen/qwen3.8-27b)

上游冲突已解决(rebase 完成,force-push 0b093bf1d → 1e591c03d)

冲突原因:master 合入了 #3544(giveUp 失效机制 + 版本轮换)、#3593(attribution 可见性)、#3395(live-state 代际守卫)——与本 PR 改的是同一组热文件(src/agent/dsh-native.ts + tests/dsh-native.test.ts),两边在 verifyAttachAndRecover 里各自加了「飞行失效」守卫、又在同一个测试 helper 签名的同一位置插参数,文本级冲突。

解法:意图并集(两套守卫都保留,触发域互补)

结构化八问

  1. 是什么问题:PR 分支与 master 文本冲突——双方都在 dsh attach 恢复链路加了飞行失效守卫,且改了同一测试 helper 签名。
  2. 什么原因导致的:并行 PR 竞争同一热文件;两个守卫机制不同但目的相同(防止被取代世界的迟到 attach 飞行改写注册态)。
  3. 影响范围与严重程度:仅 dsh attach 恢复路径。竞态窗口内(旧飞行未落地时重新 apply)注册 origin 可能被回退到陈旧代理,压缩流量路由到错误代理;其余 lane 不受影响。
  4. 怎么修复的:rebase 取意图并集——双守卫共存(各管各的触发域)、gen 穿透进抽出的 spawnFallback、新增 await 点补齐 gen 检查、测试参数按先来后到排序。
  5. 是否有回归问题:逐项核过——master 的 giveUpSeq 全部原检查点原样保留;spawnFallback 行为除多一道 gen 门(gen 匹配时零影响)外不变;bootstrap/apply/_resetRegisterForTest 语义保持;压缩接管失效后完全静默:面板与 /__bili/status 看不出压缩已停,用户全价直连直到重启才恢复 #3581/feat: make takeover-attribution failures visible (panel + /__bili/status) | 压缩接管失效可见化 #3593 的 attribution 记录、安装新版本后旧代理永远不换新:detach 代理躲过应用退出,重启只是重新挂上旧进程(「永远更新不了」) #3544 版本轮换均保留。唯一有意变更:verifyAttachAndRecover 内轮换 await 后若 gen 已被取代则直接返回 undefined 不 attach——这正是 dsh attach mode test intermittently fails on Windows CI: the async recovery flow reverts the registered origin back to i | dsh attach 模式测试在 Windows CI 偶发红:异步恢复流程把注册 origin 改回旧值(测试隔离竞态) #3616 要修的行为。
  6. 是否破坏缓存:不涉及(未触碰缓存/重试/游标/去重逻辑)。
  7. 是否改了设计方向:没有——两个代际计数器并存,各守自己的触发域,无架构转向。
  8. 是否引入新的配置:无。

⚠️ 验证状态说明(诚实报告)

本地 typecheck + 定向测试未能执行:共享工作区磁盘写满(ENOSPC,根分区 100%),node_modules 装不上,属环境故障而非代码问题。已完成的是静态审查 + 关键语义追踪(确认 fetchProxyVersion 打的正是测试 hold 住的 /__bili/plugin/manifest,即 #3616 飞行确实悬停在守卫检查点之内,修复覆盖被测路径)。全量与定向测试以远程 CI test lane 为准,红了我会定向排查。

当前 PR 状态:mergeable: true(冲突已清;显示 behind 是因 push 后 master 又合了 #2950,只动 src/plugin.ts 与本 PR 零重叠,无需再 rebase)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

实测当前没有冲突,两处独立验证:

  1. GitHub API:mergeable: true,mergeable_state: behind(不是 dirty);
  2. 本地 git merge-tree HEAD origin/master:退出码 0,无任何文件冲突。

页面如果还显示红叉,是 force-push 后 GitHub 网页端合并状态缓存未刷新(它需要重新计算,稍等片刻会转绿)。

当前 behind 的原因:我 rebase 之后 master 又合了 #2950(persona-lineage-ref-guard),只动 src/plugin.ts 和本 PR 零重叠的文件——「behind」本身不阻塞合并,无需再 rebase。PR 已可合。

@ranxianglei
ranxianglei merged commit 07501b3 into master Oct 17, 2026
42 of 43 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.549-master.07501b3 (rolling master tag).

npm install -g billion-context@0.0.549-master.07501b3  # 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

None yet

Projects

None yet

1 participant