Skip to content

fix: scope Responses ingress id healing to Bili's msg-proxy namespace - #1475

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-27_responses-provider-id-scope
Sep 27, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-27_responses-provider-id-scope

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What changed

sanitizeResponsesInputIds (Responses ingress, called from prepareResponses at src/server.ts:3444) rewrote any input[] item id longer than 64 chars to msg-fix-<hashId> without checking item type. Provider-issued opaque items (reasoning with rs_* ids, function_call fc_*, custom_tool_call, item_reference, compaction) were therefore renamed on every request; upstreams that validate id shape/namespace (e.g. Copilot Responses API: "Expected an ID that begins with 'rs'") rejected the rewritten id with HTTP 400 on every turn (#1474).

Fix: the length-based rewrite now applies only to ids starting with msg-proxy- — the exact namespace #242's healing was written for (pre-hashId round-2 ids embedded the full 54-char upstream id → 66 chars; see devlog/2026-08-25_responses-id-length). Everything else crosses ingress byte-identical. The existing msg-proxy-* assistant-message handling (omit local id on full-message replay) is unchanged. No prefix-compliant substitutes (rs_<hash> etc.) are introduced: prefix compliance ≠ acceptance, and renaming breaks identity/replay correspondence (reasoning id ↔ encrypted_content).

Behavior change (old → new)

  • Old: any over-64 input[].id → rewritten to msg-fix-*.
  • New: only over-64 ids starting with msg-proxy- are rewritten; all other ids pass through byte-identical.
  • Consequence: a client that invented its own >64-char non-msg-proxy message ids would no longer be healed. In practice such ids only ever came from old bili versions (all msg-proxy-*) or from the provider itself, so no real healing case is lost — while provider-owned ids on shape-validating upstreams stop 400ing.

Tests

  • tests/responses-proxy-id-replay.test.ts: replaced the stale boundary/healing test (which pinned the generic rewrite) with two tests — over-64 ids on reasoning / function_call / custom_tool_call / item_reference / compaction / provider message stay byte-identical; over-64 msg-proxy-* ids keep deterministic, idempotent msg-fix-* healing with the 64-char boundary preserved.
  • tests/responses-round2-lifecycle.test.ts [Bug] Responses ACP round 2 生成 66 字符 message id,导致 Codex 后续请求持续 400 #242 regression (poisoned msg-proxy-* rollout) unchanged and still green.

Pre-flight on rebased head (master cae30bb3): typecheck ✅ · full suite 2884 pass / 0 fail / 12 skip (gated e2e) ✅ · build ✅. Real-client E2E auto-runs in CI (diff touches src/loop/**).

Fixes #1474

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_responses-provider-id-scope (5dc12ad)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1404-pr.1475.ed89c82

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-pr1475.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] 🏷 Second-pass verification review of #1475 (fix for #1474) — this PR is from my earlier session on #1474; per protocol I did not redo it but independently re-verified code, base freshness, tests, and CI against live master.

① Original issue (direction) — #1474's attribution is sound and was verified in triage before implementation: sanitizeResponsesInputIds (src/loop/adapter-responses.ts) rewrote any input[].id > 64 chars without a type/ownership check; the generic scope came from #242's healing (30b3324), whose poisoning class is specifically over-long Bili-generated msg-proxy-* ids. The defect is that the sanitizer renames identifiers bili does not own — provider-issued opaque ids (reasoning rs_*, function_call fc_*, …) carry replay correspondence (reasoning id ↔ encrypted_content) and are validated by their owner's shape rules, so Copilot Responses API 400s every turn. The fix addresses the root cause at the decision point (the sanitizer's gate), not a downstream mask — litmus test holds: if the same root cause surfaced under another provider namespace tomorrow, "only rewrite what we own" still stands. Rejected alternative also correctly rejected in the issue thread: rs_<hash> substitutes would be prefix-compliant but not acceptance-guaranteed, and would break identity/replay correspondence.

② Regression review (existing behaviors on the touched path) — the only touched behavior surface is sanitizeResponsesInputIds, called from exactly one site (prepareResponses, src/server.ts:3444), at ingress of every Responses request. Inventory + verdicts:

  1. Branch 1 — assistant msg-proxy-* message items → local id omitted on full-message replay: unchanged ✅
  2. Branch 2 — over-64 length healing: previously any string id > 64 → now only msg-proxy-*. Current bili never emits ids > 64 chars (all synthesized ids ≤ ~30 chars), so today this path only ever sees historical pre-hashId msg-proxy-* poison ([Bug] Responses ACP round 2 生成 66 字符 message id,导致 Codex 后续请求持续 400 #242 class — healed exactly as before, same deterministic hashId) or provider-owned ids (which were broken anyway on shape-validating upstreams — that is the bug). Intentional change, disclosed old→new in PR body + REQ.md + Preserve provider-issued reasoning IDs in Responses input sanitization #1474 thread; no real healing case lost ✅
  3. Reference consistency: item_reference carries the referenced item's id as its own id; the rewrite is deterministic per source id, so reference and target are rewritten identically both before and after — no new inconsistency window ✅
  4. Idempotency/determinism: msg-fix-* does not start with msg-proxy-, so repeated passes stop; identical replacement across requests (sha256-hex16) ✅
  5. No other consumers of msg-fix- exist (grep: adapter + the two test files only); session state/persistence never stores provider item ids, so pass-through creates no state divergence ✅
  6. Both compression modes: ingress handling precedes mode branching; plugin mode and proxy mode are affected identically, no mode-specific semantics changed ✅

No unintended regressions found.

③ Code review — one added conjunct rec.id.startsWith("msg-proxy-") && plus doc-comment update (src/loop/adapter-responses.ts:69-72). Minimal, single-module, no as any/@ts-ignore, no config-surface change, no version bump, no load-bearing infra touched (§7.4 note honored: wire-shape change explicitly left to human merge).

④ Test validity — the stale test that pinned the generic rewrite was replaced, not just deleted: (a) byte-identical pass-through asserted via deepEqual against a structuredClone baseline for over-64 ids on message(assistant+user)/reasoning/function_call/custom_tool_call/item_reference/compaction — has teeth, catches the regression if it returns; (b) scoped-healing test pins the 64-char boundary, non-msg-proxy over-64 untouched (incl. call_id), msg-proxy-* → msg-fix-* ≤ 64 chars, idempotent second pass, deterministic per source id. The unchanged #242 regression (tests/responses-round2-lifecycle.test.ts, poisoned rollout) still passes. Behavior pinned in both directions ✅

⑤ Diff cleanliness — 4 files, every line purpose-related: gate (+9/-4 incl. comment), test replacement (+30/-7), devlog REQ/WORKLOG (repo convention). Single linear commit, base = current master cae30bb3 (verified origin/master == merge-base — no stale-base risk). No whitespace/lockfile churn ✅

Evidence (re-verified locally on head 7bc53888): typecheck ✅ · affected suites tests/responses-proxy-id-replay.test.ts + tests/responses-round2-lifecycle.test.ts 8/8 pass ✅ · build ✅. CI on head: all 13 check runs green, including real-client e2e (codex/opencode/pi/dsh lanes), hermetic registry e2e, ubuntu+windows test matrices, build-artifact, version-guard.

Verdict: ready to merge.

中文摘要:复核了本 PR(把 Responses 入口的超长 id 改写限定到 Bili 自己的 msg-proxy-* 命名空间,修复 #1474 中 Copilot rs_* reasoning id 被误改写导致每轮 400)——方向、回归面、测试与 CI 全部核验通过,无意外行为变更,可以合并。

@ranxianglei
ranxianglei force-pushed the 2026-09-27_responses-provider-id-scope branch from 7bc5388 to efd1e46 Compare September 27, 2026 06:43
…#1474)

sanitizeResponsesInputIds rewrote ANY over-64-char input item id to
msg-fix-<hashId> regardless of item type, renaming provider-issued opaque
ids (reasoning rs_*, function_call fc_*, custom_tool_call, item_reference,
compaction) that upstreams with id-shape validation reject with HTTP 400 on
every turn. The length rewrite now applies only to msg-proxy-* ids — the
exact namespace the #242 healing was written for; everything else crosses
ingress byte-identical.
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.

Preserve provider-issued reasoning IDs in Responses input sanitization

1 participant