codex: cap injected default instructions

This commit is contained in:
Finessse
2025-12-17 17:06:41 +07:00
parent ef732615a4
commit b1b30d10ea
2 changed files with 10 additions and 0 deletions
@@ -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)
}
@@ -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
}