Repository navigation
feat(database): per-family database engine selection - #173755
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 adds per-family database engine overrides and carries the boot-selected engines through plugin stores and workers. Example: A fresh installation sets database.engine to sqlite and database.families.workboard.engine to postgres.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep this maintainer-authored prototype open and unmerged as requested; review found an introduced dependency on PostgreSQL credentials for unrelated plugin commands. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherDatabase configuration enters the host selection owner, which resolves one shared PostgreSQL connection and distributes immutable family choices to database workers and plugin stores. flowchart TD
A[Database configuration] --> B[Host engine selection]
B --> C[Immutable family map]
C --> D[Shared state workers]
C --> E[Plugin store workers]
D --> F[SQLite or PostgreSQL]
E --> F
Technical reviewBest possible solution: Keep the prototype draft, prepare database credentials only for commands that consume database stores, and complete family-aware lifecycle support before production rollout. Do we have a high-confidence way to reproduce the issue? Source tracing shows that a fresh CLI process with database.engine=postgres and an unavailable database connection SecretRef rejects plugin registration before an unrelated browser command reaches its Gateway request; no target code was executed. Is this the best way to solve the issue? The immutable family map extends the existing owner coherently, but unconditional database preparation in the generic CLI loader broadens credential requirements beyond database consumers. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7bf56c8aa502. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +120, Tests +566, Docs +71, Generated 0, Other +2. Total +759 across 62 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 16, 2026, 12:06 AM ET / 04:06 UTC. |
847ac72 to
1619903
Compare
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: 1619903455
ℹ️ 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".
| export type { DatabaseEngineInput } from "./types.js"; | ||
|
|
||
| /** Resolve on the host; the existing broker input transport keeps credentials out of config/logs. */ | ||
| export async function resolveDatabaseEngineInput( | ||
| config: OpenClawConfig, | ||
| env: NodeJS.ProcessEnv = process.env, | ||
| ): Promise<DatabaseEngineInput> { | ||
| if (config.database?.engine !== "postgres") { | ||
| return undefined; | ||
| return (await resolveDatabaseEngineSelection(config, env)).postgres; |
There was a problem hiding this comment.
Preserve the public resolver's default-engine semantics
When database.engine is "sqlite" but a built-in family such as state overrides to "postgres", this retained public SDK helper now returns the PostgreSQL connection. Third-party engine-aware plugins are still documented to call resolveDatabaseEngineInput(config) and cannot specify one of the new built-in family IDs, so an existing plugin store may fail admission as an unported SQLite-to-PostgreSQL switch—or a fresh store may be created in PostgreSQL—even though the operator only selected PostgreSQL for shared state. Keep this resolver tied to the default engine for compatibility while bundled family-aware stores use getDatabaseEngineInput(family).
AGENTS.md reference: AGENTS.md:L57-L57
Useful? React with 👍 / 👎.
898e2ba to
c375285
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c375285916
ℹ️ 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".
| const engines = new Set( | ||
| stores.filter((store) => store.postgres).map((store) => selectDatabaseEngine(store, config)), | ||
| ); | ||
| if (engines.size > 1) { |
There was a problem hiding this comment.
Route homogeneous overrides through lifecycle connections
When database.engine is sqlite and all four PostgreSQL-capable families explicitly override to postgres, this set has size 1 and admits backup/restore. Those paths later call withDatabasePortConnection in port-provider.ts, which deliberately uses the public default-engine resolver; it therefore receives undefined and fails every anchored PostgreSQL store with PostgreSQL requires database.engine=postgres. Either reject effective/default divergence until family-scoped lifecycle support exists or make these lifecycle paths resolve the anchored family’s connection.
AGENTS.md reference: AGENTS.md:L52-L53
Useful? React with 👍 / 👎.
| // A capable target cannot strand a PostgreSQL store. Avoid copying live databases | ||
| // to rediscover their engines at every candidate inspection and activation boundary. | ||
| if (Array.isArray(targetEngines) && targetEngines.includes("postgres")) { | ||
| if (supportsPostgres) { | ||
| return; |
There was a problem hiding this comment.
Require a family-selection capability from update targets
For a homogeneous configuration whose family overrides invert the default—for example, default SQLite with every capable family on PostgreSQL—any pre-family target still advertises databaseEngines: ["sqlite", "postgres"], so this early return accepts an explicit --tag downgrade even though that target cannot interpret the overrides and will select SQLite from the default (or reject the new config only after mutation). Add a target capability/protocol marker for family selection and refuse such targets before activation.
AGENTS.md reference: AGENTS.md:L81-L82
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6990f094bb
ℹ️ 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".
| }, | ||
| input, | ||
| ), | ||
| const selectedDatabase = getDatabaseEngineInput("workboard"); |
There was a problem hiding this comment.
Install family selection before standalone agent plugin loads
When a standalone agent command loads an enabled Workboard plugin, runLocalAgentCommand reaches withAgentPluginRegistry without any call to installDatabaseEngineSelection (src/agents/agent-command-local.ts:92-96). This lookup therefore returns undefined even when database.families.workboard.engine selects PostgreSQL: an existing PostgreSQL anchor makes the agent command fail, while a fresh installation creates a SQLite store that the next Gateway boot refuses as an engine mismatch. Initialize the immutable selection for this direct-host entry point before loading its plugins.
AGENTS.md reference: AGENTS.md:L50-L53
Useful? React with 👍 / 👎.
| const { resolveDatabaseEngineSelection } = await import("../infra/database-engine/config.js"); | ||
| installDatabaseEngineSelection( | ||
| await resolveDatabaseEngineSelection(context.config, context.env), |
There was a problem hiding this comment.
Resolve only the CLI plugin's selected database family
For a supported mixed configuration such as PostgreSQL state with SQLite Workboard, invoking openclaw workboard ... enters this branch and resolves the entire family selection. If the state DSN is available only to the Gateway service—as is common for an env SecretRef—the Workboard CLI now fails on that unrelated credential even though its own store is SQLite and previously needed no PostgreSQL input. Prepare the selected plugin families without resolving credentials used exclusively by other families.
AGENTS.md reference: AGENTS.md:L51-L53
Useful? React with 👍 / 👎.
💡 Codex ReviewWhen a standalone agent command loads an enabled Workboard plugin, AGENTS.md reference: AGENTS.md:L50-L53 openclaw/src/plugins/cli-registry-loader.ts Lines 288 to 290 in 6990f09 For a supported mixed configuration such as PostgreSQL state with SQLite Workboard, invoking AGENTS.md reference: AGENTS.md:L51-L53 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Draft prototype only. Config approval and family-aware recovery remain pending.
6990f09 to
60a075d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60a075d69f
ℹ️ 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".
| return config.database?.engine === "postgres" | ||
| ? resolveDatabasePostgresInput(config, env) | ||
| : undefined; |
There was a problem hiding this comment.
Resolve restore admission using the owning family
When database.engine is sqlite but every configurable family explicitly overrides to postgres, the homogeneous-engine guard permits backup and restore and withDatabasePortConnection successfully restores the PostgreSQL namespace. However, preparePostgresRestoreInWorker still calls this now default-only resolver and passes undefined to descriptor.admit, so the family owner tries to admit the restored PostgreSQL anchor as SQLite and the restore fails. Resolve the input from manifest.source.owner and the effective family selection before admitting the restored anchor.
AGENTS.md reference: AGENTS.md:L50-L53
Useful? React with 👍 / 👎.
| !getDatabaseEngineSelection() && | ||
| listDatabaseEngineStores().some( | ||
| ({ id, postgres }) => postgres && (!onlyPluginIds || onlyPluginIds.includes(id)), | ||
| ) |
There was a problem hiding this comment.
Initialize family selection for diagnostic runtime loads
When Workboard is enabled with its family configured for PostgreSQL, selection is initialized only in this plugin CLI-command path; openclaw plugins inspect workboard --runtime and openclaw plugins doctor instead load the full runtime through withPluginDiagnosticsReportForInspection. Workboard registration eagerly opens its store, so getDatabaseEngineInput("workboard") returns undefined: a fresh diagnostic invocation can bootstrap SQLite, after which Gateway startup refuses the configured PostgreSQL engine, while an existing PostgreSQL anchor makes diagnostics fail. Prepare the immutable selection before these diagnostic full-runtime loads as well.
AGENTS.md reference: AGENTS.md:L50-L53
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2d56a0a154
ℹ️ 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".
| function familySetting(schema: StoreSchema): string { | ||
| return `database.families.${schema.id === "team_reports" ? "team-reports" : schema.id}.engine`; |
There was a problem hiding this comment.
Preserve default-engine guidance for external stores
When a third-party engine-aware plugin calls the public openEngineStore API with a schema ID such as acme, this helper produces database.families.acme.engine; however, the config schema accepts family overrides only for the five built-in IDs, and external stores still select PostgreSQL through database.engine. Every anchor or engine-mismatch refusal for such a plugin therefore directs the operator to an invalid configuration key. Use family-specific guidance only for registered built-in families and retain database.engine guidance for external schema IDs.
AGENTS.md reference: AGENTS.md:L57-L57
Useful? React with 👍 / 👎.
|
Merged via squash.
|
* feat(database): prototype per-family engine selection Draft prototype only. Config approval and family-aware recovery remain pending. * feat(database): guard mixed-engine lifecycle operations * test(database): carry family selection in maintenance fixtures * fix(database): preserve backup and plugin loading boundaries * fix(database): preserve default resolver and lazy CLI preparation * fix(database): close homogeneous lifecycle admission gaps * fix(database): integrate mixed selections with scoped workers * fix(database): decouple engine registry config types
What Problem This Solves
Peter approved the config shape on 2026-10-16:
database.engineremains the default; optionaldatabase.families.{state,agent,workboard,logbook,team-reports}.engineoverrides sharedatabase.postgres. Safety journals stay fixed local. No per-family DSN/prefix or per-agent settings.One context owner carries the full effective family map and resolved PostgreSQL input. Gateway boot installation is immutable and rejects conflicting reinstalls. Offline port work uses the existing task-scoped selection, including the complete family map, so retained workers can follow source/target transitions without rebinding the Gateway. State and plugin openers consume their selected families; agent/auth/inspection consumers now use the agent family. Doctor reports default, override, and effective selections without connection details.
Rebased onto current main with R4 agent routing, R13 state port/backup, Doctor PostgreSQL migration proof, and the worker-task scope repair. Homogeneous PostgreSQL includes agents. PostgreSQL agents combined with any SQLite configurable family refuse with
DATABASE_AGENT_MIXED_POSTGRES_UNSUPPORTEDuntil PR3 mixed-pair conformance; explicit SQLite agents remain valid. The minimal state-preflight hunk is retained; schemafp #173617 will rebase after PR1.Safety and remaining work
Mixed-engine database port, snapshot backup/restore, and update preflight refuse before mutation with an actionable single-engine/family-scoped-support remedy. Fixed-local safety journals do not count as mixed engines. Config-only archives remain available. Updates also reject explicit family maps until the candidate config contract supports them. Existing stores never silently switch engines or fall back to SQLite; changing a family requires an offline port and restart.
The design decision is summarized above and in the engine guide. No schema format or anchor format changes are introduced.
Evidence
2d56a0a154b1631df86d025ac5f14127a5368943. Completed successfully: 152 jobs passed and 22 planned jobs skipped. Full PostgreSQL conformance passed, includingport-command.recovery.integration.test.tsand the R4 agent cases.Known inherited local findings, with no baseline or suppression changes:
ui/src/pages/chat/components/chat-message.test.tsx:3214,ui/src/pages/config/config-page-state.ts:1, andui/src/pages/sessions/sessions-page-state.ts:1596. The result is the same when pinned to the actual PR base.presentSessionRow(rowProjection) insrc/gateway/session-utils-row.ts,createLaneQueueinsrc/process/command-queue.state.ts,presentedContentinui/src/lit/presentation-binding.ts,mountLitContentinui/src/lit/solid-content.tsx, and typePluginToolIconinui/src/pages/chat/chat-tool-icon-controller.ts.presentedContent,renderActivityGroupinui/src/pages/chat/components/chat-message-group.test-support.ts, andPluginToolIcon. All listed files are unchanged from the PR base.A prior-head CI run also failed the unchanged session-list projection test on filesystem-probe counts. A local PR replay reproduced extra
statcalls; the untouched-base comparison timed out, so attribution remains unresolved and no session fix is claimed. The final-head CI run passed all selected tests.Net production TypeScript growth is 285 lines against base
08dd80a42558ef5a5d130f6fd1fc5cd09519fb8e. The existing selection owner and task scope are reused; there is no new runtime registry.Files overlapping R4
docs/reference/database-engines.mdextensions/memory-core/src/memory-search-database.tsextensions/memory-core/src/memory/manager-db.engine-admission.test.tsscripts/pr-lib/wrapper-components.txtsrc/agents/auth-profiles/sqlite-read.tssrc/agents/auth-profiles/sqlite.tssrc/commands/doctor-database-engine.test.tssrc/infra/database-engine/open.tssrc/infra/database-engine/registry.test.tssrc/infra/database-engine/registry.tssrc/infra/sqlite-store.worker.tssrc/infra/worker-task-pool.retained.test.tssrc/state/openclaw-agent-db-engine.tssrc/state/openclaw-agent-db-registry-listing.tssrc/state/openclaw-agent-db.postgres.test.tssrc/state/openclaw-agent-schema-inspection-worker.tssrc/state/openclaw-database-preflight.ts