Skip to content

[PR] fix: drop signature-less thinking blocks for upstreams that reject them (#5998) - #6009

Merged
ranxianglei merged 3 commits into
masterfrom
2026-11-09_unsigned-thinking-egress
Nov 9, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-11-09_unsigned-thinking-egress

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #5998

Problem

DSH transcripts store reasoning blocks as {type, text} without signatures. Every turn rebuilt from such history carries signature-less thinking blocks, which signature-verifying upstreams (Anthropic proper) reject with "thinking.signature: Field required" (#2501). The mid-session opus→sonnet switch in the report amplifies it: signatures are bound to the producing model.

Mechanism verified in code: kernel anthropicToCore stamps thinkingSignature only when the inbound block carries one, while coreToAnthropic re-emits EVERY reasoning core as a thinking block — unsigned cores produce signature-less blocks on the wire.

Why not a static rule

The two affected upstream personalities are byte-indistinguishable on the inbound wire: never-signing relays (DeepSeek's /anthropic endpoint, #5495) require exactly those unsigned blocks back VERBATIM ("must be passed back"). A renderer-level drop would break #5495; forwarding everything breaks #5998. So the personality is LEARNED instead of guessed:

Behavior change disclosure (old → new)

  • Egress of unsigned thinking (anthropic lane) — old: always forwarded ⇒ guaranteed 400 on every rebuilt turn against signing upstreams (DSH→Anthropic unusable after self-compression). new: forwarded by default (status quo, keeps Anthropic-wire upstream without thinking signatures (DeepSeek /anthropic): compress re-request drops reasoning from the tool_use replay → 400 "content[].thinking must be passed back" #5495 verbatim replay); once a session's upstream proves strict via one "Field required" 400, that session drops unsigned thinking proactively before send. Cost: one internal 400+retry at first detection, transparent to the client. Posture is session-scoped (session.metadata.thinkingSignatureStrict, persisted with the session record); NO new config surface.
  • Thinking-pair sentinel — old: ANY inbound thinking block counted as a replayable asset, so its loss warned. new: only blocks with a non-empty string signature count; lost unsigned pairs stay silent. Reason: with proactive drops in place, counting unsigned blocks would false-positive on every learned-strict session (verified against the DSH shape in tests/reasoning-echo.test.ts).

Residual seams (noted, deliberately not fixed here)

The probe seam covers the main relay path (forwardCaptured). Egress paths that do NOT pass through it: the count-tokens request builder (src/server.ts), incremental-lane render (src/incremental-lane.ts), plugin-render legacy stored rows (src/plugin-render.ts), WS lane egress. The acp-loop re-request path already self-heals today via its existing degraded strip-retry (src/loop/core.ts) — "Field required" matches none of its exclusion clauses, so it strips and retries per occurrence without this change.

Tests

…em (#5998)

DSH transcripts store reasoning as {type, text} without signatures, so every
rebuilt turn carries signature-less thinking blocks that signature-verifying
upstreams (Anthropic proper) reject with "thinking.signature: Field required"
(#2501). The affected upstream personalities are byte-indistinguishable on the
inbound wire - never-signing relays (DeepSeek /anthropic, #5495) require those
same unsigned blocks back verbatim - so no static rule can discriminate; learn
the personality instead:

- src/server/thinking-posture.ts (new): the 400-wording detector, the
  wire-level strip (signed blocks and redacted_thinking pass byte-exact,
  KDD#10), and the session-scoped posture.
- relay egress seam (src/server/relay.ts): the first "Field required" 400 on
  an anthropic-lane send triggers ONE strip-and-resend probe (same
  controlled-experiment discipline as the #2645 pck ladder); accepted => the
  session remembers strict posture and later sends drop unsigned thinking
  proactively before egress; still failing => original 400 forwarded verbatim,
  nothing learned. #5495 "must be passed back" and #1960 "cannot be
  modified" wordings never enter the probe.
- warnAnthropicThinkingPairs: inbound scan narrowed to SIGNED thinking only -
  an unsigned block is never a replayable asset on any upstream, so its
  absence from a rebuilt request is by design, not a violation.
- WC-024 wire-contract ledger entry + validator clause shared by both
  anthropic lanes (main + Vertex) + gate test + ledger self-check probe row.
@ranxianglei ranxianglei changed the title fix: drop signature-less thinking blocks for upstreams that reject them (#5998) [PR] fix: drop signature-less thinking blocks for upstreams that reject them (#5998) Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-09_unsigned-thinking-egress (6f20f3a)

Latest build — install this exact version

npm install -g billion-context@0.0.8763-pr.6009.89cab6d

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
6f20f3a billion-context@0.0.8763-pr.6009.89cab6d build
287c48c billion-context@0.0.8760-pr.6009.a88fd4d build
474bc69 billion-context@0.0.8757-pr.6009.fb88393 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr6009.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei ranxianglei added bug Something isn't working dsh p1 labels Nov 9, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重: 不重复 — GitHub PR #6009 (head 474bc69) is the only open PR addressing the #5998 unsigned-thinking egress defect. Related threads it cites (#2501 original "Field required" report, #5495 never-signing-relay verbatim constraint, #1960 no-tamper rule, #2645 controlled-experiment probe discipline) are constraints on the design, not parallel fixes; no other open [PR] row targets this mechanism.

标签: bug + dsh + scope/wiring + p1 — DSH transcripts rebuilt against signature-verifying upstreams get a guaranteed 400 on every turn after self-compression: that lane is unusable in that scenario, hence p1; the change lives in the request pipeline/wire egress (new src/server/thinking-posture.ts + relay seam), no kernel change.

This is a [PR] thread, so I am reviewing, not redoing: pulling head 474bc69, reading the diff against KDD#10 and the wire-fidelity rules, running the targeted suites locally, and checking CI state on the pushed head. Initial observation from the mirror cache: the check run at this sha shows jobs as skipped with mergeable-state blocked — investigating whether that's path-filtering or a real gate problem before concluding. Full verdict follows in the structured eight-question format.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

CI fix run for PR #6009 (head now 6f20f3a): the unused-exports gate is fixed and green.

What I verified first (live): mirror cache showed architecture-docs already SUCCESS at head 287c48c (that failure was closed by the docs-registration commit itself); the only red job was unused-exports, which flagged INTERNAL_ONLY src/server/thinking-posture.ts: UnsignedThinkingStrip.

Fix: UnsignedThinkingStrip is only used as the return type of stripUnsignedThinkingFromWire inside its own file (grep over src/ + tests/ confirmed zero external imports), so the mechanical fix is dropping the leading export. Local guard run after the edit: ✓ unused-export gate: clean (8 waived). Note: a concurrent fix lane had already pushed the identical one-line change (commit 6f20f3a "keep UnsignedThinkingStrip module-internal"); my rebase onto the remote head detected it as already-applied and skipped my duplicate — branch left untouched beyond that, no force-push, no fight.

Live state after the fix (one-off check-run fetch at 06:3x UTC since the mirror cache snapshot was stale): unused-exports = success on 6f20f3a; 40 checks success, 0 failures, 16 test/static-gates jobs still in flight. If any of those turn red, the blocker detector will wake the lane again.


七问(CI 修复轮)

  1. 是什么问题:CI 门禁 unused-exports 红——新模块 src/server/thinking-posture.ts 导出的 UnsignedThinkingStrip 接口在模块外无人使用。
  2. 什么原因导致的:PR [PR] fix: drop signature-less thinking blocks for upstreams that reject them (#5998) #6009 新增该模块时把内部返回类型接口也加了 export;仓库的未用导出门禁要求模块内类型去掉导出(或列入 WAIVERS),提交时漏掉了这一步。
  3. 影响范围与严重程度:仅 CI 门禁层面,不影响运行时行为、不面向用户;严重度=合入门禁被卡。
  4. 怎么修复的:删掉接口声明前的 export(改为模块私有),一行改动;本地跑 node scripts/check-unused-exports.mjs 确认转绿。
  5. 是否有回归问题:无。该接口全仓(src/+tests/)无外部引用,grep 已钉死;项目不发 d.ts(无 tsup declaration 配置),不存在 TS4023「导出函数引用私有类型」风险;运行时字节零变化。
  6. 是否破坏缓存:不涉及——纯源码导出可见性改动,不动任何缓存键/重试/游标。
  7. 当前状态:head 6f20f3a 上 unused-exports 已绿;其余测试分片仍在跑(40 绿/0 红/16 进行中)。说明:本工作区无 node_modules,本地无法跑 typecheck/build,由 CI test 车道做最终裁决;若后续分片变红,阻塞检测会再次唤醒本车道处理。

收工判定:本轮唯一红灯(unused-exports)已修并验证为绿,分支无其他待修项,交还 CI 收尾。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Review verdict: LGTM — code is merge-quality. I reviewed the FINAL head 6f20f3a (head moved twice during review: 287c48c registered the new module in the architecture map, then 6f20f3a fixed the failed unused-exports lane by making UnsignedThinkingStrip module-internal — that fix is correct: tsup emits no .d.ts, so a non-exported interface in an exported signature is safe).

What I independently verified (not just read from the PR description):

Code vs constraints

Regression audit (existing behavior on touched paths)

  • Non-strict sessions: zero behavior change — gate short-circuits, zero byte diff on egress.
  • 400-forward semantics unchanged: no match / probe fails → original bytes/status/headers forwarded.
  • warnAnthropicThinkingPairs narrowing (unsigned loss silent, signed loss still warns) is intentional, disclosed in the PR, pinned both directions.
  • WC-024 ledger entry is additive-only (§7.3 grow-only honored). No kernel/, no config surface, no persistence-format change, no new deps.
  • Cache: strict sessions' outbound bytes change deterministically once, after the first accepted probe; prefix stable thereafter. All other sessions: zero byte change.

Local targeted runs at head 6f20f3a: issue5998 suite 16/16, reasoning-echo + wire-contract 87/87, issue5495-replay + anthropic-truncation 10/10, unused-exports gate clean, tsc --noEmit exit 0.

CI (live-verified): core matrix fully green on 6f20f3a — 14/14 runnable checks passed (test shards ubuntu 22/24 ×3, windows 22 ×5, static-gates ×2, mysql-contract); the 16 skipped lanes are skip-by-design for plain PRs under three-layer CI (#3295: real-client e2e lanes run on ci:full/dispatch/cron only). One nuance worth knowing: master's branch protection lists 14 required test contexts INCLUDING the three windows node-24 legs, which exist only in FULL scope — so GitHub keeps the computed merge state at blocked until a ci:full run posts them. This matches how recently merged PRs shipped (e.g. #5966, merged today with zero windows-24 legs at merge). If you want the full matrix before merging, add the ci:full label; otherwise it merges on owner bypass like its siblings.

One flagged edge (non-blocking): the strict posture is sticky for the session life with no forgetting. If a session later routes to a never-signing relay that wants unsigned blocks verbatim, the learned posture keeps stripping them → standing "must be passed back" 400s until a new session. Candidate follow-up in this thread: unlearn the posture on the opposing wording. Not blocking — it needs a mid-session route switch, and the failure mode is a clean 400, not corruption. Residual seams (count-tokens builder, incremental-lane render, plugin-render legacy rows, WS egress) are already disclosed in the PR body and self-heal via the existing degraded strip-retry.

八问(中文结构化结论)

  1. 是什么问题:DSH 等宿主的历史里带无签名 thinking 块,重放给要求签名的上游(如 anthropic.com)时每次请求都 400「Field required」,该宿主×上游组合完全不可用。
  2. 什么原因导致的:无签名 thinking 块是宿主侧合法产物,但严格上游回放时强制要签名;bili 出站侧此前没有针对这一类拒绝的处理机制(与 [acp-loop] In-turn compress re-request edits the latest assistant message → Anthropic 400 "thinking blocks … cannot be modified" (session stays broken) #1960 篡改拒、Anthropic-wire upstream without thinking signatures (DeepSeek /anthropic): compress re-request drops reasoning from the tool_use replay → 400 "content[].thinking must be passed back" #5495 必回传拒是三类措辞不同的 400)。
  3. 影响范围与严重程度:仅当会话历史含无签名 thinking 块且路由到签名上游时触发(典型:DSH 转录打 anthropic.com);该场景完全不可用(每请求 400)→ p1;其余会话零影响。
  4. 怎么修复的:在 relay 出站缝做「失败学习探测」(沿用 openai wire: prompt_cache_key stamped unconditionally — breaks strict-schema upstreams (NVIDIA NIM 400), no config escape #2645 pck 梯子的受控实验纪律):命中签名必需措辞的 400 → 用剥掉无签名块的同一请求重试一次,被接受才记住会话级 strict 姿态,之后每轮发送前主动剥离。只删本来就不可回放的块;有签名/redacted 块字节原样透传。
  5. 是否有回归问题:审过既有行为——非 strict 会话零变化(门短路、出站零字节差);400 转发语义不变(不匹配/探测失败时原样转发);warnAnthropicThinkingPairs 收窄(无签名丢失静默、有签名仍告警)为有意变更已披露且双向钉死测试;WC-024 账本只增不减;未动 kernel/config/持久化格式/依赖。一个非阻塞边缘:姿态终身粘滞不会遗忘——会话中途切到不回签名的中继会持续误剥(建议后续在本线程补「反向措辞即遗忘」,不拦合并)。
  6. 是否破坏缓存:非 strict 会话不受影响;strict 会话在首次探测被接受后出站字节一次性确定性改写,之后前缀稳定,后续轮次正常命中前缀缓存。
  7. 是否改了设计方向:没有——把既有的失败学习模式延伸到同一出站缝的第二种病理,新模块已登记进架构地图,无架构转向。
  8. 是否引入了新的配置:没有新增 env/config/CLI;thinkingSignatureStrict 是会话内部状态键,不是配置面。

收工判定:代码质量达标、回归面审过、定向验证全绿,可以合并。合并动作按仓库惯例由你执行:core-scope 下 GitHub 会因 windows-24 必需项未跑而保持 blocked(与 #5966 等近期 PR 的合并路径一致);想要全量矩阵就先加 ci:full 标签再合。

@ranxianglei
ranxianglei merged commit 4be21b0 into master Nov 9, 2026
56 checks passed
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1118-master.4be21b0 (rolling master tag).

npm install -g billion-context@0.0.1118-master.4be21b0  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Nov 10, 2026
Master-side commit 6b0cb61 (#6009) added tests/storage-null-identity.test.ts
pinning migrated.to / migrateSchema().from at 11 — master's newest schema at
the time it was written. This PR intentionally bumps STORAGE_SCHEMA_VERSION to
12 (src/storage/schema.ts) and already carries updated pins in its own
migration tests; the master-added test was written against the pre-bump tree,
so its two pins collide after the merge and fail deterministically on every
shard. Update both values 11 -> 12; no product-code change.
ranxianglei pushed a commit that referenced this pull request Nov 11, 2026
Master-side commit 6b0cb61 (#6009) added tests/storage-null-identity.test.ts
pinning migrated.to / migrateSchema().from at 11 — master's newest schema at
the time it was written. This PR intentionally bumps STORAGE_SCHEMA_VERSION to
12 (src/storage/schema.ts) and already carries updated pins in its own
migration tests; the master-added test was written against the pre-bump tree,
so its two pins collide after the merge and fail deterministically on every
shard. Update both values 11 -> 12; no product-code change.
ranxianglei pushed a commit that referenced this pull request Nov 14, 2026
Master-side commit 6b0cb61 (#6009) added tests/storage-null-identity.test.ts
pinning migrated.to / migrateSchema().from at 11 — master's newest schema at
the time it was written. This PR intentionally bumps STORAGE_SCHEMA_VERSION to
12 (src/storage/schema.ts) and already carries updated pins in its own
migration tests; the master-added test was written against the pre-bump tree,
so its two pins collide after the merge and fail deterministically on every
shard. Update both values 11 -> 12; no product-code change.
ranxianglei pushed a commit that referenced this pull request Nov 14, 2026
Master-side commit 6b0cb61 (#6009) added tests/storage-null-identity.test.ts
pinning migrated.to / migrateSchema().from at 11 — master's newest schema at
the time it was written. This PR intentionally bumps STORAGE_SCHEMA_VERSION to
12 (src/storage/schema.ts) and already carries updated pins in its own
migration tests; the master-added test was written against the pre-bump tree,
so its two pins collide after the merge and fail deterministically on every
shard. Update both values 11 -> 12; no product-code change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dsh p1 scope/wiring

Projects

None yet

1 participant