fix: allow bedrock signed thinking replay under anthropic policy

This commit is contained in:
Shakker
2026-04-12 05:27:03 +01:00
committed by Shakker
parent c6e2298950
commit 6ac482ca63
2 changed files with 35 additions and 10 deletions

View File

@@ -4,6 +4,9 @@ vi.mock("../plugins/provider-runtime.js", async () => {
const actual = await vi.importActual<typeof import("../plugins/provider-runtime.js")>(
"../plugins/provider-runtime.js",
);
const replayHelpers = await vi.importActual<
typeof import("../plugins/provider-replay-helpers.js")
>("../plugins/provider-replay-helpers.js");
return {
...actual,
resolveProviderRuntimePlugin: vi.fn(({ provider }: { provider?: string }) => {
@@ -51,7 +54,10 @@ vi.mock("../plugins/provider-runtime.js", async () => {
repairToolUseResultPairing: true,
validateAnthropicTurns: true,
allowSyntheticToolResults: true,
...(modelId.includes("claude") ? { dropThinkingBlocks: true } : {}),
...(modelId.includes("claude") &&
!replayHelpers.shouldPreserveThinkingBlocks(modelId)
? { dropThinkingBlocks: true }
: {}),
};
case "minimax":
case "minimax-portal":
@@ -71,7 +77,10 @@ vi.mock("../plugins/provider-runtime.js", async () => {
repairToolUseResultPairing: true,
validateAnthropicTurns: true,
allowSyntheticToolResults: true,
...(modelId.includes("claude") ? { dropThinkingBlocks: true } : {}),
...(modelId.includes("claude") &&
!replayHelpers.shouldPreserveThinkingBlocks(modelId)
? { dropThinkingBlocks: true }
: {}),
};
case "moonshot":
case "ollama":
@@ -182,9 +191,8 @@ let shouldAllowProviderOwnedThinkingReplay: typeof import("./transcript-policy.j
describe("resolveTranscriptPolicy", () => {
beforeAll(async () => {
({ resolveTranscriptPolicy, shouldAllowProviderOwnedThinkingReplay } = await import(
"./transcript-policy.js"
));
({ resolveTranscriptPolicy, shouldAllowProviderOwnedThinkingReplay } =
await import("./transcript-policy.js"));
});
beforeEach(() => {
@@ -421,6 +429,20 @@ describe("resolveTranscriptPolicy", () => {
).toBe(true);
});
it("allows immutable provider-owned thinking replay for bedrock claude replay policies", () => {
const policy = resolveTranscriptPolicy({
provider: "amazon-bedrock",
modelId: "us.anthropic.claude-opus-4-6-v1",
modelApi: "bedrock-converse-stream",
});
expect(
shouldAllowProviderOwnedThinkingReplay({
modelApi: "bedrock-converse-stream",
policy,
}),
).toBe(true);
});
it("does not allow immutable provider-owned thinking replay for strict openai-compatible replay", () => {
const policy = resolveTranscriptPolicy({
provider: "vllm",

View File

@@ -31,13 +31,16 @@ export type TranscriptPolicy = {
export function shouldAllowProviderOwnedThinkingReplay(params: {
modelApi?: string | null;
policy: Pick<TranscriptPolicy, "validateAnthropicTurns" | "preserveSignatures" | "dropThinkingBlocks">;
policy: Pick<
TranscriptPolicy,
"validateAnthropicTurns" | "preserveSignatures" | "dropThinkingBlocks"
>;
}): boolean {
return (
params.modelApi === "anthropic-messages" &&
params.policy.validateAnthropicTurns === true &&
params.policy.preserveSignatures === true &&
params.policy.dropThinkingBlocks !== true
isAnthropicApi(params.modelApi) &&
params.policy.validateAnthropicTurns &&
params.policy.preserveSignatures &&
!params.policy.dropThinkingBlocks
);
}