Skip to content

perf: remove synchronous LiteLLM free-model sync from verified-models writes - #402

Open
juanmichelini wants to merge 3 commits into
mainfrom
remove-synchronous-litellm-free-model-sync
Open

juanmichelini wants to merge 3 commits into
mainfrom
remove-synchronous-litellm-free-model-sync

Conversation

@juanmichelini

@juanmichelini juanmichelini commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Human

Why

OHE customers don't care about is_free sync, only SaaS does. Sync will be managed from infra repo instead.

Related request: https://allhandsai.slack.com/archives/C09VBG51GEM/p1789401544248149

Summary

Fixes #399.

PUT/POST/DELETE /api/admin/verified-models/... fanned out a synchronous, per-org, sequential sweep to the LiteLLM management API from inside the request cycle whenever the payload touched is_free/is_enabled. On prod-scale data (~49k teams) this hung the request until the client timed out, emitted no access-log line, and — because the sweep was pinned to a stale in-memory snapshot — kept rewriting free-tier team allowlists long after the request gave up, fighting other reconciliation.

This PR makes the admin write a pure, fast DB mutation. Free-model allowlist propagation moves entirely off the request path into the infra litellm-team-models Action (companion issue OpenHands/infra#1698).

Changes

  • server/verified_models/verified_model_service.py
    • Removed _sync_litellm_free_model_allowlists calls from create_verified_model / update_verified_model / delete_verified_model.
    • Removed the _sync_litellm_free_model_allowlists and _list_openhands_enabled_free_model_names helpers.
    • Removed the LiteLLMSyncError exception class.
  • server/verified_models/verified_model_router.py
    • Removed the LiteLLMSyncError import, the _litellm_sync_error_response 502 mapping, and the except LiteLLMSyncError handlers.
  • storage/lite_llm_manager.py
    • Removed sync_free_model_allowlists and its now-dead helpers _is_free_tier_team_info and _get_org_ids.
  • Tests updated/trimmed to assert the admin write performs no LiteLLM calls, and to drop the deleted sync tests.

Acceptance criteria

  • Admin write no longer performs any per-org LiteLLM calls.
  • No path in the verified-model service spawns a fleet-wide LiteLLM sweep.
  • Tests updated. ruff passes; changed modules import cleanly.

Testing notes

The unit suite spins up a Postgres testcontainer (Docker), which is not available in this environment, so the full suite was not executed here. Changed modules compile/import cleanly and ruff check passes on all touched files. CI will run the full suite.


This PR was created by an AI agent (OpenHands) on behalf of @juanmichelini.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-cead932

…writes

The admin PUT/POST/DELETE on /api/admin/verified-models fanned out a
synchronous, per-org, sequential sweep to the LiteLLM management API
inside the request cycle. On prod-scale data (~49k teams) this hung the
request until the client timed out, and the in-flight sweep kept
rewriting free-tier team allowlists to a stale snapshot.

Make the admin write a pure, fast DB mutation:
- Drop _sync_litellm_free_model_allowlists calls (and the helper) from
  create/update/delete_verified_model, plus _list_openhands_enabled_free_model_names.
- Remove LiteLLMSyncError and the router's 502 mapping.
- Remove LiteLlmManager.sync_free_model_allowlists and its now-dead
  helpers (_is_free_tier_team_info, _get_org_ids).

Free-model allowlist propagation now lives entirely in the infra
litellm-team-models Action. Tests updated accordingly.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  server/verified_models
  verified_model_router.py 99-108
  verified_model_service.py 167
  storage
  lite_llm_manager.py
Project Total  

This report was generated by python-coverage-comment-action

@juanmichelini

Copy link
Copy Markdown
Contributor Author

@openhands-agent /codereview-roasted

Collapse two calls/defs that ruff format wants on a single line so the
Lint python pre-commit hook passes.

Co-authored-by: openhands <openhands@all-hands.dev>
@juanmichelini juanmichelini changed the title Make admin verified-models write always fast: remove synchronous LiteLLM free-model sync perf: remove synchronous LiteLLM free-model sync from verified-models writes Sep 16, 2026
@github-actions github-actions Bot added the type: perf A performance improvement label Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: perf A performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make admin verified-models write always fast: remove synchronous LiteLLM free-model sync from the request path

2 participants