Skip to content

[PR] fix(omp): default PI_ANTHROPIC_MESSAGE_THREADS=0 so bili sees the full history - #6113

Closed
SajjadPSavoji wants to merge 0 commit into
ranxianglei:masterfrom
SajjadPSavoji:fix-6088-bug-omp-omp-18
Closed

SajjadPSavoji wants to merge 0 commit into
ranxianglei:masterfrom
SajjadPSavoji:fix-6088-bug-omp-omp-18

Conversation

@SajjadPSavoji

Copy link
Copy Markdown
Contributor

OMP 18.18+ sends official-URL Claude turns as Anthropic message threads, so after turn one each request carries only the newest message and bili never sees the conversation. PI_PROXY_ANTHROPIC leaves the model base URL official, so threads stay on and the session silently never compresses.

Added applyOmpMessageThreadsOff() in native-bootstrap.ts. It sets PI_ANTHROPIC_MESSAGE_THREADS=0 only when the var is unset or blank, so a user value still wins. It's called from the bili omp launcher branch and from the omp-native extension at load, under the same gate as the first-event-timeout stamp.

I also added anthropicBetaMessageThreads() in context-window.ts. handle.ts uses it to log one warning per session when an anthropic request carries a message-threads-* beta. It's keyed on the id before |sub:, so forks don't repeat it.

Tests: the bili omp launcher test in tests/launcher.test.ts now asserts the child env gets PI_ANTHROPIC_MESSAGE_THREADS=0. I ran tests/omp-native.test.ts (fails before the change, passes after), plus tests/model-windows.test.ts, tests/launcher.test.ts and npx tsc --noEmit -p tsconfig.json, all passing. The full suite was not run.

Fixes #6088

Generated with Claude Code (Claude Opus 5.5 and Claude Sonnet 5.5)

@ranxianglei ranxianglei changed the title fix(omp): default PI_ANTHROPIC_MESSAGE_THREADS=0 so bili sees the full history [PR] fix(omp): default PI_ANTHROPIC_MESSAGE_THREADS=0 so bili sees the full history Nov 10, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Duplicate screening: not a duplicate. Searched open+closed issues/PRs for PI_ANTHROPIC_MESSAGE_THREADS and message-threads: the only items touching this mechanism are source issue #6088 and this PR. Related-but-distinct: #3744 and the closed reforge bugs (#3569/#3579) cover Anthropic's Threads API shape (thread:{type:create|continue}, Claude Desktop) — a different wire shape from OMP's message-threads-2026-08-12 beta. Verified against master's src/server/threads-lane.ts: its detector keys on the body's thread.type, which OMP's threaded requests do not carry (the #6088 repro shows them arriving as plain 1–2-message requests forked into |sub: sessions). No other open fix targets this thread, and no parallel [PR] row exists.

Labels: bug / omp / scope/wiring / p1 — one-line reason: silent loss of bili's core compression promise for every OMP ≥18.18 session on the official Claude URL (core promise broken ⇒ p1 per the 2026-10-19 revision).

CI on head 92bb76b2 (verified live): all test shards green (ubuntu/windows × node 22/24), static-gates + mysql-contract green; e2e lanes skipped by path gate. Full diff/regression review in progress — verdict follows in this thread.

@ranxianglei ranxianglei added bug Something isn't working omp p1 scope/wiring labels Nov 10, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Verdict: APPROVE — mergeable (human merge; auto-merge gate not met by design: touches five src modules and changes a product default — §7.4 items 4/5).

