From b1b30d10eae364c25ecdb348fd3cbd2157cc86aa Mon Sep 17 00:00:00 2001 From: Finessse Date: Wed, 17 Dec 2025 17:06:41 +0700 Subject: [PATCH] codex: cap injected default instructions --- .../codex/openai/chat-completions/codex_openai_request.go | 5 +++++ .../codex/openai/responses/codex_openai-responses_request.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/internal/translator/codex/openai/chat-completions/codex_openai_request.go b/internal/translator/codex/openai/chat-completions/codex_openai_request.go index 6e790ee5..29d9a8a6 100644 --- a/internal/translator/codex/openai/chat-completions/codex_openai_request.go +++ b/internal/translator/codex/openai/chat-completions/codex_openai_request.go @@ -137,6 +137,11 @@ func ConvertOpenAIRequestToCodex(modelName string, inputRawJSON []byte, stream b out, _ = sjson.Set(out, "instructions", systemInstructions) } else { _, instructions := misc.CodexInstructionsForModel(modelName, "") + // Keep this short: upstream validators can reject large instruction blocks. + const maxInstructionsChars = 1024 + if len(instructions) > maxInstructionsChars { + instructions = instructions[:maxInstructionsChars] + "\n...[truncated]..." + } out, _ = sjson.Set(out, "instructions", instructions) } diff --git a/internal/translator/codex/openai/responses/codex_openai-responses_request.go b/internal/translator/codex/openai/responses/codex_openai-responses_request.go index 0532d28f..dea6d945 100644 --- a/internal/translator/codex/openai/responses/codex_openai-responses_request.go +++ b/internal/translator/codex/openai/responses/codex_openai-responses_request.go @@ -94,6 +94,11 @@ func ConvertOpenAIResponsesRequestToCodex(modelName string, inputRawJSON []byte, } // Otherwise, inject standard Codex instructions. + // Keep this short: upstream validators can reject large instruction blocks. + const maxInstructionsChars = 1024 + if len(instructions) > maxInstructionsChars { + instructions = instructions[:maxInstructionsChars] + "\n...[truncated]..." + } rawJSON, _ = sjson.SetBytes(rawJSON, "instructions", instructions) return rawJSON }