Repository navigation
fix(database): analyze PostgreSQL schemas after database port - #183447
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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR refreshes PostgreSQL planner statistics after database port, backup restore, and post-port memory rebuilding. Example: Port an agent store with 500 cache rows and rebuild one memory chunk.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-directed PR addresses both PostgreSQL statistics gaps still present on main, with no actionable correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe offline database workers consume verified private store images, materialize PostgreSQL namespaces, and return verified destinations for publication; the memory owner subsequently rebuilds agent indexes. flowchart TD
A[Database port command] --> B[Offline custody]
B --> C[Shared bulk-copy worker]
D[Backup restore] --> C
C --> E[Verify and commit data]
E --> F[Namespace statistics refresh]
F --> G[Publish stores and rebuild memory]
G --> H[Refresh statistics after memory closes]
Technical reviewBest possible solution: Keep statistics maintenance in one shared worker helper and refresh again after the existing memory owner closes. Do we have a high-confidence way to reproduce the issue? Current-main source confirms both missing refresh paths, and the linked report supplies immediate PostgreSQL catalog observations; this read-only review executed no target code. Is this the best way to solve the issue? The defect is missing statistics after bulk writes, the invariant is refreshed destination estimates before return, and the smallest complete repair uses the existing materializer and memory lifecycle with one bounded shared helper. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 40438e059d39. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +133, Tests +122, Docs +6. Total +261 across 14 files. Added test files: 1. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 25, 2026, 4:54 AM ET / 08:54 UTC. |
…aw#183447) openclaw database port --to postgres and backup restore into PostgreSQL handed back schemas without planner statistics, so first queries planned on default estimates. One shared helper now runs ANALYZE scoped to the destination namespace after the verified commit (and again after the memory rebuild); timeouts or errors are warnings and never undo verified data. Live PostgreSQL proof showed fresh statistics after port. Fixes openclaw#183307. Thanks @etzelm for the report and @lonexreb (openclaw#183327) and @goutamadwant (openclaw#183392) for the earlier fixes. Co-authored-by: lonexreb <[email protected]> Co-authored-by: goutamadwant <[email protected]>
Fixes #183307. Thanks @etzelm for the detailed reproduction and planner observations.
Related: #183327.
What Problem This Solves
Porting a store to PostgreSQL leaves copied data, and the later agent memory rebuild, without planner statistics until autovacuum catches up. PostgreSQL backup restore uses the same bulk-copy path and has the same gap.
User Impact
Newly ported and restored stores have statistics before returning to their caller. Agent ports refresh them again after the memory manager finishes and closes. Statistics refresh failures produce warnings while preserving the verified data; autovacuum can finish the optimization later.
Why This Change Was Made
The shared bulk-copy owner now runs namespace-scoped
ANALYZEafter canonical verification and commit, in a separate transaction. Catalog discovery includes the destination's derived tables, identifiers are quoted, and unrelated namespaces are untouched. A 10-second statement timeout and 1-second lock timeout bound the work. Port reports expose success/table counts or a warning, including the post-rebuild result. PostgreSQL backup restore automatically uses the same helper through the materializer.The existing worker owns SQL and the post-port offline owner retains custody through the memory refresh. No configuration, CLI options, dependencies, schemas, data verification, or steady-state autovacuum policy change. Simplification review retained one statistics helper for all bulk-copy callers; no parallel restore implementation was introduced.
Evidence
reltuples = -1instead of1with autovacuum disabled. After the fix, the state-port test checks statistics immediately after port and after both exact and sanitized restore.doctorDatabasePort({ family: 'agent', to: 'postgres' })ported 500 cache rows and ran the real bundled memory runtime, rebuilding one chunk in 22.7 seconds. Both phases reportedanalyzedfor 47 tables. Immediately afterward,pg_class.reltupleswas500forcache_entriesand1formemory_index_chunks;pg_stat_user_tables.last_analyzewas set for both.git diff --checkpasses. Fresh isolated Codex review found no actionable P0–P2 findings.Consumer validation ran all 34 runnable files selected by the owner-basename scan on Node 26.12.1 (the scan also matched a live-only subagent file through
report.workers; it has no changed-owner import and the normal runner excludes it). The initial run reported 808 passed tests, 9 failed, and 4 skipped across those 34 files. Two bounded follow-ups are now green, leaving only the storage-permission limitations below:agent-port.postgres.test.ts(one archive case),backup.test.ts,git-backup-secrets.postgres.test.ts(two cases),git-backup.postgres.test.ts(repository setup), andupdate-preflight.conformance.test.ts(baseline capture). The same ancestor is group-writable; no permission checks, baselines, or assertions were relaxed.The PostgreSQL commands were
OPENCLAW_VITEST_RUNTIME=node node scripts/test-database-conformance.mjs --engine postgres --connection <disposable-dsn> -- <selected test files> --maxWorkers=1. The final focused repair command selectedport-command.mixed.integration.test.tsandport-command-refusals.postgres.test.ts: 2 files and 6 tests passed, 377.6 seconds wall including 65.8 seconds of shared worker compilation.Existing slow consumer proof
The tooling pair passed 636 tests in 331.5 seconds (97% test time), dominated by its existing shell/Node fixture matrix. Whole-archive restore cases passed in 93.0, 42.8, and 48.7 seconds, including real store recovery and cold Gateway startup. Matrix account-root cases passed in 193.8, 174.8, and 69.8 seconds. The native port-command recovery cases range up to 114.4 seconds and deliberately exercise multiple full port/snapshot phases. Credential continuity cases reach 81.0 seconds; retained-agent update recovery took 81.1 seconds. These are existing broad compositions, not new planner-statistics work. The bounded mixed-suite worker-startup repair is described above; the dedicated one-shot custody proof remains intact.
Live-proof commands used isolated
HOME,OPENCLAW_STATE_DIR, andOPENCLAW_CONFIG_PATH. The Node integration harness ran vianode --import ./scripts/tsx.mjs .artifacts/port-live.mts; PostgreSQL was a disposable localpgvector/pgvector:pg17container, with the sameunaccent,pg_trgm, andvectorprerequisites as CI. No remote lease or operator Gateway was used.Limitations:
pnpm openclaw database port --family agent --to postgres --jsonstopped before executing the port because the source launcher could not verify offline runtime-artifact publication. The live owner integration above succeeded instead; no service was stopped or guard bypassed. Existing archive and snapshot tests reject the group-writable storage-volume ancestor; filesystem permissions were left unchanged. Fullcheck:changedSQLite inventory was skipped under the campaign's local gate budget; PR CI remains the broad proof.Diff: production +146/-13 lines; tests +125/-3; docs +6/-0. No release changelog edit.