gateway: a Codex side call to magpie's own API goes on the conversation's model
With magpie as Codex's provider, the Codex app asks a new conversation's title on a model it chooses itself, not the one picked for the conversation: ephemeralGenerationModel, and when the provider's model list lacks it (magpie's always does), the list's default model, else the first visible one that takes low effort (app.asar's oX). magpie wrote the title on that model as asked, so with the conversation on A/dsf4.1 the title went to B/qwen3.7, another provider (tenacious_eagle_96548). Now a title, description, summary or prediction that reaches /v1/responses goes on the session's model (codexSideSession, as the ChatGPT route already did; it waits for the conversation's turn like it does there), and on the model asked only when no session's model is known. settings.CodexTitles, when set, still writes every title. TestCodexOwnTitleFollowsThePickNotTheAppsChoice: the title on third/ (the app's choice) before the turn on fourth/, then a description and a summary on third/ in that conversation. Red on the old gateway.go (the app's choice got the requests), green on the new. Run (mote, at this commit's tree): go build ./..., go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. gofmt -l: clean. go test -count=1 -run Codex ./internal/gateway/: ok (172s). Full suite (go test -tags nogui -timeout 45m ./..., through the suite lock) was still queued/running at push; any red it shows gets an issue. After a rebase onto6b7ee4a98(its routing commits touch gateway.go and the routing doc too), go build, the three vets and go test -run 'Codex|Routing|Group' ./internal/gateway/ ran again at that tree. Then rebased onto9451ad59f(two gateway commits touching none of this change's files); go vet ./internal/gateway/ there only. Not tried: the real Codex app was not run; the oX choice was read from its app.asar. No real provider accounts. Windows and Linux: vet only. Reported-by: tenacious_eagle_96548 on Discord
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user