gateway: a Codex memory call on a provider/model id keeps it (#5413)

Codex's memories.extract_model and consolidation_model, set to
remote-magpie/sub2api/gpt-6.1-terra on the user's computer, reached the
Remote magpie as sub2api/gpt-6.1-terra, which it serves. The branch of
codexMemoryStandIn added for #4765 (a bare Codex default that a
provider happens to serve under the same name) moved any memory call
that resolves onto the conversation's model unless CodexSideSet saw
[memories] set, and the remote has no Codex config to read
(GetTOMLTable's absent file reads as "nothing set"). So the user's pick
went to sub2api/gpt-6.1-sol, recorded as codex-turn.

A "provider/model" id is never one of Codex's defaults, which are bare,
so it is the user's pick and goes as it came, as codexFollowTo (the
ChatGPT backend's path) already does. The same holds locally for a
Codex on a profile or a CODEX_HOME of its own, whose config magpie
doesn't read. A bare name that resolves still follows the conversation
when the config here names no memory model (#4765 unchanged).

Run (mote): go test ./internal/gateway -run
'TestCodexMemory|TestCodexSide|TestCodexMemories' -count=1: ok.
Broken by hand: with the "/" check taken out,
TestCodexMemoryOnAQualifiedModelKeepsIt fails with
"memory_consolidation moved to "third/gpt-6-astra" (codex-turn)", the
reporter's move.
Not tried: a real Local -> Remote magpie pair with Sub2API; a bare
memory model named in the config of a Codex on another computer still
can't be seen by the remote.

Reported-by: MariaMatrix (GitHub)
Reported-by: mahiro233 (Discord)
This commit is contained in:
yetone
2026-11-06 15:09:18 +08:00
parent 1ccad582d8
commit 73324357ed
2 changed files with 41 additions and 1 deletions
+9 -1
View File
@@ -2,6 +2,7 @@ package gateway
import (
"net/http"
"strings"
"time"
"github.com/yetone/magpie/internal/access"
@@ -85,7 +86,14 @@ func (s *Server) codexMemoryStandIn(r *http.Request, who, agent, kind, asked str
// (codexFollowTo). "" keeps it where the name resolves: any
// other call, the config's own pick, a call whose config magpie
// can't read, or no conversation of magpie's to follow.
if !isMemoryKind(kind) || CodexSideSet == nil || CodexSideSet("memories") {
//
// A "provider/model" id is never one of Codex's defaults, which
// are bare: it is the user's pick in memories.extract_model or
// consolidation_model, and goes as it came, whatever the config
// here says — a Remote magpie can't read the Codex config on the
// computer the call came from, and a Codex on a profile or a
// CODEX_HOME of its own has its config elsewhere too (#5413).
if !isMemoryKind(kind) || strings.Contains(asked, "/") || CodexSideSet == nil || CodexSideSet("memories") {
return ""
}
to := s.codexMemorySession(r, body)
+32
View File
@@ -144,3 +144,35 @@ func TestCodexMemoryOnACollidingBareNameFollowsTheSession(t *testing.T) {
t.Fatalf("the provider with the name got %d requests, the turn among them", len(reqs))
}
}
// #5413 (MariaMatrix; mahiro233 on Discord): Codex's config, on another
// computer, named sub2api/gpt-6.1-terra for its memories while the
// conversation ran on sub2api/gpt-6.1-sol, and the Remote magpie the call
// reached, with no Codex config of its own to read, put the memory on the
// conversation's model. A "provider/model" id is never one of Codex's bare
// defaults: it is the user's pick, and goes as it came, with no move.
func TestCodexMemoryOnAQualifiedModelKeepsIt(t *testing.T) {
fresh(t)
session, picked := relayOn(t, "third"), relayOn(t, "fourth")
was := CodexSideSet
CodexSideSet = func(string) bool { return false }
t.Cleanup(func() { CodexSideSet = was })
s := New()
if rec := codexCall(t, s, "third/gpt-6-astra", ""); rec.Code != 200 {
t.Fatalf("the turn: %d %s", rec.Code, rec.Body.String())
}
for _, kind := range []string{"memory_consolidation", "memgen"} {
if rec := codexCall(t, s, "fourth/gpt-6-astra", kind); rec.Code != 200 {
t.Fatalf("%s: %d %s", kind, rec.Code, rec.Body.String())
}
if r := lastRoute(s); r.Moved != nil {
t.Fatalf("%s moved to %q (%s)", kind, r.Moved.To, r.Moved.Why)
}
}
if reqs := session.requests(); len(reqs) != 1 {
t.Fatalf("the conversation's provider got %d requests, want the turn alone", len(reqs))
}
if reqs := picked.requests(); len(reqs) != 2 {
t.Fatalf("the provider picked for the memories got %d requests", len(reqs))
}
}