Repository navigation
[PR] fix: collapse adjacent output_config effort directives after fold reconstruction (#5688) - #5690
Conversation
…onstruction (ranxianglei#5688) Fold reconstruction can remove the message sitting between two per-turn effort directives (reasoning hygiene, CCR excerpting, range trimming), leaving them adjacent. OpenRouter's Anthropic Messages surface rejects that shape with a hard 400 — "Two adjacent output_config directives are not allowed" — and the session fails deterministically on every retry. Repair at egress: collapse runs of adjacent {role:"system", content:[], output_config} directives down to the last (later effort wins, matching the trailing active-directive semantics). Detection is narrowly the directive shape; text-bearing system messages are never touched. Clean histories return the input array unchanged.
(ai: vllm-qwen/qwen3.8-27b) 查重:不重复。 多组关键词("output_config"、"adjacent directives"、"effort 400"、"adjacent system merge egress")检索 open+closed issue/PR:无既有条目记录本缺陷,也无在途修复 PR。最近亲为 #4570/#5437(mid-conversation system 位置违规 400 家族)——不同症状(位置规则 vs 相邻规则)、不同机制(位置漂移 vs fold 重建把两条豁免 directive 顶成相邻),且那两条规则明确豁免 directive-only 形态;本线程是该缺陷的唯一实现。出站前二次查重(我自己的修复提交之前):同样无冲突。 标签:bug / pi / scope/wiring / p1 —— 修复 #5690 的 p1 缺陷;pi 车道(OpenRouter anthropic-messages);硬失败点在出站管线。 审核结论:方向对、方案对、测试有牙——但首版漏了同一机制的两个出网点(nudge-decide 旁路调用、loop round-2 重建)。我已直接补进本 PR 分支(两个增量标注 commit),原 commit 与作者署名完整保留。 ① 是什么问题 ② 什么原因导致的 ③ 影响范围与严重程度 ④ 怎么修复的 ⑤ 是否有回归问题(既有行为清单逐项)
⑥ 是否破坏缓存 ⑦ 是否改了设计方向 ⑧ 是否引入了新的配置 测试有效性(质量关):7 个单测有牙——identity fast path 钉数组引用相等(抓得住「拷贝了但内容没变」这种假实现)、2/3-run 折叠 deepEqual 验证 keep-latter、负行钉住「text-bearing system 不碰 / 无 output_config 空 system 不动 / 非相邻保留」。本地定向验证:4 文件 19/19 绿(本文件 + issue2499 round-2 cache + anthropic-round2-stream + issue3004 decide selfheal), 我对本 PR 的操作(增量 commit,已推送到你的 fork 分支
CI:head 95ddfa4 上运行中(回帖时镜像缓存尚未登记 check 结果,落地后我在此线程补结论)。 判定:CI 转绿即可合(我不能代合,请自行合并:https://github.com/ranxianglei/billion-context/pull/5690)。 |
(ai: vllm-qwen/qwen3.8-27b) 更正上一条的 CI 行(我之前写「运行中」,不准确): 本 PR 来自外部 fork(head =
所以镜像缓存里一直是空 checks——不是我的代码没触发,是平台层门禁拦住了。这一步需要人工动作:维护者在 PR 页点一次「Approve and run」(或把分支落到 base 仓再开 PR),CI 才会跑起来给出全量绿/红判定。 在此之前,本地已完成的定向验证(非全量、按 §7.2 纪律)供参考:
结论不变:代码侧我认为可合;但全量回归判定要等你解锁 CI 后由远端给出。 我不能代点审批、也不能代合——两者都留给你:PR #5690 。 |
🔶 需要决策 背景一句话:本 PR(外部 fork 提交)的 CI 被仓库的 fork-workflow 审批门禁拦住,维护者不点「Approve and run」它就永远不会跑,全量回归判定因此悬空。 待决问题:如何解锁本 PR 的远端 CI? 选项:
我的推荐:A(最小动作、零副作用)。不决定的默认行为:PR 保持 open、判定停留在「代码侧可合、待 CI」,我不再重复催促,等你解锁后我补 CI 结论。 |
… path (ranxianglei#5688) The unit suite pins the helper in isolation; nothing pinned the wiring — deleting the call site at the final assembly would have stayed green. Hermetic A/B rig (mock upstream that enforces OpenRouter's adjacency rule) drives a real /bili/ request: positive direction asserts the collapsed single directive (keep-latter) reaches upstream with a 200, negative direction asserts the healthy pi shape passes through untouched. Added during PR review of this branch.
buyiking01
left a comment
There was a problem hiding this comment.
Reviewed the diff against master (did not check out or run the suite — note this branch reports no CI checks).
Direction looks right. "Later wins" matches the per-turn directive semantics: the earlier directive's assistant message is gone after fold reconstruction, so it has no effect left to preserve. Keeping the referential-equality fast path (removed > 0 ? out : messages) is also the right call for downstream consumers.
Two things I'd change before merge:
1. src/server/prepare-anthropic.ts:125-127 — the warn will repeat on every request.
Dedupe only happens at egress, and rebuiltMessages is re-derived from session history each turn. As long as the fold produces the same adjacency, this log("warn", ...) fires per request for the whole session. Suggest reporting once per session (or dropping to debug) so this doesn't drown out other warnings.
2. src/dedupe-adjacent-output-config.ts:34-37 — the shape test is asymmetric.
- Misses:
content: [{ type: "text", text: "" }]is a non-empty array, so it returnsfalse; if upstream treats that as a directive shape too, the adjacency survives. - Over-matches:
content: null(or any non-array/non-string value) falls through all three checks andreturn true, so two system messages that should both be kept would collapse into one.
An explicit allowlist would be safer: only content === undefined, [], or "" count as a directive.
Optional (P3): the comment claims "every anthropic-wire egress surface", but coreToAnthropic( is also called from src/loop/core.ts, src/incremental-lane.ts, src/server/budget.ts, src/plugin-render.ts, src/image-rescale.ts. The current three sites look sufficient, but this is structurally "a future egress will silently miss the repair". Consider moving the repair to the fold-reconstruction choke point and keeping egress for assertion/logging only.
Test gaps worth adding: content: "" and content: null expectations (the latter is currently unspecified), and a "system message with text + output_config must be preserved" case.
Since the branch has no CI, locally running npm run typecheck plus node --test tests/issue5688-adjacent-output-config.test.ts tests/issue5688-egress-wiring.test.ts before merge seems worthwhile.
|
Correction to the review above — the line numbers I quoted were diff offsets, not file lines. Corrected references (head
Substance unchanged. |
(ai: vllm-qwen/qwen3.8-27b) 收到更正——我在 head
实质结论不变。另注意到第 4 个 commit( CI 状态不变:仍卡在 fork-workflow 审批门禁(见上一条 🔶,等你「Approve and run」或选 B)。解锁后我补全量结论。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1039-master.3f822d1 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Fixes the deterministic 400 reported in #5688.
What
dedupeAdjacentOutputConfig: collapses runs of adjacent{role:"system", content:[], output_config:{...}}effort directives down to the last one (later effort wins — same semantics the client's trailing active directive relies on).prepare-anthropic.tsafter fold reconstruction, before the outbound body is serialized. Clean histories hit an identity fast path (input array returned unchanged, no copy, no scan cost beyond one pass).warnlog line when a collapse actually happened, so the defect stays observable in production while being repaired.Why this shape
Evidence chain from the issue: the client's own history (197 messages, all directives) passes OpenRouter verbatim; the same history through the proxy after a fold 400s with
Two adjacent output_config directives are not allowedatmessages[2].output_config. The proxy never creates or editsoutput_config— the adjacency appears when reconstruction removes the message between two directives.Detection is deliberately narrow (empty-content system message carrying an
output_configobject — exactly the directive shape). Text-bearing system messages and empty system messages withoutoutput_configare never touched, verified by tests.Tests
tests/issue5688-adjacent-output-config.test.ts(node:test, project convention): clean-path identity, two-adjacent collapse, three-run collapse, text-bearing system untouched, no-output_config system untouched, absent-content directive detected, non-adjacent preserved. 7/7 pass vianode --import ./tests/preload-test-env.mjs --import tsx --test;tsc --noEmit -p .clean.Scope note
Only the Anthropic lane is wired (that's where the directive exists today). If other lanes grow per-turn effort directives (OpenAI
configuration_update, Responses items), the same helper applies — left unwired per minimal-change discipline.