Repository navigation
fix: finish database port --to postgres in minutes instead of hours over a network link - #201374
Conversation
…uery per row `openclaw database port --to postgres` rebuilt the transcript search rows with one awaited INSERT per message. Over a link with real latency that is one round trip per row, so a store with tens of thousands of messages kept the Gateway offline for hours. The port now sends up to 512 rows per statement, reusing the transcript owner's identity allocation so rows keep their message order and identities stay paired with their content. The compile-only PostgreSQL Kysely facade is exported so the asynchronous port connection can run the owner's query. Closes openclaw#201249 Related: openclaw#188397 Signed-off-by: Deepak Jain <[email protected]>
|
🦞👀 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 real behavior proof before merge. What this changesBatch transcript search writes during PostgreSQL ports using the transcript owner's existing identity-allocation query. Example: Port one session containing 1,100 searchable messages to PostgreSQL.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain This PR addresses a current PostgreSQL port performance defect with a focused change that preserves the existing identity-allocation contract; no concrete correctness defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe offline database-port worker copies canonical agent data, rebuilds derived transcript search rows on the destination connection, verifies the destination, and commits the port. flowchart TD
A[Database port CLI] --> B[Port worker transaction]
B --> C[Copy canonical agent tables]
C --> D[Prepare transcript projections]
D --> E[Shared FTS allocation query]
E --> F[PostgreSQL search tables]
F --> G[Verify and commit]
Technical reviewBest possible solution: Retain bounded PostgreSQL batching through the shared transcript allocation owner, with the existing port transaction and verification boundaries. Do we have a high-confidence way to reproduce the issue? Current-main source confirms one awaited write per FTS row, matching the official-release report; this read-only review did not execute a port. Is this the best way to solve the issue? Reusing the established allocation query is the smallest complete fix for serial FTS writes; eliminating transcript readback is a separate optimization. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3da0bc802e10. Provenance checked
TestingProof path: unit tests only. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +57, Tests +89. Total +146 across 4 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 November 18, 2026, 1:47 PM ET / 18:47 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
|
Inherited CI failure named for the record (landed at
|
…uery per row (openclaw#201374) `openclaw database port --to postgres` rebuilt the transcript search rows with one awaited INSERT per message. Over a link with real latency that is one round trip per row, so a store with tens of thousands of messages kept the Gateway offline for hours. The port now sends up to 512 rows per statement, reusing the transcript owner's identity allocation so rows keep their message order and identities stay paired with their content. The compile-only PostgreSQL Kysely facade is exported so the asynchronous port connection can run the owner's query. Closes openclaw#201249 Related: openclaw#188397 Signed-off-by: Deepak Jain <[email protected]>
…uery per row (#201374) `openclaw database port --to postgres` rebuilt the transcript search rows with one awaited INSERT per message. Over a link with real latency that is one round trip per row, so a store with tens of thousands of messages kept the Gateway offline for hours. The port now sends up to 512 rows per statement, reusing the transcript owner's identity allocation so rows keep their message order and identities stay paired with their content. The compile-only PostgreSQL Kysely facade is exported so the asynchronous port connection can run the owner's query. Closes #201249 Related: #188397 Signed-off-by: Deepak Jain <[email protected]> (cherry picked from commit bc4e269) Co-authored-by: RomneyDa <[email protected]>
…uery per row (openclaw#201374) `openclaw database port --to postgres` rebuilt the transcript search rows with one awaited INSERT per message. Over a link with real latency that is one round trip per row, so a store with tens of thousands of messages kept the Gateway offline for hours. The port now sends up to 512 rows per statement, reusing the transcript owner's identity allocation so rows keep their message order and identities stay paired with their content. The compile-only PostgreSQL Kysely facade is exported so the asynchronous port connection can run the owner's query. Closes openclaw#201249 Related: openclaw#188397 Signed-off-by: Deepak Jain <[email protected]> (cherry picked from commit bc4e269) Release adaptation: Preserve stable activeRows loop and metadata INSERT; replace only PG FTS loop and share allocator. Add retention assertions; runtime proof blocked. Co-authored-by: RomneyDa <[email protected]>
Closes #201249
Prior work: #188397 (merged) made the port copy navigation rows exactly instead of rebuilding them row by row. It left the search rows, which this PR batches.
What Problem This Solves
Moving an agent store to PostgreSQL with
openclaw database port --to postgresrebuilds the transcript search rows after the bulk copy, and it sent one INSERT per message. When the PostgreSQL server is not on the same network, each INSERT waits a full round trip, so the port time is set by latency, not by data size. The reporter measured about 21,000 search rows at roughly 92 ms per round trip, and the Gateway has to stay offline for the whole port.User Impact
User impact: operators porting a large agent store to a remote PostgreSQL server wait for a few dozen round trips instead of one per message, so the Gateway comes back much sooner. The ported rows are the same, in the same order.
Why This Change Was Made
The transcript owner already has a batched PostgreSQL write that allocates identities in message order and pairs each identity with its own content. The port was bypassing it with a hand-written per-row statement. It now builds the same statement for a batch of up to 512 rows and runs it over the port's connection, so there is one allocation contract instead of two. To make that possible, the compile-only PostgreSQL Kysely facade in
kysely-sync.tsis exported for asynchronous callers that run the compiled query themselves. Rows are collected from the source generator one batch at a time, so memory stays bounded.This does not change the other cost the issue mentions, reading each session's events back from the target before projecting. That is left for a separate change.
Evidence
Before the change, a 1,100-message session produced 1,100 search-row statements in the new regression test. After it, the same session produces 3 (512, 512 and 76 rows), the message IDs reach the database in transcript order, and each statement stays well under PostgreSQL's 65,535-parameter limit. The test fails on the old code and passes on the new code. For the reporter's 21,000 rows that is about 41 statements instead of 21,000; at 92 ms each that is a few seconds of waiting by arithmetic, not a measurement.
I ran the exact compiled statement against a real PostgreSQL engine (PGlite) with a 1,100-row, three-batch run that included null message IDs, roles and timestamps. Row IDs came out 1 through 1,100 in input order, each row's text, message ID, role and timestamp matched its input,
session_transcript_fts_rowsagreed withsession_transcript_fts, and the identity sequence ended at 1,100.Commands and what was not run
src/infra/database-engine/agent-port-projections.test.ts, two tests, run with vitest 5.0.5: pass on the change, fail on the oldagent-port-projections.ts(1,100 statements instead of 3). Wall time about 1 s including module import; this is not apnpm testmeasurement because a fullpnpm installwas not possible in the environment.oxfmt --checkon the four changed files,tscon the changed files with no errors reported in them, andgit diff --checkpass.session-transcript-projection-rebuildandquery-compilertests pass. Four unrelatedkysely-synctests fail only becausetsxis missing from the scratch dependency set.scripts/test-database-conformance.mjs --engine postgres) against a live server,pnpm tsgo,pnpm lint(oxlint did not discover files in this environment), a port over a real WAN link, and CI.