Repository navigation
Add per-agent SQLite cache store - #88349
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 30, 2026, 11:45 AM ET / 15:45 UTC. Summary PR surface: Source +678, Tests +477, Generated +66, Other +16. Total +1237 across 12 files. Reproducibility: not applicable. as a feature PR; there is no reported current-main bug to reproduce. The changed storage behavior is source-reviewable and covered by focused SQLite tests in the PR body. Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge only after a maintainer explicitly accepts the staged per-agent SQLite cache direction and its availability/upgrade guardrails; otherwise pause it behind the canonical storage I/O decision. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature PR; there is no reported current-main bug to reproduce. The changed storage behavior is source-reviewable and covered by focused SQLite tests in the PR body. Is this the best way to solve the issue? Unclear until maintainer signoff: the implementation matches the database-first per-agent boundary, but the specific per-agent WAL cache direction needs explicit acceptance because the related I/O issue remains open. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 05634708e053. Label changesLabel justifications:
Evidence reviewedPR surface: Source +678, Tests +477, Generated +66, Other +16. Total +1237 across 12 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
82e8a5c to
50f8d5f
Compare
* feat: add per-agent sqlite cache store * fix: preserve sqlite cache adapter scope * chore: mark sqlite cache scaffold intentional
* feat: add per-agent sqlite cache store * fix: preserve sqlite cache adapter scope * chore: mark sqlite cache scaffold intentional
Closes #204880 ## What Problem This Solves A build currently refuses every database written at a newer schema version, even when the change only adds storage that the older build can safely ignore. This prevents a previous Gateway from reopening compatible state after an update trial. ## User Impact The next stable can reopen future SQLite state, agent stores, and PostgreSQL schemas when their recorded reader floor permits it. Incompatible changes still stop startup with a clear schema refusal. Existing strict stores retain their current format and behavior; this PR does not change update backup policy. ## Why This Change Was Made The existing version owners publish or clear `min_reader` in the version transaction. An absent/null floor means the writer version, so strict steps need no new storage; the first tolerable step adds a nullable floor column. Pre-v43 agent history stays strict; from v43 the SQLite migration finisher derives tolerance from the migrated predecessor catalog. No schema number is bumped, and port publication is unchanged. Admission, boot preflight and catalog checks preserve the actual writer version while accepting unknown tables and NULL-safe nullable columns. Non-nullable columns, non-NULL defaults, CHECKs rejecting NULL, generated columns, keys and references stay non-additive. Known constraints, triggers and ownership checks remain enforced; PostgreSQL also requires the newer writer's unchanged catalog seal. Newer registry rows remain discovery candidates; the `raised` case in `openclaw-agent-db.checkonce.test.ts` proves that a store whose floor is above this code is still refused at open. Ayaan approved this schema contract change on 2026-11-24 (`state-model-decision.md`). This PR targets main only; the release manager owns any backport. Rollback also retains the valid restored config when automatic recovery finds a newer writer's backup. The existing destructive-action guard remains enforced for an actually loaded newer config; prepared, synchronous and asynchronous recovery share this rule. The independent config-recovery repair is being landed first as a prerequisite (it also affects existing copy-and-swap rollback). Once main contains it, this PR will inherit the same implementation rather than carry a second change. ## Evidence - AWS: 164 SQLite/boot/catalog tests and 44 PostgreSQL tests passed ([run](https://crabbox.openclaw.ai/portal/runs/run_44448ae157b99967d36d4de1029769af)). - Red on unmodified main: SQLite state, SQLite agent, and PostgreSQL writable/read-only admission refuse the same compatible-newer fixtures ([run](https://crabbox.openclaw.ai/portal/runs/run_06577478aecf849ce6463a01fab37b53)). - Two local ClawSweeper rounds completed; verified findings were fixed. The lead reviewed the final registry delta and the subsequent behavior-equivalent type/lint fixes against the exact head. - AWS `check:changed` passed on `956fc25da6`: core/core-test type graphs, lint, format, dead-export checks, SQLite worker/dialect guards, and the remaining selected guards ([run](https://crabbox.openclaw.ai/portal/runs/run_cf80edb44a2a04deba0c2cf62af5810f)). Narrow subsequent auth/guard changes require the checks below. - Linux T/T+1 packages built successfully ([run](https://crabbox.openclaw.ai/portal/runs/run_5eaf078abca514a139d8c599b2092035)). That run exposed the restored-config recovery blocker, which was fixed rather than bypassed. The recovery regression then failed against the old owner and all 56 main config tests passed ([run](https://crabbox.openclaw.ai/portal/runs/run_96332cda9f136830532e490fd55faacb)). **Proof status:** the completed main SQLite downgrade run is recorded below. The built PostgreSQL downgrade cell remains NOT RUN; it is not claimed green. Affected behavior and final-head type checks remain covered by required PR CI. ## Scope One version owner per store publishes the floor; strict steps retain the existing encoding. The change removes duplicate shared-version publication rather than adding a parallel migration mechanism. The focused column classifier now lives in `sqlite-additive-column.ts` to satisfy the existing owner's line cap; both consumers import it directly, without a facade or re-export. No broad historical fixture rewrites or unrelated documentation changes remain. Follow-up class: the admission rule currently spans about 15 independent version gates; consolidate them behind one admission owner so a future rule change is one edit. This PR only changes their existing decisions and required propagation. <details> <summary>LSP production reader inventory</summary> LSP references were collected before edits; its index is anchored to the primary checkout, so coordinates are not claimed for these frozen worktrees. New worktree-only consumers are named explicitly below. Paths without a prefix are under `src/state/`. - Shared version gate: `openclaw-state-db-schema-version.ts`, `openclaw-state-db-maintenance.ts`, `openclaw-state-db-fast-path.ts`, `openclaw-state-db-existing-schema.ts`, `openclaw-state-db-open.ts`, `openclaw-state-db-read-schema.ts`, `openclaw-state-db-existing-write.ts`, `openclaw-state-db-startup-checkpoint.ts`, `openclaw-state-db-schema-runtime.ts`, `openclaw-state-db-read-connection.ts`, `openclaw-state-db.ts`, `startup-metadata-live-read.worker.ts`, `src/plugins/update-cohort-recovery.ts`, `src/snapshot/openclaw-snapshot-copy.ts`, `src/snapshot/git-backup-codec.ts`, `src/agents/harness/native-hook-relay-client-read.ts`. New floor-read consumers: `openclaw-state-schema-preflight.ts`, `src/infra/sqlite-schema-header.ts`. - Agent version gate: `openclaw-agent-db-schema-read.ts`, `openclaw-agent-db-owner-read.ts`, `openclaw-agent-db-readonly-open.ts`, `openclaw-agent-db-schema.ts`, `openclaw-agent-db-maintenance.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`, `src/infra/database-engine/agent-port-descriptor.ts`, `src/infra/state-migrations.media-persistence.ts`, `src/snapshot/git-backup-codec.ts`, `src/snapshot/openclaw-snapshot-copy.ts`. Current-agent metadata gate: `openclaw-agent-db-engine.ts`, `openclaw-agent-db-schema-helpers.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`. - PostgreSQL physical admission: `src/infra/database-engine/open.ts`, `openclaw-state-db-engine.ts`. Schema verification: `src/infra/database-engine/physical-facts.ts`, `src/infra/database-engine/adapters.ts`. Engine-open callers: `openclaw-state-db-open.ts`, `openclaw-agent-db-engine.ts`, `openclaw-state-db-engine.ts`, `src/infra/database-engine/historical-index-ordering-port.ts`, `src/infra/database-engine/state-port-descriptor.ts`; Plugin SDK re-export unchanged. - Runtime inspection/preflight: `openclaw-agent-schema-inspection.worker.ts`, `openclaw-database-preflight.ts`, `openclaw-state-read-operation-registry.ts`. Preflight entry callers include Doctor database preflight, startup client credentials, preflight contexts, update-data-at-risk, auto-update compatibility, daemon status, Gateway bootstrap/startup maintenance, Doctor lease refusal and agent admission. Explicit updater-target policy remains strict. - Audit catalog admission: `openclaw-state-db-audit-migration.ts`, `openclaw-state-db-schema-repair.ts`. Canonical session-validation catalog admission: `openclaw-agent-canonical-validation-schema.ts`, `openclaw-agent-canonical-validation-receipt.ts`, `openclaw-agent-db-validation-cache.ts`, `openclaw-agent-db-readonly-open.ts`, `openclaw-agent-db-schema-admission.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`, `src/config/sessions/session-canonical-key.ts`. - Registry candidate filtering: `openclaw-agent-db-registry-listing.ts` (inspection, memo and snapshot paths), `src/infra/update-data-at-risk.ts`, `src/commands/doctor-db-bloat.read.ts`. Actual store admission remains the floor authority. - Config recovery's existing future-version guard is now consulted by the shared recovery plan builder. LSP callers: `io.observe-recovery.ts` prepared and immediate recovery entrypoints; synchronous/asynchronous startup loaders at `src/config/io.load.ts:210-212`; prepared snapshot recovery at `src/config/io.snapshot.ts:486`. Actual current-config admission in Gateway pre-bootstrap is unchanged. - Auth-profile reader admission: LSP production consumers `src/agents/auth-profiles/sqlite-json.ts:187,210` and `src/agents/auth-profiles/sqlite.ts:239,361` now use the canonical agent floor gate. Pooled same-version reuse remains query-free; a changed supplied version is checked once. </details> ## Test growth allocation The maintainer approved allocation **150** for measured net test growth550: the prior127, optional-floor reference metadata (5), persisted-floor/refusal proof (2), cold-worker zero-comparison-DDL coverage (6), and cap-required fixture extraction/imports/formatting (10). The obsolete strict43-reader refusal case is replaced by actual44-writer/floor43 admission and old-writer NULL insertion proof. Only a redundant step-presence assertion was removed; exact rollback, ownership, catalog and constraint assertions remain. | Test file (`src/` unless otherwise qualified) | + / - | Protected contract | | --- | ---: | --- | | `agents/auth-profiles.sqlite-read-pool.test.ts` | 42 / 0 | Retained/raised floors through projected/plain auth readers; query-free warm reuse. | | `config/sessions/startup-migration.acp.test.ts` | 4 / 1 | Legacy admission uses consistent header/ownership markers. | | `infra/database-engine/bridge-prestart.test.ts` | 1 / 0 | PostgreSQL admission facts carry the required floor. | | `infra/database-engine/physical-facts.test.ts` | 2 / 2 | Strict metadata keeps absent-floor compatibility. | | `infra/database-engine/schema-admission.postgres.test.ts` | 172 / 1 | Writable/read-only T+1 admission; malformed/raised floors; nullable versus constrained catalogs; seals and rollback. | | `infra/sqlite-schema-facts.test.ts` | 42 / 0 | Warm future-reader cache stays query-free and rejects floors raised after schema/version invalidation. | | `infra/sqlite-schema-header.test.ts` | 9 / 5 | Floor/ownership survive inspection; native lock/WAL fixtures carry historical agent metadata. | | `state/openclaw-agent-db-registry-listing.snapshot.test.ts` | 2 / 2 | Future stores remain discovery candidates, not implicitly admitted stores. | | `state/openclaw-agent-db.checkonce.test.ts` | 120 / 5 | SQLite agent admission, readonly open, metadata preservation and transactional floor publication/rollback. | | `state/openclaw-agent-db.committed-read.test.ts` | 4 / 1 | A legacy replacement is refused before invoking its reader. | | `state/openclaw-database-preflight.startup-prepared.test.ts` | 7 / 1 | Boot preflight retains the actual legacy migration refusal. | | `state/openclaw-schema-metadata.test.ts` | 15 / 0 | SQLite ownership metadata/floor contract. | | `state/openclaw-state-db-checkonce.test.ts` | 1 / 1 | Cold content/floor read still executes exactly once. | | `state/openclaw-state-db-cron-delivery-migration.test.ts` | 1 / 1 | Managed snapshot qualification retains its exact query sequence. | | `state/openclaw-state-db-schema-version.test.ts` | 83 / 1 | SQLite state T+1 admission, raised-floor refusal and atomic floor publication/rollback. | | `state/openclaw-state-read.owned-native-token.test.ts` | 7 / 4 | Snapshot files and stable SHM bytes remain exact; only documented read marks may vary. | | `state/openclaw-state-read.worker.test.ts` | 1 / 0 | PostgreSQL worker facts retain the floor. | | `state/openclaw-agent-active-event-facts-migration.postgres.test.ts` | 1 / 1 | Strict legacy reader-floor refusal reports floor41 versus reader40. | | `state/openclaw-approval-profile-migration.postgres.test.ts` | 1 / 1 | Strict state reader-floor refusal reports floor41 versus reader40. | | `state/openclaw-worker-provision-source-migration.postgres.test.ts` | 1 / 1 | Strict state reader-floor refusal reports floor41 versus reader39. | | `extensions/workboard/src/postgres-store.test.ts` | 1 / 1 | A legacy strict workboard floor refuses the unsupported reader. | | `state/openclaw-agent-tool-usage-migration.postgres.test.ts` | 5 / 3 | Persists derived floor43 after strict42/43 plus additive44, and refuses reader41. | | `state/openclaw-agent-schema-inspection-worker.test.ts` | 16 / 0 | A future agent floor is read even when ownership projection is not requested. | | `state/openclaw-database-preflight.artifacts.test.ts` | 2 / 2 | Locked source fixture retains the real agent metadata shape; lock/readiness assertions unchanged. | | `commands/backup-verify.test.ts` | 4 / 4 | Wrong-role/path negatives carry otherwise complete agent metadata; rejection assertions unchanged. | | `commands/doctor-maintenance.schema-preflight.test.ts` | 2 / 2 | A raised agent floor refuses before incomplete registry repairs. | | `flows/doctor-health.dangling-workshop-index.test.ts` | 2 / 2 | Newer agent refusal preserves damaged shared-state bytes. | | `infra/database-engine/admitted-diagnostics.test.ts` | 1 / 1 | Read-free diagnostic agent fixture includes ownership columns. | | `infra/update-database-backup.agent-owners.test.ts` | 2 / 2 | Backup manifest owner discovery uses complete agent metadata. | | `infra/update-database-backup.test.ts` | 1 / 1 | External-agent backup fixture matches its existing version17 header. | | `state/openclaw-state-worker-loss-recovery.postgres.test.ts` | 4 / 1 | Newly merged v42 migration still refuses its v41 reader, asserting the floor diagnostic dynamically. | | `infra/sqlite-schema-contract.test.ts` | 25 / 16 | NULL-safe CHECK/default positives; six non-additive negatives, retaining strict known-object checks. | | `state/openclaw-agent-member-access-migration.test.ts` | 30 / 19 | Real step44 retains floor43 and old-reader/write compatibility; commit/rollback, sharing, witness and exact shipped PG SQL stay covered. | | `infra/database-engine/doctor-migration.postgres.test.ts` | 6 / 9 | Exact seven historical-agent upgrade/rollback catalogs; coherent fixture extraction keeps the owner within its line cap. | | `infra/database-engine/doctor-migration.postgres.test-support.ts` | 16 / 0 | Independent relocated full-catalog reader and optional-floor reference metadata fixture; no comparison filtering. | | `infra/sqlite-schema-contract.worker.test.ts` | 6 / 0 | NULL-safe CHECK drift remains compatible with strictly zero comparison DDL. | | `state/openclaw-state-ownership.test.ts` | 3 / 1 | A truly incompatible non-NULL default still blocks malformed-owner repair without changing its bytes. | The supported-header warm shortcut relies on atomically matching markers and `min_reader <= writer_version`; it does **not** short-circuit newer headers. The `raised` case in `openclaw-agent-db.checkonce.test.ts` asserts refusal at physical open, and the new `sqlite-schema-facts.test.ts` schema/version-invalidation cases require `SqliteSchemaVersionError` after a floor rises above this build. These new-head checks remain part of the explicitly outstanding proof, not a claim of final-head green. ## Completed SQLite downgrade proof [AWS run `run_9344a01fac267cad3cc0253546ab206b`](https://crabbox.openclaw.ai/portal/runs/run_9344a01fac267cad3cc0253546ab206b) completed the real packed main agent44→45 Gateway cases. T reached readiness with T+1's retained-floor shared/agent stores, including the first newly added nullable floor storage; agent-only retained snapshots also reached readiness. Raised shared and agent-only floors both refused with exit78. Metadata and seeded session rows were preserved. Main auth tests, SQLite floor/CI regressions and PostgreSQL floor regressions passed; Kysely passed. The run used frozen main `546bde6b` before later warm-path and fixture corrections, so it is not presented as a blanket final-head CI result. The five canonical `check-test-types-core-*` jobs passed on run `45517151870`; the ad-hoc proof typecheck configuration was discarded rather than loosening its libraries. **PostgreSQL built downgrade cell: NOT RUN.** The initial run stopped at T+1 Doctor's strict pre-repair predecessor catalog check; the repaired predecessor fixture is prepared but its bounded replay could not run. Both standard-profile AWS allocations (including the single retry after capacity was freed) were quota-rejected down to an undersized `t3.small`; both leases were released without launching builds. PostgreSQL floor unit regressions passed. No backup/catalog gate was bypassed and no PG downgrade boot is claimed. Per the maintainer's decision, this capacity gap does not block the SQLite-proven PR; required CI and review still apply. ## Codex timeout attribution [Controlled AWS comparison `run_f1242c2eb06315326ef5805841e000b1`](https://crabbox.openclaw.ai/portal/runs/run_f1242c2eb06315326ef5805841e000b1) ran the single Codex runtime test on the actual release merge candidate `adbb7d9d` (head `8b9199fd`) and its base `6b006bb1`, using the same pinned Bun and Node24.22.1. **Both reproduced the identical45000ms timeout.** Base/head wall time was114.352s/114.205s; Vitest110.85s/110.71s; max RSS5405548/5225840KiB. No head slowdown was observed in this isolated comparison. This is baseline reproduction, not a passing test or a “flake cleared” claim. The optional SQL trace covered diagnostics_channel only and does not establish absence of native SQLite calls. ## Round-two owner-selection regression One local `ocx test --no-memo src/state/openclaw-agent-schema-inspection-worker.test.ts` run on `6f3417a4c8` was **red**: only the new 45/min_reader44, ownership-disabled case failed because minReader44 was omitted (7 existing tests passed). One run on the fixed `acaf8043a6` head was **green: 8/8**. Proof tier: vitest-source, no build. Agent inspection always reads the agent metadata floor; only the ownership result is optional, and the state floor owner is unchanged. This is review round2/2; no additional full review was requested. Historical ownership check: the first agent-store commit `fc50f949` (#88349), shipped `v2026.5.30-beta.1`, and retained stable `v2026.7.35` all have required `role` and `schema_version` metadata. The `git log --follow -S 'schema_version INTEGER'` history contains no shipped removal. Four minimal two-column test fixtures were corrected in place, with no assertion/timing changes or net test growth; no legacy product fallback was added. Focused local fixture proof (vitest-source, no build): one `ocx test --no-memo src/state/openclaw-database-preflight.artifacts.test.ts src/infra/sqlite-schema-header.test.ts` invocation passed **19/19** (9 preflight, 10 header), including unchanged lock tolerance, hot-journal and WAL byte-preservation cases. Completed a full `CREATE TABLE schema_meta` / agent_id fixture inventory across `src` and `test`, including multiline/quoted forms. All remaining synthetic agent fixtures now carry role/schema_version; the deliberately malformed populated-v0 refusal fixture remains malformed by design. Shared/global, credential-source and generic engine-scope fixtures are not agent stores and remain unchanged. The sweep changes only SQL fixture lines (12 replacements/net0), not assertions or timeouts. One local `ocx test --no-memo` invocation of all six sweep files passed **87 tests, 1 Windows-only skip** on main (43 infra +44 commands); proof tier vitest-source/no build. Total main diff after the newly merged PostgreSQL refusal diagnostic correction: **77 files, +1331/-268 (net1063)** against merge-base `8aaf3820112a`; production/config +740/-216, tests +552/-45, versioning doc +39/-7. After merging main's new shared schema42, PostgreSQL conformance run45543740954/job138969182913 exposed its newly introduced worker-loss migration test's old `is newer` diagnostic expectation. The actual refusal correctly required floor42 versus reader41. Updated only that expectation to the dynamic minimum-reader diagnostic; a sweep of all `*.postgres.test.ts` under `src`/`test` found no other remaining `is newer` refusal expectation. Green PostgreSQL execution of this narrow correction is left to required CI, not claimed from a skipped local test. ## Real step44: classifier-derived compatibility `src/infra/sqlite-additive-column.ts` is the single column predicate. Its SELECT-only evaluator replaces the earlier candidate CREATE/INSERT probe: it parses nullable/default/CHECK clauses and evaluates scalar CHECK expressions over an explicit NULL value under deterministic-function authorization. It executes no comparison DDL and never touches source state. Non-nullable/unsafe default/key/reference/generated declarations stay incompatible; bare-type and warm admission paths retain their existing fast paths. `src/state/openclaw-agent-db-schema-helpers.ts:450` compares the migrated catalog with the actual predecessor before atomically stamping the version and derived floor. Pre-v43 history remains strict. PostgreSQL step44 computes its existing `minReader` property lazily through the same predicate (`openclaw-agent-member-access-schema.ts:10`, `openclaw-agent-db-engine.ts:431`), with no hand-declared floor43. Its generated migration SQL is asserted **byte-identical** to main's shipped SQL. Removed: the obsolete strict43-reader refusal test and the claimed43→44 pre-image requirement. There is no step44-specific production copy/pre-image branch to retain; generic backup restoration proof remains. Witness normalization treats `min_reader` like the existing version/app/time migration metadata; raw same-version schema/content hashes remain exact. This update adds **no persistent application column or table beyond the min_reader storage already present at870ef9ba31**, and the final classifier also performs **zero comparison DDL**. Proof: the two owning files on baseline870ef9ba31 with the new regression were **red: 4 intended failures, 35 passing**. Final main-only change **7f02f3b218** is **green: 39/39** via `ocx test --no-memo src/infra/sqlite-schema-contract.test.ts src/state/openclaw-agent-member-access-migration.test.ts` (vitest-source/no build). Logs: `ReaderFloor-null-safe-check/red-870ef9ba31.log`, `green-final.log`. Intermediate helper-regex and witness failures were corrected in their owners; no assertion/timeout masking. Latest measured scope against8aaf3820112a, superseding earlier historical counts: **82 files, +1485/-321, net1164**; production/config48 +836/-233 (net603), tests33 +607/-80 (net527), versioning doc +42/-8 (net34). Allocation127 covers the requested step44 contract and six negatives. Architecture CI's native-opener guard found one owned integration issue at7f02f3b218: the disposable classifier probe used the raw constructor. Fixed only its opener/import through `openNodeSqliteDatabase` (no exemption); owning39tests and `pnpm lint:kysely` both pass. Repair748ab989ac is +3/-3, no net scope growth or schema change. Logs: `ReaderFloor-null-safe-check/canonical-opener-tests.log`, `canonical-opener-guard.log`. ## Consolidated CI repair The SELECT-only helper's +83 production lines replace its DDL probe while preserving the cold-worker zero-comparison-DDL contract. The trusted PR wrapper legitimately imports this schema-rule owner through its already-inventoried schema contract; `scripts/pr-lib/wrapper-components.txt` now declares the extracted helper (one path), rather than relocating a schema rule into an unrelated native owner or weakening the closure test. PostgreSQL's seven reported historical-agent failures occurred before rollback: migrated engine metadata had its optional floor column, while the fresh reference intentionally omitted it. The independent reference fixture now includes that exact nullable BIGINT metadata representation; whole-catalog equality and all rollback/foreign-write assertions remain. Fresh production bootstrap remains unchanged. The tool-usage predecessor refusal now asserts the correct derived floor43, not44. The malformed-owner negative uses a non-NULL default because DEFAULT NULL is now intentionally additive. The unrelated startup timing case from #204943 is owned by the maintainer's override; this repair neither changes nor reruns it. Owning local schema/PostgreSQL lanes initially failed during dependency setup, before tests, when parallel ocx installs rematerialized a shared checkout; source-identical committed-head serial proof runs in an isolated checkout instead. CI on652ae1d9aa remains the full proof. Latest consolidated scope against8aaf3820112a: **87 files, +1604/-333, net1271**; production/config49 +920/-233 (net687), tests37 +642/-92 (net550), versioning doc +42/-8 (net34). Head652ae1d9aa differs from consolidated repair e57d895 only by its approved allocation record. Kysely guardrails passed; final local/CI outcomes are not claimed before completion. ## Merged native-observer compatibility Main was merged once to include #205022's migration observer. Its catalog capture happens before every observed statement, so the private NULL probe now permits only the observer's read-only catalog PRAGMAs/schema reads in addition to its scalar CHECK evaluation, and clears its authorizer before disposal. Writes, user-table reads and nondeterministic functions remain denied; neither the observer nor source guards changed. Merged-tree local proof: **45/45 passed** (migration-chain5, classifier/cold-worker/real-step44 tests40), log `ReaderFloor-consolidated-repairs/observer-merged.log`. Earlier owning schema proof was71/71; wrapper closure23/23 and provisioner17 cases passed, with only the independently observed plain-main macOS sparse-transition120s timeout remaining locally. PostgreSQL's hand-built pre-merge local proof had later credential-restore/transaction errors; it is not claimed green, and the maintainer designated CI's PostgreSQL conformance as authoritative. Current head **c946b3fc75**, measured against main merge-base **3f2e0ade38**: **87 files, +1614/-333, net1281**; production/config49 net697, tests37 net550, versioning doc net34. Allocation150 is unchanged. All task-owned local PostgreSQL/container and scratch resources have been released. Co-authored-by: Ayaan Zaidi <[email protected]>
) Closes openclaw#204880 ## What Problem This Solves A build currently refuses every database written at a newer schema version, even when the change only adds storage that the older build can safely ignore. This prevents a previous Gateway from reopening compatible state after an update trial. ## User Impact The next stable can reopen future SQLite state, agent stores, and PostgreSQL schemas when their recorded reader floor permits it. Incompatible changes still stop startup with a clear schema refusal. Existing strict stores retain their current format and behavior; this PR does not change update backup policy. ## Why This Change Was Made The existing version owners publish or clear `min_reader` in the version transaction. An absent/null floor means the writer version, so strict steps need no new storage; the first tolerable step adds a nullable floor column. Pre-v43 agent history stays strict; from v43 the SQLite migration finisher derives tolerance from the migrated predecessor catalog. No schema number is bumped, and port publication is unchanged. Admission, boot preflight and catalog checks preserve the actual writer version while accepting unknown tables and NULL-safe nullable columns. Non-nullable columns, non-NULL defaults, CHECKs rejecting NULL, generated columns, keys and references stay non-additive. Known constraints, triggers and ownership checks remain enforced; PostgreSQL also requires the newer writer's unchanged catalog seal. Newer registry rows remain discovery candidates; the `raised` case in `openclaw-agent-db.checkonce.test.ts` proves that a store whose floor is above this code is still refused at open. Ayaan approved this schema contract change on 2026-11-24 (`state-model-decision.md`). This PR targets main only; the release manager owns any backport. Rollback also retains the valid restored config when automatic recovery finds a newer writer's backup. The existing destructive-action guard remains enforced for an actually loaded newer config; prepared, synchronous and asynchronous recovery share this rule. The independent config-recovery repair is being landed first as a prerequisite (it also affects existing copy-and-swap rollback). Once main contains it, this PR will inherit the same implementation rather than carry a second change. ## Evidence - AWS: 164 SQLite/boot/catalog tests and 44 PostgreSQL tests passed ([run](https://crabbox.openclaw.ai/portal/runs/run_44448ae157b99967d36d4de1029769af)). - Red on unmodified main: SQLite state, SQLite agent, and PostgreSQL writable/read-only admission refuse the same compatible-newer fixtures ([run](https://crabbox.openclaw.ai/portal/runs/run_06577478aecf849ce6463a01fab37b53)). - Two local ClawSweeper rounds completed; verified findings were fixed. The lead reviewed the final registry delta and the subsequent behavior-equivalent type/lint fixes against the exact head. - AWS `check:changed` passed on `956fc25da6`: core/core-test type graphs, lint, format, dead-export checks, SQLite worker/dialect guards, and the remaining selected guards ([run](https://crabbox.openclaw.ai/portal/runs/run_cf80edb44a2a04deba0c2cf62af5810f)). Narrow subsequent auth/guard changes require the checks below. - Linux T/T+1 packages built successfully ([run](https://crabbox.openclaw.ai/portal/runs/run_5eaf078abca514a139d8c599b2092035)). That run exposed the restored-config recovery blocker, which was fixed rather than bypassed. The recovery regression then failed against the old owner and all 56 main config tests passed ([run](https://crabbox.openclaw.ai/portal/runs/run_96332cda9f136830532e490fd55faacb)). **Proof status:** the completed main SQLite downgrade run is recorded below. The built PostgreSQL downgrade cell remains NOT RUN; it is not claimed green. Affected behavior and final-head type checks remain covered by required PR CI. ## Scope One version owner per store publishes the floor; strict steps retain the existing encoding. The change removes duplicate shared-version publication rather than adding a parallel migration mechanism. The focused column classifier now lives in `sqlite-additive-column.ts` to satisfy the existing owner's line cap; both consumers import it directly, without a facade or re-export. No broad historical fixture rewrites or unrelated documentation changes remain. Follow-up class: the admission rule currently spans about 15 independent version gates; consolidate them behind one admission owner so a future rule change is one edit. This PR only changes their existing decisions and required propagation. <details> <summary>LSP production reader inventory</summary> LSP references were collected before edits; its index is anchored to the primary checkout, so coordinates are not claimed for these frozen worktrees. New worktree-only consumers are named explicitly below. Paths without a prefix are under `src/state/`. - Shared version gate: `openclaw-state-db-schema-version.ts`, `openclaw-state-db-maintenance.ts`, `openclaw-state-db-fast-path.ts`, `openclaw-state-db-existing-schema.ts`, `openclaw-state-db-open.ts`, `openclaw-state-db-read-schema.ts`, `openclaw-state-db-existing-write.ts`, `openclaw-state-db-startup-checkpoint.ts`, `openclaw-state-db-schema-runtime.ts`, `openclaw-state-db-read-connection.ts`, `openclaw-state-db.ts`, `startup-metadata-live-read.worker.ts`, `src/plugins/update-cohort-recovery.ts`, `src/snapshot/openclaw-snapshot-copy.ts`, `src/snapshot/git-backup-codec.ts`, `src/agents/harness/native-hook-relay-client-read.ts`. New floor-read consumers: `openclaw-state-schema-preflight.ts`, `src/infra/sqlite-schema-header.ts`. - Agent version gate: `openclaw-agent-db-schema-read.ts`, `openclaw-agent-db-owner-read.ts`, `openclaw-agent-db-readonly-open.ts`, `openclaw-agent-db-schema.ts`, `openclaw-agent-db-maintenance.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`, `src/infra/database-engine/agent-port-descriptor.ts`, `src/infra/state-migrations.media-persistence.ts`, `src/snapshot/git-backup-codec.ts`, `src/snapshot/openclaw-snapshot-copy.ts`. Current-agent metadata gate: `openclaw-agent-db-engine.ts`, `openclaw-agent-db-schema-helpers.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`. - PostgreSQL physical admission: `src/infra/database-engine/open.ts`, `openclaw-state-db-engine.ts`. Schema verification: `src/infra/database-engine/physical-facts.ts`, `src/infra/database-engine/adapters.ts`. Engine-open callers: `openclaw-state-db-open.ts`, `openclaw-agent-db-engine.ts`, `openclaw-state-db-engine.ts`, `src/infra/database-engine/historical-index-ordering-port.ts`, `src/infra/database-engine/state-port-descriptor.ts`; Plugin SDK re-export unchanged. - Runtime inspection/preflight: `openclaw-agent-schema-inspection.worker.ts`, `openclaw-database-preflight.ts`, `openclaw-state-read-operation-registry.ts`. Preflight entry callers include Doctor database preflight, startup client credentials, preflight contexts, update-data-at-risk, auto-update compatibility, daemon status, Gateway bootstrap/startup maintenance, Doctor lease refusal and agent admission. Explicit updater-target policy remains strict. - Audit catalog admission: `openclaw-state-db-audit-migration.ts`, `openclaw-state-db-schema-repair.ts`. Canonical session-validation catalog admission: `openclaw-agent-canonical-validation-schema.ts`, `openclaw-agent-canonical-validation-receipt.ts`, `openclaw-agent-db-validation-cache.ts`, `openclaw-agent-db-readonly-open.ts`, `openclaw-agent-db-schema-admission.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`, `src/config/sessions/session-canonical-key.ts`. - Registry candidate filtering: `openclaw-agent-db-registry-listing.ts` (inspection, memo and snapshot paths), `src/infra/update-data-at-risk.ts`, `src/commands/doctor-db-bloat.read.ts`. Actual store admission remains the floor authority. - Config recovery's existing future-version guard is now consulted by the shared recovery plan builder. LSP callers: `io.observe-recovery.ts` prepared and immediate recovery entrypoints; synchronous/asynchronous startup loaders at `src/config/io.load.ts:210-212`; prepared snapshot recovery at `src/config/io.snapshot.ts:486`. Actual current-config admission in Gateway pre-bootstrap is unchanged. - Auth-profile reader admission: LSP production consumers `src/agents/auth-profiles/sqlite-json.ts:187,210` and `src/agents/auth-profiles/sqlite.ts:239,361` now use the canonical agent floor gate. Pooled same-version reuse remains query-free; a changed supplied version is checked once. </details> ## Test growth allocation The maintainer approved allocation **150** for measured net test growth550: the prior127, optional-floor reference metadata (5), persisted-floor/refusal proof (2), cold-worker zero-comparison-DDL coverage (6), and cap-required fixture extraction/imports/formatting (10). The obsolete strict43-reader refusal case is replaced by actual44-writer/floor43 admission and old-writer NULL insertion proof. Only a redundant step-presence assertion was removed; exact rollback, ownership, catalog and constraint assertions remain. | Test file (`src/` unless otherwise qualified) | + / - | Protected contract | | --- | ---: | --- | | `agents/auth-profiles.sqlite-read-pool.test.ts` | 42 / 0 | Retained/raised floors through projected/plain auth readers; query-free warm reuse. | | `config/sessions/startup-migration.acp.test.ts` | 4 / 1 | Legacy admission uses consistent header/ownership markers. | | `infra/database-engine/bridge-prestart.test.ts` | 1 / 0 | PostgreSQL admission facts carry the required floor. | | `infra/database-engine/physical-facts.test.ts` | 2 / 2 | Strict metadata keeps absent-floor compatibility. | | `infra/database-engine/schema-admission.postgres.test.ts` | 172 / 1 | Writable/read-only T+1 admission; malformed/raised floors; nullable versus constrained catalogs; seals and rollback. | | `infra/sqlite-schema-facts.test.ts` | 42 / 0 | Warm future-reader cache stays query-free and rejects floors raised after schema/version invalidation. | | `infra/sqlite-schema-header.test.ts` | 9 / 5 | Floor/ownership survive inspection; native lock/WAL fixtures carry historical agent metadata. | | `state/openclaw-agent-db-registry-listing.snapshot.test.ts` | 2 / 2 | Future stores remain discovery candidates, not implicitly admitted stores. | | `state/openclaw-agent-db.checkonce.test.ts` | 120 / 5 | SQLite agent admission, readonly open, metadata preservation and transactional floor publication/rollback. | | `state/openclaw-agent-db.committed-read.test.ts` | 4 / 1 | A legacy replacement is refused before invoking its reader. | | `state/openclaw-database-preflight.startup-prepared.test.ts` | 7 / 1 | Boot preflight retains the actual legacy migration refusal. | | `state/openclaw-schema-metadata.test.ts` | 15 / 0 | SQLite ownership metadata/floor contract. | | `state/openclaw-state-db-checkonce.test.ts` | 1 / 1 | Cold content/floor read still executes exactly once. | | `state/openclaw-state-db-cron-delivery-migration.test.ts` | 1 / 1 | Managed snapshot qualification retains its exact query sequence. | | `state/openclaw-state-db-schema-version.test.ts` | 83 / 1 | SQLite state T+1 admission, raised-floor refusal and atomic floor publication/rollback. | | `state/openclaw-state-read.owned-native-token.test.ts` | 7 / 4 | Snapshot files and stable SHM bytes remain exact; only documented read marks may vary. | | `state/openclaw-state-read.worker.test.ts` | 1 / 0 | PostgreSQL worker facts retain the floor. | | `state/openclaw-agent-active-event-facts-migration.postgres.test.ts` | 1 / 1 | Strict legacy reader-floor refusal reports floor41 versus reader40. | | `state/openclaw-approval-profile-migration.postgres.test.ts` | 1 / 1 | Strict state reader-floor refusal reports floor41 versus reader40. | | `state/openclaw-worker-provision-source-migration.postgres.test.ts` | 1 / 1 | Strict state reader-floor refusal reports floor41 versus reader39. | | `extensions/workboard/src/postgres-store.test.ts` | 1 / 1 | A legacy strict workboard floor refuses the unsupported reader. | | `state/openclaw-agent-tool-usage-migration.postgres.test.ts` | 5 / 3 | Persists derived floor43 after strict42/43 plus additive44, and refuses reader41. | | `state/openclaw-agent-schema-inspection-worker.test.ts` | 16 / 0 | A future agent floor is read even when ownership projection is not requested. | | `state/openclaw-database-preflight.artifacts.test.ts` | 2 / 2 | Locked source fixture retains the real agent metadata shape; lock/readiness assertions unchanged. | | `commands/backup-verify.test.ts` | 4 / 4 | Wrong-role/path negatives carry otherwise complete agent metadata; rejection assertions unchanged. | | `commands/doctor-maintenance.schema-preflight.test.ts` | 2 / 2 | A raised agent floor refuses before incomplete registry repairs. | | `flows/doctor-health.dangling-workshop-index.test.ts` | 2 / 2 | Newer agent refusal preserves damaged shared-state bytes. | | `infra/database-engine/admitted-diagnostics.test.ts` | 1 / 1 | Read-free diagnostic agent fixture includes ownership columns. | | `infra/update-database-backup.agent-owners.test.ts` | 2 / 2 | Backup manifest owner discovery uses complete agent metadata. | | `infra/update-database-backup.test.ts` | 1 / 1 | External-agent backup fixture matches its existing version17 header. | | `state/openclaw-state-worker-loss-recovery.postgres.test.ts` | 4 / 1 | Newly merged v42 migration still refuses its v41 reader, asserting the floor diagnostic dynamically. | | `infra/sqlite-schema-contract.test.ts` | 25 / 16 | NULL-safe CHECK/default positives; six non-additive negatives, retaining strict known-object checks. | | `state/openclaw-agent-member-access-migration.test.ts` | 30 / 19 | Real step44 retains floor43 and old-reader/write compatibility; commit/rollback, sharing, witness and exact shipped PG SQL stay covered. | | `infra/database-engine/doctor-migration.postgres.test.ts` | 6 / 9 | Exact seven historical-agent upgrade/rollback catalogs; coherent fixture extraction keeps the owner within its line cap. | | `infra/database-engine/doctor-migration.postgres.test-support.ts` | 16 / 0 | Independent relocated full-catalog reader and optional-floor reference metadata fixture; no comparison filtering. | | `infra/sqlite-schema-contract.worker.test.ts` | 6 / 0 | NULL-safe CHECK drift remains compatible with strictly zero comparison DDL. | | `state/openclaw-state-ownership.test.ts` | 3 / 1 | A truly incompatible non-NULL default still blocks malformed-owner repair without changing its bytes. | The supported-header warm shortcut relies on atomically matching markers and `min_reader <= writer_version`; it does **not** short-circuit newer headers. The `raised` case in `openclaw-agent-db.checkonce.test.ts` asserts refusal at physical open, and the new `sqlite-schema-facts.test.ts` schema/version-invalidation cases require `SqliteSchemaVersionError` after a floor rises above this build. These new-head checks remain part of the explicitly outstanding proof, not a claim of final-head green. ## Completed SQLite downgrade proof [AWS run `run_9344a01fac267cad3cc0253546ab206b`](https://crabbox.openclaw.ai/portal/runs/run_9344a01fac267cad3cc0253546ab206b) completed the real packed main agent44→45 Gateway cases. T reached readiness with T+1's retained-floor shared/agent stores, including the first newly added nullable floor storage; agent-only retained snapshots also reached readiness. Raised shared and agent-only floors both refused with exit78. Metadata and seeded session rows were preserved. Main auth tests, SQLite floor/CI regressions and PostgreSQL floor regressions passed; Kysely passed. The run used frozen main `546bde6b` before later warm-path and fixture corrections, so it is not presented as a blanket final-head CI result. The five canonical `check-test-types-core-*` jobs passed on run `45517151870`; the ad-hoc proof typecheck configuration was discarded rather than loosening its libraries. **PostgreSQL built downgrade cell: NOT RUN.** The initial run stopped at T+1 Doctor's strict pre-repair predecessor catalog check; the repaired predecessor fixture is prepared but its bounded replay could not run. Both standard-profile AWS allocations (including the single retry after capacity was freed) were quota-rejected down to an undersized `t3.small`; both leases were released without launching builds. PostgreSQL floor unit regressions passed. No backup/catalog gate was bypassed and no PG downgrade boot is claimed. Per the maintainer's decision, this capacity gap does not block the SQLite-proven PR; required CI and review still apply. ## Codex timeout attribution [Controlled AWS comparison `run_f1242c2eb06315326ef5805841e000b1`](https://crabbox.openclaw.ai/portal/runs/run_f1242c2eb06315326ef5805841e000b1) ran the single Codex runtime test on the actual release merge candidate `adbb7d9d` (head `8b9199fd`) and its base `6b006bb1`, using the same pinned Bun and Node24.22.1. **Both reproduced the identical45000ms timeout.** Base/head wall time was114.352s/114.205s; Vitest110.85s/110.71s; max RSS5405548/5225840KiB. No head slowdown was observed in this isolated comparison. This is baseline reproduction, not a passing test or a “flake cleared” claim. The optional SQL trace covered diagnostics_channel only and does not establish absence of native SQLite calls. ## Round-two owner-selection regression One local `ocx test --no-memo src/state/openclaw-agent-schema-inspection-worker.test.ts` run on `6f3417a4c8` was **red**: only the new 45/min_reader44, ownership-disabled case failed because minReader44 was omitted (7 existing tests passed). One run on the fixed `acaf8043a6` head was **green: 8/8**. Proof tier: vitest-source, no build. Agent inspection always reads the agent metadata floor; only the ownership result is optional, and the state floor owner is unchanged. This is review round2/2; no additional full review was requested. Historical ownership check: the first agent-store commit `227691b6` (openclaw#88349), shipped `v2026.5.30-beta.1`, and retained stable `v2026.7.35` all have required `role` and `schema_version` metadata. The `git log --follow -S 'schema_version INTEGER'` history contains no shipped removal. Four minimal two-column test fixtures were corrected in place, with no assertion/timing changes or net test growth; no legacy product fallback was added. Focused local fixture proof (vitest-source, no build): one `ocx test --no-memo src/state/openclaw-database-preflight.artifacts.test.ts src/infra/sqlite-schema-header.test.ts` invocation passed **19/19** (9 preflight, 10 header), including unchanged lock tolerance, hot-journal and WAL byte-preservation cases. Completed a full `CREATE TABLE schema_meta` / agent_id fixture inventory across `src` and `test`, including multiline/quoted forms. All remaining synthetic agent fixtures now carry role/schema_version; the deliberately malformed populated-v0 refusal fixture remains malformed by design. Shared/global, credential-source and generic engine-scope fixtures are not agent stores and remain unchanged. The sweep changes only SQL fixture lines (12 replacements/net0), not assertions or timeouts. One local `ocx test --no-memo` invocation of all six sweep files passed **87 tests, 1 Windows-only skip** on main (43 infra +44 commands); proof tier vitest-source/no build. Total main diff after the newly merged PostgreSQL refusal diagnostic correction: **77 files, +1331/-268 (net1063)** against merge-base `44d311177c0f`; production/config +740/-216, tests +552/-45, versioning doc +39/-7. After merging main's new shared schema42, PostgreSQL conformance run45543740954/job138969182913 exposed its newly introduced worker-loss migration test's old `is newer` diagnostic expectation. The actual refusal correctly required floor42 versus reader41. Updated only that expectation to the dynamic minimum-reader diagnostic; a sweep of all `*.postgres.test.ts` under `src`/`test` found no other remaining `is newer` refusal expectation. Green PostgreSQL execution of this narrow correction is left to required CI, not claimed from a skipped local test. ## Real step44: classifier-derived compatibility `src/infra/sqlite-additive-column.ts` is the single column predicate. Its SELECT-only evaluator replaces the earlier candidate CREATE/INSERT probe: it parses nullable/default/CHECK clauses and evaluates scalar CHECK expressions over an explicit NULL value under deterministic-function authorization. It executes no comparison DDL and never touches source state. Non-nullable/unsafe default/key/reference/generated declarations stay incompatible; bare-type and warm admission paths retain their existing fast paths. `src/state/openclaw-agent-db-schema-helpers.ts:450` compares the migrated catalog with the actual predecessor before atomically stamping the version and derived floor. Pre-v43 history remains strict. PostgreSQL step44 computes its existing `minReader` property lazily through the same predicate (`openclaw-agent-member-access-schema.ts:10`, `openclaw-agent-db-engine.ts:431`), with no hand-declared floor43. Its generated migration SQL is asserted **byte-identical** to main's shipped SQL. Removed: the obsolete strict43-reader refusal test and the claimed43→44 pre-image requirement. There is no step44-specific production copy/pre-image branch to retain; generic backup restoration proof remains. Witness normalization treats `min_reader` like the existing version/app/time migration metadata; raw same-version schema/content hashes remain exact. This update adds **no persistent application column or table beyond the min_reader storage already present at870ef9ba31**, and the final classifier also performs **zero comparison DDL**. Proof: the two owning files on baseline870ef9ba31 with the new regression were **red: 4 intended failures, 35 passing**. Final main-only change **7f02f3b218** is **green: 39/39** via `ocx test --no-memo src/infra/sqlite-schema-contract.test.ts src/state/openclaw-agent-member-access-migration.test.ts` (vitest-source/no build). Logs: `ReaderFloor-null-safe-check/red-870ef9ba31.log`, `green-final.log`. Intermediate helper-regex and witness failures were corrected in their owners; no assertion/timeout masking. Latest measured scope against8aaf3820112a, superseding earlier historical counts: **82 files, +1485/-321, net1164**; production/config48 +836/-233 (net603), tests33 +607/-80 (net527), versioning doc +42/-8 (net34). Allocation127 covers the requested step44 contract and six negatives. Architecture CI's native-opener guard found one owned integration issue at7f02f3b218: the disposable classifier probe used the raw constructor. Fixed only its opener/import through `openNodeSqliteDatabase` (no exemption); owning39tests and `pnpm lint:kysely` both pass. Repair748ab989ac is +3/-3, no net scope growth or schema change. Logs: `ReaderFloor-null-safe-check/canonical-opener-tests.log`, `canonical-opener-guard.log`. ## Consolidated CI repair The SELECT-only helper's +83 production lines replace its DDL probe while preserving the cold-worker zero-comparison-DDL contract. The trusted PR wrapper legitimately imports this schema-rule owner through its already-inventoried schema contract; `scripts/pr-lib/wrapper-components.txt` now declares the extracted helper (one path), rather than relocating a schema rule into an unrelated native owner or weakening the closure test. PostgreSQL's seven reported historical-agent failures occurred before rollback: migrated engine metadata had its optional floor column, while the fresh reference intentionally omitted it. The independent reference fixture now includes that exact nullable BIGINT metadata representation; whole-catalog equality and all rollback/foreign-write assertions remain. Fresh production bootstrap remains unchanged. The tool-usage predecessor refusal now asserts the correct derived floor43, not44. The malformed-owner negative uses a non-NULL default because DEFAULT NULL is now intentionally additive. The unrelated startup timing case from openclaw#204943 is owned by the maintainer's override; this repair neither changes nor reruns it. Owning local schema/PostgreSQL lanes initially failed during dependency setup, before tests, when parallel ocx installs rematerialized a shared checkout; source-identical committed-head serial proof runs in an isolated checkout instead. CI on652ae1d9aa remains the full proof. Latest consolidated scope against8aaf3820112a: **87 files, +1604/-333, net1271**; production/config49 +920/-233 (net687), tests37 +642/-92 (net550), versioning doc +42/-8 (net34). Head652ae1d9aa differs from consolidated repair e57d895 only by its approved allocation record. Kysely guardrails passed; final local/CI outcomes are not claimed before completion. ## Merged native-observer compatibility Main was merged once to include openclaw#205022's migration observer. Its catalog capture happens before every observed statement, so the private NULL probe now permits only the observer's read-only catalog PRAGMAs/schema reads in addition to its scalar CHECK evaluation, and clears its authorizer before disposal. Writes, user-table reads and nondeterministic functions remain denied; neither the observer nor source guards changed. Merged-tree local proof: **45/45 passed** (migration-chain5, classifier/cold-worker/real-step44 tests40), log `ReaderFloor-consolidated-repairs/observer-merged.log`. Earlier owning schema proof was71/71; wrapper closure23/23 and provisioner17 cases passed, with only the independently observed plain-main macOS sparse-transition120s timeout remaining locally. PostgreSQL's hand-built pre-merge local proof had later credential-restore/transaction errors; it is not claimed green, and the maintainer designated CI's PostgreSQL conformance as authoritative. Current head **c946b3fc75**, measured against main merge-base **5f9e215d2a**: **87 files, +1614/-333, net1281**; production/config49 net697, tests37 net550, versioning doc net34. Allocation150 is unchanged. All task-owned local PostgreSQL/container and scratch resources have been released. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #204880 A build currently refuses every database written at a newer schema version, even when the change only adds storage that the older build can safely ignore. This prevents a previous Gateway from reopening compatible state after an update trial. The next stable can reopen future SQLite state, agent stores, and PostgreSQL schemas when their recorded reader floor permits it. Incompatible changes still stop startup with a clear schema refusal. Existing strict stores retain their current format and behavior; this PR does not change update backup policy. The existing version owners publish or clear `min_reader` in the version transaction. An absent/null floor means the writer version, so strict steps need no new storage; the first tolerable step adds a nullable floor column. Pre-v43 agent history stays strict; from v43 the SQLite migration finisher derives tolerance from the migrated predecessor catalog. No schema number is bumped, and port publication is unchanged. Admission, boot preflight and catalog checks preserve the actual writer version while accepting unknown tables and NULL-safe nullable columns. Non-nullable columns, non-NULL defaults, CHECKs rejecting NULL, generated columns, keys and references stay non-additive. Known constraints, triggers and ownership checks remain enforced; PostgreSQL also requires the newer writer's unchanged catalog seal. Newer registry rows remain discovery candidates; the `raised` case in `openclaw-agent-db.checkonce.test.ts` proves that a store whose floor is above this code is still refused at open. Ayaan approved this schema contract change on 2026-11-24 (`state-model-decision.md`). This PR targets main only; the release manager owns any backport. Rollback also retains the valid restored config when automatic recovery finds a newer writer's backup. The existing destructive-action guard remains enforced for an actually loaded newer config; prepared, synchronous and asynchronous recovery share this rule. The independent config-recovery repair is being landed first as a prerequisite (it also affects existing copy-and-swap rollback). Once main contains it, this PR will inherit the same implementation rather than carry a second change. - AWS: 164 SQLite/boot/catalog tests and 44 PostgreSQL tests passed ([run](https://crabbox.openclaw.ai/portal/runs/run_44448ae157b99967d36d4de1029769af)). - Red on unmodified main: SQLite state, SQLite agent, and PostgreSQL writable/read-only admission refuse the same compatible-newer fixtures ([run](https://crabbox.openclaw.ai/portal/runs/run_06577478aecf849ce6463a01fab37b53)). - Two local ClawSweeper rounds completed; verified findings were fixed. The lead reviewed the final registry delta and the subsequent behavior-equivalent type/lint fixes against the exact head. - AWS `check:changed` passed on `956fc25da6`: core/core-test type graphs, lint, format, dead-export checks, SQLite worker/dialect guards, and the remaining selected guards ([run](https://crabbox.openclaw.ai/portal/runs/run_cf80edb44a2a04deba0c2cf62af5810f)). Narrow subsequent auth/guard changes require the checks below. - Linux T/T+1 packages built successfully ([run](https://crabbox.openclaw.ai/portal/runs/run_5eaf078abca514a139d8c599b2092035)). That run exposed the restored-config recovery blocker, which was fixed rather than bypassed. The recovery regression then failed against the old owner and all 56 main config tests passed ([run](https://crabbox.openclaw.ai/portal/runs/run_96332cda9f136830532e490fd55faacb)). **Proof status:** the completed main SQLite downgrade run is recorded below. The built PostgreSQL downgrade cell remains NOT RUN; it is not claimed green. Affected behavior and final-head type checks remain covered by required PR CI. One version owner per store publishes the floor; strict steps retain the existing encoding. The change removes duplicate shared-version publication rather than adding a parallel migration mechanism. The focused column classifier now lives in `sqlite-additive-column.ts` to satisfy the existing owner's line cap; both consumers import it directly, without a facade or re-export. No broad historical fixture rewrites or unrelated documentation changes remain. Follow-up class: the admission rule currently spans about 15 independent version gates; consolidate them behind one admission owner so a future rule change is one edit. This PR only changes their existing decisions and required propagation. <details> <summary>LSP production reader inventory</summary> LSP references were collected before edits; its index is anchored to the primary checkout, so coordinates are not claimed for these frozen worktrees. New worktree-only consumers are named explicitly below. Paths without a prefix are under `src/state/`. - Shared version gate: `openclaw-state-db-schema-version.ts`, `openclaw-state-db-maintenance.ts`, `openclaw-state-db-fast-path.ts`, `openclaw-state-db-existing-schema.ts`, `openclaw-state-db-open.ts`, `openclaw-state-db-read-schema.ts`, `openclaw-state-db-existing-write.ts`, `openclaw-state-db-startup-checkpoint.ts`, `openclaw-state-db-schema-runtime.ts`, `openclaw-state-db-read-connection.ts`, `openclaw-state-db.ts`, `startup-metadata-live-read.worker.ts`, `src/plugins/update-cohort-recovery.ts`, `src/snapshot/openclaw-snapshot-copy.ts`, `src/snapshot/git-backup-codec.ts`, `src/agents/harness/native-hook-relay-client-read.ts`. New floor-read consumers: `openclaw-state-schema-preflight.ts`, `src/infra/sqlite-schema-header.ts`. - Agent version gate: `openclaw-agent-db-schema-read.ts`, `openclaw-agent-db-owner-read.ts`, `openclaw-agent-db-readonly-open.ts`, `openclaw-agent-db-schema.ts`, `openclaw-agent-db-maintenance.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`, `src/infra/database-engine/agent-port-descriptor.ts`, `src/infra/state-migrations.media-persistence.ts`, `src/snapshot/git-backup-codec.ts`, `src/snapshot/openclaw-snapshot-copy.ts`. Current-agent metadata gate: `openclaw-agent-db-engine.ts`, `openclaw-agent-db-schema-helpers.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`. - PostgreSQL physical admission: `src/infra/database-engine/open.ts`, `openclaw-state-db-engine.ts`. Schema verification: `src/infra/database-engine/physical-facts.ts`, `src/infra/database-engine/adapters.ts`. Engine-open callers: `openclaw-state-db-open.ts`, `openclaw-agent-db-engine.ts`, `openclaw-state-db-engine.ts`, `src/infra/database-engine/historical-index-ordering-port.ts`, `src/infra/database-engine/state-port-descriptor.ts`; Plugin SDK re-export unchanged. - Runtime inspection/preflight: `openclaw-agent-schema-inspection.worker.ts`, `openclaw-database-preflight.ts`, `openclaw-state-read-operation-registry.ts`. Preflight entry callers include Doctor database preflight, startup client credentials, preflight contexts, update-data-at-risk, auto-update compatibility, daemon status, Gateway bootstrap/startup maintenance, Doctor lease refusal and agent admission. Explicit updater-target policy remains strict. - Audit catalog admission: `openclaw-state-db-audit-migration.ts`, `openclaw-state-db-schema-repair.ts`. Canonical session-validation catalog admission: `openclaw-agent-canonical-validation-schema.ts`, `openclaw-agent-canonical-validation-receipt.ts`, `openclaw-agent-db-validation-cache.ts`, `openclaw-agent-db-readonly-open.ts`, `openclaw-agent-db-schema-admission.ts`, `openclaw-agent-db.ts`, `openclaw-agent-db-schema-refresh.ts`, `src/config/sessions/session-canonical-key.ts`. - Registry candidate filtering: `openclaw-agent-db-registry-listing.ts` (inspection, memo and snapshot paths), `src/infra/update-data-at-risk.ts`, `src/commands/doctor-db-bloat.read.ts`. Actual store admission remains the floor authority. - Config recovery's existing future-version guard is now consulted by the shared recovery plan builder. LSP callers: `io.observe-recovery.ts` prepared and immediate recovery entrypoints; synchronous/asynchronous startup loaders at `src/config/io.load.ts:210-212`; prepared snapshot recovery at `src/config/io.snapshot.ts:486`. Actual current-config admission in Gateway pre-bootstrap is unchanged. - Auth-profile reader admission: LSP production consumers `src/agents/auth-profiles/sqlite-json.ts:187,210` and `src/agents/auth-profiles/sqlite.ts:239,361` now use the canonical agent floor gate. Pooled same-version reuse remains query-free; a changed supplied version is checked once. </details> The maintainer approved allocation **150** for measured net test growth550: the prior127, optional-floor reference metadata (5), persisted-floor/refusal proof (2), cold-worker zero-comparison-DDL coverage (6), and cap-required fixture extraction/imports/formatting (10). The obsolete strict43-reader refusal case is replaced by actual44-writer/floor43 admission and old-writer NULL insertion proof. Only a redundant step-presence assertion was removed; exact rollback, ownership, catalog and constraint assertions remain. | Test file (`src/` unless otherwise qualified) | + / - | Protected contract | | --- | ---: | --- | | `agents/auth-profiles.sqlite-read-pool.test.ts` | 42 / 0 | Retained/raised floors through projected/plain auth readers; query-free warm reuse. | | `config/sessions/startup-migration.acp.test.ts` | 4 / 1 | Legacy admission uses consistent header/ownership markers. | | `infra/database-engine/bridge-prestart.test.ts` | 1 / 0 | PostgreSQL admission facts carry the required floor. | | `infra/database-engine/physical-facts.test.ts` | 2 / 2 | Strict metadata keeps absent-floor compatibility. | | `infra/database-engine/schema-admission.postgres.test.ts` | 172 / 1 | Writable/read-only T+1 admission; malformed/raised floors; nullable versus constrained catalogs; seals and rollback. | | `infra/sqlite-schema-facts.test.ts` | 42 / 0 | Warm future-reader cache stays query-free and rejects floors raised after schema/version invalidation. | | `infra/sqlite-schema-header.test.ts` | 9 / 5 | Floor/ownership survive inspection; native lock/WAL fixtures carry historical agent metadata. | | `state/openclaw-agent-db-registry-listing.snapshot.test.ts` | 2 / 2 | Future stores remain discovery candidates, not implicitly admitted stores. | | `state/openclaw-agent-db.checkonce.test.ts` | 120 / 5 | SQLite agent admission, readonly open, metadata preservation and transactional floor publication/rollback. | | `state/openclaw-agent-db.committed-read.test.ts` | 4 / 1 | A legacy replacement is refused before invoking its reader. | | `state/openclaw-database-preflight.startup-prepared.test.ts` | 7 / 1 | Boot preflight retains the actual legacy migration refusal. | | `state/openclaw-schema-metadata.test.ts` | 15 / 0 | SQLite ownership metadata/floor contract. | | `state/openclaw-state-db-checkonce.test.ts` | 1 / 1 | Cold content/floor read still executes exactly once. | | `state/openclaw-state-db-cron-delivery-migration.test.ts` | 1 / 1 | Managed snapshot qualification retains its exact query sequence. | | `state/openclaw-state-db-schema-version.test.ts` | 83 / 1 | SQLite state T+1 admission, raised-floor refusal and atomic floor publication/rollback. | | `state/openclaw-state-read.owned-native-token.test.ts` | 7 / 4 | Snapshot files and stable SHM bytes remain exact; only documented read marks may vary. | | `state/openclaw-state-read.worker.test.ts` | 1 / 0 | PostgreSQL worker facts retain the floor. | | `state/openclaw-agent-active-event-facts-migration.postgres.test.ts` | 1 / 1 | Strict legacy reader-floor refusal reports floor41 versus reader40. | | `state/openclaw-approval-profile-migration.postgres.test.ts` | 1 / 1 | Strict state reader-floor refusal reports floor41 versus reader40. | | `state/openclaw-worker-provision-source-migration.postgres.test.ts` | 1 / 1 | Strict state reader-floor refusal reports floor41 versus reader39. | | `extensions/workboard/src/postgres-store.test.ts` | 1 / 1 | A legacy strict workboard floor refuses the unsupported reader. | | `state/openclaw-agent-tool-usage-migration.postgres.test.ts` | 5 / 3 | Persists derived floor43 after strict42/43 plus additive44, and refuses reader41. | | `state/openclaw-agent-schema-inspection-worker.test.ts` | 16 / 0 | A future agent floor is read even when ownership projection is not requested. | | `state/openclaw-database-preflight.artifacts.test.ts` | 2 / 2 | Locked source fixture retains the real agent metadata shape; lock/readiness assertions unchanged. | | `commands/backup-verify.test.ts` | 4 / 4 | Wrong-role/path negatives carry otherwise complete agent metadata; rejection assertions unchanged. | | `commands/doctor-maintenance.schema-preflight.test.ts` | 2 / 2 | A raised agent floor refuses before incomplete registry repairs. | | `flows/doctor-health.dangling-workshop-index.test.ts` | 2 / 2 | Newer agent refusal preserves damaged shared-state bytes. | | `infra/database-engine/admitted-diagnostics.test.ts` | 1 / 1 | Read-free diagnostic agent fixture includes ownership columns. | | `infra/update-database-backup.agent-owners.test.ts` | 2 / 2 | Backup manifest owner discovery uses complete agent metadata. | | `infra/update-database-backup.test.ts` | 1 / 1 | External-agent backup fixture matches its existing version17 header. | | `state/openclaw-state-worker-loss-recovery.postgres.test.ts` | 4 / 1 | Newly merged v42 migration still refuses its v41 reader, asserting the floor diagnostic dynamically. | | `infra/sqlite-schema-contract.test.ts` | 25 / 16 | NULL-safe CHECK/default positives; six non-additive negatives, retaining strict known-object checks. | | `state/openclaw-agent-member-access-migration.test.ts` | 30 / 19 | Real step44 retains floor43 and old-reader/write compatibility; commit/rollback, sharing, witness and exact shipped PG SQL stay covered. | | `infra/database-engine/doctor-migration.postgres.test.ts` | 6 / 9 | Exact seven historical-agent upgrade/rollback catalogs; coherent fixture extraction keeps the owner within its line cap. | | `infra/database-engine/doctor-migration.postgres.test-support.ts` | 16 / 0 | Independent relocated full-catalog reader and optional-floor reference metadata fixture; no comparison filtering. | | `infra/sqlite-schema-contract.worker.test.ts` | 6 / 0 | NULL-safe CHECK drift remains compatible with strictly zero comparison DDL. | | `state/openclaw-state-ownership.test.ts` | 3 / 1 | A truly incompatible non-NULL default still blocks malformed-owner repair without changing its bytes. | The supported-header warm shortcut relies on atomically matching markers and `min_reader <= writer_version`; it does **not** short-circuit newer headers. The `raised` case in `openclaw-agent-db.checkonce.test.ts` asserts refusal at physical open, and the new `sqlite-schema-facts.test.ts` schema/version-invalidation cases require `SqliteSchemaVersionError` after a floor rises above this build. These new-head checks remain part of the explicitly outstanding proof, not a claim of final-head green. [AWS run `run_9344a01fac267cad3cc0253546ab206b`](https://crabbox.openclaw.ai/portal/runs/run_9344a01fac267cad3cc0253546ab206b) completed the real packed main agent44→45 Gateway cases. T reached readiness with T+1's retained-floor shared/agent stores, including the first newly added nullable floor storage; agent-only retained snapshots also reached readiness. Raised shared and agent-only floors both refused with exit78. Metadata and seeded session rows were preserved. Main auth tests, SQLite floor/CI regressions and PostgreSQL floor regressions passed; Kysely passed. The run used frozen main `546bde6b` before later warm-path and fixture corrections, so it is not presented as a blanket final-head CI result. The five canonical `check-test-types-core-*` jobs passed on run `45517151870`; the ad-hoc proof typecheck configuration was discarded rather than loosening its libraries. **PostgreSQL built downgrade cell: NOT RUN.** The initial run stopped at T+1 Doctor's strict pre-repair predecessor catalog check; the repaired predecessor fixture is prepared but its bounded replay could not run. Both standard-profile AWS allocations (including the single retry after capacity was freed) were quota-rejected down to an undersized `t3.small`; both leases were released without launching builds. PostgreSQL floor unit regressions passed. No backup/catalog gate was bypassed and no PG downgrade boot is claimed. Per the maintainer's decision, this capacity gap does not block the SQLite-proven PR; required CI and review still apply. [Controlled AWS comparison `run_f1242c2eb06315326ef5805841e000b1`](https://crabbox.openclaw.ai/portal/runs/run_f1242c2eb06315326ef5805841e000b1) ran the single Codex runtime test on the actual release merge candidate `adbb7d9d` (head `8b9199fd`) and its base `6b006bb1`, using the same pinned Bun and Node24.22.1. **Both reproduced the identical45000ms timeout.** Base/head wall time was114.352s/114.205s; Vitest110.85s/110.71s; max RSS5405548/5225840KiB. No head slowdown was observed in this isolated comparison. This is baseline reproduction, not a passing test or a “flake cleared” claim. The optional SQL trace covered diagnostics_channel only and does not establish absence of native SQLite calls. One local `ocx test --no-memo src/state/openclaw-agent-schema-inspection-worker.test.ts` run on `6f3417a4c8` was **red**: only the new 45/min_reader44, ownership-disabled case failed because minReader44 was omitted (7 existing tests passed). One run on the fixed `acaf8043a6` head was **green: 8/8**. Proof tier: vitest-source, no build. Agent inspection always reads the agent metadata floor; only the ownership result is optional, and the state floor owner is unchanged. This is review round2/2; no additional full review was requested. Historical ownership check: the first agent-store commit `fc50f949` (#88349), shipped `v2026.5.30-beta.1`, and retained stable `v2026.7.35` all have required `role` and `schema_version` metadata. The `git log --follow -S 'schema_version INTEGER'` history contains no shipped removal. Four minimal two-column test fixtures were corrected in place, with no assertion/timing changes or net test growth; no legacy product fallback was added. Focused local fixture proof (vitest-source, no build): one `ocx test --no-memo src/state/openclaw-database-preflight.artifacts.test.ts src/infra/sqlite-schema-header.test.ts` invocation passed **19/19** (9 preflight, 10 header), including unchanged lock tolerance, hot-journal and WAL byte-preservation cases. Completed a full `CREATE TABLE schema_meta` / agent_id fixture inventory across `src` and `test`, including multiline/quoted forms. All remaining synthetic agent fixtures now carry role/schema_version; the deliberately malformed populated-v0 refusal fixture remains malformed by design. Shared/global, credential-source and generic engine-scope fixtures are not agent stores and remain unchanged. The sweep changes only SQL fixture lines (12 replacements/net0), not assertions or timeouts. One local `ocx test --no-memo` invocation of all six sweep files passed **87 tests, 1 Windows-only skip** on main (43 infra +44 commands); proof tier vitest-source/no build. Total main diff after the newly merged PostgreSQL refusal diagnostic correction: **77 files, +1331/-268 (net1063)** against merge-base `8aaf3820112a`; production/config +740/-216, tests +552/-45, versioning doc +39/-7. After merging main's new shared schema42, PostgreSQL conformance run45543740954/job138969182913 exposed its newly introduced worker-loss migration test's old `is newer` diagnostic expectation. The actual refusal correctly required floor42 versus reader41. Updated only that expectation to the dynamic minimum-reader diagnostic; a sweep of all `*.postgres.test.ts` under `src`/`test` found no other remaining `is newer` refusal expectation. Green PostgreSQL execution of this narrow correction is left to required CI, not claimed from a skipped local test. `src/infra/sqlite-additive-column.ts` is the single column predicate. Its SELECT-only evaluator replaces the earlier candidate CREATE/INSERT probe: it parses nullable/default/CHECK clauses and evaluates scalar CHECK expressions over an explicit NULL value under deterministic-function authorization. It executes no comparison DDL and never touches source state. Non-nullable/unsafe default/key/reference/generated declarations stay incompatible; bare-type and warm admission paths retain their existing fast paths. `src/state/openclaw-agent-db-schema-helpers.ts:450` compares the migrated catalog with the actual predecessor before atomically stamping the version and derived floor. Pre-v43 history remains strict. PostgreSQL step44 computes its existing `minReader` property lazily through the same predicate (`openclaw-agent-member-access-schema.ts:10`, `openclaw-agent-db-engine.ts:431`), with no hand-declared floor43. Its generated migration SQL is asserted **byte-identical** to main's shipped SQL. Removed: the obsolete strict43-reader refusal test and the claimed43→44 pre-image requirement. There is no step44-specific production copy/pre-image branch to retain; generic backup restoration proof remains. Witness normalization treats `min_reader` like the existing version/app/time migration metadata; raw same-version schema/content hashes remain exact. This update adds **no persistent application column or table beyond the min_reader storage already present at870ef9ba31**, and the final classifier also performs **zero comparison DDL**. Proof: the two owning files on baseline870ef9ba31 with the new regression were **red: 4 intended failures, 35 passing**. Final main-only change **7f02f3b218** is **green: 39/39** via `ocx test --no-memo src/infra/sqlite-schema-contract.test.ts src/state/openclaw-agent-member-access-migration.test.ts` (vitest-source/no build). Logs: `ReaderFloor-null-safe-check/red-870ef9ba31.log`, `green-final.log`. Intermediate helper-regex and witness failures were corrected in their owners; no assertion/timeout masking. Latest measured scope against8aaf3820112a, superseding earlier historical counts: **82 files, +1485/-321, net1164**; production/config48 +836/-233 (net603), tests33 +607/-80 (net527), versioning doc +42/-8 (net34). Allocation127 covers the requested step44 contract and six negatives. Architecture CI's native-opener guard found one owned integration issue at7f02f3b218: the disposable classifier probe used the raw constructor. Fixed only its opener/import through `openNodeSqliteDatabase` (no exemption); owning39tests and `pnpm lint:kysely` both pass. Repair748ab989ac is +3/-3, no net scope growth or schema change. Logs: `ReaderFloor-null-safe-check/canonical-opener-tests.log`, `canonical-opener-guard.log`. The SELECT-only helper's +83 production lines replace its DDL probe while preserving the cold-worker zero-comparison-DDL contract. The trusted PR wrapper legitimately imports this schema-rule owner through its already-inventoried schema contract; `scripts/pr-lib/wrapper-components.txt` now declares the extracted helper (one path), rather than relocating a schema rule into an unrelated native owner or weakening the closure test. PostgreSQL's seven reported historical-agent failures occurred before rollback: migrated engine metadata had its optional floor column, while the fresh reference intentionally omitted it. The independent reference fixture now includes that exact nullable BIGINT metadata representation; whole-catalog equality and all rollback/foreign-write assertions remain. Fresh production bootstrap remains unchanged. The tool-usage predecessor refusal now asserts the correct derived floor43, not44. The malformed-owner negative uses a non-NULL default because DEFAULT NULL is now intentionally additive. The unrelated startup timing case from #204943 is owned by the maintainer's override; this repair neither changes nor reruns it. Owning local schema/PostgreSQL lanes initially failed during dependency setup, before tests, when parallel ocx installs rematerialized a shared checkout; source-identical committed-head serial proof runs in an isolated checkout instead. CI on652ae1d9aa remains the full proof. Latest consolidated scope against8aaf3820112a: **87 files, +1604/-333, net1271**; production/config49 +920/-233 (net687), tests37 +642/-92 (net550), versioning doc +42/-8 (net34). Head652ae1d9aa differs from consolidated repair e57d895 only by its approved allocation record. Kysely guardrails passed; final local/CI outcomes are not claimed before completion. Main was merged once to include #205022's migration observer. Its catalog capture happens before every observed statement, so the private NULL probe now permits only the observer's read-only catalog PRAGMAs/schema reads in addition to its scalar CHECK evaluation, and clears its authorizer before disposal. Writes, user-table reads and nondeterministic functions remain denied; neither the observer nor source guards changed. Merged-tree local proof: **45/45 passed** (migration-chain5, classifier/cold-worker/real-step44 tests40), log `ReaderFloor-consolidated-repairs/observer-merged.log`. Earlier owning schema proof was71/71; wrapper closure23/23 and provisioner17 cases passed, with only the independently observed plain-main macOS sparse-transition120s timeout remaining locally. PostgreSQL's hand-built pre-merge local proof had later credential-restore/transaction errors; it is not claimed green, and the maintainer designated CI's PostgreSQL conformance as authoritative. Current head **c946b3fc75**, measured against main merge-base **3f2e0ade38**: **87 files, +1614/-333, net1281**; production/config49 net697, tests37 net550, versioning doc net34. Allocation150 is unchanged. All task-owned local PostgreSQL/container and scratch resources have been released. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit cf9a46d) Release adaptation: release lacks agent schema v44 (session member access) and state schema v42 (worker-loss recovery), so their migration files and member-access reader-floor hunks are omitted; openclaw-agent-db-engine.ts takes only the admission/minReader hunks. Postgres migration tests take the source reader-floor assertions. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
Summary
agents/<agentId>/agent/openclaw-agent.sqlite, registered from the globalagent_databasesindex.Verification
pnpm test src/state/openclaw-agent-db.test.ts src/agents/cache/agent-cache-store.sqlite.test.ts -- --reporter=verbosepnpm tsgo:corepnpm tsgo:core:testpnpm db:kysely:checkpnpm lint:kyselygit diff --check/Users/steipete/Projects/agent-skills/skills/autoreview/scripts/autoreview --mode local-> clean, no accepted/actionable findingsenv -u OPENCLAW_TESTBOX mise exec [email protected] -- pnpm check:changedReal behavior proof
Behavior addressed: Adds the next per-agent SQLite storage slice: database lifecycle, schema metadata, global registration, and a scoped per-agent cache table for rebuildable runtime state.
Real environment tested: Local macOS checkout with Node 24.16.0 for the changed gate; focused Vitest/unit checks against real Node SQLite; delegated Blacksmith Testbox attempted separately.
Exact steps or command run after this patch: The commands listed in Verification were run after the final commit. The Node 24 changed gate used repo
pnpmdirectly becausecorepack pnpmselected pnpm 11.3.0 and failed the repo package-manager version preflight before checks.Evidence after fix: Focused tests pass 14 assertions across the new agent DB and cache store. Local Node 24
pnpm check:changedcompleted core/core-test typecheck, core/scripts lint, import-cycle, runtime-sidecar, and guard checks successfully. Autoreview initially found explicit-path ownership/test-isolation bugs; both were fixed with regression tests and the final autoreview run was clean.Observed result after fix: Per-agent DBs are created under the same state root as the global DB, including Vitest worker isolation; explicit DB paths cannot be shared across agent ids; explicit paths pointing at the global state DB are rejected before agent schema application; scoped cache rows preserve JSON/blob values and hide/clear expired entries.
What was not tested: No production caller was switched to this cache store yet, and no live agent workflow depends on it in this PR. Delegated Testbox
pnpm check:changedontbx_01kswkj9rce9m2gr1f334za01kfailed in unrelatedsrc/agents/embedded-agent-runner/model.tstype errors outside this diff; a local Node 24 changed gate passed on the exact branch.