Repository navigation
[PR] kernel: reuse the client's leading message role when rebuilding the Responses input - #6064
Conversation
…de 422 rejections (for ranxianglei#6063) DeepSeek-class serde backends answer a role rejection with 422 and the deserialization text 'messages[0].role: unknown variant `developer`' instead of 400 'Invalid role: developer'. The learn-on-failure ladder only admitted 400s (relay funnel + both detectors) and its patterns required the rejection keyword BEFORE the field name, so such clients never self-healed and every request kept failing upstream. Widen the relay funnel gate and detectRoleRejection/detectSystemPlacementError to 400/422, and add a serde-shaped pattern (field path first, 'unknown variant' after). Every existing conservative gate stays intact: stopword guard on the captured token, placement-marker requirement for the placement detector, rewritten===0 short-circuit, hard cap of original+2 attempts, and the original error body forwarded verbatim after a failed retry.
(ai: vllm-qwen/qwen3.8-27b) CI auto-fix run (attempt 1/3): docs-sync fixed and verified green. What was broken:
Fix: ran the generator on the PR head; the output matched the CI failure diff byte-for-byte (same hunks, same blob hashes), so I committed the four regenerated files as Concurrent work handled: while CI was starting, a second commit Live verification (mirror cache, this run): head 八问(中文结论)
判定:docs-sync 已绿并实测确认;当前 30 项检查零失败,仅剩 5 个长时 test 分片在跑。本次自动修复任务完成。 |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)
|
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1137-master.3cae710 # this exact build
npm install -g billion-context@master # always the newest merged build
|
kernel-change:
responsesToCoredrops the role of the client's leading system/developer message andinjectResponsesDeveloperMessagehardcodesrole: "developer", so a client that must sendsystem(DeepSeek-backed models withcompat.supportsDeveloperRole: false) gets its head rewritten into a role the upstream rejects with HTTP 422. The fix records the hoisted role on the projection and reuses it; it is a literal-vs-client-value defect, not a design change, and ships with a reproducing regression test (mechanical-bug exemption, rule 1).Closes #6063
What breaks
A
/v1/responsesclient that declarescompat.supportsDeveloperRole: falsesendsinput[0].role = "system"on purpose.responsesToCorehoists that item intosystemPartsbut keeps only the text, and the two rebuild sites re-inject the merged block with a hardcodedrole: "developer". DeepSeek answers HTTP 422messages[0].role: unknown variant 'developer', killing the turn, while the same request that skips the bili rewrite succeeds — exactly the asymmetry in the report.Measured on
master4446301with a two-line probe:Fix
kernel/src/wire/responses.ts:ResponsesProjectiongainsheadRole?: "system" | "developer", set (??=) only while the leading system/developer run is still being hoisted — mid-history system items keep their existing sidecar path and never become the head role.injectResponsesDeveloperMessagetakes an optionalroleparameter, defaulting todeveloperso every existing caller keeps its old bytes.src/server/prepare-responses.tsandsrc/loop/adapter-responses.ts: passprojection.headRole ?? "developer"at all three injection sites.Same probe after the change:
Both compression modes are covered: the HTTP/proxy path goes through
prepare-responses.ts(two sites, compress-on and tags-only) and the ACP/plugin path throughadapter-responses.ts. When the body carries no head message at all the field staysundefined, so behaviour is byte-identical to before — no upstream that acceptsdeveloperstarts seeingsystem.Fix — part 2: the #552 learn-on-failure ladder recognises serde 422 rejections
Part 1 makes the request correct in the first place; this half teaches the proxy to learn from the failure for clients that still send
developer. Against DeepSeek-class serde backends that learning never fired: the relay funnel (src/server/relay.ts) only admitted 400s into the ladder, both detectors insrc/compat-roles.tsrequired status 400, and neither regex matched Rust serde wording — the field path comes first andunknown variantafter, the reverse word order of pattern 1. Every such request kept failing upstream with no self-heal.src/server/relay.ts: the funnel gate admits 400 or 422 (request-validation error bodies for these statuses are small and are already buffered below the gate).src/compat-roles.ts:detectRoleRejectionanddetectSystemPlacementErroraccept 400/422;ROLE_REJECTION_PATTERNSgains a serde-shaped third rule (role … : unknown|invalid|unsupported variant <name>).rewritten === 0short-circuit, hard cap of original + 2 attempts, and the original error body forwarded verbatim after a failed retry.Tests
kernel/tests/responses-head-role.test.ts(5 cases: hoistedsystem, hoisteddeveloper, mid-history system must not become the head role, no-head default, explicit-role injection). Reverting onlykernel/src/wire/responses.tsturns two of them red; the default-role guards stay green, which is the point.tests/compat-roles.test.ts: unit rows for the serde shape on 400/422 plus stopword / non-validation-status negatives, a 422 row for the placement detector, and an e2e that mirrors billion-context: 400 Bad Request when codex sendsrole: "developer"messages — request a request-body compat transform hook #552-E against a serde-422 upstream (auto-retry developer→system, session learns, second request skips the round-trip).node --import tsx --test tests/compat-roles.test.ts→ 21 passed, 0 failed.npm --prefix kernel test→ 1633 passed, 0 failed.tests/*response*.test.ts, 36 files) → 226 passed, 1 skipped; two e2e cases (e2e chat relay … marker protocol,Responses WS: a title-persona side request …) tripped under 36-file concurrency and pass when run individually — I am not claiming a clean full-concurrency run.tsc --noEmitclean in bothkernel/and the repo root.kernel/package.jsonbumped to 0.0.191 with the lock files synced, per the kernel boundary.Part 2 was originally offered as a separate change; it lands here instead under the one-fix-PR-per-thread rule — same issue (#6063), same symptom (this very 422), different mechanism layer (request rewrite vs learn-on-failure). Together the PR covers both halves of the report: the request goes out right, and clients that still send
developerself-heal instead of failing every turn.