Skip to content

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

warm-up: Warm up now sends one account its warm-up at once (Codex and Claude)

yetone1801c96bfbeb
diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md
index 241bb97f9..5a6f07bce 100644
--- a/docs/subsystems/providers-accounts.md
+++ b/docs/subsystems/providers-accounts.md
@@ -233,6 +233,7 @@ and `TestHistoricalWindowHoldsUsesEachWindowsOwnReading`.
- The account Codex or Claude Code is signed in to can be paused (`SetLoginOn` off, #263) only while another of its accounts is on. The gateway then sends it nothing: Codex's own-model turns go through routing, which passes over it (`OwnPaused`), and a native compaction (`/responses/compact`) goes to the first account on that isn't resting, signed as that account (`compactOn` in [codex_backend.go](../../internal/gateway/codex_backend.go)). The last other account off, the paused one is used again. A switched-off Codex provider is not a pause: Codex's own-model requests still relay on its sign-in as they came.
- A switched-off provider (`Off`, #163) stays saved. The gateway says it is off instead of saying the model is unknown.
- A subscription switched off (`Off`) or whose account was removed from magpie (`Hidden`) is left alone in the background (`leftAlone` in [`left_alone.go`](../../internal/provider/left_alone.go); Riko on Discord, whose Claude switched off still ran `claude auth status --json` every minute). No CLI is asked who is signed in (`claudeIdentity`, `cliIdentity.get` for Cursor and Devin): what it said last, in memory or `cli-identity.json`, is served, so the account stays listed to switch on again. Nor is its allowance read (`fetchSubscriptionUsage`, `loginUsageAt`), a saved ChatGPT sign-in renewed (`RenewLogins`), the agent's account switched (`NextLogin`), a window warmed (`keepWarm`), its model list fetched (`newDue`), a daily check-in made by the loop (`checkinNow` with `soon` false; a press still checks in), or a Codex reset about to run out read and spent (`SpendExpiringCodexResets`, #2226; `TestExpiringResetLeftAlone`). A Cursor switched off that was never asked who is signed in isn't listed until it is switched on. `TestLeftAloneRunsNoCLI` runs those paths with fake `claude`, `cursor-agent` and `devin` CLIs on PATH and checks none ran. Plugins' model lists (`KeepPluginsListed`) are asked of the plugin host all at once and aren't held back per provider.
+- *Warm up now*, the last row of Settings › Usage's Codex and Claude Code warm-up tabs (`renderWarmNow` in `app.js`, `POST /api/warm-now`), sends one account the request the scheduled warm-up sends, whatever the warm-up settings say ([`warm_now.go`](../../internal/provider/warm_now.go)): `warmCodexLogin` for a ChatGPT account, then `StaleAllowance`; for a Claude account Claude Code's own run, `warmClaudeLogin` over the gateway's `warmClaude` (`WarmClaudeVia`), in the saved account's directory, then `claudeWarmedNow`. With several accounts the press opens the app's menu of them. An account whose sign-in lapsed is sent nothing and says so, and the vendor's refusal comes back as the row's line, in red. The scheduled warm-up's file (`codex-warmup.json`) isn't written: its next look reads the window as started. `TestWarmNowSendsTheScheduledWarmUp` checks the body and headers equal the scheduled warm-up's; `warm-now.test.cjs` covers the GUI.
- An Antigravity subscription offers the union of its On accounts' models (`antigravityPoolModels` in [`antigravity_pool.go`](../../internal/provider/antigravity_pool.go)), each account's own list kept beside it (`accountModels`, read by `Account.Lists` for routing). The lists are fetched at the first listing, a probe, a sync or a Refetch, and also at each account's quota reading, which asks `fetchAvailableModels` anyway: a reading whose models differ from the account's saved list saves it and merges the pooled list again from every On account's own (`noteAntigravityList`), so a model Google gives one account of several later (01huadalang on Discord: Gemini 4) is offered, routed to and given its bar without that account made preferred or probed. A switched-off account's reading changes nothing. `TestAntigravityQuotaReadingListsNewModels`. Each `fetchAvailableModels` names the account's paid and current tier first (`entitlement.userTier`, `askTiers`), then none; a tier Google answers 400 (a Google AI Pro account's g1-pro-tier, #1553) is left out of that account's lists and quota readings for `tierRefusedFor` (a day), and the refused request is no row of the request log.
- A provider removed or switched off takes its models out of the catalog. [Agent wiring](agent-wiring.md)'s `Reseat` moves agents off them.
- A preset marked `NoList` uses its preset model list instead of requesting `/models`, and ignores previously fetched lists, including their protocol and key restrictions, unless the user sets `ModelsURL` or chooses a region marked `Lists`. Each region can carry a different list. Volcengine Ark's Coding Plan and Agent Plan use separate preset lists. Both plans include their embedding model separately from agents' chat-model lists; Agent Plan additionally exposes its image- and video-generation models to Settings → Images; Ark itself refuses video generation on Small and Medium Agent Plans, which include it only in the Large and Max tiers. Models magpie does not yet serve (Agent Plan's speech models) are not advertised. Ark's pay-as-you-go region still fetches its own list. Coding's `/api/coding/v3/models` returns a general Ark catalog instead of the plan's model ids, while Agent's `/api/plan/v3/models` returns 404. [`presets.go`](../../internal/provider/presets.go) defines these choices; `List`, `fetch`, `live`, `planModels`, `PlanEmbeddings`, `PlanDrawers` and `PlanVideos` in [`models.go`](../../internal/provider/models.go) apply them when adding, refreshing and reading cached models. `TestVolcengineModelLists` checks that the plans make no list requests, ignore old cached lists and return their own preset models; pay-as-you-go and an explicit list URL still make requests.
diff --git a/internal/gateway/claude_warmup.go b/internal/gateway/claude_warmup.go
index e1f80725e..dd1067c17 100644
--- a/internal/gateway/claude_warmup.go
+++ b/internal/gateway/claude_warmup.go
@@ -76,6 +76,8 @@ func askClaude(ctx context.Context, configDir, model string) error {
func init() {
provider.ProbeClaudeVia(askClaude)
+ // Warm up now sends what the scheduled warm-up sends
+ provider.WarmClaudeVia(warmClaude)
provider.UsageClaudeVia(claudeUsage)
}
diff --git a/internal/gui/api.go b/internal/gui/api.go
index 85efcd9e9..02f931115 100644
--- a/internal/gui/api.go
+++ b/internal/gui/api.go
@@ -493,6 +493,8 @@ type settingsJSON struct {
// the ChatGPT accounts signed in, each of which can have a daily
// warm-up time of its own (#957)
CodexUsers []string `json:"codexUsers,omitempty"`
+ // and the Claude accounts, which Warm up now picks from
+ ClaudeUsers []string `json:"claudeUsers,omitempty"`
// the Codexes here that kept the background compaction's table (and
// its share) out of the config at the last sync: too old for it
// (before 0.163.0-alpha.8), or of no known version (codex_async.go)
@@ -673,7 +675,7 @@ func settingsState() settingsJSON {
s.LANPublic = gateway.PublicURLs(s.LANURLs)
}
s.CodexWarmed, s.ClaudeWarmed = latest(provider.CodexWarmed()), latest(provider.ClaudeWarmed())
- s.CodexUsers = codexUsers()
+ s.CodexUsers, s.ClaudeUsers = loginUsers("codex"), loginUsers("claude")
s.CodexAsyncHeld = agent.CodexAsyncHeld()
s.WorkBuddy, s.WorkBuddyCheckins = provider.HasWorkBuddy(), provider.WorkBuddyCheckins()
s.Trae, s.TraeCheckins = provider.HasTrae(), provider.TraeCheckins()
@@ -1801,6 +1803,20 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
}
writeJSON(rw, settingsState())
})
+ // Warm up now: one Codex or Claude account's warm-up sent at once, and
+ // why it failed
+ mux.HandleFunc("POST /api/warm-now", func(rw http.ResponseWriter, r *http.Request) {
+ var in struct{ Agent, User string }
+ if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
+ fail(rw, err)
+ return
+ }
+ if err := provider.WarmNow(r.Context(), in.Agent, in.User); err != nil {
+ fail(rw, err)
+ return
+ }
+ writeJSON(rw, map[string]bool{"ok": true})
+ })
// whether a Codex account spends one of its resets by itself once its
// week is used up, the Usage card's toggle, set on its own
// a Codex account's own daily warm-up time: "06:00", "off", or "" to
@@ -2845,10 +2861,10 @@ func tilde(p string) string {
return p
}
-// codexUsers is the ChatGPT accounts signed in, by name, each once.
-func codexUsers() []string {
+// loginUsers is agent's accounts signed in, by name, each once.
+func loginUsers(agent string) []string {
var out []string
- for _, l := range provider.Logins("codex") {
+ for _, l := range provider.Logins(agent) {
if l.User != "" && !slices.ContainsFunc(out, func(u string) bool { return strings.EqualFold(u, l.User) }) {
out = append(out, l.User)
}
diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css
index 5791c5f2f..6116a865e 100644
--- a/internal/gui/assets/app.css
+++ b/internal/gui/assets/app.css
@@ -3566,6 +3566,8 @@ input.words.search-key, input.words.search-url { flex: 1 1 120px; width: auto; m
.prefs .row.rule-editing .val.rule-add { flex-wrap: wrap; row-gap: 6px; }
.prefs .row.rule-editing .rule-tail { display: flex; align-items: center; gap: 6px; flex: 1 1 240px; min-width: 0; }
.row.pref .sub.err { color: var(--red); white-space: normal; }
+/* Warm up now's line holds a vendor's reason, which can be one long word */
+.row.warm-now .sub { white-space: normal; overflow-wrap: anywhere; }
.warm-at { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
.warm-at input.at { width: auto; height: 27px; padding: 0 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--card); color: var(--fg); font: inherit; font-size: 12.5px; font-variant-numeric: tabular-nums; outline: none; transition: border-color .12s, box-shadow .12s; }
.warm-at input.at:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 5c2934cd9..8463f8e7b 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -19599,6 +19599,8 @@ function renderSettings() {
(v) => savePrefs({ ...keep, claudeWarmAts: v, claudeWarmAt: v[0] || "" }));
renderWarmAtOwn(s);
renderAutoResetOwn(s);
+ renderWarmNow("codex", s.codexUsers, "#warmNowRow");
+ renderWarmNow("claude", s.claudeUsers, "#claudeWarmNowRow");
// each built-in vendor's daily check-in, its tab shown while one of its
// accounts is signed in (#694, #811): its switch, how each account went,
// and under it each account's own (#1902)
@@ -20857,8 +20859,47 @@ function renderWarmAtOwn(s) {
box.append(segs([["same", t("Same")], ["own", t("Own")], ["off", t("Off")]], mode, (v) =>
save(user, v === "same" ? "" : v === "off" ? "off" : s.codexWarmAt || "06:00")));
r.append(who, box);
- list.append(r);
- }
+ $("#warmNowRow").before(r); // Warm up now stays last
+ }
+}
+
+// renderWarmNow is Warm up now (a Windows user on Discord): one account's
+// warm-up request, the one the scheduled warm-up sends, sent at once. One
+// account is sent at a press; with more the press asks which. What it came
+// to stays on the row's line (warmNowSaid) across renders.
+const warmNowSaid = {};
+function renderWarmNow(agent, users, rowId) {
+ const row = $(rowId), sub = row.querySelector(".sub"), box = row.lastElementChild;
+ users = users || [];
+ row.hidden = !users.length;
+ const said = warmNowSaid[agent];
+ sub.textContent = said ? said.text : t("Sends the warm-up's one tiny request to an account now");
+ sub.classList.toggle("err", !!said?.bad);
+ const b = el("button", "text warm-now-go", t(users.length > 1 ? "Warm up…" : "Warm up"));
+ b.type = "button";
+ b.disabled = !!said?.busy;
+ b.classList.toggle("busy", !!said?.busy);
+ if (users.length > 1) b.setAttribute("aria-haspopup", "menu");
+ const send = async (user) => {
+ const say = (o) => { warmNowSaid[agent] = o; if ($(rowId).isConnected) renderWarmNow(agent, users, rowId); };
+ say({ busy: true, text: t("Warming up {who}…", { who: user }) });
+ try {
+ await api("warm-now", { agent, user });
+ say({ text: t("Warmed up {who} {when}", { who: user, when: syncWhen(new Date().toISOString()) }) });
+ status(t("Warmed up {who}", { who: user }), "ok");
+ loadQuotas(); // the window it started
+ } catch (e) {
+ say({ bad: true, text: t("Couldn't warm up {who}: {why}", { who: user, why: e.message }) });
+ status(t("Couldn't warm up {who}: {why}", { who: user, why: e.message }), "err");
+ }
+ };
+ b.onclick = (e) => {
+ e.stopPropagation();
+ if (users.length === 1) return send(users[0]);
+ if (b.classList.contains("open")) return closeProtoMenu();
+ openProtoMenu(b, users.map((u) => ({ v: u, name: u, note: "", literalName: true })), null, send, "Warm up which account", "sess-menu", "right");
+ };
+ box.replaceChildren(b);
}
// renderAlerts draws the usage alerts (#368): a notification when a window
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js
index 9bb903222..3bde367f1 100644
--- a/internal/gui/assets/i18n.js
+++ b/internal/gui/assets/i18n.js
@@ -1117,6 +1117,15 @@ const I18N = {
"Weekly": "每周",
"Weekly and 5-hour": "每周和 5 小时",
"One tiny request starts the next window at once": "发一条极小的请求,让下一个窗口立即开始计时",
+ "Warm up now": "现在预热",
+ "Sends the warm-up's one tiny request to an account now": "现在给一个账号发出预热的那条极小请求",
+ "Warm up": "预热",
+ "Warm up…": "预热…",
+ "Warm up which account": "预热哪个账号",
+ "Warming up {who}…": "正在预热 {who}…",
+ "Warmed up {who} {when}": "已预热 {who},{when}",
+ "Warmed up {who}": "已预热 {who}",
+ "Couldn't warm up {who}: {why}": "{who} 预热失败:{why}",
"One tiny request through Claude Code (Haiku) starts the next window at once": "通过 Claude Code(Haiku)发一条极小的请求,让下一个窗口立即开始计时",
"Starts each account's 5-hour window at this time every day": "每天到这个时间开启各账号的 5 小时窗口",
"Starts each account's 5-hour window at each of these times every day": "每天到其中每个时间开启各账号的 5 小时窗口",
@@ -5196,6 +5205,15 @@ const I18N = {
"Weekly": "每週",
"Weekly and 5-hour": "每週和 5 小時",
"One tiny request starts the next window at once": "發一條極小的請求,讓下一個時段立即開始計時",
+ "Warm up now": "現在預熱",
+ "Sends the warm-up's one tiny request to an account now": "現在給一個帳號發出預熱的那條極小請求",
+ "Warm up": "預熱",
+ "Warm up…": "預熱…",
+ "Warm up which account": "預熱哪個帳號",
+ "Warming up {who}…": "正在預熱 {who}…",
+ "Warmed up {who} {when}": "已預熱 {who},{when}",
+ "Warmed up {who}": "已預熱 {who}",
+ "Couldn't warm up {who}: {why}": "{who} 預熱失敗:{why}",
"One tiny request through Claude Code (Haiku) starts the next window at once": "透過 Claude Code(Haiku)發一條極小的請求,讓下一個時段立即開始計時",
"Starts each account's 5-hour window at this time every day": "每天到這個時間開啟各帳號的 5 小時時段",
"Starts each account's 5-hour window at each of these times every day": "每天到其中每個時間開啟各帳號的 5 小時時段",
@@ -9245,6 +9263,15 @@ const I18N = {
"Weekly": "週",
"Weekly and 5-hour": "週と 5 時間",
"One tiny request starts the next window at once": "ごく小さなリクエストを 1 件送り、次の期間をすぐに開始します",
+ "Warm up now": "今すぐウォームアップ",
+ "Sends the warm-up's one tiny request to an account now": "ウォームアップのごく小さなリクエストを今すぐアカウントに送ります",
+ "Warm up": "ウォームアップ",
+ "Warm up…": "ウォームアップ…",
+ "Warm up which account": "ウォームアップするアカウント",
+ "Warming up {who}…": "{who} をウォームアップ中…",
+ "Warmed up {who} {when}": "{who} をウォームアップしました({when})",
+ "Warmed up {who}": "{who} をウォームアップしました",
+ "Couldn't warm up {who}: {why}": "{who} をウォームアップできませんでした: {why}",
"One tiny request through Claude Code (Haiku) starts the next window at once": "Claude Code(Haiku)経由でごく小さなリクエストを 1 件送り、次の期間をすぐに開始します",
"Starts each account's 5-hour window at this time every day": "毎日この時刻に各アカウントの 5 時間枠を開始します",
"Starts each account's 5-hour window at each of these times every day": "毎日これらの各時刻に各アカウントの 5 時間枠を開始します",
@@ -13324,6 +13351,15 @@ const I18N = {
"Weekly": "Wöchentlich",
"Weekly and 5-hour": "Wöchentlich und 5 Stunden",
"One tiny request starts the next window at once": "Eine winzige Anfrage startet sofort das nächste Zeitfenster",
+ "Warm up now": "Jetzt vorwärmen",
+ "Sends the warm-up's one tiny request to an account now": "Sendet die winzige Vorwärm-Anfrage jetzt an ein Konto",
+ "Warm up": "Vorwärmen",
+ "Warm up…": "Vorwärmen…",
+ "Warm up which account": "Welches Konto vorwärmen",
+ "Warming up {who}…": "{who} wird vorgewärmt…",
+ "Warmed up {who} {when}": "{who} vorgewärmt, {when}",
+ "Warmed up {who}": "{who} vorgewärmt",
+ "Couldn't warm up {who}: {why}": "{who} konnte nicht vorgewärmt werden: {why}",
"One tiny request through Claude Code (Haiku) starts the next window at once": "Eine winzige Anfrage über Claude Code (Haiku) startet sofort das nächste Zeitfenster",
"Starts each account's 5-hour window at this time every day": "Startet das 5-Stunden-Zeitfenster jedes Kontos täglich zu dieser Uhrzeit",
"Starts each account's 5-hour window at each of these times every day": "Startet das 5-Stunden-Zeitfenster jedes Kontos täglich zu jeder dieser Uhrzeiten",
diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html
index ff8414fe1..60557730d 100644
--- a/internal/gui/assets/index.html
+++ b/internal/gui/assets/index.html
@@ -333,6 +333,10 @@
<div class="who"><div class="name" data-t>Daily warm-up</div><div class="sub" id="warmAtSub"></div></div>
<div id="warmAtSegs" class="warm-at"></div>
</div>
+ <div class="row pref warm-now" id="warmNowRow" hidden>
+ <div class="who"><div class="name" data-t>Warm up now</div><div class="sub" id="warmNowSub"></div></div>
+ <div id="warmNowBox"></div>
+ </div>
</div>
<div class="list prefs" id="claudeWarmList" role="tabpanel" aria-labelledby="warmTab-claude">
<div class="row pref">
@@ -343,6 +347,10 @@
<div class="who"><div class="name" data-t>Daily warm-up</div><div class="sub" id="claudeWarmAtSub"></div></div>
<div id="claudeWarmAtSegs" class="warm-at"></div>
</div>
+ <div class="row pref warm-now" id="claudeWarmNowRow" hidden>
+ <div class="who"><div class="name" data-t>Warm up now</div><div class="sub" id="claudeWarmNowSub"></div></div>
+ <div id="claudeWarmNowBox"></div>
+ </div>
</div>
<div class="list prefs" id="wbList" role="tabpanel" aria-labelledby="warmTab-wb">
<div class="row pref" id="wbCheckinRow">
diff --git a/internal/gui/tests/warm-now.test.cjs b/internal/gui/tests/warm-now.test.cjs
new file mode 100644
index 000000000..0cc8c12b5
--- /dev/null
+++ b/internal/gui/tests/warm-now.test.cjs
@@ -0,0 +1,157 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// Warm up now (a Windows user on Discord): the last row of Settings › Usage's
+// Codex and Claude Code warm-up tabs sends one account the warm-up's request
+// at once (POST /api/warm-now {agent, user}). One account goes at a press;
+// with more the press opens the app's menu of them (no <select>). What it
+// came to stays on the row's line: done, or failed with the vendor's reason,
+// in red. The row is hidden with no account; a click never moves the page;
+// nothing runs off the side at 440px. en, zh, zh-TW, ja, de; the API is faked here.
+const assert = require("node:assert/strict");
+const fs = require("node:fs/promises");
+const path = require("node:path");
+const { test } = require("node:test");
+const { chromium, webkit } = require("playwright");
+
+const assets = path.resolve(__dirname, "../assets");
+const WHY = "429 Too Many Requests: {\"detail\":\"usage limit reached\"} https://chatgpt.com/backend-api/codex/responses-with-a-very-long-unbroken-reason";
+
+function serve(lang, asked, codexUsers, claudeUsers) {
+ const settings = { theme: "light", lang, currency: "usd", codexWarmup: "", codexUsers, claudeUsers };
+ return async (route) => {
+ const url = new URL(route.request().url());
+ const json = (data, status = 200) => route.fulfill({ status, json: data });
+ if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
+ if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
+ if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings });
+ if (url.pathname === "/api/settings") return json(settings);
+ if (url.pathname === "/api/warm-now") {
+ const b = route.request().postDataJSON();
+ asked.push([b.agent, b.user]);
+ return b.user === "[email protected]" ? json({ error: WHY }, 400) : json({ ok: true });
+ }
+ if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
+ if (url.pathname === "/api/plugins") return json({ plugins: [] });
+ if (url.pathname.startsWith("/api/")) return json({});
+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
+ try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
+ };
+}
+
+const W = {
+ en: { name: "Warm up now", go: "Warm up", pick: "Warm up…", head: "Warm up which account", done: "Warmed up [email protected] at ", failed: "Couldn't warm up [email protected]: ", own: "Warmed up [email protected] at " },
+ zh: { name: "现在预热", go: "预热", pick: "预热…", head: "预热哪个账号", done: "已预热 [email protected],", failed: "[email protected] 预热失败:", own: "已预热 [email protected]," },
+ "zh-TW": { name: "現在預熱", go: "預熱", pick: "預熱…", head: "預熱哪個帳號", done: "已預熱 [email protected],", failed: "[email protected] 預熱失敗:", own: "已預熱 [email protected]," },
+ ja: { name: "今すぐウォームアップ", go: "ウォームアップ", pick: "ウォームアップ…", head: "ウォームアップするアカウント", done: "[email protected] をウォームアップしました(", failed: "[email protected] をウォームアップできませんでした: ", own: "[email protected] をウォームアップしました(" },
+ de: { name: "Jetzt vorwärmen", go: "Vorwärmen", pick: "Vorwärmen…", head: "Welches Konto vorwärmen", done: "[email protected] vorgewärmt, ", failed: "[email protected] konnte nicht vorgewärmt werden: ", own: "[email protected] vorgewärmt, " },
+};
+
+// where the button the reader pressed is on the screen: it stays there while
+// the line beside it grows to hold a reason (gui-shell.md, "A click never
+// moves"), so the view's scrollTop may change, the button may not
+const at = (loc) => loc.evaluate((b) => Math.round(b.getBoundingClientRect().top));
+const sideways = (page) => page.evaluate(() => {
+ const out = [];
+ const de = document.documentElement, v = document.querySelector("#view-settings");
+ if (de.scrollWidth > de.clientWidth) out.push("page");
+ if (v.scrollWidth > v.clientWidth) out.push("view");
+ for (const r of document.querySelectorAll(".row.warm-now:not([hidden])")) {
+ const rr = r.getBoundingClientRect();
+ for (const e of r.querySelectorAll(".name, .sub, button")) {
+ const b = e.getBoundingClientRect();
+ if (b.right > rr.right + 0.5 || b.left < rr.left - 0.5) out.push(r.id + " " + e.className);
+ }
+ }
+ return out;
+});
+const launch = (engine) => engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" });
+
+for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+ for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
+ const w = W[lang];
+ for (const width of [900, 440]) {
+ test(`${engine} ${lang} ${width}px: Warm up now sends one account's warm-up and says what it came to`, async (t) => {
+ const browser = await launch(engine);
+ t.after(() => browser.close());
+ const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
+ page.setDefaultTimeout(5000);
+ const errors = [], asked = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", serve(lang, asked, ["[email protected]", "[email protected]"], ["[email protected]"]));
+ await page.goto("http://magpie.test/?view=settings&tab=usage");
+ const row = page.locator("#warmNowRow");
+ await row.locator("button").waitFor();
+ assert.equal((await row.locator(".name").innerText()).trim(), w.name);
+ // last in the tab, under each account's own daily row
+ assert.equal(await page.evaluate(() => document.querySelector("#codexWarmList").lastElementChild.id), "warmNowRow");
+ assert.equal(await page.locator("#codexWarmList .warm-own").count(), 2);
+ const go = row.locator("button");
+ assert.equal((await go.innerText()).trim(), w.pick);
+ assert.equal(await go.getAttribute("aria-haspopup"), "menu");
+ assert.deepEqual(await sideways(page), []);
+
+ await page.mouse.move(220, 400);
+ for (let i = 0; i < 12; i++) { await page.mouse.wheel(0, 400); await page.waitForTimeout(20); }
+ const y = await at(go);
+ // two accounts: the press asks which, in the app's menu
+ await go.click();
+ const menu = page.locator(".proto-menu");
+ await menu.waitFor();
+ assert.equal((await menu.locator(".pm-head").innerText()).trim(), w.head);
+ assert.deepEqual((await menu.locator(".pm-name").allInnerTexts()).map((s) => s.trim()), ["[email protected]", "[email protected]"]);
+ assert.deepEqual(asked, [], "the menu opening sent nothing");
+ await menu.locator(".pm-item").nth(1).click();
+ await page.waitForFunction((s) => document.querySelector("#warmNowSub")?.textContent.startsWith(s), w.done);
+ assert.deepEqual(asked, [["codex", "[email protected]"]], "that account alone, by its name as it is");
+ assert.equal(await page.locator("#warmNowSub.err").count(), 0);
+ if (process.env.ARTIFACT_DIR) await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `warm-now-${engine}-${lang}-${width}-done.png`) });
+
+ // refused: the vendor's reason, in red, on the line and in the status
+ await go.click();
+ await menu.locator(".pm-item").nth(0).click();
+ await page.waitForFunction(() => document.querySelector("#warmNowSub.err"));
+ assert.equal((await page.locator("#warmNowSub").innerText()).trim(), w.failed + WHY);
+ assert.ok((await page.locator("#status").textContent()).includes("usage limit reached"));
+ assert.deepEqual(asked, [["codex", "[email protected]"], ["codex", "[email protected]"]]);
+ assert.equal(await go.isDisabled(), false, "pressable again");
+ if (process.env.ARTIFACT_DIR) await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `warm-now-${engine}-${lang}-${width}-failed.png`) });
+ // the click guard puts a redraw's move back before it's painted, a
+ // frame later in WebKit: the button's place once that frame is done
+ const settled = () => page.evaluate(() => new Promise((ok) => requestAnimationFrame(() => requestAnimationFrame(ok))));
+ await settled();
+ assert.ok(Math.abs(await at(go) - y) <= 1, `a click moved the page: the button went from ${y} to ${await at(go)}`);
+ assert.deepEqual(await sideways(page), []);
+
+ // Claude Code's tab: one account, sent at a press
+ await page.locator("#warmTab-claude").click();
+ const crow = page.locator("#claudeWarmNowRow");
+ await crow.locator("button").waitFor();
+ assert.equal((await crow.locator("button").innerText()).trim(), w.go);
+ assert.equal(await crow.locator("button").getAttribute("aria-haspopup"), null);
+ await crow.locator("button").click();
+ await page.waitForFunction((s) => document.querySelector("#claudeWarmNowSub")?.textContent.startsWith(s), w.own);
+ assert.deepEqual(asked.at(-1), ["claude", "[email protected]"]);
+ assert.equal(asked.length, 3);
+ assert.deepEqual(await sideways(page), []);
+ assert.equal(await page.locator("select").count(), 0);
+ assert.deepEqual(errors, []);
+ });
+ }
+ }
+
+ test(`${engine}: no account, no Warm up now`, async (t) => {
+ const browser = await launch(engine);
+ t.after(() => browser.close());
+ const page = await (await browser.newContext({ viewport: { width: 900, height: 800 }, reducedMotion: "reduce" })).newPage();
+ page.setDefaultTimeout(5000);
+ const errors = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", serve("en", [], undefined, undefined));
+ await page.goto("http://magpie.test/?view=settings&tab=usage");
+ await page.locator("#warmAtSegs .opt").first().waitFor();
+ assert.equal(await page.locator("#warmNowRow").isHidden(), true);
+ assert.equal(await page.locator("#claudeWarmNowRow").isHidden(), true);
+ assert.deepEqual(errors, []);
+ });
+}
diff --git a/internal/gui/warm_now_api_test.go b/internal/gui/warm_now_api_test.go
new file mode 100644
index 000000000..370b5cb05
--- /dev/null
+++ b/internal/gui/warm_now_api_test.go
@@ -0,0 +1,38 @@
+package gui
+
+import (
+ "encoding/json"
+ "net/http/httptest"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// Warm up now's route answers a failure with why, as the row shows it: an
+// account that isn't signed in, or an agent with no warm-up, is a 400 with
+// the reason, and nothing is sent.
+func TestWarmNowAPISaysWhy(t *testing.T) {
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("USERPROFILE", home)
+ t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
+ t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
+ t.Setenv("CODEX_HOME", filepath.Join(home, ".codex"))
+ t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join(home, ".claude"))
+ t.Setenv("MAGPIE_NO_ACCOUNTS", "1") // no sign-in read, the Keychain's included
+ h := Handler(nil, nil)
+ for _, c := range []struct{ body, want string }{
+ {`{"agent":"codex","user":"[email protected]"}`, `no ChatGPT account "[email protected]"`},
+ {`{"agent":"claude","user":"[email protected]"}`, `no Claude account "[email protected]"`},
+ {`{"agent":"copilot","user":"octocat"}`, `"copilot" has no warm-up`},
+ {`{"agent":"codex"}`, `no ChatGPT account ""`},
+ } {
+ rec := httptest.NewRecorder()
+ h.ServeHTTP(rec, httptest.NewRequest("POST", "/api/warm-now", strings.NewReader(c.body)))
+ var out struct{ Error string }
+ json.Unmarshal(rec.Body.Bytes(), &out)
+ if rec.Code != 400 || !strings.Contains(out.Error, c.want) {
+ t.Errorf("%s: %d %s, want 400 saying %s", c.body, rec.Code, rec.Body, c.want)
+ }
+ }
+}
diff --git a/internal/provider/warm_now.go b/internal/provider/warm_now.go
new file mode 100644
index 000000000..728e721bf
--- /dev/null
+++ b/internal/provider/warm_now.go
@@ -0,0 +1,71 @@
+package provider
+
+// Warm up now (a Windows user on Discord): one account's warm-up sent at
+// once from Settings › Warm-up and check-in, whatever the warm-up settings
+// say. It is the request the scheduled warm-up sends — warmCodexLogin for
+// a ChatGPT account, Claude Code's own run (WarmClaudeVia) for a Claude
+// one — to that account alone, and what it says back is the result. The
+// scheduled warm-up's file is left to the scheduled one: its next look
+// reads the window as started, from its own read.
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "slices"
+ "strings"
+ "time"
+)
+
+// warmNowWait is how long Warm up now waits on its request, as long as
+// the scheduled warm-up gives one look.
+const warmNowWait = 2 * time.Minute
+
+// claudeWarmSend is a Claude warm-up's send, Claude Code asked with
+// configDir the config directory of a saved account, "" for the one it is
+// signed in to. The gateway, which runs Claude Code, sets it (WarmClaudeVia).
+var claudeWarmSend func(ctx context.Context, configDir string) error
+
+// WarmClaudeVia sets how a Claude account's warm-up runs Claude Code.
+func WarmClaudeVia(f func(ctx context.Context, configDir string) error) { claudeWarmSend = f }
+
+// WarmNow sends agent's ("codex" or "claude") account user the warm-up's
+// one tiny request now, and says why it failed. Once it went, what the
+// account has left is read again, as after a scheduled warm-up.
+func WarmNow(ctx context.Context, agent, user string) error {
+ var name string
+ switch agent {
+ case "codex":
+ name = "ChatGPT"
+ case "claude":
+ name = "Claude"
+ default:
+ return fmt.Errorf("%q has no warm-up", agent)
+ }
+ ls := Logins(agent)
+ i := slices.IndexFunc(ls, func(l Login) bool { return strings.EqualFold(l.User, user) })
+ if user == "" || i < 0 {
+ return fmt.Errorf("no %s account %q", name, user)
+ }
+ if ls[i].Lapsed != "" {
+ // as the scheduled warm-up leaves it out (codexWarmUsage)
+ return fmt.Errorf("%s needs signing in again: %s", ls[i].User, ls[i].Lapsed)
+ }
+ ctx, cancel := context.WithTimeout(ctx, warmNowWait)
+ defer cancel()
+ if agent == "codex" {
+ if err := warmCodexLogin(ctx, ls[i].User); err != nil {
+ return err
+ }
+ StaleAllowance("codex", ls[i].User)
+ return nil
+ }
+ if claudeWarmSend == nil {
+ return errors.New("Claude Code isn't available to send the warm-up")
+ }
+ if err := warmClaudeLogin(claudeWarmSend)(ctx, ls[i].User); err != nil {
+ return err
+ }
+ claudeWarmedNow(ls[i].User)
+ return nil
+}
diff --git a/internal/provider/warm_now_test.go b/internal/provider/warm_now_test.go
new file mode 100644
index 000000000..2802e260a
--- /dev/null
+++ b/internal/provider/warm_now_test.go
@@ -0,0 +1,159 @@
+package provider
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+)
+
+// Warm up now sends a ChatGPT account the very request the scheduled
+// warm-up sends, to that account alone and with the warm-ups off, and
+// says why it failed.
+func TestWarmNowSendsTheScheduledWarmUp(t *testing.T) {
+ signIn(t) // [email protected], acct-1, lists gpt-5.5
+ rememberLogins(true)
+ var mu sync.Mutex
+ var bodies []map[string]any
+ var hdrs []http.Header
+ refuse := false
+ fake := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ mu.Lock()
+ defer mu.Unlock()
+ switch r.URL.Path {
+ case "/backend-api/wham/usage":
+ // a week that hasn't started: nothing used, its reset a week off
+ json.NewEncoder(w).Encode(map[string]any{"plan_type": "plus", "rate_limit": map[string]any{
+ "primary_window": map[string]any{"used_percent": 0, "limit_window_seconds": 18000, "reset_after_seconds": 18000},
+ "secondary_window": map[string]any{"used_percent": 0, "limit_window_seconds": 604800, "reset_after_seconds": 604800}}})
+ case "/backend-api/codex/responses":
+ var m map[string]any
+ b, _ := io.ReadAll(r.Body)
+ json.Unmarshal(b, &m)
+ bodies, hdrs = append(bodies, m), append(hdrs, r.Header.Clone())
+ if refuse {
+ w.WriteHeader(http.StatusTooManyRequests)
+ io.WriteString(w, `{"detail":"usage limit reached"}`)
+ return
+ }
+ w.Header().Set("Content-Type", "text/event-stream")
+ io.WriteString(w, "event: response.completed\ndata: {\"type\":\"response.completed\"}\n\n")
+ default:
+ http.NotFound(w, r)
+ }
+ }))
+ defer fake.Close()
+ old := CodexBase
+ CodexBase = fake.URL + "/backend-api/codex"
+ t.Cleanup(func() { CodexBase = old })
+ sent := func() int { mu.Lock(); defer mu.Unlock(); return len(bodies) }
+
+ // the account as its name is typed, whatever its case
+ if err := WarmNow(context.Background(), "codex", "[email protected]"); err != nil {
+ t.Fatalf("warm up now: %v", err)
+ }
+ if sent() != 1 {
+ t.Fatalf("%d requests, want 1", sent())
+ }
+ // the scheduled warm-up's own request, for the same account
+ w := codexWarmer{path: codexWarmPath(), now: time.Now, usage: codexWarmUsage, send: warmCodexLogin}
+ if rs := w.warmNow(context.Background(), "week", nil); len(rs) != 1 || rs[0].Err != "" {
+ t.Fatalf("scheduled: %+v", rs)
+ }
+ if sent() != 2 {
+ t.Fatalf("%d requests, want 2", sent())
+ }
+ now, scheduled := bodies[0], bodies[1]
+ if a, b := warmJSON(t, now), warmJSON(t, scheduled); a != b {
+ t.Fatalf("Warm up now sent\n%s\nthe scheduled warm-up sends\n%s", a, b)
+ }
+ if now["model"] != "gpt-5.5" || now["store"] != false || now["instructions"] == nil {
+ t.Fatalf("body: %v", now)
+ }
+ for _, h := range []string{"Authorization", "chatgpt-account-id", "originator", "User-Agent", "Content-Encoding"} {
+ if hdrs[0].Get(h) != hdrs[1].Get(h) {
+ t.Errorf("%s: %q, the scheduled warm-up sends %q", h, hdrs[0].Get(h), hdrs[1].Get(h))
+ }
+ }
+
+ // refused: the vendor's reason comes back
+ refuse = true
+ err := WarmNow(context.Background(), "codex", "[email protected]")
+ if err == nil || !strings.Contains(err.Error(), "429") || !strings.Contains(err.Error(), "usage limit reached") {
+ t.Fatalf("refused: %v", err)
+ }
+ // no such account, or no warm-up for the agent: nothing sent
+ n := sent()
+ if err := WarmNow(context.Background(), "codex", "[email protected]"); err == nil {
+ t.Fatal("warmed an account that isn't signed in")
+ }
+ if err := WarmNow(context.Background(), "copilot", "octocat"); err == nil {
+ t.Fatal("warmed a Copilot account")
+ }
+ if sent() != n {
+ t.Fatalf("%d requests for accounts that aren't there", sent()-n)
+ }
+}
+
+// A Claude account's Warm up now is Claude Code's run the scheduled
+// warm-up makes (WarmClaudeVia), in that account's own config directory.
+func TestWarmNowClaudeRunsClaudeCode(t *testing.T) {
+ _, side := claudeAuthFixture(t, "")
+ rememberLogins(true) // the one Claude Code is signed in to, listed beside it
+ old := claudeWarmSend
+ t.Cleanup(func() { claudeWarmSend = old })
+ claudeWarmSend = nil
+ if err := WarmNow(context.Background(), "claude", side.User); err == nil {
+ t.Fatal("warmed with no Claude Code to send it")
+ }
+ var mu sync.Mutex
+ var dirs []string
+ fail := error(nil)
+ WarmClaudeVia(func(_ context.Context, dir string) error {
+ mu.Lock()
+ defer mu.Unlock()
+ dirs = append(dirs, dir)
+ return fail
+ })
+ if err := WarmNow(context.Background(), "claude", side.User); err != nil {
+ t.Fatalf("saved account: %v", err)
+ }
+ if err := WarmNow(context.Background(), "claude", "[email protected]"); err != nil {
+ t.Fatalf("own account: %v", err)
+ }
+ if len(dirs) != 2 || dirs[0] == "" || dirs[1] != "" {
+ t.Fatalf("Claude Code run in %q, want the saved account's directory, then its own", dirs)
+ }
+ fail = errors.New("Claude Code: You've hit your session limit")
+ if err := WarmNow(context.Background(), "claude", "[email protected]"); err == nil || !strings.Contains(err.Error(), "session limit") {
+ t.Fatalf("failed run: %v", err)
+ }
+}
+
+// An account whose sign-in lapsed is sent nothing, and says so.
+func TestWarmNowLapsedAccount(t *testing.T) {
+ _, side := claudeAuthFixture(t, "Failed to authenticate: OAuth token revoked")
+ old := claudeWarmSend
+ t.Cleanup(func() { claudeWarmSend = old })
+ ran := 0
+ WarmClaudeVia(func(context.Context, string) error { ran++; return nil })
+ err := WarmNow(context.Background(), "claude", side.User)
+ if err == nil || !strings.Contains(err.Error(), "signing in again") || ran != 0 {
+ t.Fatalf("lapsed: %v, %d runs", err, ran)
+ }
+}
+
+func warmJSON(t *testing.T, v any) string {
+ t.Helper()
+ b, err := json.Marshal(v)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(b)
+}