Skip to content

server: batch dialog work and qualify prepared queries - #123

Closed
morajabi wants to merge 5 commits into
mainfrom
codex/db-roundtrips
Closed

morajabi wants to merge 5 commits into
mainfrom
codex/db-roundtrips

Conversation

@morajabi

@morajabi morajabi commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Drizzle calls postgres.js unsafe() with preparation disabled, adding a Describe/Flush exchange to parameterized queries. Dialog opening also locked each owner separately and reread unchanged state. Batch owner locks in user-ID order, bind hot owner lists as one array, and skip only proven no-op readbacks. Reset replay rewind backoff after the client passes its previous high-water mark.

Keep preparation restricted to the previously tuned replay-access queries by default. Broad preparation is now an explicit INLINE_DATABASE_PREPARED_QUERIES=all-custom opt-in: startup and readiness check force_custom_plan through the query pool. This avoids introducing generic plans for parameter-sensitive queries. The application does not change database roles/settings. Operators must qualify role defaults, recycle existing pooled backends, and measure representative replay before enabling it; one sampled backend cannot prove the whole pool inherited a setting.

Cap retained signatures at 200, admit broad shapes only after a second observation, and reserve capacity for access queries by limiting broad signatures to 100. Candidate tracking is bounded. Retained signatures are deliberately not advertised as an LRU; overflow keeps the original unnamed path. Pool/per-call opt-outs and transaction/savepoint behavior remain intact.

Validation: 40 focused prepared/connection/wire tests passed, final guard/readiness integration rerun passed 12; four dialog PostgreSQL tests and five replay guard tests passed. Partial-index tests verify retained index use and zero generic plans after more than five custom executions. Benchmark harness mode/report tests and typecheck passed. Controlled 20-sample handler benchmarks at injected +6 ms show access→all-custom exchanges 43→24 for DM sends, 51→28 for public sends, and 19→11 for history; respective medians 267.54→142.41 ms, 363.07→201.41 ms, and 192.13→101.56 ms. Proxy calibration differs slightly between runs; these are synthetic handler measurements, not production API latency. User-bucket replay qualification is separate; these replay fixtures exercise chat buckets. Full server/image CI passed at 0b51ed38f; latest test-only proxy half-close fix has 11 passing wire/measurement tests and typecheck, with hosted CI pending. Prior 5dc49a0f2 global-preparation measurements are historical, not evidence for the revised default. No production deploy, role change, migration, DNS or traffic switch.

@morajabi morajabi changed the title server: prepare database queries and batch dialog owner locks server: batch dialog work and qualify prepared queries Oct 15, 2026
@morajabi

Copy link
Copy Markdown
Contributor Author

Landed on main through the rebase merge of #124, which contained all five commits of this branch (now 6c12232, f98d034, 7095cfd, dc40a07, ff9fc5b).

@morajabi morajabi closed this Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant