Skip to content

fix: size OMP native windows from conversation-scoped runtime-info (#1531) - #1532

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-28_omp-runtime-info-window
Sep 28, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-28_omp-runtime-info-window

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1531

What was wrong (all four claims verified on master v0.1.163)

  1. Header-only runtime lookup (src/server.ts:1423): window selection consulted the runtime-info table with the request's x-bili-plugin header agent only. OMP native sends no such header on model requests (it binds via identity register + prompt_cache_key stamping; omp has no per-request header event surface — [native] omp: three-mode alignment (proxy / launcher / native plugin) + runtime-info #957), so reported contextWindow was silently ignored → registry-peek fallback (the issue's 922000). The maxOutput headroom fallback had the same header-only lookup.
  2. One slot per agent (src/plugin.ts): pluginRuntimeTable kept a single entry per agent name, so a sub-agent session's report clobbered the main session's entry (and vice versa) even though both run different models/windows under the same agent name omp.
  3. Model-id-only client dedup (src/agent/shared.ts): reportRuntimeInfoOnChange skipped re-reporting whenever the model id was unchanged, suppressing corrective reports after config changes (window/baseURL/maxOutput), across proxy origins, and across sibling sessions sharing one process's module-level cache.
  4. Cold-start race: the OMP first-request report was fire-and-forget with no origin waiter registered for the omp lane, so it could be skipped or land after dispatch.

Changes

  • src/plugin.ts: new per-conversation runtime table keyed by conversationId (model-gated lookup, same cap/eviction); handler records optional conversationId; /status runtimeInfo + pre-first-request probe fall back to it.
  • src/server.ts: strict dual lookup at window selection AND the maxOutput fallback — x-bili-plugin present → per-agent entry only (byte-identical to today); absent → conversation-scoped entry keyed by the same session signals used for binding (client conversation header, custom session header, body prompt_cache_key). A miss there degrades to exactly today's legacy resolution — it can never produce a wrong hit.
  • src/agent/shared.ts: dedup now keys on (agent, conversation) with a full-field fingerprint including proxy origin; re-reports on any reported-config change; async never-rejecting with rollback-on-failure.
  • src/agent/pi.ts: the OMP report awaits bounded proxy-origin readiness (≤15 s), includes conversationId, and is awaited in before_provider_request so it lands before dispatch (worst-case hold ~20 s < omp's ~30 s handler guardrail; mirrors pi's Native pi one-shot (-p): first request races the proxy bootstrap — x-bili-plugin never stamped, session binds anonymous wire mode #1243 behavior).
  • src/agent/omp-native.ts: registers the native origin waiter, like pi-native does.
  • TECHNICAL-NOTES en/zh: document conversationId + the per-agent vs conversation-scoped resolution semantics.
  • Tests: conv-scoped storage/lookup/model-mismatch/eviction/handler-parse/signal-precedence units; e2e regressions (header-less pck-identity adoption → runtime-info source with exact contextLimit; A/B/A no-clobber; per-agent header wins exclusively; plain-client compat unchanged); dedup fingerprint units; the [native] omp: three-mode alignment (proxy / launcher / native plugin) + runtime-info #957 test now asserts conversationId in the report body and that the report lands before dispatch.

Behavior changes (old → new)

  1. OMP native window sizing: previously the reported contextWindow/maxOutput were ignored (registry-peek, e.g. 922000 in the issue setup); now adopted at the runtime-info rank (e.g. 258400 − min(128000, 25%) = 193800). Compression/nudge cadence becomes much more aggressive for correctly-sized small windows — this is the intended fix.
  2. Client runtime-info dedup: per-agent model-id-only → per-(agent, conversation) full-field fingerprint scoped by proxy origin. The pi/opencode lanes now also re-report when contextWindow/maxOutput/baseURL/proxy origin changes (previously only on model-id change) — extra loopback admin POSTs, negligible cost.
  3. Main/sub-agent isolation: per-conversation entries no longer clobber each other.
  4. OMP cold-start first request: now waits for proxy-origin readiness (≤15 s) + the awaited report POST (≤5 s) before dispatch (previously fire-and-forget race). Bounded; mirrors pi.

Activation boundary: the conversation-scoped lookup fires on exactly the signals session binding already uses — wherever OMP native binds its session today, window adoption now works there; where no binding signal exists (e.g. Responses-API-shaped bodies are not pck-stamped), behavior stays at today's legacy resolution (no regression).

No config-surface change (no new config fields / env vars / CLI flags). Both compression modes considered: the window cascade is mode-agnostic; plain clients are unaffected (covered by the e2e compat test).

Pre-flight on current master (86e0b68): typecheck clean · npm test 3015 pass / 0 fail · build OK.

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-28_omp-runtime-info-window (ceff209)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1479-pr.1532.ad2296f

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-pr1532.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] 🏷 收到,开始审查 PR #1532(fix OMP native 窗口尺寸来自 conversation-scoped runtime-info)。正在拉取分支、核对原 issue #1531 的四个论断、检查 CI 状态并做回归审查,结论稍后在本线程给出。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — mergeable. Verified branch pr-1532 (single commit 3e819de4 on current master 86e0b684), reviewed the full diff against both compression modes, ran local checks, and confirmed CI. Findings per review order:

