forked from tickernelz/opencode-mem
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor(importer): keep host adapters out of shared code, and fix tag migration #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
de4425d
refactor(importer): keep host adapters out of shared code
cmdaltctr 72d1722
fix(web): tag migration touches only untagged memories
cmdaltctr b5b501b
chore: let CodeRabbit review stacked pull requests
cmdaltctr e95d1c7
fix(web): save migrated tags and vectors in one update
cmdaltctr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json | ||
| reviews: | ||
| auto_review: | ||
| # Review stacked pull requests too, not only those that target main. | ||
| base_branches: | ||
| - ".*" |
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
55 changes: 55 additions & 0 deletions
55
docs/tdr/012-tag-migration-touches-only-untagged-memories.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # TDR-012: Tag migration touches only untagged memories | ||
|
|
||
| **Date:** 2026-09-28 | ||
| **Status:** Proposed | ||
| **Deciders:** OMMS maintainers | ||
| **Tags:** web-ui, embeddings, migration | ||
|
|
||
| ## Context | ||
|
|
||
| The web UI's **Memory Tagging Migration** dialog reports how many memories have no tags ("Found 1 memories needing technical tags") and offers **Start Migration**. On a store with 2,236 memories and one untagged memory, the run showed `/2236` and worked through every memory. | ||
|
|
||
| ### Root Cause Analysis | ||
|
|
||
| `handleDetectTagMigration` counted only rows with empty `tags`, but `handleRunTagMigrationBatch` loaded `SELECT * FROM memories` from every project shard and re-embedded each row's content and tags, calling the model only for the untagged ones. Tagged memories got identical vectors back, so no data was lost, but the run took far longer than the dialog implied and ran the local embedding model thousands of times. A second defect: a memory that threw an error did not advance `processed`, so every later batch restarted at the same memory and the run could never finish. | ||
|
|
||
| ## Decision | ||
|
|
||
| The run builds its work list once, when it starts, from `SELECT id FROM memories WHERE tags IS NULL OR tags = ''` in each project shard, so the total matches the dialog's count. Each memory is re-read by id; one that gained tags or was deleted since is passed over. Only a memory that receives tags is re-embedded. Its tags and both vectors are saved in one `UPDATE`, so a failed embedding leaves it untagged and a later run tries it again. A failure is recorded in `errors` and the run always moves on. When a run completes, the next run starts from a fresh list of whatever is still untagged. | ||
|
|
||
| ## Consequences | ||
|
|
||
| ### Positive | ||
|
|
||
| - The dialog's count and the run's total agree, and tagged memories are never rewritten. | ||
| - A failing memory cannot stall the run; it stays untagged for a later run. | ||
|
|
||
| ### Negative | ||
|
|
||
| - A memory whose model call fails stays untagged, so the dialog reappears until a run succeeds. | ||
|
|
||
| ### Neutral | ||
|
|
||
| - Migration state is still held in the web server's memory; restarting the server restarts the run. | ||
|
|
||
| ## Alternatives Considered | ||
|
|
||
| | Option | Rejected Because | | ||
| | ----------------------------------- | ---------------------------------------------------------------- | | ||
| | Keep re-embedding everything | Wastes time and CPU, and contradicts the dialog's count | | ||
| | Select untagged rows on every batch | Rows that fail stay untagged and would be selected again forever | | ||
|
|
||
| ## How to Recognise / Handle This Again | ||
|
|
||
| 1. A migration or backfill total is much larger than the count shown before it starts. | ||
| 2. Compare the detect query with the query the run iterates over. | ||
| 3. Build the run's list from the same filter as the detect step, and always advance past failures. | ||
|
|
||
| ## Revisit Triggers | ||
|
|
||
| - Tags or tag vectors change format and existing tagged memories need re-embedding on purpose. | ||
|
|
||
| ## References | ||
|
|
||
| - `src/services/api-handlers.ts` (`handleDetectTagMigration`, `handleRunTagMigrationBatch`) | ||
| - `tests/tag-migration.test.ts` |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * True when a prompt is omms's own structured-summary or profile-analysis | ||
| * request. Both hosts echo it back like a user message; recording or learning | ||
| * from it would create self-referential memories and a learning loop. | ||
| */ | ||
| export function isStructuredSummaryPromptMessage(userMessage: string): boolean { | ||
| if (userMessage.includes("# User Profile Analysis")) { | ||
| return true; | ||
| } | ||
| return userMessage.includes("Analyze this conversation.") && userMessage.includes('type="skip"'); | ||
| } |
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
2 changes: 1 addition & 1 deletion
2
src/adapters/pi/conversation.ts → src/importer/pi-conversation.ts
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.