improve bandwidth - #27
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThis PR refactors article enrichment and AI budget accounting while centralizing source bias labeling. It introduces new schema fields for tracking enrichment state (needsFactExtraction, latestEmbeddingVersion, needsReenrichment), creates a daily AI budget aggregation table, extracts sourceBiasLabel into a shared utility, and refactors candidate claiming/deferring logic to use derived maintenance fields. Summary word limits are increased, and formatting/line-wrapping changes are applied throughout. ChangesArticle Enrichment, Budget Aggregation, and Source Bias Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/backend/convex/enrichment.ts (1)
642-670:⚠️ Potential issue | 🟠 Major | ⚡ Quick winClean up older
articleEmbeddingsrows before writing the new embedding.This no longer converges existing multi-row articles to the “single hot row” state described in the comment. Any older rows stay in the vector index, so one article can keep returning duplicate or stale matches.
Proposed fix
- const latestEmbeddingRow = await ctx.db + const embeddingRows = await ctx.db .query("articleEmbeddings") .withIndex("by_article_version", (q) => q.eq("articleId", articleId)) .order("desc") - .first(); + .collect(); + const [latestEmbeddingRow, ...staleEmbeddingRows] = embeddingRows; + + for (const row of staleEmbeddingRows) { + await ctx.db.delete(row._id); + } // Keep a single hot embedding row per article in steady state. if (latestEmbeddingRow) { await ctx.db.patch(latestEmbeddingRow._id, { embedding,🤖 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 `@packages/backend/convex/enrichment.ts` around lines 642 - 670, The code updates or inserts a single "hot" article embedding but does not remove older articleEmbeddings rows, leaving stale duplicates in the vector index; modify the logic around latestEmbeddingRow/articleEmbeddings to remove all other rows for the same articleId after you patch or insert: query all rows via ctx.db.query("articleEmbeddings").withIndex("by_article_version", ...) (or reuse the existing result set), keep the one you just patched/inserted (latestEmbeddingRow._id or the newly returned id), and call ctx.db.delete for any other rows where _id !== keptId so only a single hot row remains; ensure this cleanup runs both in the branch that calls ctx.db.patch and in the branch that calls ctx.db.insert.
🤖 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.
Inline comments:
In `@packages/backend/convex/aiBudget.ts`:
- Around line 214-220: The daily aggregate update is using the original
requested deltas (deltaSpent/deltaReserved) instead of the actual clamped shard
changes, allowing aiBudgetDailyTotal to drift; change the code so that after
computing the clamped shard adjustments you compute the actual applied deltas
(e.g., appliedSpent = newShardSpent - oldShardSpent, appliedReserved =
newShardReserved - oldShardReserved) and use those appliedSpent/appliedReserved
when computing nextTotalSpent/nextTotalReserved and when updating
aiBudgetDailyTotal (also apply the same fix in the second identical block around
the aiBudgetDailyTotal updates at the later section referenced). Ensure you
reference ensureDailyBudgetTotal, aiBudgetDailyTotal, and the shard
variables/roundUsd calculations when making the change.
---
Outside diff comments:
In `@packages/backend/convex/enrichment.ts`:
- Around line 642-670: The code updates or inserts a single "hot" article
embedding but does not remove older articleEmbeddings rows, leaving stale
duplicates in the vector index; modify the logic around
latestEmbeddingRow/articleEmbeddings to remove all other rows for the same
articleId after you patch or insert: query all rows via
ctx.db.query("articleEmbeddings").withIndex("by_article_version", ...) (or reuse
the existing result set), keep the one you just patched/inserted
(latestEmbeddingRow._id or the newly returned id), and call ctx.db.delete for
any other rows where _id !== keptId so only a single hot row remains; ensure
this cleanup runs both in the branch that calls ctx.db.patch and in the branch
that calls ctx.db.insert.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: f9f5abd1-79f6-446a-bc8b-c7c2bac975d3
⛔ Files ignored due to path filters (1)
packages/backend/convex/_generated/api.d.tsis excluded by!**/_generated/**,!**/_generated/**
📒 Files selected for processing (9)
packages/backend/convex/aiBudget.tspackages/backend/convex/claimDivergence.tspackages/backend/convex/clustering.tspackages/backend/convex/enrichment.tspackages/backend/convex/lib/sourceBias.tspackages/backend/convex/schema.tspackages/backend/convex/sources.tspackages/backend/convex/summarization.tspackages/backend/convex/summarizationNode.ts
Summary by CodeRabbit
New Features
Performance Improvements