Skip to content

[PR] fix(dsh): discover seeded forks through request-scoped session lookup - #4424

Closed
abworks-dev wants to merge 4 commits into
ranxianglei:masterfrom
abworks-dev:2026-10-23_dsh-scoped-fork-discovery
Closed

abworks-dev wants to merge 4 commits into
ranxianglei:masterfrom
abworks-dev:2026-10-23_dsh-scoped-fork-discovery

Conversation

@abworks-dev

Copy link
Copy Markdown
Contributor

Summary

Fix the scoped-identity fork-discovery blind spot reported in #4215 (category G; related canonical tracking #3011). This is the behavioral C10b counterpart to the log-only C10a PR #4223, not a replacement for its diagnostics.

In v0.1.204, attributionOf() can correctly identify a model dispatch from the llm/stream request scope while forkChildOf() still reads only currentInitiator(). When that ambient agent is absent, a seeded fork child silently skips adoption and replays its unfolded history. Large histories can then enter repeated local 413 rejection.

Change

  • If the ambient session is undefined, resolve the existing attributed sid through the host's optional agents.get(sid).
  • Require the returned session.id to equal the requested sid, then retain the existing isSeeded === true, nonempty parentSession, and parent != child gates.
  • Preserve the ambient path and its throw/fail-closed behavior; do not guess a recent agent, scan sessions, or infer lineage from content.
  • Keep compatibility with hosts lacking agents.get.

The host lookup is already available in the inspected DSH runtime; no new host API, configuration, kernel change, persistence format, or wire transformation is introduced. This only enables the existing snapshot/match/fork admission protocol to run. Parent snapshot validation and prefix checks are unchanged in both plugin and proxy modes.

Regression evidence

  • Real registered llm/stream waterfall + async stream continuation, with synthetic session metadata only.
  • Positive scoped lookup and legacy ambient path; negatives for unknown/unscoped identity, mismatched returned session id, subagent/nonseeded session, empty/self parent, missing optional lookup, throwing lookup and disposed initiator.
  • Negative control: removing only the lookup change makes the new regression fail (actual undefined vs expected child/parent). Restoring it passes.
  • npm run typecheck: passed.
  • npm run build: passed.
  • node --import tsx --test tests/dsh-llm-stream-attribution.test.ts tests/dsh-fork-adopt.test.ts: 25 passed, 0 failed.
  • Broader tests/dsh-native.test.ts: 64 passed, 1 failed in the existing [Bug][dsh-native] 运行中自动换版后接管静默失效:旧 fetch hook 持有已 dispose 的 ctx,currentInitiator() 永久 threw,重启才恢复 #3578 test's Windows temporary-directory cleanup (rmSync EPERM); repeated standalone with the same cleanup failure. Not claimed green; remote CI remains authoritative.

Boundaries / review

Human review requested because this touches session binding. No auto-merge or release requested. Coordinate with #4223 because it changes the same discovery helper. This PR fixes only the request-scoped discovery gap; unavailable/opaque parent snapshots, retroactive CHILD_CONFLICT, and interrupted-preflight recovery remain separate #3011/#4215 family work. It does not claim that every historical incident necessarily took this gate. No real transcripts, databases, local recovery scripts, credentials, session IDs, or business data are included.

@ranxianglei ranxianglei changed the title fix(dsh): discover seeded forks through request-scoped session lookup [PR] fix(dsh): discover seeded forks through request-scoped session lookup Oct 23, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

ework

ranxianglei#4449 added tests/codex-mcp-shell.test.ts and
tests/codex-plugin-version-sync.test.ts; both match the SPAWN_RE
tripwire but were never registered in scripts/live-files.mjs, so every
CI test shard dies at startup before running a single test (red master
since 751c354, inherited by all open PRs).

Concurrency review required by the tripwire:
- codex-mcp-shell.test.ts spawns node MCP-server children over stdio
  only — no port binding, temp dirs only;
- codex-plugin-version-sync.test.ts execFileSyncs
  sync-codex-plugin-version.mjs against mkdtemp fixtures — no ports.
Both are safe under --test-concurrency 4; their zone bands stay unused.

Appended per the append-only slot rule in live-files.mjs. Verified by
replicating run-ci-tests.mjs's full-set tripwire scan locally.

