feat(quota): add opt-in Codex auto-ping

Generalize Claude 5h auto-ping into a provider-generic scheduler and add
opt-in Codex auto-ping that warms the next 5h window via a tiny gpt-5.5
request when session.resetAt slides. Default off, per-connection toggle,
failure cooldown, blocking-quota skip, drains stream before success.

Closes #2107

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Emirhan
2026-06-29 15:13:17 +07:00
committed by decolua
co-authored by Cursor
parent fc8722e897
commit b66b5c68ce
9 changed files with 757 additions and 168 deletions
+25 -7
View File
@@ -62,16 +62,34 @@ export const CONSOLE_LOG_CONFIG = {
// Client-side store TTL: how long fetched data stays fresh before re-fetching
export const CLIENT_STORE_TTL_MS = 60000;
// Claude auto-ping: keep 5h window warm by sending a tiny request right after reset
export const CLAUDE_AUTOPING_CONFIG = {
settingsKey: "claudeAutoPing", // settings table field
// Quota auto-ping: keep 5h windows warm by sending a tiny request right after reset.
export const QUOTA_AUTOPING_CONFIG = {
tickIntervalMs: 60000, // scheduler tick
pingLeadMs: 5000, // fire once reset passes (within tolerance)
pingModel: "claude-haiku-4-5-20251001", // cheapest model
pingText: "hi",
pingMaxTokens: 1,
refreshAheadMs: 300000, // refetch usage when within 5min of reset
fiveHourKey: "session (5h)", // quota key returned by usage handler
failureCooldownMs: 900000, // avoid failed ping spam while upstream/auth is unhealthy
providers: {
claude: {
settingsKey: "claudeAutoPing", // preserve existing settings contract
quotaKey: "session (5h)", // quota key returned by usage handler
pingModel: "claude-haiku-4-5-20251001",
pingText: "hi",
pingMaxTokens: 1,
},
codex: {
settingsKey: "codexAutoPing",
quotaKey: "session",
pingWhenResetAtSlides: true,
resetAtDriftMs: 30000,
minPingIntervalMs: 600000,
skipWhenBlockingQuotaExhausted: true,
// Free and Plus Codex accounts both expose gpt-5.5; avoid fallback probes that waste requests.
pingModel: "gpt-5.5",
pingText: "hi",
pingInstructions: "Reply with OK.",
pingReasoningEffort: "none",
},
},
};
// Re-export from providers.js for backward compatibility