Skip to content

fix: catch incompatible ownership before porting to SQLite - #202101

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/sqlite-port-ownership
Nov 20, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/sqlite-port-ownership

Conversation

@VACInc

@VACInc VACInc commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

A move from PostgreSQL to SQLite could copy and verify the database before telling the operator that installation ownership makes the destination config invalid. The command and dry run now report the incompatible setting before copying. The operator chooses when to turn off installation ownership.

What Problem This Solves

The late failure leaves an active recovery manifest, so the Gateway requires rollback before it can start again. The early refusal applies to both whole-installation and family ports.

Root Cause

The config schema requires every configurable family to use PostgreSQL when database.postgres.ownership is installation. The port changes the selected engine and leaves the ownership setting as configured. Previously, strict config validation caught the conflict at publication, after the staged SQLite store had been verified. The command now checks the destination in its existing engine selection preflight and the operator guide explains the prerequisite.

Real behavior proof

Ran the production database port CLI registration against a disposable PostgreSQL 18.7 server over a Unix socket. Seeded a shared-state store with a seven-byte blob and configured installation ownership.

  • On main, openclaw database port --to sqlite --dry-run reported Database port: preflight (postgres → sqlite); 1 database stores. The real command exited 1 at switch config with CONFIG_VALIDATION_FAILED. The active manifest was preparing with a verified target. The source config and PostgreSQL anchor remained active.
  • With the fix, openclaw database port --to sqlite and openclaw database port --family state --to sqlite each exited 1 with the ownership guidance. Both dry runs did the same. The config and anchor still selected PostgreSQL and the recovery directory was absent.
  • Using the fixed command, openclaw database port --rollback <manifest> completed for the interrupted baseline operation and archived its active manifest. The original PostgreSQL config and installation ownership remained intact.
  • With all writers stopped, set ownership to state-directory in the fresh fixture and reran openclaw database port --to sqlite. The command reported Database port: complete (sqlite); 1 database stores. The SQLite row matched the original blob and the operation archived its manifest.

Three timed dry runs after one warmup per build on the same host and workload took 35.33–45.61 s on main (median 44.65 s) and 11.64–19.38 s with the fix (median 14.56 s). These are source CLI invocations under shared host load. The before run inventories the source, while the after run refuses at config admission.

What was not tested

No live Gateway, paid model calls, or production-size port. The disposable fixture covered one shared-state store. The interrupted-port proof covered rollback. No resume, cross-host lock failover, or older-release upgrade was verified.

Verification

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations size: XS labels Nov 19, 2026
@VACInc
VACInc marked this pull request as ready for review November 19, 2026 22:35
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Reject PostgreSQL-to-SQLite ports with installation ownership before copying stores or creating recovery artifacts.

Example: Run openclaw database port --to sqlite with database.engine="postgres" and database.postgres.ownership="installation".

  • Before: The command copies and verifies stores, then fails config validation and leaves an active recovery manifest.
  • After: The command immediately explains the ownership prerequisite and leaves the config, stores, and recovery directory untouched.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair supported by scoped real CLI evidence and reported base-red/head-green regressions; broad PostgreSQL CI remains pending.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied production CLI evidence exercises the changed admission owner against disposable PostgreSQL 18.7, records early refusal without recovery artifacts, and verifies rollback and successful retry with retained data.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An incompatible reverse port performs expensive copying and leaves a recovery manifest that blocks Gateway startup before explaining the required ownership change.
Reason: The maintainer-authored change moves an existing rejection before side effects and gives a concrete recovery path without changing supported configurations.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a concrete late-validation failure with a focused preflight check; no introduced correctness or security defects were found.

Priority: P2
Reviewed head: 79452f476694028c0fe338156a7bf39a94d379ba

Before merge

None.

Findings

None.

Agent review details

How this fits together

The database port CLI passes destination and family selections to the existing port owner, which admits the operation before capturing stores, publishing engine changes, or managing recovery.

flowchart TD
  A[Database port CLI] --> B[Port selection admission]
  B --> C[Ownership guidance]
  B --> D[Offline state owner]
  D --> E[Capture and verify stores]
  E --> F[Publish stores and config]
  D --> G[Resume or rollback]
