-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(router): add deterministic lifecycle (close()/ aclose() + context managers) #14551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grahama1970 modifying our docker-compose seems out of scope for this PR.
Can this be reverted please? @grahama1970
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for flagging. Reverted — no repo Docker/compose changes remain. Scope is limited to router lifecycle + tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert the docker-compose changes
|
||
try: | ||
parsed_body = json.loads(body_str) | ||
parsed_body = json.loads(body_str) if body_str else {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change this? the change seems like it would be harder to catch invalid json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — reverted. No parsing changes in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this related to this pr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted — unrelated to router lifecycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment - why does this file exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted — unrelated to this PR; will handle separately if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume this is to fix the ci / cd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I'll back to this PR in 48 hours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted — unrelated to this PR; will handle separately if needed.
…t managers)\n\n- Add Router.close()/aclose() with idempotent shutdown flag and managed thread joins\n- Add sync/async context manager support\n- Hook into existing discard() to unhook callbacks\n- Tests for idempotency and context managers
…se/aclose + context managers only
…agers); tests for idempotent close + sync/async context; fix(org): restore transform_organization_update_request alias; chore(make): ci-parity-local lints only changed files and add preflight-local
…o avoid TypeError in files endpoint; chore(makefile): add smoke-proxy-files target and clearer progress output
…purpose to str; prevent MagicMock TypeError in CI
…efile targets inside CI container; add Dockerfile.ci and docker-compose.yml
58ac17c
to
8c65aec
Compare
Scope narrowed to exactly the router lifecycle + tests. Summary for reviewers: What changed (now)
Validation (tests-only in container as repo user)
Notes
Request
Reviewer comments addressed
|
Title: Router Lifecycle: Deterministic close()/aclose() + Context Managers (Tests Only)
Summary
litellm.Router
:Router.close()
andRouter.aclose()
— idempotent teardown that unhooks Router-managed callbacks.__enter__/__exit__
,__aenter__/__aexit__
) that call close/aclose.Motivation
Behavior & API
Router.close()
:_closed
flag).discard()
to unhook callbacks from global managers.discard()
to keep teardown resilient.Router.aclose()
:close()
for symmetry.with Router(...) as r:
callsclose()
on exit.async with Router(...) as r:
callsaclose()
on exit.Backwards Compatibility
Performance & Threading
_closed
boolean flag and a call intodiscard()
during teardown.Security
Files Touched (and why)
litellm/router.py
— Adds_closed
flag,close()/aclose()
, and sync/async context manager methods. Uses existingdiscard()
for unhooking.tests/test_litellm/test_router.py
— Adds tests for:close()
Developer Feedback Addressed (from earlier review)
local/
in the fork and is excluded from the PR.http_parsing_utils.py
,openai_endpoint_utils.py
,organization_endpoints.py
, files endpoints guards) — Removed from this PR. If needed, we’ll submit targeted follow-ups with focused tests.Testing
tests/test_litellm/test_router.py
in a clean Python container.Reviewer Notes
Router
plus targeted tests. No docs included to keep scope tight; happy to add a brief “Lifecycle” section in Router docs if desired.Examples
Changelog