① Original issue direction — correct, root-cause level

Issue #1531's four claims were already triage-verified against master v0.1.163. The PR fixes each at its decision point, not at the symptom:

  • Lookup key: the producer of "reported window ignored" was server.ts consulting the runtime-info table only through x-bili-plugin ([Bug][OMP native][0.1.163] contextWindow 上报后仍使用 registry 窗口,runtime-info 存在跨会话覆盖 #1531 RC1). Fix is a strict dual lookup at the cascade slot (src/server.ts:1423-1431): header present → the exact old call, byte-identical; header absent → resolve the conversation-scoped entry via the same conversation signal the session binds on (runtimeConversationId: client conversation header > custom session header > body prompt_cache_key) with the model-match gate retained.
  • Storage clobber (RC2): reports carrying a conversationId go to a separate pluginRuntimeByConversation table; the agent slot stays untouched — main vs subagent sessions sharing agent name omp can no longer evict each other's windows.
  • Dedup staleness (RC3): fingerprint widened from model-id to full-field [proxyBase, agent, conversationId, model, contextWindow, maxOutput, baseURL], keyed per (agent, conversation) — sibling sessions and config edits now re-report.
  • Cold-start race (RC4): the OMP before_provider_request handler now awaits the report before dispatch, with the origin wait made bounded (readyOrigin races state.ready against readyTimeoutMs ?? 15000; non-native hosts have no waiter registered and resolve immediately). Worst hold ≈ 15 s + one loopback POST ≈ 20 s < omp's ~30 s handler guardrail; failure soft-fails to legacy resolution, so a dead report can never break a model request (same semantics as the old fire-and-forget).

The key consistency invariant holds end-to-end: report conversationId = wire-stamped prompt_cache_key = sessionIdOf(ctx), all three the same value (verified in stampPromptCacheKey and reportOmpRuntimeInfo). Chat-completions-shaped bodies get stamped; Responses-shaped bodies (p.input) don't, so those requests miss the conv table and ride legacy resolution — exactly the declared activation boundary.

② Regression audit — existing behaviors inventoried

Touched path Verdict
Header-present window/maxOutput lookups (x-bili-plugin clients: pi/opencode/dsh/kimi/hermes) Preserved — identical call, identical precedence slot in the cascade
recordPluginRuntimeInfo for callers without conversationId (opencode-native.ts:631, opencode-v2.ts:217, pi.ts:700) Preserved — agent table, same 32-entry eviction; caller audit confirms only the OMP path passes a conv id
Header-absent requests (plain clients) Strictly additive — old code passed undefined agent → always missed → legacy resolution; a hit now requires a matching conv-scoped entry (only created by a real plugin report for that conversation) AND model match. Miss ⇒ today's behavior. Wrong-hit impossible
/status probes Additive fallback only — agent table first, conv table second; conversationIdForSession maps to resident session ids, misses degrade to null
pi/opencode re-report cadence Intended change, disclosed — see below (§behavior)
First OMP request latency Intended change, disclosed — bounded wait, soft-fail
Compression-mode invariants Both modes reasoned: the change selects which source sizes the window/nudge denominator; no injection/suppression/system-message handling touched
Config surface Untouched — no new config fields/env vars/CLI flags; conversationId is an internal plugin↔proxy protocol field

No fail-fast→swallow drift, no threshold/timing/output-format drift beyond the two disclosed items.

③ Code review

Clean. No as any/@ts-ignore; the new console.error sits in src/agent/pi.ts (client-side plugin file — allowed; server-side ban respected). Rollback-on-failure (delete(key)) keeps the dedup cache honest so a failed report retries next round. setNativeOriginWaiter in omp-native.ts is gated by the exact NODE_TEST_CONTEXT === undefined && nativeActive condition as bootstrap — zero test interference. Eviction helper shared by both tables, cap 32 each.

④ Test effectiveness — real teeth

New tests/runtime-info.test.ts (198 lines): exact-value assertions, A/B/A no-clobber, eviction survivors (sid-39/a39), negative gates (numeric pck rejected, x-bili-plugin-conversation alone correctly unused, agent slot stays empty when convId given), dedup fingerprint branches incl. failed-report rollback and proxy-origin switch, plus a real end-to-end case through the live server asserting windowSource === "runtime-info" via the header-less pck path — i.e., the exact regression this bug was (pre-fix it would have resolved to the registry value). The pre-existing #957 unit test was strengthened: polling replaced by a direct ordering assertion (report lands before dispatch) plus conversationId in the expected payload. The changed behavior is pinned.

⑤ Diff cleanliness

9 files, +353/−42, single linear commit on current master. Every file serves the fix: the five source paths, their tests, and TECHNICAL-NOTES en+zh (kept in sync, accurately describing the dual-table resolution and its #1531 rationale). No unrelated churn, no lockfile/version changes.

Behavior changes (confirmed accurate as disclosed in the PR body)

  1. OMP native (chat-completions shape): reported contextWindow/maxOutput now adopted — old: silently ignored (registry fallback, e.g. 922000 instead of 193800 in the [Bug][OMP native][0.1.163] contextWindow 上报后仍使用 registry 窗口,runtime-info 存在跨会话覆盖 #1531 repro) → new: conversation-scoped runtime-info entry wins. This is the fix itself.
  2. pi/opencode lanes re-report on any reported-field change (was: model-id change only) — extra loopback admin POSTs, negligible cost.
  3. Storage split: one 32-slot agent table → agent table (32) + conversation table (32).
  4. First OMP model request may block up to ~20 s on proxy-origin readiness (bounded, soft-fails to legacy).

Verification evidence

  • Local on pr-1532: npm ci clean; npm run typecheck clean; npm test → 3027 tests, 3015 pass, 0 fail, 12 skipped; npm run build success.
  • CI on head 3e819de4: 13/13 check runs green (unit matrix ubuntu/windows × node 22/24, e2e, hermetic registry e2e, real pi/dsh/opencode/codex lanes, version-guard, build-artifact).

修复了 OMP native 模式下客户端上报的上下文窗口因缺少 x-bili-plugin 头而被忽略(以及主/子代理共用 agent 名互相覆盖、去重键过粗、冷启动竞态)的问题——把运行时信息改为按会话信号存储与查找、上报改为全字段指纹去重并在请求前等待落地,所有既有路径保持字节级不变且未命中时严格回退旧行为,本地与 CI 全绿,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Deep review complete — mergeable. This fixes all three reported defects of #1531 with one coherent shape, and I verified each leg:

1. Cross-session overwrite (the headline bug). runtime-info is now dual-tabled: legacy agent-keyed (kept for header-carrying agents and pre-first-request status) + conversation-keyed (pluginRuntimeByConversation). A main Astra session and a Gemini subagent in the same OMP process no longer fight over one pluginRuntimeTable["omp"] slot. Mutation check: forcing reports back into the agent-keyed table → 7/29 tests red — the scoping is pinned hard.

2. Wrong-window resolution. Header-less agents (omp sends no x-bili-plugin header) resolve by conversation signal: client conversation header → custom session header → body prompt_cache_key — which mirrors exactly the points where a reported conversationId can have been minted (omp stamps its session uuid into prompt_cache_key, #957/#1230). Model mismatch on the resolved entry degrades to a miss → legacy registry behavior, never a wrong hit. The window chain and the max_tokens fallback chain (server.ts:2214) got the same dual lookup.

3. Same-model config change never re-reported. The dedup key was the bare model id; the fingerprint is now proxyBase+agent+conversation+model+contextWindow+maxOutput+baseURL — any field change re-reports. Mutation check: fingerprint → bare model → 2/29 red.

Ordering fix I specifically approve: reportOmpRuntimeInfo is now awaited inside before_provider_request so the first request can't outrun its own report (the old fire-and-forget let round 1 resolve against a stale/absent entry — part of why 258400 never won). Worst-case hold is bounded (bootstrap readyTimeoutMs + STATUS_TIMEOUT_MS), documented in the diff.

Housekeeping verified: both tables capped at 32 entries with FIFO eviction; _resetPluginStateForTest clears the new table; /acp pre-first-request and runtimeInfo field check both tables; 90/90 runtime-info+plugin-agent, neighborhood 77/77 (plugin-agent, issue957, plugin-protocol), typecheck clean.

Non-blocking observation: a conversation entry can age out via the 32-entry FIFO in a busy process (many concurrent conversations) — degradation is the documented legacy miss, acceptable, but worth remembering if someone reports a window flipping back to registry-peek mid-session.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,独立复核结论与你的深审一致——可以合并。补充两点:

  1. FIFO 老化观察:同意且无需动作。这沿用了既有设计——legacy agent 表本来就有 32 条上限 + FIFO 驱逐,会话级表只是把同一边界应用到新维度;而且老化后的降级方向是「未命中 → legacy registry 解析」,正是本 PR 的 miss-only 不变量保证的安全方向(不会错配窗口)。若将来真有人报「窗口中途翻回 registry-peek」,按你提示的现象对照这个老化路径即可定位;到那一步再决定是否扩大上限或改 LRU。
  2. 合并:按系统规则 PR 合并只能由人操作,等你点按钮即可:fix: size OMP native windows from conversation-scoped runtime-info (#1531) #1532

合并后 CI 会自动发布,若需要我再跑一次发布后验证(npm view billion-context version + 自动更新链路)随时说。

中文摘要:owner 深审与 bot 复核结论一致(可合并),FIFO 老化确认为既有 32 条上限设计的延伸且降级方向安全、暂不处理,等待人工合并。

…1531)

OMP native binds sessions via identity register + prompt_cache_key stamping but sends no x-bili-plugin header on model requests, so the proxy's runtime-info window lookup (header-agent only) always missed and reported contextWindow/maxOutput were silently ignored (registry-peek fallback). The server also kept one runtime slot per agent, so a sub-agent session clobbered the main session's entry, and the client deduped on model id alone, suppressing corrective re-reports.

- src/plugin.ts: per-conversation runtime table keyed by conversationId (model-gated); handler records optional conversationId; status + pre-first-request probe fall back to it

- src/server.ts: strict dual lookup at window selection and maxOutput fallback - x-bili-plugin header present -> per-agent entry only (unchanged); absent -> conversation-scoped entry keyed by the same session signals used for binding (client conversation header, custom session header, body prompt_cache_key)

- src/agent/shared.ts: reportRuntimeInfoOnChange dedupes on (agent, conversation) with a full-field fingerprint incl. proxy origin, re-posting on any reported-config change; async, never rejecting

- src/agent/pi.ts: OMP reports await bounded proxy-origin readiness, include conversationId, and are awaited in before_provider_request so the report lands before dispatch

- src/agent/omp-native.ts: register the native origin waiter (setNativeOriginWaiter) like pi-native

- TECHNICAL-NOTES en/zh: document conversationId and per-agent vs conversation-scoped resolution semantics

- tests: conv-scoped storage/lookup/eviction units, e2e header-less pck adoption + clobber regression + header-wins + plain-client compat, dedup fingerprint units, #957 test asserts conversationId + ordering
@ranxianglei
ranxianglei force-pushed the 2026-09-28_omp-runtime-info-window branch from 3e819de to ceff209 Compare September 28, 2026 02:06
@ranxianglei

Copy link
Copy Markdown
Owner Author

Conflict resolved — rebased onto master (new head ceff209), which now includes #1530's backstop.

Single conflict, union-resolved: the plugin.js import line (#1532 adds pluginRuntimeInfoForConversation + runtimeConversationId) vs the mitm.js import line (#1530 adds liveBlindTunnels) — both sides' additions kept; liveBlindTunnels consumer verified intact at the exposure log line. No semantic overlaps anywhere else (#1530 = client-facing socket paths, #1532 = runtime-info resolution).

Post-rebase verification: runtime-info + plugin-agent suites 90/90, typecheck clean, tree clean (9 files, +353/−42 unchanged from review). Ready once CI is green.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Rebase 已独立核验,与你的描述逐项对上——新 head ceff209a 可以合并:

冲突解决核验(对实际代码,非仅读报告)

Rebase 后全量重跑(本地,head ceff209a)

CI(head ceff209a):13/13 全绿(unit matrix ×4、e2e、hermetic registry e2e、real pi/dsh/opencode/codex lanes、version-guard、build-artifact)。PR 状态 mergeable: true,仅剩人工合并。

合并入口:#1532

中文摘要:rebase 后的新 head 经逐行核验(import union、liveBlindTunnels 消费者、diff 零漂移)+ 本地全量重跑(3026/0 fail)+ CI 13/13 全绿,确认可以合并。

@ranxianglei
ranxianglei merged commit 80b8f5a into master Sep 28, 2026
13 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-28_omp-runtime-info-window branch October 15, 2026 05:32
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][OMP native][0.1.163] contextWindow 上报后仍使用 registry 窗口,runtime-info 存在跨会话覆盖

1 participant