This repository reproduces and verifies the fix for a bug where continuous task stats are not properly recorded after Ctrl-C.
When multiple continuous tasks run from a single Nx command (e.g., nx serve app which triggers both a build-watch dependency and the dev server), tasks were missing from postTasksExecution plugin hooks after Ctrl-C.
-
Multiple
process.exit()calls on SIGINT - Several locations callprocess.exit()immediately when SIGINT is received, before the orchestrator can complete cleanup:src/executors/run-commands/running-tasks.js(line 345)src/tasks-runner/forked-process-task-runner.js(line 162, 299)src/tasks-runner/task-orchestrator.js(lines 491, 536)
-
No SIGINT handler in non-TUI mode - The orchestrator's
run()method only registers a shutdown handler for TUI mode, leaving non-TUI runs stuck inPromise.race(). -
Missing cleanup of continuous tasks - The
cleanup()method didn't callpostRunSteps()for continuous tasks before killing them.
The patch (patches/nx@22.3.3.patch) includes:
- Remove immediate
process.exit()on SIGINT - Changed to let the orchestrator complete cleanup first - Add SIGINT handler for non-TUI mode - Allows
Promise.race()to resolve on Ctrl-C - Call
postRunSteps()incleanup()before killing - Records stats for continuous tasks - Add
cleaningUpguards - Prevents premature exits during cleanup - Guard
postRunSteps()against duplicates - Filters already-completed tasks
pnpm install./test-continuous-stats.shOr manually:
# Run serve with timeout
NX_DAEMON=false timeout --signal=INT 4 npx nx serve app
# Check the stats plugin output
cat task-stats.json | jq '.summary'With patch (fixed):
✅ PASS: All 2 continuous tasks properly recorded
Present: app:build-watch, app:serve
Without patch (bug):
❌ FAIL: postTasksExecution was not called
The repository uses an NX plugin (plugins/stats-plugin.js) that implements:
preTasksExecution- Records when tasks startpostTasksExecution- Records task results after completion
This plugin verifies that the postTasksExecution hook receives all continuous tasks after SIGINT.
plugins/stats-plugin.js- NX plugin that tracks task lifecycle eventspatches/nx@22.3.3.patch- pnpm patch with the fixtest-continuous-stats.sh- Automated test scriptproject.json- Definesserveandbuild-watchtargetsnx.json- Marks targets as continuous and registers the plugin