fix(tag-migration): skip memories that are already fully tagged - #351
Merged
Merged
Conversation
handleRunTagMigrationBatch re-computed the content vector and tags vector for every memory in the current window, even when a memory already had tags and a tags vector. Re-embedding an already-tagged memory cannot change anything -- its tags are unchanged, so the tags vector is identical, and the content vector is identical. Because the endpoint walks the whole project list one window at a time (the web UI drives it with batchSize: 3), a store with hundreds of memories and a single untagged memory still re-embeds the whole store twice per memory (content + tags), taking minutes of local CPU to tag one memory. Short-circuit a memory that already has tags AND a tags vector: count it as processed and move on without calling the embedding service or touching the shard. Memories with tags but no tags vector are still processed, so a missing tags vector is still rebuilt; untagged memories and the soft-failure path are unchanged.
3 tasks
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
handleRunTagMigrationBatchre-computes the content vector and tags vector for every memory in the current window, even when a memory already has tags and a tags vector. This endpoint walks the whole project list one window at a time (the web UI drives it withbatchSize: 3), so on a store with, say, 732 project memories and only 1 untagged memory, a full run still re-embeds all 732 memories — twice per memory (content + tags) — taking several minutes of local CPU to tag one memory.Re-embedding an already-tagged memory cannot change anything: its tags are unchanged, so the tag vector is identical, and the content vector is identical. Skipping those memories makes the endpoint proportional to the number of memories that actually need work.
Change
In
handleRunTagMigrationBatch, short-circuit a memory that is already fully migrated (has tags and a tags vector): count it as processed and move on without calling the embedding service or touching the shard.Memories that have tags but no tags vector are still processed, so a missing tags vector is still rebuilt. Untagged memories (and the tag-generation soft-failure path) are unchanged.
Why this is safe
tagsand both vectors are provably unchanged by the run, so their stored state is already correct.processed/cursoraccounting is preserved (a skipped memory is counted as processed and the window still advances), so the progress UI and the "retry after completion" reset keep working.Test plan
bun test tests/tag-migration-skip-tagged.test.ts— a fully-migrated memory is not re-vectorized (noembedWithTimeoutcall for its content, noupdateVector), while the untagged memory still gets tagged + vectorized and both are counted as processed.bun test tests/tag-migration-soft-failure.test.ts— existing soft-failure behavior unchanged.bunx tsc --noEmiteslint --max-warnings=0on the changed fileContext
Follows #319 (soft-failure accounting) and #333 (force the
save_tagstool call). Those made tagging correct; this makes a run proportional to the work left to do instead of to the whole store. On a 732-memory store with a single untagged memory this turns a multi-minute run into a few seconds.(Also mentioned in #350 as a related annoyance — separate from the Windows engine-migration failure reported there.)