fix enrichment bach - atomic fact extraction - #21
Conversation
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ 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: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThe PR enhances the article enrichment pipeline by splitting combined AI status validators into separate fact and bias validators, introducing attempt-capped retry logic with deferral mechanics, and refactoring fact extraction and bias detection processing from single-shot to chunked operations with budget re-checks. New diagnostic queries and schema fields enable pipeline funnel visibility and attempt tracking. Changes
Sequence Diagram(s)sequenceDiagram
participant Scheduler as Scheduler/Runner
participant Backend as Backend Service
participant DB as Database
participant LLM as LLM Service
participant Budget as Budget Manager
Scheduler->>Backend: Trigger enrichment run
Backend->>DB: claimArticlesNeedingFactExtraction<br/>(limit, leaseExpiresAt, beforePublishedAt,<br/>includeFailed, includeSucceededEmpty)
DB-->>Backend: Return claimed articles batch
Backend->>Backend: Split into chunks (chunkArray)
loop For Each Chunk
Backend->>Budget: Check budget remaining
alt Budget available
Backend->>LLM: Extract facts from chunk
LLM-->>Backend: Fact extraction results
Backend->>DB: markArticleEnriched<br/>(factExtractionStatus, attempts++)
alt All facts extracted
Backend->>Backend: Prepare for bias detection
Backend->>LLM: Score bias from chunk
LLM-->>Backend: Bias detection results
Backend->>DB: markArticleEnriched<br/>(biasDetectionStatus, attempts++)
else LLM omitted articles
Backend->>DB: deferArticleFactExtraction<br/>(deferred, reason)
Note over Backend: Skip bias for deferred articles
end
else Budget exhausted
Backend->>DB: deferArticleFactExtraction<br/>(deferred reason, analyzedAt)
Note over Backend: Remaining chunks deferred for retry
Backend->>Backend: Return control, signal retry needed
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 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)
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. Review rate limit: 0/1 reviews remaining, refill in 40 minutes and 49 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/backend/convex/pipelineDiagnostics.ts`:
- Around line 91-155: The per-event loop in pipelineDiagnostics (the for (const
event of events) loop) issues queries for "articles" and "eventClaims" per event
and can be very slow for large event sets; add a clear doc comment at the top of
the pipelineDiagnostics routine (or immediately above the loop) stating this
function is intended for ad-hoc/diagnostic use only and may be slow for many
events, and either (a) add a configurable maxEvents parameter/default (e.g.,
maxEvents = 1000) and early-return or truncate when events.length > maxEvents,
or (b) document that callers must batch/paginate and not call this frequently;
reference the loop, the articles and eventClaims queries, stageEventIds, and
samples when documenting so future readers know which operations are expensive.
🪄 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: 08e6395f-f64f-4da8-bbbe-ef789851aef4
⛔ Files ignored due to path filters (1)
packages/backend/convex/_generated/api.d.tsis excluded by!**/_generated/**,!**/_generated/**
📒 Files selected for processing (4)
packages/backend/convex/enrichment.tspackages/backend/convex/enrichmentNode.tspackages/backend/convex/pipelineDiagnostics.tspackages/backend/convex/schema.ts
| for (const event of events) { | ||
| stageEventIds.published.add(event._id); | ||
|
|
||
| const articles = await ctx.db | ||
| .query("articles") | ||
| .withIndex("by_event", (q) => q.eq("eventId", event._id)) | ||
| .collect(); | ||
| const sourceCount = new Set(articles.map((article) => article.sourceId)) | ||
| .size; | ||
| const factualArticles = articles.filter(hasAtomicFacts); | ||
| const factualSourceCount = new Set( | ||
| factualArticles.map((article) => article.sourceId), | ||
| ).size; | ||
|
|
||
| if (articles.length >= 3) stageEventIds.article3.add(event._id); | ||
| if (articles.length >= 3 && sourceCount >= 2) { | ||
| stageEventIds.source2.add(event._id); | ||
| } else if (samples.missingArticleCoverage.length < 10) { | ||
| samples.missingArticleCoverage.push({ | ||
| eventId: event._id, | ||
| title: event.title, | ||
| articleCount: articles.length, | ||
| sourceCount, | ||
| }); | ||
| } | ||
|
|
||
| if (articles.length >= 3 && sourceCount >= 2 && factualArticles.length >= 3) { | ||
| stageEventIds.factualArticle3.add(event._id); | ||
| } | ||
| if ( | ||
| articles.length >= 3 && | ||
| sourceCount >= 2 && | ||
| factualArticles.length >= 3 && | ||
| factualSourceCount >= 2 | ||
| ) { | ||
| stageEventIds.factualSource2.add(event._id); | ||
| } else if ( | ||
| articles.length >= 3 && | ||
| sourceCount >= 2 && | ||
| samples.missingFactualCoverage.length < 10 | ||
| ) { | ||
| samples.missingFactualCoverage.push({ | ||
| eventId: event._id, | ||
| title: event.title, | ||
| articleCount: articles.length, | ||
| sourceCount, | ||
| factualArticleCount: factualArticles.length, | ||
| factualSourceCount, | ||
| }); | ||
| } | ||
|
|
||
| if (hasPerspectiveSummary(event)) { | ||
| stageEventIds.summarized.add(event._id); | ||
| } | ||
| if (event.lastClaimAnalysisAt) { | ||
| stageEventIds.claimAnalyzed.add(event._id); | ||
| } | ||
|
|
||
| const hasClaimRows = Boolean( | ||
| await ctx.db | ||
| .query("eventClaims") | ||
| .withIndex("by_event", (q) => q.eq("eventId", event._id)) | ||
| .first(), | ||
| ); | ||
| if (hasClaimRows) stageEventIds.hasClaims.add(event._id); |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Consider performance implications for large event sets.
The loop queries articles and potentially eventClaims for each event (up to 1000 events). While acceptable for an internal diagnostic query, be aware this could be slow with many events. Consider adding documentation noting this is intended for ad-hoc diagnostics rather than frequent automated calls.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/backend/convex/pipelineDiagnostics.ts` around lines 91 - 155, The
per-event loop in pipelineDiagnostics (the for (const event of events) loop)
issues queries for "articles" and "eventClaims" per event and can be very slow
for large event sets; add a clear doc comment at the top of the
pipelineDiagnostics routine (or immediately above the loop) stating this
function is intended for ad-hoc/diagnostic use only and may be slow for many
events, and either (a) add a configurable maxEvents parameter/default (e.g.,
maxEvents = 1000) and early-return or truncate when events.length > maxEvents,
or (b) document that callers must batch/paginate and not call this frequently;
reference the loop, the articles and eventClaims queries, stageEventIds, and
samples when documenting so future readers know which operations are expensive.
Summary by CodeRabbit
New Features
Improvements