Skip to content

feat(core): add nx show running-tasks CLI command#34591

Draft
juristr wants to merge 6 commits intomasterfrom
feat/show-running-tasks
Draft

feat(core): add nx show running-tasks CLI command#34591
juristr wants to merge 6 commits intomasterfrom
feat/show-running-tasks

Conversation

@juristr
Copy link
Member

@juristr juristr commented Feb 25, 2026

Current Behavior

AI agents can access running task information through Nx Console's MCP server, which receives updates from the TUI via a socket-based JSON-RPC channel. However, this requires VSCode with Nx Console installed. Terminal-based agents (Claude Code, Cursor terminal, etc.) that don't have access to Nx Console have no way to query running task status — even though the Nx CLI already has this information internally.

Expected Behavior

Expose running task information directly via the Nx CLI with nx show running-tasks. Since the CLI already tracks this data through its lifecycle system, this provides a more direct path for any agent to query task status without depending on Nx Console or the MCP server.

Usage

# List all running tasks (JSON output)
nx show running-tasks

# Get log output for a specific task (last 100 lines)
nx show running-tasks --task myapp:serve

Output Format

[
  {
    "pid": 12345,
    "command": "nx run-many -t build,serve",
    "startTime": "2026-02-24T10:00:00.000Z",
    "tasks": {
      "myapp:build": {
        "status": "success",
        "continuous": false,
        "startTime": "2026-02-24T10:00:01.000Z",
        "endTime": "2026-02-24T10:00:05.000Z"
      },
      "myapp:serve": {
        "status": "in-progress",
        "continuous": true,
        "startTime": "2026-02-24T10:00:05.000Z"
      }
    }
  }
]

Architecture

nx run-many -t build,serve            nx show running-tasks
        │                                      │
        │ LifeCycle hooks                      │ daemon client
        ▼                                      ▼
   ┌──────────────────── Nx Daemon ─────────────────────────┐
   │  In-memory: Map<pid, RunningProcessState>              │
   │                                                        │
   │  REGISTER_RUNNING_TASKS    → store initial state       │
   │  UPDATE_RUNNING_TASKS      → update task statuses      │
   │  UNREGISTER_RUNNING_TASKS  → remove on end             │
   │  GET_RUNNING_TASKS         → return all active runs    │
   │  GET_RUNNING_TASK_OUTPUT   → return task's log output  │
   └────────────────────────────────────────────────────────┘

Running nx processes report state to the daemon via a new DaemonReportingLifeCycle. The nx show running-tasks command queries the daemon. No files on disk, no new sockets — reuses existing daemon IPC infrastructure.

Key implementation details

  • 5 new daemon message types for register/update/unregister/get tasks/get output
  • DaemonReportingLifeCycle — fire-and-forget reporting, never blocks task execution, batches output with 2s interval flush
  • Ring buffer — last 100 lines of output per task stored in daemon memory
  • Dead PID pruningGET_RUNNING_TASKS prunes processes that are no longer alive
  • Multiple concurrent runs — each nx process registers with its own PID

Edge cases handled

  • Daemon disabled (NX_DAEMON=false, CI) → lifecycle silently no-ops
  • Daemon crashes mid-run → lifecycle catches errors, task execution unaffected
  • Process killed without cleanup → GET_RUNNING_TASKS prunes dead PIDs
  • Multiple nx run processes simultaneously → each registers with own PID
  • No tasks running → returns []
  • --task with non-existent task → clear error message with list of available tasks

Related Issue(s)

@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 64acf17
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69a5a7de677b9e0008cdf630
😎 Deploy Preview https://deploy-preview-34591--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 64acf17
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69a5a7de463b3c00084e156b
😎 Deploy Preview https://deploy-preview-34591--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Feb 25, 2026

View your CI Pipeline Execution ↗ for commit 64acf17

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 55m 33s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 28s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-02 16:07:54 UTC

@juristr juristr self-assigned this Feb 25, 2026
juristr added 6 commits March 2, 2026 16:04
Add message types, server handler, and client methods to track
running task state in the daemon's memory. This enables live querying
of task status from separate CLI processes.
Reports task status and output to the daemon via existing IPC.
Debounces output flushes at 2s intervals. Fire-and-forget to never
block task execution. Only active when daemon is enabled.
Queries the daemon for live task status. Returns JSON by default.
Use --task <taskId> to get log output for a specific running task.
Return raw objects from handlers instead of JSON.stringify'd strings.
The daemon's IPC layer handles serialization — double-serializing
caused "[object Object]" parse errors on the client.
Plain string responses fail isJsonMessage() detection on the client,
causing v8 deserialization error. Wrap in { output } object instead.
@juristr juristr force-pushed the feat/show-running-tasks branch from f898b23 to 64acf17 Compare March 2, 2026 15:08
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx create-nx-workspace@22.6.0-pr.34591.64acf17 my-workspace

Or just copy this version and use it in your own command:

22.6.0-pr.34591.64acf17
Release details 📑
Published version 22.6.0-pr.34591.64acf17
Triggered by @juristr
Branch feat/show-running-tasks
Commit 64acf17
Workflow run 22585594020

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant