From 1801c96bfbebcb7a3302e06fcf423dec5962a999 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 29 Oct 2026 15:31:09 +0800 Subject: [PATCH] warm-up: Warm up now sends one account its warm-up at once (Codex and Claude) A Windows user on Discord asked for a manual warm-up of a Codex account. Settings > Warm-up and check-in now ends both the ChatGPT and the Claude tab with a "Warm up now" row. Its text button sends the account's warm-up right away. With one account it sends straight off. With several it opens the app menu ("Warm up which account"), not a select. The row then says "Warmed up {who} {when}", or "Couldn't warm up {who}: {why}" in red, and the status line says the same. What is sent: provider.WarmNow(agent, user) sends the scheduled warm-up's own request to that one account and to no other. For Codex that is warmCodexLogin; for Claude it is warmClaudeLogin over the gateway's warmClaude (Claude Code's run in that account's config directory), set through WarmClaudeVia. It works whether the warm-ups are on or off. An account whose sign-in lapsed is refused with the reason. Afterwards the allowance is read again (StaleAllowance / claudeWarmedNow), as after a scheduled warm-up. The schedule's file is left to the schedule. The Codex prompt, identity and base_instructions are unchanged: it is the same body. The route is POST /api/warm-now, and /api/settings carries claudeUsers beside codexUsers. Claude gets the item too. It shares the warm-up engine and the same tab, and the send is the same warmClaude the schedule uses. No size budget was raised. Run: - WSL (wsl-run), Chromium and WebKit, with the GUI test warm-now.test.cjs in en/zh/zh-TW/ja/de at 900px and 440px: 22/22. The pressed button stays in place within 1px after two frames. - WSL, the related files (warm-now, warm-at-own, warm-at-times, warm-reset-asleep, settings-groups, settings-search, i18n-keys): 102/102. - WSL, the other files that touch these lists (checkin-account, checkin-reason, checkin-reason-once, plugin-checkin, segs-press-redraw, settings-sections, usage-checkin): 169/170. The red is segs-press-redraw "webkit ja 440px: every Settings option..." with "could not bring the option into view" after 103s under load. It passed 3/3 alone and is filed as #4189. - mote (macOS) at the final tree: go vet for internal/gui, provider and gateway; go test -run 'WarmNow|Budget|Warm' ./internal/gui ./internal/provider: ok. An earlier mote run, before the route move, ran go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build ./... and the budget tests: ok. - Windows (win-run): go test -run 'TestWarmNow|TestCodexWarm|TestClaudeWarm' ./internal/provider/ ./internal/gui/: ok. - WSL: go vet -tags nogui ./... is ok and gofmt -l is empty. go test -tags nogui -timeout 45m ./...: 75 packages ok, including internal/gui and internal/provider. internal/agent has 4 reds on the WSL box (TestInstalledVersion, TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI, TestOmpDetectedWithPiDir). They are already filed as #4033 and #3548 (fake binaries hit WSL interop). internal/gateway has 1 red, TestUnroutedRequestShownThenAnswered: giveUp answers the 504 before it marks the route done. That is not this change, and it is filed as #4200. At the head rebased on origin/main 9474eaf9c: - mote: gofmt -l is empty. go vet passes for gui, provider and gateway, and GOOS=windows go vet passes for gui and provider. go test -run 'WarmNow|Budget|Warm|I18n' ./internal/gui ./internal/provider: ok. - WSL: warm-now, i18n-keys and warm-at-own GUI tests: 44/44. Broken by hand (each was red, then restored and checked with cmp): - WarmNow swallowing the Codex error: TestWarmNowSendsTheScheduledWarmUp went red on the refused request. - Running Claude in ls[0]'s directory: TestWarmNowClaudeRunsClaudeCode went red. - Dropping the lapsed check: TestWarmNowLapsedAccount went red. - The menu always sending users[0]: warm-now.test.cjs went red (timed out) in both engines. Not tried: - A warm-up of a real account. The request-equality test compares against the scheduled warm-up's request through a fake vendor. - Breaking the request-equality check by changing the body itself. - The GUI suite on macOS, because mote's browsers hang (#4125). --- docs/subsystems/providers-accounts.md | 1 + internal/gateway/claude_warmup.go | 2 + internal/gui/api.go | 24 +++- internal/gui/assets/app.css | 2 + internal/gui/assets/app.js | 43 ++++++- internal/gui/assets/i18n.js | 36 ++++++ internal/gui/assets/index.html | 8 ++ internal/gui/tests/warm-now.test.cjs | 157 +++++++++++++++++++++++++ internal/gui/warm_now_api_test.go | 38 ++++++ internal/provider/warm_now.go | 71 ++++++++++++ internal/provider/warm_now_test.go | 159 ++++++++++++++++++++++++++ 11 files changed, 536 insertions(+), 5 deletions(-) create mode 100644 internal/gui/tests/warm-now.test.cjs create mode 100644 internal/gui/warm_now_api_test.go create mode 100644 internal/provider/warm_now.go create mode 100644 internal/provider/warm_now_test.go 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,10 +20859,49 @@ 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 // that routing counts reaches the share set, or a balance falls to the // amount set, each once; Off, or the number in a field beside On. 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 @@
Daily warm-up
+
@@ -343,6 +347,10 @@
Daily warm-up
+
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