feat: memory content editing with versioning via update_memory (by Wren)#431
Open
conoremclaughlin wants to merge 3 commits into
Open
feat: memory content editing with versioning via update_memory (by Wren)#431conoremclaughlin wants to merge 3 commits into
conoremclaughlin wants to merge 3 commits into
Conversation
…epository (by Wren) updateMemory now accepts content and summary. The existing archive_memory_on_update DB trigger snapshots the prior row into memory_history and bumps version, so edits are fully versioned with no migration needed. Content/summary changes refresh semantic embeddings via the same tryEmbedMemory pipeline remember() uses; tryEmbedMemory now reports success and trims stale higher-index chunk rows on re-embed. If re-embedding fails (provider disabled/unavailable), stale vectors, chunk rows, and embedding metadata are cleared so recall falls back to text search instead of matching pre-edit text. restoreMemory gets the same refresh since rollback also rewrites the memory text. Co-Authored-By: Wren <noreply@anthropic.com>
Adds optional content (min 1 char) and summary params to the update_memory schema and handler. Undefined fields are left unchanged per repo upsert-safety conventions; an empty-string summary clears it. Calls with no update fields are rejected before hitting the DB. Tool description now explains when to edit in place (correct/revise while preserving the history trail) vs forget + remember (replacing a topic entirely). Response includes content, summary, and the bumped version. Co-Authored-By: Wren <noreply@anthropic.com>
… Wren) Verifies against the real DB that a content edit archives the prior version to memory_history (visible via getMemoryHistory), bumps version, supports restore_memory rollback, and that metadata-only updates create no history entry. Co-Authored-By: Wren <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
update_memorypreviously only updated salience/topics/metadata — correcting a memory requiredforget+remember, which destroys the history trail. This PR adds content and summary editing with versioning: the prior version is preserved inmemory_history, visible viaget_memory_history, and reversible viarestore_memory. This matters most for "current state" memories that get revised as understanding improves.How history capture works (no migration needed)
The existing
archive_memory_on_updateDB trigger already fires whencontent,summary,salience,topics, ortopic_keychange: it snapshots the OLD row intomemory_historyand bumpsversion. Content edits are versioned automatically — verified with integration tests against the real database.Changes
Repository (
memory-repository.ts)updateMemoryaccepts optionalcontentandsummary.undefined= leave unchanged (per upsert-safety conventions); empty-stringsummaryclears it.tryEmbedMemorypipelineremember()uses (chunked embeddings + primary vector + metadata).tryEmbedMemorynow returns success and trims stale higher-index chunk rows when a re-embed produces fewer chunks.restoreMemorygets the same embedding refresh — rollback also rewrites the memory text (and the recreate-after-delete branch previously produced a memory with no embedding at all).MCP tool (
memory-handlers.ts,index.ts)update_memoryschema gainscontent(min 1 char) andsummary; calls with no update fields are rejected before hitting the DB.forget+remember(replacing a topic entirely).content,summary, and the bumpedversion.Tests
memory-repository.test.ts,memory-handlers.test.ts): content+summary update persists with only provided fields written; salience-only update unchanged and skips embedding refresh; empty summary clears; stale embedding cleanup on failed re-embed (and skipped when never embedded); schema accepts/rejects correctly; handler pass-through, no-op guard, and not-found paths.memory-hierarchical.integration.test.ts, real DB): content edit archives prior version (content, summary, version, change_type='update') and bumps version;restoreMemoryrolls back to the pre-edit content; metadata-only updates create no history entry. All 17 integration tests pass.npx vitest run: 155 files, 2837 passed / 4 skipped.yarn type-check: only the known baseline errors (channels/gateway.ts Json, mcp/server.ts:451).🤖 Generated with Claude Code