fix(proxy): add stable usage keys and idempotent raw-response logging

Derive request ids from upstream envelope ids (Codex/OpenAI top-level
id, Gemini responseId, Claude message id with non-empty filtering)
scoped as session:{app_type}:{provider_id}:{id} for non-Claude sources;
Claude keeps bare session:{id} to preserve session-log convergence.

The logger now queries and conditionally writes under a single
connection guard: identical semantic replays return without writing or
notifying, session_log rows may be upgraded by proxy, and same-id
different-semantic responses land on a deterministic SHA-256 collision
fallback key instead of being overwritten. Fixes the random-UUID
INSERT OR REPLACE duplication behind #5496.
This commit is contained in:
Jason
2026-07-20 12:16:57 +08:00
parent df3e07edbb
commit c9ac6efd69
5 changed files with 385 additions and 54 deletions
+2 -1
View File
@@ -642,7 +642,8 @@ async fn log_usage_internal(
model
};
let request_id = usage.dedup_request_id();
let dedup_scope = (app_type != "claude").then_some((app_type, provider_id));
let request_id = usage.dedup_request_id(dedup_scope);
log::debug!(
"[{app_type}] 记录请求日志: id={request_id}, provider={provider_id}, model={model}, streaming={is_streaming}, status={status_code}, latency_ms={latency_ms}, first_token_ms={first_token_ms:?}, session={}, input={}, output={}, cache_read={}, cache_creation={}",