gokoshiki wants a Codex subscription first, then an OpenAI API key, then
the subscription's credits. Until now an account at 100% that holds
credits either kept its place and spent them there (on) or was held
(off). This adds a third way per account, "last":
- settings: CodexCreditsLast []string, empty by default, so a setting
saved before it keeps its order. provider.CodexCreditsLast,
CodexCreditsMode and SetCodexCreditsMode(user, on|last|off);
SetCodexCredits(on) still means "in its place" and clears last.
- gateway: candidate.creditsLast is true for such an account once a
window for the model is used up and it is going on its credits (a
call ChatGPT counts in no window stays in its place). restLast orders
ready, then resting, then those, and marks Weighed.CreditsLast.
restLast runs over the asides too, so such an account goes behind a
provider's reserves (Accounts at once, 2c6b7c063) as well.
lastBehind keeps In turn's next turn (after), a new conversation's
spread (leastHeld) and a subagent's lead (readyForNew) from bringing
it forward, and a kept conversation moves off it to one not on its
credits (Affinity.Why "credits").
- CLI: magpie quota credits <account> [on|last|off]; alone it lists
accounts set off and last.
- API: POST /api/settings/codex-credits takes {user, on, last?}.
- GUI: under a Codex account's Use credits, while on, a second switch
"Only after every other account, key and fallback", in the Usage
page's card and the tray panel's (both wrap it to its own line at 360
to 900px), and the panel's folded brief says "On, after everything
else". The Routing page's trace says why such an account is behind
(aside, the kept conversation's why, the row tag). zh, zh-TW, ja, de.
creditsButton and the new switch share creditsSwitch, and the Codex
options' comments in app.js were cut, so the core budget holds with
no raise (1,532,664 of 1,533,105).
- docs: reference.md (quota credits) and gateway-routing.md.
Tests:
- gateway: TestCodexCreditsLastAfterTheOthers (two accounts, In order:
the one at 100% on its credits goes behind, the trace says so, and
back in place when turned on), TestCodexCreditsLastAfterTheFallback
(both accounts at 100% and set last: the API key the provider falls
back to answers before either one's credits; with the credits in
their place an account answers on them, as before),
TestCodexCreditsLastNotKept (a kept conversation moves off it).
All three red with creditsLast and lastBehind forced false.
- provider: TestCodexCreditsLastMode.
- gui: settings_keep_test carries CodexCreditsLast;
tests/codex-credits-last.test.cjs (Chromium and WebKit, en zh zh-TW
ja de; Usage at 900 and 440, the panel at 440 and 360, the folded
brief, the Routing page's aside and why, every key in I18N). Red on
the old assets (no .ar-credits-last).
Run at this change on origin/main c76bcaea7, on mote (pushed on fd70def82, whose
one commit since, fd70def82, changes only the Providers poll's Go
files in internal/gui):
gofmt clean; go vet of gateway, provider, gui, cli and settings ok;
their tests ok but internal/gui's #4514 and #3949, both on main. The
8 commits between d6aa9cdf6 and c76bcaea7 touch none of this
change's files.
Run at this change on origin/main d6aa9cdf6, Go 1.26.8:
- mote: gofmt -l clean; go vet ./..., and GOOS=linux and GOOS=windows
go vet -tags nogui ./...: ok. go test -count=1 -timeout 45m ./...:
85 packages ok; internal/gui red only on TestSettingsSaveKeepsWhatIt
DoesNotSend's SearchAll (#4514), TestMainWindowCorners (#3949) and
TestColdTurnsTaken (#4510), all three on main. TestCoreScriptBudget
passes.
- WSL magpie-desktop, Playwright 1.62.0, both engines: codex-credits*,
i18n-keys, gui-ja, gui-zh-tw, panel-options-fold, provider-at-once and
every routing-* file: 2127 tests, 2064 pass. Every codex-credits and
codex-credits-last test passed (26). The red files (gui-ja, 19 routing
files) run again at this tree and at d6aa9cdf6, alike: 200 tests, 61
and 57 red. gui-ja is #4580; the routing reds are timeouts and
waits, on both. The one file red at this tree only,
routing-request-model (WebKit 420px "the model is cut"), is 5 of 5
green alone at both, and with six copies at once red at both (29 and
27 of 30 here, 28 and 27 of 30 at d6aa9cdf6): a fixed 150ms wait
after a resize, filed as #4650. Nothing this change adds to Routing
draws unless an account is set last (fixtures don't).
- Earlier, at 3564eb04b (this change on 7428f3229), WSL: the whole GUI
suite beside two other sessions' suites, 16944 tests, 16496 pass;
its 102 red files again at that head and at 7428f3229, 444 and 425
red. The files red at the head only, run alone: view-open-wheel,
usage-accounts, add-button, usage-ledger-open-settled 0 red;
view-wheel-after-click, view-wheel-unheard and context-map (#3488)
red alone at 7428f3229 too. mote, the credits and i18n files: 172 of
174, the two #4580 and a click timeout in quota-curve at load 148
(alone 30 of 30).
Not tried: a real ChatGPT account at 100% with credits beside a real
OpenAI key; the order is shown with the gateway's fake Codex backend.