diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index f1033b9cc..41bcebaed 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -105,7 +105,16 @@ record), cybercaius on Discord `TestCodexMemoryOfASwitchedConversationFollowsTheSwitch`, `TestCodexMemoryStandInFollowsTheSwitch`). A call tied to a seen thread and not started with a turn (a prediction, a known thread's title) takes -that thread's last model at once. Codex +that thread's last model at once. With magpie as Codex's provider (`/v1/responses`) +the model in such a request is not the user's pick either: the Codex app +asks a new conversation's title on its provider list's default or first +model that takes low effort (app.asar's `oX`), never the thread's, so a +title, description, summary or prediction there goes on the session's +model (`codexSideSession`, through `codexSideTo`), and on the model asked +only when no session's is known (tenacious_eagle_96548 on Discord: titles +on another provider's qwen while the conversation was on dsf4.1, +`TestCodexOwnTitleFollowsThePickNotTheAppsChoice`). settings.CodexTitles, +when set, still writes every title. Codex asks a title with no reasoning effort on any model but its own title model, and its auto-review at a model's default, which it has none of for magpie's models; a model that needs an effort answered those with 400 diff --git a/internal/gateway/codex_follow_test.go b/internal/gateway/codex_follow_test.go index ca20cf88c..2b1c01c07 100644 --- a/internal/gateway/codex_follow_test.go +++ b/internal/gateway/codex_follow_test.go @@ -225,6 +225,50 @@ func TestCodexFirstTitleFollowsThePickNotTheConfig(t *testing.T) { } } +// codexOwnCall is a request Codex with magpie as its provider sends to +// /v1/responses on model, in the thread session: a turn of its own +// (source "") or one of the app's side turns. +func codexOwnCall(t *testing.T, s *Server, model, session, source string) { + t.Helper() + req := httptest.NewRequest("POST", "/v1/responses", strings.NewReader(`{"model":"`+model+`","stream":true,"input":[`+leadAsk+`]}`)) + req.Header.Set("Authorization", "Bearer "+TokenFor("codex")) + req.Header.Set("session_id", session) + if source != "" { + req.Header.Set("x-codex-turn-metadata", `{"thread_source":"`+source+`"}`) + } + s.Handler().ServeHTTP(httptest.NewRecorder(), req) +} + +// tenacious_eagle_96548 on Discord, with magpie as Codex's provider: the +// conversation on fourth/ picked in the app, its title on third/. The app +// asks for a new conversation's title on a model it chooses itself (the +// provider list's default, else its first), never the conversation's, so +// the model in the request is not the user's pick. Each of the app's side +// turns goes on the conversation's model, the title waiting for the turn +// it is sent beside. +func TestCodexOwnTitleFollowsThePickNotTheAppsChoice(t *testing.T) { + fresh(t) + appChose := relayOn(t, "third") + picked := relayOn(t, "fourth") + wasModel, wasWait := CodexSideModel, codexSideWait + CodexSideModel = func() string { return "" } + codexSideWait = time.Minute + t.Cleanup(func() { CodexSideModel, codexSideWait = wasModel, wasWait }) + s := New() + beforeTheTurn(t, s, func() { codexOwnCall(t, s, "third/gpt-6-astra", "title-thread", "thread_title") }, func() { + codexOwnCall(t, s, "fourth/gpt-6-astra", "conv-1", "") + }) + for _, src := range []string{"thread_description", "thread_summary"} { + codexOwnCall(t, s, "third/gpt-6-astra", "conv-1", src) + } + if reqs := appChose.requests(); len(reqs) != 0 { + t.Fatalf("the app's choice got %d requests", len(reqs)) + } + if reqs := picked.requests(); len(reqs) != 4 { + t.Fatalf("the picked model got %d requests, want the turn, the title, the description and the summary", len(reqs)) + } +} + // A composer prediction runs on a fork of the conversation, a thread of // its own: it follows the conversation it was forked from, not whichever // one this key's Codex last had a turn in. diff --git a/internal/gateway/codex_titles.go b/internal/gateway/codex_titles.go index 492972786..3ba873e77 100644 --- a/internal/gateway/codex_titles.go +++ b/internal/gateway/codex_titles.go @@ -17,14 +17,13 @@ import ( // codexTitlesTo is where a request Codex makes for a thread's title goes // (#705): a hidden turn of its own (thread_title, -// thread_title_reconsideration), which Codex sends on its own model — -// gpt-5.6-luna when signed in to ChatGPT, the conversation's model when -// magpie is its provider. "" for a request that isn't one, or one left to -// go as Codex sent it; "off", or the model that writes the title: -// settings.CodexTitles, else the model Codex asked for when it is one of -// magpie's (ours: the request came to magpie's own API, where every model -// is). Codex reads a title only as the {"title": …} its text.format asks -// for, which a model behind the Chat or Anthropic API is never shown, so +// thread_title_reconsideration), which Codex sends on a model it chooses +// itself — gpt-5.6-luna when signed in to ChatGPT, its provider list's +// default or first model when magpie is its provider. "" for a request +// that isn't one, or one left to go as Codex sent it; "off", or the model +// that writes the title: settings.CodexTitles, else the conversation's +// model (codexSideTo). Codex reads a title only as the {"title": …} its +// text.format asks for, which a model behind the Chat or Anthropic API is never shown, so // a title on one of magpie's models goes through codexTitle whoever picked // it (#743: Codex as magpie's provider had none at all, the model's plain // answer turned down). @@ -54,12 +53,28 @@ var CodexSideModel func() string // (atom_Ray on X: an hour on a third-party model took 2% of the 5-hour // window). Those go on the session's model (session: Server.codexSideSession), // as the conversation's turns do; on Codex's own, as Codex sent them. +// +// With magpie as Codex's provider the model asked for is not the user's +// pick either: the app asks for a new conversation's title on +// ephemeralGenerationModel, and when the provider's list lacks it, on the +// list's default model or else its first (the app's oX), never on the +// model picked for the conversation (tenacious_eagle_96548 on Discord: +// the conversation on A/dsf4.1, its title on B/qwen3.7). Those go on the +// session's model too when magpie knows it, else on the model asked for. func codexSideTo(body []byte, ours bool, session func() string) string { m := modelOf(body) - if m != "" && (ours || strings.Contains(m, "/")) { + if ours { + if session != nil { + if to := session(); to != "" { + return to + } + } return m } - if !ours && session != nil { + if strings.Contains(m, "/") { + return m + } + if session != nil { return session() } return "" diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index e430e81e1..bf4064f49 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -2073,19 +2073,22 @@ func (s *Server) handle(from provider.Protocol) http.HandlerFunc { // Codex with magpie as its provider asks for a thread's title // here (#743) if from == provider.Responses { - if to := codexTitlesTo(r.Header, body, true, nil); to != "" { + // on the conversation's model, not the one the app chose + // for it (codexSideTo) + session := func() string { return s.codexSideSession(r, body) } + if to := codexTitlesTo(r.Header, body, true, session); to != "" { s.codexTitle(w, r, body, to) return } - if to := codexDescriptionsTo(r.Header, body, true, nil); to != "" { + if to := codexDescriptionsTo(r.Header, body, true, session); to != "" { s.codexDescription(w, r, body, to) return } - if to := codexSummariesTo(r.Header, body, true, nil); to != "" { + if to := codexSummariesTo(r.Header, body, true, session); to != "" { s.codexSummary(w, r, body, to) return } - if to := codexPredictionsTo(r.Header, body, true, nil); to != "" { + if to := codexPredictionsTo(r.Header, body, true, session); to != "" { s.codexPrediction(w, r, body, to) return }