fix(risk-treatment): re-embed tasks with missing vectors in upstash#3450
Closed
tofikwest wants to merge 1 commit into
Closed
fix(risk-treatment): re-embed tasks with missing vectors in upstash#3450tofikwest wants to merge 1 commit into
tofikwest wants to merge 1 commit into
Conversation
## Problem When drafting a treatment plan for a risk, the AI tool returns "0 tasks and 0 controls" even though the org has existing tasks. This affects multiple risks in the customer's account, blocking compliance progress. ## Root cause The linkage process fetches task vectors from Upstash to find similar tasks. Two previous fixes (#3340 and #3359) improved retrieval but could not recover vectors that don't exist in the store. The real gap: `upsertEntityEmbeddings` skips re-embedding a task whenever its `embeddingHash` matches a stored value, assuming the vector still exists in Upstash. Once a vector is deleted or lost while the hash persists, `runLinkage` will skip that task forever during the next run. The org then enumerates zero vectors and returns zero suggestions. ## Fix Added a reconciliation step in the linkage flow to verify that vectors actually exist in Upstash before trusting the hash. If a task's hash is present but its vector is missing from the store, re-embed it immediately. This ensures `fetchOrgTaskVectors` finds all in-scope tasks even after vector loss, restoring the suggestion pipeline. ## Explicitly NOT touched The reranker, link threshold logic, API routes, and general suggestion scoring remain unchanged. This is a retrieval-only fix that does not alter ranking or filtering. ## Verification Added regression test asserting that tasks with valid hashes but missing vectors are re-embedded and then found during linkage. Unit tests for run-linkage and index reconciliation pass locally. ✅
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
cubic analysis
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Linked issue analysis
Linked issue: CS-681: [Bug] - "Draft Plan & Suggest Links" Returns 0 Tasks and 0 Controls on Risk Treatment Plan
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Verify the linkage flow checks Upstash for the existence of hash-matched vectors and re-embeds any that are missing (heals hash→vector desync). | The PR adds findEntitiesWithoutVectors and changes upsertEntityEmbeddings to call it and include missing-vector entities in the re-embed set, so entities whose hash matches but whose vectors are absent are re-embedded. |
| ✅ | Batch vector existence checks within Upstash limits (handle up to 1000 ids per fetch). | The implementation batches ID fetches using VECTOR_FETCH_BATCH_SIZE = 1000 and iterates over candidates in slices before calling index.fetch, respecting Upstash limits. |
| ✅ | Add regression test asserting that a task with a valid hash but a missing Upstash vector is re-embedded and becomes discoverable during linkage. | A new unit/regression test simulates a missing vector via fetchMock, runs upsertEntityEmbeddings, and asserts upsert was called for the missing vector and that the result reports the applied hash. |
| ✅ | Fix results in treatment-plan linkage returning previously-suppressed suggestions (i.e., restores finding existing tasks/controls for affected risks) without changing reranking/threshold logic. | PR explicitly states it's a retrieval-only fix (no changes to reranker or thresholds). The code changes ensure missing vectors are recreated so the linkage path can enumerate those tasks; the regression test demonstrates the entity becomes discoverable in linkage. |
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.
Problem
When drafting a treatment plan for a risk, the AI tool returns "0 tasks and 0 controls" even though the org has existing tasks. This affects multiple risks in the customer's account, blocking compliance progress.
Root cause
The linkage process fetches task vectors from Upstash to find similar tasks. Two previous fixes (#3340 and #3359) improved retrieval but could not recover vectors that don't exist in the store. The real gap:
upsertEntityEmbeddingsskips re-embedding a task whenever itsembeddingHashmatches a stored value, assuming the vector still exists in Upstash. Once a vector is deleted or lost while the hash persists,runLinkagewill skip that task forever during the next run. The org then enumerates zero vectors and returns zero suggestions.Fix
Added a reconciliation step in the linkage flow to verify that vectors actually exist in Upstash before trusting the hash. If a task's hash is present but its vector is missing from the store, re-embed it immediately. This ensures
fetchOrgTaskVectorsfinds all in-scope tasks even after vector loss, restoring the suggestion pipeline.Explicitly NOT touched
The reranker, link threshold logic, API routes, and general suggestion scoring remain unchanged. This is a retrieval-only fix that does not alter ranking or filtering.
Verification
Added regression test asserting that tasks with valid hashes but missing vectors are re-embedded and then found during linkage. Unit tests for run-linkage and index reconciliation pass locally. ✅
Fixes CS-681
Summary by cubic
Restores task/control suggestions in Risk Treatment by reconciling missing Upstash vectors: hash-matched tasks are now checked and re-embedded when their vectors are absent. Addresses Linear CS-681.
@upstash/vectorIndex.fetch; re-embed and upsert when missing.Written for commit 2e773c0. Summary will update on new commits.