Skip to content

fix(usage): replace redis.keys() with async scan_iter in cost tracker — eliminates O(N) block (#4443)#4733

Merged
mrveiss merged 1 commit intoDev_new_guifrom
issue-4443
Apr 15, 2026
Merged

fix(usage): replace redis.keys() with async scan_iter in cost tracker — eliminates O(N) block (#4443)#4733
mrveiss merged 1 commit intoDev_new_guifrom
issue-4443

Conversation

@mrveiss
Copy link
Copy Markdown
Owner

@mrveiss mrveiss commented Apr 15, 2026

Closes #4443

Summary

  • _fetch_model_costs, get_all_agent_costs, get_all_user_costs in llm_cost_tracker.py all used await redis.keys(pattern) — a blocking O(N) call that scans the entire keyspace
  • Replaced all three with [k async for k in redis.scan_iter(pattern)] — non-blocking cursor-based iteration
  • Removed intermediate all_keys variable in get_all_user_costs, inlined filter directly into the async comprehension
  • Return types and :daily: sub-key filtering behaviour fully preserved

Tests

  • 5 new TestScanIterUsage tests + 53 pre-existing = 63 passed

🤖 Generated with Claude Code

…_costs, get_all_agent_costs, _fetch_model_costs (#4443)

Eliminates O(N) blocking KEYS command across three cost-tracking methods;
adds 5 async unit tests verifying scan_iter is called and daily sub-keys
are correctly filtered.
@mrveiss mrveiss merged commit 522c5db into Dev_new_gui Apr 15, 2026
3 of 4 checks passed
@mrveiss mrveiss deleted the issue-4443 branch April 15, 2026 18:06
@github-actions
Copy link
Copy Markdown

✅ SSOT Configuration Compliance: Passing

🎉 No hardcoded values detected that have SSOT config equivalents!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant