fix(gateway): /usage billing route follows the most recent model too
`_persisted_billing_route` (idle `/usage` account-limits lookup) was the last reader of the lifetime-dominant route, so it queried the retired provider's account after a switch. Point it at `get_recent_session_model_route` and delete the dominant query, which no longer has a caller.
This commit is contained in:
@@ -744,29 +744,11 @@ class SessionSessionsMixin:
|
||||
)
|
||||
return self._session_row_dict(row) if row else None
|
||||
|
||||
def get_dominant_session_model_route(self, session_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""Main-loop model route that served most API calls (``session_model_usage`` keeps the coherent
|
||||
per-call tuple; ``sessions`` mixes route changes)."""
|
||||
self.flush_token_counts()
|
||||
row = self._read_one(
|
||||
"""SELECT model, billing_provider, billing_base_url, billing_mode,
|
||||
api_call_count
|
||||
FROM session_model_usage
|
||||
WHERE session_id = ?
|
||||
AND task = ''
|
||||
AND model <> 'unknown'
|
||||
AND billing_provider <> ''
|
||||
ORDER BY api_call_count DESC,
|
||||
(input_tokens + output_tokens + cache_read_tokens +
|
||||
cache_write_tokens + reasoning_tokens) DESC,
|
||||
last_seen DESC
|
||||
LIMIT 1""",
|
||||
(session_id,),
|
||||
)
|
||||
return dict(row) if row else None
|
||||
|
||||
def get_recent_session_model_route(self, session_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""Most recently used main-loop model route as one coherent per-call tuple."""
|
||||
"""Most recently used main-loop model route as one coherent per-call tuple
|
||||
(``session_model_usage`` keeps model+provider together; ``sessions`` mixes route changes).
|
||||
Recency, not lifetime call count: on a long session a route retired weeks ago can hold the
|
||||
highest ``api_call_count`` forever, and /status and /usage would keep calling it current."""
|
||||
self.flush_token_counts()
|
||||
row = self._read_one(
|
||||
"""SELECT model, billing_provider, billing_base_url, billing_mode,
|
||||
|
||||
Reference in New Issue
Block a user