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) + } + } +}