Repository navigation
fix(images): honor a deployment's turn_off_message_logging, Langfuse keys and callbacks again - #54668
quietjules wants to merge 3 commits into
Conversation
…res one logging object
…ment_log_settings # Conflicts: # tests/unit/proxy/image_endpoints/test_endpoints.py
…ment_log_settings
PR overviewThis PR restores image deployments’ handling of turn_off_message_logging, deployment-specific Langfuse credentials, and callbacks. Two security issues remain open, with none addressed so far. An authenticated caller can redirect deployment Langfuse credentials to an attacker-controlled host when the optional destination allowlist is not enabled. Deployment callbacks also persist globally, allowing prompts and responses from unrelated deployments to reach a previously registered logger. Open issues (2)
Fixed/addressed: 0 · PR risk: 8/10 Reviews
|
| ) | ||
|
|
||
| def follow_attempt_callback_settings(self, attempt_fields: Mapping[str, object]) -> None: | ||
| self.standard_callback_dynamic_params = _initialize_standard_callback_dynamic_params(dict(attempt_fields)) |
There was a problem hiding this comment.
High: Client-selected Langfuse host receives deployment keys
For an image deployment configured with Langfuse credentials and a Langfuse callback, an authenticated caller can supply "langfuse_host": "https://attacker.example": the image attempt merges that host with the deployment keys, and this new assignment passes both to LangFuseHandler, whose exporter sends the keys in Basic authentication; the host allowlist is only enforced with OTel V2 enabled, which is off by default. Keep deployment credentials bound to their configured destination, and reject client destination overrides unless they use a complete caller-owned credential set.
There was a problem hiding this comment.
The proxy rejects a request-body langfuse_host with a 401 before routing, unless the admin opts in (code). The PR body shows it live
| return attempt_kwargs | ||
| deployment_callbacks: Final = configured_callbacks(attempt_kwargs.get("callbacks")) | ||
| if deployment_callbacks: | ||
| register_dynamic_callbacks(deployment_callbacks) |
There was a problem hiding this comment.
Medium: Deployment callbacks persist across unrelated requests
register_dynamic_callbacks() permanently adds these deployment-specific callbacks to the process-wide input/success/failure registries, so requesting deployment A with callbacks: [loggerA] causes later requests to unrelated deployment B to deliver their prompts and responses to loggerA through get_combined_callback_list(). Attach deployment callbacks to the current attempt's Logging object instead, reserving global registration for server-wide callbacks.
surlymochan
left a comment
There was a problem hiding this comment.
Verified the mechanism: image requests previously kept the first attempt's callback list for the whole call, so a fallback deployment's own turn_off_message_logging, Langfuse keys, and callbacks were ignored. The new follow_attempt_callback_settings swaps in each attempt's callbacks via _swapped_callbacks (keeps request-level callbacks, appends the new attempt's), and _attempt_callbacks_from returns None for success/failure when the request itself set callbacks — so request-level settings still win over per-attempt ones.
The tests pin the exact behaviors: test_image_log_follows_the_deployments_message_logging_setting, test_image_fallback_logs_each_attempt_by_its_own_deployments_message_logging, and test_image_log_carries_the_deployments_callback_params_unless_the_key_sets_them. The _resolved_dynamic_callbacks expansion of known-logger strings into instances also explains the test_repeated_image_requests_register_a_deployments_named_logger_once case — no duplicate logger registration across repeated requests.
One question on precedence: when the request sets success callbacks, per-attempt success callbacks are skipped entirely (None branch). Is that the intended precedence — request wins, attempt contributes nothing — or should the attempt's callbacks still run alongside? The code is consistent, just confirming the intent is deliberate.
[Medium impact] The PR appears safe to merge with no actionable findings.
|
Handwritten 1-3 sentence description
Image generation on the proxy stopped following a deployment's own logging settings, so a deployment set to keep prompts out of logs still sent the prompt to every logging integration, and its own Langfuse project got nothing. This puts those settings back for each image request and each fallback attempt, so every logged row follows the deployment that actually handled it
Details
TLDR
Problem this solves:
turn_off_message_loggingsince v1.112.0-dev.1How it solves it:
User Flow
Before: an admin who turned off message logging on one image deployment still sees its prompts in their logs
turn_off_message_logging: true, its own Langfuse keys andsuccess_callback: ["langfuse"]on an image deployment and restarts the proxyAfter: the same request logs no prompt, and its trace lands in the deployment's own Langfuse project
turn_off_message_logging: true, its own Langfuse keys andsuccess_callback: ["langfuse"]on an image deployment and restarts the proxylitellm-aimage_generationtrace with an empty inputAffected release
Regression since v1.112.0-dev.1 (#52103), also on the rc/1.112.0 line
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Both proxies ran at the same time on one machine, 2 workers each, no database, with real Gemini calls (
gemini/gemini-3.1-flash-image, chat ongemini/gemini-3.5-flash-lite). A small custom logger writes one row per logged event, andprompt_in_logis true when the prompt textzebra-marker-7731shows up anywhere the logger can read. Each request sends its ownx-litellm-call-idso its rows can be found again. Deployments namedprivate*setturn_off_message_logging: true, and the*failandprivatefirstones use an invalid key so Google answers a real error. The deployment's own Langfuse project is a local Langfuse 4.86.0, since the Langfuse Cloud project this ran against before is out of free units and now answers every export with a 403langfuse_hostEvery private deployment's own row should show no prompt and every open one should show it. This PR brings back the behavior from before #52103 and also covers image streaming, which came to main after it. A caller still cannot send the deployment's Langfuse keys to a host of its own, since the proxy rejects
langfuse_hostin the request body on both commitsShared setup: config.yaml, custom logger, local Langfuse, start script, case script
Env var names:
GEMINI_API_KEY,QA_LANGFUSE_PUBLIC_KEY,QA_LANGFUSE_SECRET_KEY,QA_LANGFUSE_HOST,CAPTURE_LOG_PATH,PYTHONPATH(the folder holdingcapture_logger.py). The three Langfuse values come fromlangfuse.env, which points at the local Langfuse, andlangfuse-selfhost.curlrcholds the same key pair for the read API. Each proxy started aslaunch.sh <worktree> <port> <capture file>and the cases ran ascases.sh <port> <capture file>Local Langfuse, from the
docker-compose.ymlat tag v4.86.0 of langfuse/langfuse, withLANGFUSE_INIT_ORG_ID,LANGFUSE_INIT_PROJECT_ID,LANGFUSE_INIT_PROJECT_PUBLIC_KEYandLANGFUSE_INIT_PROJECT_SECRET_KEYset inkeys.envand an override that publishes only the web port on 127.0.0.1config.yaml
capture_logger.py
launch.sh
cases.sh
Before (beb69b2)
private, served
privatefail, failed
Commands and output
openfail falls back to private
Commands and output
privatefirst falls back to open
Commands and output
private, streamed
Commands and output
privatelangfuse, its own Langfuse project
Commands and output
privatelangfuse with a client-sent Langfuse host
Commands and output
langfuse_hostopen, served (control)
Commands and output
privatechat, chat (out of scope)
Commands and output
After (a75b927)
private, served
privatefail, failed
Commands and output
openfail falls back to private
Commands and output
privatefirst falls back to open
Commands and output
private, streamed
Commands and output
privatelangfuse, its own Langfuse project
Commands and output
privatelangfuse with a client-sent Langfuse host
Commands and output
langfuse_hostopen, served (control)
Commands and output
privatechat, chat (out of scope)
Commands and output
Earlier checkpoints
e42e0db, the commit before #52103
113766d, #52103
Surprises from the run
Decisions
callbacksregister once under the existing lock, the same way the SDK registers them. That keeps them process-wide, as images did before fix(gemini): return n images for image generations and edits when n > 1 #52103 and as chat and every other endpoint still do. Scoping them to one request would be its own change for every endpointlangfuse_hostin the request body before routing unless the admin opts in, which the live case above shows on both commitsType
🐛 Bug Fix
Final Attestation