feat(quota): background poll keeps idle account quota fresh#56
Conversation
1399ceb to
e67f58c
Compare
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
e67f58c to
823e46a
Compare
|
Thanks. Background quota refresh is useful, but this needs revision before merge:
Please rerun the complete gate after these changes. |
823e46a to
3751617
Compare
|
Thanks for the revision. Rebase and main-refresh lease use are now correct. Remaining blockers:
Please rerun the full gate after these changes. |
3751617 to
578efd0
Compare
|
Thanks for the revision. The per-loader lifecycle and in-flight stop work are now covered. Three blockers remain:
Please rerun the full gate after these fixes. |
578efd0 to
885fd94
Compare
885fd94 to
09f4d2f
Compare
|
Fixed in
Full gate green (748/0). The fallback-identity mechanism here is byte-identical to #57's ( |
Why
Quota is push-primary (
x-codex-*headers / WScodex.rate_limitsframes), so a fallback account that is not currently being routed to shows stale or missing quota until the operator manually runs/openai-quota. The sibling anthropic-auth plugin keeps idle accounts fresh with a background poll; this brings the same behavior here — without request spam from multiple concurrent opencode processes, and without letting any process publish stale data over fresh.What
Background poll
core/background-quota-refresh.ts— singleton 5-minute timer (±30 s jitter per process), unref'd so it never keeps the process alive, idempotentstart, stopped from both the plugin-level and auth-loader dispose paths.refreshAllQuotawithrespectBackoff: trueplus a 4-minute freshness gate (skipFresherThanMs). Rides the 15 s abort timeout + quota-channel logging from fix(quota): bound and log the active quota fetch path #52. Deliberate deviation from the sibling: no immediate first run — the boot seed covers startup; first poll fires at the jittered 5-minute mark.Cross-process dedup (no locks)
checkedAt). Whichever process polls first refreshes the file; every other process's tick inside the window sees the freshcheckedAtand skips. Worst case under jitter collision is 2 concurrent fetches, never N.Stale-write clobber fix (machine-state sidebar writes)
setSidebarMachineStatenow freshness-merges per-account inside the existing compare-retry callback: for main and each fallback (matched by id), the side with the fresher finitecheckedAtwins; invalid/missing loses to valid; both missing → incoming wins.activeId/routekeep last-writer semantics;activeRoutingmerge unchanged.quota.checkedAtadded: a complete authoritative frame may retire every window (noprimary.checkedAtleft), and without a timestamp on the snapshot itself the freshness merge would resurrect the retired window from disk.Unchanged: the manual
/openai-quotacommand path (no gate, always writes) and the boot seed. No new config keys, commands, or TUI changes.Verification
random()=0/1→ ∓30 s.