Repository navigation
fix: learn-on-failure ladder entry for placement-only system 400s (#1996) - #2014
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2064-pr.2014.13f66d0This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2014.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2014 review — 可合并(待人工合并) 审查基础:PR head ① 方向关:方向正确,打在根因上。#1996 的缺陷是 learn-on-failure ladder 的入口条件过窄—— ② 回归清点(逐项判定):
③ 代码关: ④ 测试有效性:单测有牙——钉住 ⑤ diff 整洁度:每行都属于 #1996 或 #2013(两个线性 commit、独立标注),无空白/lockfile/version churn。干净。 结构化七问
行为变更披露(PR 描述已声明,核实无误):
收工判定:✅ 可合并。按 §7.4,本 PR 触碰请求管道行为(新增 live retry hop),留人工合并。CI 已全绿( |
4fb0e6e to
9453c7e
Compare
Closes #1996
Also repairs the pre-existing master typecheck breakage blocking every CI job: #2013 (separate labeled commit).
Mechanism (#1996)
Production 400 from vLLM serving a Qwen model over
/v1/responses:chat_template.jinja … Jinja Exception: System message must be at the beginning.— the model's Jinja guard rejects any literalrole:"system"that is not the first chat-producing item (or any second system). vLLM passes role-bearing Responses items through verbatim (_construct_message_from_response_itemreturns dict items with arolekey unchanged), so only a literalsystemcan trip it.bili never emits such items itself (front block and compression anchors ride as
developer, nudges/separators asuser, top-levelinstructionsstripped). The offenders are client-origin mid-history system items forwarded verbatim by the plugin-mode position-preserving pass-through (#1638) — OMP reshapes its history around host compaction so one of those sits off-head post-compression. That trigger is client-side; the bili defect is what happened next:The #552/#583 learn-on-failure role ladder never fired because its entry detector (
detectRoleRejection) requires a named role in the error body — this error names none (invalid_prompt/invalid_request_errordon't match either). Result: permanent 400 loop on every request of the session (two sessions in the log, retries hours apart).Fix
src/compat-roles.ts: newhasOffHeadSystem(body, protocol)— detects the offending shape on the wire itself (off-head or duplicate literalsystem, incl. the top-level-instructionsvirtual-leading case; eligibility mirrorsapplyCompatRolesJsonexactly).src/server.ts: the ladder now ALSO enters when the error matches the existing placement markers (detectSystemPlacementError) and the wire carries the shape — entering as{role:"system"}, which skips the identity hop and goes straight to the singlesystem→userrepair hop. On success the mapping is remembered per session exactly like billion-context: 400 Bad Request when codex sendsrole: "developer"messages — request a request-body compat transform hook #552/compat auto-fix: developer→system retry can still 400 on system-at-index-0 backends (#377 class); add second-chance developer→user learn #583 (session metadatalearnedCompatRoles, permanent-config snippet logged). A rejection where the detector DID capture a literalsystemkeeps the old exclusion (unchanged).tests/wire-contract-fakes.ts(strict-Jinja system-placement rule, provenance = this production 400) + probe intests/wire-contract.test.ts.hasOffHeadSystemshapes; hermetic e2etests/e2e-responses-offhead-system.test.tsdriving the real pipeline through the validation-parity fake: turn 1 transparently repaired (client sees 200, original forward kept the offender verbatim, retry carried zero systems), turn 2 rides clean proactively with no second violation.Behavior changes (disclosure)
systemnow triggers up to ONE extra retry hop (system→user). Old behavior: such 400s were relayed verbatim on every request (permanent failure loop). All other 400 paths unchanged.{"system":"user"}is remembered in session-scopedlearnedCompatRoles(not persisted config) and a permanent-config snippet is logged — same mechanism as billion-context: 400 Bad Request when codex sendsrole: "developer"messages — request a request-body compat transform hook #552/compat auto-fix: developer→system retry can still 400 on system-at-index-0 backends (#377 class); add second-chance developer→user learn #583.systemitems throughstartFakeUpstream("responses")now get a 400 (intended: ledger only grows).No config-surface changes (no new fields/env/flags), no
versionbump, acp-kernel pin untouched.Verification (targeted, local)
npm run typecheck— clean (was red on master pre-repair; see masternpm run typecheckred — 4 test files break tsc, all CI test jobs fail #2013)node --import tsx --test tests/compat-roles.test.ts tests/wire-contract.test.ts tests/e2e-responses-offhead-system.test.ts tests/responses-plugin-dev-position.test.ts— 39/39 passnode --import tsx --test tests/issue1987-preflight-baseline-anchor.test.ts tests/issue1993-preflight-400.test.ts tests/ws-bridge.test.ts— 9/9 passnpm run build— success