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.
This commit is contained in:
yetone
2026-11-01 22:44:23 +08:00
parent 50e8da4c34
commit 206efc90c8
2 changed files with 43 additions and 8 deletions
+25 -8
View File
@@ -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
}
+18
View File
@@ -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)
}
}
}