No bili behavior change.
@ranxianglei ranxianglei added bug Something isn't working dsh p1 scope/wiring ci:full Run the FULL CI matrix (all e2e lanes + 12-leg test matrix) on this PR labels Oct 24, 2026
Covers the one untested branch of the C10b scoped fallback: an ambient
initiator that is present but whose session is already cleared (mid-dispose)
must take the same request-scoped agents.get(sid) path as a missing one and
resolve the exact child when found. The missing-initiator shape was already
pinned by the existing cases; this closes the bidirectional pair of the
'session === undefined' branch.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重:不重复。 同族相关条目:#3011(跟踪主 issue)、#4266(p1 伞 issue,你已定「下个版本统一解决」)、#4215(已关闭的复现实例)、#4223(C10a 兄弟面——只加诊断日志,机制不同)。本 PR 是 C10b(请求作用域查找)这一具体机制面,没有其他 PR 实现同一面。

标签: bug + dsh + scope/wiring + p1(症状与 #4266 同族:fork 继承丢失 → 零折叠重放 → 大会话 413 循环,按「会话恢复/继承类」口径定 p1)。

方向关(需要你拍板)

本 PR 实现的是 C10b 路线②:ambient 为空时,通过可选宿主 API agents.get(sid) 用请求作用域 sid 兜底解析 AgentLike。#3011 floor 20 时两条路线还悬而未决(「两者都动宿主契约面,等你定路线」),floor 34 只定了「立 p1、下版本统一解决」,没碰路线。我的评估:②更通用——不需要宿主逐分支改动、老宿主优雅降级(已测)、严格 id 匹配门防错认;PR 声称其检查过的 DSH 运行时已经暴露该 lookup(本仓库内无法验证)。请确认路线②,或告诉我 hold 到 #4266 的车上再走。

八问

  1. 是什么问题:DSH 克隆长会话时,若子会话的 ambient initiator 尚未就位(或已被 dispose),bili 找不到子会话 → 静默跳过 fork 采纳 → 子会话从零折叠开始、重放父会话全部未压缩历史;大会话反复撞本地 413 拒绝。
  2. 什么原因导致的:归因层(attributionOf,Why did it spike to several M tokens: after dsh attribution was lost, requests bypassed bili and were sent directly, ren | 为什么会涨到几 M tokens:dsh 归因丢失后请求绕过 bili 直发,压缩与护栏全部失效 #4082)早已改用请求作用域(AsyncLocalStorage)解析 sid,但发现层(forkChildOf)仍只读 ambient currentInitiator()——两层身份源不一致,ambient 空时发现层失明。根因 = 发现层没有跟上归因层迁到请求作用域身份。
  3. 影响范围与严重程度:仅 dsh 插件车道「克隆长会话」场景,且限当时 ambient 恰好为空/dispose 的时刻;后果 = fork 继承丢失、上下文膨胀、413 循环、极端不可用——与 [Bug] Fork of DSH branch clone: inheritance permanently abandoned by 409 SNAPSHOT_UNAVAILABLE — zero-fold clone triggers context_length_exceeded 400 on first turn | [Bug] DSH 分支克隆的 fork 继承被 409 SNAPSHOT_UNAVAILABLE 永久放弃:克隆零折叠,首轮即 context_length_exceeded … #3011/Zero-Inheritance Session Cloning: Unified Fix for Eight Independent Defects in the Fork Adoption Chain (Next Release Tar | 会话克隆零继承:fork 收养链上八类独立缺陷统一修复(下版目标) #4266 同症状族(p1);本 PR 修其中 C10 这一个入口机制。
  4. 怎么修复的:ambient session 为 undefined 时,退回用请求作用域 sid 经 agents.get(sid) 解析;要求返回的 session.id 与请求 sid 严格一致(防错认);其余门(isSeeded / parentSession / fail-closed)原样不动;ambient 存在时行为与之前逐字节一致(测试钉住)。
  5. 是否有回归问题:逐项审过——ambient 路径(不变,优先级测试钉住);出错 fail-closed(保持);无 agents.get 的老宿主兼容(测试覆盖);采纳门(不变);proxy 模式(不触碰,纯插件车道);wire/配置/持久化/kernel(不触碰)。未发现回归。一个已知残留盲区(有意为之、测试钉住):currentInitiator() 抛异常(disposed scope)时仍返回 undefined、不进 scoped 兜底——该形状待 [PR] fix: name every skipped DSH fork-adoption entry gate instead of returning silently (#4215) #4223(C10a 诊断)落地后会被命名,属同一 C10 入口盲区族,在 Zero-Inheritance Session Cloning: Unified Fix for Eight Independent Defects in the Fork Adoption Chain (Next Release Tar | 会话克隆零继承:fork 收养链上八类独立缺陷统一修复(下版目标) #4266 跟踪,不单立。
  6. 是否破坏缓存:不涉及(缓存/重试/游标/去重键均未触碰)。
  7. 是否改了设计方向:无架构转向;是把发现层补进 Why did it spike to several M tokens: after dsh attribution was lost, requests bypassed bili and were sent directly, ren | 为什么会涨到几 M tokens:dsh 归因丢失后请求绕过 bili 直发,压缩与护栏全部失效 #4082 既有的请求作用域身份体系。但它确实押注了 C10b 路线②——见上方方向关,等你确认。
  8. 是否引入新配置:无 config/env/CLI 变更;仅在 PluginContext.agents 上加一个可选字段 agents.get——宿主侧加法接口,老宿主优雅降级(已测)。

代码审查(独立复审)

  • 正确性:scoped 兜底只在 ambient session 为 undefined 时触发(initiator 抛异常不会走到);严格 id 匹配门;lookup 出错 fail-closed(测试钉住);无作用域的 dispatch 不做猜测(测试断言 lookup 零调用)。
  • 测试有效性:双向断言有牙。我本地独立做了负控——只删掉 6 行 lookup 逻辑块(保留 export),恰好 1 个新测试失败、同文件其余通过 → 新测试确实钉住了这个修复,不是恒真。
  • 顺手修掉的小缺口:原测试未覆盖「initiator 在场但 session 已清空(mid-dispose)」的形状——已顺手补 case,commit 6757fe408(test(dsh): pin sessionless-ambient fallback in the fork discovery gate)。
  • 合并顺序建议:[PR] fix: name every skipped DSH fork-adoption entry gate instead of returning silently (#4215) #4223(C10a)改同一个函数(改名 forkChildVerdict + 结构化 verdicts),且已过审转绿。建议先合 [PR] fix: name every skipped DSH fork-adoption entry gate instead of returning silently (#4215) #4223,再把本 PR rebase 上去;rebase 时把 scoped-not-found / scoped-id-mismatch 两个 verdict 形状补进它的 verdict 矩阵,保住 C10a「无静默返回」的承诺。

行为变更披露(旧→新)

Seeded fork child 在 ambient initiator 缺席时的处置:旧 = 静默不采纳(重放父会话全部未压缩历史,大会话陷入 413 循环);新 = 经请求作用域 agents.get lookup 采纳(严格 id 匹配门)。加法可选宿主 API 字段,无 config/env/wire/kernel/持久化变更。原因:让发现层与归因层(#4082)身份源一致,闭合 C10 入口盲区。

CI master 红(已顺手修掉,查重:无)

PR head 最初全红(11 个 test shard 全挂)——根因不在本 PR:master 上的 #4449(codex 插件)新增了两个会 spawn 进程的测试文件但没登记进 LIVE_FILES(scripts/live-files.mjs),CI tripwire 在跑任何测试前杀掉全部 test shard;master head 本身同样红。两个文件的并发假设已核实(一个只 spawn stdio MCP 子进程、另一个对临时目录 fixture execFileSync,均不绑端口),按 append-only 规则追加登记,commit c69a544a0 独立推到本 PR 分支。open+closed issues/PRs 按失败签名检索过,无既有跟踪条目。

验证证据

  • 本地定向:tests/dsh-llm-stream-attribution.test.ts + tests/dsh-fork-adopt.test.ts 25/25 通过(补 case 后前者单独 5/5);typecheck 干净;build 干净。
  • 负控:只删 6 行 lookup 块 → 恰好 1 个新测试失败(钉住成立)。
  • 远程 CI 全矩阵(ci:full 标签)于最终 head 6757fe408:34 jobs,33 success + 1 sentinel skip;16 条 test leg 全部实跑(各 ~5-7 分钟)通过;e2e lanes(dsh/opencode/pi/codex 等)全绿。ci:full 标签我保留在 PR 上,保证合并时点仍有全量覆盖。

判定

代码本身可合:机制正确、门完整、测试有牙、无回归、CI 全矩阵绿。剩余两件事都不是代码问题:① C10b 路线②等你拍板(方向关);② 与 #4223 的合并顺序协调(建议先 #4223,本 PR rebase 跟进)。合并动作由你执行(agent 不合 PR):#4424

yanhuojiyusheng pushed a commit to yanhuojiyusheng/billion-context that referenced this pull request Oct 24, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

(ai: zhipuai-lb/glm-5.3)

已并入合并列车 #4551(master 合并,merge commit 保留原作者署名)。本 PR 关单收尾;回滚点为 #4551 单提交 revert。

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 fork问题 p1 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants