A Codex reset card that would run out unused was spent 30 minutes before
it expired, a fixed resetExpiryLead. Now the lead is codexResetLead in
settings.json (minutes, 15 to 1440). Unset, out of range or unreadable
reads as 30m, never 0, and magpie never writes it unless the user does.
- settings: CodexResetLead and Settings.ResetLead(); the menu's values
are 15m, 30m (default), 1h, 2h, 3h, 6h, 12h, 24h.
- provider: the spend (expiringResetSpent) and routing
(Allowance.Restarts, through nextResetLook) read the same resetLead(),
so they still agree (#717, #718). The "near" look cadence follows it:
lead + 30m, at least 1h, so a look lands inside a long lead.
- GUI: Settings > Usage, under the Codex auto-use rows, a row "Codex:
how early before one expires" with an app menu (no <select>), and the
sub text says spending earlier loses what the windows have left. The
four "before it expires" strings say the chosen lead. POST
/api/settings/codex-reset-lead; the general save keeps the field.
en, zh, zh-TW, ja, de.
- CLI: magpie quota auto-reset lead [30m|3h|<minutes>|default].
- app.js budget: the auto-use rows moved out to lazy autoresetown.js
(painted in the same draw once loaded), so app.js and the core script
stay under their budgets with no raise. The button sizes to its widest
label (a grid of every label), so picking one never rewraps the row.
Run (all on mote through mote-run):
- go vet: darwin, GOOS=linux -tags nogui, GOOS=windows; nogui build.
- go test -tags nogui -timeout 45m ./... at 3955adccf (this change
before the paint and sizer fixes, which touch only GUI assets): 81 ok.
go test ./internal/gui at this head: ok.
- GUI, Chromium: codex-reset-lead, codex-auto-reset,
codex-auto-reset-settings, segs-press-redraw, i18n-keys: 62/62.
WebKit: every case of those files failed at browserType.launch
(180s timeout) before a page loaded, both runs; mote's browser
launches hang under #4125 (load ~26), so WebKit is not run.
- Rebased onto f7f2d75f2 (old-webkit's lazy list now has traywindows.js
too): go build ./..., go vet -tags nogui ./internal/..., go test
internal/gui (budgets included), cli, settings, gateway: ok. provider:
ok but TestQuotaSpanCarriesEveryWindowField, red on main since
7d4a63148 (#4457, fixed in ccbefe2a2). GUI old-webkit, i18n-keys,
codex-reset-lead in Chromium: pass.
- Rebased again onto 62a1dcdd7 (clean): go test internal/gui (budgets)
and internal/provider: ok; i18n-keys and Chromium codex-reset-lead
12/12 pass; old-webkit 9/10, its Safari 15.0 case a WebKit launch
timeout (#4125).
Broken by hand, each went red:
- resetLead() pinned to 30m: all 3 provider tests.
- resetExpiryNear pinned to 1h: the long-lead look test.
- ResetLead's range check turned into m == 0: TestResetLeadUnreadIsDefault.
- GUI resetLeadMinutes returning 30: codex-reset-lead in every language.
- The button without the sizer: de at 420px, "no click moved the page".
Not tried: a real Codex account spending a card at a non-default lead;
Windows and Linux runs (vet only). The whole GUI suite in Chromium on
mote has ~45 tests in 31 files crash with "browser has been closed" on
untouched origin/main c84c3e1c0 too (reducedMotion files, #4458).
tongzhenbao on X: a Codex Pro account with "when its week runs out" on,
its week at 0% left, one reset held until 11-06 (after the week's own
reset on 11-03) and Use credits on. Overnight ~10k credits went and the
reset stayed; the card said "not auto-used" beside the switch on.
Cause: the week's auto-use ran only on a vendor refusal. autoReset in
routing needs a 429 usage_limit_reached on the last candidate, and the
relay's autoResetSignedIn the same on its 429. An account let spend its
credits is never refused for its week: ChatGPT answers on the credits,
and routing never benches it (full() and onCredits). So the week's reset
could only ever be spent with credits off.
Decision (product call delegated): a reset is free, credits cost money,
so a reset the user set to go when the week runs out goes before any
credits. resetBeforeCredits runs before a try is sent to a Codex account
on its credits whose last reading has its week used up, with the week's
switch on; AutoUseCodexReset reads the week again and keeps one a week
at most, so a second time in the same week goes on the credits. Hooked
in the routing loop and in codexUpstreamOn (the relay, signed-in or an
account). With no reset held, or the week's switch off, nothing changes.
The card's summary: with only the week's switch on it now says "auto-used
when the week runs out" (zh 周额度用完时自动使用), not "not auto-used",
with its title in all five languages. CLI help and auto-reset messages
say "or before its credits are spent". gateway-routing.md names it.
Siblings: the expiring switch already spends regardless of credits
(usedUp ignores them); the credits-off path (planned.held) is unchanged.
Run (mote, through mote-run, at this tree):
- go test ./internal/gateway -run 'TestCodexResetBeforeCredits|TestCodexAutoReset|TestCodexCredits|TestCodexNoCredits': ok
- broken by hand: gateway.go and codex_backend.go at origin/main:
TestCodexResetBeforeCredits/relayed and /routed red (200, spent ""),
the two negative cases green
- node --test codex-auto-reset, i18n-keys, codex-auto-reset-settings,
codex-resets-used, panel-options-fold, quota-curve: 96/96 (chromium +
webkit, en/zh/zh-TW/ja/de); codex-auto-reset red with origin/main's
app.js ("· not auto-used")
- full suite, before the rebase onto 300b7eee0: wsl-run go test -timeout
45m ./... ok for internal/gateway, provider, settings, tui and the rest;
root, cli and gui don't build in WSL (no gtk4/webkitgtk-6.0), and
internal/agent's fake-binary tests (TestInstalledVersion and four more)
fail there with "Invalid argument"; on mote those packages are ok
(., cli 49s, agent 179s)
- at the pushed head 7b6a0675f (on 300b7eee0), on mote: internal/gui,
provider and cli; provider and cli ok, gui ok except TestMainWindowCorners,
red the same on a clean 300b7eee0 copy on mote (macOS 27), #3949;
TestCoreScriptBudget ok with no raise (app.js 1,311,588 of 1,311,735,
after shortening resetsWords' change); the focused gateway tests and the
six GUI files above again, ok and 96/96
Not tried: a real account with credits and a held reset at 0% week; the
owner's accounts have no reset at 0% to spend.
codex-auto-reset was red about once a run in Chromium, one 420px case in
a different language each time: "locator.scrollIntoViewIfNeeded: Element
is not attached to the DOM" in flip(), at the panel's first switch.
Opening the panel's Allowances tab calls quotasOpened(), an asked read
(usage/quotas?asked=1); when it answers, loadQuotas' finally calls
renderQuotas() -> renderPanelQuota(), which builds every card anew. The
cards drawn at boot are already there, so waitFor(psel) passed on them,
and when the asked answer came a few ms later than usual it landed
between flip's locate and its scroll. Instrumented on main (Chromium, en,
420): boot draw at 3ms, the tab's asked read at 76ms, its redraw at
105ms, the first flip after it. codex-credits met the same thing in
#1622 (0b3444999) and waits for !quotasLoading after opening the tab;
this test now does too, and codex-resets-used, which measures the
panel's card on the same draw, gets the same wait. No app change: a
fresh read redrawing the cards can only swallow a press held across
the moment it lands, and a real read's cards differ (their read time),
so skipping an unchanged redraw would not help a user.
Run: the asked answer held back on purpose (a scratch copy serving
usage/quotas?asked=1 60ms late, en 420 Chromium): the old test failed 2
of 3 with the reported "Element is not attached to the DOM" at flip; the
new one passed 3 of 3 (also passed held 30, 120 and 250ms). Unchanged
copies: codex-auto-reset + codex-resets-used pass 15/15 in Chromium 3
runs out of 3, and 15/15 in WebKit, every language. Test-only change, no
Go code touched.
Full suite: SUITE_LINE
alanwalk asked for "自动使用重置卡" to be split: they want a reset that is
about to expire used rather than lost, but a used-up week waited out rather
than spending a reset on it (and the other way round for others).
What changed:
- settings: codexAutoResetOnly narrows an account in codexAutoReset to
"week" or "expiring". An account with no entry keeps both, so every
existing config means what it meant: nothing to migrate, and no user
value is rewritten. Load drops entries for accounts not in the list or
with an unknown value.
- provider: CodexAutoResetWhen(user) reads both times. AutoUseCodexReset
(the week used up, called from the gateway's autoReset and
autoResetSignedIn through AutoResetsWeek) only acts when the week is on;
SpendExpiringCodexResets and routing's resetRunsOut only count on the
expiring reset when that is on. SetCodexAutoResetCase(user, when, on)
sets one time and keeps the other; SetCodexAutoReset still sets both.
Both off removes the account.
- gateway: POST /api/settings/codex-auto-reset takes an optional "when";
POST /api/settings keeps codexAutoResetOnly, which the page doesn't send.
- GUI: the account's card (Usage page and the menu bar panel) says
"Auto-use resets:" with each time on its own line and its own switch;
the brief account's one switch still sets both, its title naming each
time; Settings › Usage gives each account an Off/On per time. The status
line says which times are on now. "· auto-used before it expires" on
the resets held follows the expiring switch alone. Strings in zh, zh-TW,
ja and de.
- CLI/TUI: `magpie quota auto-reset <account> week|expiring on|off`; the
quota and accounts tables and the TUI say "auto", "auto when the week
runs out" or "auto before one expires".
What was run (worktree on origin/main 2fbbd1694):
- gofmt -l on the changed Go files: clean. go vet ./... (darwin),
GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -tags nogui ./internal/provider ./internal/gateway ./internal/cli
./internal/tui ./internal/gui ./internal/settings: ok. The gateway
package hit go test's 10m default once while ~15 sibling sessions were
building on this machine (no test failed; TestRemoteMagpieModels was
merely running); with -timeout 30m it passed in 967s.
- New Go tests: TestCodexAutoResetCases (provider), a week-only step in
TestSpendExpiringCodexResets, an "only before one expires" case in
TestCodexAutoResetNot (gateway), CodexAutoResetOnly in
TestSettingsSaveKeepsWhatItDoesNotSend. Broken by hand: making
CodexAutoResetWhen ignore the narrowing turned all three reset tests
red (the gateway case answered 200, a week-only account read 2 and
spent 1); dropping the keep line in api.go turned the settings test red.
- GUI (Playwright, chromium and webkit): codex-auto-reset.test.cjs, now in
en, zh, zh-TW, ja and de at 1100 and 420 wide, flips each time's switch
on the card and the panel and checks posts carry "when", the other time
is kept, the status, the resets-held line, the brief switch, fit at 420,
no left border, no select; codex-auto-reset-settings.test.cjs does the
same for Settings › Usage. Both, with codex-resets-used, routing-auto-reset,
quota-curve (its class list now holds ar-split) and i18n-keys: 56 + 18
pass. Broken by hand: posting without "when" turned 20 of 21 red.
quota-curve failed 2 of 18 once while a go test build ran beside it; it
passed 15/15 serially and 18/18 again at concurrency 4 just after.
Not tried: a real ChatGPT account using or keeping a reset; the times are
driven with the faked usage reads the existing tests use.