Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

routing: a try a plugin or Claude Code sent says why it has no time split

yetonef5dd4e1423cf
diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go
index 4476e3bc4..e7c6bd97a 100644
--- a/internal/gateway/gateway.go
+++ b/internal/gateway/gateway.go
@@ -3150,7 +3150,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
ended = time.Now()
try := Try{ID: c.rest, Model: c.model, Effort: wentAt, Picked: picked, Fixed: fixed, RuleEffort: ruled, Fast: fast, Start: began, Done: true, Status: call.Status, Millis: ended.Sub(began).Milliseconds(), Error: call.Error, Queued: queued,
Served: call.Usage.Served, Upstream: call.Usage.Upstream, Pin: c.p.ClinePassAsked(c.model), Tier: wentTier, TierServed: call.Usage.Tier, Auto: autoPicked(),
- Net: nt.timing(began, queued)}
+ Net: nt.timing(began, queued), SentBy: sentBy(c.p)}
if resetFirst != nil {
// the reset spent for it before it was asked
try.Reset, resetFirst = resetFirst, nil
diff --git a/internal/gateway/nettrace.go b/internal/gateway/nettrace.go
index 10cc6af9a..b642e5a14 100644
--- a/internal/gateway/nettrace.go
+++ b/internal/gateway/nettrace.go
@@ -7,6 +7,8 @@ import (
"sync"
"sync/atomic"
"time"
+
+ "github.com/yetone/magpie/internal/provider"
)
// TryNet is where a try's time went up to its reply's first byte, as Go's
@@ -165,6 +167,22 @@ func (n *netTrace) timing(began time.Time, queued int64) *TryNet {
return t
}
+// sentBy is what sends a request to p's vendor when magpie's own client
+// doesn't, which TryNet can't follow: "plugin", its plugin's fetch in the
+// plugin host; "claude", Claude Code's own run (the subscription bridge,
+// attempt); "" for magpie's client. The Routing page says it in place of
+// where the time went (Discord, lute: some requests had it and some
+// didn't, with nothing said).
+func sentBy(p provider.Provider) string {
+ switch {
+ case p.IsPlugin():
+ return "plugin"
+ case p.Account != nil && p.Account.Agent == "claude":
+ return "claude"
+ }
+ return ""
+}
+
// tenth is d in ms, to a tenth.
func tenth(d time.Duration) float64 {
return math.Round(float64(d)/float64(time.Millisecond)*10) / 10
diff --git a/internal/gateway/nettrace_test.go b/internal/gateway/nettrace_test.go
index 6e7186518..7b801cd6a 100644
--- a/internal/gateway/nettrace_test.go
+++ b/internal/gateway/nettrace_test.go
@@ -90,3 +90,32 @@ func TestTryNetWithoutARequest(t *testing.T) {
t.Fatalf("%+v", got)
}
}
+
+// lute on Discord: some requests on the Routing page said where their
+// time went and some didn't. A plugin sends its request itself, through
+// its host, so magpie has no timing for it: its try says who sent it,
+// which the page shows in the timing's place.
+func TestPluginTrySaysWhoSentIt(t *testing.T) {
+ pid := besideFake(t, "cursor", &cursorUp{})
+ r := postProto(t, New(), "/v1/chat/completions", `{"model":"`+pid+`/fake-1","messages":[{"role":"user","content":"hi"}]}`)
+ if len(r.Tries) != 1 || r.Tries[0].Net != nil || r.Tries[0].SentBy != "plugin" {
+ t.Fatalf("tries %+v", r.Tries)
+ }
+}
+
+// Who sent a try: a plugin, Claude Code for a Claude subscription, and
+// magpie itself, whose try has its timing, for the rest.
+func TestSentBy(t *testing.T) {
+ for _, c := range []struct {
+ p provider.Provider
+ want string
+ }{
+ {provider.Provider{ID: "claude", Account: &provider.Account{Agent: "claude", User: "u"}}, "claude"},
+ {provider.Provider{ID: "codex", Account: &provider.Account{Agent: "codex", User: "u"}}, ""},
+ {provider.Provider{ID: "a"}, ""},
+ } {
+ if got := sentBy(c.p); got != c.want {
+ t.Errorf("sentBy(%s) = %q, want %q", c.p.ID, got, c.want)
+ }
+ }
+}
diff --git a/internal/gateway/trace.go b/internal/gateway/trace.go
index 2cf7cbeb8..1565f78e8 100644
--- a/internal/gateway/trace.go
+++ b/internal/gateway/trace.go
@@ -356,6 +356,10 @@ type Try struct {
// first text, when it streamed any (#196)
TTFT int64 `json:"ttft,omitempty"`
FirstText int64 `json:"firstText,omitempty"`
+ // SentBy: what sent its request to the vendor when magpie's own
+ // client didn't, so it has no Net and the Routing page says why
+ // (sentBy)
+ SentBy string `json:"sentBy,omitempty"`
// FirstReasoning is the start of paced visible reasoning, absent for hidden reasoning.
FirstReasoning int64 `json:"firstReasoning,omitempty"`
ReasoningHidden bool `json:"reasoningHidden,omitempty"`
diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js
index 2d9cc96a4..bc87c968f 100644
--- a/internal/gui/assets/plugins/routing/client.js
+++ b/internal/gui/assets/plugins/routing/client.js
@@ -1206,6 +1206,11 @@ function routingPage(part) {
return out;
}
const WHO = { magpie: "magpie {ms}", net: "network {ms}", vendor: "vendor {ms}" };
+ // why a try that went out some other way has no split (gateway.sentBy)
+ const SENT_BY = {
+ plugin: "Its plugin sent this request itself, so magpie can't split its time",
+ claude: "Claude Code sent this request itself, so magpie can't split its time",
+ };
function timeSaid(tr) {
const parts = timeParts(tr);
if (!parts.length) return "";
@@ -2887,6 +2892,9 @@ function routingPage(part) {
const timed = i === 0 && r.masking > 0 ? { ...tr, masking: r.masking } : tr;
const when = tr.done && timeSaid(timed);
if (when) items.push([when, "aside time", timed]);
+ // a plugin or Claude Code sent it, out of magpie's sight: said, so
+ // its missing split doesn't read as a request that lost it (lute)
+ if (tr.done && !tr.net && tryOk(tr) && SENT_BY[tr.sentBy]) items.push([t(SENT_BY[tr.sentBy]), "aside"]);
// each model Copilot's Auto picked for it, where from, and whether
// Copilot refused it, on which API and with Auto's session token or
// without (#256)
diff --git a/internal/gui/assets/plugins/routing/i18n.js b/internal/gui/assets/plugins/routing/i18n.js
index bfb003a53..eced6e535 100644
--- a/internal/gui/assets/plugins/routing/i18n.js
+++ b/internal/gui/assets/plugins/routing/i18n.js
@@ -2,6 +2,8 @@
// kernel adds them to i18n.js's (magpie.strings).
magpie.strings({
zh: {
+ "Its plugin sent this request itself, so magpie can't split its time": "此请求由插件自行发出,magpie 无法拆分它的耗时",
+ "Claude Code sent this request itself, so magpie can't split its time": "此请求由 Claude Code 自行发出,magpie 无法拆分它的耗时",
"magpie is masking this request before routing it (Settings › Privacy), so who takes it isn't picked yet.": "magpie 正在给这个请求脱敏(设置 › 隐私),脱敏完才路由,所以还没选出由谁处理。",
"magpie hasn't routed this request yet, so who takes it isn't picked yet.": "magpie 还没开始路由这个请求,所以还没选出由谁处理。",
"Nothing took this request: {error}": "没有谁处理这个请求:{error}",
@@ -592,6 +594,8 @@ magpie.strings({
"Open Folder": "打开文件夹",
},
"zh-TW": {
+ "Its plugin sent this request itself, so magpie can't split its time": "此請求由外掛自行發出,magpie 無法拆分它的耗時",
+ "Claude Code sent this request itself, so magpie can't split its time": "此請求由 Claude Code 自行發出,magpie 無法拆分它的耗時",
"magpie is masking this request before routing it (Settings › Privacy), so who takes it isn't picked yet.": "magpie 正在為這個請求脫敏(設定 › 隱私),脫敏完才路由,所以還沒選出由誰處理。",
"magpie hasn't routed this request yet, so who takes it isn't picked yet.": "magpie 還沒開始路由這個請求,所以還沒選出由誰處理。",
"Nothing took this request: {error}": "沒有誰處理這個請求:{error}",
@@ -1182,6 +1186,8 @@ magpie.strings({
"Open Folder": "打開資料夾",
},
ja: {
+ "Its plugin sent this request itself, so magpie can't split its time": "このリクエストはプラグインが自ら送信したため、magpie では時間の内訳を出せません",
+ "Claude Code sent this request itself, so magpie can't split its time": "このリクエストは Claude Code が自ら送信したため、magpie では時間の内訳を出せません",
"magpie is masking this request before routing it (Settings › Privacy), so who takes it isn't picked yet.": "magpie はルーティングの前にこのリクエストをマスクしています(設定 › プライバシー)。誰が処理するかはまだ決まっていません。",
"magpie hasn't routed this request yet, so who takes it isn't picked yet.": "magpie はまだこのリクエストをルーティングしていないため、誰が処理するかはまだ決まっていません。",
"Nothing took this request: {error}": "このリクエストを処理したものはありません: {error}",
@@ -1772,6 +1778,8 @@ magpie.strings({
"Open Folder": "フォルダを開く",
},
de: {
+ "Its plugin sent this request itself, so magpie can't split its time": "Diese Anfrage hat die Erweiterung selbst gesendet, daher kann magpie ihre Zeit nicht aufschlüsseln",
+ "Claude Code sent this request itself, so magpie can't split its time": "Diese Anfrage hat Claude Code selbst gesendet, daher kann magpie ihre Zeit nicht aufschlüsseln",
"magpie is masking this request before routing it (Settings › Privacy), so who takes it isn't picked yet.": "magpie maskiert diese Anfrage vor der Weiterleitung (Einstellungen › Datenschutz), daher steht noch nicht fest, wer sie übernimmt.",
"magpie hasn't routed this request yet, so who takes it isn't picked yet.": "magpie hat diese Anfrage noch nicht weitergeleitet, daher steht noch nicht fest, wer sie übernimmt.",
"Nothing took this request: {error}": "Niemand hat diese Anfrage übernommen: {error}",
diff --git a/internal/gui/tests/routing-time-went.test.cjs b/internal/gui/tests/routing-time-went.test.cjs
index 771171b26..b07cd9208 100644
--- a/internal/gui/tests/routing-time-went.test.cjs
+++ b/internal/gui/tests/routing-time-went.test.cjs
@@ -4,7 +4,9 @@
// network's and the vendor's, and each part that took any, as one stacked
// bar and named values, the queue for a slot among them. A part that took
// none isn't named. A try sent through a plugin's own fetch, or traced
-// before magpie measured it, has no network timing and no breakdown. Both engines, a narrow window, every language; no
+// before magpie measured it, has no network timing and no breakdown; the
+// plugin's says it sent the request itself, so the missing split doesn't
+// read as lost (Discord, lute). Both engines, a narrow window, every language; no
// part runs out of the story, no left-border accent. The API is faked.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
@@ -26,7 +28,7 @@ const routes = [
tries: [{ id: key.id, model: "deepseek-chat", start: at(0), done: true, status: 200, ms: 4200, ttft: 2100, queued: 40, net }],
done: true, status: 200, ms: 4200, ttft: 2100, tokens: 900, served: "deepseek-chat" },
{ id: 100, seq: 100, time: at(1), agent: "codex", model: "kiro/claude-sonnet-4.5", provider: "kiro", order: [plug],
- tries: [{ id: plug.id, model: "claude-sonnet-4.5", start: at(1), done: true, status: 200, ms: 3000, ttft: 1200 }],
+ tries: [{ id: plug.id, model: "claude-sonnet-4.5", start: at(1), done: true, status: 200, ms: 3000, ttft: 1200, sentBy: "plugin" }],
done: true, status: 200, ms: 3000, ttft: 1200, tokens: 900, served: "claude-sonnet-4.5" },
];
@@ -63,11 +65,11 @@ function serve(lang) {
}
const want = {
- en: { head: "Where the time went", vendor: "Vendor (first byte)", slot: "Waiting for a slot" },
- zh: { head: "时间花在哪里", vendor: "供应商(首字节)", slot: "排队等空位" },
- "zh-TW": { head: "時間花在哪裡", vendor: "供應商(首位元組)", slot: "排隊等空位" },
- ja: { head: "時間の内訳", vendor: "ベンダー(最初のバイト)", slot: "空き枠待ち" },
- de: { head: "Wohin die Zeit ging", vendor: "Anbieter (erstes Byte)", slot: "Warten auf einen freien Platz" },
+ en: { head: "Where the time went", vendor: "Vendor (first byte)", slot: "Waiting for a slot", plugin: "Its plugin sent this request itself, so magpie can't split its time" },
+ zh: { head: "时间花在哪里", vendor: "供应商(首字节)", slot: "排队等空位", plugin: "此请求由插件自行发出,magpie 无法拆分它的耗时" },
+ "zh-TW": { head: "時間花在哪裡", vendor: "供應商(首位元組)", slot: "排隊等空位", plugin: "此請求由外掛自行發出,magpie 無法拆分它的耗時" },
+ ja: { head: "時間の内訳", vendor: "ベンダー(最初のバイト)", slot: "空き枠待ち", plugin: "このリクエストはプラグインが自ら送信したため、magpie では時間の内訳を出せません" },
+ de: { head: "Wohin die Zeit ging", vendor: "Anbieter (erstes Byte)", slot: "Warten auf einen freien Platz", plugin: "Diese Anfrage hat die Erweiterung selbst gesendet, daher kann magpie ihre Zeit nicht aufschlüsseln" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
@@ -135,6 +137,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator(".rt-req").nth(1).and(page.locator('[aria-pressed="true"]')).waitFor();
await page.locator(".rt-steps li.ok").first().waitFor();
assert.equal(await page.locator(".rt-time").count(), 0);
+ const why = page.locator(".rt-steps li.aside", { hasText: want[lang].plugin });
+ await why.waitFor();
+ assert.equal(await why.count(), 1);
+ // and the routed try, which has its split, says nothing of the kind
+ await page.locator(".rt-req").nth(0).click();
+ await page.locator(".rt-steps li.time .rt-time").waitFor();
+ assert.equal(await page.locator(".rt-steps li.aside", { hasText: want[lang].plugin }).count(), 0);
assert.deepEqual(errors, []);
});
}