Title: fix(knowledge): dispatch document processing from inside Trigger.dev runs by waleedlatif1 · Pull Request #6920 · simstudioai/sim · GitHub
Open Graph Title: fix(knowledge): dispatch document processing from inside Trigger.dev runs by waleedlatif1 · Pull Request #6920 · simstudioai/sim
X Title: fix(knowledge): dispatch document processing from inside Trigger.dev runs by waleedlatif1 · Pull Request #6920 · simstudioai/sim
Description: This is the fix for the knowledge-connector-sync OOMs. isTriggerAvailable() returns false inside Trigger.dev worker runs, so every connector document has been downloaded, parsed, chunked, and embedded inside the sync task at concurrency 5 rather than dispatched to knowledge-process-document. The per-document fan-out is inert in production and has been for some time. Evidence From the crashed run's spans, not inference: The dispatch log line carries backend: "direct" — the literal branch discriminator in processDocumentsWithQueue. dispatchViaBatchTrigger was never entered. Zero knowledge-process-document runs exist for that knowledge base in the window, while five other knowledge bases dispatched normally in the same period. No Failed to batchTrigger, no Trigger.dev batches dispatched, no in-process fallback warning — and other logger.error lines do render in that trace, so the absence is meaningful rather than a gap. On the largest connector — 7,730 documents, individual XLSX files over 20MB (one span shows a 21,099,055-byte buffer, 12 sheets, 65,821 rows) — that exhausts the heap. Smaller connectors do the same in-process work and simply never reach the ceiling, which is why only one connector crashes. Why the previous fix didn't take 04e0fe00c0 (#6869) added syncEnvVars setting TRIGGER_DEV_ENABLED: 'TRUE' for exactly this bug. That commit is in v0.8.7; the crashed run executed on the v0.8.7 deploy. The flag was still effectively false a day later. Its TSDoc also asserts that TRIGGER_SECRET_KEY is something "only the Trigger.dev runtime provides". The SDK's own resolution path (APIClientManagerAPI.accessToken) reads it from the environment with no in-run bypass — if runs lacked it, triggering a child task from inside a task would be impossible, and Trigger.dev documents that as a first-class pattern. So that comment is corrected here. The fix Inside a run the answer is unconditionally yes: the platform is what is executing the process, so no environment guess can be more reliable than the run marker itself. Two independent signals, because this has now been got wrong twice and either alone is a single point of failure: taskContext.isInsideTask — the SDK's ambient flag, already load-bearing in getAsyncBackendType for precisely this carve-out. Its existing comment describes the same bug class: "a worker pod missing TRIGGER_DEV_ENABLED=true silently routes cell jobs to the database backend that nothing's draining." isTriggerAvailable() never got the same treatment. A marker written by the global init lifecycle hook, which uses only the documented public surface and so holds even if the internal taskContext shape moves. It lives on globalThis under a registered symbol rather than in module scope, because the build bundles the config entrypoint alongside the task graph and a duplicated module binding would let the hook write one copy while dispatch reads another. Neither signal reads TRIGGER_SECRET_KEY or TRIGGER_DEV_ENABLED. Non-regressive under either hypothesis about which conjunct was false. If a run process turns out not to expose the secret key, the SDK rejects the batch trigger and dispatchViaBatchTrigger falls back to in-process — which is exactly where a false predicate lands today. Regression guard The first evaluation per process logs the resolved inputs — available, insideTriggerRun, triggerDevEnabled, hasSecretKey. Once per worker process, not per dispatch. A predicate unit test would not have caught either shipment; both were deploy-environment differences. A startup assertion would now be tautological (the init hook makes the predicate true by construction), and a health check tests the app container, which was never broken — the failure is an app-vs-worker asymmetry, visible only from inside a worker. This log names which conjunct is false, which is the question the investigation could not answer from code alone. Blast radius isTriggerAvailable() has three call sites; only processDocumentsWithQueue is reachable inside a run, and it is this incident. dispatchSync and dispatchCleanupJobs are cron-only and unaffected. Noted for follow-up, not touched here: several sites using the plain isTriggerDevEnabled flag do execute inside runs with the same silent-inline failure mode — lib/table/backfill-runner.ts, lib/table/workflow-columns.ts, lib/execution/remote-sandbox/image-registry.ts. And lib/messaging/lifecycle.ts duplicates the same conjunction where the false arm silently drops the email (app-only today, but the same latent bug copy-pasted). Verification type-check clean · check:audits 32/32 · 2,059 tests across lib/knowledge, lib/core, and background. Mutation-checked: disabling the run-marker disjunct turns both "inside a run" dispatch tests red; dropping the init marker turns 4 red; dropping taskContext turns 1 red. No test that cannot fail. Known untested: the init: wiring in trigger.config.ts cannot be unit-tested here, since config hooks are invoked by the Trigger.dev runtime. That is precisely why the fix does not rely on it alone. Follow-up dispatchViaBatchTrigger's per-chunk fallback-on-failure is deliberately untouched — it is the safety net that makes this change non-regressive. Removing it before this lands would delete the only in-process path that isn't firing while leaving the one that is. Dispatch granularity (SYNC_BATCH_SIZE = 5 producing one batchTrigger call per five documents) is a real design smell, but no batchTrigger call has ever been made from a sync worker, so no Trigger.dev limit has been approached. That becomes measurable only after this lands.
Open Graph Description: This is the fix for the knowledge-connector-sync OOMs. isTriggerAvailable() returns false inside Trigger.dev worker runs, so every connector document has been downloaded, parsed, chunked, and embed...
X Description: This is the fix for the knowledge-connector-sync OOMs. isTriggerAvailable() returns false inside Trigger.dev worker runs, so every connector document has been downloaded, parsed, chunked, and embed...
Opengraph URL: https://github.com/simstudioai/sim/pull/6920
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:92258b15-5257-f11b-720b-0e0cdf3a00e5 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D248:9CA74:DEC7B2:131D0E8:6AFB5F0B |
| html-safe-nonce | fad1264f53aa67c316f2508c25ca7563f86de1b72c74874de55492e56316ccbb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjQ4OjlDQTc0OkRFQzdCMjoxMzFEMEU4OjZBRkI1RjBCIiwidmlzaXRvcl9pZCI6Ijc1MTI1MzY3NjQ3ODM0ODQ2ODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b973f694f820076ab99cdd9b1bdaa91cf7b15b457d45b25d5913b55ed56c8f9e |
| hovercard-subject-tag | pull_request:4327751575 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/simstudioai/sim/pull/6920/files |
| twitter:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/40672544?s=400&v=4 |
| og:image:alt | This is the fix for the knowledge-connector-sync OOMs. isTriggerAvailable() returns false inside Trigger.dev worker runs, so every connector document has been downloaded, parsed, chunked, and embed... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ea33d13c96d0ff66bd8fa906b193d2213536b78cb06b0c50a4632c58b1418f94 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/simstudioai/sim git https://github.com/simstudioai/sim.git |
| octolytics-dimension-user_id | 199344406 |
| octolytics-dimension-user_login | simstudioai |
| octolytics-dimension-repository_id | 912559512 |
| octolytics-dimension-repository_nwo | simstudioai/sim |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 912559512 |
| octolytics-dimension-repository_network_root_nwo | simstudioai/sim |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 59ef97164c52cf59bd10558ddec9c4f482763988 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width