Loading

Technical review

Best possible solution:

Keep the ownership prerequisite in the existing port admission owner while preserving operator choice and interrupted-port rollback.

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

Current-main admission permits the incompatible destination, while switchConfig retains installation ownership and reaches the schema rejection after staging; the supplied CLI evidence reports that exact failure.

Is this the best way to solve the issue?

This is the smallest complete fix: enforce the existing destination invariant in assertPortSelection, retain the established recovery owner, and cover ordinary and scoped dry-run admission without new machinery.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Port selection admission keeps the original intent (8a2935f: Family-scoped ports centralize mixed-engine selection checks and change only the selected family's engine.)
  • Installation ownership restriction keeps the original intent (c886f82: Opt-in PostgreSQL installation ownership requires all configurable families to use PostgreSQL while preserving the default local ownership mode.)
  • Reverse-port operator guidance keeps the original intent (1e78ee6: Provide source-backed PostgreSQL migration and recovery instructions, including a new reverse port that retains current data.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 8a2935f adds src/commands/doctor-database-port-context.ts:40 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8a2935fbfe45; files: src/commands/doctor-database-port-context.ts)

PR surface

Source +5, Tests +15, Docs +6. Total +26 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 5 0 +5
Tests 1 16 1 +15
Docs 1 7 1 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 28 2 +26

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: A specific advanced database migration configuration fails late and requires rollback before restarting; the source data remains intact.
  • 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 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A specific advanced database migration configuration fails late and requires rollback before restarting; the source data remains intact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • 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 19, 2026, 5:52 PM ET / 22:52 UTC.

@VACInc
VACInc merged commit 835d722 into openclaw:main Nov 20, 2026
219 checks passed
@VACInc

VACInc commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Merged via squash.

@VACInc
VACInc deleted the fix/sqlite-port-ownership branch November 20, 2026 17:43
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…law#194384)

* docs: clarify PostgreSQL conformance coverage

* fix(cron): keep one-shot finalization working on PostgreSQL 16

* test(database): reuse cron conformance for JSON conversion regression

* test(postgres): accept fractional explain row counts

(cherry picked from commit 7ab0143)

Release adaptation: Only engine-owned jsonValue and retained cron enabled JSON replacement; preserve native boolean type with PG16 explicit ::json and SQLite json(). Omit unrelated PG docs/EXPLAIN test edits; retained one-shot enabled-transition caller present on baseline.

Follow-up dispositions: e029e18 docs: document isolated PostgreSQL restore drills (openclaw#202704); 49f0740 fix(database): report disabled memory after a port (openclaw#202630); a80b564 fix: keep database workers healthy after silent connection loss (openclaw#201856); 3d91af2 fix(config): reject reserved PostgreSQL schema prefixes (openclaw#202097); 835d722 fix: catch incompatible ownership before porting to SQLite (openclaw#202101); 67796a6 fix: keep scheduled Git backups current on PostgreSQL (openclaw#201870); cc849dd fix: recover lease heartbeats after a PostgreSQL connection loss (openclaw#201858); 6594caf fix: prepare macOS runtime pins without the PostgreSQL secret (openclaw#202102); 6ca56cd docs: clarify PostgreSQL storage and backup coverage (openclaw#202086); a079190 fix(postgres): chat history slows under concurrent reads (openclaw#190129); 2ff4256 feat(database): keep PostgreSQL rollback captures in PostgreSQL (openclaw#196236); 96c685b feat(backup): restore PostgreSQL stores into a staging database for restore drills (openclaw#194808); fb83d65 fix: reduce transcript allocation when preparing native context seeds; 71ec4d2 fix(config): keep Workboard PostgreSQL upgrades readable (openclaw#194648); b6ed907 perf(sessions): persist active transcript facts for hydration (openclaw#193682)

Validation: Baseline cron generated json(bound text) on PostgreSQL where json(text) is unavailable; helper and focused boolean regression retained. Exact PostgreSQL16 server proof unavailable; focused SQLite/helper tests queued. diff check passed.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 38fdd9b52704d588d9ca24ef8e391d644961c985)
(cherry picked from commit fb935e6912388314851b05cb698ef038b83bbd07)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant