From 7217a24c28d8ae43caf0d0fddf2cace1f810c947 Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Sat, 16 May 2026 19:26:16 +0200 Subject: [PATCH] fix(quota/openrouter): suppress usedFraction since SF policy is :free-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenRouter's credit-balance (total_usage / total_credits) was being used as a quota signal in phase 2's quotaHeadroomMultiplier, demoting openrouter once credits got high (e.g., 80% used → 0.5 multiplier). But SF's built-in policy (preferences-models.js:123-131 isModelAllowedByBuiltInProviderPolicy) hard-restricts every OpenRouter route to `:free` + zero-cost models for ALL SF users — there's no opt-in, no way to bypass it. Therefore SF dispatches NEVER consume OpenRouter credits, and the credit balance is purely historical noise. Fix: stop emitting `usedFraction` for OpenRouter's credit window. The window is still reported (so `sf headless usage` shows credits state for awareness) but quotaHeadroomMultiplier now treats OpenRouter as "no quota signal" → neutral 1.0 — no spurious demotion. Affects only the routing layer (selector). Display layer unchanged beyond the label tweak ("info only — SF routes :free"). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../extensions/sf/provider-quota-cache.js | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/resources/extensions/sf/provider-quota-cache.js b/src/resources/extensions/sf/provider-quota-cache.js index 39a0d6af9..d8ac756da 100644 --- a/src/resources/extensions/sf/provider-quota-cache.js +++ b/src/resources/extensions/sf/provider-quota-cache.js @@ -142,7 +142,18 @@ async function fetchKimiCodingQuota(apiKey) { /** * OpenRouter — GET https://openrouter.ai/api/v1/credits with Bearer auth. * Returns { data: { total_credits, total_usage } } where both are USD floats. - * Used relative to the user's purchased credits, not a rolling window. + * + * Important: SF's built-in policy (preferences-models.js:123-131 + * isModelAllowedByBuiltInProviderPolicy) restricts OpenRouter routes to + * `:free` + zero-cost models for ALL SF users, no opt-in needed. Routing + * through SF therefore never consumes credits — the credits balance is + * historical noise, not a signal for the quota-aware router. + * + * The window IS reported (so `sf headless usage` can display credits state + * for user awareness) but `usedFraction` is deliberately left undefined so + * benchmark-selector's quotaHeadroomMultiplier treats OpenRouter as "no + * quota signal" (neutral 1.0) rather than incorrectly demoting at the + * credits high-water mark. */ async function fetchOpenrouterQuota(apiKey) { const res = await fetch("https://openrouter.ai/api/v1/credits", { @@ -157,14 +168,12 @@ async function fetchOpenrouterQuota(apiKey) { return { windows: [ { - label: "credits (USD)", + label: "credits (USD, info only — SF routes :free)", used: totalUsage, limit: totalCredits || totalUsage, // avoid divide-by-zero - usedFraction: - totalCredits > 0 - ? clampFraction(totalUsage, totalCredits) - : undefined, - resetHint: remaining >= 0 ? `${remaining.toFixed(2)} USD remaining` : undefined, + // usedFraction intentionally omitted; see comment above. + resetHint: + remaining >= 0 ? `${remaining.toFixed(2)} USD remaining` : undefined, }, ], raw: payload,