Conversation
diogenxs
force-pushed
the
lazybirds/pg
branch
2 times, most recently
from
October 1, 2026 18:44
82013cc to
2719644
Compare
…indable Bun.sql binds plain objects to text parameters via String() → '[object Object]', so every *_json column write stored garbage on Postgres while the SQLite adapter JSON.stringify'd the same values.
Author
|
Filed the underlying report as #593. Rebased onto current main (the adapter gained |
This branch has not been deployed
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.
Fixes #593.
Problem
On Postgres, Bun SQL binds plain objects to
textparameters viaString(), storing literal'[object Object]'in every*_jsoncolumn. The SQLite adapter'stoBindableJSON.stringify's the same values, so the two dialects silently diverge: a PG deployment writes garbage toai_messages.content_json, conversation settings, plugin records — and replaying that content into a provider request fails with a confusing downstream 500.Root cause
docs/reference/database-dialects.mdRule 2 documents both adapters as auto-serializing JSON-shaped writes. The SQLite adapter does it intoBindable; the Postgres side relied onBun.sqlparameter binding — which binds a plain object to atextcolumn viaString().Related upstream: oven-sh/bun#29010 (
prepare:falsejsonb variant) — but this fix is needed independently: for atextparameter Bun can't infer a JSON contract, so the adapter must own the serialization, exactly like the SQLite path already does.Fix
Mirror SQLite's
toBindablein the PG wrapper (tagged templates +unsafe()params):JSON.stringify(the actual bug)Date→ ISO 8601 string (Bun PG text-format binding is localetoString())Uint8Array/Buffer→ pass through untouched — Bun binds binary natively tobytea(verified round-trip); stringifying would corrupt AES-GCM credential ciphertext/iv and break every decryptVerification
End-to-end on Postgres 16 with a live provider credential:
content_json='[object Object]'; replaying the conversation 500s the provider callcontent_json=[{"kind":"text","text":"…"}]; multi-turn agent chats (toolCall/toolResult blocks) persist and replay correctly; credential decrypt works (binary passthrough); setup/login/roles/users/onboarding unaffectedFound while running Instatic on shared Postgres at LazyBirds (one database per site, provisioned automatically). Happy to add a PG regression test — pointing me at the preferred harness for DB-backed tests would help.