diff --git a/internal/gateway/codex_memory.go b/internal/gateway/codex_memory.go index 630890c7b..b93bec2a5 100644 --- a/internal/gateway/codex_memory.go +++ b/internal/gateway/codex_memory.go @@ -71,9 +71,13 @@ func freeOnChatGPT(model, plan string) bool { return provider.ChatGPTReviewFree( // model was switched: it is read after that turn, as the app's titles are // (codexLeads.sideOf, beside), not on the model switched away from // (cybercaius on Discord). -func (s *Server) codexMemoryStandIn(r *http.Request, who, agent, kind, asked string, body []byte) string { +// +// why is the move's reason for the trace: movedCodexFollow for a bare +// default magpie serves that went on the conversation's model instead, +// movedCodexTurn for a model magpie doesn't serve. +func (s *Server) codexMemoryStandIn(r *http.Request, who, agent, kind, asked string, body []byte) (to, why string) { if agent != "codex" || !isMemoryKind(kind) && !isReviewCall(kind, asked) { - return "" + return "", "" } if _, _, ok := provider.Resolve(asked); ok { // A memory call on one of Codex's own bare defaults that a @@ -94,18 +98,18 @@ func (s *Server) codexMemoryStandIn(r *http.Request, who, agent, kind, asked str // 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 "" + return "", "" } to := s.codexMemorySession(r, body) if to == "" || to == asked { - return "" + return "", "" } - return to + return to, movedCodexFollow } if isMemoryKind(kind) { if m := s.codexLeads.sideOf(r, body, true); m != "" && m != asked { if _, _, ok := provider.Resolve(m); ok { - return m + return m, movedCodexTurn } } } @@ -113,7 +117,7 @@ func (s *Server) codexMemoryStandIn(r *http.Request, who, agent, kind, asked str if m, ok := s.codexTurns.Load(key); ok { if m, _ := m.(string); m != "" && m != asked { if _, _, ok := provider.Resolve(m); ok { - return m + return m, movedCodexTurn } } } @@ -132,10 +136,10 @@ func (s *Server) codexMemoryStandIn(r *http.Request, who, agent, kind, asked str m = id } if m == "" || m == asked { - return "" + return "", "" } if _, _, ok := provider.Resolve(m); !ok { - return "" + return "", "" } - return m + return m, movedCodexTurn } diff --git a/internal/gateway/codex_memory_test.go b/internal/gateway/codex_memory_test.go index 4e2f6fe99..287456691 100644 --- a/internal/gateway/codex_memory_test.go +++ b/internal/gateway/codex_memory_test.go @@ -122,6 +122,10 @@ func TestCodexMemoryOnACollidingBareNameFollowsTheSession(t *testing.T) { if reqs := relay.requests(); len(reqs) != 0 { t.Fatalf("the provider with the name got the memory (%d requests)", len(reqs)) } + // and says so: magpie serves the name, so not "magpie doesn't serve it" (#5413) + if r := lastRoute(s); r.Moved == nil || r.Moved.Why != movedCodexFollow { + t.Fatalf("the move: %+v", r.Moved) + } reqs := session.requests() if len(reqs) != 2 || modelOf([]byte(reqs[1])) != "gpt-6-astra" { t.Fatalf("the session's provider got %d requests, the last on %q", len(reqs), modelOf([]byte(reqs[len(reqs)-1]))) diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 18d5a2f9c..87c1f6d3e 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -158,11 +158,12 @@ func wiresOf(ctx context.Context) map[string]string { // The reasons serve gives a model move of its own (ModelMove.Why); // Claude Desktop's are desktopMove's. const ( - movedClassifier = "classifier" // Claude Code's auto mode classifier: the model /model moved its tier to - movedClaudeTier = "claude-tier" // Claude Code's full id of a Claude model: the model set for its tier - movedStandIn = "stand-in" // a model magpie doesn't serve: the one the agent's config names - movedCodexTurn = "codex-turn" // Codex's memory or auto-review call: its last turn's model - movedPrivacy = "privacy" // a request masking would change: Settings › Privacy's model for it + movedClassifier = "classifier" // Claude Code's auto mode classifier: the model /model moved its tier to + movedClaudeTier = "claude-tier" // Claude Code's full id of a Claude model: the model set for its tier + movedStandIn = "stand-in" // a model magpie doesn't serve: the one the agent's config names + movedCodexTurn = "codex-turn" // Codex's memory or auto-review call: its last turn's model + movedCodexFollow = "codex-follow" // Codex's memory call on a bare default of its own magpie serves, nothing set for it: the conversation's model + movedPrivacy = "privacy" // a request masking would change: Settings › Privacy's model for it ) // standIn is StandIn's model for one magpie shows no entry for: not a @@ -2377,9 +2378,9 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro asked = grouped(at(m)) move(m, movedStandIn) } - if m := s.codexMemoryStandIn(r, call.Agent, agent, call.Kind, asked, body); m != "" { + if m, why := s.codexMemoryStandIn(r, call.Agent, agent, call.Kind, asked, body); m != "" { asked = m - move(m, movedCodexTurn) + move(m, why) } // a Codex subagent on the model set for Codex's subagents, whatever // its lead asked for (willz on Discord), and a Claude Desktop diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 7da709256..14332f58f 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -3499,6 +3499,7 @@ function routingPage(part) { case "claude-tier": return t("{agent} asked for {model} by Claude's full id; magpie served it on {to}, the model set for that tier.", v); case "stand-in": return t("{agent} asked for {model}, which magpie doesn't serve; magpie served it on {to}, the model its config names.", v); case "codex-turn": return t("{agent} asked for {model} for a call of its own, which magpie doesn't serve; magpie served it on {to}, the model its last turn was answered on.", v); + case "codex-follow": return t("{agent} asked for {model}, one of its own default models, for its memories, and its config names no model for them; magpie served it on {to}, the model of its conversation.", v); case "privacy": return t("Masking would have changed this request, so magpie sent it as written to {to}, the model set for that in Settings › Privacy.", v); default: return t("magpie served it on {to} in place of {model}.", v); } diff --git a/internal/gui/assets/plugins/routing/i18n.js b/internal/gui/assets/plugins/routing/i18n.js index f971b0d3b..b2f90f657 100644 --- a/internal/gui/assets/plugins/routing/i18n.js +++ b/internal/gui/assets/plugins/routing/i18n.js @@ -499,6 +499,7 @@ magpie.strings({ "{agent} asked for {model} by Claude's full id; magpie served it on {to}, the model set for that tier.": "{agent} 用 Claude 的完整 id 请求了 {model};magpie 让 {to} 来处理,即为该档位设定的模型。", "{agent} asked for {model}, which magpie doesn't serve; magpie served it on {to}, the model its config names.": "{agent} 请求了 {model},但 magpie 不提供它;magpie 让 {to} 来处理,即它配置里写的模型。", "{agent} asked for {model} for a call of its own, which magpie doesn't serve; magpie served it on {to}, the model its last turn was answered on.": "{agent} 为它自己的调用请求了 {model},但 magpie 不提供它;magpie 让 {to} 来处理,即它上一轮所用的模型。", + "{agent} asked for {model}, one of its own default models, for its memories, and its config names no model for them; magpie served it on {to}, the model of its conversation.": "{agent} 为它的记忆请求了它自己的默认模型 {model},而它的配置没有为记忆指定模型;magpie 让 {to} 来处理,即它这段对话所用的模型。", "Masking would have changed this request, so magpie sent it as written to {to}, the model set for that in Settings › Privacy.": "脱敏会改动这个请求,所以 magpie 把它原样发给了 {to},即在 设置 › 隐私 里为此设定的模型。", "magpie served it on {to} in place of {model}.": "magpie 让 {to} 代替 {model} 处理了它。", "Stand-in": "替代", @@ -1165,6 +1166,7 @@ magpie.strings({ "{agent} asked for {model} by Claude's full id; magpie served it on {to}, the model set for that tier.": "{agent} 用 Claude 的完整 id 請求了 {model};magpie 讓 {to} 來處理,即為該檔位設定的模型。", "{agent} asked for {model}, which magpie doesn't serve; magpie served it on {to}, the model its config names.": "{agent} 請求了 {model},但 magpie 不提供它;magpie 讓 {to} 來處理,即它設定裡寫的模型。", "{agent} asked for {model} for a call of its own, which magpie doesn't serve; magpie served it on {to}, the model its last turn was answered on.": "{agent} 為它自己的呼叫請求了 {model},但 magpie 不提供它;magpie 讓 {to} 來處理,即它上一輪所用的模型。", + "{agent} asked for {model}, one of its own default models, for its memories, and its config names no model for them; magpie served it on {to}, the model of its conversation.": "{agent} 為它的記憶請求了它自己的預設模型 {model},而它的設定沒有為記憶指定模型;magpie 讓 {to} 來處理,即它這段對話所用的模型。", "Masking would have changed this request, so magpie sent it as written to {to}, the model set for that in Settings › Privacy.": "去識別化會改動這個請求,所以 magpie 把它原樣送給了 {to},即在 設定 › 隱私 裡為此設定的模型。", "magpie served it on {to} in place of {model}.": "magpie 讓 {to} 代替 {model} 處理了它。", "Stand-in": "替代", @@ -1829,6 +1831,7 @@ magpie.strings({ "{agent} asked for {model} by Claude's full id; magpie served it on {to}, the model set for that tier.": "{agent} が Claude の完全な id で {model} をリクエストしました。magpie は {to}(そのティアに設定されたモデル)で応答しました。", "{agent} asked for {model}, which magpie doesn't serve; magpie served it on {to}, the model its config names.": "{agent} は magpie が提供していない {model} をリクエストしました。magpie は {to}(設定に書かれたモデル)で応答しました。", "{agent} asked for {model} for a call of its own, which magpie doesn't serve; magpie served it on {to}, the model its last turn was answered on.": "{agent} は自身の呼び出しに magpie が提供していない {model} をリクエストしました。magpie は {to}(直前のターンに応答したモデル)で応答しました。", + "{agent} asked for {model}, one of its own default models, for its memories, and its config names no model for them; magpie served it on {to}, the model of its conversation.": "{agent} はメモリのために自身のデフォルトモデル {model} をリクエストしましたが、設定でメモリ用のモデルが指定されていません。magpie は {to}(会話のモデル)で応答しました。", "Masking would have changed this request, so magpie sent it as written to {to}, the model set for that in Settings › Privacy.": "マスキングでこのリクエストが変わるため、magpie はそのまま {to}(設定 › プライバシーで指定されたモデル)に送りました。", "magpie served it on {to} in place of {model}.": "magpie は {model} の代わりに {to} で応答しました。", "Stand-in": "代替", @@ -2495,6 +2498,7 @@ magpie.strings({ "{agent} asked for {model} by Claude's full id; magpie served it on {to}, the model set for that tier.": "{agent} hat {model} mit Claudes voller ID angefordert; magpie hat sie mit {to} beantwortet, dem für diese Stufe festgelegten Modell.", "{agent} asked for {model}, which magpie doesn't serve; magpie served it on {to}, the model its config names.": "{agent} hat {model} angefordert, das magpie nicht anbietet; magpie hat sie mit {to} beantwortet, dem Modell aus seiner Konfiguration.", "{agent} asked for {model} for a call of its own, which magpie doesn't serve; magpie served it on {to}, the model its last turn was answered on.": "{agent} hat für einen eigenen Aufruf {model} angefordert, das magpie nicht anbietet; magpie hat ihn mit {to} beantwortet, dem Modell, das seinen letzten Zug beantwortet hat.", + "{agent} asked for {model}, one of its own default models, for its memories, and its config names no model for them; magpie served it on {to}, the model of its conversation.": "{agent} hat für seine Erinnerungen {model} angefordert, eines seiner eigenen Standardmodelle, und seine Konfiguration legt dafür kein Modell fest; magpie hat sie mit {to} beantwortet, dem Modell seiner Unterhaltung.", "Masking would have changed this request, so magpie sent it as written to {to}, the model set for that in Settings › Privacy.": "Die Maskierung hätte diese Anfrage verändert, daher hat magpie sie unverändert an {to} gesendet, das dafür unter Einstellungen › Datenschutz festgelegte Modell.", "magpie served it on {to} in place of {model}.": "magpie hat sie mit {to} statt {model} beantwortet.", "Stand-in": "Ersatz", diff --git a/internal/gui/tests/routing-moved-why.test.cjs b/internal/gui/tests/routing-moved-why.test.cjs index a6d78eaac..10dd1c24f 100644 --- a/internal/gui/tests/routing-moved-why.test.cjs +++ b/internal/gui/tests/routing-moved-why.test.cjs @@ -24,6 +24,7 @@ const req = (id, agent, session, model, provider, sent, extra = {}) => ({ id, se const opus = "chatflowsai/claude-opus-5-5", gpt = "agentrouter/gpt-6.1-sol"; // Newest first, as the list shows them. The oldest replays first. const routes = [ + req(6, "codex", "cx", "gpt-6.1-terra", "fake", "m2", { kind: "memory_consolidation", moved: { to: "fake/m2", why: "codex-follow" } }), req(5, "claude-desktop", "desk", gpt, "agentrouter", "gpt-6.1-sol"), req(4, "claude-desktop", "", opus, "agentrouter", "gpt-6.1-sol", { kind: "connection_check", moved: { to: gpt, why: "desktop-check" } }), req(3, "claude", "term", "fake/m1", "fake", "m2", { moved: { to: "fake/m2", why: "privacy" } }), @@ -42,7 +43,7 @@ function serve(lang) { if (url.pathname === "/api/state") return json(state); if (url.pathname === "/api/gateway/trace") { if (url.searchParams.has("wait")) return new Promise(() => {}); - return json({ mine: true, now: new Date().toISOString(), seq: 5, totals: { requests: 5, rerouted: 0, errors: 0 }, routes }); + return json({ mine: true, now: new Date().toISOString(), seq: 6, totals: { requests: 6, rerouted: 0, errors: 0 }, routes }); } if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] }); if (url.pathname === "/api/gateway/session-titles") return json({ titles: {} }); @@ -60,23 +61,28 @@ function serve(lang) { // Expected reader-facing words, independent of the translation lookup. const W = { - en: { title: "Title", check: "Connection check", stood: "Stand-in", review: "Review", + en: { memory: "Memory", follow: "Codex asked for gpt-6.1-terra, one of its own default models, for its memories, and its config names no model for them; magpie served it on fake/m2, the model of its conversation.", + title: "Title", check: "Connection check", stood: "Stand-in", review: "Review", titleWhy: "Claude Desktop picked chatflowsai/claude-opus-5-5 by itself for a short request without tools, such as a chat's title; magpie served it on agentrouter/gpt-6.1-sol, the model of its latest chat turn, so it stays with the provider the chat is on.", privacy: "Masking would have changed this request, so magpie sent it as written to fake/m2, the model set for that in Settings › Privacy.", codex: "Codex asked for fake/m1 for a call of its own, which magpie doesn't serve; magpie served it on fake/m2, the model its last turn was answered on." }, - zh: { title: "标题", check: "连接检查", stood: "替代", review: "审查", + zh: { memory: "记忆", follow: "Codex 为它的记忆请求了它自己的默认模型 gpt-6.1-terra,而它的配置没有为记忆指定模型;magpie 让 fake/m2 来处理,即它这段对话所用的模型。", + title: "标题", check: "连接检查", stood: "替代", review: "审查", titleWhy: "Claude Desktop 自行选了 chatflowsai/claude-opus-5-5 来发一个不带工具的短请求(比如对话标题);magpie 让 agentrouter/gpt-6.1-sol 来处理,即它最近一轮对话所用的模型,这样它留在对话所在的服务商。", privacy: "脱敏会改动这个请求,所以 magpie 把它原样发给了 fake/m2,即在 设置 › 隐私 里为此设定的模型。", codex: "Codex 为它自己的调用请求了 fake/m1,但 magpie 不提供它;magpie 让 fake/m2 来处理,即它上一轮所用的模型。" }, - "zh-TW": { title: "標題", check: "連線檢查", stood: "替代", review: "審查", + "zh-TW": { memory: "記憶", follow: "Codex 為它的記憶請求了它自己的預設模型 gpt-6.1-terra,而它的設定沒有為記憶指定模型;magpie 讓 fake/m2 來處理,即它這段對話所用的模型。", + title: "標題", check: "連線檢查", stood: "替代", review: "審查", titleWhy: "Claude Desktop 自行選了 chatflowsai/claude-opus-5-5 來發一個不帶工具的短請求(例如對話標題);magpie 讓 agentrouter/gpt-6.1-sol 來處理,即它最近一輪對話所用的模型,這樣它留在對話所在的服務商。", privacy: "去識別化會改動這個請求,所以 magpie 把它原樣送給了 fake/m2,即在 設定 › 隱私 裡為此設定的模型。", codex: "Codex 為它自己的呼叫請求了 fake/m1,但 magpie 不提供它;magpie 讓 fake/m2 來處理,即它上一輪所用的模型。" }, - ja: { title: "タイトル", check: "接続チェック", stood: "代替", review: "レビュー", + ja: { memory: "メモリ", follow: "Codex はメモリのために自身のデフォルトモデル gpt-6.1-terra をリクエストしましたが、設定でメモリ用のモデルが指定されていません。magpie は fake/m2(会話のモデル)で応答しました。", + title: "タイトル", check: "接続チェック", stood: "代替", review: "レビュー", titleWhy: "Claude Desktop はツールなしの短いリクエスト(チャットのタイトルなど)に chatflowsai/claude-opus-5-5 を自分で選びました。magpie は agentrouter/gpt-6.1-sol(直近のチャットのターンのモデル)で応答し、チャットと同じプロバイダーに留めました。", privacy: "マスキングでこのリクエストが変わるため、magpie はそのまま fake/m2(設定 › プライバシーで指定されたモデル)に送りました。", codex: "Codex は自身の呼び出しに magpie が提供していない fake/m1 をリクエストしました。magpie は fake/m2(直前のターンに応答したモデル)で応答しました。" }, - de: { title: "Titel", check: "Verbindungstest", stood: "Ersatz", review: "Review", + de: { memory: "Memory", follow: "Codex hat für seine Erinnerungen gpt-6.1-terra angefordert, eines seiner eigenen Standardmodelle, und seine Konfiguration legt dafür kein Modell fest; magpie hat sie mit fake/m2 beantwortet, dem Modell seiner Unterhaltung.", + title: "Titel", check: "Verbindungstest", stood: "Ersatz", review: "Review", titleWhy: "Claude Desktop hat chatflowsai/claude-opus-5-5 selbst für eine kurze Anfrage ohne Werkzeuge gewählt, etwa den Titel eines Chats; magpie hat sie mit agentrouter/gpt-6.1-sol beantwortet, dem Modell seines letzten Chat-Zugs, damit sie beim Anbieter des Chats bleibt.", privacy: "Die Maskierung hätte diese Anfrage verändert, daher hat magpie sie unverändert an fake/m2 gesendet, das dafür unter Einstellungen › Datenschutz festgelegte Modell.", codex: "Codex hat für einen eigenen Aufruf fake/m1 angefordert, das magpie nicht anbietet; magpie hat ihn mit fake/m2 beantwortet, dem Modell, das seinen letzten Zug beantwortet hat." }, @@ -114,9 +120,9 @@ for (const engine of engines) { const k = r.querySelectorAll(".kind"); return k.length > 1 ? "two tags" : k[0] ? [k[0].textContent, k[0].title] : ["", ""]; })); - const want = [["", ""], [w.check], [w.stood, w.privacy], [w.review], [w.title, w.titleWhy]]; + const want = [[w.memory], ["", ""], [w.check], [w.stood, w.privacy], [w.review], [w.title, w.titleWhy]]; const same = (got, msg) => assert.deepEqual(got.map((x, i) => want[i].length === 1 ? [x[0]] : x), want, msg); - const said = [null, null, w.privacy, w.codex, w.titleWhy]; + const said = [w.follow, null, null, w.privacy, w.codex, w.titleWhy]; // the list, by request: the tag beside the model, the reason under // the pointer and in the row's title, nothing pushed out of the row @@ -148,7 +154,7 @@ for (const engine of engines) { continue; } assert.equal(story.split(s).length - 1, 1, `row ${i}: ${s}\nonce in\n${story}`); - assert.deepEqual(stood, i === 3 ? [] : [want[i][0]], `story tag of row ${i}`); + assert.deepEqual(stood, i === 0 || i === 4 ? [] : [want[i][0]], `story tag of row ${i}`); } // the replay: the oldest, Desktop's title, goes first with its tag @@ -169,7 +175,7 @@ for (const engine of engines) { await page.close(); page = await open("http://magpie.test/?view=routing", { width, height: 760 }, true); await page.locator(".rt-req").nth(routes.length - 1).waitFor(); - const sorted = (xs) => xs.map((x) => x[0] === w.review || x[0] === w.check ? [x[0]] : x).map((x) => JSON.stringify(x)).sort(); + const sorted = (xs) => xs.map((x) => x[0] === w.review || x[0] === w.check || x[0] === w.memory ? [x[0]] : x).map((x) => JSON.stringify(x)).sort(); assert.deepEqual(sorted(await tags(page, ".rt-req")), sorted(want), "by session"); // the tray panel's rows, from the live trace @@ -179,7 +185,7 @@ for (const engine of engines) { const pr = await panel.locator(".pr-req").evaluateAll((rows) => rows.map((r) => [r.querySelector(".pr-a .kind")?.textContent || "", r.querySelector(".pr-a .kind")?.title || ""])); same(pr, "panel"); const pt = await panel.locator(".pr-req").evaluateAll((rows) => rows.map((r) => r.title)); - assert(pt[4].includes(w.titleWhy), `panel title: ${pt[4]}`); + assert(pt[5].includes(w.titleWhy), `panel title: ${pt[5]}`); assert.deepEqual(errors, []); }); }