Repository navigation
Conversation
…ne per row - Version 2 text search snippets embedded the punctuation split three times and ts_headline twice per row (strpos and length each repeated the headline call). - The snippet is now a scalar subquery: split once, headline once. OFFSET 0 keeps PostgreSQL from inlining the subqueries back into each reference. - Output is unchanged; the test pins the snippet text and asserts one ts_headline and one split in the EXPLAIN VERBOSE plan.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR computes punctuation normalization and the PostgreSQL headline once per version 2 search snippet. Example: Search for server.py in the existing deployment-note fixture.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR provides a focused, useful PostgreSQL optimization that current main still needs; no actionable correctness or security defects were found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe shared PostgreSQL search adapter converts admitted index fields and literal queries into SQL expressions consumed by transcript search and other text-search callers. flowchart TD
A[Session search request] --> B[Scoped transcript search]
B --> C[Shared PostgreSQL search adapter]
C --> D[Normalize punctuation once]
D --> E[Compute headline once]
E --> F[Slice original text]
F --> G[Search results with snippets]
Technical reviewBest possible solution: Retain this shared-owner optimization and its focused regression while keeping the generic-plan repair separate. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows the duplicated headline expression, and the contributor reports a base-failing PostgreSQL plan regression; this review ran no target code. Is this the best way to solve the issue? The smallest complete fix is to reuse normalization and headline results inside the existing adapter while preserving original-text slicing; both OFFSET fences have a reported mutation check showing why they are necessary. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5ca51dcffd9c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +34. Total +34 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 30, 2026, 10:10 PM ET / October 31, 2026, 02:10 UTC. |
What Problem This Solves
PostgreSQL session and memory keyword search spends about half of its snippet time computing the same headline twice for every returned row.
User Impact
User impact:
sessions.search(and other PostgreSQL text-search snippets on version 2 indexes) builds each snippet with about half the database CPU, and the snippet text is unchanged.Why This Change Was Made
Version 2 snippets re-slice the headline from the original text so displayed punctuation survives. The expression repeated the punctuation split three times and
ts_headlinetwice per row, becausestrpos(...)andlength(...)each embedded the same headline call. The snippet is now a scalar subquery that splits once and headlines once.OFFSET 0keeps PostgreSQL from inlining the subqueries back into each reference; without it the plan still callsts_headlinetwice (checked by mutation, below). Version 1 snippets and SQLite are unchanged.Evidence
sessions.searchstatements for all 12 terms return identical result sets (md5) before and after.node scripts/test-database-conformance.mjs --engine postgres --connection <dsn> -- src/infra/database-engine/postgres-text-search-schema.postgres.test.ts src/infra/database-engine/session-search-product.postgres.test.ts src/infra/database-engine/postgres-search.conformance.test.tsexpected [ 'ts_headline(', 'ts_headline(' ] to have a length of 1 but got 2.OFFSET 0fences): fails the same way (2 headlines), because PostgreSQL pulls the subqueries up.oxfmtandoxlintare clean on both files.Gap: gateway-level search latency on the shared host (load average 12-100 during the runs) was too noisy to attribute a latency number to this change alone. In the one interleaved round where base and this change ran at similar load (12-16), search SQL per call in pg_stat_statements dropped from 21.6 to 15.5 ms (concurrency 1), 21.1 to 15.2 ms (concurrency 8) and 21.5 to 17.6 ms (read mix). Separately, the Gateway currently runs
sessions.searchon a generic plan that skips the text index (see the linked issue). That dominates end-to-end search time until it is fixed, and this change applies on top of either plan.