Repository navigation
fix(proxy): start on Postgres databases with SQL_ASCII encoding - #53965
Merged
Merged
Conversation
Collaborator
Author
Collaborator
Author
|
bugbot run |
Contributor
Contributor
[Low impact] The PR appears safe to merge, with the previous finding fixed and no new issues found.
|
Collaborator
Author
Collaborator
Author
|
bugbot run |
Contributor
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 3faa5e1. Configure here.
kerry-berri
approved these changes
Nov 24, 2026
This was referenced Nov 24, 2026
Closed
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.
Handwritten 1-3 sentence description
The proxy now starts and restarts on a Postgres database whose encoding is SQL_ASCII, and builds its request-log indexes there. Before, the first boot logged an error and skipped the indexes, and every later boot crashed.
Details
Link to Devin session: https://app.devin.ai/sessions/83d42fd3dca2490c941686a5f537a783
Open in Devin Desktop: https://app.devin.ai/desktop/session/83d42fd3dca2490c941686a5f537a783?variant=devin
Requested by: @kenneth-berri
TLDR
Problem this solves:
How it solves it:
User Flow
Before: an operator whose Postgres database was created with SQL_ASCII encoding can start the proxy once and never again
ValueError: invalid literal for int() with base 10: "b'8192'"TypeError: cannot use a string pattern on a bytes-like objectAfter: the same operator starts and restarts the proxy with no error
Relevant issues
Fixes #52247
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
Shared setup, run the same way for both legs against a local Postgres 16. Each leg uses a fresh database and boots the proxy twice. The proxy ran with one worker and without Redis or
--reload, because the bug is in startup migrations and index builds and does not involve shared worker state.DATABASE_URLandANTHROPIC_API_KEYare the only env vars.Before (6088120)
After (ccc316f)
The new integration test
test_a_sql_ascii_database_migrates_on_every_boot_and_gets_its_request_log_indexesfails on 6088120 and passes on ccc316f for both migration resolvers.Type
🐛 Bug Fix
Caveats (if any)
Low
Final Attestation
Note
Low Risk
Narrow change to how psycopg negotiates client encoding on existing startup paths; risk is limited to non-UTF-8 identifiers in SQL_ASCII databases.
Overview
Fixes proxy startup when the Postgres database uses SQL_ASCII encoding by passing
client_encoding="utf8"on every proxy-extraspsycopg.connectused for migrations, migration locking, request-log index builds, and related catalog/ledger queries. That forces migration names, settings, and catalog values to arrive as normal strings instead of byte literals that previously broke index builds on first boot and crashed restarts.The injectable
LensCheckConnectprotocol and unit-testpsycopg.connectmocks are updated to acceptclient_encoding. An integration test provisions a SQL_ASCII database and asserts migrations and request-log indexes succeed across repeated boots on both resolvers.Reviewed by Cursor Bugbot for commit 3faa5e1. Bugbot is set up for automated code reviews on this repo. Configure here.