Skip to content

fix(api-keys): backfill new limit usage#522

Open
mgwals wants to merge 1 commit intoSoju06:mainfrom
mgwals:fix/api-key-limit-backfill-current-usage
Open

fix(api-keys): backfill new limit usage#522
mgwals wants to merge 1 commit intoSoju06:mainfrom
mgwals:fix/api-key-limit-backfill-current-usage

Conversation

@mgwals
Copy link
Copy Markdown

@mgwals mgwals commented Apr 30, 2026

Summary

  • Backfill newly added API key limits from successful request-log usage in the active lookback window.
  • Preserve existing matching limit counters and keep resetUsage as the explicit zero-reset path.
  • Add OpenSpec coverage and regression tests for total-token, model-filtered, reset, and non-success-log behavior.

Closes #518

Validation

  • openspec validate --specs
  • openspec validate backfill-api-key-limit-current-usage
  • uv run pytest -q tests/integration/test_api_keys_trends_api.py::test_adding_limit_backfills_current_window_usage tests/integration/test_api_keys_trends_api.py::test_adding_model_scoped_limit_backfills_only_matching_model tests/integration/test_api_keys_trends_api.py::test_adding_limit_with_reset_usage_keeps_current_value_zero
  • uv run pytest -q tests/unit/test_api_keys_service.py tests/integration/test_api_keys_trends_api.py
  • uv run ruff check app/modules/api_keys tests/integration/test_api_keys_trends_api.py tests/unit/test_api_keys_service.py
  • uv run ruff format --check app/modules/api_keys tests/integration/test_api_keys_trends_api.py tests/unit/test_api_keys_service.py
  • uv run ty check
  • codex-review-high --base origin/main

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.

Limits are not applying after add limit rule to existing API key with current usage

1 participant