home / skills / rstackjs / agent-skills / rspack-debugging

rspack-debugging skill

/skills/rspack-debugging

This skill helps you debug Rspack crashes and hangs by guiding automated LLDB backtrace capture and artifact collection for rapid root-cause analysis.

npx playbooks add skill rstackjs/agent-skills --skill rspack-debugging

Review the files below or copy the command above to add this skill to your agents.

Files (9)
SKILL.md
3.6 KB
---
name: rspack-debugging
description: Helps Rspack users and developers debug crashes or deadlocks/hangs in the Rspack build process using LLDB. Use this Skill when users encounter "Segmentation fault" errors during Rspack builds or when the build progress gets stuck.
---

# Rspack Debugging

## Overview

This Skill guides you on how to capture the underlying crash state of Rspack (which is based on Rust). By using the LLDB debugger and Rspack packages with debug symbols, we can obtain detailed stack backtraces, which are crucial for pinpointing issues. The guides focus on non-interactive, automated debugging to easily capture backtraces.

## Preparation

Before starting, please ensure your environment meets the requirements.

1.  **Install LLDB**: You must install the LLDB debugger.
    *   macOS: Run `xcode-select --install`
    *   Linux: Install the `lldb` package (e.g., `apt-get install lldb`)
    *   Detailed guide: [references/lldb.md](references/lldb.md)

2.  **Replace Debug Packages**:
    Production packages like `@rspack/core` have debug symbols stripped. They must be replaced with the `@rspack-debug/*` series packages to see useful stack information.

    **Automatic Replacement Script**:
    ```bash
    node ${CLAUDE_PLUGIN_ROOT}/skills/debugging/scripts/setup_debug_deps.cjs
    ```
    Running the above script will automatically add `pnpm.overrides` configuration to `package.json`, pointing Rspack packages to their corresponding Debug versions. Afterwards, please be sure to run `pnpm install` to update dependencies.

## Debugging Workflows

Identify your specific scenario and follow the corresponding linked guide.

## Detailed Guides

## Detailed Guides

### Guide A: Crash during HMR
**Scenario**: Stable Crash/Deadlock during DevServer HMR.
[Read Guide: references/guide_a_hmr_crash.md](references/guide_a_hmr_crash.md)

### Guide B: Crash during Build
**Scenario**: Stable Crash/Deadlock during Build (or Unstable Build Crash that is frequent enough).
[Read Guide: references/guide_b_build_crash.md](references/guide_b_build_crash.md)

### Guide C: Attach to Stuck Process
**Scenario**: Unstable Deadlock during Build (happens randomly).
[Read Guide: references/guide_c_attach_to_stuck_process.md](references/guide_c_attach_to_stuck_process.md)

### Guide D: Coredump Analysis (Dev)
**Scenario**: Unstable Crash during DevServer HMR (hard to catch interactively).
[Read Guide: references/guide_d_coredump_analysis_dev.md](references/guide_d_coredump_analysis_dev.md)

### Guide E: Coredump Analysis (Build)
**Scenario**: Unstable Crash during Build.
[Read Guide: references/guide_e_coredump_analysis_build.md](references/guide_e_coredump_analysis_build.md)

### Guide F: Async Deadlock Identification
**Scenario**: Unstable Async Deadlock. Main thread stuck in `uv_run`.
[Read Guide: references/guide_f_async_deadlock.md](references/guide_f_async_deadlock.md)

## Saving Debug Artifacts

**Critical Instruction for Agents**:
When you successfully obtain a backtrace or a tracing log, you **MUST** save it to a local file in the user's project directory so it is preserved after the session.

1.  **Create Directory**: Ensure a directory named `debug_artifacts` exists in the project root.
2.  **Save Backtraces**: Write the full output of `thread backtrace all` to `debug_artifacts/backtrace_<timestamp>.txt`.
3.  **Save Tracing Logs**: (Only if using Tracing Skill)

## Environment Restoration

After debugging is complete, restore your `package.json` to use production packages:

```bash
node ${CLAUDE_PLUGIN_ROOT}/skills/debugging/scripts/setup_debug_deps.cjs --restore
pnpm install
```

Overview

This skill helps Rspack users and developers capture and analyze crashes, deadlocks, and hangs in the Rspack build process using LLDB and debug-symbol packages. It focuses on non-interactive, repeatable debugging to produce reliable backtraces and diagnostic artifacts. Use it when you see segmentation faults or when builds hang or stall.

How this skill works

The skill instructs you to install LLDB, swap production Rspack packages for debug-symbol variants, and run targeted workflows to capture backtraces or attach to stuck processes. It automates dependency overrides, describes scenario-based workflows (HMR, build, coredump, async deadlocks), and requires saving debug outputs to project-local artifact files for later analysis. It also includes steps to restore the normal production setup after debugging.

When to use it

  • You encounter a Segmentation fault during an Rspack build or dev server run.
  • Build progress stalls or the process appears deadlocked or hung.
  • Crashes are reproducible and you can run the build under a debugger.
  • Crashes are intermittent but frequent enough to attach to a stuck process.
  • You need detailed Rust backtraces that are not available in production packages.

Best practices

  • Install and verify LLDB before trying to capture crashes (macOS: xcode-select --install; Linux: apt-get install lldb).
  • Replace production packages with @rspack-debug/* variants to retain debug symbols; use the provided setup script to automate overrides.
  • Run the scenario-specific guide that matches the failure: HMR, build, attach-to-stuck, or coredump workflows.
  • Always save full backtraces and any tracing logs to a debug_artifacts directory in the project root with timestamps.
  • After debugging, restore package.json to production packages and run pnpm install to return to normal operation.

Example use cases

  • Stable crash during DevServer HMR: follow the HMR crash guide to capture a deterministic backtrace.
  • Stable build crash: switch to debug packages and run the build under LLDB to get thread backtraces.
  • Intermittent deadlock during builds: attach LLDB to the stuck process and dump all thread stacks for analysis.
  • Hard-to-catch crashes: collect coredumps and analyze them with LLDB to extract the crash state and stack traces.

FAQ

How do I enable debug-symbol packages quickly?

Run the provided node script to add pnpm.overrides for @rspack-debug/* packages, then run pnpm install.

Where should I store backtraces and logs?

Create a debug_artifacts directory at the project root and save backtraces as backtrace_<timestamp>.txt and tracing logs there.