Skip to content

fix: withhold prompt_cache_key stamp when OMP's Cowork transport bypasses fetch interception (#2583) - #2589

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-10_omp-cowork-pck-leak
Oct 11, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-10_omp-cowork-pck-leak

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #2583

What & why

The native OMP extension's prompt_cache_key stamping gate (stampPromptCacheKey, src/agent/pi.ts) assumed its native fetch-interception fallback covers every model request whose destination is not already proxied. That assumption broke when OMP introduced the Cowork transport (can1357/oh-my-pi 642892ae, proxy handling e22a5ff2): default anthropic / anthropic-messages requests are sent over node:https directly — never touching globalThis.fetch — unless an explicit proxy (PI_PROXY / PI_PROXY_ANTHROPIC) pushes them back onto Bun's fetch. On those requests the stamped prompt_cache_key rides verbatim into Anthropic's strict schema → HTTP 400 Extra inputs are not permitted on Anthropic subagent delegations (the reported Scout/Haiku failures; the issue's injected-field probe shows Opus is rejected too, so it is transport-shaped, not model-shaped).

Fix

A deterministic, evidence-permitlist predicate (ompCoworkTransportBypassesFetch, exported for tests) mirrors OMP's own egress selection exactly: provider === "anthropic" && api === "anthropic-messages" AND no effective PI_PROXY / PI_PROXY_ANTHROPIC. When it fires inside the stamping gate's NATIVE branch only, the stamp is withheld and a once-per-process-per-model warning explains that those requests go direct (uncompressed, invisible to the proxy). Missing provider/api fields cannot conclude bypass → today's optimistic stamp is kept (fail-safe toward #1579 for older hosts). Launcher lanes (/bili/ path, MITM whitelist), non-anthropic models and proxy-set hosts are untouched — they reach the proxy at the network layer regardless of transport.

Rationale for withholding rather than routing around it: the stamp's sole consumer is bili itself (identity bind + strip-before-forward, #1403/#1579). A mis-stamp is a guaranteed hard 400; a missed stamp degrades identity only (anonymous pfa session; compression still works server-side). #1403 set this trade explicitly.

Behavior changes (old → new)

  1. Native omp + recent OMP (≥ Cowork transport, post ~2026-08-21) + direct Anthropic, no PI_PROXY: was pck stamped → guaranteed HTTP 400 (Anthropic subagent delegation broken). Now unstamped → request succeeds direct; uncompressed and anonymous to the proxy; one-time loud warning per model.
  2. Native omp + OLD OMP (< ~2026-08-20, pre-Cowork) whose ctx.model carries provider/api: was stamped, routed, identity-bound. Now unstamped; bytes still route through globalThis.fetch so compression stays intact, but session identity degrades to anonymous prefix affinity (/acp-by-host-id lost; the racy pending-register binding may still catch the first request). Minor regression for machines still on pre-Cowork builds — disclosed per policy.
  3. Everything else (launcher lanes, MITM whitelist, non-anthropic models, PI_PROXY set): unchanged.

Config surface

None added. No new config fields, env vars or CLI flags — the predicate reads the host's own existing PI_PROXY* conventions and the model metadata the host already supplies.

Tests

  • tests/omp-native-identity.test.ts: 9 pre-existing cases unchanged + 7 new (regression case: anthropic-messages without proxy env → NOT stamped; PI_PROXY present → stamped; PI_PROXY_ANTHROPIC present → stamped; third-party relay with anthropic-messages api → stamped; non-anthropic-messages api → stamped; missing fields → optimistic stamp kept; predicate unit table). 16/16 pass locally.
  • Targeted local runs: plugin-agent 64/64, pi-native+omp-native 35/35, typecheck clean, build green. Full suite left to CI.

Boundary note (§7.3)

On OMP ≥ Cowork, direct Anthropic traffic is unreachable by bili in any mode — the true fix home is host-side (route Cowork egress through globalThis.fetch / allow custom fetch injection in oh-my-pi). Nothing is submitted cross-repo without owner approval; this PR ships the in-scope part only.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-10_omp-cowork-pck-leak (5ccb0fa)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2819-pr.2589.7854bac

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-pr2589.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 PR #2589(修 #2583)。CI 已全绿,按规范重点审代码与既有行为回归。稍后给结构化八问结论。

@ranxianglei
ranxianglei force-pushed the 2026-10-10_omp-cowork-pck-leak branch from 3fdda00 to 05f6560 Compare October 10, 2026 04:10
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成(rebased head 上验证)。结构化八问:

1. 是什么问题
native omp 插件的 prompt_cache_key 打戳闸门假设「fetch 层拦截覆盖所有模型请求」;OMP 新版 Cowork 传输下默认 anthropic/anthropic-messages 请求经 node:https 直发(不碰 globalThis.fetch),已打戳的字段原样进入 Anthropic 严格 schema → HTTP 400,Anthropic subagent delegation(Scout/Haiku)完全不可用。

2. 什么原因导致的
OMP 引入 Cowork 传输(642892ae,2026-07-30;代理处理 e22a5ff2,2026-08-21——两个日期我已对上游核实,文档引用准确):无 PI_PROXY*/PI_PROXY 时该传输直连。bili 打戳闸门只判断「目的地是否已路由到代理」,没判断「宿主出口是否真的经过 globalThis.fetch」——前提失效而闸门未跟随。

3. 影响范围与严重程度
native omp + 较新 OMP + 直连 Anthropic + 未设 PI_PROXY → 该类请求全部硬 400(subagent delegation 完全不可用)。launcher lane、MITM 白名单、非 anthropic 模型、设了代理的宿主均不受影响。

4. 怎么修复的
新增 evidence-permitlist 谓词 ompCoworkTransportBypassesFetch(导出供测试),镜像 OMP 自己的按模型出口选择;仅 NATIVE 分支命中时不打戳 + 每进程每模型一次警告。我逐行对照了 oh-my-pi main 源码验证镜像精确性:transport-fetch.ts 的 base 选择条件(provider==="anthropic" && api==="anthropic-messages")与谓词 model 条件一致;getProxyForProvider 的 JS-truthy env 语义与谓词的 length 检查一致;coworkFetch 在 init.proxy 存在时确实回落到 globalThis.fetch(即设代理=回到 bili 可拦截路径)。选「放弃打戳」而非绕路是正确的:戳的唯一消费者是 bili 自身(#1403),误打=必 400,漏打=仅身份退化(匿名 pfa,压缩照常)。

5. 是否有回归问题
逐项审过既有行为:launcher /bili/+MITM lane 不进 native 分支→仍打戳 ✓;非 anthropic provider/api→谓词 false→打戳 ✓;PI_PROXY* 已设→打戳且流量确实回 fetch ✓;缺 provider/api 字段→保留乐观打戳(面向旧宿主的 fail-safe)✓;master 大重构后 pck 消费端(server.ts strip-before-forward、session-id promotion)完好 ✓;与 master 新增 fork-adoption hook(#2399,同一 handler 内)交互:adoption 走自己的 HTTP origin,与模型请求传输无关,不受影响(pi-omp-fork-adopt 13/13 绿)✓。有意变更(PR 正文已披露):pre-Cowork 旧 OMP 且 ctx.model 带 provider/api 字段者失去身份绑定→匿名前缀亲和,轻微回归,披露合规。
review 新发现(已顺手修):原文档「mirrors … exactly」过强——NO_PROXY/no_proxy 命中模型 host 时会静默 OMP 的代理处理(shouldBypassProxy 先于 proxy init 生效,e22a5ff2 提交信息自证 "NO_PROXY targets stay direct"),即使 PI_PROXY* 已设→直发但已打戳→同类 400 残留窗口。已在 TECHNICAL-NOTES en/zh 补披露 + 规避方法(docs commit 05f656090)。另查了 whitespace-only PI_PROXY=" " 分歧(OMP raw-truthy 视为有代理 vs 谓词 trim 视为无):该配置下流量本身因无效代理 URL 必坏,分歧不可观测,无需动作。

6. 是否破坏缓存
不涉及。压缩/缓存路径零改动;那些直发请求本来就不经代理(无压缩、无 ledger 条目),修复前后状态一致,只是从「必然 400」变为「匿名 pfa 会话」。

7. 是否改了设计方向
没有。维持 #1403 既定取舍轴(宁漏勿错);真正修法在宿主侧(Cowork 出口走 globalThis.fetch/支持自定义 fetch 注入),PR 边界注记已写明,未做跨仓提交。

8. 是否引入了新的配置
没有。谓词只读宿主既有的 PI_PROXY* 约定与宿主已提供的 model metadata;无新 env/config/CLI 面。

验证记录:PR base(f2b84b6)落后 master 227 个提交→已 rebase 到当前 master(8e7bb12,hunks 逐字一致,rebase 干净);rebased head 上 typecheck clean、定向 lane 测试 116/116(omp-native-identity/plugin-agent/pi-native/omp-native)、fork-adopt 13/13、build green;旧 head CI 11/11 workflows 全绿。rebase + docs 修订已推回 PR 分支(新 head 05f656090),等其 CI 复跑。测试质量:回归 case 无修复必红、谓词单测表覆盖空串/whitespace 变体、env save/restore 无跨用例污染,断言有牙。

判定:可合。§7.4 触碰 identity/session-binding 逻辑(打戳闸门)→ 需人合,不能 auto-merge。建议合并前看一眼新 head 05f656090 的 CI;另见我在 #2583 留的关于 NO_PROXY 残留 facet 的处置问题(Closes 关键字会在合并时自动关单,残留已入 TECHNICAL-NOTES,是否接受由你定)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

冲突

@ranxianglei
ranxianglei force-pushed the 2026-10-10_omp-cowork-pck-leak branch from 05f6560 to 5ccb0fa Compare October 10, 2026 07:08
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 冲突已解,分支已更新到 5ccb0faa5(rebase 到当前 master 022e3f165)。

冲突来源:master 新合入的 #2469(fork-seed 判定,replayedMessageCount/FORK_SEED_MIN_REPLAYED_MESSAGES)与本 PR 的谓词(ompCoworkTransportBypassesFetch/noteOmpCoworkBypass)在 src/agent/pi.ts 同一空位插入模块级代码——纯插入位冲突,无语义交叠。其余 master delta(#2585 agent-providers、#2423 observability、#2566 lone-surrogate)与打戳闸门无交集。

解法:union——#2469 块在前、本 PR 块在后,两侧代码原样全保留,零内容取舍。已核对合并后区域结构完整(两函数各自闭合)。

rebased head 验证:typecheck clean;定向 lane 测试 138/138(omp-native-identity / plugin-agent / pi-native / omp-native / pi-omp-fork-adopt——最后这个专门覆盖与新 #2469 代码同文件共存的 fork-adoption 路径)。build 与 CI 交给新 head 复跑。

八问对照(相对上一轮 review 的增量):①问题不变;②原因不变;③影响面不变;④修法不变(仅插入位置随 union 调整);⑤回归——新增核查项:#2469/#2585 两块新代码与本 PR 语义无交互(fork adoption 走独立 HTTP origin,#2585 只动 provider 上报),既有行为结论维持上轮逐项结果;⑥缓存不涉及;⑦设计方向不变;⑧新配置不涉及。

判定维持:可合(人合,§7.4 identity-binding 域)。等 5ccb0faa5 的 CI 绿即可。

@ranxianglei
ranxianglei merged commit 5a6d9a7 into master Oct 11, 2026
25 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.265-master.5a6d9a7 (rolling master tag).

npm install -g billion-context@0.0.265-master.5a6d9a7  # 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.

[Bug] Anthropic requests leak prompt_cache_key when Cowork transport bypasses native fetch interception

1 participant