Files
magpie/docs
yetone 3f91b98eac gateway: a group's last member out of quota sends the request back to a relay that blipped, and rests
dbydd on Discord: an in-order group of sub2api relays with a Codex (or
OpenCode Zen) subscription last. Once that last member's quota answers
429, requests still landed on it, the 429 reached the agent and broke
its loop, and a new conversation stayed stuck there.

Two causes, both in serve:

- A relay that failed for a moment (503/502/429/500) went on to the last
  member; its quota 429 is not busy(), so the patience/replan block
  (#1418) never ran and the agent got the 429 while the relay could
  answer. Now a group's last member refused out of quota or credit
  (lastSpent: failQuota/failCredit, not passing, an earlier member busy
  this request) replans like a busy one: the earlier member is asked
  again, and the spent one rests with restAfterMarked.
- The last one asked was never rested for quota when it was an account
  (#1772 rested keys only), so each later request asked it again. The
  #1772 block now rests the last account out of quota or credit too;
  quotaHeld still holds keys alone, and a Codex autoReset unrests the
  account whose reset it spends.

Tests (internal/gateway/group_spent_last_test.go):
- TestGroupRelayBlipDoesNotEndOnSpentLast: usage_limit_reached /
  rate_limit_exceeded / bare 429 on Codex, crossed with relay blips
  503/502/429/500; every turn must be 200 from the relay, Codex asked at
  most once when spent. Red on the old code (turn 0 got the 429).
- TestGroupSpentLastAccountRests: Patience off; Codex asked at most once.
  Red on the old code ("Codex asked 2 times").
- TestGroupLastMemberSpentGoesBackToEarlier: the reporter's stick case
  (on Codex, relay back, Codex spent); passed on the old code as well.

Broken by hand: lastSpent forced false -> the blip test red; the #1772
block back to keys only -> TestGroupSpentLastAccountRests red.

Not tried: a real OpenCode Zen or ChatGPT quota 429 body (the tests use
Codex's usage_limit_reached shape, rate_limit_exceeded and a bare 429),
and real sub2api relays.
2026-10-30 11:55:36 +08:00
..