From c3121edceada069988d5530531f7670b77c00b3a Mon Sep 17 00:00:00 2001 From: Sorin Albu-Irimies Date: Wed, 14 Oct 2026 17:54:51 +0200 Subject: [PATCH 1/3] fix(server): redacted_thinking arms the #651 reasoning-drop gate (#1960) withReasoningDrop only treated a signed reasoning message as signed thinking. redacted_thinking rides as a text message with rawAnthropicBlock, so it never armed the gate; dropping the sibling reasoning run rewrote the latest assistant message -> 400 'thinking or redacted_thinking blocks ... cannot be modified'. --- src/server.ts | 15 ++++++++++++++- tests/reasoning-echo.test.ts | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index 18bfa16398..6365ccfc04 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1560,6 +1560,14 @@ const ACP_TAG_MARK = "\x3cacp "; // nonexistent (preflight), so acp_summary survives as the carrier and // systemToUser later re-voices the survivors as USER messages (leaving them at // their anchors) for strict backends (#377). +/** True for a signed Anthropic thinking-family message: a reasoning message + * with a signature, or a verbatim redacted_thinking block sidecar. */ +function hasSignedThinkingBlock(m: BiliMessage): boolean { + if (m.contentType === "reasoning") return typeof m.thinkingSignature === "string" && m.thinkingSignature.length > 0; + const raw = m.rawAnthropicBlock as { type?: unknown } | undefined; + return raw?.type === "redacted_thinking"; +} + /** [#651] Strip oversized reasoning from closed compress turns (see * src/reasoning-drop.ts) with an ops log line when anything was dropped. */ export function withReasoningDrop( @@ -1581,7 +1589,12 @@ export function withReasoningDrop( // any signed thinking in view disables the drop for this request. // Presence-based and per-request: Claude sessions without extended // thinking keep #651's savings. - if (msgs.some((m) => m.contentType === "reasoning" && typeof m.thinkingSignature === "string" && m.thinkingSignature.length > 0)) return msgs; + // [#1960] redacted_thinking blocks are signed too, but the kernel codec + // carries them as a `text` message whose rawAnthropicBlock is the verbatim + // block (never contentType "reasoning"), so they must arm the gate as well: + // dropping a sibling reasoning run rewrites the assistant message that + // holds them -> "thinking or redacted_thinking blocks ... cannot be modified". + if (msgs.some(hasSignedThinkingBlock)) return msgs; const out = dropCompressReasoning(msgs, reasoning); if (out.length !== msgs.length) { log("info", `[${sessionId}] compress-reasoning: dropped ${msgs.length - out.length} reasoning message(s) from closed compress turns (#651)`); diff --git a/tests/reasoning-echo.test.ts b/tests/reasoning-echo.test.ts index 2407fb98c8..c9fd109088 100644 --- a/tests/reasoning-echo.test.ts +++ b/tests/reasoning-echo.test.ts @@ -647,6 +647,14 @@ describe("#1658 anthropic signed-thinking gate (#651 drop vs #684 pair invariant assert.equal(c.lines.length, 1); }); + it("redacted_thinking in view disables the #651 drop (#1960)", () => { + const redacted: BiliMessage = { id: "rd", role: "assistant", contentType: "text", text: "[redacted_thinking]", rawAnthropicBlock: { type: "redacted_thinking", data: "ZGF0YQ==" } }; + const msgs: BiliMessage[] = [{ id: "r", role: "assistant", contentType: "reasoning", text: "x".repeat(3000) }, redacted, CALL(), RESULT(), USER()]; + const c = collector(); + assert.equal(withReasoningDrop(msgs, undefined, c.log, "s1", false), msgs); + assert.equal(c.lines.length, 0); + }); + it("empty-string signature does not arm the gate", () => { const msgs: BiliMessage[] = [{ id: "r", role: "assistant", contentType: "reasoning", text: "x".repeat(3000), thinkingSignature: "" }, CALL(), RESULT(), USER()]; const c = collector(); From 81ed5f36e0ac1d395fbc34d02c71d176a172cf1f Mon Sep 17 00:00:00 2001 From: awork Date: Thu, 15 Oct 2026 00:27:13 +0800 Subject: [PATCH 2/3] test(server): give the #1960 redacted_thinking gate test real teeth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review fix for PR #3196 (external contribution, aligned per repo review policy). The original test placed the redacted carrier AFTER the reasoning run, where dropCompressReasoning's contiguity walk stops immediately — nothing was ever dropped, so the test passed against the pre-fix code too (verified empirically). Reordered so the redacted block shares the assistant message prefix of the dropped run (the shape coreToAnthropic merges into one rewritten API message), and added a wire-level regression case through anthropicToCore/coreToAnthropic pinning both the kernel side-car shape and the no-rewrite guarantee. --- tests/reasoning-echo.test.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/reasoning-echo.test.ts b/tests/reasoning-echo.test.ts index c9fd109088..f44bd85848 100644 --- a/tests/reasoning-echo.test.ts +++ b/tests/reasoning-echo.test.ts @@ -648,13 +648,34 @@ describe("#1658 anthropic signed-thinking gate (#651 drop vs #684 pair invariant }); it("redacted_thinking in view disables the #651 drop (#1960)", () => { + // The redacted carrier must sit BEFORE the reasoning run: coreToAnthropic merges same-role messages into one assistant message, so dropping the run rewrites the message carrying the redacted block. Placed after the run it would break contiguity and the drop never fires at all (test would pass without the fix). const redacted: BiliMessage = { id: "rd", role: "assistant", contentType: "text", text: "[redacted_thinking]", rawAnthropicBlock: { type: "redacted_thinking", data: "ZGF0YQ==" } }; - const msgs: BiliMessage[] = [{ id: "r", role: "assistant", contentType: "reasoning", text: "x".repeat(3000) }, redacted, CALL(), RESULT(), USER()]; + const msgs: BiliMessage[] = [redacted, { id: "r", role: "assistant", contentType: "reasoning", text: "x".repeat(3000) }, CALL(), RESULT(), USER()]; const c = collector(); assert.equal(withReasoningDrop(msgs, undefined, c.log, "s1", false), msgs); assert.equal(c.lines.length, 0); }); + const reproInboundRedacted: AnthropicMessage[] = [ + { role: "user", content: "q" }, + { role: "assistant", content: [{ type: "redacted_thinking", data: "ZGF0YQ==" }, { type: "thinking", thinking: "x".repeat(3000) }, { type: "tool_use", id: "tu1", name: "compress", input: {} }] }, + { role: "user", content: [{ type: "tool_result", tool_use_id: "tu1", content: "ok" }] }, + { role: "user", content: "next" }, + ]; + + it("regression: unsigned thinking beside a redacted block no longer drops (#1960 wire shape)", () => { + const { msgs } = anthropicToCore({ model: "claude-opus-4-5", messages: reproInboundRedacted }); + assert.ok(msgs.some((m) => m.rawAnthropicBlock !== undefined && (m.rawAnthropicBlock as { type?: string }).type === "redacted_thinking")); + const c = collector(); + const out = withReasoningDrop(msgs, undefined, c.log, "s1", false); + assert.equal(out, msgs); + assert.equal(c.lines.length, 0); + const outbound = coreToAnthropic(out); + const assistantOut = outbound[1]!; + assert.ok(Array.isArray(assistantOut.content)); + assert.equal(assistantOut.content.length, 3); + }); + it("empty-string signature does not arm the gate", () => { const msgs: BiliMessage[] = [{ id: "r", role: "assistant", contentType: "reasoning", text: "x".repeat(3000), thinkingSignature: "" }, CALL(), RESULT(), USER()]; const c = collector(); From 06b5a0c735913837193588446e422734c753635d Mon Sep 17 00:00:00 2001 From: Sorin Albu-Irimies Date: Wed, 14 Oct 2026 18:12:28 +0200 Subject: [PATCH 3/3] ci: retrigger (unrelated opencode e2e flake)