Hotfix/AI post limits deploy fixes#461
Draft
dspachos wants to merge 11 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR delivers hotfixes around spend-cap persistence/synchronization with LiteLLM and adds an operational script to clean up “orphaned” LiteLLM keys referenced from the DB.
Changes:
- Add a one-off script to detect LiteLLM keys that no longer exist remotely and optionally null out their DB references (plus remove associated spend_caps).
- Fix spend_caps lookup/upsert/delete helpers to match the spend_caps partial unique-index columns and repair stale team/user metadata to avoid unique constraint violations.
- Deprecate the legacy private-ai-keys spend endpoint and adjust it to prefer the configured DB spend cap when present.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
scripts/detect_orphaned_keys.py |
New maintenance script to detect orphaned LiteLLM tokens and optionally clean up DB state + spend_caps. |
scripts/backfill_litellm_sync.py |
Formatting-only change to add_team_member call for readability. |
app/api/spend.py |
Align spend_caps lookups with partial unique indexes; repair stale columns on update to prevent duplicate inserts. |
app/api/private_ai_keys.py |
Deprecate legacy spend endpoint and override returned max_budget from spend_caps when configured. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
|
@copilot apply changes based on the comments in this thread |
…okup - Redact litellm_token in report output (store only last 4 chars hint as litellm_token_hint) to avoid writing secrets to disk - Apply --limit at DB query level instead of after .all() to bound DB load - Update docstring to reflect both 401 and 404 are treated as orphaned - Preload regions and reuse LiteLLMService per region to avoid N+1 DB pattern - Fix key-scope spend_cap lookup in private_ai_keys.py to use (region_id, key_id) matching the unique index uq_spend_caps_key_scope instead of filtering on team_id/user_id which are metadata and can be stale/NULL - Add regression test for stale-column repair path in _upsert_spend_cap to verify it finds existing row by (region_id, key_id) and repairs team_id/ user_id in-place without UniqueViolation Agent-Logs-Url: https://github.com/amazeeio/amazee.ai/sessions/e02b1833-5c0a-44ee-bbfe-84aa4855e49c Co-authored-by: dspachos <6309422+dspachos@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…deploy-fixes # Conflicts: # app/api/private_ai_keys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.