fix: omit empty signature field from thinking blocks

Emit signature only when non-empty in both streaming content_block_start
and non-streaming thinking blocks. Avoids turning 'missing signature'
into 'empty/invalid signature' which Claude clients may reject.
This commit is contained in:
Ravi Tharuma
2026-03-25 07:44:21 +01:00
parent c31ae2f3b5
commit 73b22ec29b
2 changed files with 9 additions and 7 deletions

View File

@@ -84,7 +84,7 @@ func ConvertCodexResponseToClaude(_ context.Context, _ string, originalRequestRa
if params.ThinkingBlockOpen && params.ThinkingStopPending {
output = append(output, finalizeCodexThinkingBlock(params)...)
}
template = []byte(`{"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":"","signature":""}}`)
template = []byte(`{"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":""}}`)
template, _ = sjson.SetBytes(template, "index", params.BlockIndex)
params.ThinkingBlockOpen = true
params.ThinkingStopPending = false
@@ -270,9 +270,11 @@ func ConvertCodexResponseToClaudeNonStream(_ context.Context, _ string, original
}
}
if thinkingBuilder.Len() > 0 || signature != "" {
block := []byte(`{"type":"thinking","thinking":"","signature":""}`)
block := []byte(`{"type":"thinking","thinking":""}`)
block, _ = sjson.SetBytes(block, "thinking", thinkingBuilder.String())
block, _ = sjson.SetBytes(block, "signature", signature)
if signature != "" {
block, _ = sjson.SetBytes(block, "signature", signature)
}
out, _ = sjson.SetRawBytes(out, "content.-1", block)
}
case "message":

View File

@@ -40,8 +40,8 @@ func TestConvertCodexResponseToClaude_StreamThinkingIncludesSignature(t *testing
case "content_block_start":
if data.Get("content_block.type").String() == "thinking" {
startFound = true
if !data.Get("content_block.signature").Exists() {
t.Fatalf("thinking start block missing signature field: %s", line)
if data.Get("content_block.signature").Exists() {
t.Fatalf("thinking start block should NOT have signature field when signature is unknown: %s", line)
}
}
case "content_block_delta":
@@ -97,8 +97,8 @@ func TestConvertCodexResponseToClaude_StreamThinkingWithoutReasoningItemStillInc
data := gjson.Parse(strings.TrimPrefix(line, "data: "))
if data.Get("type").String() == "content_block_start" && data.Get("content_block.type").String() == "thinking" {
thinkingStartFound = true
if !data.Get("content_block.signature").Exists() {
t.Fatalf("thinking start block missing signature field: %s", line)
if data.Get("content_block.signature").Exists() {
t.Fatalf("thinking start block should NOT have signature field without encrypted_content: %s", line)
}
}
if data.Get("type").String() == "content_block_stop" && data.Get("index").Int() == 0 {