Skip to content

fix(rag): drop stale legacy chunks from document summaries - #3662

Merged
BigSimmo merged 1 commit into
mainfrom
claude/project-thread-h7cvje
Oct 19, 2026
Merged

BigSimmo merged 1 commit into
mainfrom
claude/project-thread-h7cvje

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Before: a reindexed document could be summarised from both its old (legacy, NULL-generation) chunks and its new committed-generation chunks, because the fenced commit path leaves legacy rows in place and the summary query selected both.
  • After: legacy chunks are used only while the committed generation has written no chunks of its own, which matches the commit RPC's "preserve legacy rows unless this generation wrote replacements" rule. Documents that were never reindexed still summarise from their legacy chunks.
  • How: loadDocumentSummaryContext filters out NULL-generation rows whenever any committed-generation row is present. No query, migration or ranking change.
  • Follow-up to the two protected search findings deferred from Fix confirmed merged-PR review findings and stage atomic milestone repair (rebuild of #3638) #3652 and fix: remediate full-deep audit findings and retain release holds (rebuild of #3640) #3653, with the owner's approval to draft. The second finding (repeated rag_cache_scope_revision_v1 calls in rag-cache.ts) is deliberately not changed. Every call is a fresh before/after fence against revocation and mid-request reindexing, and the function's own contract forbids a memo. Making the RPC cheaper would need a database change.

Areas touched: Answer engine
RAG impact: no retrieval behaviour change — only the document-summary context changes; search retrieval, ranking, ordering and RPCs are untouched, and the retrieval eval canary does not exercise summaries

Verification

  • Checks run:
    • Both new tests in tests/rag-document-summary.test.ts were run without the fix: "drops stale NULL-generation chunks once the committed generation has rows" failed (Tests 1 failed | 5 passed (6)). With the fix: Tests 6 passed (6).
    • npm run test:focused: Tests 1328 passed (1328).
    • Typecheck passed, and eslint and prettier are clean on the changed files.

Risk and rollout

  • Risk: low. If a document's committed generation has some chunks, its summaries no longer include its legacy chunks. That is the intended behaviour.
  • Rollback: revert this single commit.
  • Provider or production effects: None.

Notes

  • Draft until the owner decides to merge.

Generated by Claude Code


Summary by cubic

Fixes document summaries mixing stale legacy chunks with newly committed chunks after a reindex.

loadDocumentSummaryContext now drops NULL-generation (legacy) rows whenever the committed generation has written chunks of its own, matching the commit RPC's preserve rule. Documents that were never reindexed still summarise from their legacy chunks.

  • Adds tests covering both the stale-chunk drop and the legacy-only fallback.
  • Search retrieval, ranking, and RPCs are unchanged.

Written for commit 6469d47. Summary will update on new commits.

View guided diff Turn on auto-fix

loadDocumentSummaryContext kept NULL-generation chunks alongside the
committed generation's chunks. The fenced commit path does not delete
legacy rows, so a reindexed document could be summarised from both its
old and new text. Legacy rows now stand in only while the committed
generation has written no chunks, matching the commit RPC's preserve rule.

Search ranking and retrieval RPCs are unchanged; only the document
summary context is affected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018UBtJDgQZJ3eBsxLWte9r4
@supabase

supabase Bot commented Oct 18, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 127 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: BigSimmo/PsychSift/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: fa98cf04-35b2-439c-88f6-874146e43627
📥 Commits

Reviewing files that changed from the base of the PR and between b907b5c and 6469d47.

📒 Files selected for processing: 2
  • src/lib/rag/rag-document-summary-context.ts
  • tests/rag-document-summary.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@gitar-bot

gitar-bot Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Code Review ✅ Approved

🟡 Medium risk · Changing summary chunk selection to drop legacy rows when committed chunks exist could omit useful context if generation metadata is inconsistent.

Document summaries now drop stale NULL-generation legacy chunks once the committed generation has written its own chunks, so reindexed documents no longer mix old and new content. Documents never reindexed still summarise from legacy chunks. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Approved

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Important

Your trial ends in 3 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

@gitar-bot gitar-bot 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.

Gitar has auto-approved this PR (configure)

@BigSimmo
BigSimmo marked this pull request as ready for review October 18, 2026 14:34

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

BigSimmo has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T14:37:06.577092Z 6469d47 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@BigSimmo
BigSimmo merged commit a472624 into main Oct 19, 2026
62 checks passed
@BigSimmo
BigSimmo deleted the claude/project-thread-h7cvje branch October 19, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants