Skip to content

fix: exclude hidden doubts from similarity matches (#1349) - #1391

Merged
knoxiboy merged 1 commit into
knoxiboy:mainfrom
Shreya-nipunge:fix-1349-hidden-doubts-matches
Aug 13, 2026
Merged

fix: exclude hidden doubts from similarity matches (#1349)#1391
knoxiboy merged 1 commit into
knoxiboy:mainfrom
Shreya-nipunge:fix-1349-hidden-doubts-matches

Conversation

@Shreya-nipunge

@Shreya-nipunge Shreya-nipunge commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update (README, guides, comments)
  • Style / UI change (no logic change)
  • Code refactor (no behavior change)
  • Test addition or update
  • Breaking change (fix or feature that would cause existing functionality to change)

Screenshots (if UI change)

Not applicable — this is a backend-only change.

How Has This Been Tested?

  • TypeScript check (npx tsc --noEmit)
  • ESLint
  • Relevant Jest tests
  • git diff --check
  • Tested locally with npm run dev
  • Verified on mobile viewport (375px)
  • Verified on desktop viewport (1440px)

Test Results

  • 3 test suites passed
  • 17 tests passed
  • TypeScript check passed
  • ESLint passed
  • git diff --check passed

Checklist

  • I have tested my changes locally
  • My code follows the existing code style (TypeScript, Tailwind, no any types)
  • I have not introduced unrelated changes (each PR should address one issue)
  • I have added comments where necessary
  • My branch is up to date with main
  • I have linked the related issue above
  • Screenshots are included (not applicable — no UI change)

CodeAnt-AI Description

Prevent hidden doubts from appearing in similarity and duplicate matches

What Changed

  • Similarity searches now ignore hidden doubts before returning potential matches
  • Duplicate checks now exclude hidden doubts from recent and semantic candidate results
  • Added coverage to verify hidden content is excluded across all matching paths

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:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

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:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

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

    • Hidden doubts are now excluded from duplicate and similarity checks.
    • Prevents hidden content from appearing as a match in public-facing checks.
  • Tests

    • Added regression coverage confirming hidden doubts remain excluded across all duplicate-detection paths.

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@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

codeant-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR cabc429 Aug 11, 2026 · 13:37 13:40

@codeant-ai

codeant-ai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@github-actions github-actions Bot added gssoc'26 GSSoC program issue level:intermediate Intermediate level task type:bug Bug fix type:docs Documentation update labels Aug 11, 2026
@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Aug 11, 2026
@github-actions
github-actions Bot requested a review from knoxiboy August 11, 2026 13:37
@github-actions

Copy link
Copy Markdown

@coderabbitai review
@codeantai review

@github-actions github-actions Bot added size/l and removed size:L This PR changes 100-499 lines, ignoring generated files labels Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] I will review the current changes in #1391. I only have the latest comment context.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions github-actions Bot added size/m and removed size/l labels Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a0156783-ba99-4363-a0b4-5c9bf0b14e5e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Duplicate and similarity candidate queries now exclude hidden doubts. API and embedding tests inspect generated query predicates and verify the isHidden condition.

Changes

Hidden doubt filtering

Layer / File(s) Summary
Candidate query filters
src/app/api/doubts/check-duplicate/route.ts, src/app/api/doubts/check-similarity/route.ts, src/lib/ai/embeddings.ts
Duplicate, similarity, and semantic duplicate queries now require candidate doubts to have isHidden set to false.
Regression coverage
src/__tests__/api/doubts-check-duplicate.test.ts, src/__tests__/api/doubts-similarity.test.ts, src/__tests__/lib/embeddings.test.ts
Tests inspect generated where predicates and verify that duplicate and similarity requests exclude hidden doubts. The similarity tests add Groq mocks and environment setup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: knoxiboy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes exclude hidden doubts from similarity and duplicate candidate queries and add regression tests for issue #1349.
Out of Scope Changes check ✅ Passed All implementation and test changes directly support excluding hidden doubts from similarity and duplicate detection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the exclusion of hidden doubts from similarity matches, which is a central part of the changeset.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment on lines +137 to +148
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.

Fix in Cursor Fix in VSCode Claude

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
👍 | 👎

Comment on lines +189 to +200
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`.

Fix in Cursor Fix in VSCode Claude

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
👍 | 👎

Comment on lines +79 to +86
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in VSCode Claude

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 fix
👍 | 👎

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/__tests__/api/doubts-similarity.test.ts (1)

214-221: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the isHidden = false predicate.

Each helper only verifies that the predicate references isHidden. It also passes if the query uses eq(doubtsTable.isHidden, true). Assert the comparison value is false, 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 requires isHidden to be false.
  • src/__tests__/api/doubts-check-duplicate.test.ts#L162-L169: verify that the fallback candidate predicate requires isHidden to be false.
  • src/__tests__/lib/embeddings.test.ts#L79-L86: verify that the semantic candidate predicate requires isHidden to be false.
🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between cc15691 and cabc429.

📒 Files selected for processing (6)
  • src/__tests__/api/doubts-check-duplicate.test.ts
  • src/__tests__/api/doubts-similarity.test.ts
  • src/__tests__/lib/embeddings.test.ts
  • src/app/api/doubts/check-duplicate/route.ts
  • src/app/api/doubts/check-similarity/route.ts
  • src/lib/ai/embeddings.ts

@knoxiboy
knoxiboy merged commit 6a10bbe into knoxiboy:main Aug 13, 2026
26 of 29 checks passed
@github-actions github-actions Bot added gssoc:approved Approved for GSSoC quality:clean Clean code quality and removed size/m review-needed labels Aug 13, 2026
@knoxiboy knoxiboy added level:advanced Advanced level task and removed level:intermediate Intermediate level task labels Aug 13, 2026
@Shreya-nipunge
Shreya-nipunge deleted the fix-1349-hidden-doubts-matches branch August 15, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC gssoc'26 GSSoC program issue level:advanced Advanced level task quality:clean Clean code quality type:bug Bug fix type:docs Documentation update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Similarity and duplicate check endpoints expose hidden doubts as matches

2 participants