mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
fix(codex): normalize small output budgets for all source formats
- Raise positive integer max_output_tokens below 16 to the Codex minimum on the translated payload across HTTP and WebSocket paths, before user payload rules. - Send inference verification with a 16-token budget so healthy Codex OAuth credentials are no longer rejected by the upstream minimum. - Add regression coverage for VerifyInference and small budgets from every Codex source format. Closes: #7304
This commit is contained in:
@@ -89,7 +89,9 @@ func TestCodexClaudeOutputBudgetBoundariesAndPayloadRules(t *testing.T) {
|
||||
{name: "fallback field", field: `,"max_output_tokens":1`, want: "16"},
|
||||
{name: "zero remains invalid", field: `,"max_tokens":0`, want: "0"},
|
||||
{name: "negative remains invalid", field: `,"max_tokens":-1`, want: "-1"},
|
||||
{name: "fractional input is not normalized", field: `,"max_tokens":1.5`, want: "1"},
|
||||
// The Claude translator truncates 1.5 to the integer 1 before the executor
|
||||
// sees it, so the translated payload carries a sub-minimum integer budget.
|
||||
{name: "fractional input truncated by translator", field: `,"max_tokens":1.5`, want: "16"},
|
||||
{name: "non-numeric input", field: `,"max_tokens":"1"`},
|
||||
{
|
||||
name: "override matches normalized value", field: `,"max_tokens":1`, want: "8",
|
||||
@@ -99,7 +101,7 @@ func TestCodexClaudeOutputBudgetBoundariesAndPayloadRules(t *testing.T) {
|
||||
name: "final filter wins", field: `,"max_tokens":1`,
|
||||
payload: config.PayloadConfig{Filter: []config.PayloadFilterRule{{Models: modelRule, Params: []string{"max_output_tokens"}}}},
|
||||
},
|
||||
{name: "native responses unchanged", field: `,"max_output_tokens":1`, from: sdktranslator.FormatOpenAIResponse, want: "1"},
|
||||
{name: "native responses normalized", field: `,"max_output_tokens":1`, from: sdktranslator.FormatOpenAIResponse, want: "16"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
for _, useWebsocket := range []bool{false, true} {
|
||||
|
||||
@@ -58,7 +58,7 @@ func (e *CodexExecutor) Execute(ctx context.Context, auth *cliproxyauth.Auth, re
|
||||
}
|
||||
originalTranslated = helps.SetStringIfDifferent(originalTranslated, "model", baseModel)
|
||||
doc := ojson.NewDoc(body)
|
||||
normalizeCodexClaudeOutputBudgetDoc(doc, from, req.Payload)
|
||||
normalizeCodexOutputBudgetDoc(doc)
|
||||
helps.SetStringIfDifferentDoc(doc, "model", baseModel)
|
||||
|
||||
if err = helps.ApplyRequestThinkingDoc(doc, req, opts, from.String(), to.String(), e.Identifier(), updatesChanged); err != nil {
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
package executor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/MoeForge/moego/ojson"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/router-for-me/CLIProxyAPI/v8/internal/config"
|
||||
"github.com/router-for-me/CLIProxyAPI/v8/internal/registry"
|
||||
_ "github.com/router-for-me/CLIProxyAPI/v8/internal/translator"
|
||||
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/auth"
|
||||
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/executor"
|
||||
sdktranslator "github.com/router-for-me/CLIProxyAPI/v8/sdk/translator"
|
||||
)
|
||||
|
||||
// codexMinimumBudgetUpstream is a simplified lower-bound-only model of the ChatGPT
|
||||
// Codex backend for this regression test: it records every body, rejects any numeric
|
||||
// max_output_tokens below 16 (integer or fractional, so the floor is the only rule
|
||||
// exercised), and accepts absent or non-numeric values. It does not model the real
|
||||
// backend's full input validation.
|
||||
func codexMinimumBudgetUpstream(t *testing.T) (*httptest.Server, <-chan []byte) {
|
||||
t.Helper()
|
||||
requests := make(chan []byte, 4)
|
||||
completed := `{"type":"response.completed","response":{"id":"resp_1","object":"response","status":"completed","model":"gpt-5.6-sol","output":[{"type":"message","role":"assistant","content":[{"type":"output_text","text":"Hi"}]}],"usage":{"input_tokens":1,"output_tokens":1,"total_tokens":2}}}`
|
||||
accepts := func(body []byte) bool {
|
||||
value := ojson.GetBytes(body, "max_output_tokens")
|
||||
return !value.Exists() || value.Type != ojson.Number || value.Int() >= 16
|
||||
}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("Upgrade") == "websocket" {
|
||||
upgrader := websocket.Upgrader{CheckOrigin: func(*http.Request) bool { return true }}
|
||||
conn, errUpgrade := upgrader.Upgrade(w, r, nil)
|
||||
if errUpgrade != nil {
|
||||
t.Errorf("upgrade: %v", errUpgrade)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if errClose := conn.Close(); errClose != nil {
|
||||
t.Errorf("close websocket: %v", errClose)
|
||||
}
|
||||
}()
|
||||
_, body, errRead := conn.ReadMessage()
|
||||
if errRead != nil {
|
||||
t.Errorf("read websocket request: %v", errRead)
|
||||
return
|
||||
}
|
||||
requests <- body
|
||||
if !accepts(body) {
|
||||
_ = conn.WriteMessage(websocket.TextMessage, []byte(`{"type":"error","error":{"type":"invalid_request_error","message":"Invalid 'max_output_tokens': integer below minimum value. Expected a value >= 16."}}`))
|
||||
return
|
||||
}
|
||||
if errWrite := conn.WriteMessage(websocket.TextMessage, []byte(completed)); errWrite != nil {
|
||||
t.Errorf("write websocket response: %v", errWrite)
|
||||
}
|
||||
return
|
||||
}
|
||||
body, errRead := io.ReadAll(r.Body)
|
||||
if errRead != nil {
|
||||
t.Errorf("read HTTP request: %v", errRead)
|
||||
return
|
||||
}
|
||||
requests <- body
|
||||
if !accepts(body) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, _ = io.WriteString(w, `{"error":{"message":"Invalid 'max_output_tokens': integer below minimum value. Expected a value >= 16.","type":"invalid_request_error","param":"max_output_tokens"}}`)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
_, _ = io.WriteString(w, "data: "+completed+"\n\n")
|
||||
}))
|
||||
t.Cleanup(server.Close)
|
||||
return server, requests
|
||||
}
|
||||
|
||||
// Issue 7304: operator-triggered inference verification must succeed against the
|
||||
// real Codex minimum even though it uses a minimal synthetic prompt budget.
|
||||
func TestCodexVerifyInferenceMinimumOutputBudget_Issue7304(t *testing.T) {
|
||||
server, requests := codexMinimumBudgetUpstream(t)
|
||||
|
||||
executor := NewCodexExecutor(&config.Config{})
|
||||
manager := cliproxyauth.NewManager(nil, nil, nil)
|
||||
manager.RegisterExecutor(executor)
|
||||
|
||||
ctx := cliproxyauth.WithSkipPersist(context.Background())
|
||||
auth := &cliproxyauth.Auth{
|
||||
ID: "codex-verify-7304.json",
|
||||
FileName: "codex-verify-7304.json",
|
||||
Provider: "codex",
|
||||
Status: cliproxyauth.StatusActive,
|
||||
Attributes: map[string]string{"base_url": server.URL},
|
||||
Metadata: map[string]any{
|
||||
"type": "codex",
|
||||
"email": "verify-7304@example.com",
|
||||
"access_token": "at-verify-7304",
|
||||
"refresh_token": "rt-verify-7304",
|
||||
"expired": time.Now().UTC().Add(24 * time.Hour).Format(time.RFC3339),
|
||||
},
|
||||
}
|
||||
if _, errReg := manager.Register(ctx, auth); errReg != nil {
|
||||
t.Fatalf("Register auth: %v", errReg)
|
||||
}
|
||||
registry.GetGlobalRegistry().RegisterClient(auth.ID, "codex", []*registry.ModelInfo{{ID: "gpt-5.6-sol"}})
|
||||
t.Cleanup(func() { registry.GetGlobalRegistry().UnregisterClient(auth.ID) })
|
||||
|
||||
verified, errVerify := manager.VerifyInference(ctx, auth.ID, "gpt-5.6-sol")
|
||||
if errVerify != nil {
|
||||
t.Fatalf("VerifyInference must succeed against the Codex >=16 minimum, got error: %v", errVerify)
|
||||
}
|
||||
if verified == nil || !verified.InferenceVerified {
|
||||
t.Fatalf("expected InferenceVerified=true after verification, got %+v", verified)
|
||||
}
|
||||
body := <-requests
|
||||
if got := ojson.GetBytes(body, "max_output_tokens").Raw; got != "16" {
|
||||
t.Fatalf("upstream max_output_tokens = %q, want 16; body=%s", got, body)
|
||||
}
|
||||
}
|
||||
|
||||
// Issue 7304: small positive integer budgets from every Codex source format must be
|
||||
// normalized to the upstream minimum before user payload rules; invalid budgets
|
||||
// (0, negative, fractional, non-numeric) stay untouched and no budget is injected.
|
||||
func TestCodexSmallOutputBudgetsAllSourceFormats_Issue7304(t *testing.T) {
|
||||
modelRule := []config.PayloadModelRule{{Name: "gpt-5.6-sol", Protocol: "codex"}}
|
||||
matchedRule := []config.PayloadModelRule{{
|
||||
Name: "gpt-5.6-sol", Protocol: "codex", Match: []map[string]any{{"max_output_tokens": 16}},
|
||||
}}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
from sdktranslator.Format
|
||||
payload string
|
||||
want string
|
||||
rules config.PayloadConfig
|
||||
}{
|
||||
{name: "responses max_output_tokens 1", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":1,"input":"Hi"}`, want: "16"},
|
||||
{name: "responses max_output_tokens 15", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":15,"input":"Hi"}`, want: "16"},
|
||||
{name: "responses legacy max_completion_tokens 1", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_completion_tokens":1,"input":"Hi"}`, want: "16"},
|
||||
{name: "responses legacy max_tokens 1", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_tokens":1,"input":"Hi"}`, want: "16"},
|
||||
{name: "responses 16 unchanged", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":16,"input":"Hi"}`, want: "16"},
|
||||
{name: "responses 1024 unchanged", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":1024,"input":"Hi"}`, want: "1024"},
|
||||
{name: "responses zero untouched", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":0,"input":"Hi"}`, want: "0"},
|
||||
{name: "responses negative untouched", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":-5,"input":"Hi"}`, want: "-5"},
|
||||
{name: "responses fractional untouched", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":1.5,"input":"Hi"}`, want: "1.5"},
|
||||
{name: "responses integral float normalized", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":15.0,"input":"Hi"}`, want: "16"},
|
||||
{name: "responses scientific integral normalized", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":1e1,"input":"Hi"}`, want: "16"},
|
||||
{name: "responses string untouched", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","max_output_tokens":"1","input":"Hi"}`, want: `"1"`},
|
||||
{name: "responses absent", from: sdktranslator.FormatOpenAIResponse, payload: `{"model":"gpt-5.6-sol","input":"Hi"}`},
|
||||
{name: "chat max_tokens 1", from: sdktranslator.FormatOpenAI, payload: `{"model":"gpt-5.6-sol","max_tokens":1,"messages":[{"role":"user","content":"Hi"}]}`, want: "16"},
|
||||
{name: "chat max_completion_tokens 1", from: sdktranslator.FormatOpenAI, payload: `{"model":"gpt-5.6-sol","max_completion_tokens":1,"messages":[{"role":"user","content":"Hi"}]}`, want: "16"},
|
||||
{name: "chat max_output_tokens 1", from: sdktranslator.FormatOpenAI, payload: `{"model":"gpt-5.6-sol","max_output_tokens":1,"messages":[{"role":"user","content":"Hi"}]}`, want: "16"},
|
||||
{name: "claude max_tokens 1", from: sdktranslator.FormatClaude, payload: `{"model":"gpt-5.6-sol","max_tokens":1,"messages":[{"role":"user","content":[{"type":"text","text":"Hi"}]}]}`, want: "16"},
|
||||
{name: "gemini maxOutputTokens 1", from: sdktranslator.FormatGemini, payload: `{"model":"gpt-5.6-sol","contents":[{"role":"user","parts":[{"text":"Hi"}]}],"generationConfig":{"maxOutputTokens":1}}`, want: "16"},
|
||||
{name: "gemini top-level max_tokens 1", from: sdktranslator.FormatGemini, payload: `{"model":"gpt-5.6-sol","contents":[{"role":"user","parts":[{"text":"Hi"}]}],"max_tokens":1}`, want: "16"},
|
||||
{name: "interactions max_output_tokens 1", from: sdktranslator.FormatInteractions, payload: `{"model":"gpt-5.6-sol","input":"Hi","max_output_tokens":1}`, want: "16"},
|
||||
{name: "interactions generation_config 1", from: sdktranslator.FormatInteractions, payload: `{"model":"gpt-5.6-sol","input":"Hi","generation_config":{"max_output_tokens":1}}`, want: "16"},
|
||||
{
|
||||
name: "responses payload override still final", from: sdktranslator.FormatOpenAIResponse,
|
||||
payload: `{"model":"gpt-5.6-sol","max_output_tokens":1,"input":"Hi"}`, want: "8",
|
||||
rules: config.PayloadConfig{Override: []config.PayloadRule{{Models: matchedRule, Params: map[string]any{"max_output_tokens": 8}}}},
|
||||
},
|
||||
{
|
||||
name: "responses payload filter still final", from: sdktranslator.FormatOpenAIResponse,
|
||||
payload: `{"model":"gpt-5.6-sol","max_output_tokens":1,"input":"Hi"}`,
|
||||
rules: config.PayloadConfig{Filter: []config.PayloadFilterRule{{Models: modelRule, Params: []string{"max_output_tokens"}}}},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
for _, useWebsocket := range []bool{false, true} {
|
||||
for _, stream := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("%s/websocket=%t/stream=%t", tc.name, useWebsocket, stream), func(t *testing.T) {
|
||||
server, requests := codexMinimumBudgetUpstream(t)
|
||||
cfg := &config.Config{Payload: tc.rules}
|
||||
var executor cliproxyauth.ProviderExecutor = NewCodexExecutor(cfg)
|
||||
if useWebsocket {
|
||||
executor = NewCodexWebsocketsExecutor(cfg)
|
||||
}
|
||||
req := cliproxyexecutor.Request{Model: "gpt-5.6-sol", Payload: []byte(tc.payload)}
|
||||
opts := cliproxyexecutor.Options{SourceFormat: tc.from, Stream: stream}
|
||||
auth := codexOAuthTestAuth(server.URL)
|
||||
auth.ID = "codex-output-budget-7304-test"
|
||||
|
||||
// wantAccept mirrors the simplified upstream model above: any
|
||||
// numeric budget below 16 is rejected (the simulator does not
|
||||
// distinguish integer from fractional), so accepts cover normalized,
|
||||
// valid, absent, and non-numeric values. Accepted requests must
|
||||
// succeed; rejected ones must surface a budget error.
|
||||
wantAccept := true
|
||||
if tc.want != "" {
|
||||
if parsed, errParse := strconv.ParseFloat(tc.want, 64); errParse == nil && parsed < 16 {
|
||||
wantAccept = false
|
||||
}
|
||||
}
|
||||
var execErr error
|
||||
if stream {
|
||||
result, errStream := executor.ExecuteStream(context.Background(), auth, req, opts)
|
||||
execErr = errStream
|
||||
if errStream == nil {
|
||||
for chunk := range result.Chunks {
|
||||
if chunk.Err != nil && execErr == nil {
|
||||
execErr = chunk.Err
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_, execErr = executor.Execute(context.Background(), auth, req, opts)
|
||||
}
|
||||
if wantAccept && execErr != nil {
|
||||
t.Fatalf("execution must succeed for an upstream-acceptable budget, got error: %v", execErr)
|
||||
}
|
||||
if !wantAccept && execErr == nil {
|
||||
t.Fatal("execution must fail when the untouched budget stays below the upstream minimum")
|
||||
}
|
||||
if !wantAccept && execErr != nil && !strings.Contains(execErr.Error(), "max_output_tokens") {
|
||||
t.Fatalf("rejected execution error must propagate the upstream budget error, got: %v", execErr)
|
||||
}
|
||||
select {
|
||||
case body := <-requests:
|
||||
if got := ojson.GetBytes(body, "max_output_tokens").Raw; got != tc.want {
|
||||
t.Fatalf("upstream max_output_tokens = %q, want %q; body=%s", got, tc.want, body)
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("upstream received no request within 10s")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
neturl "net/url"
|
||||
"runtime"
|
||||
@@ -67,26 +68,29 @@ func translateCodexRequestPairWithUpdateIntentContext(ctx context.Context, from,
|
||||
return originalTranslated, body, changed, err
|
||||
}
|
||||
|
||||
// normalizeCodexClaudeOutputBudgetDoc bridges Claude's smaller valid budgets to Codex's minimum.
|
||||
func normalizeCodexClaudeOutputBudgetDoc(doc *ojson.Doc, from sdktranslator.Format, payload []byte) {
|
||||
if doc == nil || from != sdktranslator.FormatClaude {
|
||||
return
|
||||
}
|
||||
requested := ojson.GetBytesNoCopy(payload, "max_tokens")
|
||||
if !requested.Exists() {
|
||||
requested = ojson.GetBytesNoCopy(payload, "max_output_tokens")
|
||||
}
|
||||
if requested.Type != ojson.Number {
|
||||
return
|
||||
}
|
||||
requestedTokens, errParse := strconv.ParseInt(requested.Raw, 10, 64)
|
||||
if errParse != nil || requestedTokens < 1 || requestedTokens >= 16 {
|
||||
// codexMinOutputTokens is the smallest integer max_output_tokens value the ChatGPT
|
||||
// Codex backend accepts; smaller integers are rejected with invalid_request_error.
|
||||
const codexMinOutputTokens = 16
|
||||
|
||||
// normalizeCodexOutputBudgetDoc raises small positive integer output budgets to the
|
||||
// Codex minimum. It judges the translated payload (max_output_tokens) rather than the
|
||||
// client payload so every source format and budget field (max_tokens,
|
||||
// max_completion_tokens, generation_config, ...) is covered uniformly. Budgets that
|
||||
// are missing, non-numeric, non-integral, or <= 0 are left untouched for the upstream
|
||||
// to reject. This runs before user payload rules so overrides and filters stay final.
|
||||
func normalizeCodexOutputBudgetDoc(doc *ojson.Doc) {
|
||||
if doc == nil {
|
||||
return
|
||||
}
|
||||
translated := doc.Get("max_output_tokens")
|
||||
if translated.Type == ojson.Number && translated.Int() > 0 && translated.Int() < 16 {
|
||||
_ = doc.Set("max_output_tokens", 16)
|
||||
if translated.Type != ojson.Number {
|
||||
return
|
||||
}
|
||||
tokens, errFloat := strconv.ParseFloat(translated.Raw, 64)
|
||||
if errFloat != nil || tokens < 1 || tokens >= codexMinOutputTokens || tokens != math.Trunc(tokens) {
|
||||
return
|
||||
}
|
||||
_ = doc.Set("max_output_tokens", codexMinOutputTokens)
|
||||
}
|
||||
|
||||
// PrepareRequest injects Codex credentials into the outgoing HTTP request.
|
||||
|
||||
@@ -576,7 +576,7 @@ func TestCodexVerifyInferenceTranslatesPayloadAndRequiresCompletedEvent_Issue578
|
||||
}
|
||||
cfg.Codex.StreamBootstrapBuffering = false
|
||||
|
||||
// 2. Real completed stream succeeds and the translated body preserves VerifyInference's max_output_tokens=1 while setting stream=true.
|
||||
// 2. Real completed stream succeeds and the translated body carries VerifyInference's max_output_tokens=16 while setting stream=true.
|
||||
sseResponse = "event: response.created\ndata: {\"type\":\"response.created\",\"response\":{\"id\":\"r2\",\"model\":\"gpt-5.4\"}}\n\n" +
|
||||
"event: response.output_text.delta\ndata: {\"type\":\"response.output_text.delta\",\"delta\":\"pong\"}\n\n" +
|
||||
"event: response.completed\ndata: {\"type\":\"response.completed\",\"response\":{\"id\":\"r2\",\"model\":\"gpt-5.4\",\"status\":\"completed\",\"output\":[{\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"output_text\",\"text\":\"pong\"}]}]}}\n\n"
|
||||
@@ -594,8 +594,8 @@ func TestCodexVerifyInferenceTranslatesPayloadAndRequiresCompletedEvent_Issue578
|
||||
if upstreamJSON["stream"] != true || upstreamJSON["store"] != false {
|
||||
t.Fatalf("expected translated Codex body with stream=true and store=false, got: %s", string(capturedBody))
|
||||
}
|
||||
if maxOutputTokens := upstreamJSON["max_output_tokens"]; maxOutputTokens != float64(1) {
|
||||
t.Fatalf("translated Codex body must preserve max_output_tokens=1, got: %s", string(capturedBody))
|
||||
if maxOutputTokens := upstreamJSON["max_output_tokens"]; maxOutputTokens != float64(16) {
|
||||
t.Fatalf("translated Codex body must carry max_output_tokens=16, got: %s", string(capturedBody))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ func (e *CodexExecutor) ExecuteStream(ctx context.Context, auth *cliproxyauth.Au
|
||||
}
|
||||
originalTranslated = helps.SetStringIfDifferent(originalTranslated, "model", baseModel)
|
||||
doc := ojson.NewDoc(body)
|
||||
normalizeCodexClaudeOutputBudgetDoc(doc, from, req.Payload)
|
||||
normalizeCodexOutputBudgetDoc(doc)
|
||||
helps.SetStringIfDifferentDoc(doc, "model", baseModel)
|
||||
|
||||
if err = helps.ApplyRequestThinkingDoc(doc, req, opts, from.String(), to.String(), e.Identifier(), updatesChanged); err != nil {
|
||||
|
||||
@@ -63,7 +63,7 @@ func (e *CodexWebsocketsExecutor) Execute(ctx context.Context, auth *cliproxyaut
|
||||
}
|
||||
originalTranslated = helps.SetStringIfDifferent(originalTranslated, "model", baseModel)
|
||||
doc := ojson.NewDoc(body)
|
||||
normalizeCodexClaudeOutputBudgetDoc(doc, from, req.Payload)
|
||||
normalizeCodexOutputBudgetDoc(doc)
|
||||
helps.SetStringIfDifferentDoc(doc, "model", baseModel)
|
||||
|
||||
if err = helps.ApplyRequestThinkingDoc(doc, req, opts, from.String(), to.String(), e.Identifier(), updatesChanged); err != nil {
|
||||
|
||||
@@ -891,7 +891,7 @@ func (e *CodexWebsocketsExecutor) prepareCodexWebsocketStream(ctx context.Contex
|
||||
}
|
||||
originalTranslated = helps.SetStringIfDifferent(originalTranslated, "model", baseModel)
|
||||
doc := ojson.NewDoc(body)
|
||||
normalizeCodexClaudeOutputBudgetDoc(doc, from, req.Payload)
|
||||
normalizeCodexOutputBudgetDoc(doc)
|
||||
helps.SetStringIfDifferentDoc(doc, "model", baseModel)
|
||||
|
||||
if err = helps.ApplyRequestThinkingDoc(doc, req, opts, from.String(), to.String(), e.Identifier(), updatesChanged); err != nil {
|
||||
|
||||
@@ -2288,7 +2288,9 @@ func (m *Manager) VerifyInference(ctx context.Context, id, model string) (*Auth,
|
||||
}
|
||||
|
||||
sessionID := fmt.Sprintf("verify-%s-%d", auth.ID, time.Now().UTC().UnixNano())
|
||||
payload := []byte(fmt.Sprintf(`{"model":%q,"input":[{"type":"message","role":"user","content":[{"type":"input_text","text":"ping"}]}],"max_output_tokens":1,"store":false}`, verifyModel))
|
||||
// Codex upstreams reject integer max_output_tokens below 16, so the minimal
|
||||
// verification budget must sit at that floor.
|
||||
payload := []byte(fmt.Sprintf(`{"model":%q,"input":[{"type":"message","role":"user","content":[{"type":"input_text","text":"ping"}]}],"max_output_tokens":16,"store":false}`, verifyModel))
|
||||
req := cliproxyexecutor.Request{
|
||||
Model: verifyModel,
|
||||
Payload: payload,
|
||||
|
||||
@@ -1082,7 +1082,7 @@ func TestManager_CodexTerminalRenewalRecoveryLifecycle_Issue5783(t *testing.T) {
|
||||
t.Fatal("VerifyInference must fail when stream ends with response.incomplete")
|
||||
}
|
||||
|
||||
// Operator-triggered VerifyInference pins to primary, uses an isolated session and minimal 1-token prompt, and marks InferenceVerified = true upon response.completed.
|
||||
// Operator-triggered VerifyInference pins to primary, uses an isolated session and a minimal 16-token (Codex floor) prompt, and marks InferenceVerified = true upon response.completed.
|
||||
executor.mu.Lock()
|
||||
executor.streamPayloads = nil
|
||||
executor.streamCalls = nil
|
||||
@@ -1102,8 +1102,8 @@ func TestManager_CodexTerminalRenewalRecoveryLifecycle_Issue5783(t *testing.T) {
|
||||
if gotSession := verifyOpts.Headers.Get("X-Session-Id"); gotSession == "" || len(gotSession) < 7 || gotSession[:7] != "verify-" {
|
||||
t.Fatalf("VerifyInference X-Session-Id = %q, want isolated verify-* session", gotSession)
|
||||
}
|
||||
if !containsSubstr(string(verifyReq.Payload), `"max_output_tokens":1`) || !containsSubstr(string(verifyReq.Payload), `"store":false`) {
|
||||
t.Fatalf("VerifyInference payload = %s, want minimal 1-token non-stored prompt", string(verifyReq.Payload))
|
||||
if !containsSubstr(string(verifyReq.Payload), `"max_output_tokens":16`) || !containsSubstr(string(verifyReq.Payload), `"store":false`) {
|
||||
t.Fatalf("VerifyInference payload = %s, want minimal 16-token non-stored prompt", string(verifyReq.Payload))
|
||||
}
|
||||
if !afterVerify.InferenceVerified || afterVerify.RecoveryStageAt(now) != RecoveryStageInferenceVerified {
|
||||
t.Fatalf("expected InferenceVerified=true and stage=inference_verified after VerifyInference, got %v / %q", afterVerify.InferenceVerified, afterVerify.RecoveryStageAt(now))
|
||||
|
||||
Reference in New Issue
Block a user