Skip to content

improve(memory): drop embedding cache copies the published index already serves - #195369

Merged
roboclaw-bot merged 5 commits into
openclaw:mainfrom
etzelm:perf/memory-retire-published-cache-duplicates
Nov 13, 2026
Merged

roboclaw-bot merged 5 commits into
openclaw:mainfrom
etzelm:perf/memory-retire-published-cache-duplicates

Conversation

@etzelm

@etzelm etzelm commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Refs #168777

What Problem This Solves

The memory embedding cache keeps a second full copy of every vector the published memory index already holds, so most of a large cache (64% of a 50,000-row cache in #168777) is duplicate data.

User Impact

User impact: memory databases stop growing a second copy of published vectors. On a 4096-dim store the cache table drops from 32.9 MB to 0.95 MB after the first full rebuild, with no new embedding calls. The cost: text copied into a different memory file, and switching back to an earlier provider or model, are embedded again (details below). No schema change and no user action.

Why This Change Was Made

Stage 1a (#185968) lets ordinary memory-file edits reuse vectors from the published index. The embedding cache still keeps its own copy of every vector it wrote, so most cache rows duplicate a published chunk. This change deletes those copies after a successful publication, in two commits:

  • 1b (perf(memory): retire cache rows a publication already serves): after an ordinary sync publishes its memory files, and after a full rebuild publishes, the cache rows that run wrote are deleted when the published index holds the same bytes.
  • Step 2 (perf(memory): retire existing cache duplicates after a full rebuild): after a full rebuild publishes, older rows that the new index holds are deleted too. This commit can be dropped on its own (the "1b only" option below).

Accepted decision: both-stage cache retirement

On November 13, 2026, @Patrick-Erichsen instructed landing after the retention alternatives and their re-embedding costs were disclosed in the review and landing discussion. This records acceptance of the current proposal: both 1b and step 2, including the three re-embedding costs below. The linked discussion is for team reference and requires sign-in.

This is the maintainer acceptance of the intentional valid-cache retention change required by docs/reference/database-schemas/storage-changes.md, "Review checkpoint for material changes". No source or retention semantics were changed to obtain acceptance.

Alternatives considered:

  • Accept both commits (recommended). New duplicates are deleted after each clean publication, and existing duplicates after the next full rebuild. In the upgrade run below, a forced rebuild takes the cache from 977 rows on base to 14 on head, with 0 embedding inputs and the same published vectors.
  • Accept 1b only. Drop perf(memory): retire existing cache duplicates after a full rebuild. Rows written after the upgrade are retired as in A. Rows already in the cache stay until the cap prune evicts them. Not measured separately.
  • Reject. Close this PR. The cache keeps every duplicate up to the cap, and none of the costs below apply.

Why both: each cost below is paid as one embedding call per affected chunk, like any cache miss today; switching back to an earlier provider or model can re-embed the whole store. None changes what is published or searched: chunk checksums and search hits match base after every step below. The savings grow with the store: 64% of a 50,000-row cache in #168777, and on the upgraded 2026.11.2 store below the cache vectors go from 500,224 B on base to 7,168 B on head. Rolling back to the newest build without this PR needs no repair: base works on a cleaned store with the same inputs and results as on its own store (table under "Rolling back"). Accepting 1b only keeps an existing store's duplicates until the cap prune reaches them.

The accepted policy:

A cache row of the active primary embedding identity is deleted after a successful publication when every published chunk carrying its text hash holds exactly the same bytes, at least one of those chunks belongs to a memory file, and the published index metadata binds the same provider, model, provider key, input format and dimensions. Nothing else is deleted:

  • a row whose vector differs from any published copy (non-deterministic providers, ambiguous hashes) is kept;
  • unpublished rows, rows for session-only text, alias identities and other identities are kept;
  • a disabled cache keeps its rows;
  • failed, partial and deferred runs keep every row they wrote. The skipped run's start carries to the next sync that finishes cleanly, which deletes those rows only after its publication holds the same bytes.

Accepting this means accepting these re-embedding costs, which the cache used to absorb:

  1. Text copied or moved into a different memory file. Read-through from 1a is scoped to the file being indexed, so a retired vector for text that appears in another file is embedded again.
  2. Switching back to a previous provider or model. After a full rebuild under identity A, A's cache rows are gone. Rebuilding under B and then back under A embeds everything again. On main, A's rows could survive in the cache up to the cap.
  3. Downgrading to a build without published read-through (before 198b761). Unchanged chunks of edited memory files are embedded again, because the cache no longer has them.

How it runs

  • New cache.retire command on the SQLite publication worker and the PostgreSQL binding. One write transaction handles one page of up to 256 candidates in (updated_at, hash) order on idx_memory_embedding_cache_updated_at, with one chunk read per page. The caller yields between pages and stops while closing.
  • Fences:
    • Ordinary sync: rows written since the sync started, or since the oldest earlier sync that did not finish cleanly.
    • Full rebuild: rows written since the rebuild started (1b), then rows written before it started (step 2). The two fences meet at the rebuild start.
  • Gates: it runs only when the cache is enabled, and on ordinary syncs only when the memory sync returned normally with no dirty or full-retry state.
  • It runs before the cap prune, after publication, outside every publication transaction. Publication transactions gain no work. A retirement error is logged and never fails the sync, marks retry state or records a reindex failure.
  • No schema change and no new index. The 1a metadata gate is shared through readMemoryPublishedVectorMeta.

Evidence

Measured costs

On a fresh store, the CLI proof drove the built openclaw memory index and openclaw memory search through a loopback /v1/embeddings stub with 64 and 4096 dimensions. It ran on 120 memory files with 965 distinct chunks, comparing base 476cce7 against this head. Chunk checksums are identical between the two builds after every step.

step base: inputs embedded head: inputs embedded base: cache rows head: cache rows
initial full index 940 940 940 0
prepend a paragraph to 10 files 20 20 960 0
copy 10 indexed paragraphs into other files 0 10 960 0
failed run (3 of 15 files written) 12 (6 ok) 12 (6 ok) 966 6
retry 24 24 990 6
full rebuild 0 0 990 0

With 4096 dimensions, the same sequence leaves a 32,952,320 B cache table on base and 4,096 B on head. The failed run's 6 rows stay until the full rebuild here, because each CLI command is a new process. A long-lived manager deletes them at its next clean sync.

Upgrading an existing store (head run on the base store above): ordinary syncs leave older rows in place. The first full rebuild takes the cache from 990 rows to 28, the 28 that no published chunk holds, and embeds nothing. At 4096 dimensions the table goes from 32,952,320 B to 946,176 B.

Time and lock hold (synthetic SQLite store, 4096 dimensions, both passes run back to back):

store cache table rows retired pages total page p50 page p95 page max
22,000 chunk rows, 23,000 cache rows 765 MB to 173 MB 17,800 91 7.6 s 75 to 91 ms 124 to 158 ms 182 ms
44,000 chunk rows, 46,000 cache rows 1.53 GB to 346 MB 35,600 181 24.9 s 113 to 159 ms 162 to 262 ms 395 ms

Each page holds the writer for well under the 5 s busy timeout discussed in #143640. The cost per page grows with the chunk table, because chunks have no hash index and each page reads the chunks for its 256 hashes. The database file does not shrink: freed pages are reused by later writes, as after any delete.

Upgrade from latest stable ([email protected]) and data-model compatibility

All runs use the shipped CLI (openclaw memory index/status/search, openclaw doctor --fix, openclaw database port) in isolated OPENCLAW_STATE_DIR/HOME directories, with no Gateway process. Embeddings come from a loopback /v1/embeddings stub (64 dims, deterministic except for one step). PostgreSQL is 17.11 with pgvector 0.8.7 in a local container bound to 127.0.0.1.

Builds:

  • stable: [email protected] from npm (dist-tag latest on 2026-11-08).
  • head: this PR, 9c16f4e, built from source. Later commits change no production code: 8b5b0f0 adds a test and the test-line allocation, and 6a7323d merges main 277e32c (one import conflict in a test file). The production diff against main is line-for-line the same as at 9c16f4e.
  • base: control at the merge-base 476cce7, built from source. Every head run is repeated with base on an identical copy of the same store. That separates this PR from what main already does to a 2026.11.2 store.

The existing store, written by 2026.11.2

Contents 120 memory files, plus the workspace files and one session transcript from a local agent turn (loopback chat stub)
Steps full index (951 inputs); prepend a paragraph to 10 files (20); copy 10 indexed paragraphs into other files (0); copy 5 paragraphs into a new file with the cache disabled and a non-deterministic provider (5 inputs, random vectors)
Agent DB user_version 27
Chunks 996 (995 memory, 1 session); 5 hashes carry two different published vectors
Cache rows 971 rows (497,152 vector bytes): 956 equal to every published copy, 5 differ from a published copy, 10 have no published chunk

SQLite: 2026.11.2 store upgraded to head, with base as control

Head and base both refuse the v27 store until it is migrated: uses schema version 27; stop active agents and run openclaw doctor --fix to upgrade it to schema version 41 before using it. This PR adds no schema change and touches no .sql or src/state file, so the 27 to 41 migration is main's. Each arm ran openclaw doctor --fix --non-interactive, then the steps below.

step inputs embedded (head / base) chunk checksum (head = base) cache rows (head / base)
2026.11.2 store 80149dab 971 / 971
doctor --fix (v27 to v41) 0 / 0 80149dab 971 / 971
memory status 0 / 0 80149dab 971 / 971
3 searches 1 query each 80149dab 971 / 971
index, no edits 0 / 0 80149dab 971 / 971
edit 3 files, index 6 / 6 ea07cfb0 971 / 977
forced rebuild 0 / 0 ef7fdec9 14 / 977
3 searches 1 query each ef7fdec9 14 / 977

Final cache vector bytes: 7,168 on head and 500,224 on base.

  • Existing data loads and works. After the migration, the chunk checksum (decoded vectors, path, line, hash) and the cache checksum equal the 2026.11.2 store. Status, the no-edit index (0 inputs) and all searches work. Every search returns the same hits as 2026.11.2: 6 for a marker in 10 edited files, 1 for a marker in one original file, and 1 for a phrase only in the session transcript.
  • Head and base publish identical data. Chunk checksums match at every step, and a per-row compare of the final stores shows 999 of 999 chunk vectors identical. Among all 76 agent-DB tables, only memory_embedding_cache differs in row count, and the schema is identical.
  • Settings are unchanged. memory_index_meta is byte-identical before and after every step on both arms. doctor --fix rewrites openclaw.json as JSON and adds meta, wizard and skills entries on both arms. The memory, models, plugins, gateway and agents.defaults blocks are semantically identical to the 2026.11.2 file.
  • Duplicates are retired only as described above:
    • Migration, status, search and the no-edit index delete nothing: 971 rows stay through all of them.
    • The 3-file edit writes 6 rows, and head deletes them after publication. Base keeps them.
    • The forced rebuild deletes the older duplicates. Head keeps 14 rows: the 13 whose hash no published chunk carries, and the 1 whose text exists only in the session transcript. All 14 are also in base's final cache.
    • The 5 rows that differed from a published copy are kept through every ordinary sync. On the forced rebuild, both builds republish those 5 chunks with the cached vector (the same 999/999 identical chunks), so the rows stop differing and head retires them.

Rolling back

  • To 2026.11.2: refused, with or without this PR. 2026.11.2 refuses the head-upgraded store and the base-upgraded store with the same error: OpenClaw state database <state>/state/openclaw.sqlite uses newer schema version 39; this build supports 22. ... To use an older build, restore your pre-update backup created with openclaw backup create. Once main has migrated a store, 2026.11.2 cannot open it, so its missing read-through (below) cannot re-embed anything on that store. Going back means restoring the pre-update backup, which still holds the full 2026.11.2 cache.
  • To base 476cce7, the newest build without this PR:
step base on head-cleaned store base on its own store
index, no edits 0 inputs 0 inputs
edit 3 files 6 inputs 6 inputs
forced rebuild 0 inputs 0 inputs
final chunk checksum 3d677fde 3d677fde
searches same hits same hits

Published read-through (198b761) is not in 2026.11.2. The evidence:

PostgreSQL

2026.11.2 has no PostgreSQL memory store, so a stable PostgreSQL upgrade does not exist.

Two substitutes were run instead.

1. Existing PostgreSQL store written by base 476cce7, upgraded to head. The fixture steps match the SQLite store, including the session transcript and the non-deterministic copy. The store was then copied with CREATE DATABASE ... TEMPLATE so head and base each start from identical data.

step inputs (head / base) chunk checksum (head = base) cache rows (head / base)
existing store (schema_meta 41) e33dad37 971 / 971
status, 3 searches, no-edit index 0 / 0 (plus 1 per query) e33dad37 971 / 971
edit 3 files 6 / 6 b9636702 971 / 977
forced rebuild 0 / 0 addc9f90 14 / 977
  • Final cache vector bytes are 7,168 on head and 500,224 on base.
  • schema_meta stays 41, and memory_index_meta is unchanged.
  • Of the 10 memory tables, only memory_embedding_cache differs in row count between head and base.
  • Every search returns the same hits as the SQLite runs.

2. The 2026.11.2 SQLite store moved to PostgreSQL the supported way, then upgraded to head. The steps: doctor --fix, then openclaw database port --to postgres --dry-run, then openclaw database port --to postgres (run with base). The port completed with 0 embedding inputs and rebuilt the memory index on PostgreSQL (996 chunks).

  • After the port, the PostgreSQL store holds 996 chunks and 971 cache rows. The cache checksum equals the 2026.11.2 store's.
  • 991 of 996 chunk vectors are identical to the 2026.11.2 store. The other 5 are the non-deterministic copy, which takes the cached vector in the port's rebuild. That is main's port behavior.
  • Status and all searches work.

Head and base then ran on copies of the ported store:

step inputs (head / base) chunk checksum (head = base) cache rows (head / base)
ported store 7ead0c53 971 / 971
status, 3 searches, no-edit index 0 / 0 (plus 1 per query) 7ead0c53 971 / 971
edit 3 files 6 / 6 50edc75f 971 / 977
forced rebuild 0 / 0 50edc75f 14 / 977

Across all SQLite and PostgreSQL arms, 57 search runs return the same hits as 2026.11.2. The session file id is normalized for the store written on PostgreSQL.

Not covered

  • Rollback to 2026.11.2 after the upgrade. 2026.11.2 refuses any store main has migrated (above), so only base was used as the older build.
  • A stable PostgreSQL upgrade. 2026.11.2 has no PostgreSQL memory store.
  • Gateway processes. Each command is a separate CLI process; no long-lived Gateway process was exercised.
  • Real providers. No real embedding provider was used, and these runs use 64 dims. The 4096-dim measurements are in "Measured costs".
Per-step measurements for every run

Columns: inputs sent to the embedding stub; search hits; agent DB user_version (schema_meta version on PostgreSQL); chunk rows (memory/session); chunk checksum over path, line, hash and the decoded float32 vector; cache rows split by whether the row equals every published copy of its hash, differs from one, or has no published chunk; cache vector bytes; sha256 of the memory_index_meta_v1 value; cache checksum. Step prefixes: P populate, U upgrade, R rollback, T port, X PostgreSQL. stable-rollback-on-head stops at the schema refusal quoted above (exit 1 on every command).

stable-populate (version=2026.11.2 node=v24.22.2)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
P0-agent-turn 0 0 27 0 (0/0) e3b0c44298fc 0 0 / 0 / 0 0 e3b0c44298fc
P1-force-initial 0 951 27 971 (970/1) 397234b12b54 951 951 / 0 / 0 486912 efc8a7f5eff4b661 555a47f420f8
P2-prepend10 0 20 27 981 (980/1) 928375f565e6 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
P3-crosspath10 0 0 27 991 (990/1) 02c77fe8f7c9 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
P4-nondeterministic-copy 0 5 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
P5-status 0 0 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
P6a-search-s2marker 0 1 6 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
P6b-search-origmarker 0 1 1 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
P6c-search-session 0 1 1 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999

head-on-stable (version=2026.11.1 rev=9c16f4e808423fb5d71214988bdde6307b36c158)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
U0-before 0 0 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U0m-doctor-fix 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U1-status 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U2a-search-s2marker 0 1 6 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U2b-search-origmarker 0 1 1 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U2c-search-session 0 1 1 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U3-index-noedit 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U4-edit3 0 6 41 999 (998/1) ea07cfb03f95 971 953 / 5 / 13 497152 efc8a7f5eff4b661 bf5aa467b999
U5-force 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
U6a-search-s2marker 0 1 6 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
U6b-search-origmarker 0 1 1 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
U6c-search-session 0 1 1 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6

base-on-stable (version=2026.11.1 rev=476cce7a8a343ac1524bf12276da839a690cff8a)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
U0-before 0 0 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U0m-doctor-fix 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U1-status 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U2a-search-s2marker 0 1 6 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U2b-search-origmarker 0 1 1 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U2c-search-session 0 1 1 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U3-index-noedit 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
U4-edit3 0 6 41 999 (998/1) ea07cfb03f95 977 959 / 5 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
U5-force 0 0 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
U6a-search-s2marker 0 1 6 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
U6b-search-origmarker 0 1 1 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
U6c-search-session 0 1 1 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18

stable-rollback-on-head (version=2026.11.2 rev=npm state=head-on-stable)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
R0-before 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R1-status 1 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R2a-search-s2marker 1 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R2b-search-origmarker 1 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R2c-search-session 1 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R3-index-noedit 1 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R4-edit3 1 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R5-force 1 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R6a-search-s2marker 1 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R6b-search-origmarker 1 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R6c-search-session 1 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6

base-rollback-on-head (version=2026.11.1 rev=476cce7a8a343ac1524bf12276da839a690cff8a state=head-on-stable)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
R0-before 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R1-status 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R2a-search-s2marker 0 1 6 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R2b-search-origmarker 0 1 1 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R2c-search-session 0 1 1 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R3-index-noedit 0 0 41 999 (998/1) ef7fdec98d1e 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
R4-edit3 0 6 41 1002 (1001/1) 3d677fde2ab1 20 7 / 0 / 13 10240 efc8a7f5eff4b661 5b799cd5d488
R5-force 0 0 41 1002 (1001/1) 3d677fde2ab1 20 7 / 0 / 13 10240 efc8a7f5eff4b661 5b799cd5d488
R6a-search-s2marker 0 1 6 41 1002 (1001/1) 3d677fde2ab1 20 7 / 0 / 13 10240 efc8a7f5eff4b661 5b799cd5d488
R6b-search-origmarker 0 1 1 41 1002 (1001/1) 3d677fde2ab1 20 7 / 0 / 13 10240 efc8a7f5eff4b661 5b799cd5d488
R6c-search-session 0 1 1 41 1002 (1001/1) 3d677fde2ab1 20 7 / 0 / 13 10240 efc8a7f5eff4b661 5b799cd5d488

base-rollback-on-base (version=2026.11.1 rev=476cce7a8a343ac1524bf12276da839a690cff8a state=base-on-stable)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
R0-before 0 0 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
R1-status 0 0 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
R2a-search-s2marker 0 1 6 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
R2b-search-origmarker 0 1 1 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
R2c-search-session 0 1 1 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
R3-index-noedit 0 0 41 999 (998/1) ef7fdec98d1e 977 964 / 0 / 13 500224 efc8a7f5eff4b661 5d276cbc3c18
R4-edit3 0 6 41 1002 (1001/1) 3d677fde2ab1 983 967 / 0 / 16 503296 efc8a7f5eff4b661 a981df94397a
R5-force 0 0 41 1002 (1001/1) 3d677fde2ab1 983 967 / 0 / 16 503296 efc8a7f5eff4b661 a981df94397a
R6a-search-s2marker 0 1 6 41 1002 (1001/1) 3d677fde2ab1 983 967 / 0 / 16 503296 efc8a7f5eff4b661 a981df94397a
R6b-search-origmarker 0 1 1 41 1002 (1001/1) 3d677fde2ab1 983 967 / 0 / 16 503296 efc8a7f5eff4b661 a981df94397a
R6c-search-session 0 1 1 41 1002 (1001/1) 3d677fde2ab1 983 967 / 0 / 16 503296 efc8a7f5eff4b661 a981df94397a

pg-base-populate (version=2026.11.1 node=v24.22.2)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
P0-agent-turn 0 0 41 0 (0/0) e3b0c44298fc 0 0 / 0 / 0 0 e3b0c44298fc
P1-force-initial 0 951 41 971 (970/1) 791aad7748ca 951 951 / 0 / 0 486912 9bf72985c0c1d02c 555a47f420f8
P2-prepend10 0 20 41 981 (980/1) e735e7289ea9 971 961 / 0 / 10 497152 9bf72985c0c1d02c bf5aa467b999
P3-crosspath10 0 0 41 991 (990/1) 7929011196ae 971 961 / 0 / 10 497152 9bf72985c0c1d02c bf5aa467b999
P4-nondeterministic-copy 0 5 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
P5-status 0 0 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
P6a-search-s2marker 0 1 6 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
P6b-search-origmarker 0 1 1 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
P6c-search-session 0 1 1 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999

pg-head-on-base (version=2026.11.1 rev=9c16f4e808423fb5d71214988bdde6307b36c158 state=pg-base-populate)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
X0-before 0 0 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X1-status 0 0 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X2a-search-s2marker 0 1 6 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X2b-search-origmarker 0 1 1 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X2c-search-session 0 1 1 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X3-index-noedit 0 0 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X4-edit3 0 6 41 999 (998/1) b9636702d83b 971 953 / 5 / 13 497152 9bf72985c0c1d02c bf5aa467b999
X5-force 0 0 41 999 (998/1) addc9f9052a0 14 1 / 0 / 13 7168 9bf72985c0c1d02c 14fe3737d9c6
X6a-search-s2marker 0 1 6 41 999 (998/1) addc9f9052a0 14 1 / 0 / 13 7168 9bf72985c0c1d02c 14fe3737d9c6
X6b-search-origmarker 0 1 1 41 999 (998/1) addc9f9052a0 14 1 / 0 / 13 7168 9bf72985c0c1d02c 14fe3737d9c6
X6c-search-session 0 1 1 41 999 (998/1) addc9f9052a0 14 1 / 0 / 13 7168 9bf72985c0c1d02c 14fe3737d9c6

pg-base-on-base (version=2026.11.1 rev=476cce7a8a343ac1524bf12276da839a690cff8a state=pg-base-populate)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
X0-before 0 0 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X1-status 0 0 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X2a-search-s2marker 0 1 6 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X2b-search-origmarker 0 1 1 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X2c-search-session 0 1 1 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X3-index-noedit 0 0 41 996 (995/1) e33dad373c38 971 956 / 5 / 10 497152 9bf72985c0c1d02c bf5aa467b999
X4-edit3 0 6 41 999 (998/1) b9636702d83b 977 959 / 5 / 13 500224 9bf72985c0c1d02c 281ab037821a
X5-force 0 0 41 999 (998/1) addc9f9052a0 977 964 / 0 / 13 500224 9bf72985c0c1d02c 281ab037821a
X6a-search-s2marker 0 1 6 41 999 (998/1) addc9f9052a0 977 964 / 0 / 13 500224 9bf72985c0c1d02c 281ab037821a
X6b-search-origmarker 0 1 1 41 999 (998/1) addc9f9052a0 977 964 / 0 / 13 500224 9bf72985c0c1d02c 281ab037821a
X6c-search-session 0 1 1 41 999 (998/1) addc9f9052a0 977 964 / 0 / 13 500224 9bf72985c0c1d02c 281ab037821a

pg-port-stable (version=2026.11.1 rev=476cce7a8a343ac1524bf12276da839a690cff8a pgdb=pg_port)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
T0-sqlite-before 0 0 27 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
T1-doctor-fix 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
T2-port-dry-run 0 0 41 996 (995/1) 80149dab1b81 971 956 / 5 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
T3-port 0 0 (0/0) / /
T4-pg-after-port 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
T5-status 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
T6a-search-s2marker 0 1 6 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
T6b-search-origmarker 0 1 1 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
T6c-search-session 0 1 1 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999

pg-head-on-port (version=2026.11.1 rev=9c16f4e808423fb5d71214988bdde6307b36c158 state=pg-port-stable)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
X0-before 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X1-status 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X2a-search-s2marker 0 1 6 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X2b-search-origmarker 0 1 1 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X2c-search-session 0 1 1 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X3-index-noedit 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X4-edit3 0 6 41 999 (998/1) 50edc75f4572 971 958 / 0 / 13 497152 efc8a7f5eff4b661 bf5aa467b999
X5-force 0 0 41 999 (998/1) 50edc75f4572 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
X6a-search-s2marker 0 1 6 41 999 (998/1) 50edc75f4572 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
X6b-search-origmarker 0 1 1 41 999 (998/1) 50edc75f4572 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6
X6c-search-session 0 1 1 41 999 (998/1) 50edc75f4572 14 1 / 0 / 13 7168 efc8a7f5eff4b661 14fe3737d9c6

pg-base-on-port (version=2026.11.1 rev=476cce7a8a343ac1524bf12276da839a690cff8a state=pg-port-stable)

step exit embed inputs hits user_version chunks (mem/sess) chunk checksum cache rows cache: identical / differs / no chunk cache vec bytes meta sha cache checksum
X0-before 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X1-status 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X2a-search-s2marker 0 1 6 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X2b-search-origmarker 0 1 1 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X2c-search-session 0 1 1 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X3-index-noedit 0 0 41 996 (995/1) 7ead0c539fe0 971 961 / 0 / 10 497152 efc8a7f5eff4b661 bf5aa467b999
X4-edit3 0 6 41 999 (998/1) 50edc75f4572 977 964 / 0 / 13 500224 efc8a7f5eff4b661 281ab037821a
X5-force 0 0 41 999 (998/1) 50edc75f4572 977 964 / 0 / 13 500224 efc8a7f5eff4b661 281ab037821a
X6a-search-s2marker 0 1 6 41 999 (998/1) 50edc75f4572 977 964 / 0 / 13 500224 efc8a7f5eff4b661 281ab037821a
X6b-search-origmarker 0 1 1 41 999 (998/1) 50edc75f4572 977 964 / 0 / 13 500224 efc8a7f5eff4b661 281ab037821a
X6c-search-session 0 1 1 41 999 (998/1) 50edc75f4572 977 964 / 0 / 13 500224 efc8a7f5eff4b661 281ab037821a
database port --to postgres output (paths shortened)
{
 "phase": "complete",
 "engine": "postgres",
 "stores": [
  "<state>/agents/main/agent/openclaw-agent.sqlite",
  "<state>/openclaw.sqlite"
 ],
 "plannerStatistics": [
  {
   "path": "<state>/agents/main/agent/openclaw-agent.sqlite",
   "result": {
    "status": "analyzed",
    "tables": 50
   }
  },
  {
   "path": "<state>/openclaw.sqlite",
   "result": {
    "status": "analyzed",
    "tables": 98
   }
  }
 ],
 "backup": "<state>/recovery/database-port/d38d1051-35c6-431e-8660-f6610fef8f99",
 "remainingSqlite": [
  "<state>/control/services.sqlite",
  "<state>/client/credentials.sqlite"
 ],
 "manifest": "<state>/recovery/database-port/d38d1051-35c6-431e-8660-f6610fef8f99/manifest.json",
 "serverCapacity": "unknown; former PostgreSQL namespaces retained",
 "restart": "Start the Gateway through its service owner.",
 "memoryRebuilds": [
  {
   "agentId": "main",
   "path": "<state>/agents/main/agent/openclaw-agent.sqlite",
   "status": "rebuilt",
   "elapsedMs": 3789,
   "files": 123,
   "chunks": 996,
   "plannerStatistics": {
    "status": "analyzed",
    "tables": 51
   }
  }
 ]
}

Tests

  • manager-embedding-cache-retire.test.ts and manager-embedding-cache-retire.postgres.test.ts cover the kernel on SQLite and PostgreSQL:
    • the full predicate;
    • metadata refusals (provider key, dimensions, input format, fts-only, unreadable metadata);
    • both fences and paging with the cursor;
    • an EXPLAIN guard that later pages search one updated_at range. A bare OR keyset sorted the remaining rows on every page under the step-2 fence.
  • manager.cache-duplicate-retirement.test.ts covers the manager:
    • ordinary edits and full rebuilds;
    • a failed edit whose retry reuses its rows;
    • a failed edit whose text another file already publishes;
    • a skipped sync retired by the next clean sync;
    • a cached vector that differs from the published one;
    • a cleanup error that leaves publication and retry state alone;
    • a disabled cache whose existing duplicate rows survive an edit and a forced rebuild;
    • existing duplicates retired only by a full rebuild.
  • Each predicate, fence, gate and call site was mutated (19 mutants). Every mutant fails the suite.
  • Existing tests that read generated vectors back from the cache as a probe now hold retirement with keepPublishedCacheDuplicates, and their assertions are unchanged. They cover reindex recovery, chunk publication retry, source and session races, legacy-format upgrade, declared-dimension repair, and PostgreSQL rebuild reuse. manager-cache-rebuild.test.ts re-seeds the rows an older build kept, and expects only superseded rows after a published rebuild.
  • Docs: docs/concepts/memory-builtin.md describes the rule.

Not covered by a test: the retained cache size the worker and the PostgreSQL binding track after a retirement. It is adjusted by the removed count, the same way cache.clear adjusts it.

Landing review and recovered current-head CI

The independently reviewed source remains 6a7323d419eef267e12afbc6b6273902fafb8823. CI run 42966846081, attempt 2 completed successfully after one documented failed-job recovery. The new PostgreSQL 1/3 execution ran both conformance and the previously interrupted PostgreSQL 16 Gateway cron smoke successfully, followed by a successful aggregate gate. Passing lanes reused from attempt 1 retain their original execution. The original whole-job deadline cancellation and failed aggregate are preserved as historical evidence; successful recovery supplies missing coverage, not proof that an infrastructure cause was repaired. The post-CI Security Review publisher published successful CI, security-sensitive and dependency statuses for this exact head. No CI was rerun for the later acceptance or for age.

The earlier shipped-CLI, SQLite/PostgreSQL upgrade/port/rollback measurements below retain their stated executing revisions. Current-main composition is conflict-free, with the production patch unchanged from the completed source review.

Checks

On 6a7323d (merged with main 277e32c):

  • extensions/memory-core/src/memory: 113 files passed, 6 skipped; 1043 tests passed, 56 skipped, 0 failed.
  • PostgreSQL 17 with pgvector, all 7 memory-core *.postgres.test.ts files: 59 of 59 passed.
  • pnpm check:changed: every lane passes except the dead export scan. It lists the same 86 unused exports on main 277e32c, all in extensions/knowledge and src/, none in a file this PR touches.
  • pnpm build: passes.
  • The 1b commit alone (the "1b only" option), checked on the earlier head: 30 PostgreSQL tests passed in the 4 cache and publication files.
  • config/test-lines-allocations/195369-memory-cache-retire.txt allocates the 747 added test lines (kernel tests on SQLite and PostgreSQL, the manager scenarios above, and the existing-test holds).

- After an ordinary sync publishes its memory files, and after a full
  rebuild publishes, delete cache rows of the primary sync identity written
  since that run started whose exact bytes every published chunk carrying
  the hash holds, when at least one of those chunks is a memory-file chunk
  under the same published identity, input format and dimensions.
- Rows whose vector differs from any published variant, unpublished rows,
  session-only hashes, aliases and other identities are kept.
- Ordinary syncs retire only when the memory sync returned normally and left
  no dirty or full-retry state, so failed, partial and deferred runs keep
  every row for their retry; the skipped sync's start carries to the next
  clean sync, which retires those rows once its publication serves them.
- New cache.retire worker command on SQLite and PostgreSQL: one write
  transaction per page of 256 candidates in (updated_at, hash) order on the
  updated_at index, one chunk read per page, yields between pages, stops
  while closing.
- Runs before the cap prune, outside every publication transaction, gated
  on cache.enabled. Errors are logged and never reach publication or retry
  state.
- The 1a published-meta identity gate is shared through
  readMemoryPublishedVectorMeta. The kernel is registered as worker-only in
  the database worker inventory.
- Existing cases that read generated vectors back from the cache as a probe
  (reindex recovery, chunk publication retry, source and session races,
  legacy-format upgrade, declared-dimension repair, PostgreSQL rebuild
  reuse) hold retirement through keepPublishedCacheDuplicates; their
  assertions are unchanged.
- manager-cache-rebuild.test.ts re-seeds the rows an older build kept, and
  its full-mode cap case holds retirement so the cap still settles the rows.
- Docs describe the retention rule.
- After a full rebuild publishes, a second cache.retire pass covers rows
  last written before the rebuild started, with the same predicate, page
  bound and failure isolation as the pass over the rows the rebuild wrote.
  The two fences meet at the rebuild start, so together they cover every
  row of the identity, and the replacement index rewrote every chunk.
- Rows whose vector differs from every published variant, ambiguous hashes,
  unpublished rows and session-only hashes are kept.
- Ordinary syncs still retire only rows written since they, or the oldest
  earlier sync that did not finish cleanly, started; older rows wait for the
  next full rebuild.
- manager-cache-rebuild.test.ts now expects the superseded rows alone after
  a published rebuild. Docs describe the full-rebuild pass.
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

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

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core scripts Repository scripts size: XL triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Nov 8, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR removes embedding-cache rows after successful publication when the memory index holds identical vectors.

Example: Force-rebuild the demonstrated upgraded SQLite store containing 977 cache rows.

  • Before: The cache retains 977 rows and 500,224 vector bytes.
  • After: The cache retains 14 rows and 7,168 vector bytes, with no embedding inputs and identical published vectors.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong CLI and compatibility evidence supports a coherent implementation with no concrete findings; product readiness remains capped by the unresolved retention decision.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied built-CLI indexing and search results exercise duplicate retirement on fresh SQLite stores, upgraded stable SQLite stores, existing PostgreSQL stores and supported database ports; controls preserve published vectors, search hits and settings while measuring reduced cache rows. The production changes match the exercised candidate; live providers and a long-lived Gateway were not exercised.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Large memory stores retain a second copy of published vectors, consuming substantial database space.
Reason: The storage benefit is demonstrated, but intentional deletion of valid reusable cache data requires recorded storage-owner acceptance.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it provides useful, demonstrated storage savings, but deleting valid cache entries still requires the storage owner's retention decision.

Priority: P2
Reviewed head: 6a7323d419eef267e12afbc6b6273902fafb8823
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should Memory Core retire both newly published and existing duplicate cache rows, retire only newly published duplicates, or retain the current cache policy?
  • Recommendation: Accept both retirement stages: Accept the demonstrated storage savings and documented cross-file, provider-switch-back and older-build re-embedding costs.
  • Why: These are valid reusable vectors, and the prior merged implementation and reopening discussion deliberately left their retention undecided; the contributor's recommendation is not owner acceptance.

Before merge

  • Await maintainer action - The storage owner must record acceptance or rejection of the proposed cache-retention policy before merge.

Findings

None.

Agent review details

How this fits together

Memory Core converts memory files and session sources into a published search index; its publication workers also maintain the reusable embedding cache on SQLite and PostgreSQL.

flowchart LR
  A[Memory files and sessions] --> B[Memory sync owner]
  B --> C[Cache and published vector lookup]
  C --> D[Embedding provider for misses]
  B --> E[Publication worker]
  E --> F[Published search index]
  E --> G[Post publication cache retirement]
Loading

Technical review

Best possible solution:

Adopt bounded duplicate retirement through the existing publication workers only after the storage owner accepts its documented storage-versus-re-embedding tradeoff.

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

Current-main source retains generated cache copies, and the contributor's CLI comparisons demonstrate their storage cost; this read-only review ran no target code.

Is this the best way to solve the issue?

The smallest complete implementation uses the existing publication workers and one shared predicate, preserves failed-run reuse, and keeps cleanup outside publication transactions; accepting the retention policy remains an owner choice.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Published-vector identity validation keeps the original intent (f89350c: Reuse compatible published vectors after database ports without purchasing missing cache entries again; the PR extracts and preserves that metadata gate.)
  • Ordinary-edit read-through changes intended behavior with a stated reason (198b761: Reuse unchanged chunks within their source and path while preserving existing cache rows and deferring duplicate-retention policy.)
  • Cache retention and rebuild cleanup changes intended behavior with a stated reason (1cb75e9: Bound temporary rebuild growth while preserving vectors needed by later batches; this PR keeps those mechanics and separately proposes post-publication duplicate deletion.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1cb75e9 adds extensions/memory-core/src/memory/manager-embedding-cache-ops.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1cb75e90b29b; files: extensions/memory-core/src/memory/manager-embedding-cache-ops.ts)
  • Mitchell Etzel: Raw commit 4928146 adds extensions/memory-core/src/memory/manager-embedding-cache-ops.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 492814665d81; files: extensions/memory-core/src/memory/manager-embedding-cache-ops.ts)

PR surface

Source +263, Tests +747, Docs +19, Other +3. Total +1032 across 26 files. Added test files: 4.

View PR surface stats
Area Files Added Removed Net
Source 10 289 26 +263
Tests 13 751 4 +747
Docs 1 19 0 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 2 3 0 +3
Total 26 1062 30 +1032

Preflight source

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

Review metrics

Metric Value Why it matters
Production versus test changes Production +289/-26; tests and test support +751/-4 Growth implements one shared retirement kernel, existing worker adapters, and distinct predicate, paging, failure, disabled-cache and backend coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #168777
Summary: This PR implements the duplicate-retirement stages left open after scoped published-vector reuse merged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Measured storage savings are useful, but the PR addresses no current functional outage.
  • merge-risk: 🚨 compatibility: Deleting valid cache rows changes reuse and rollback costs for existing stores; compatibility runs support operation but cannot authorize the retention tradeoff.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on maintainer: Only explicit maintainer approvals or decisions remain; merge is still blocked.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Have the storage owner accept both retirement stages, accept only new-row retirement, or reject the proposed policy.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-11-08T19:38:59.423Z sha 6542ebd :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-08T21:04:14.551Z sha 9c16f4e :: blocked before merge. :: none
  • reviewed 2026-11-09T00:08:24.784Z sha 8b5b0f0 :: blocked before merge. :: none

Reviewed November 11, 2026, 12:42 AM ET / 05:42 UTC (Revision 4).

@etzelm etzelm changed the title perf(memory): retire cache duplicates the published index serves improve(memory): drop embedding cache copies the published index already serves Nov 8, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 8, 2026
@etzelm

etzelm commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Nov 8, 2026
@etzelm
etzelm force-pushed the perf/memory-retire-published-cache-duplicates branch from 5a75f21 to 8b5b0f0 Compare November 8, 2026 23:36
@etzelm

etzelm commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Nov 9, 2026
@etzelm

etzelm commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Merged current main (one import conflict in manager.reindex-recovery.test.ts; no production change, the PR's production diff against main is line-for-line the same as at 8b5b0f0). The body now has a "Decision needed" block with the retention question, the three options and a recommendation.

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot
roboclaw-bot merged commit 3ea0883 into openclaw:main Nov 13, 2026
190 of 194 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…ady serves (openclaw#195369)

Retire exact embedding-cache duplicates after clean publication through the existing SQLite/PostgreSQL worker owners. Include both newly published duplicates and older duplicates after a full rebuild, while preserving failed-run, disabled-cache, ambiguous-vector and session-only rows.

Patrick-Erichsen instructed landing after disclosure of the retention alternatives and re-embedding costs; the accepted both-stage decision is recorded in the PR.

Validation: independently reviewed source and qualified shipped-CLI/SQLite/PostgreSQL proof at their recorded executing revisions; exact-head CI42966846081 attempt2 and security/dependency publication succeeded. The original cancelled attempt remains historical evidence.

Co-authored-by: Mitchell Etzel <[email protected]>
Co-authored-by: Patrick-Erichsen <[email protected]>
roboclaw-bot added a commit that referenced this pull request Nov 13, 2026
Align the Memory shutdown regression with #195369: a successful full
publication now retires its redundant embedding-cache row. Preserve the
accepted-sync, published-text, executor-reuse and lease-release checks.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…198153)

Align the Memory shutdown regression with openclaw#195369: a successful full
publication now retires its redundant embedding-cache row. Preserve the
accepted-sync, published-text, executor-reuse and lease-release checks.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 14, 2026
…196378)

fix(memory): let large memory rebuilds finish without running out of worker memory

A full memory rebuild ran out of its 512 MiB worker and restarted on every attempt when the index held tens of thousands of embedded chunks, for example after the chunking-format upgrade from 2026.10.9, so vector search never came back and search kept serving the old keyword index. Two steps held a whole pass in one worker. Vector reuse now reads cached embeddings in pages of whole hashes sized to 8 MiB of decoded vectors. The SQLite publication worker now parses each staged row as it arrives and keeps its vector as a Float64Array instead of JSON, turning one row at a time back into a number array at source.replace, which stays one atomic replace. Stored bytes, schema and retention are unchanged, no table is added, and the PostgreSQL path is untouched.

Evidence: a 94,919-chunk index at 1536 dimensions built through the real import and memory index paths in a secretless node:24.22.1 container with a stand-in embeddings server. On the PR base and current main, the format-upgrade rebuild and memory index --force ran out of memory after 19-33 s with the read worker near 490 MiB, and a running Gateway retried and failed again while search served the keyword index. With this change both rebuilds finish in 320-415 s with peak worker heaps near 100-110 MiB, no embedding calls, byte-identical stored vectors and vector search hits. A 634-chunk index and an already-rebuilt index behave the same on both. The red changed-extensions bundles are three memory-core integrity tests that fail on main since #194484: #196378 (comment). Net 0 test lines. Details: #196378 (comment).

Thanks @garrytan.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 3e7fb1b)

Release adaptation: page the release branch's existing cache-only reads; do
not import newer published-vector fallback, PostgreSQL, or retirement owners.
Retain provider identity order, disabled-cache behavior and SQLite publication
contracts. Packed staging is unchanged from the source fix.

Companion review: 3ea0883 (#195369) is a separate cache-retention change,
not required for bounded reads or packed staging; intentionally excluded.
No later PR-number follow-ups. Existing transfer/settlement fixtures retain
the same protocol. No storage format, schema or retention change.

Proof: Node syntax checks and exact production staging-helper value/order,
replay and fragmented-tail checks pass. Full owner tests/typecheck remain
unrun: isolated worktree has no dependencies; no install authorized.
Independent review remains with the parent (worker cannot spawn children).

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

Labels

clawtributors PR from a clawtributor docs Improvements or additions to documentation extensions: memory-core Extension: memory-core merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants