fix: exclude hidden doubts from similarity matches (#1349) - #1391
Conversation
|
@Shreya-nipunge is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel. A member of the Team first needs to authorize it. |
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
@coderabbitai review |
|
|
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughDuplicate and similarity candidate queries now exclude hidden doubts. API and embedding tests inspect generated query predicates and verify the ChangesHidden doubt filtering
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| let capturedWhereArg: any = null; | ||
| const trackingQuery: any = { | ||
| from: () => trackingQuery, | ||
| where: (arg: any) => { | ||
| capturedWhereArg = arg; | ||
| return trackingQuery; | ||
| }, | ||
| orderBy: () => trackingQuery, | ||
| limit: () => trackingQuery, | ||
| then: (resolve: any) => Promise.resolve(resolve([])), | ||
| }; | ||
| dbSelectMock.mockReturnValue(trackingQuery); |
There was a problem hiding this comment.
Suggestion: The new test only reaches the fallback query: the embedding mock is never configured with a valid 1536-dimensional vector, so findSemanticDuplicates returns an empty result before its database query is executed. A regression removing the hidden predicate from the primary vector-search path would therefore still pass this test. Configure the embedding response and capture/assert the vector query separately. [code quality]
Severity Level: Major ⚠️
- ⚠️ Primary vector-search regressions remain undetected.
- ❌ Hidden doubts could reappear in duplicate results.
- ⚠️ AskDoubt displays returned matches at `src/components/classroom/AskDoubt.tsx:701-710`.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** src/__tests__/api/doubts-check-duplicate.test.ts
**Line:** 137:148
**Comment:**
*Code Quality: The new test only reaches the fallback query: the embedding mock is never configured with a valid 1536-dimensional vector, so `findSemanticDuplicates` returns an empty result before its database query is executed. A regression removing the hidden predicate from the primary vector-search path would therefore still pass this test. Configure the embedding response and capture/assert the vector query separately.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| let capturedWhereArg: any = null; | ||
| const trackingQuery: any = { | ||
| from: () => trackingQuery, | ||
| where: (arg: any) => { | ||
| capturedWhereArg = arg; | ||
| return trackingQuery; | ||
| }, | ||
| orderBy: () => trackingQuery, | ||
| limit: () => trackingQuery, | ||
| then: (resolve: any) => Promise.resolve(resolve([])), | ||
| }; | ||
| dbSelectMock.mockReturnValue(trackingQuery); |
There was a problem hiding this comment.
Suggestion: The new test also bypasses the primary semantic-search path because the mocked embedding call has no successful vector response and the tracking query resolves to an empty list. Consequently, the assertion verifies only the LLM fallback query and cannot catch hidden doubts returned by findSemanticDuplicates. Configure a valid embedding response and assert both candidate-query paths. [code quality]
Severity Level: Major ⚠️
- ⚠️ Semantic-search regressions remain undetected.
- ❌ Hidden doubts could surface in similarity results.
- ⚠️ Similarity results are rendered by `AskDoubt`.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** src/__tests__/api/doubts-similarity.test.ts
**Line:** 189:200
**Comment:**
*Code Quality: The new test also bypasses the primary semantic-search path because the mocked embedding call has no successful vector response and the tracking query resolves to an empty list. Consequently, the assertion verifies only the LLM fallback query and cannot catch hidden doubts returned by `findSemanticDuplicates`. Configure a valid embedding response and assert both candidate-query paths.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix| const hasIsHidden = (expr: any): boolean => { | ||
| if (!expr || typeof expr !== "object") return false; | ||
| if (expr.name === "isHidden") return true; | ||
| if (expr.queryChunks) | ||
| return expr.queryChunks.some((c: any) => hasIsHidden(c)); | ||
| return false; | ||
| }; | ||
| expect(hasIsHidden(whereArg)).toBe(true); |
There was a problem hiding this comment.
Suggestion: The test checks only that some AST node is named isHidden; it does not verify that the generated predicate compares the column to false or that hidden rows are excluded from returned results. The assertion would still pass for a malformed or ineffective expression containing the column reference. Execute the query against representative hidden and visible rows, or assert the generated SQL and bound value. [code quality]
Severity Level: Major ⚠️
- ⚠️ Test does not validate the hidden-value comparison.
- ❌ A wrong predicate could expose moderated doubts.
- ⚠️ Vector matches feed both duplicate-check endpoints.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** src/__tests__/lib/embeddings.test.ts
**Line:** 79:86
**Comment:**
*Code Quality: The test checks only that some AST node is named `isHidden`; it does not verify that the generated predicate compares the column to `false` or that hidden rows are excluded from returned results. The assertion would still pass for a malformed or ineffective expression containing the column reference. Execute the query against representative hidden and visible rows, or assert the generated SQL and bound value.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
🧹 Nitpick comments (1)
src/__tests__/api/doubts-similarity.test.ts (1)
214-221: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAssert the
isHidden = falsepredicate.Each helper only verifies that the predicate references
isHidden. It also passes if the query useseq(doubtsTable.isHidden, true). Assert the comparison value isfalse, or add a behavior test with both visible and hidden candidate rows.
src/__tests__/api/doubts-similarity.test.ts#L214-L221: verify that the fallback candidate predicate requiresisHiddento befalse.src/__tests__/api/doubts-check-duplicate.test.ts#L162-L169: verify that the fallback candidate predicate requiresisHiddento befalse.src/__tests__/lib/embeddings.test.ts#L79-L86: verify that the semantic candidate predicate requiresisHiddento befalse.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/__tests__/api/doubts-similarity.test.ts` around lines 214 - 221, Update the predicate helpers to verify that isHidden is compared specifically to false, not merely referenced. Apply this to the fallback candidate assertion in src/__tests__/api/doubts-similarity.test.ts:214-221, the fallback candidate assertion in src/__tests__/api/doubts-check-duplicate.test.ts:162-169, and the semantic candidate assertion in src/__tests__/lib/embeddings.test.ts:79-86; alternatively add behavior coverage using both visible and hidden candidates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/__tests__/api/doubts-similarity.test.ts`:
- Around line 214-221: Update the predicate helpers to verify that isHidden is
compared specifically to false, not merely referenced. Apply this to the
fallback candidate assertion in
src/__tests__/api/doubts-similarity.test.ts:214-221, the fallback candidate
assertion in src/__tests__/api/doubts-check-duplicate.test.ts:162-169, and the
semantic candidate assertion in src/__tests__/lib/embeddings.test.ts:79-86;
alternatively add behavior coverage using both visible and hidden candidates.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ef3c590d-3c4e-45fc-a994-1a62b9fbb412
📒 Files selected for processing (6)
src/__tests__/api/doubts-check-duplicate.test.tssrc/__tests__/api/doubts-similarity.test.tssrc/__tests__/lib/embeddings.test.tssrc/app/api/doubts/check-duplicate/route.tssrc/app/api/doubts/check-similarity/route.tssrc/lib/ai/embeddings.ts
User description
Description
Fixes hidden doubts appearing in similarity and duplicate check results.
The candidate queries used by the similarity and duplicate detection flows now explicitly exclude doubts where
isHidden = true. This applies to both the semantic embedding search and the LLM fallback queries, preventing moderated/hidden content from being surfaced as matches.Related Issue
Closes #1349
Type of Change
Screenshots (if UI change)
Not applicable — this is a backend-only change.
How Has This Been Tested?
npx tsc --noEmit)git diff --checknpm run devTest Results
git diff --checkpassedChecklist
anytypes)mainCodeAnt-AI Description
Prevent hidden doubts from appearing in similarity and duplicate matches
What Changed
Impact
✅ Hidden doubts stay out of similarity results✅ Hidden doubts stay out of duplicate warnings✅ Safer moderation of community content💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.
Summary by CodeRabbit
Bug Fixes
Tests