Skip to content

improve(database): avoid repeated PostgreSQL search snippet work - #190309

Merged
roboclaw-bot merged 1 commit into
mainfrom
loop/contributor-pr-188951
Nov 1, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
loop/contributor-pr-188951

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Supersedes #188951, thanks @etzelm.

What Problem This Solves

PostgreSQL version 2 text searches spend database CPU computing the same headline twice for each snippet.

User Impact

Search returns the same results and punctuation-preserving snippets with one headline evaluation per SQL result row. No configuration, schema migration, or operator action is required.

Why This Change Was Made

The shared PostgreSQL snippet owner now reuses normalized text and its headline through scalar subqueries. Two OFFSET 0 fences prevent PostgreSQL from expanding those expressions at each reference. Existing candidate limits and ranking stay in their owners.

Production delta is +3/-3 (net 0): the duplicated headline expression disappears. The existing migration test gains 21 lines to pin the returned snippet and inspect the real PostgreSQL plan; its separate allocation covers exactly that regression growth. Simplification reuses the existing fixture without another helper or test setup.

Evidence

  • Acceptance: preserve the result ID and exact snippet bytes, with one headline and one punctuation-normalization expression in the PostgreSQL plan.
  • Base 5342923d897ad8a8021bdf586753f8cd38cd3094 plus the regression: expected result and snippet pass; the headline-count assertion fails (four plan occurrences across the Limit/scan outputs; the expression itself contains two evaluations).
  • Replacement: 15/15 tests pass across PostgreSQL text migration, engine search conformance, and session-search product flow. This includes ranking, filtering, bounds, literal/prefix matching, and a late punctuation-joined match. Test runtime: 18.90 seconds total; runner including fixture compilation: 53.56 seconds. The changed migration test takes 172 ms.
  • Real PostgreSQL in a task-owned rootless Podman container capped at 4 CPUs and 8 GiB. No production database or Gateway state was used. The contributor head was read with gh pr view/diff and was never checked out or executed.
  • Scoped formatting, lint, typecheck (the two changed TypeScript files and their dependencies), and git diff --check pass. Broad validation runs in PR CI.
  • Independent autoreview (P0–P2) completed scoped-clean, with no actionable findings.
  • Exact-head CI passed, including all three PostgreSQL conformance shards. Full shard job times were 1,230 / 1,283 / 1,326 seconds, including setup and the broader suite; these are not the incremental cost of this regression.
  • Hosted ClawSweeper review found no actionable correctness or security defects on the same head.

This establishes reduced expression evaluation, not an end-to-end latency claim. The PostgreSQL product harness exercises search through the tool and Gateway handler; no live model/Gateway deployment was run on the production host.

Compute normalization and the headline once while preserving snippet text.
Pin the migrated search result and PostgreSQL execution-plan expressions.

Co-authored-by: Mitchell Etzel <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 1, 2026 12:15
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

Credited replacement for #188951. Independent local autoreview completed clean; focused real-PostgreSQL regression and product checks pass. Current proof and limitations are in the PR description.

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) November 1, 2026 12:19
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR computes punctuation normalization and the PostgreSQL headline once per version 2 search snippet.

Example: Search for server.py in the deployment-note fixture with a six-token snippet.

  • Before: Returns "server.py landed; the API serves" using two embedded headline evaluations.
  • After: Returns the same snippet using one headline evaluation.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, worthwhile optimization with reusable production evidence, fresh PostgreSQL boundary checks, and no identified defects.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The linked predecessor records real PostgreSQL and Gateway measurements for the same fenced snippet computation, with exact output comparisons; this replacement additionally reports passing real-PostgreSQL migration, conformance, and tool-to-handler product checks on its revised SQL aliases. These support reduced expression work, without establishing a reliable end-to-end latency improvement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: PostgreSQL search spends avoidable database CPU constructing each returned snippet.
Reason: The maintainer-authored change removes repeated work at its existing owner with no new setting, state, or public contract, and preserves the original punctuation behavior.

Merge readiness

✅ Ready for maintainer review

This PR is a useful, focused optimization that current main still needs; no actionable correctness or security defects were found, and exact-head CI remains pending.

Priority: P2
Reviewed head: a3ed568a0a710be1b67795bf30bd45ee33946b2a

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared PostgreSQL search adapter turns admitted index fields and literal queries into SQL expressions; transcript search consumes its snippet expression after selecting bounded hits.

flowchart TD
A[Session search request] --> B[Scoped and ranked hits]
B --> C[Shared PostgreSQL search adapter]
C --> D[Normalize punctuation once]
D --> E[Compute headline once]
E --> F[Slice original text]
F --> G[Results with preserved punctuation]
Loading

Technical review

Best possible solution:

Retain the shared-owner optimization and its focused regression while preserving exact snippet bytes and existing search policy.

Do we have a high-confidence way to reproduce the issue?

Current-main source directly exposes the duplicated expression, and the supplied PostgreSQL regression reports failure on the base and success with the fix; this review executed no target code.

Is this the best way to solve the issue?

The smallest complete fix is to reuse normalization and headline results within the existing adapter; the linked predecessor's fence-removal mutation supports retaining both OFFSET 0 fences.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 72a691e5f732.

Provenance checked

  • Version 2 PostgreSQL snippet construction keeps the original intent (338c811: Find punctuation-joined matches using position-preserving normalized text, then display the corresponding original passage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit bf46379 adds src/infra/database-engine/postgres-search.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bf4637941b40; files: src/infra/database-engine/postgres-search.ts)
  • Shubhankar Tripathy: Raw commit 338c811 adds src/infra/database-engine/postgres-search.ts:155 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 338c8118a27b; files: src/infra/database-engine/postgres-search.ts)

PR surface

Source 0, Tests +21, Other +2. Total +23 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 21 0 +21
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 26 3 +23

Review metrics

Metric Value Why it matters
Production versus regression growth Production +3/-3; tests +21 The production change adds no net lines, and the regression reuses the existing PostgreSQL fixture to protect output equality and reduced expression work.

Root-cause cluster

Relationship: canonical
Canonical: #190309
Summary: This PR explicitly replaces the contributor's earlier implementation of the same snippet optimization.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add P2: This reduces avoidable PostgreSQL CPU during snippet construction without an established outage or incorrect search result.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This reduces avoidable PostgreSQL CPU during snippet construction without an established outage or incorrect search result.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 1, 2026, 7:20 AM ET / 12:20 UTC.

@roboclaw-bot
roboclaw-bot merged commit 7159dfd into main Nov 1, 2026
193 checks passed
@roboclaw-bot
roboclaw-bot deleted the loop/contributor-pr-188951 branch November 1, 2026 12:40
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
…90309)

Compute normalization and the headline once while preserving snippet text.
Pin the migrated search result and PostgreSQL execution-plan expressions.

Co-authored-by: Mitchell Etzel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant