Skip to content

fix: preserve existing memory_units when update_mode=append#2785

Closed
handnewb wants to merge 2 commits into
vectorize-io:mainfrom
handnewb:fix/append-mode-preserve-memories
Closed

fix: preserve existing memory_units when update_mode=append#2785
handnewb wants to merge 2 commits into
vectorize-io:mainfrom
handnewb:fix/append-mode-preserve-memories

Conversation

@handnewb

Copy link
Copy Markdown
Contributor

Summary

When update_mode="append" is used with a stable document_id, the server-side implementation performs a full replace on every retain, silently deleting all existing memory_units for that document. This breaks the documented behavior and causes silent memory loss for integrations that use session-scoped document IDs (OpenClaw, Hermes, etc.).

Root Cause

In the retain orchestrator, is_recovery is only set to True when content_hash matches. With update_mode="append", the content is always (old+new), so the hash never matches and handle_document_tracking (cascade-delete old chunks + memory_units) is called instead of upsert_document_metadata (preserve existing + add new).

Fix

When update_mode="append" and the document already exists, set is_recovery = True so upsert_document_metadata is used, preserving old chunks whose content_hash hasn't changed and their memory_units.

9 lines added, zero existing behavior changed for non-append paths.

Impact

  • Old chunks and memory_units are preserved on re-retain with append mode
  • Document text still accumulates correctly
  • Only new chunks go through fact extraction
  • Orphan entity accumulation is prevented

Closes #2664

handnewb added 2 commits July 17, 2026 14:04
When update_mode='append' and the document already exists, the
content_hash is always different (old+new text), so is_recovery
stays False and handle_document_tracking cascade-deletes all
existing chunks and memory_units on every retain.

This change sets is_recovery=True when update_mode='append' and
a document row exists, so upsert_document_metadata is used instead
of handle_document_tracking. Old chunks whose content_hash hasn't
changed are preserved alongside their memory_units.

Closes vectorize-io#2664
@nicoloboschi

Copy link
Copy Markdown
Collaborator

see comment in the original issue, this is by design

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] update_mode=append silently deletes existing memory_units on re-retain (v0.8.4) — breaks long-term memory in OpenClaw plugin v0.9.0

2 participants