Direction (source issue #6088). The report is well-evidenced (repro table: threads on → 1 request / 2 msgs / 2 |sub: forks; threads off → 3 requests / 6 msgs / 0 forks with 99% prefix-cache hit). The fix lands on the right layer: it sets OMP's own client-side switch (PI_ANTHROPIC_MESSAGE_THREADS) at exactly the two points where bili owns the process's model traffic — the bili omp launcher child env (src/launcher.ts:7150) and the omp-native extension module eval (src/agent/omp-native.ts:415) — instead of patching over delta-shaped requests downstream. Not a mask: the producer of the newest-message-only requests is OMP's per-request policy, and this restores full-history traffic, the shape bili's pipeline assumes. User-pinned values win in both places (blank counts as unset). The third piece — warn-once-per-base-session in src/server/handle.ts:1556 — turns any residual threaded session (other clients, or a user who deliberately pins threads on) from silent non-compression into an actionable log line, keyed before |sub: so persona forks don't repeat it (KDD #9).

Interaction with the existing threads lane. No conflict: src/server/threads-lane.ts (#2926) keys on the Threads API body shape (thread.type create/continue — Claude Desktop per #3744); OMP's message-threads-* beta rides plain /v1/messages bodies that lane never matches (the #6088 repro arrived as plain 1–2-message requests forked to |sub:). This PR keeps OMP traffic on the standard full-history path; the threads lane stays intact for clients without a switch.

Regression inventory (existing behaviors on touched paths).

  • bili omp launch env: previously unset → OMP ≥18.18 default (threads on for official-URL Claude). Now "0" unless pinned — intended, disclosed below. Side effects checked: no other consumer of this variable exists in the repo (zero hits on master); harmless no-op when OMP routes Claude through a non-official base URL (model policy wouldn't enable threads anyway).
  • omp-native module eval: same stamp under ompTrafficRidesBili + the NODE_TEST_CONTEXT guard — identical gate shape to the OMP native: preflight SSE comments do not reset 300s first-event timeout (Working → aborted) #1774 first-event-timeout stamp directly above it; never runs inside node:test.
  • handle.ts: purely additive warn-once block after session identity resolution; no effect on passthrough/artifact decisions. Set growth bounded to one short string per base session, matching the existing codexConfigWindowWarned precedent.
  • context-window.ts / server.ts: pure-function addition + re-export; sibling anthropicBetaContextWindow untouched, new parser mirrors its style exactly.
  • Tests: the launcher test saves/restores the variable around its case — no cross-test leakage.
    High-risk patterns walked: no fail-fast→swallow, no threshold/timing/output-format drift beyond the intended default plus the additive log line.

Tests. All three new tests are genuine red→green (on master they fail by construction: import of not-yet-existing exports / assertion on an unset child-env value). Local run on head 92bb76b2 just now: tests/omp-native.test.ts + tests/launcher.test.ts + tests/model-windows.test.ts → 401 pass / 0 fail / 1 skip. CI re-verified live before this verdict: head unchanged, zero non-green checks (all test shards ubuntu/windows × node 22/24 green, static-gates + mysql-contract green).

Two non-blocking observations (recorded as notes, no commits pushed):

  1. The warn-once dedup in handle.ts (base-id keying, fork suppression) has no direct test. It is log-only with zero functional impact, and pinning it would require exporting a _reset…ForTest hook from a hot file — disproportionate for observability code. Happy to add it if you want it.
  2. Native-lane in-process stamping relies on OMP reading process.env (Bun-unified with Bun.env) at request time — sound per the [Bug][omp] OMP ≥ 18.18 sends Claude turns as Anthropic message threads → bili omp and the omp native lane never compress (fix: PI_ANTHROPIC_MESSAGE_THREADS=0) | OMP 18.18 起 Claude 走 message threads,每轮只发最新一条 → bili omp 不压缩 #6088 source dive, unit-covered at helper level, but not integration-proven (the issue flagged it "untested"). Worst case degrades to pre-fix behavior plus the new warning. A post-merge smoke of the native lane on OMP ≥18.18 would close the gap.

结构化八问(中文)

  1. 是什么问题:OMP ≥18.18 把发往官方地址的 Claude 请求切到 Anthropic 服务端 message threads——每轮只发最新一条消息,历史留在上游,bili 永远看不到完整对话,会话静默地从不压缩(也不报错)。
  2. 什么原因导致的:根因在客户端侧——OMP 按请求读 PI_ANTHROPIC_MESSAGE_THREADS(未设时走模型策略:官方 base URL 即开 threads);bili 的 PI_PROXY_ANTHROPIC 路由不改变模型 base URL,所以策略照开。修复打在产生方(OMP 的请求形状决策点),不是下游打补丁。
  3. 影响范围与严重程度:所有经 bili 走官方 Claude URL 的 OMP ≥18.18 用户(bili omp launcher 与 omp-native 扩展两种用法都中招);长会话上下文只增不减直到撞窗口上限且全程无报错——核心承诺(压缩)静默失效,p1。
  4. 怎么修复的:在 bili 拥有进程模型流量的两个点(launcher 子进程 env、native 扩展模块加载时)把 PI_ANTHROPIC_MESSAGE_THREADS 默认为 "0",用户显式值优先(空白视同未设);另加一条按基础会话 id 去重的 warn 日志,让任何仍开 threads 的会话可见、可操作。
  5. 是否有回归问题:无意外回归。触碰路径既有行为逐项清点见上:唯一行为变更是本次目标默认值 + 一行纯增量 warn 日志;无 fail-fast 变吞错、无阈值/时序/输出格式漂移;与既有 threads lane([Tracking] SQLite-backed threads-lane compression (endgame for the #2884 cap) #2926,Threads API 形状/Claude Desktop)线形不同、互不干扰。
  6. 是否破坏缓存:不影响 bili 自身缓存/重试/游标;上游前缀缓存反而改善(issue 实测 threads off 后 99% cache hit,每轮重发同一前缀)。
  7. 是否改了设计方向:没有。OMP 流量回到标准全量历史压缩路径(而非扩展 threads lane 适配 delta 形状),与原 issue 判断一致(OMP 有现成客户端开关,不需要 threads lane);threads lane 保留给没有开关的客户端。
  8. 是否引入了新的配置:bili 自身零新配置(无新 BILI_* env、无 config key)。仅在 bili 拥有的进程 env 里写 OMP 自家的变量 PI_ANTHROPIC_MESSAGE_THREADS(与 OMP native: preflight SSE comments do not reset 300s first-event timeout (Working → aborted) #1774 first-event timeout、PI_PROXY_ANTHROPIC 先例同类);想保留 threads 的用户自己导出该变量即可覆盖。

行为变更披露(旧→新):bili omp 及 omp-native 模式下未显式设置该变量的用户——旧 = OMP ≥18.18 默认开 threads(官方 URL),每轮仅最新消息入 bili,永不压缩;新 = 默认 "0",每轮全量历史入 bili,正常压缩 + 正常前缀缓存。原因:恢复 bili 可见性这一核心前提。另新增一条每基础会话一次的 warn 日志。

判定:可合并(人工合并)。两条非阻塞观察已列上方,不构成合并障碍。

@ranxianglei

Copy link
Copy Markdown
Owner

conflicts

@SajjadPSavoji

Copy link
Copy Markdown
Contributor Author

merged master in, it's clean again now

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

The merge conflict is already cleared — the PR is now mergeable: true. What happened and what I verified this run:

Why it was dirty: the branch was based on an old master (4dea18e) that had drifted ~5150 commits behind current master (58a8796), so it conflicted on the same regions master had since rewritten.

What I did (independent verification): I reproduced the exact same merge locally — same two parents (92bb76b + 58a8796). Only two textual conflicts, both resolved by keeping BOTH sides' independent additions:

  • src/agent/omp-native.ts — import union: kept the PR's applyOmpMessageThreadsOff plus master's setDeclaredModelEndpoints / ../model-endpoints.js import.
  • src/server/handle.ts — adjacent module-level consts: kept the PR's messageThreadsWarned alongside master's WEAK_ADOPT_MIN_PREFIX_RATIO.

Then I validated the result: typecheck clean, full build clean, and the three PR-touched suites (omp-native, model-windows, launcher) — 401/401 pass. A full-tree diff confirms my merge and the author's ccdea23919 are byte-identical (same two parents, zero diff), so that local green applies directly to the live branch.

Nothing pushed. The author had already pushed ccdea23919 ("Merge branch 'master' into fix-6088-bug-omp-omp-18") while I was working, resolving the same conflicts identically. Pushing my copy would be redundant and would fight for a branch the author is actively maintaining — so I left ccdea23919 as the head.

Live CI (head ccdea23919): fast gates already green (static-gates/ubuntu, mysql-contract, gate); the e2e/hermetic lanes are correctly skipped (their env gates aren't set for a normal PR); the multi-shard test matrix (windows/ubuntu × node 22/24) is still in-progress/queued with no failures so far. I can't call it green yet — I'm staying on hook to fix any red that lands in this run's scope.

七问

  1. 是什么问题:PR 分支基线过旧(落后 master 约 5150 个提交),与当前 master 冲突(merge state: dirty)。
  2. 什么原因导致的:master 在 omp-native.ts、handle.ts 的同一区域有独立改动,与 PR 的新增行撞在同一位置,产生两处文本冲突。
  3. 影响范围与严重程度:仅阻塞合并流程本身,不影响任何运行行为;属合并/同步问题,不是代码缺陷。
  4. 怎么修复的:把当前 master 合入 PR 头分支;两处冲突都按「两侧独立改动同时保留」解(import 取并集、两个模块级常量并存)。作者已自行完成同样的合并(ccdea23919)。
  5. 是否有回归问题:无。我对字节级相同的树本地跑了 typecheck + build + 401 个定向测试全绿;master 侧改动本身已由 master 的 CI 覆盖。
  6. 是否破坏缓存:不涉及——本次只解决合并冲突,未改动任何运行时逻辑、阈值或时序。
  7. 是否改了设计方向 / 引入新配置:本次冲突处理不涉及。注:PR 自身会默认设 PI_ANTHROPIC_MESSAGE_THREADS=0(仅当该变量未设置或为空时,用户显式值仍优先),这是该 PR 声明的功能意图,已在 PR 描述中披露,非本次冲突处理引入。

结论:冲突已解除(mergeable: true),无需要我推送的内容;CI 在新头 ccdea23919 上运行中、暂无失败。若后续 test 矩阵出现红,我来跟进修复。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

ranxianglei pushed a commit to SajjadPSavoji/billion-context that referenced this pull request Nov 13, 2026
Resolve the src/server/handle.ts conflict from master drift (ranxianglei#6113 round 2).
Master added the ranxianglei#6220 BILI_PLUGIN_BYPASS warn-once flags at the same
module-level spot the PR added its ranxianglei#6088 messageThreadsWarned set; keep both
(independent declarations, no interaction).
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Resolved and pushed. This time the conflict was real — both sides had moved since the author's earlier merge:

  • master advanced 58a8796 → a007974683
  • the author added a docs-only commit on top: ccdea23919 → 4c96dc14f2 ("docs(omp): document exported PI_ANTHROPIC_MESSAGE_THREADS default")

Where it conflicted: src/server/handle.ts. Master's #6220 change inserted its BILI_PLUGIN_BYPASS warn-once flags (bypassOverrideOnWarned/bypassOverrideOffWarned) at the exact module-level spot the PR had put its #6088 messageThreadsWarned set. Two independent declarations, same line → textual conflict.

How I resolved it: kept both (they don't interact). Then validated the merged tree locally: typecheck clean, full build clean, and the three PR-touched suites (omp-native, model-windows, launcher) — 401/401 pass.

Push: merge commit 6c4db56015 (parents 4c96dc14f2 + a007974683) pushed to the branch as a clean fast-forward — I re-fetched first and the author had not moved it, so no force-push was needed.

Live state now: mergeable: true (was dirty); mergeable_state: blocked only because CI checks are still running on the new head. I'm on hook for any red that lands.

七问

  1. 是什么问题:PR 与 master 再次冲突(dirty)——不是上次的陈旧快照,这次是真冲突。
  2. 什么原因导致的:自作者上次合并后,master 前进了(58a8796→a007974683),作者在分支上又加了一个 docs 提交(4c96dc14f2);master 的 x-bili-plugin-bypass: 1 Allow forced specification | x-bili-plugin-bypass: 1 允许强制指定 #6220 改动与 PR 的 [Bug][omp] OMP ≥ 18.18 sends Claude turns as Anthropic message threads → bili omp and the omp native lane never compress (fix: PI_ANTHROPIC_MESSAGE_THREADS=0) | OMP 18.18 起 Claude 走 message threads,每轮只发最新一条 → bili omp 不压缩 #6088 改动都在 handle.ts 同一模块级位置插入声明,撞车。
  3. 影响范围与严重程度:仅阻塞合并流程,不影响运行行为;属合并/同步问题。
  4. 怎么修复的:把当前 master 合入 PR 头分支,handle.ts 冲突按「两侧独立声明都保留」解(messageThreadsWarned 与 bypassOverride* 并存,互不交互);本地 typecheck+build+401 定向测试全绿后推送。
  5. 是否有回归问题:无。合并只做了声明并集,未改动任何运行逻辑;master 侧改动本身已由 master CI 覆盖。
  6. 是否破坏缓存:不涉及——纯合并冲突解决,未改任何运行时逻辑/阈值/时序。
  7. 是否改了设计方向/引入新配置:本次冲突处理不涉及。(注:master 侧 x-bili-plugin-bypass: 1 Allow forced specification | x-bili-plugin-bypass: 1 允许强制指定 #6220 引入了 BILI_PLUGIN_BYPASS 的 on/off 强制开关,那是 master 已有功能,非本次引入;PR 自身的 PI_ANTHROPIC_MESSAGE_THREADS=0 默认值仍是该 PR 声明的功能意图。)

结论:冲突已解除并推送(mergeable: true),CI 在新头 6c4db56015 上运行中。若 test 矩阵出现红,我来跟进。

ranxianglei pushed a commit to SajjadPSavoji/billion-context that referenced this pull request Nov 13, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI red triaged and resolved as far as this lane can take it — all 4 failing shards are inherited/known, none caused by this PR. Synced the branch to the latest master and reported to #4599.

What was red (run 43436720968, head 6c4db56):

  • 3 shards (ubuntu-22-3, ubuntu-24-3, windows-22-3) + 2 subtests inside windows-22-2 = tests/notice-registry.test.ts (storage-sqlite-default missing from visibleNotices()).
  • 10 subtests inside windows-22-2 = storage tests (BILI_PERSIST_ZSTD / BILIENC1 / legacy-plaintext / fzstd) — Windows-only.

Root cause (both confirmed via #4599, same signatures as PRs #6429/#6435):

  1. notice-registry (inherited master red): the storage-sqlite-default notice (brand-new master feature, [PR] storage: pure-SQLite default — JSON envelopes stop being written unless dual-write is requested (#6479) #6480) is gated by sqliteDefaultNoticeActive (src/notices.ts:82), which requires unifiedSelectionIsSqlite. In CI, storage resolves to full mode (BILI_STORAGE_UNIFIED=full), and the hermetic test doesn't pin/unset the storage env vars → notice hidden → assertion fails. Local: clean env 5/5 green, BILI_STORAGE_UNIFIED=full → 2 red (byte-identical to CI). This PR (omp PI_ANTHROPIC_MESSAGE_THREADS=0) has zero intersection with notices/storage.
  2. storage tests (Windows file-lock flake): EBUSY: resource busy or locked, unlink '...index.db' — the known windows-node22 file-lock family (CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 floor 1307); clears on re-run.

Action taken:

八问(中文):

  1. 是什么问题:PR head 4 个 test 分片红——notice-registry 的 storage-sqlite-default 公告缺失(4 分片共 8 例)+ windows-22-2 的 10 例存储测试(BILI_PERSIST_ZSTD / BILIENC1 / legacy / fzstd)。
  2. 什么原因导致的:两类均非本 PR 引入——① notice-registry 是继承性 master 红:[PR] storage: pure-SQLite default — JSON envelopes stop being written unless dual-write is requested (#6479) #6480 新增公告由 sqliteDefaultNoticeActive(src/notices.ts:82)门控要求 unifiedSelectionIsSqlite,CI 环境 BILI_STORAGE_UNIFIED=full 使门为假,hermetic 测试未 pin 存储 env 变量 → 公告不显示;本 PR(omp message-threads)与 notices/storage 零交集。② 存储测试是 windows-node22 文件锁 flake(EBUSY unlink index.db),在档族,重跑即绿。
  3. 影响范围与严重程度:仅 CI 红(挡合并),非功能回归;本 PR 功能(omp 全历史)不受影响;master 侧 notice 测试 born-red([PR] storage: pure-SQLite default — JSON envelopes stop being written unless dual-write is requested (#6479) #6480 落 master 后),只在 PR head 全矩阵显形。
  4. 怎么修复的:本分支不夹带 master 级修复——已 merge 最新 master(e1f31ad)同步基线,新 head 3bff4d1;notice 测试的 hermetic 修复(pin/unset 存储 env)按 CI 协调政策收敛到 ci-fixes(哨兵),已在 CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599(floor 1305/1307)请求;存储 flake 重跑即绿,无需改码。
  5. 是否有回归问题:无——merge 只加入 master 的 persist.ts + bounded-boot 测试,本 PR 功能(messageThreadsWarned / applyOmpMessageThreadsOff)逐字节保留,无既有行为变更。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

判定:本 PR 的 4 个红分片全部为继承红 + 在档 flake,非本 PR 引入;已同步到最新 master 并推送(3bff4d1)。notice 测试的根治等哨兵在 ci-fixes 收敛后本 PR 应转绿;存储 flake 重跑即清。

@ranxianglei

Copy link
Copy Markdown
Owner

Landed via batch PR #6482 (merged) — closing as superseded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants