ac4af582301a4e8a29245dbba767eba31334ddf9
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
00afcf97a1 |
provider, gui, cli: a Codex account's auto-use of its resets is two switches, its week used up and one about to expire (#2078, alanwalk)
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
|
||
|
|
e297a8ab27 |
provider: a codex-autoreset.json that can't be read no longer lets a Codex account's auto-use spend a second reset the same week (#2017, ggbdpq)
What changed: - autoResets.load read a codex-autoreset.json that didn't parse (a crash leaving it zeroed, as #1505's files were) as "none spent this week", so the next week-used-up look spent another reset, and the write after it took the unreadable bytes with it. Now a file that can't be read or parsed is unknown: the bytes are copied aside as .bad-<ts> (as noteResetUsed keeps codex-resets-used.json's), and what was spent is rebuilt from codex-resets-used.json, which records every reset used for a week used up. When that file can't be read either, no account spends one by itself for a week (the longest a lost spend could still count), kept past restarts under a "*" entry. - autoResets.save writes through steady.WriteFile, as every write of magpie's own state does since #1505, and logs a failed write. ggbdpq's patch kept the file aside and made the write durable, but still read the unreadable file as none spent, so its own scenario (a crash, then a restart) still spent a second reset. This takes their patch and fixes the read at the cause. Run: - TestAutoResetUnreadableKeptAside (ggbdpq's) fails on main: "the unreadable file was written over with nothing kept aside". - TestAutoResetUnreadableReadsResetsUsed and TestAutoResetNothingKnownSpendsNone fail on main and on ggbdpq's patch alone: "spent 1 resets, want 0" / "spent 1 resets with nothing known of the week". Cases: an auto-use an hour ago holds off; one 8 days ago, one by hand, or another account's doesn't. - go test -tags nogui ./internal/provider under a temp HOME passes; -race -count=10 -run TestAutoReset passes; gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/provider pass. - Not tried: a real corrupted file from a user (none reported); a real Codex account (checked against the fake ChatGPT server only). Co-authored-by: ggbdpq <ggbdpq@gmail.com> |
||
|
|
d1ec1cdf62 | usage: a Codex account can spend one of its rate-limit resets by itself once its week is used up (StringKe on Discord: 账号里有 Bank Reset 的重置次数,可以自动使用 — 七天全部用完的时候重置) — off by default, turned on per account with Auto-use beside Use a reset (Usage page, panel) or magpie quota auto-reset <account> on. It fires only when every other account a request could go to is resting, fresh usage shows the weekly window used up (the 5 hours' being full never counts: a reset starts both, and five hours pass on their own), the account holds one, and none was spent by itself this week (kept in codex-autoreset.json across restarts); it spends the one expiring first, lifts the rest and asks once more, and on nothing_to_reset/no_credit/error ChatGPT's own 429 goes to the agent. Both the pooled accounts and Codex's own sign-in are covered; each use shows on the Routing page and in the request log. TestCodexAutoResetOneAccount, TestCodexAutoResetAfterEveryAccount, TestCodexAutoResetNot, TestWeekUsedUp, TestAutoResetKeptPastRestart, codex-auto-reset.test.cjs and routing-auto-reset.test.cjs are new; the gateway and GUI ones fail without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass; click-scroll, old-webkit, tray-usages pass. |