Skip to content

Commit 755b4ac

Browse files
committed
fix(ccswitch): 去掉 data_source='proxy' 过滤,修复 CC Switch 采集读到 0 的 bug
上游 SQL 的 where coalesce(data_source,'proxy')='proxy' 假设 data_source 列值为 'proxy',但实际 CC Switch 数据库里该列值是 codex_session/opencode_session/session_log, 一行都不匹配 'proxy',导致 CC Switch 源静默报告 0 token。 去掉该过滤条件(status_code 成功 + token>0 已足够过滤),CC Switch 采集现在能 正确读取真实代理活动数据。 这是上游 macOS 版的同款 bug(移植时严格照抄了上游 SQL),本修复同时适用于两端。 对齐上游 8d387aa:仅 macOS 公证脚本(script/package_release.sh),Windows 版跳过, TokenStepSwift 源码无变化。
1 parent c05fc99 commit 755b4ac

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

windows/src-tauri/src/collector.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,12 @@ fn collect_ccswitch() -> (Vec<UsageRecord>, SourceInfo) {
519519
);
520520
}
521521

522-
// The aggregate query mirrors upstream exactly (coalesce model fallbacks,
523-
// filter to successful proxy rows with tokens).
522+
// NOTE: upstream uses `where coalesce(data_source,'proxy')='proxy'`, but
523+
// real-world CC Switch DBs store `data_source` as 'codex_session' /
524+
// 'opencode_session' / 'session_log' — NONE equal 'proxy', so that filter
525+
// drops every row and the source silently reports zero. We drop the
526+
// data_source clause entirely (success-status + tokens>0 is enough) so the
527+
// actual proxy activity is aggregated.
524528
let sql = "select \
525529
created_at, app_type, \
526530
coalesce(nullif(pricing_model, ''), nullif(model, ''), nullif(request_model, ''), 'unknown') as display_model, \
@@ -530,9 +534,8 @@ fn collect_ccswitch() -> (Vec<UsageRecord>, SourceInfo) {
530534
coalesce(cache_creation_tokens, 0) as cache_creation_tokens, \
531535
cast(coalesce(nullif(total_cost_usd, ''), '0') as real) as total_cost_usd \
532536
from proxy_request_logs \
533-
where coalesce(data_source, 'proxy') = 'proxy' \
534-
and status_code >= 200 and status_code < 300 \
535-
and (coalesce(input_tokens, 0) + coalesce(output_tokens, 0) \
537+
where status_code >= 200 and status_code < 300 \
538+
and (coalesce(input_tokens, 0) + coalesce(output_tokens, 0) \
536539
+ coalesce(cache_read_tokens, 0) + coalesce(cache_creation_tokens, 0)) > 0 \
537540
order by created_at, request_id";
538541

0 commit comments

Comments
 (0)