agy-cli Switch by itself: switch when agy's own run hits its quota, not only on the 5-minute reading (plugins#1762)
From plugins#1762 (ArmedHelicopter): with Switch by itself on for agy-cli, switch agy's account when agy hits a quota error, not only on the 5-minute usage reading.
What's there now:
- Switch by itself (
auto-switch agy-cli on, which needsswitch-only agy-cli on) reads the usage of the account agy is on, and only that one, every 5 minutes (nextAgyLogin,agySwitchReadingin internal/provider/agy_auto.go). When a pool reaches the subscription's spent share, it switches agy to the next account with room in that pool. The list shows "usage not read" because magpie doesn't read the other accounts on a timer. The other accounts are read only once the one agy is on is spent. - Through the gateway, agy-cli's quota ending ("Individual quota reached" / "Third-party quota reached", relayed by the plugin as a 429 rate_limit_error) already rests that model's pool on that account until its reset and falls over (
antigravityPoolSpent, internal/gateway/agy_quota_test.go). - With switch-only on, the gateway sends agy-cli no requests (
KeptToAgent), so the plugin's 429 never reaches magpie. agy's and the Antigravity app's own runs go straight to Google.
So a quota-error trigger would have to read agy's own records of a run. The likely place is the transcript at ~/.gemini/antigravity-cli/brain/
Needed before building:
- either the reporter's transcript lines around a real "Individual quota reached";
- or agy run in a sandbox HOME against a fake Code Assist endpoint that answers the quota 429, as calls_agy_times_test.go's fixture was made.
Then: a sighting of the notice for the account agy is on (AgyOn), newer than the last switch (AgySwitchedAt), triggers SwitchAgyWhenSpent at once. It treats the noticed pool (Individual = Gemini, Third-party = Claude & GPT) as past, and still needs room in that pool on the next account. A request-content refusal (the bare 429 "Resource has been exhausted" to a turned-away system prompt) must not count.
Real lines from this machine (Windows 11, agy 1.5.18 plus the Antigravity app), from the accounts in plugins#1762 that hit "Individual quota reached". Conversation text, ids and names are removed.
Where they are
- Antigravity app:
~/.gemini/antigravity/brain/<conversation>/.system_generated/logs/transcript_full.jsonl. 759 quota-notice lines across 42 conversations, first on 2026-11-26. - agy CLI:
~/.gemini/antigravity-cli/brain/*/…/transcript_full.jsonl(19 transcripts here). None has a quota notice, so I have no CLI sample. The app is where these show up.
The line
One JSON object per step, the same keys as the other steps around it:
{"step_index": 74, "source": "SYSTEM", "type": "SYSTEM_MESSAGE", "status": "DONE", "created_at": "2026-11-26T03:04:08Z",
"content": "The following is a <SYSTEM_MESSAGE> not actually sent by the user. It is provided by the system as important information to pay attention to.\n\n<SYSTEM_MESSAGE>\n[Message] timestamp=2026-11-26T03:04:08Z sender=system priority=MESSAGE_PRIORITY_HIGH content=The subagent <name> (<id>) with id \"<uuid>\" encountered an error and has either stopped or failed to start execution: RESOURCE_EXHAUSTED (code 429): Individual quota reached. Please upgrade your subscription to increase your limits. Resets in 3h36m9s.\n</SYSTEM_MESSAGE>"}
- The step before it is a
PLANNER_RESPONSE(source: MODEL, withmodel,input_tokens, …). The step after it is anotherSYSTEM_MESSAGE. statusisDONE, not an error status. The quota end is only in thecontenttext:RESOURCE_EXHAUSTED (code 429): <Individual|Third-party> quota reached. … Resets in <Go duration>.- All 759 are this "subagent … encountered an error" relay to the parent conversation. I found no line for a top-level run ending on the notice. The app may show that only in its UI.
- Only
Individual quota reachedappears here. NoThird-partysample, although the same account gotclaude-opus-5-5 429 … Third-party quota reachedthrough the gateway. - The line names no account.
created_at>AgySwitchedAtplusAgyOnat sighting time, as you planned, is the only way to tie it to an account.
A match that keeps out the bare "Resource has been exhausted" refusal could be:
RESOURCE_EXHAUSTED \(code 429\): (Individual|Third-party) quota reached\..*?Resets in ([0-9hms.]+)\.
There's also an earlier warning (8 lines) in the same SYSTEM_MESSAGE form: [quota] model gemini-4-neon-high is low on quota (NN% remaining, resets at <RFC3339>) — check swarm{action:"models"} …. Its swarm{…} hint suggests it comes from a multi-agent extension, not agy itself (unverified), so I wouldn't rely on it.
Two things that slow down an automatic switch once one is due
- Quitting the Antigravity app truncates its conversation WALs: here, five
*.db-walfiles written in the same second, all 0 bytes.agyTurnUnderWaycounts any.db-waltouched withinagyBusyWindow, so a switch right after quitting is refused with "in the middle of a turn" for a minute. - That refusal is a plain error.
switchAgyWhenFreekeeps a switch pending only for*AgyRunning, so after a turn refusal the pending switch is cleared and the next try waits for the 5-minute full look, notagyWaitEvery.
A fix for both is being written on my fork (empty WALs don't count; a turn refusal waits like a running agy). I'll link it here when it's tested.
Also, on Windows, agy-cli's MIN_AGY_VERSION = "1.5.19" (plugins 4e3211e) stops every usage read here, and with it auto-switch, with "agy 1.5.18 is older than 1.5.19 … Update agy", while agy's own updater reports {"success":true,"message":"Already on the latest version."} on 1.5.18.
Asked the reporter for a real transcript of a quota ending: https://github.com/magpie-community/plugins/issues/1762#issuecomment-7298636811