Skip to content

fix: position-preserve mid-history system/developer items on the plugin responses lane (#1638) - #1671

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-30_plugin-responses-inplace-sysdev
Sep 29, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-30_plugin-responses-inplace-sysdev

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem (#1638)

Plugin-mode clients on the responses wire that append mid-history role:"developer" items — OMP converts custom_message notifications (todo nudges, launch completions) to developer items and re-sends them every turn — break the upstream prefix cache every time a new notification lands:

  1. kernel responsesToCore hoists system/developer content from any position into projection.systemParts;
  2. prepareResponses merges them with the compress prompt and injects the block at input[0];
  3. → the outbound first item rewrites on every notification append → OpenAI prefix cache misses the whole input → cached pinned to the instructions+tools residual (4992 = 39×128), the exact [Bug] bili 启动 OMP 后缓存命中率 82.7%,连续请求多次骤降至 4992 cached tokens #1638 sawtooth.

Root-cause archaeology: hoist-and-inject landed 97190f5 (2026-08-09); stableSystemAnchor && !pluginMode scoped the anchor away from plugin mode deliberately in df499d1 (#1085). Not a regression of the recent detection work (49a2c1c / a08deb2 / fb32b4a / #1663 are probes only).

Fix

Plugin mode only, responses lane only: mark the non-head system/developer items with an unknown type for the duration of responsesToCore — they become coreId-less layout slots, which patchResponsesInput re-emits verbatim in their original position. The head run keeps the hoist (stable system prompt), so the front developer block is byte-identical across turns. This gives the responses wire the position-preserved semantics the openai-chat wire already has (kernel head-only hoist, src/wire/openai.ts).

  • proxy mode (native codex, [Feature] Optimize the cache by reorganizing the context. #1085 anchor path) untouched
  • easy-form items ({role:"developer", content}, OMP shorthand) re-emitted as-is
  • additional_tools / mcp_list_tools are head-neutral
  • marked items were never foldable before or after (they never enter core space) — no fold interaction change
  • transition cost: one-time cache miss per active plugin session at upgrade (front block drops accumulated notification text)

Tests (tests/responses-plugin-dev-position.test.ts)

  1. plugin main — front block byte-stable across notification appends; notifications present exactly once, in position, easy-form intact; append-only bodies (byte-prefix property); no sentinel leak
  2. fold interaction — post-fold notification rides in place exactly once; in-place carrier counts keep the plugin mode: in-place acp_summary never stripped when the client's own compress pair rides inbound — double summary carrier on every post-fold turn #1567 pins (0 markers, 2 summary quotes)
  3. head-neutral — leading additional_tools does not break the head run
  4. proxy negative pin — native mode keeps hoist semantics (notifications NOT re-emitted in place)

Fills the developer-item probe gap neptune62 flagged in #1638/#1650 (the #1663 probe suite covers user/reasoning/function_call but zero developer items).

Verification

Closes #1638 (plugin-mode half; the relay-side patterns from #1613 §4 are out of scope here).

…in responses lane (#1638)

OMP-style plugin clients append custom_message-derived developer
notifications mid-history and re-send them every turn. The kernel's
responsesToCore hoists system/developer content from ANY position into
projection.systemParts, and prepareResponses re-injects the merged block
at input[0] — so every notification append rewrote the outbound FIRST
item and the upstream prefix cache missed the whole input (production
sawtooth: cached pinned to the instructions-only residual, #1638).

In plugin mode, mark the non-head system/developer items with an
unknown type just for the duration of responsesToCore: they land in the
projection layout as coreId-less slots and patchResponsesInput re-emits
them verbatim in their original position — the position-preserved
semantics the openai-chat wire already has (head-only hoist). The head
run keeps the hoist (stable system prompt), so the front developer
block stays byte-identical across turns. Proxy mode (native codex)
keeps the hoist-and-anchor behavior (#1085) untouched.

Transition cost: one-time cache miss per active plugin session at
upgrade (front block no longer carries accumulated notification text).

Tests (tests/responses-plugin-dev-position.test.ts): front block
byte-stability + in-place notification re-emission + append-only bodies
+ no sentinel leak; fold interaction (in-place carrier counts keep the
#1567 pins); leading additional_tools head-neutrality; proxy-mode
negative pin (hoist semantics unchanged). Fills the developer-item gap
neptune62 flagged in #1650/#1663.
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-30_plugin-responses-inplace-sysdev (dff0920)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1618-pr.1671.afddb51

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-pr1671.tgz
npm install -g package

Install instructions are refreshed on each push.

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] bili 启动 OMP 后缓存命中率 82.7%,连续请求多次骤降至 4992 cached tokens

1 participant