From 206efc90c83de8abd7a121cdabd9e6caaf224313 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 1 Nov 2026 22:12:41 +0800 Subject: [PATCH] gateway: a Codex side call with no setting still goes on Codex's sign-in (#4590 review) e99e75dab took every side call on one of Codex's own models (title, description, summary, prediction) off Codex's ChatGPT sign-in. With no setting naming a model, codexTitlesTo and its siblings hand back the bare model Codex asked for, which magpie serves nothing for: a user signed in to ChatGPT whose titles worked through the sign-in got "magpie knows no model \"gpt-6.1-sol\"" 404 for every title, description, summary and prediction. A thread's summary has no setting at all, so it always went that way. Now only a side call whose setting names where it goes (CodexTitles, CodexDescriptions, CodexPredictions: a model or "off") stays off the sign-in (codexSideSet); without one it goes on the sign-in as before. Run (mote, at this tree, -tags nogui): - TestCodexSideCallOnOwnModelUnsetGoesOnSignIn (new: signed in, no setting, each of the four kinds): red on e99e75dab, the 404 above for all four; green now. - go test -run 'TestCodexSideCallOnOwnModel|TestCodexOwnModelOnMagpieThread| TestCodexTitlesSetting|TestCodexTitleOnMagpieProvider| TestCodexDescriptionsSetting|TestCodexDescriptionFallbackOnMagpie| TestCodexPrediction|TestCodexSummar' ./internal/gateway: ok - broken by hand: codexSideSet always false turns gua's TestCodexSideCallOnOwnModelNotPutOnSignIn red (the reporter's 404); always true turns the new test red. --- internal/gateway/codex_own_v1.go | 33 ++++++++++++++++++++------- internal/gateway/codex_own_v1_test.go | 18 +++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/internal/gateway/codex_own_v1.go b/internal/gateway/codex_own_v1.go index 7ad044118..2ee27bb8d 100644 --- a/internal/gateway/codex_own_v1.go +++ b/internal/gateway/codex_own_v1.go @@ -11,6 +11,7 @@ import ( "github.com/yetone/magpie/internal/catalog" "github.com/yetone/magpie/internal/codexcat" "github.com/yetone/magpie/internal/provider" + "github.com/yetone/magpie/internal/settings" ) // codexSignInToken is Codex's ChatGPT sign-in as Codex keeps it, which @@ -36,14 +37,15 @@ func codexOwnOffMagpie(r *http.Request, body []byte, model string) (to *http.Req if model == "" || strings.Contains(model, "/") || !local(r) { return nil, "" } - // one of Codex's hidden side calls on its own model — a thread's title - // or description, a summary, a composer prediction — is magpie's to - // answer where it stands (codexTitlesTo and its siblings, further down - // handle), never to put on Codex's ChatGPT sign-in: with no sign-in to - // be had (no ChatGPT account in magpie, Codex itself never signed in) - // the request was answered 404 and Codex named the thread after its - // first message, whatever the settings said (#4590) - if k := requestCallKind(r.Header, requestSessionMetadata(r.Header, body)); isTitleKind(k) || isDescriptionKind(k) || isSummaryKind(k) || isPredictionKind(k) { + // one of Codex's hidden side calls on its own model that a setting + // sends elsewhere — a thread's title or description, a composer + // prediction — is magpie's to answer where it stands (codexTitlesTo + // and its siblings, further down handle), never to put on Codex's + // ChatGPT sign-in: with no sign-in to be had the request was answered + // 404 and Codex named the thread after its first message, whatever the + // settings said (#4590). With no setting magpie has nothing of its own + // to answer it with, and it goes on the sign-in as the thread's turns do. + if codexSideSet(requestCallKind(r.Header, requestSessionMetadata(r.Header, body))) { return nil, "" } if !fromCodex(r.Header) && agentOf(r) != "codex" { @@ -118,3 +120,18 @@ func codexOwnModel(model string) bool { } return false } + +// codexSideSet: a side call of this kind has a setting naming where it +// goes (a model, or "off"). A thread's summary has none. +func codexSideSet(kind string) bool { + st := settings.Load() + switch { + case isTitleKind(kind): + return st.CodexTitles != "" + case isDescriptionKind(kind): + return st.CodexDescriptions != "" + case isPredictionKind(kind): + return st.CodexPredictions != "" + } + return false +} diff --git a/internal/gateway/codex_own_v1_test.go b/internal/gateway/codex_own_v1_test.go index 62a6db57c..5f2fae5d0 100644 --- a/internal/gateway/codex_own_v1_test.go +++ b/internal/gateway/codex_own_v1_test.go @@ -251,3 +251,21 @@ func TestCodexSideCallOnOwnModelNotPutOnSignIn(t *testing.T) { } }) } + +// With no setting naming where a side call goes, a title asked on one of +// Codex's own models still goes on Codex's sign-in, as every turn of the +// thread does: magpie has nothing of its own to answer it with, and +// before #4590 that is where it was answered. +func TestCodexSideCallOnOwnModelUnsetGoesOnSignIn(t *testing.T) { + _, models := codexOwnOffMagpieSetup(t, false) + for _, kind := range []string{"thread_title", "thread_description", "thread_summary", "composer_predictions"} { + *models = nil + req := codexOnMagpieRequest("127.0.0.1:51000") + req.Header.Set("x-codex-turn-metadata", `{"thread_source":"`+kind+`","parent_thread_id":"main-chat"}`) + rec := httptest.NewRecorder() + New().Handler().ServeHTTP(rec, req) + if len(*models) != 1 || (*models)[0] != "gpt-6.1-sol" { + t.Errorf("%s with no setting: %d %s, backend asked for %v", kind, rec.Code, rec.Body.String(), *models) + } + } +}