Repository navigation
fix(database): split punctuation-joined tokens in PostgreSQL keyword search like SQLite FTS5 - #183547
Conversation
|
🦞👀 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 changesAligns PostgreSQL punctuation tokenization across stored indexes, queries, and snippets, with an upgrade for existing agent stores. Example: Search for server in a PostgreSQL memory note containing server.py.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR repairs a concrete PostgreSQL search defect still present on current main; the reviewed head has no actionable findings and passed exact-head CI. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory and transcript owners declare text indexes to the shared database engine, which maintains PostgreSQL search vectors and returns matches, scores, and bounded snippets. flowchart LR
A[Memory and transcripts] --> B[Shared search owner]
C[Literal query] --> B
B --> D[PostgreSQL text indexes]
E[Doctor migration] --> D
D --> F[Matches and original text snippets]
Technical reviewBest possible solution: Land the shared tokenization repair with its existing-index migration and preserved historical backup definitions. Do we have a high-confidence way to reproduce the issue? The linked report supplies synthetic CLI inputs and missing results, and current-main source confirms the index/query token mismatch; this read-only review ran no target code. Is this the best way to solve the issue? The smallest complete repair aligns indexing, query parsing, and snippet selection in the existing search owner, then recomputes existing derived vectors through the established migration owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against fbef7079fc72. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +180, Tests +7, Docs +30, Config 0, Other +1. Total +218 across 37 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (8 earlier review cycles)
Reviewed October 27, 2026, 6:45 PM ET / 22:45 UTC (Revision 9). |
|
Addressed the review on head
PR body updated with the above. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Addressed the remaining P2 on head
Body Evidence updated. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…search like SQLite FTS5 (openclaw#183547) * fix(database): split punctuation-joined PostgreSQL full-text tokens like SQLite FTS5 (openclaw#183439) PostgreSQL's text search parser keeps dates, paths, file names and a/b pairs as single lexemes ('-08', 'server.py', '/v1/models', 'input/output'), so memory and transcript keyword search missed words that SQLite FTS5 unicode61 matches. On a real 44,740-chunk memory index the reporter measured hybrid top-1 relevance dropping from 15/40 on SQLite to 7/40 on PostgreSQL. Text search version 2 replaces punctuation runs with spaces before to_tsvector and before the query parser, for the stored vector and every tsquery path. PostgreSQL 16 cannot replace a generated column's expression in place and dropping the column would move it out of the sealed catalog position, so the version 2 vector is maintained by a <table>_search_sync trigger with a backfill UPDATE that is a no-op on fresh tables and indexes rows a port copied earlier. The agent schema migration carries the cutover through the existing versioned PostgreSQL migration: it drops the generated expression in place, installs the trigger and reparses existing rows once for the transcript index and every persisted search extension. SQLite advances version metadata only. Historical admission and backup descriptors keep the generated column. * fix(database): locate PostgreSQL snippets with the split query tokenization Text search version 2 splits punctuation-joined words in the stored vector and the query, but ts_headline still parsed the original field, where server.py is one lexeme. A query for server.py became 'server' & 'py', found no match in the headline parser and returned the opening words instead of the matching passage. On version 2 stores the headline now parses the field with each punctuation character replaced by one space. That keeps character offsets, so the selected fragment is sliced back out of the original field and keeps its punctuation. Version 1 stores keep the previous headline. * test(database): share PostgreSQL store fixture lifecycle * test(database): declare context-free fixture methods --------- Co-authored-by: Peter Steinberger <[email protected]>
Absorbs openclaw/openclaw main at 8ea3ef8 (369 commits past U8 7fdf69f) into the j8 candidate 8183790. 16 textual conflicts, resolved upstream-first. Generated files were regenerated (gateway:validators:gen, config:docs:gen, db:postgres:gen), never hand-merged. Agent schema collision: upstream openclaw#183547 took agent schema 38 (PostgreSQL text search splits punctuation-joined tokens; SQLite metadata-only). Upstream keeps 38 byte-for-byte; continuation's recipient-authority step is renumbered 38 -> 39 on top of it (OPENCLAW_AGENT_SCHEMA_VERSION, package.json schemaVersions, the authority constant, migration registry, port descriptor pin, backup scopes, witness versions, schema history, regenerated catalogs). On SQLite the authority step stays idempotent, so the j8 candidate's schema-38 databases (upstream 38 plus the table) keep their rows. PostgreSQL admission of the j8 candidate's 38 follows separately. Refs karmaterminal/openclaw-bootstrap#1727
…t step 39 Jump 9 renumbered continuation's recipient-authority step 38 -> 39 on top of upstream openclaw#183547's 38 (PostgreSQL text search splits punctuation-joined tokens). A PostgreSQL agent store written by the j8 candidate also reads 38 but is upstream's 37 plus the authority table, without the text-search split. Step 39's declared predecessor is upstream's 38, so the migration refused it as schema drift. A PostgreSQL migration step may now list alternate exact predecessors recorded at version - 1, each with the SQL that converges it to the step's schema. The engine verifies the declared source first, then each alternate; a failed check writes nothing (the definition check runs under a savepoint), and with no match the declared source's refusal stands unchanged. Step 39 lists the j8 shape: it keeps the authority table and rows and runs only upstream's text-search conversion. Detection is by exact catalog, not version. Accepted edge, documented: Doctor's pre-migration PostgreSQL export loads the version-38 port descriptor (upstream's shape), so a j8 PostgreSQL store is refused at backup before any write; the fleet's agent stores are SQLite. The earlier 35/36 candidates stay refused. Fixtures (pinned pgvector pg16@sha256:7b822b0a...b90a, private port): - jump-8 store with an authority row and transcript search -> 39: rows kept, openclaw_search no longer generated, 'server.py' reparsed to 'py'/'server', catalog == fresh 39, reopen DDL-free; - upstream 35/36/37/38 -> 39 in place, reopen DDL-free; - 34 -> 39 chain; mixed 38 (split + table) refused byte-unchanged. RED at e5c7bb0 (no alternate): the jump-8 case refused with "PostgreSQL schema drift detected against generated DDL" (1/9). GREEN: 9/9; with agent-port, text-search, agent-db and doctor-migration PostgreSQL suites 53/53. Refs karmaterminal/openclaw-bootstrap#1727
Closes #183439
What Problem This Solves
Fixes missing PostgreSQL memory and transcript matches when a query word appears inside a date, path, filename, or slash-separated pair such as
2026-08-18,/v1/models,server.py, orinput/output.User Impact
PostgreSQL keyword search finds the words SQLite FTS5 already finds. Long transcript snippets show the matching passage and retain its punctuation. Ranking policy and canonical memory/transcript content are unchanged; Unicode normalization and engine-local scores can still differ.
Agent schema 38 reparses existing PostgreSQL text indexes once, including persisted memory search extensions. SQLite advances schema metadata only. Operators should retain the matching pre-upgrade backup for rollback; the first PostgreSQL migration includes a one-time index backfill.
Why This Change Was Made
The shared PostgreSQL search owner applies the same punctuation split to indexed text and query terms. A trigger maintains the stored vector because PostgreSQL 16 cannot replace a generated expression in place, and dropping/re-adding the column would break the sealed catalog's column positions. The migration preserves those positions and GIN indexes, while historical definitions remain available for old-store backup and restore. Snippets locate the passage in position-preserving normalized text and return the corresponding original text.
Integrated main at
dc960f50ad6e; main still uses agent schema 37, so this migration remains 38. Production delta is +204/-24 lines (net +180) for version propagation, the migration, and historical backup/port compatibility. Shared test-fixture cleanup keeps the test/support delta to +460/-453 (net +7), without raising the test-line ceiling. Docs are +37/-7; metadata/tooling +2/-1.Thanks to @lonexreb for the implementation and @etzelm for the report and independent real-index validation. Contributor commits are preserved.
Evidence
Current integration proof used a disposable local PostgreSQL 17/pgvector container, synthetic data, and the production store/search owners. No operator state or database was used.
364c0d4ebcd4at08 18: expected [] to deeply equal [{id: 'deploy'}](8.68s Vitest, 70.49s total). On the integrated head, 21/21 tests in five files passed (45.07s Vitest, 108.04s total): the same regression, populated 37→38 migration and reopen, schema-35 memory-path upgrade through current, historical backup descriptors, and the real session-search owner returning the late punctuation-preserving snippet.git diff --checkpassed. Independent P0–P2 review: scoped-clean, no actionable findings on the complete integrated diff.The following broader CLI, Gateway, stable-upgrade and hybrid proof was previously recorded on the unchanged implementation before this main integration; it was not rerun during this pass:
serveron SQLite, then returned no results after a realdatabase port --family agent --to postgres. The regression also failed on exact initial CI base7c4bc0162dcat08 18: expected [] to deeply equal [{id:'deploy'}](34.80s Vitest; 252.11s including cold setup).08,18,server,py,models,input, andoutputtokens. All four search-column positions were preserved. Six independent CLI searches (08 18,server,models,input output,server.py,Release) passed in 130.70s; reopen retained the schema version and catalog seal.sessions.searchreturned the latefix to server.py landedpassage with punctuation (13.62s). A verified schema-37 archive restored in 7.52s, upgraded in 43.44s, and passed search plus an independent reopen with an unchanged admitted extension set and seal.2026.10.8SQLite seed upgraded agent 25→38/state 20→35 in 49.77s. Both integrity checks passed, both memory chunks remained, and two opens retained identical schema metadata and recovery-file inventories. Stable predates PostgreSQL port support; the upgraded store then passed the current CLI port to PostgreSQL (19.26s) and keyword search.nomic-embed-textrebuilt 768-dimensional vectors and returnedserver.pywith text score 0.97348 and vector score 0.63478. Final rebuild/query took 44.74s/73.52s, with the same model digest before, between, and after. An earlier attempt encountered a shared Ollama outage (connection reset/refused and transient provider-identity mismatch); no service restart, model unload, suppression, or metadata edit was used.DROP DATABASEcleanup statements timed out during a 243s container checkpoint. Only those cases were replayed after checkpoint completion, with unchanged limits: 2/2 passed (5.62s test file, 104.13s with setup). The nine-file unit/tooling batch passed 240/240 in 570.02s. The original PostgreSQL batch took 1300.47s, including the 20-case historical rollback matrix (497.27s).Initial CI run 40448958449 was investigated against its exact base. Four failures have independent main repairs now included: QA ACK #185840, Google Chat authority #185972, Copilot ordering #185612, and iMessage lookup #185409. The Feishu lifecycle failure did not reproduce on the exact base (8/8); its unchanged shared-state/KV path does not use this agent PostgreSQL search migration. This is an intermittent/unresolved initial failure, not a claimed fix. Final exact-head CI is recorded below.
Limitations: this integration used PostgreSQL 17; the earlier CLI proof used 17.11; PostgreSQL 16 compatibility is supported by the
DROP EXPRESSIONcontract and the contributor's earlier PG16 run, rather than a fresh PG16 run here. The published stable's indexing command needed bounded cleanup interruption while seeding; cold integrity checks passed before upgrade.Fresh CLI/Gateway/live-model proof was not repeated for this integration: the production-boundary PostgreSQL regression, upgrade, reopen and snippet tests were rerun, while the broader prior-head evidence above is retained explicitly.
An earlier integrated-head CI run, 40589855961, exposed eight inherited memory fixture failures in
checks-node-changed-extensions-bundle-24/-27. All eight reproduced on unchanged main25c300f73654. Upstream repairb954f6cef456makes embedding-failure fixtures change their input instead of expecting unchanged chunks to be embedded again; it is included by the final main integration. The PostgreSQL production owners and migration are unchanged from the earlier successful database proof. Fresh independent P0–P2 review after this integration is clean.After the final main integration, all 16 tests across the three affected memory suites passed (163.09s total). The eight previously failing cases are green. The earlier 21-test real-PostgreSQL proof remains applicable because the integration does not change those production owners.
Final exact-head validation: CI run 40593236753 passed on
26a81af6cb1dcfab3875a5df36ec45795080e08d: 159 jobs passed, 24 skipped, no failures or cancellations. All three PostgreSQL conformance shards, all three repaired memory-test bundles, andopenclaw/ci-gatepassed. ClawSweeper's review of the same head is complete with no findings or Before merge items.