improvement(knowledge): batch trigger dispatch, prune redundant DB roundtrips#4680
Conversation
…undtrips Connector sync was dispatching Trigger.dev document-processing jobs one HTTP roundtrip at a time. processDocumentsWithQueue now uses tasks.batchTrigger when Trigger.dev is available, collapsing N roundtrips to ceil(N/1000). Idempotency keys protect against duplicate runs on retry. Also trims DB roundtrips inside the sync loop: - Per-batch isConnectorDeleted + isKnowledgeBaseDeleted collapsed into a single checkSyncLiveness JOIN (one SELECT instead of two per batch). - Dropped redundant pre-upload isKnowledgeBaseDeleted checks from addDocument/updateDocument: the batch-boundary liveness check already catches pre-batch deletions and the in-tx FOR UPDATE is authoritative for races during the batch. - Removed dead processDocumentsWithTrigger helper (never called).
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Batches Trigger.dev processing enqueues. Prunes redundant pre-upload KB deletion checks. Reviewed by Cursor Bugbot for commit a2cf183. Configure here. |
Greptile SummaryThis PR tightens the document-processing dispatch pipeline in two ways: it collapses per-document Trigger.dev
Confidence Score: 5/5Safe to merge — the dispatch and liveness-check refactors are logically equivalent to the paths they replace, and the transactional FOR UPDATE guard that matters for correctness is untouched. Both changed code paths (batch dispatch and liveness JOIN) preserve the observable contract: the same exceptions are thrown on deletion, the same documents land in Trigger.dev, and the direct-mode fallback calls the identical processDocumentAsync signature. The idempotency keys and typed batchTrigger generics are additive improvements with no downside risk. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "improvement(knowledge): thread requestId..." | Re-trigger Greptile |
- Use the canonical DocumentProcessingPayload from the task module instead of the duplicate DocumentJobData interface in service.ts - Pass typeof processDocumentTask as a generic to tasks.batchTrigger so the payload shape is type-checked against the task definition - Inline TRIGGER_BATCH_SIZE provenance (Trigger.dev SDK 4.3.1+ doc'd cap, we're on 4.4.3) - Split direct vs trigger dispatch into dispatchInProcess and dispatchViaBatchTrigger; collapse the all-failed throw into a single check on the combined dispatched counter - Remove dispatchDocumentProcessingJob — its trigger branch is no longer reachable now that batchTrigger handles the trigger path, and the direct branch is inlined
tasks.batchTrigger returns a batchId per call. Collecting and logging them after dispatch makes it possible to look up or cancel batches in the Trigger.dev dashboard when investigating stuck or missing documents.
|
@greptile |
|
@cursor review |
Symmetry polish: dispatchInProcess now includes [requestId] in its error log so direct-mode failures are correlatable the same way trigger-mode failures already are.
Tightens TSDoc on processDocumentsWithQueue, TRIGGER_BATCH_SIZE, checkSyncLiveness, and the idempotency-key inline comment.
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a2cf183. Configure here.
Summary
processDocumentsWithQueuenow usestasks.batchTriggerwhen Trigger.dev is available — collapses N HTTP roundtrips toceil(N / 1000)per dispatch (a 100-doc connector sync drops from 100 calls to 1).doc-process-${documentId}-${requestId}) so retried dispatches don't double-enqueue.isConnectorDeleted+isKnowledgeBaseDeletedchecks merged into onecheckSyncLivenessJOIN — one SELECT instead of two per sync batch.isKnowledgeBaseDeletedchecks fromaddDocument/updateDocument: the batch-boundary liveness check already catches pre-batch deletions, and the in-txSELECT … FOR UPDATEis the authoritative point for mid-batch races.processDocumentsWithTriggerhelper.Type of Change
Testing
lib/knowledge/**,app/api/knowledge/**).dispatchDocumentProcessingJob.Checklist