Repository navigation
fix: prime pi/omp manifest fetch at load time so -p round 1 carries plugin headers (#1217) - #1222
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1222Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1222.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review 进行中,先报两个已确认的发现(最终结论稍后补): ① 发现并修复了 CI 红灯(windows-latest, Node 22) ② base 过期,已 rebase 到当前 master ( 方向性审核结论(初步):根因定位正确(-p 首请求与异步 manifest fetch 的竞态),priming 方案正确且两个被否方案(gate 放宽 / header hook 内 await)的否决理由成立。回归清点、测试有效性、diff 整洁度的完整结论等 rebase+修复后的全量验证跑完即发。 |
ac67d76 to
6b83de5
Compare
[bot] 🏷 Review 完成,结论:可以合并(CI 已全绿;合并按仓库规则由人工操作)。以下是完整审核记录。 ① 原 issue 方向关(#1217)— 通过根因定位正确: ② 回归审查(既有行为逐项清点)
③ 代码审查
④ 测试有效性
⑤ 我在 PR 分支上的两处干预(均已推送,head =
|
[bot] 🏷 收到,顺序确认:先合 #1228(await 硬串行化保正确性),本 PR rebase 后作为加载时预热的延迟优化跟进(对 omp 有独立价值——omp 不发 我已对着 #1228 的 head(
一个刻意不做的事:我不会提前 rebase 到 #1228 的 head 上——那会把它的未合并 commit 卷进本 PR 的 当前状态:本分支 |
|
冲突 |
[bot] 🏷 收到——是的,#1228/#1229 先后落 master 后本 PR 的 base( |
6b83de5 to
502c6b8
Compare
[bot] 🏷 Rebase 完成,CI 全绿,PR body 已更新——可以合并了(合并按仓库规则由人工操作)。 做了什么(head
验证证据(head
一句话中文:已按「先 #1228 后本 PR」的顺序把分支 rebase 到最新 master,把两处测试适配到 await 硬串行化的新语义并 squash 成单 commit,本地全套与 GitHub CI 8/8 全绿,PR body 已改定位为延迟优化+omp 覆盖,可以合并。 |
Problem (#1217)
pi -p(single-shot) sends its first model request without anyx-bili-plugin*headers: the header-stamp gate insrc/agent/pi.tsrequirestoolsReady === true, but tool registration only started an async manifest fetch atsession_start. In-pmode round 1 fires within milliseconds of startup — before the fetch resolves — so the request lands in proxy mode bound to an anonymouspfa-session instead of plugin mode. TUI mode wins the race because user typing gives the fetch seconds.Reproduced with real pi 0.83.6 through a local proxy (baseline log):
Division of labor with #1228 (merged)
Per owner decision (#1222 thread), this PR is sequenced after #1228:
5792e3cd) supplies correctness under any latency: thebefore_provider_headershandler now awaits tool registration, so pi's-pround 1 always carries the plugin marker regardless of fetch speed.before_provider_headers, so fix: pi one-shot (-p) first request claims plugin mode — await tool registration before header stamp #1228 cannot reach it — gets itstoolsReadyflip (and thus the identity-register that binds the conversation into plugin mode) ahead of its first request. Complementary, not competing.Fix
Prime the manifest fetch at extension load time (
createBiliPluginfactory): whenBILLION_CONTEXT_PROXYis set (launcher mode always sets it before spawning the client, after health-checking the proxy), startfetchManifest()immediately and store the promise onRegisterState.registerToolsconsumes it once (same-origin guard); a failed prime resolves toundefinedand falls through to the existing event-time fetch + retry-throttle path unchanged. The ownership gate itself is untouched — it still refuses to claim plugin mode without registered tools, preserving the graceful wire-mode fallback for permanently failing manifests.Why priming instead of relaxing the gate: stamping unconditionally would create a tool-less plugin-mode session (sticky, never downgraded) whenever the manifest fetch fails — strictly worse than today's fallback. Why not rely solely on #1228's await: correct, but it moves the manifest RTT onto the first request's critical path for every launcher session, and it covers no client without an awaitable header hook (omp).
Residual: if the manifest fetch is slower than the load→round-1 gap, pi is still covered by #1228's await (only the latency benefit is lost); omp may still miss round 1 in that case — strictly no worse than pre-fix. Native mode (
pi-native) setsBILLION_CONTEXT_PROXYonly after async bootstrap (#519), so no prime exists there and round 1 stays on wire mode (unchanged residual).Behavior disclosure (OLD → NEW)
Layered on merged #1228:
-pround 1-pfirst requesttoolsReadyBILLION_CONTEXT_PLUGIN=0detectProxyBase→ undefined → no prime)Proxy side untouched. No config schema, persistence, or version changes.
Tests (all deterministic — arrival-based, no wall-clock margins)
src/agent/pi.ts(test fails without the prime).BILLION_CONTEXT_PLUGIN=0keeps the plugin fully inert at load time (zero manifest requests).An earlier revision of test 2 used fixed flush intervals to detect settlement and flaked on slow Windows runners (in-flight fallback fetch crossed the assertion boundary); it is now driven by observed request arrival + deadline-bounded polling.
Pre-flight (head
502c6b87, rebased onto masterdb52a965)npm run typecheck✅ ·npm run build✅origin/master(machine-local environment, unrelated to this diff)tests/plugin-agent.test.ts: 50/50 across 5 consecutive runssrc/agent/pi.ts(kept fix: pi one-shot (-p) first request claims plugin mode — await tool registration before header stamp #1228's wording + this PR's priming sentence); two tests adapted to the awaited-claim semantics above; squashed to a single commit.