fix: cascade correlation — fallback to _latest MITM usage
When the MITM can't extract a cascade ID from the intercepted request (Content-Length: 0 / chunked encoding), usage is stored under '_latest'. Now usage_from_poll and completions try the exact cascade_id first, then fall back to '_latest' so MITM-captured tokens are actually used.
This commit is contained in:
@@ -277,7 +277,12 @@ async fn usage_from_poll(
|
||||
output_text: &str,
|
||||
) -> Usage {
|
||||
// Priority 1: MITM intercepted data (most accurate — includes cache tokens)
|
||||
if let Some(mitm_usage) = mitm_store.take_usage(cascade_id).await {
|
||||
// Try exact cascade_id match first, then fall back to "_latest" (unmatched)
|
||||
let mitm_usage = match mitm_store.take_usage(cascade_id).await {
|
||||
Some(u) => Some(u),
|
||||
None => mitm_store.take_usage("_latest").await,
|
||||
};
|
||||
if let Some(mitm_usage) = mitm_usage {
|
||||
tracing::debug!(
|
||||
input = mitm_usage.input_tokens,
|
||||
output = mitm_usage.output_tokens,
|
||||
|
||||
Reference in New Issue
Block a user