Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Nx Continuous Tasks Stats Bug Reproduction

This repository reproduces and verifies the fix for a bug where continuous task stats are not properly recorded after Ctrl-C.

Problem Summary

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.

Root Causes

  1. Multiple process.exit() calls on SIGINT - Several locations call process.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)
  2. 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 in Promise.race().

  3. Missing cleanup of continuous tasks - The cleanup() method didn't call postRunSteps() for continuous tasks before killing them.

The Fix

The patch (patches/nx@22.3.3.patch) includes:

  1. Remove immediate process.exit() on SIGINT - Changed to let the orchestrator complete cleanup first
  2. Add SIGINT handler for non-TUI mode - Allows Promise.race() to resolve on Ctrl-C
  3. Call postRunSteps() in cleanup() before killing - Records stats for continuous tasks
  4. Add cleaningUp guards - Prevents premature exits during cleanup
  5. Guard postRunSteps() against duplicates - Filters already-completed tasks

Setup

pnpm install

Test the Fix

./test-continuous-stats.sh

Or 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'

Expected Results

With patch (fixed):

✅ PASS: All 2 continuous tasks properly recorded
   Present: app:build-watch, app:serve

Without patch (bug):

❌ FAIL: postTasksExecution was not called

How It Works

The repository uses an NX plugin (plugins/stats-plugin.js) that implements:

  • preTasksExecution - Records when tasks start
  • postTasksExecution - Records task results after completion

This plugin verifies that the postTasksExecution hook receives all continuous tasks after SIGINT.

Files

  • plugins/stats-plugin.js - NX plugin that tracks task lifecycle events
  • patches/nx@22.3.3.patch - pnpm patch with the fix
  • test-continuous-stats.sh - Automated test script
  • project.json - Defines serve and build-watch targets
  • nx.json - Marks targets as continuous and registers the plugin

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages