fix(billing): prefer Goose session cost over token estimate
Billing fell back to inflated token list-price estimates when Finish frames carried inline accumulatedCost, causing ~70x overcharge vs DeepSeek. Always fetch session accumulated_cost first; add Aug 4+ compensation script. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -38,15 +38,16 @@ export function enrichTokenStateForBilling(
|
||||
env = process.env,
|
||||
) {
|
||||
const state = normalizeTokenState(tokenStateRaw);
|
||||
if (state.accumulatedCost != null && Number(state.accumulatedCost) >= 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const sessionUsd = pickSessionAccumulatedCost(sessionCost);
|
||||
if (sessionUsd != null) {
|
||||
return { ...state, accumulatedCost: sessionUsd };
|
||||
}
|
||||
|
||||
if (state.accumulatedCost != null && Number(state.accumulatedCost) >= 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
const estimatedUsd = estimateAccumulatedCostUsd(state, loadCostEstimateConfig(env));
|
||||
if (estimatedUsd != null) {
|
||||
return { ...state, accumulatedCost: estimatedUsd };
|
||||
@@ -61,9 +62,6 @@ export async function resolveBillingTokenState(
|
||||
env = process.env,
|
||||
) {
|
||||
const state = normalizeTokenState(tokenStateRaw);
|
||||
if (state.accumulatedCost != null && Number(state.accumulatedCost) >= 0) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (typeof fetchSession === 'function' && sessionId) {
|
||||
try {
|
||||
@@ -71,7 +69,7 @@ export async function resolveBillingTokenState(
|
||||
const enriched = enrichTokenStateForBilling(state, { sessionCost: session }, env);
|
||||
if (enriched.accumulatedCost != null) return enriched;
|
||||
} catch {
|
||||
// Best-effort: fall through to token estimate.
|
||||
// Best-effort: fall through to inline cost / token estimate.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user