litellm/tests/unit/proxy/management_helpers
martenj4 deaf20bdf9
fix(proxy): retry failed audit log writes and count the ones that stay lost (#54417)
* fix(proxy): retry failed audit log writes and count the ones that stay lost

A failed audit insert after a management change was logged and dropped, so a 200 could leave no audit row and no signal. Temporary database failures now retry in a tracked background task, and a write that still fails names its rows in the log and increments the callback failure metric once per row

* fix(proxy): log each lost audit row on its own bounded line

* fix(proxy): run audit log retries one at a time per worker

Retries share the Rust connection pool with key auth reads, so a slow failing insert could hold every connection. Each worker now runs one retry attempt at a time, and a write stops retrying 30 seconds after its first failure

* fix(audit): bound audit retries by their time limit and try once more at shutdown

A retry that hung on the database held the per-worker retry lock past its
30 second limit, so the retries queued behind it were neither stored nor
counted. The limit now covers both waiting for the lock and the attempt, and
a spent limit no longer sleeps out the remaining delays. When the shutdown
drain starts, a waiting retry skips its delay and makes one last attempt, so
SIGTERM no longer waits out a retry delay before the entry is stored or
counted

* fix(proxy): log the first failed audit write and retry it for the full 30 seconds

A failed first attempt now logs a warning before its background retry, so a
short failure or a killed worker still leaves a trace. The retry delays now
reach 28.5 seconds, so a fast lasting failure is retried across the whole
window instead of 7.5 seconds. A retry error naming the audit primary key
counts as already stored only when the database rejected it as data.

* fix(proxy): let an audit retry still running at its time limit finish

The 30 second retry limit cancelled an insert that was still running on the
database. Cancelling the native insert mid-flight left the worker's database
pool stuck, so later audit writes hung and every key request waited 10 seconds
for its user lookup until the proxy restarted.

The limit now bounds only the wait for a retry's turn. An attempt that is
still running when the limit passes is counted as lost at once and finishes in
a tracked background task, which releases the retry lock when it returns.

* test(proxy): drive the still-running audit retry test with a skippable loop clock

The test now stalls the retry on an event and moves the loop clock past the retry limit, so it no longer depends on real sleeps finishing in order. It also drops an unused time import.

* fix(proxy): let a failed audit retry answer for the retries waiting behind it

During a slow database failure each worker ran its queued audit retries back to back, so one pool
connection stayed busy for the whole 30 s window and a shutdown drain ran out of time with
retries still queued, dropping them without logging or counting them.

A retry that waited for its turn while the attempt ahead of it failed now counts that failure as
its own and moves on to its next delay, so a worker makes one attempt per turn while the database
keeps failing and every queued retry is counted soon after shutdown starts. A retry still running
at its 30 s limit that stores its row afterwards now logs that it was saved after being counted.

The concurrent retries test now expects 5 attempts instead of 9, because the retries queued
behind a failed attempt no longer each try the database

* fix(proxy): share a failed audit retry only when the database is unavailable

A retry that waited for its turn while the attempt ahead of it failed took
that failure as its own for any retryable error. A batch whose retry timed
out then made smaller writes queued behind it skip inserts that would have
worked, and on their last turn or at shutdown those entries were counted as
lost without a try of their own.

Only a failure that marks the database unavailable, a lost connection or no
free connection, now stands in for the retries waiting behind it. Any other
failure leaves each waiting retry its own attempt.

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 21:03:03 +00:00
..
__init__.py
team_metadata_validator_impls.py test(proxy): move management_endpoints, management_helpers and guardrails tests into tests/unit/proxy (#44003) 2026-10-01 10:52:03 -07:00
test_access_group_key_sync.py fix(proxy): preserve concurrent access group assignments (#53840) 2026-11-23 16:27:41 -08:00
test_access_group_model_sync.py fix(proxy): preserve concurrent access group assignments (#53840) 2026-11-23 16:27:41 -08:00
test_access_group_team_sync.py test(proxy): move management_endpoints, management_helpers and guardrails tests into tests/unit/proxy (#44003) 2026-10-01 10:52:03 -07:00
test_app_groups.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00
test_apps.py feat(proxy): add app groups with shared budgets and usage (#53232) 2026-11-21 12:50:58 -08:00
test_audit_log_callbacks.py refactor(s3-log): move the rust-backed s3 logger from s3_v3 to s3_v2 (#51893) 2026-11-14 22:24:23 -08:00
test_audit_logs_proxy.py fix(proxy): retry failed audit log writes and count the ones that stay lost (#54417) 2026-11-25 21:03:03 +00:00
test_auto_router_availability.py refactor(router): fence the router surface and document the router-core boundary (#48839) 2026-10-29 00:01:52 +00:00
test_auto_router_permissions.py fix(databricks): call the ai_decide AI Function route for decisions and the auto-router (#45722) 2026-10-10 23:58:16 -07:00
test_bulk_user_creation.py feat(caching): configure semantic cache params per key, user and team (#53905) 2026-11-23 13:55:45 -08:00
test_bulk_user_deletion.py refactor(auth_cache): type auth cache keys and keep the cache always native (#51130) 2026-11-21 17:20:30 +09:00
test_customer_budget_usage.py fix(budgets): match window starts to stored millisecond precision (#51921) 2026-11-16 04:02:44 +08:00
test_customer_hierarchy.py fix(proxy): preserve budget window edits during resets (#53064) 2026-11-20 10:50:27 -08:00
test_management_helpers_utils.py test(proxy): expect the rollover guard in the budget update test (#53575) 2026-11-22 18:16:45 +00:00
test_mcp_auth_profile_grants.py feat(mcp): add grant parsing and canonicalization helpers (#53680) 2026-11-24 23:33:58 -08:00
test_object_permission_utils.py feat(proxy): app-scoped read access to Customer Management through object permissions (#52781) 2026-11-19 10:43:41 -08:00
test_resource_display_names.py feat(access-groups): name group vector stores and list them on team info (#51484) 2026-11-13 07:53:04 -08:00
test_team_list_sorting.py feat(ui): sort every teams table data column (#48109) 2026-10-23 16:21:36 -07:00
test_team_member_permission_checks.py fix(proxy): align ownership and scope handling (#50600) 2026-11-08 07:03:36 +00:00
test_team_metadata_validation.py feat(lens): add key and team tracing controls (#53191) 2026-11-23 17:59:37 +00:00
test_team_roster_sync.py feat(proxy): sync LDAP groups to team memberships (#50130) 2026-11-24 11:13:49 -08:00
test_user_list_sorting.py feat(ui): sort every users table data column (#48105) 2026-10-23 16:12:51 -07:00