Nx Cloud Self-Healing CI is an AI-powered system that automatically detects, analyzes, and proposes fixes for CI failures, offering several key advantages:
- Improves Time to Green (TTG): Significantly reduces the time it takes to get your PR merge-ready by automatically proposing fixes when your tasks fail. No more babysitting PRs until they are ready for review.
- Keeps You in the Flow: With Nx Console, you get direct notifications in your editor (VS Code, Cursor, or WebStorm) showing failed PRs and proposed fixes. Review, approve, and keep working while the AI handles the rest in the background.
- Leverages Deep Context: AI agents understand your workspace structure, project relationships, and build configurations through Nx's project graph and metadata.
- Non-Invasive Integration: Works with your existing CI provider and doesn't require overhauling your current setup.
Enable Self-Healing CI
Section titled “Enable Self-Healing CI”To enable Self-Healing CI in your workspace, you'll need to connect to Nx Cloud and configure your CI pipeline.
If you haven't already connected to Nx Cloud, run the following command:
npx nx@latest connect
Next, check the Nx Cloud workspace settings in the Nx Cloud web application to ensure that "Self-Healing CI" is enabled (it should be enabled by default).
Configure your CI pipeline
Section titled “Configure your CI pipeline”To enable Self-Healing CI, add the following lines to your CI configuration:
name: CI
jobs: main: runs-on: ubuntu-latest steps: ... - name: Start CI Run - run: npx nx start-ci-run --no-distribution ... - run: npx nx affected -t lint test build
- run: npx nx fix-ci if: always()
If you're already using Nx Agents, then you can omit the --no-distribution
flag and use your existing Nx Agents configuration.
Enable Auto-fixing
Section titled “Enable Auto-fixing”By default, Self-Healing CI proposes a fix for you to review and only applies it automatically to your PR after you confirm it. However, for some tasks, it makes sense to have them be auto-fixed without waiting for manual approval. Auto-fixes are only applied if the verification phase passes.
Below is an example of enabling auto-fixing for the Nx format
command and lint
tasks using the --auto-apply-fixes
flag:
name: CI
jobs: main: runs-on: ubuntu-latest steps: ... - name: Start CI Run run: npx nx start-ci-run --auto-apply-fixes="*format*,*lint*" --no-distribution ...
Tasks are passed to the --auto-apply-fixes
as <project>:<task-name>:<configuration>
. Commands like nx format
which you configure with nx-cloud record --
are passed as nx-cloud record -- <params>
.
Specify Which Tasks to Fix
Section titled “Specify Which Tasks to Fix”By using the --fix-tasks
flag you can fine-tune which tasks should be considered by the Nx Cloud self-healing CI. Below is an example of running self-healing on all tasks except deploy
and test
tasks.
name: CI
jobs: main: runs-on: ubuntu-latest steps: ... - name: Start CI Run run: npx nx start-ci-run --fix-tasks="!*deploy,!*test" --no-distribution
...
Similarly, if you only want to self-heal linting tasks you'd use --fix-tasks="*lint*"
.
Tasks are passed to the --fix-tasks
as <project>:<task-name>:<configuration>
. Commands like nx format
which you configure with nx-cloud record --
are passed as nx-cloud record -- <params>
.
How Self-Healing CI works
Section titled “How Self-Healing CI works”Here's what happens when you push a PR with Self-Healing CI enabled:
1. Failure Detection
Section titled “1. Failure Detection”When you push your PR and tasks fail, Nx Cloud automatically detects the failure and triggers the self-healing process.
2. Fix Generation
Section titled “2. Fix Generation”Nx Cloud starts an AI agent that analyzes the failed tasks and creates an appropriate fix, leveraging the context from Nx and Nx Cloud:
- It has the complete failure context with the exact tasks that ran, including error logs
- Thanks to the Nx graph, it has vast context about the codebase, including project structure, dependencies, configuration, and runnable tasks
3. Notification
Section titled “3. Notification”Once the fix is available, you'll be notified immediately based on where you're currently working:
In your editor: If you have Nx Console installed, you'll get a notification directly in your editor:
Clicking the notification will open a dedicated view showing the failed task log, the status of the fix as well as the actual git diff.
In your browser: If you're not currently working in your editor, you will also see the notification about an available fix from Nx Cloud directly in your GitHub PR comments:
4. Verification
Section titled “4. Verification”While you're being notified, Nx Cloud automatically runs a verification phase in the background.
The purpose is to rerun the failed task with the proposed fix to make sure it actually solves the issue. This step can be skipped if you see the proposed fix and already know that it is valid. However, it is a useful additional step to verify the correctness of the change.
5. Review & Apply
Section titled “5. Review & Apply”You can review the fix and decide whether to apply or reject it. If you apply the fix, Nx Cloud automatically pushes a commit to your original PR.
Open the Nx Console view or click the PR fix notification.
Review the Git diff directly in the commend and click "Apply fix" or "Reject fix" to take immediate action. If you want to take a closer look, you can click "View interactive diff" and you'll be redirected to the Nx Cloud app which has a more sophisticated diff viewer.
Apply Fixes Locally
Section titled “Apply Fixes Locally”If you want to tweak a fix before committing it, you can apply it locally rather than having it pushed directly to your PR. To do this, use the corresponding buttons on the GitHub comment, Nx Console view, or Nx Cloud app to get the command to run locally:
Learn more
Section titled “Learn more”Self-Healing CI represents the next evolution in CI automation, moving beyond just speeding up builds to actually fixing them automatically. Learn more about this feature in our blog post: Introducing Self-Healing CI for Nx and Nx Cloud.