provider: a Codex account with no credits and every window at 100% counts held though allowed isn't false (xiaoq6285)

xiaoq6285 (Discord, magpie 0.1.2891, Codex App 26.1029, Windows): a used-up
Plus account, no credits, 用量 showing it used up, config.toml with
model_provider = "magpie" and requires_openai_auth = true, Send grey until
Codex was switched off in magpie. Banked resets and paid credits were ruled
out (codexHeld reads neither resets nor, here, any credits). What is left is
a reading that doesn't say allowed false: codexHeld needed exactly that, so
CodexUsedUp stayed false and Sync kept requires_openai_auth, which makes the
app read the account's rate limit and grey Send.

codexAtLimit now holds: allowed false (as before); allowed not said with
limit_reached or a window at 100%; allowed true with every reported window
at 100%. Credits and the workspace-overage exemptions are unchanged and
still run after it.

Why the two cases that were false stay narrow: a7c4e5ddd (#996) pinned
"limit_reached but allowed, no credits" to not held, because the composer
gate (hP / hardBlocked in 26.930) reads allowed alone and the app still
sent; holding such an account only takes the app out of ChatGPT (durable
threads, remote control, cloud tasks, its usage meter) for nothing. That
cost is real, so allowed true still stands unless no window has room: a 5h
window at 100% with the week open is not held (new case). The case
"limit_reached, allowed not said" does flip to held.

Not known: the reporter's actual reading (allowed true or missing, never
seen) or the 26.1029 gate (its bundle isn't on any test box; 26.1021 is).
If their reading says allowed false with no credits this changes nothing
for them.

Run on mote: go test -timeout 45m ./internal/provider ./internal/agent ok
(194s, 346s); GOOS=linux, GOOS=windows and native go vet on both ok; gofmt -l
clean. Broken by hand: with the old subscription_usage.go and the new tests,
TestCodexUsedUpIsWhatTheAppHolds fails on "limit_reached, allowed not said,
no credits" and "every window at 100% but allowed, no credits".
Not tried: the real 26.1029 app, a real used-up reading, Windows run.
This commit is contained in:
yetone
2026-11-04 12:41:11 +08:00
parent d1fa254b1d
commit 40cfd32b0b
3 changed files with 62 additions and 6 deletions
File diff suppressed because one or more lines are too long
+23 -1
View File
@@ -75,15 +75,37 @@ func TestCodexUsedUpIsWhatTheAppHolds(t *testing.T) {
{"Pro with credits, at a spend cap", with(read("codex_usage_pro_credits.json"), func(m map[string]any) {
m["spend_control"].(map[string]any)["reached"] = true
}), false},
// only allowed false holds it: limit_reached alone doesn't
// allowed false holds it. With allowed not said, so does a limit
// reached or a window at 100%; with allowed true, only every
// window at 100% (the 26.1029 app blocked such an account, with
// 用量 showing it used up). A 5h window at 100% with the week open
// is not held: the app still sends, and holding takes it out of
// ChatGPT (#996).
{"limit reached but allowed, no credits", with(read("codex_usage_pro_credits.json"), func(m map[string]any) {
delete(m, "credits")
rateLimit(m)["limit_reached"], rateLimit(m)["allowed"] = true, true
rateLimit(m)["primary_window"].(map[string]any)["used_percent"] = 40
}), false},
{"limit reached, allowed not said, no credits", with(read("codex_usage_pro_credits.json"), func(m map[string]any) {
delete(m, "credits")
rateLimit(m)["limit_reached"] = true
delete(rateLimit(m), "allowed")
}), true},
{"every window at 100% but allowed, no credits", with(read("codex_usage_pro_credits.json"), func(m map[string]any) {
delete(m, "credits")
rateLimit(m)["limit_reached"], rateLimit(m)["allowed"] = false, true
rateLimit(m)["primary_window"].(map[string]any)["used_percent"] = 100
}), true},
{"5h window at 100%, week open, allowed, no credits", with(read("codex_usage_pro_credits.json"), func(m map[string]any) {
delete(m, "credits")
rateLimit(m)["limit_reached"], rateLimit(m)["allowed"] = false, true
rateLimit(m)["primary_window"].(map[string]any)["used_percent"] = 100
rateLimit(m)["secondary_window"] = map[string]any{"used_percent": 30, "limit_window_seconds": 18000, "reset_after_seconds": 100, "reset_at": 1791640059}
}), false},
{"window at 99%, allowed, no credits", with(read("codex_usage_pro_credits.json"), func(m map[string]any) {
delete(m, "credits")
rateLimit(m)["limit_reached"], rateLimit(m)["allowed"] = false, true
rateLimit(m)["primary_window"].(map[string]any)["used_percent"] = 99
}), false},
{"not allowed, limit not reached, no credits", with(read("codex_usage_pro_credits.json"), func(m map[string]any) {
delete(m, "credits")
+38 -4
View File
@@ -1105,9 +1105,11 @@ type codexUsage struct {
RateLimit struct {
// false once its allowance is used up; held only with no credits
// to go on with (codexHeld)
Allowed *bool `json:"allowed"`
Primary *codexWindow `json:"primary_window"`
Secondary *codexWindow `json:"secondary_window"`
Allowed *bool `json:"allowed"`
// the backend's own word that a limit is hit
LimitReached *bool `json:"limit_reached"`
Primary *codexWindow `json:"primary_window"`
Secondary *codexWindow `json:"secondary_window"`
} `json:"rate_limit"`
SpendControl *struct {
Reached bool `json:"reached"`
@@ -1163,7 +1165,7 @@ var codexReservePlans = []string{"team", "self_serve_business_prolite"}
// says held: wrongly held costs the app its ChatGPT extras while magpie
// serves the turn, wrongly not held leaves it sending nothing at all.
func codexHeld(u codexUsage) bool {
if u.RateLimit.Allowed == nil || *u.RateLimit.Allowed {
if !codexAtLimit(u) {
return false
}
c := u.Credits
@@ -1180,6 +1182,38 @@ func codexHeld(u codexUsage) bool {
return true
}
// codexAtLimit is whether the reading says the allowance is used up:
// rate_limit.allowed false, which is what ChatGPT.app 26.1021 gates on, or
// else one the backend does not call open (allowed not said) with
// limit_reached or a window at 100%, or one it calls allowed with every
// window it reports at 100%. The 26.1029 app blocked an account magpie's
// 用量 showed used up, with no credits (xiaoq6285 on Discord), and a
// reading that did not say allowed false is the only way codexHeld could
// have missed it. Held wrongly takes the app out of ChatGPT (durable
// threads, remote control) while it would still send (#996 undid that for
// limit_reached alone), so allowed true stands unless nothing is left in
// any window: a 5h window at 100% with the week open is not held.
func codexAtLimit(u codexUsage) bool {
r := u.RateLimit
if r.Allowed != nil && !*r.Allowed {
return true
}
spent, any := true, false
for _, w := range []*codexWindow{r.Primary, r.Secondary} {
if w == nil {
continue
}
any = true
if w.UsedPercent < 100 {
spent = false
}
}
if r.Allowed != nil { // allowed true: held only with every window gone
return any && spent
}
return r.LimitReached != nil && *r.LimitReached || any && spent
}
type codexWindow struct {
UsedPercent float64 `json:"used_percent"`
LimitWindowSecs int64 `json:"limit_window_seconds"`