Repository navigation
[PR] kernel: move illegally-positioned directive-only systems to the trailing run (#7270) - #7281
Conversation
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.10968-pr.7281.1efb6bfThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7281.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…ing run (#7270) kernel-change: the ANY-position exemption for directive-only systems (content:[] + output_config) does not hold on every upstream. A real Anthropic endpoint rejected system(directive)→user adjacency with the same 'must precede an assistant' 400 as content-bearing systems, permanently bricking the session after a degenerate fold. The fix moves an illegally-positioned directive-only system to the trailing run instead of skipping it, preserving the effort/tool-control semantics. Closes #7270
…the 0.0.199 collision with #7252's kernel bump)
jensenojs
left a comment
There was a problem hiding this comment.
修复方向正确,端到端验证通过:用 #7270 现场抓到的真实 6 条出站 body(user | system:dir-medium | user | system:dir-high | user | system:text)喂给 PR 分支的 healAnthropicSystemPositions,结果是 user | user | user | system | system | system — system→user 非法邻接消除,medium/high 两个 effort 值保留,5 个新增测试全绿。根因定位和修复层级都对:在 kernel heal 层修,不降级 directive,legal 位置不动。
当前不能合,有一个 CI blocker 和一个需在合入前确认的语义点:
-
[blocker] kernel-guard FAILURE 是 BEHIND 造成的假失败。master 的 kernel/package.json 已是 0.0.199,本 PR 从 0.0.198 bump 到 0.0.199,guard 相对 master 看不到版本提升而报错。rebase 到最新 master 并 bump 到 0.0.200,重跑 CI。
-
[需确认] 多个 directive 全部移到末尾后,#5688 dedupe 只保留最后一个,会覆盖当前 effort。#7270 现场会话当前 variant 是 low,history 里残留 medium/high 两条遗迹 directive(切 variant 累加的)。本 PR 把它们都移到末尾后,prepare-anthropic 的 dedupeAdjacentOutputConfig 只留最后一个 high,最终上游生效的是 high 而非 low。不影响 400 修复,但 effort 语义会变。建议移动前按「同 run 保留最后一个」折叠,或确认覆盖可接受并补多 directive 测试。
-
[建议] 测试只走 coreToAnthropic 内部 heal,未覆盖 prepare-anthropic L663 的最终 healAnthropicSystemPositions 出口(本单真实路径)。同一函数风险低,但值得加一个直接调 healAnthropicSystemPositions 的 case。
| out[j] = { role: "user", content: kept }; | ||
| prevNonSystem = j; | ||
| } | ||
| for (const d of movedDirectives) { |
There was a problem hiding this comment.
这里把所有被移动的 directive 无差别 push 到末尾。history 里有多条遗迹 directive 时(本单现场 medium/high 两条,当前 variant 是 low),它们在末尾相邻,随后被 prepare-anthropic 的 dedupeAdjacentOutputConfig 折叠成最后一条 high,覆盖当前 effort。建议移动前按「同 run 保留最后一个」折叠,或确认该覆盖可接受并补测试。
#7270 precede-heal Drive-by (review of #7281): the PR updated the isDirectiveOnlySystem comment but left three stale spots that now contradict the new behavior — - anthropic.ts heal comment: 'accepted at ANY position, so it is never healed' - issue5432 orphanSystems helper: still exempted directive-only on BOTH sides (a divergent mirror of the old behavior; the real heal now checks the PRECEDE side for them). Made the helper judge directive-only systems on the precede side only, matching healIllegalSystemPositions. - issue5432 test name + issue4292 header comment: 'exempt at any position' / 'directive-only anywhere'. All 53 targeted system-position tests still pass; kernel typecheck clean.
e1095ab to
2975a63
Compare
Rebasing #7281 onto master's kernel 0.0.199→0.0.200 bump left the root package-lock.json's kernel entry at 0.0.199. The kernel/ own lockfile was synced (88f6780) but the root lock was not, so lock-sync's 'npm install --package-lock-only' + 'git diff --exit-code -- package-lock.json' failed. Regenerated the root lockfile to record kernel 0.0.200.
(ai: vllm-qwen/qwen3.8-27b) lock-sync is fixed and pushed. What was red: the Root cause: when #7281 was rebased onto master's kernel bump (0.0.199 → 0.0.200), commit Fix (pushed as final head 八问(中文,供人工 reviewer):
收工判定:lock-sync 已修,PR 分支 head 现为 |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 #7281 is the only PR referencing #7270. It is related to open PR #5800 (same heal function, same issue4292 test, same kernel version line) but a different system type: #5800 relocates misplaced tool-delta systems (#4818); #7281 moves illegally-positioned directive-only systems (#7270). Complementary, not redundant — but they contend on the same files (flagged below). Verdict: the fix is correct and closes a real heal gap. I traced the real 6-message post-fold shape (user, dir, user, dir, user, system-with-content) through Root cause (layered). #7270 is a diagnostic puzzle: the heal's PRECEDE check should catch a content-bearing system followed by a user, yet messages[2] survived the fold unhealed. The only systems the heal skips are directive-only ones (the old unconditional CI was red — both lanes are now fixed.
Drive-by fixes (commit 2975a63). The PR updated the
结构化八问
判定:代码正确、CI 两个红 lane 已修复,可进入人工 review(kernel 变更,按 Kernel Boundary 走人工审核,不 auto-merge)。建议 #5800 先行、本 PR rebase 跟进。新 head 9a880e4 的 CI 重跑中,转绿后我确认。 |
(ai: vllm-qwen/qwen3.8-27b) CI update on head 9a880e4 (verified live):
So the substantive gates (kernel-guard + test suite) are already green on the rebased head. I'll confirm lock-sync + the remaining guard lanes once the runner queue drains. No further code changes expected. |
(ai: vllm-qwen/qwen3.8-27b) Final CI status on head
What's verified: the fix is correct (manually traced the 6-message repro shape + 53 targeted kernel tests pass: issue7270 5 cases, issue4292 updated, issue4457/4570/5432, passthrough). The two CI reds (kernel-guard version collision, lock-sync) are fixed. What remains: the 5 full-regression test shards. Risk: low — this is a kernel wire-layout heal with no client/wire surface that would make the standard suite flaky; the targeted suite already passes. Verdict: ready for human review (kernel change → human-only per the Kernel Boundary, no auto-merge). I'll confirm the test shards the moment they land. Reminder from the review: #5800 (tool-delta relocate) should merge first — it touches the same |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1236-master.7652de9 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…nder golden conflict Master's hash-cleanup batches + kernel 0.0.200 bump (#7149/#7151/#7191/#7281) regenerated the storage-render goldens; the PR's lastFoldDrift field also touches them. Regenerated from the merged code so the snapshots reflect both; golden suite 5/5, PR test 3/3, typecheck clean. Built on the concurrent comment-fix commit 0cae5a0.
#7270 precede-heal Drive-by (review of #7281): the PR updated the isDirectiveOnlySystem comment but left three stale spots that now contradict the new behavior — - anthropic.ts heal comment: 'accepted at ANY position, so it is never healed' - issue5432 orphanSystems helper: still exempted directive-only on BOTH sides (a divergent mirror of the old behavior; the real heal now checks the PRECEDE side for them). Made the helper judge directive-only systems on the precede side only, matching healIllegalSystemPositions. - issue5432 test name + issue4292 header comment: 'exempt at any position' / 'directive-only anywhere'. All 53 targeted system-position tests still pass; kernel typecheck clean.
Rebasing #7281 onto master's kernel 0.0.199→0.0.200 bump left the root package-lock.json's kernel entry at 0.0.199. The kernel/ own lockfile was synced (88f6780) but the root lock was not, so lock-sync's 'npm install --package-lock-only' + 'git diff --exit-code -- package-lock.json' failed. Regenerated the root lockfile to record kernel 0.0.200.
kernel-change: the ANY-position exemption for directive-only systems (content:[] + output_config) does not hold on every upstream. A real Anthropic endpoint rejected system(directive)→user adjacency with the same 'must precede an assistant' 400 as content-bearing systems, permanently bricking the session after a degenerate fold.
Root cause:
isDirectiveOnlySystem()inkernel/src/wire/anthropic.tstreatscontent:[] + output_configas "legal at ANY position", sohealIllegalSystemPositionsunconditionally skips it (L443continue). After a degenerate fold reorders the wire, a directive-only system can land between two user messages — an illegal PRECEDE adjacency that the upstream rejects withmessages.N: role 'system' must precede an 'assistant' message or end the array. The session is permanently stuck because every retry resends the same layout.Fix:
healIllegalSystemPositionsnow checks the PRECEDE side for directive-only systems. If the system is followed by a non-assistant (illegal position), it is moved to the trailing run instead of being skipped. This preserves the effort/tool-control semantics (no re-voice to user) while landing the directive in a legal position. Legal positions (followed by assistant, or at array end) are untouched — prefix-cache stability preserved.Files changed:
kernel/src/wire/anthropic.ts—healIllegalSystemPositions: directive-only systems in illegal PRECEDE positions are spliced out and appended to the trailing run. Comment onisDirectiveOnlySystemupdated to reflect the [Bug][anthropic][opencode] 0.1.216: After degenerate fold, messages[2] system is dispatched as-is (bypassing the final h | [Bug][anthropic][opencode] 0.1.216: degenerate fold 后 messages[2] system 原样出站(越过最终 healAnthropicSystemPositions)→ 400 must precede … #7270 finding.kernel/package.json— version bump 0.0.198 → 0.0.199.kernel/tests/issue7270-directive-only-precede-heal.test.ts— new regression test: 5 cases (directive→user moved to end, directive→assistant stays, real 6-message shape, two negative guards).kernel/tests/issue4292-orphan-system-guard.test.ts— updated the "directive-only system adjacent to the anchor" test to reflect the new behavior (moved to trailing run instead of staying in place).Behavior change: directive-only systems (content:[] + output_config) in an illegal PRECEDE position (followed by a non-assistant) are now moved to the end of the messages array instead of being left in place. Previously they were skipped unconditionally on the assumption that Anthropic accepts them at any position. Legal positions (followed by assistant, or at array end) are unchanged.
Closes #7270