From e5dc7a8c4dca79de2d94912af7358be8d5718791 Mon Sep 17 00:00:00 2001 From: luvs01 Date: Mon, 10 Aug 2026 11:10:11 +0900 Subject: [PATCH] fix(kiro): gate diagnostic body encoding --- src/adapters/kiro.ts | 25 ++++++++++++++----------- tests/kiro-stream.test.ts | 13 +++++++++++++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/adapters/kiro.ts b/src/adapters/kiro.ts index 2ea1bc84d..4a4108d55 100644 --- a/src/adapters/kiro.ts +++ b/src/adapters/kiro.ts @@ -1,6 +1,7 @@ import { decodeEventStream } from "../lib/eventstream-decoder"; import { estimateTokens } from "../lib/token-estimate"; import { debugProviderDiagnostic } from "../lib/debug"; +import { isDebugEnabled } from "../lib/debug-settings"; import { resolveKiroApiRegion, resolveKiroProfileArn } from "../oauth/kiro"; import { KIRO_MODEL_CONTEXT_WINDOWS, normalizeKiroModelId } from "../providers/kiro-models"; import { modelRecordValue } from "../reasoning-effort"; @@ -1755,17 +1756,19 @@ export function createKiroAdapter(provider: OcxProviderConfig): ProviderAdapter await normalizeKiroImages(built.payload); const contextInputEstimate = estimateKiroPayloadInputTokens(built.payload, parsed.modelId); const body = JSON.stringify(built.payload); - debugProviderDiagnostic("kiro", "request", { - region, - requestedModel: parsed.modelId, - completionMode: built.completionMode, - bodyBytes: new TextEncoder().encode(body).length, - messageCount: kiroPayloadMessages(parsed).length, - toolCount: parsed.context.tools?.length ?? 0, - hasProfileArn: Boolean(profileArn), - wireClient, - hasPreviousResponseId: Boolean(parsed.previousResponseId), - }); + if (isDebugEnabled()) { + debugProviderDiagnostic("kiro", "request", { + region, + requestedModel: parsed.modelId, + completionMode: built.completionMode, + bodyBytes: new TextEncoder().encode(body).length, + messageCount: kiroPayloadMessages(parsed).length, + toolCount: parsed.context.tools?.length ?? 0, + hasProfileArn: Boolean(profileArn), + wireClient, + hasPreviousResponseId: Boolean(parsed.previousResponseId), + }); + } return { request: { url: kiroRuntimeEndpoint(provider, region), diff --git a/tests/kiro-stream.test.ts b/tests/kiro-stream.test.ts index 744fa8ab1..1928d757b 100644 --- a/tests/kiro-stream.test.ts +++ b/tests/kiro-stream.test.ts @@ -1728,6 +1728,19 @@ describe("kiro adapter — parseStream", () => { error.mockRestore(); } }); + + test("buildRequest does not encode the request body for diagnostics when debug is disabled", async () => { + const encode = spyOn(TextEncoder.prototype, "encode").mockImplementation(() => { + throw new Error("diagnostic encoding must stay behind the debug gate"); + }); + try { + const request = await createKiroAdapter(provider).buildRequest(parsedWith([{ role: "user", content: "hello" }])); + expect(typeof request.body).toBe("string"); + expect(encode).not.toHaveBeenCalled(); + } finally { + encode.mockRestore(); + } + }); }); describe("kiro adapter — parseResponse (web-search sidecar non-streaming path)", () => {