Skip to content

fix(usage): derive API key last-used and bound stream memory#126

Closed
mojomast wants to merge 1 commit intofollowup/pr125-db-hardeningfrom
followup/pr126-usage-correctness
Closed

fix(usage): derive API key last-used and bound stream memory#126
mojomast wants to merge 1 commit intofollowup/pr125-db-hardeningfrom
followup/pr126-usage-correctness

Conversation

@mojomast
Copy link
Collaborator

@mojomast mojomast commented Feb 14, 2026

Summary

  • make last_used_at accurate in user/UI key listings by deriving from MAX(usage_events.timestamp) per key instead of relying on stale nullable column writes
  • surface derived last-used timestamps in /ui/me API key table
  • replace unbounded stream chunk accumulation with lightweight StreamUsageTracker metadata tracking for usage attribution and logging
  • keep request accounting behavior unchanged while reducing stream memory growth risk

Verification

  • PYTHONPATH=src .venv/bin/python -m py_compile src/proxy_app/usage_queries.py src/proxy_app/routers/user_api.py src/proxy_app/routers/ui.py src/proxy_app/stream_usage.py src/proxy_app/main.py tests/test_api_keys.py tests/test_stream_usage.py
  • PYTHONPATH=src .venv/bin/pytest -q tests/test_api_keys.py tests/test_stream_usage.py tests/test_usage_attribution.py

Important

Improve API key last-used tracking and stream memory management with StreamUsageTracker and derived timestamps.

  • Behavior:
    • Derive last_used_at for API keys from MAX(usage_events.timestamp) instead of a nullable column.
    • Display derived last-used timestamps in /ui/me API key table.
    • Replace unbounded stream chunk accumulation with StreamUsageTracker for metadata tracking in stream_usage.py.
  • Functions:
    • Add fetch_api_key_last_used_map() in usage_queries.py to derive last-used timestamps.
    • Update streaming_response_wrapper() in main.py to use StreamUsageTracker.
  • Templates:
    • Update me.html to show derived last-used timestamps.
  • Tests:
    • Add test_list_api_keys_uses_derived_last_used_timestamp() in test_api_keys.py.
    • Add test_stream_usage_tracker_keeps_only_minimal_metadata() in test_stream_usage.py.

This description was created by Ellipsis for 5fd3f9a. You can customize this summary. It will automatically update as commits are pushed.

@mojomast mojomast requested a review from Mirrowel as a code owner February 14, 2026 03:24
@mojomast
Copy link
Collaborator Author

Superseded by updates pushed to #123 to keep all MVP changes in one review thread.

@mojomast mojomast closed this Feb 14, 2026
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