Skip to content

fix(dev): open inspector only in the process serving the app - #1388

Merged
danielroe merged 2 commits into
mainfrom
fix/inspect-flag
Jul 25, 2026
Merged

fix(dev): open inspector only in the process serving the app#1388
danielroe merged 2 commits into
mainfrom
fix/inspect-flag

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves #1195
resolves #1369

📚 Description

this bundles some fixes for native --inspect usage

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@danielroe, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d0ae49e4-3cab-405b-90ee-c0c370fbf62e

📥 Commits

Reviewing files that changed from the base of the PR and between a945895 and 51c2b8d.

📒 Files selected for processing (7)
  • packages/nuxt-cli/src/commands/dev.ts
  • packages/nuxt-cli/src/dev/index.ts
  • packages/nuxt-cli/src/dev/inspect.ts
  • packages/nuxt-cli/src/dev/pool.ts
  • packages/nuxt-cli/src/dev/utils.ts
  • packages/nuxt-cli/test/unit/help.spec.ts
  • packages/nuxt-cli/test/unit/inspect.spec.ts
📝 Walkthrough

Walkthrough

The nuxt dev command now supports --inspect and --inspect-brk, parses inspector host and port options, and manages inspector startup and shutdown. Inspector configuration is propagated through fork-pool IPC to the development process. Fork cleanup is asynchronous, preventing restart races before reusing inspector ports. Unit tests cover inspector argument parsing, and the help snapshot includes the new options.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: inspector startup is restricted to the app-serving process.
Description check ✅ Passed The description is brief but clearly related to the native --inspect fixes in this PR.
Linked Issues check ✅ Passed The changes satisfy [#1195, #1369] by preventing duplicate inspector binds and supporting custom host/port parsing.
Out of Scope Changes check ✅ Passed The diff stays focused on inspector handling, fork lifecycle cleanup, and matching tests, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/inspect-flag

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 25, 2026

Copy link
Copy Markdown
  • nuxt-cli-playground

    npm i https://pkg.pr.new/create-nuxt@1388
    
    npm i https://pkg.pr.new/nuxi@1388
    
    npm i https://pkg.pr.new/@nuxt/cli@1388
    

commit: 51c2b8d

@codspeed-hq

codspeed-hq Bot commented Jul 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing fix/inspect-flag (51c2b8d) with main (a94b9f5)

Open in CodSpeed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/nuxt-cli/src/commands/dev.ts (1)

160-166: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Close the inspector on every terminal close path.

--no-fork/profile returns close directly, and closeAll can run before the first fork handoff; both leave the parent inspector listening after the dev server closes. Wrap terminal closes with closeInspector() in a finally block.

Also applies to: 223-225

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/nuxt-cli/src/commands/dev.ts` around lines 160 - 166, Update the
terminal close paths in the dev command, including the direct return around
setupShortcuts and closeAll, so they always invoke closeInspector() in a finally
block after closing the dev server. Ensure the inspector is closed when
--no-fork/profile exits directly and when closeAll runs before the first fork
handoff, while preserving the existing close behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/nuxt-cli/src/commands/dev.ts`:
- Around line 36-43: Update the dev command option handling around the inspect
and inspect-brk definitions so inline Node inspector targets such as
--inspect=host:port remain available to resolveInspectOptions(ctx.rawArgs).
Either exclude these Node-style flags from citty parsing and read them from
unprocessed CLI/exec arguments, or configure the command to preserve unknown
options, while retaining normal boolean flag behavior when no inline value is
supplied.

In `@packages/nuxt-cli/src/dev/inspect.ts`:
- Around line 95-100: Update openInspector so it preserves an existing inspector
session when inspector.url() reports port, host, and wait settings compatible
with the requested options; do not call inspector.close() or reopen in that
case. Only close and invoke inspector.open when an explicit option override
changes the target, while retaining the existing native process.execArgv
configuration behavior.

---

Outside diff comments:
In `@packages/nuxt-cli/src/commands/dev.ts`:
- Around line 160-166: Update the terminal close paths in the dev command,
including the direct return around setupShortcuts and closeAll, so they always
invoke closeInspector() in a finally block after closing the dev server. Ensure
the inspector is closed when --no-fork/profile exits directly and when closeAll
runs before the first fork handoff, while preserving the existing close
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: acb9e3db-334f-4ce4-b417-0dc5cb15fbce

📥 Commits

Reviewing files that changed from the base of the PR and between a94b9f5 and a945895.

📒 Files selected for processing (7)
  • packages/nuxt-cli/src/commands/dev.ts
  • packages/nuxt-cli/src/dev/index.ts
  • packages/nuxt-cli/src/dev/inspect.ts
  • packages/nuxt-cli/src/dev/pool.ts
  • packages/nuxt-cli/src/dev/utils.ts
  • packages/nuxt-cli/test/unit/help.spec.ts
  • packages/nuxt-cli/test/unit/inspect.spec.ts

Comment thread packages/nuxt-cli/src/commands/dev.ts
Comment on lines +95 to +100
try {
if (inspector.url()) {
inspector.close()
}
// Node itself logs `Debugger listening on …` when the inspector opens.
inspector.open(options.port, options.host, options.wait)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🌐 Web query:

For supported Node.js versions, what occurs when inspector.close()followed byinspector.open(port, host, true)is called after the process was launched with--inspect-brk and execution has resumed?

💡 Result:

When a Node.js process is launched with the --inspect-brk flag, the V8 inspector is activated automatically, and the process pauses execution on the first line of code to wait for a debugger client to connect [1][2]. If you call inspector.close while the process is running, the inspector server is deactivated, and all active inspector connections are forcibly terminated [3][4]. Subsequently calling inspector.open(port, host, true) will restart the inspector on the specified port and host [3][5]. Because the wait parameter is set to true, the Node.js process will block execution at that point until a debugger client connects to the new inspector instance [3][6]. Once a client connects, the process will resume execution [3][5]. In summary, the sequence effectively re-initializes the inspector and forces the application to pause and wait for a new debugging session, effectively re-entering the "wait-for-debugger" state despite the process having already been running [3]. Top results: [3][5][4]

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant file/module without executing repository code.
if [ -f packages/nuxt-cli/src/dev/inspect.ts ]; then
  echo "== file exists =="
  wc -l packages/nuxt-cli/src/dev/inspect.ts
  echo
  sed -n '1,140p' packages/nuxt-cli/src/dev/inspect.ts | cat -n
else
  echo "== file missing =="
  fd -a 'inspect\.ts$' .
fi

echo
echo "== related inspect argument references =="
rg -n "openInspector|resolveInspectOptions|process\.execArgv|\\-\\-inspect(-brk)?|inspect\.open|inspector\.close|wait" packages/nuxt-cli/src packages 2>/dev/null || true

echo
echo "== changed file stat =="
git diff --stat
echo
git diff -- packages/nuxt-cli/src/dev/inspect.ts | sed -n '1,240p'

Repository: nuxt/cli

Length of output: 50365


🌐 Web query:

Node.js inspect.close deactivates inspector server inspector.clientClosedEvent on connections closed

💡 Result:

The inspector.close() method in Node.js is responsible for deactivating the inspector [1][2]. When called, it forcibly terminates any active connections and blocks execution until the inspector server has fully stopped [1][3]. Regarding your query about inspector.clientClosedEvent, there is no documented event by this exact name in the standard Node.js inspector module API [1][3]. The module's primary events are managed through the inspector.Session class, which emits close events when a session is disconnected [4]. In summary, inspector.close() deactivates the inspector and ensures all connections are terminated [1][3]. If you are looking for information on connection lifecycle events, you should refer to the inspector.Session class documentation, which handles connection-specific events such as inspectorNotification and session termination [4][5].

Citations:


Preserve an existing native inspector session.

When the native process.execArgv inspection configuration wins, Node opens the inspector before openInspector() runs. Closing it inlines inspector.close() and then calling inspector.open(..., options.wait) deactivates existing connections and re-waits if options.wait is true. Preserve an existing inspect URL when its port, host, and wait settings already satisfy the requested options, and only reopen when an explicit override changes the target.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/nuxt-cli/src/dev/inspect.ts` around lines 95 - 100, Update
openInspector so it preserves an existing inspector session when inspector.url()
reports port, host, and wait settings compatible with the requested options; do
not call inspector.close() or reopen in that case. Only close and invoke
inspector.open when an explicit option override changes the target, while
retaining the existing native process.execArgv configuration behavior.

@danielroe
danielroe merged commit 8f10582 into main Jul 25, 2026
19 checks passed
@danielroe
danielroe deleted the fix/inspect-flag branch July 25, 2026 15:36
This was referenced Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant