mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-22 08:03:40 +00:00
* fix(ai): strip Anthropic signed thinking when context prefix mutates (#4073) Anthropic preserved-thinking signatures bind to the exact conversation prefix. Step compression/prune and durable summary keep-tail were replaying later signed blocks after mutating earlier tool_results, causing stable 400 Invalid signature errors on long tool chats. Strip signed reasoning when prepareStep didAdjust, skip signatures on durable-summary tails, and one-shot retry after matching 400. * fix(ai): propagate Anthropic signature stream errors with progress-aware retry (#4074) P1-1: rethrow signature failures from cattyStreamProcessor error chunks (and reader catch) via createCattyAnthropicSignatureRetryError so the turn-driver strip-and-retry path can see them. P1-2: mirror the 413 hadToolProgress path on signature retry — rebuild from latest session, retain completed tool results, new assistant message, and enable write replay before stripping/retrying. * fix(ai): preserve plain-object Anthropic signature messages in retry wrapper (#4074) * fix(ai): only strip Anthropic signed thinking when provider allows removal (#4074) DeepSeek Anthropic-compat requires thinking blocks with replayed tool calls; gate durable-summary and prepareStep strips behind providerAllowsAnthropicSignedThinkingRemoval. Keep 400 invalid-signature strip-and-retry unchanged. * chore: retrigger CI after runner shutdown cancel on lint-and-test (#4074)
100 lines
3.8 KiB
TypeScript
100 lines
3.8 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
createCattyAnthropicSignatureRetryError,
|
|
createCattyRequestTooLargeRetryError,
|
|
hadToolProgressBeforeRequestTooLarge,
|
|
} from "./cattyRequestTooLargeRetry.ts";
|
|
import { isInvalidAnthropicThinkingSignatureError } from "./errorClassifier.ts";
|
|
|
|
test("createCattyRequestTooLargeRetryError marks 413 retry errors after tool progress", () => {
|
|
const source = Object.assign(new Error("HTTP 413 Request Entity Too Large"), {
|
|
status: 413,
|
|
responseBody: "<html>too large</html>",
|
|
});
|
|
|
|
const retryError = createCattyRequestTooLargeRetryError(source, true);
|
|
|
|
assert.equal(retryError.statusCode, 413);
|
|
assert.equal(retryError.status, 413);
|
|
assert.equal(retryError.responseBody, "<html>too large</html>");
|
|
assert.equal(retryError.cause, source);
|
|
assert.equal(hadToolProgressBeforeRequestTooLarge(retryError), true);
|
|
});
|
|
|
|
test("hadToolProgressBeforeRequestTooLarge is false when no tool progress was recorded", () => {
|
|
const retryError = createCattyRequestTooLargeRetryError("HTTP 413", false);
|
|
|
|
assert.equal(hadToolProgressBeforeRequestTooLarge(retryError), false);
|
|
assert.equal(hadToolProgressBeforeRequestTooLarge(new Error("HTTP 413")), false);
|
|
});
|
|
|
|
test("createCattyAnthropicSignatureRetryError preserves classifier fields and tool progress", () => {
|
|
const source = Object.assign(
|
|
new Error("Invalid signature in thinking block. The block is bound to a different conversation."),
|
|
{
|
|
statusCode: 400,
|
|
responseBody: JSON.stringify({
|
|
error: {
|
|
message: "Invalid signature in thinking block. The block is bound to a different conversation.",
|
|
},
|
|
}),
|
|
},
|
|
);
|
|
|
|
const retryError = createCattyAnthropicSignatureRetryError(source, true);
|
|
|
|
assert.equal(retryError.statusCode, 400);
|
|
assert.equal(retryError.responseBody, source.responseBody);
|
|
assert.equal(retryError.cause, source);
|
|
assert.equal(hadToolProgressBeforeRequestTooLarge(retryError), true);
|
|
assert.equal(isInvalidAnthropicThinkingSignatureError(retryError), true);
|
|
});
|
|
|
|
test("createCattyAnthropicSignatureRetryError defaults status 400 and no progress", () => {
|
|
const retryError = createCattyAnthropicSignatureRetryError(
|
|
"Invalid signature in thinking block. The block is bound to a different conversation.",
|
|
false,
|
|
);
|
|
|
|
assert.equal(retryError.statusCode, 400);
|
|
assert.equal(hadToolProgressBeforeRequestTooLarge(retryError), false);
|
|
assert.equal(isInvalidAnthropicThinkingSignatureError(retryError), true);
|
|
});
|
|
|
|
test("createCattyAnthropicSignatureRetryError preserves plain-object SSE signature message", () => {
|
|
const source = {
|
|
type: "invalid_request_error",
|
|
message: "Invalid signature in thinking block",
|
|
status: 400,
|
|
};
|
|
|
|
const retryError = createCattyAnthropicSignatureRetryError(source, false);
|
|
|
|
assert.equal(retryError.message, "Invalid signature in thinking block");
|
|
assert.notEqual(retryError.message, "[object Object]");
|
|
assert.equal(retryError.statusCode, 400);
|
|
assert.equal(retryError.status, 400);
|
|
assert.equal(retryError.cause, source);
|
|
assert.equal(isInvalidAnthropicThinkingSignatureError(retryError), true);
|
|
});
|
|
|
|
test("createCattyAnthropicSignatureRetryError preserves plain-object message with statusCode", () => {
|
|
const source = {
|
|
type: "invalid_request_error",
|
|
message: "Invalid signature in thinking block. The block is bound to a different conversation.",
|
|
statusCode: 400,
|
|
};
|
|
|
|
const retryError = createCattyAnthropicSignatureRetryError(source, true);
|
|
|
|
assert.equal(
|
|
retryError.message,
|
|
"Invalid signature in thinking block. The block is bound to a different conversation.",
|
|
);
|
|
assert.equal(retryError.statusCode, 400);
|
|
assert.equal(hadToolProgressBeforeRequestTooLarge(retryError), true);
|
|
assert.equal(isInvalidAnthropicThinkingSignatureError(retryError), true);
|
|
});
|