René's URL Explorer Experiment


Title: Fix/orphaned worker processes by thegodtune · Pull Request #3481 · triggerdotdev/trigger.dev · GitHub

Open Graph Title: Fix/orphaned worker processes by thegodtune · Pull Request #3481 · triggerdotdev/trigger.dev

X Title: Fix/orphaned worker processes by thegodtune · Pull Request #3481 · triggerdotdev/trigger.dev

Description: Closes #2909 ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention I ran and tested the code works Testing Ran existing taskRunProcess.test.ts suite, passes clean Added taskRunProcessPool.test.ts covering getAllPids() on a fresh pool Integration test against local self-hosted instance: Started CLI with locally built binary against http://localhost:3030 Triggered a 60-second sleep task to force worker processes to spawn Confirmed active-runs.json contained real PIDs in workerPids Sent kill -9 , bypassing all signal handlers, exactly what pnpm does Waited 5 seconds for watchdog poll cycle ps -p ,, -> All dead ✔️ Changelog Fix orphaned trigger-dev-run-worker processes that accumulate and consume significant CPU when the CLI is killed ungracefully via SIGKILL. The watchdog now reads worker PIDs from active-runs.json and kills them when the parent CLI process dies. Screenshots Fix: Kill orphaned worker processes when the CLI is killed ungracefully Problem When running trigger.dev dev through pnpm and the session is stopped, trigger-dev-run-worker child processes are left alive on the machine, consuming significant CPU, up to 450%+ combined after several restarts. The root cause is how pnpm handles process termination. When you do Ctrl+C, pnpm sends SIGKILL directly to the CLI process, not SIGTERM. SIGKILL cannot be caught or handled. Node.js signal handlers (process.on("SIGINT", ...), process.on("SIGTERM", ...)) never run. The graceful shutdown() path, which calls taskRunProcessPool.shutdown() and kills all tracked worker processes, is bypassed entirely. On Linux and macOS, child processes are not automatically killed when their parent dies. So the trigger-dev-run-worker processes spawned by TaskRunProcess.initialize() via fork() continue running indefinitely, orphaned, with no parent to report to and no work to do. What already existed PR #3191 introduced a detached watchdog process (devWatchdog.ts) that survives SIGKILL and handles server-side cleanup. It polls for parent death, then calls /engine/v1/dev/disconnect to cancel in-flight runs on the server. This is correct and important. However, the watchdog only addresses the server's view of those runs. It does not kill the actual OS-level worker processes on the user's machine. Those processes keep running regardless of what the API call does. How I found it Tracing the codebase from the issue report: DevSupervisor.init() registers SIGINT/SIGTERM handlers and spawns the watchdog, but those handlers are unreachable under SIGKILL. TaskRunProcessPool manages two maps: availableProcessesByVersion (idle, reusable processes) and busyProcessesByVersion (actively executing). Both are populated with TaskRunProcess instances, each wrapping a forked child process with a known PID. DevSupervisor.#updateActiveRunsFile() writes active-runs.json to .trigger/ in the user's project directory, the file the watchdog reads on parent death. It contained parentPid and runFriendlyIds but not the worker PIDs. devWatchdog.ts reads that file in onParentDied(), calls disconnect, and exits. No process killing. The gap: the watchdog had everything it needed to cancel runs on the server, but no information about which OS processes to kill locally. What I changed Three files, one new test file. 1. packages/cli-v3/src/dev/taskRunProcessPool.ts Added getAllPids(), which collects PIDs from both the available and busy process maps: getAllPids(): number[] { const pids: number[] = []; for (const processes of this.availableProcessesByVersion.values()) { for (const process of processes) { if (process.pid !== undefined) pids.push(process.pid); } } for (const processSet of this.busyProcessesByVersion.values()) { for (const process of processSet) { if (process.pid !== undefined) pids.push(process.pid); } } return pids; } This includes both idle pooled processes and actively executing ones; both are orphaned under SIGKILL. 2. packages/cli-v3/src/dev/devSupervisor.ts Two changes here: #updateActiveRunsFile(), now includes workerPids alongside the existing fields: const data = { parentPid: process.pid, runFriendlyIds: Array.from(this.runControllers.keys()), workerPids: this.taskRunProcessPool?.getAllPids() ?? [], }; Periodic refresh interval, I discovered during testing that a timing issue exists: worker processes are spawned after #updateActiveRunsFile() is first called when a run is dequeued, so the file would be written before the PID existed, leaving workerPids empty. A 2-second refresh interval keeps the file current as processes enter and leave the pool: // In init(): this.activeRunsUpdateInterval = setInterval(() => { this.#updateActiveRunsFile(); }, 2_000); // In shutdown(): if (this.activeRunsUpdateInterval) { clearInterval(this.activeRunsUpdateInterval); } The interval is cleared on clean shutdown, so it doesn't interfere with the normal Ctrl+C exit path. 3. packages/cli-v3/src/dev/devWatchdog.ts Updated readActiveRuns() to return the new workerPids field, and added killWorkerProcesses() called at the start of onParentDied(): async function killWorkerProcesses(pids: number[]): Promise { for (const pid of pids) { try { process.kill(pid, "SIGTERM"); } catch { /* Already dead */ } } if (pids.length === 0) return; await new Promise((resolve) => setTimeout(resolve, 3_000)); for (const pid of pids) { try { process.kill(pid, 0); process.kill(pid, "SIGKILL"); } catch { /* Already dead, good */ } } } Worker processes are killed before the disconnect API call; there's no dependency between the two, but it makes sense to handle the local machine first. How I tested it Unit tests: ran the existing taskRunProcess.test.ts suite (passes clean) and added taskRunProcessPool.test.ts covering getAllPids() returning an empty array on a fresh pool and returning only defined numeric values. Integration test against a local self-hosted instance: ran the full Docker stack and webapp locally, then: Started the CLI with the locally built binary pointed at http://localhost:3030 Triggered a long-running task (60-second sleep) to force worker processes to spawn Confirmed active-runs.json contained real PIDs in workerPids Sent SIGKILL to the CLI process (kill -9 ) — bypassing all signal handlers, exactly what pnpm does Waited 5 seconds for the watchdog's poll cycle to detect parent death Checked all worker PIDs: ps -p ,, → All dead ✓ Before this fix, the same sequence left all worker processes running indefinitely. After, they're gone within the watchdog's poll interval. Backward compatibility The change to active-runs.json is additive; workerPids defaults to [] if the field is missing, so any existing watchdog reading an old-format file degrades gracefully. The periodic interval only runs during an active dev session and is always cleared on clean shutdown, leaving the normal Ctrl+C path completely unaffected. Fixes #2909

Open Graph Description: Closes #2909 ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention I ran and tested the code works Testing Ran existing taskRunProcess.test.ts ...

X Description: Closes #2909 ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention I ran and tested the code works Testing Ran existing taskRunProcess.test.ts ...

Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/3481

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:a263a508-0264-3d93-d4dd-e96f141114d7
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9AF6:376D0C:443257B:5C90684:6AFAE146
html-safe-nonce1ad3df6f0269ff5c6e61e9ac3b47cb178a811a289deec80b090ce6cd9f3ae1af
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QUY2OjM3NkQwQzo0NDMyNTdCOjVDOTA2ODQ6NkFGQUUxNDYiLCJ2aXNpdG9yX2lkIjoiNjY2NTYxNjYzOTA0MTEzNDkxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace28eff459b46be1c052999b3d98c1d4cc5857fe181c02d3d35ac352e0af47a22
hovercard-subject-tagpull_request:3610384533
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/pull/3481/files
twitter:imagehttps://avatars.githubusercontent.com/u/37498608?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/37498608?s=400&v=4
og:image:altCloses #2909 ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention I ran and tested the code works Testing Ran existing taskRunProcess.test.ts ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None9d9bd51a568909a83d1abb9d6f74d68f0c87ca85fe3a56d3f5d70d8b89add9f2
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git
octolytics-dimension-user_id95297378
octolytics-dimension-user_logintriggerdotdev
octolytics-dimension-repository_id572570113
octolytics-dimension-repository_nwotriggerdotdev/trigger.dev
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id572570113
octolytics-dimension-repository_network_root_nwotriggerdotdev/trigger.dev
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4a7ae932999cc6d511008dbf980ff9efad2a31f7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/triggerdotdev/trigger.dev/pull/3481/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftriggerdotdev%2Ftrigger.dev%2Fpull%2F3481%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftriggerdotdev%2Ftrigger.dev%2Fpull%2F3481%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=triggerdotdev%2Ftrigger.dev
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/3481/files
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/3481/files
Reloadhttps://github.com/triggerdotdev/trigger.dev/pull/3481/files
triggerdotdevhttps://github.com/triggerdotdev
trigger.devhttps://github.com/triggerdotdev/trigger.dev
Codehttps://github.com/triggerdotdev/trigger.dev
Issues203 (203)https://github.com/triggerdotdev/trigger.dev/issues
Pull requests66 (66)https://github.com/triggerdotdev/trigger.dev/pulls
Discussionshttps://github.com/triggerdotdev/trigger.dev/discussions
Actionshttps://github.com/triggerdotdev/trigger.dev/actions
Projectshttps://github.com/triggerdotdev/trigger.dev/projects
Security and quality39 (39)https://github.com/triggerdotdev/trigger.dev/security
Insightshttps://github.com/triggerdotdev/trigger.dev/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Ftriggerdotdev%2Ftrigger.dev%2Fissues%2Fnew%2Fchoose
thegodtunehttps://github.com/thegodtune
triggerdotdev:mainhttps://github.com/triggerdotdev/trigger.dev/tree/main
thegodtune:fix/orphaned-worker-processeshttps://github.com/thegodtune/trigger.dev/tree/fix/orphaned-worker-processes
Conversation 4 https://github.com/triggerdotdev/trigger.dev/pull/3481
Commits 2 https://github.com/triggerdotdev/trigger.dev/pull/3481/commits
Checks 2 https://github.com/triggerdotdev/trigger.dev/pull/3481/checks
Files changed https://github.com/triggerdotdev/trigger.dev/pull/3481/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/3481/files
Fix/orphaned worker processes https://github.com/triggerdotdev/trigger.dev/pull/3481/files#top
Show all changes 2 commits https://github.com/triggerdotdev/trigger.dev/pull/3481/files
7cc02ee fix: kill orphaned worker processes when CLI is killed ungracefully thegodtune Apr 30, 2026 https://github.com/triggerdotdev/trigger.dev/pull/3481/commits/7cc02ee3d8691e724ec721e99f87890adcb5b0f1
85952d8 chore: add changeset thegodtune Apr 30, 2026 https://github.com/triggerdotdev/trigger.dev/pull/3481/commits/85952d8db70d806611f0c5a6373c25fabaac2cd6
Clear filters https://github.com/triggerdotdev/trigger.dev/pull/3481/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/3481/files
Please reload this pagehttps://github.com/triggerdotdev/trigger.dev/pull/3481/files
silly-planes-march.md https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-31fd4c93f117e91fadc7da656d1cb872eb0693059ac8954663ee4bf37692ce28
devSupervisor.ts https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
devWatchdog.ts https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-924000127cbd2c80eb673384e5a539c836aa7850262700657769949dc6edf620
taskRunProcessPool.test.ts https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-c6084a5cd4adb11e75da574152e1f2dc230ad638d53d0e710eb70b92d94b9794
taskRunProcessPool.ts https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-45d1aea79764748e4ba25f46e22a2305dd2031dd8505ac7b131b2c3376331577
.changeset/silly-planes-march.mdhttps://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-31fd4c93f117e91fadc7da656d1cb872eb0693059ac8954663ee4bf37692ce28
View file https://github.com/thegodtune/trigger.dev/blob/85952d8db70d806611f0c5a6373c25fabaac2cd6/.changeset/silly-planes-march.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/3481/{{ revealButtonHref }}
packages/cli-v3/src/dev/devSupervisor.tshttps://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
View file https://github.com/thegodtune/trigger.dev/blob/85952d8db70d806611f0c5a6373c25fabaac2cd6/packages/cli-v3/src/dev/devSupervisor.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/3481/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-071ef3fb057647679a2bd68f4e5dbf642a873e637baaa657347b5a7bf1d701c3
packages/cli-v3/src/dev/devWatchdog.tshttps://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-924000127cbd2c80eb673384e5a539c836aa7850262700657769949dc6edf620
View file https://github.com/thegodtune/trigger.dev/blob/85952d8db70d806611f0c5a6373c25fabaac2cd6/packages/cli-v3/src/dev/devWatchdog.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/3481/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-924000127cbd2c80eb673384e5a539c836aa7850262700657769949dc6edf620
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-924000127cbd2c80eb673384e5a539c836aa7850262700657769949dc6edf620
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-924000127cbd2c80eb673384e5a539c836aa7850262700657769949dc6edf620
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-924000127cbd2c80eb673384e5a539c836aa7850262700657769949dc6edf620
packages/cli-v3/src/dev/taskRunProcessPool.test.tshttps://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-c6084a5cd4adb11e75da574152e1f2dc230ad638d53d0e710eb70b92d94b9794
View file https://github.com/thegodtune/trigger.dev/blob/85952d8db70d806611f0c5a6373c25fabaac2cd6/packages/cli-v3/src/dev/taskRunProcessPool.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/3481/{{ revealButtonHref }}
packages/cli-v3/src/dev/taskRunProcessPool.tshttps://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-45d1aea79764748e4ba25f46e22a2305dd2031dd8505ac7b131b2c3376331577
View file https://github.com/thegodtune/trigger.dev/blob/85952d8db70d806611f0c5a6373c25fabaac2cd6/packages/cli-v3/src/dev/taskRunProcessPool.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/triggerdotdev/trigger.dev/pull/3481/{{ revealButtonHref }}
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-45d1aea79764748e4ba25f46e22a2305dd2031dd8505ac7b131b2c3376331577
https://github.com/triggerdotdev/trigger.dev/pull/3481/files#diff-45d1aea79764748e4ba25f46e22a2305dd2031dd8505ac7b131b2c3376331577
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.