@@ -191,8 +191,9 @@ without exceptions outside doctor/import/export/debug boundaries.
191191- No active session files.
192192- No fake JSONL test fixtures except doctor legacy migration tests.
193193- No raw SQLite access where Kysely is expected.
194- - No new legacy DB migrations. This layout has not shipped; keep schema version
195- at ` 1 ` unless there is a strong reason.
194+ - No new file-era DB migrations. The global schema remains at version ` 1 ` .
195+ The shipped per-agent version ` 1 ` schema has one bounded runtime migration to
196+ version ` 2 ` for stable memory-source identities.
196197
197198## Code-Read Assumptions
198199
@@ -206,9 +207,9 @@ proceed with these assumptions:
206207- Runtime compatibility files are not required. Legacy JSON and JSONL files are
207208 migration inputs only. The branch-local SQLite sidecars never shipped and are
208209 deleted instead of imported.
209- - ` openclaw doctor --fix ` owns the legacy file-to-database migration step.
210- Runtime startup and ` openclaw migrate ` should not carry legacy OpenClaw
211- database-upgrade paths .
210+ - ` openclaw doctor --fix ` owns legacy file-to-database migration. Runtime
211+ startup owns only bounded upgrades between shipped SQLite schema versions;
212+ it must not import file-era state .
212213- Credential compatibility follows the same rule: runtime credentials live in
213214 SQLite. Old ` auth-profiles.json ` , per-agent ` auth.json ` , and shared
214215 ` credentials/oauth.json ` files are doctor migration inputs, then removed
@@ -295,10 +296,10 @@ The branch already has a real shared SQLite base:
295296- Runtime stores derive selected and inserted row types from those generated
296297 Kysely ` DB ` interfaces instead of shadowing SQLite row shapes by hand. Raw SQL
297298 remains limited to schema application, pragmas, and migration-only DDL.
298- - The SQLite schemas are collapsed to ` user_version = 1 ` because this database
299- layout has not shipped yet. Runtime openers create the current schema only;
300- file-to-database import remains in doctor code, and branch-local
301- database upgrade helpers have been deleted .
299+ - The global SQLite schema remains at ` user_version = 1 ` . The per-agent schema
300+ is at version ` 2 ` ; its opener atomically migrates the shipped version ` 1 `
301+ memory-source key to a stable integer identity. File-to-database import
302+ remains in doctor code .
302303- Relational ownership is enforced where the ownership boundary is canonical:
303304 source migration rows cascade from ` migration_runs ` , task delivery state
304305 cascades from ` task_runs ` , and transcript identity rows cascade from
@@ -333,8 +334,9 @@ The branch already has a real shared SQLite base:
333334 ` agent_databases ` registry instead of reimplementing that query at each call
334335 site.
335336- Global and per-agent databases record a ` schema_meta ` row with database role,
336- schema version, timestamps, and agent id for agent databases. The layout still
337- stays at ` user_version = 1 ` because this SQLite schema has not shipped yet.
337+ schema version, timestamps, and agent id for agent databases. The global DB
338+ remains at ` user_version = 1 ` ; per-agent DBs use version ` 2 ` after the bounded
339+ memory-source identity migration.
338340- Per-agent session identity now has a canonical ` sessions ` root table keyed by
339341 ` session_id ` , with ` session_key ` , ` session_scope ` , ` account_id ` ,
340342 ` primary_conversation_id ` , timestamps, display fields, model metadata,
@@ -1498,13 +1500,15 @@ tool_artifacts(run_id, artifact_id, kind, metadata_json, blob, created_at)
14981500run_artifacts(run_id, path, kind, metadata_json, blob, created_at)
14991501trajectory_runtime_events(session_id, run_id, seq, event_json, created_at)
15001502memory_index_meta(key, value)
1501- memory_index_sources(path, source, hash, mtime, size)
1503+ memory_index_sources(id, path, source, hash, mtime, size)
15021504memory_index_chunks(id, path, source, start_line, end_line, hash, model, text, embedding, updated_at)
15031505memory_embedding_cache(provider, model, provider_key, hash, embedding, dims, updated_at)
15041506memory_index_state(id, revision)
15051507cache_entries(scope, key, value_json, blob, expires_at, updated_at)
15061508```
15071509
1510+ ` memory_index_sources.id ` is the stable integer primary key; ` (path, source) ` remains unique.
1511+
15081512Future search can add FTS tables without changing the canonical event tables:
15091513
15101514``` text
@@ -1824,9 +1828,9 @@ Backups remain one archive file:
18241828 ` openclaw backup create ` does this archive verification by default;
18251829 ` --no-verify ` skips only the post-write archive pass, not the snapshot
18261830 creation integrity check.
1827- - Restore copies snapshots back to their target paths. This branch resets the
1828- unshipped SQLite layout to ` user_version = 1 ` ; future shipped schema changes
1829- can add explicit migrations when they are needed .
1831+ - Restore copies snapshots back to their target paths. Restored global DBs use
1832+ version ` 1 ` ; restored per-agent DBs use version ` 2 ` , with version ` 1 ` snapshots
1833+ upgraded atomically when opened .
18301834
18311835### Phase 6: Worker Runtime
18321836
@@ -1874,17 +1878,18 @@ agent id, schema version, source path, snapshot path, byte size, and integrity
18741878status.
18751879
18761880Restore should rebuild the global database and agent database files from the
1877- archive snapshots. Because the SQLite layout has not shipped yet, this refactor
1878- keeps only the version-1 schema plus doctor file-to-database import. The restore
1879- command validates the archive first, then replaces each manifest asset from the
1880- verified extracted payload.
1881+ archive snapshots. The global schema remains version ` 1 ` ; per-agent version ` 1 `
1882+ snapshots receive the bounded runtime upgrade to version ` 2 ` . Doctor remains
1883+ the only owner of file-to-database import. The restore command validates the
1884+ archive first, then replaces each manifest asset from the verified extracted
1885+ payload.
18811886
18821887## Runtime Refactor Plan
18831888
188418891 . Add database registry APIs.
18851890 - Resolve global DB and per-agent DB paths.
1886- - Keep the unshipped schemas at ` user_version = 1 ` ; do not add schema
1887- migration runner code until a shipped schema needs it .
1891+ - Keep the global schema at ` user_version = 1 ` . Per-agent DBs use version ` 2 `
1892+ with one atomic migration from the shipped version ` 1 ` memory-source shape .
18881893 - Add close/checkpoint/integrity helpers used by tests, backup, and doctor.
18891894
189018952 . Collapse sidecar SQLite stores.
0 commit comments