Skip to content

fix: pi-subagent-registry fake stores per-event handler arrays (#2234) - #2235

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-06_pi-registry-fake-handler-arrays
Oct 6, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-06_pi-registry-fake-handler-arrays

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #2234.

Root cause

Classic #517-style semantic merge conflict: #2209 (selfRegisterForSession in pi.ts session_start + tests/pi-subagent-registry.test.ts) branched from e5a0066 — before #2186's wirePiSubagents landed. Each PR was green alone; on merged master the factory registers TWO session_start handlers (pi.ts's selfRegister first, the subagents wiring's second). The test's fake pi stored handlers in a Map keyed by event — last registration wins — so the wiring handler shadowed selfRegister and registry().bySession never filled: AssertionError: entry present after session_start (tests/pi-subagent-registry.test.ts:275). Master HEAD bd33b11 is red on all four test jobs; every open PR inherits it.

The real pi host awaits a per-event handler ARRAY in registration order (pi-coding-agent dist/core/extensions/runner.js emit(): for (const handler of handlers)) — production runs both handlers; only the fake was wrong. Same defect class as the issue2072 fake fixed earlier (tests/issue2072-native-caller-stamping.test.ts).

Fix (test-only, zero src change)

  • makeFakePi events: Map<string, FakePiHandler[]>, on() appends.
  • New firePiEvent helper awaits every handler in order (the runner's emit contract).
  • Both factory tests converted to firePiEvent; the presence assert checks non-empty arrays.

Tests

  • tests/pi-subagent-registry.test.ts: 10/10 green (was 9 pass / 1 fail on master HEAD).
  • tests/pi-subagents-wiring.test.ts: 14/14 (unaffected).
  • typecheck green. Full matrix in CI.

The fake pi keyed handlers by event in a Map (last registration wins),
but the real pi host awaits a per-event handler ARRAY in registration
order (pi-coding-agent runner.js emit). On post-#2186+#2209 master,
pi.ts's selfRegister session_start handler is registered before
wirePiSubagents' wiring handler, so the Map kept only the wiring handler
and the factory test lost its bySession entry. Same defect class as the
issue2072 fake fixed earlier.
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-06_pi-registry-fake-handler-arrays (782bb22)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2305-pr.2235.ea6f493

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-pr2235.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

[bot] 🏷 Review of PR #2235 (fixes #2234) — done. All claims verified locally against live master and the pinned pi host package.

结构化七问

  1. 是什么问题:feat(pi): deterministic bili loading for pi-subagents children — required-extension self-registration (Plan A) #2209(selfRegisterForSession)与 [pi] 内置 billion-context-pi-subagents(acp_delegate)进 Pi lane:官方自有 subagents 支持 #2186(wirePiSubagents)先后合入后,pi 工厂对 session_start 注册了两个 handler;而测试的 fake pi 用按事件名做 key 的 Map(后注册覆盖先注册),wiring handler 把 selfRegister 影子掉了,工厂测试红掉,连带 master 全部 4 个 test job 变红。
  2. 什么原因导致的:典型 fix: reject stale in-memory snapshots that would roll back persisted session state (#405) #517 类语义合并冲突——两个 PR 各自单独都是绿的,合入后注册次数翻倍。缺陷在测试 fake 的数据结构(每事件单 handler),与真实宿主契约不符;生产代码本身是对的。
  3. 怎么修复的:把 fake 对齐真实宿主契约——makeFakePi 改为 Map<string, FakePiHandler[]>,on() append;新增 firePiEvent 按注册顺序逐个 await(镜像 runner 的 emit 语义);两个工厂测试改用 firePiEvent,存在性断言改查非空数组。零 src 变更。
  4. 是否有回归问题:无。diff 只碰 tests/pi-subagent-registry.test.ts(+27/−9),不碰 src/wire/config/persistence。同类 fake 清点:tests/plugin-agent.test.ts:210 早已用链式合成处理多 handler(不受影响);tests/pi-subagents-wiring.test.ts 的 fake 虽也是 last-write-wins,但该文件每个事件只注册一次、无影子路径(实测全绿)。
  5. 是否破坏缓存:不涉及(test-only)。
  6. 是否改了设计方向:没有,反而是把 fake 拉向真实契约。已对照钉住的 devDep @earendil-works/pi-coding-agent@0.83.0 验证:dist/core/extensions/loader.js:192-193 push 进 per-event 数组,runner.js emit 为 for (const handler of handlers) 逐个 await,注释明言单扩展可注册多 handler——生产跑两个 handler 属实,只有 fake 错了。执行顺序(pi.ts 的 selfRegister 先、wiring 后)也与真实宿主一致。
  7. 是否引入了新的配置:不涉及。

验证证据

  • master HEAD bd33b11d9 本地复现红:tests/pi-subagent-registry.test.ts 9 pass / 1 fail,AssertionError @ :275("entry present after session_start")——与 issue 描述逐字吻合。
  • PR 分支(782bb22e9,base = 当前 master,单提交,mergeable):pi-subagent-registry 10/10 绿、pi-subagents-wiring 9/9 绿、typecheck 干净。
  • CI:head 提交 21/21 check-run 全绿,含 ubuntu/windows × node 22/24 四个 test matrix job。
  • 回归测试有效性:断言有牙——若有人把 fake 退回 Map.set,selfRegister 再次被影子、bySession 为空,该测试必然再红。

小 nit(不阻断):PR 描述写 "tests/pi-subagents-wiring.test.ts: 14/14",实际该文件是 9 个顶层测试(全过)。数字笔误,代码无碍。

判定:可合并(merge 留给人)。

@ranxianglei
ranxianglei merged commit ebe7a5e into master Oct 6, 2026
21 checks passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.68-master.ebe7a5e (rolling master tag).

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

Development

Successfully merging this pull request may close these issues.

master red: pi-subagent-registry factory test broken by #2209 + #2186 semantic merge (fake pi Map shadows selfRegister handler)

1 participant