gui: Warm up on reset says a window that resets during sleep starts on waking

LEO_CHEN_X on X (https://x.com/LEO_CHEN_X/status/2113864310367961569):
on opening the lid, Codex's 5-hour window always shows 4h59m left, and
they took it to mean the auto-start is broken.

The code does what it should. keepWarm (internal/provider/codex_warmup.go)
checks every minute on a Go timer. On macOS that timer runs on
mach_absolute_time, which stops during sleep, so it fires within a minute
of waking. The 5-minute look goes by the wall clock, so the look is due
at once. warmNow then finds the window past its reset (asOf, even on a
read cached before sleep) and idle, and sends the one request. A window
still running at wake is not idle and gets nothing (checked in a scratch
test: an account warmed at 20:00 and woken at 22:00 sent nothing, and
one woken at 04:00 sent one). Nothing can send during sleep, and magpie
doesn't schedule a wake. Starting at wake is the earliest start there
is, no later than the user's own first request would make it.

What was wrong is that the row never said so. Daily warm-up's title
explains what a sleeping computer does with its time, and Warm up on
reset said nothing. Codex's and Claude Code's Warm up on reset lines now
carry a title (index.html data-tt, translated with the page) saying
nothing is sent while the computer sleeps, and that a window which
resets then starts on waking and counts from then. Translated into zh,
zh-TW, ja and de. The title is static, so app.js doesn't change and
TestCoreScriptBudget keeps its budget (an app.js version came in 754
bytes over).

Run at this tree:
- gofmt -l internal/: nothing. go vet, GOOS=linux go vet -tags nogui,
  GOOS=windows go vet on ./internal/gui ./internal/provider: ok.
  go build, GOOS=linux go build -tags nogui, GOOS=windows go build: ok.
- go test -tags nogui -timeout 45m -count=1 ./internal/gui: ok (92s).
- New internal/gui/tests/warm-reset-asleep.test.cjs: 10 of 10 in
  Chromium and WebKit, en zh zh-TW ja de. With the old index.html it
  fails 10 of 10.
- Both engines, 13 files: gui-de, gui-ja, gui-zh-tw, header-relang,
  i18n-keys, settings-general, settings-groups, settings-search,
  settings-sections, settings-tabs-stick, warm-at-own, warm-at-times
  and warm-reset-asleep, 162 of 162 pass.
Not run: the full GUI suite, since app.js is unchanged and no selector,
API or layout changed. Also not run: go test ./... and a real sleep and
wake of a Mac with a real account (the wake path was read in the code
and checked with the scratch test above).
This commit is contained in:
yetone
2026-10-24 16:46:04 +08:00
parent 4689ba69bd
commit 9d6436311a
3 changed files with 76 additions and 2 deletions
+4
View File
@@ -1082,6 +1082,7 @@ const I18N = {
"Sent through Claude Code.": "通过 Claude Code 发送。",
"One tiny request, sent only to an account whose 5-hour window isn't running then.": "只发一条极小的请求,且只发给那时 5 小时窗口没在计时的账号。",
"A computer asleep then sends it on waking, up to an hour late; later than that, the day is left be.": "届时电脑若在睡眠,醒来后一小时内补发;超过则跳过当天。",
"Nothing is sent while the computer sleeps: a window that resets then starts when it wakes, and counts from then.": "电脑睡眠时不会发送:睡眠期间重置的窗口在唤醒后开启,从唤醒时开始计时。",
"With Weekly and 5-hour on, a window that would still be running then isn't started on its reset: the windows follow one another from this time.": "同时开启「每周和 5 小时」时,届时仍在计时的窗口不在重置时开启:窗口从此时间起依次衔接。",
"Time of day": "时间",
"last started {when}": "上次启动于{when}",
@@ -4974,6 +4975,7 @@ const I18N = {
"Sent through Claude Code.": "透過 Claude Code 傳送。",
"One tiny request, sent only to an account whose 5-hour window isn't running then.": "只發一條極小的請求,且只發給那時 5 小時時段沒在計時的帳號。",
"A computer asleep then sends it on waking, up to an hour late; later than that, the day is left be.": "屆時電腦若在睡眠,醒來後一小時內補發;超過則跳過當天。",
"Nothing is sent while the computer sleeps: a window that resets then starts when it wakes, and counts from then.": "電腦睡眠時不會發送:睡眠期間重置的時段在喚醒後開啟,從喚醒時開始計時。",
"With Weekly and 5-hour on, a window that would still be running then isn't started on its reset: the windows follow one another from this time.": "同時開啟「每週和 5 小時」時,屆時仍在計時的時段不在重置時開啟:時段從此時間起依次銜接。",
"Time of day": "時間",
"last started {when}": "上次啟動於{when}",
@@ -8836,6 +8838,7 @@ const I18N = {
"Sent through Claude Code.": "Claude Code 経由で送信します。",
"One tiny request, sent only to an account whose 5-hour window isn't running then.": "ごく小さなリクエストを 1 件、その時点で 5 時間枠が動いていないアカウントにだけ送ります。",
"A computer asleep then sends it on waking, up to an hour late; later than that, the day is left be.": "その時刻にコンピュータがスリープしていた場合は、復帰後 1 時間以内なら送信します。それより遅ければその日はスキップします。",
"Nothing is sent while the computer sleeps: a window that resets then starts when it wakes, and counts from then.": "コンピュータのスリープ中は送信しません。スリープ中にリセットされた期間は復帰時に開始され、そこから数えます。",
"With Weekly and 5-hour on, a window that would still be running then isn't started on its reset: the windows follow one another from this time.": "「週と 5 時間」がオンのときは、その時刻にまだ動いている枠はリセット時に開始されません。枠はこの時刻から順に続きます。",
"Time of day": "時刻",
"last started {when}": "最終開始 {when}",
@@ -12728,6 +12731,7 @@ const I18N = {
"Sent through Claude Code.": "Über Claude Code gesendet.",
"One tiny request, sent only to an account whose 5-hour window isn't running then.": "Eine winzige Anfrage, nur an Konten, deren 5-Stunden-Zeitfenster dann nicht läuft.",
"A computer asleep then sends it on waking, up to an hour late; later than that, the day is left be.": "Schläft der Computer dann, sendet er sie beim Aufwachen bis zu einer Stunde später; danach entfällt der Tag.",
"Nothing is sent while the computer sleeps: a window that resets then starts when it wakes, and counts from then.": "Während der Computer schläft, wird nichts gesendet: Ein Zeitfenster, das dann zurückgesetzt wird, startet beim Aufwachen und zählt ab dann.",
"With Weekly and 5-hour on, a window that would still be running then isn't started on its reset: the windows follow one another from this time.": "Ist „Wöchentlich und 5 Stunden“ an, wird ein Zeitfenster, das dann noch laufen würde, nicht beim Reset gestartet: die Zeitfenster folgen ab dieser Uhrzeit aufeinander.",
"Time of day": "Uhrzeit",
"last started {when}": "zuletzt gestartet {when}",
+2 -2
View File
@@ -295,7 +295,7 @@
<div class="warm-panes" data-feature="warmups">
<div class="list prefs" id="codexWarmList" role="tabpanel" aria-labelledby="warmTab-codex">
<div class="row pref">
<div class="who"><div class="name" data-t>Warm up on reset</div><div class="sub" id="warmSub"></div></div>
<div class="who"><div class="name" data-t>Warm up on reset</div><div class="sub" id="warmSub" title="Nothing is sent while the computer sleeps: a window that resets then starts when it wakes, and counts from then." data-tt></div></div>
<div id="warmSegs"></div>
</div>
<div class="row pref">
@@ -305,7 +305,7 @@
</div>
<div class="list prefs" id="claudeWarmList" role="tabpanel" aria-labelledby="warmTab-claude">
<div class="row pref">
<div class="who"><div class="name" data-t>Warm up on reset</div><div class="sub" id="claudeWarmSub"></div></div>
<div class="who"><div class="name" data-t>Warm up on reset</div><div class="sub" id="claudeWarmSub" title="Nothing is sent while the computer sleeps: a window that resets then starts when it wakes, and counts from then." data-tt></div></div>
<div id="claudeWarmSegs"></div>
</div>
<div class="row pref">
@@ -0,0 +1,70 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Warm up on reset across sleep (LEO_CHEN_X on X, 10-24): nothing runs
// while the computer sleeps, so a window that resets then is started when
// it wakes (keepWarm, codex_warmup.go, within a minute) and counts from
// then: a full 5-hour window on opening the lid. Codex's and Claude Code's
// Warm up on reset rows say so in their line's title (index.html's
// data-tt, translated with the page), as Daily warm-up's says what a
// sleeping computer does with its time. 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 { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
function serve(lang) {
const settings = { theme: "light", lang, currency: "usd", codexWarmup: "all", claudeWarmup: "week", codexWarmed: "2026-10-24T01:00:00Z", codexUsers: ["a@example.com"] };
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ 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/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 ASLEEP = {
en: "Nothing is sent while the computer sleeps: a window that resets then starts when it wakes, and counts from then.",
zh: "电脑睡眠时不会发送:睡眠期间重置的窗口在唤醒后开启,从唤醒时开始计时。",
"zh-TW": "電腦睡眠時不會發送:睡眠期間重置的時段在喚醒後開啟,從喚醒時開始計時。",
ja: "コンピュータのスリープ中は送信しません。スリープ中にリセットされた期間は復帰時に開始され、そこから数えます。",
de: "Während der Computer schläft, wird nichts gesendet: Ein Zeitfenster, das dann zurückgesetzt wird, startet beim Aufwachen und zählt ab dann.",
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(ASLEEP)) {
test(`${engine} ${lang}: Warm up on reset says what a sleeping computer does`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width: 440, height: 800 } })).newPage();
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
await watchSettingsReads(page);
await page.goto("http://magpie.test/?view=settings&tab=usage");
await settingsDrawn(page);
for (const id of ["#warmSub", "#claudeWarmSub"]) {
const sub = page.locator(id);
// the language's own, once the page has put its words in
await page.waitForFunction(([id, want]) => document.querySelector(id)?.title === want, [id, ASLEEP[lang]]).catch(() => {});
const [shown, title] = await sub.evaluate((e) => [e.textContent, e.title]);
assert.equal(title, ASLEEP[lang], `${id}: what a sleeping computer does`);
assert.ok(shown && !shown.includes(title), `${id}: the line keeps its purpose, the fine print in the title (${shown})`);
}
assert.deepEqual(errors, []);
});
}
}