Repository navigation
feat(database): shared-state port and backup on PostgreSQL - #173676
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: blocked before merge. What this changesThis PR registers shared state for PostgreSQL port and backup operations through the existing database-family registry. Example: Port a schema-24 shared-state database containing audit sequence 9007199254740993 to PostgreSQL.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 3 items remain Keep this PR open: it adds useful maintainer-directed PostgreSQL support, but external-store discovery introduces a recovery defect. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe offline database owner discovers registered stores, captures originals, copies and verifies canonical rows, admits destinations, and publishes their files before switching configuration. flowchart TD
A[Database port CLI] --> B[Offline state owner]
B --> C[Family provider registry]
C --> D[Shared state descriptor]
D --> E[Verified copy and admission]
E --> F[SQLite or PostgreSQL destination]
B --> G[Recovery manifest]
Technical reviewBest possible solution: Make the existing port owner recover every admitted target safely and complete shared-state recovery compatibility validation. Do we have a high-confidence way to reproduce the issue? Source establishes the failure: configure Voice Call storage outside the selected state directory, interrupt a port after its manifest is recorded, and loadRecovery rejects either recovery action; no target code was executed. Is this the best way to solve the issue? Reusing the family registry and canonical copy owner is appropriate, but discovery must stay consistent with recovery target validation. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4e90d155d8ab. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +14526, Tests +281, Docs +10, Other +87. Total +14904 across 23 files. Added test files: 2. View PR surface stats
Review metrics
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 15, 2026, 11:16 PM ET / October 16, 2026, 03:16 UTC. |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c643ed5dee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| path.resolve( | ||
| store.trim().replace(/^~(?=$|[\\/])/, () => context.env.HOME?.trim() || os.homedir()), | ||
| ), |
There was a problem hiding this comment.
Keep external state roots recoverable
When plugins.entries.voice-call.config.store resolves outside stateDir, which this code explicitly supports, an interrupted port cannot be resumed or rolled back: loadRecovery() in src/commands/doctor-database-port.ts rejects every captured target whose original path does not start with stateDir, while the active manifest continues blocking startup. Either allow these recorded external targets during recovery validation or exclude them from the port operation.
AGENTS.md reference: AGENTS.md:L50-L53
Useful? React with 👍 / 👎.
| `openclaw database port` as the migration path. The port command handles | ||
| current-schema shared state, Workboard, Logbook, and Team Reports. Upgrade older | ||
| shared state with `openclaw doctor --fix` using a compatible binary before porting. |
There was a problem hiding this comment.
Update the port inventory consistently
This now says the command handles shared state, but the same “Port existing stores” section at lines 184–197 still says only Workboard, Logbook, and Team Reports are registered and that the command does not port shared state. That contradiction leaves operators unable to tell whether the newly documented workflow is supported; update the registry and inventory paragraphs with this behavior change.
AGENTS.md reference: AGENTS.md:L127-L129
Useful? React with 👍 / 👎.
c643ed5 to
5768aa0
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5768aa0cee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try { | ||
| return await run(); | ||
| } finally { |
There was a problem hiding this comment.
Make the post-config state receipt crash-recoverable
If the process terminates after writeConfigFile publishes the config and writes config.lastTouchedAt or audit rows into the newly published shared-state store, but before this finally records its receipt, recovery has only the pre-write staged verification. A subsequent --resume treats the target anchor as fresh and compares the live rows against that stale proof, so it refuses and leaves startup blocked; the receipt must be persisted at the point of effect or recovery must safely recognize and re-verify this committed target state.
AGENTS.md reference: AGENTS.md:L7-L7
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f08ba661a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| path.resolve( | ||
| store.trim().replace(/^~(?=$|[\\/])/, () => context.env.HOME?.trim() || os.homedir()), | ||
| ), |
There was a problem hiding this comment.
Canonicalize configured state roots before matching
When an external Voice Call store path contains a symlink, this records only its lexical absolute path, while discoverBackupDatabasePaths() canonicalizes every existing database with fs.realpath() before preflight() compares it against these roots. The configured store is therefore excluded: SQLite-to-PostgreSQL can complete the global config switch while leaving that store on SQLite, and an existing PostgreSQL anchor instead fails as “unclassified.” Canonicalize the configured roots before matching them to the discovered inventory.
Useful? React with 👍 / 👎.
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
R4 (#173462) installed each worker task's engine selection as immutable process state. R13 (#173676) reuses those workers across offline database port transitions, so reverse-port lease inspection failed with OWNER_UNAVAILABLE before its handler could run. Scope the incoming engine selection around task execution and serialized resource cleanup. Preserve immutable Gateway boot selection and clear absent task selections. Extend the existing prewarmed-worker regression across SQLite, PostgreSQL, and return-to-boot selection in both transports. Validation: PostgreSQL conformance fallback 526 passed; worker/context checks 95 passed; core and affected test types, scoped lint, formatting, and independent review passed. Testbox capacity queued; pgvector-dependent coverage remains unverified on the Homebrew PostgreSQL 17 fallback.
…173676) * feat(database): add shared-state port and backup provider * refactor(database): reuse shared-state schema owners for port metadata * fix(database): preserve state recovery identities and restore receipts * fix(database): retain shared-state custody across port publication * fix(database): preserve recovery revisions after failed publication
R4 (openclaw#173462) installed each worker task's engine selection as immutable process state. R13 (openclaw#173676) reuses those workers across offline database port transitions, so reverse-port lease inspection failed with OWNER_UNAVAILABLE before its handler could run. Scope the incoming engine selection around task execution and serialized resource cleanup. Preserve immutable Gateway boot selection and clear absent task selections. Extend the existing prewarmed-worker regression across SQLite, PostgreSQL, and return-to-boot selection in both transports. Validation: PostgreSQL conformance fallback 526 passed; worker/context checks 95 passed; core and affected test types, scoped lint, formatting, and independent review passed. Testbox capacity queued; pgvector-dependent coverage remains unverified on the Homebrew PostgreSQL 17 fallback.
What Problem This Solves
Registers shared state with R12's existing database port and matched-backup provider. Existing
state/openclaw.sqlitestores can move between SQLite and PostgreSQL through the same family owner used for backups and restores.User Impact
Discovery covers the selected state root, retained Voice Call roots, and explicitly configured stores even when the plugin is disabled or removed. Matrix account/token roots remain excluded for R18. Exact captures retain secrets and transient rows; user backups use the existing sanitizer. Restores use normal owner admission, including PostgreSQL catalog drift checks. Older SQLite schemas must run Doctor with a compatible binary before porting. No canonical schema or schema-version change.
R14a (#173683) is integrated. The port holds exclusive offline maintenance custody throughout publication. It materializes initially absent shared state before capture, retires source actors before replacement, and selects the target for config publication effects after publishing stores. Recovery follows the physical shared anchor when config and files reflect an interrupted transition. Boot selection remains immutable; pooled readers scope selection to each request. PostgreSQL admission accepts an absent redundant content-version row when current schema metadata already declares the version, matching valid SQLite stores; mismatched metadata still refuses.
The config writer's own metadata and audit writes occur after capture. Recovery records their canonical state in a recovery receipt in the existing private manifest artifacts while custody remains held. Original captures stay unchanged, and later recovery verifies against the recorded state. Rollback verifies canonical contents even when a SQLite WAL write leaves the main-file hash unchanged. Failed manifest writes no longer consume an in-memory revision before publication, so the config-failure receipt can be recorded and resumed. The publication/drift helpers now live in one sibling module to keep the command within its line cap. Command recovery suites dispatch the real port handler in-process under native-section control, while retaining real backup, snapshot, proxy and foreign-owner workers; repeated isolate startup no longer dominates full shared-state captures. An abrupt process death between a config side effect and its durable receipt, or an I/O failure after manifest rename but before directory synchronization, can still require guarded manual recovery; immutable original captures are retained and unrecognized contents are refused.
Why This Change Was Made
The descriptor contains port-specific copy order, identity allocation policy and DDL offsets. It references the bundled PostgreSQL runtime DDL/catalog, canonical SQLite schema and feature-schema owners; fragment dependencies come from runtime facts. Loading remains lazy through the R12 registry, once per operation.
state-port.jsonshrank from 457,460 bytes / 14,386 lines to 26,959 bytes / 1,905 lines (94.1% smaller). It contains no inline SQL or duplicate column/constraint facts. The generator enforces a 60 KB ceiling. All 134 canonical tables and optional fragments remain covered, including absent Doctor-owned deletion history, keyless duplicate/null rows, UTF-8/blob bytes and allocator high-watermarks.Evidence
pnpm db:postgres:genandpnpm db:postgres:check: passed after rebase and again on final head, including generator tests; regeneration produced no changes.The local max-lines failure on untouched
ui/src/pages/chat/components/chat-message.test.tsxis inherited: the same check fails on rebased main415b542893a3c5606f471ac3d1ecd7ac35120881, and the source, baseline and guard are byte-identical. Knip passes on this rebased branch; the older loading-skeleton finding disappeared when its removal on main was integrated.Doctor schema-migration end-to-end proof remains a follow-up. The Doctor migration backup/recovery runner and native repair entry still explicitly reject PostgreSQL; a truthful success proof needs production integration beyond a 40-line test. Data-only Doctor custody is covered here.
Related: #172677. Parallel append-only generator work in #173617 remains open; whichever lane lands second must integrate and regenerate, keeping both registrations.
The full change is +459 net handwritten production lines, +575 test lines, +1,924 generated lines, and +8 documentation lines against the rebased main. The descriptor removes duplicate schema ownership; the remaining production growth covers provider loading/discovery and custody across publication/recovery. Independent review identified the config-effect receipt and WAL-drift cases; both were fixed and covered through command recovery tests. CI also caught a missing SAFETY annotation on the already-explained private receipt cast; its comment was corrected.
CI
Final run 38860699217, head
9f08ba661af96288fe46ff87c3e77f10088d4d2e:agent.visitor-access.test.tsretains[email protected]in the remote access-policy email list. Inherited: latest scheduled main run 38856273519, job 116828581734, fails the identical case and assertion atagent.visitor-access.test-utils.ts:456, retaining the same expired email. The classifier missed it because the main job is namedchecks-node-compact-large-27.The PostgreSQL, generator, updater, inventory and typecheck requirements are green. Overall CI remains red solely for the inherited Visitor failure; landing uses the operator-authorized native admin exception.
Causal path: the failing assertion follows Visitor plugin startup →
VisitorAccessService.sweep()→ Cloudflare policy update. It does not invoke the state-port descriptor, port commands, database backups, or updater inventory. Shared SQLite state-reader infrastructure is exercised, including R13-touched request-scoped engine selection; the identical current-main failure independently establishes baseline attribution. Main evidence: https://github.com/openclaw/openclaw/actions/runs/38856273519/job/116828581734. PR evidence: https://github.com/openclaw/openclaw/actions/runs/38860699217/job/116842627256.Initial run 38855894511 on the preceding head failed PostgreSQL because repeated one-shot worker startup exceeded existing command test timeouts and polluted later fixtures. The real-handler test harness removes that startup cost without changing SQL or timeout budgets. The corrected run also proves recovery after a failed manifest publication without consuming an unpublished revision. Its separate assertion-safety annotation failure is fixed.
The inherited UI max-lines warning was reproduced on rebased main with identical source/baseline/guard files. Knip is green after integrating main's removal of the former loading-skeleton issue. Matrix roots remain R18; the Doctor PostgreSQL schema-migration end-to-end proof remains the follow-up described above.