fix(trigger): let workers see that Trigger.dev is available - #6869
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview
Reviewed by Cursor Bugbot for commit 3868baa. Configure here. |
Greptile SummaryThis PR enables Trigger.dev availability checks inside Trigger.dev workers and recovers partially failed document enqueues by processing those documents in-process.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issue identified. The worker flag parses as intended, queued batches retain their existing behavior, and failed batches use the existing per-document in-process path with bounded concurrency and isolated error handling.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/knowledge/documents/service.ts | Adds bounded in-process recovery for document chunks whose Trigger.dev batch enqueue throws; no actionable defect was established. |
| apps/sim/trigger.config.ts | Synchronizes the existing Trigger.dev enablement flag into worker environments so nested dispatch paths use the queue. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
Sync[Connector sync worker] --> Available{Trigger.dev available?}
Available -- No --> Local[Process documents in-process]
Available -- Yes --> Batch[Enqueue document batches]
Batch --> Success[Trigger.dev document workers]
Batch -->|Batch enqueue fails| Recover[Collect undispatched documents]
Recover --> Local
Success --> Process[Parse, chunk, embed, and persist]
Local --> Process
Reviews (1): Last reviewed commit: "fix(trigger): let workers see that Trigg..." | Re-trigger Greptile
Workers run Trigger.dev by definition, but the flag saying so is read from the environment and had only ever been set on the app container. isTriggerAvailable() was therefore false inside every task run, so work a task dispatched silently took the in-process fallback instead of the queue it was written for. Document processing is where this showed: a connector sync chunked and embedded its documents itself, five at a time, rather than handing them to the document-processing queue. The queue's concurrency limit, the per-document task's machine, retry policy and duration budget all sat unused, and a sync with thousands of documents ran until it hit its own max duration. It also explains why that task has no runs for connector-synced knowledge bases at all. Asserting the flag here is safe because the same check still requires TRIGGER_SECRET_KEY, which only the Trigger.dev runtime provides: anywhere dispatching is not actually possible the flag stays ineffective and behaviour is unchanged. Dispatch failure is now recoverable rather than silent. Only a total failure raised before, so one failed batch left its documents at pending with nothing recording why. Those are processed in-process instead, which costs the caller the time it hoped to hand to the queue but does not drop the work. That path was unreachable from a worker until this change made dispatching happen there.
…ation Both sets explained the incident that motivated the code rather than the code itself. That kind of narrative stops being true as the surrounding system moves and starts misleading instead, so each is cut back to the reason a reader needs.
7ed1ead to
fbc21e6
Compare
Problem
isTriggerAvailable()isBoolean(env.TRIGGER_SECRET_KEY) && isTriggerDevEnabled, andisTriggerDevEnabledreadsTRIGGER_DEV_ENABLED. That variable is set on the app container but not in the Trigger.dev environment, so the check is false inside every task run — and work a task dispatches silently takes the in-process fallback instead of the queue it was written for.TRIGGER_DEV_ENABLEDisTriggerAvailable()TRUEdispatchInProcessDocument processing is where this surfaced. A connector sync chunks and embeds its own documents at
IN_PROCESS_DISPATCH_CONCURRENCY = 5instead of handing them toknowledge-process-document, so that task's queue concurrency limit, machine, retry policy and duration budget all sit unused, and a sync with thousands of documents runs until it hits its own max duration.Evidence, three independent ways:
MAX_DURATION_EXCEEDED."Document dispatch failed"— a string that appears in exactly one place in the codebase, thedispatchInProcesscatch block.knowledge-process-documenthas zero runs for that knowledge base over two days, despite thousands of documents being processed.The flag is read in 17 files, so the same silent downgrade applies to any dispatching path reachable from a task run, table backfills and imports among them.
Change
Assert the flag for workers via the
syncEnvVarsextension that already runs there forDB_APP_NAME. Putting it intrigger.config.tskeeps it version-controlled and reviewable rather than being dashboard state that can drift out of agreement with the app again.This is fail-safe. The availability check still requires
TRIGGER_SECRET_KEY, which only the Trigger.dev runtime provides. Anywhere dispatching is not actually possible, the flag stays ineffective and behaviour is unchanged — the change cannot enable dispatch in an environment that cannot dispatch.Dispatch failure is also made recoverable. Only a total failure raised before, so a single failed batch left its documents at
pendingwith nothing recording why — invisible until the stuck-document sweep happened to reach them, and never if they aged out of its 7-day window first. Those are now processed in-process instead: it costs the caller the time it hoped to hand to the queue, but the work is not dropped. That path was unreachable from a worker until this change made dispatching happen there, which is why it belongs with it.Risk and how to verify
This changes where document processing executes for every connector sync, so it is worth watching rather than assuming:
knowledge-process-documentruns appear for connector-synced knowledge bases, where there are currently none; connector sync runs get much shorter.Also here
A comment trim, carried in a second commit rather than its own PR. Both this change's TSDoc and the quota classification's from #6868 explained the incident that motivated the code rather than the code itself — narrative that stops being true as the system moves and misleads instead. Each is cut back to the reason a reader needs; no behaviour change.
Verification