Files
magpie/internal/provider/codex_tier.go
T
yetone add0dadd4f codex: a service tier set in Codex's settings goes on every request of Codex's (JackyFill on X)
JackyFill asked for a choice in Codex's agent settings that rewrites
service_tier: follow the request, force Fast, force Ultra Fast. Codex's
settings on the Agents page now have "Codex service tier", picked from
the app menu: As Codex asks (the default, nothing changes), Standard,
Fast or Ultrafast.

The values are Codex's own request values (codex-rs protocol
config_types.rs ServiceTier, tui service_tier_resolution.rs): Fast is
"priority", Ultra Fast is "ultrafast", and Standard sends no
service_tier. Flex isn't offered: the ChatGPT backend's requests drop
it (codex_request.go).

settings.CodexServiceTier ("", "default", "priority", "ultrafast";
anything else refused) is set through POST
/api/settings/codex-service-tier. codexTiered rewrites the body where
Codex's requests come in, on both ways: codexBackend (Codex signed in,
/backend-api/codex) and the main handler's Codex-on-Responses block,
which a websocket turn goes through too. It applies only when the
request is Codex's (fromCodex or agentOf == codex). Everything after
treats it as Codex's own ask: an account whose list lacks Ultrafast is
put after a mate that has it or sent priority. A bare model (Codex's own
sign-in, whose plan magpie doesn't know) gets ultrafast only where one
of magpie's Codex accounts lists it on the model (UltraModels), else
priority. The body is edited with topMember/withoutTopMember, no full
decode. Fast picks still apply after, unchanged.

Run (mote):
- TestCodexServiceTierSet, TestWithServiceTier: ok. The test signs in a
  Plus and a Pro ChatGPT account against a fake backend whose lists offer
  gpt-6-luna's Ultrafast to Pro only, and checks the tier sent for each
  setting x what Codex asked, through /v1/responses (account:tier tried)
  and on /backend-api/codex for a model with Ultrafast and one without;
  OpenCode's own priority is left alone; "flex" is refused.
- go test -count=1 -timeout 45m ./internal/settings ./internal/provider
  ./internal/gui ./internal/gateway: ok but internal/gui, which was red
  twice: TestCoreScriptBudget (1,535,075 > 1,533,802) and
  TestSettingsSaveKeepsWhatItDoesNotSend (a save of the Settings page
  dropped the tier). Paid for by eight Codex-row comments cut in app.js
  (now 1,533,416), no raise; settingsapi.Apply keeps CodexServiceTier
  as it keeps the other Codex rows. At the pushed head: go test
  ./internal/settingsapi ./internal/settings ./internal/gui ok, the two
  gateway tier tests ok.
- go vet darwin; GOOS=linux -tags nogui; GOOS=windows (gateway,
  provider, settings, gui): clean. gofmt -l: clean.
- GUI, chromium + webkit: codex-service-tier (new, en/zh/zh-TW/ja/de at
  900 and 400px: 20/20), agent-prefs (56/56, Codex's row list updated),
  i18n-keys, i18n-en-no-cjk, settings-search, codex-titles,
  codex-subagent-model, settings-general, codex-sheet-providers,
  click-scroll: all pass; at the pushed head codex-service-tier,
  agent-prefs, i18n-keys, settings-search, codex-titles,
  codex-subagent-model, settings-general, click-scroll: 166/166.

Broken by hand:
- codexTiered returning the body as it came: TestCodexServiceTierSet red
  (17 lines).
- the Ultrafast-to-Fast downgrade for a bare model removed: red on
  gpt-6-sol (sent ultrafast, want priority).
- the GUI posting to the wrong path, and the row left out of Codex's
  AGENT_PREFS: codex-service-tier red in chromium and webkit.
- settingsapi without the CodexServiceTier keep:
  TestSettingsSaveKeepsWhatItDoesNotSend red.

Not tried: a real ChatGPT account's Ultrafast or Fast request with the
setting on (only the fake backend), a real Codex websocket session, and
Windows/Linux runs of the GUI.
2026-11-10 15:24:40 +08:00

36 lines
1007 B
Go

package provider
import (
"fmt"
"slices"
"strings"
"github.com/yetone/magpie/internal/settings"
)
// CodexServiceTier is the service tier set for every request Codex sends
// (settings.CodexServiceTier): "" as Codex asks it, settings.CodexTierStandard
// for none, "priority" or "ultrafast". A value this magpie doesn't know
// (a newer one's, a file edited by hand) is read as "" and changes nothing.
func CodexServiceTier() string {
v := strings.TrimSpace(heldSettings().CodexServiceTier)
if !slices.Contains(settings.CodexServiceTiers, v) {
return ""
}
return v
}
// SetCodexServiceTier sets settings.CodexServiceTier.
func SetCodexServiceTier(tier string) error {
tier = strings.TrimSpace(tier)
if !slices.Contains(settings.CodexServiceTiers, tier) {
return fmt.Errorf("Codex's service tier must be one of %q, not %q", settings.CodexServiceTiers[1:], tier)
}
s := settings.Load()
if s.CodexServiceTier == tier {
return nil
}
s.CodexServiceTier = tier
return settings.Save(s)
}