Skip to content

fix: show MCPORTER_DEBUG_HANG handle dumps at the default log level - #524

Open
KrasimirKralev wants to merge 1 commit into
openclaw:mainfrom
KrasimirKralev:fix/debug-hang-visible
Open

KrasimirKralev wants to merge 1 commit into
openclaw:mainfrom
KrasimirKralev:fix/debug-hang-visible

Conversation

@KrasimirKralev

@KrasimirKralev KrasimirKralev commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When a mcporter command does not exit, docs/hang-debug.md says to set MCPORTER_DEBUG_HANG=1 and read the active-handle dump. With only that variable set, the dump never appears: the handle lines are logged at info, and the default log level is warn. The only line printed is the final forcibly … child warning, so the person debugging a hang sees nothing that names the handle keeping Node alive.

Raising the level with --log-level info brings the dump back, but info goes to stdout, so the dump lands in the middle of --output json results.

User Impact

MCPORTER_DEBUG_HANG=1 now prints the documented handle and request dump with no other flag. The dump goes to stderr, next to the existing forcibly killed breadcrumb, so stdout keeps only the command result. Runs without MCPORTER_DEBUG_HANG=1 print nothing new. --log-level error still hides these lines, as it already hid the forcibly killed line.

Why This Change Was Made

The hang breadcrumbs (dumpActiveHandles and the two runtime.close() timing lines) now use the same logWarn path as the kill breadcrumb that already showed at the default level. One line in docs/hang-debug.md says the diagnostics go to stderr.

Evidence

Built CLI (pnpm build, node dist/cli.js) against the repo's tests/fixtures/stdio-memory-server.mjs, with MCPORTER_DEBUG_HANG=1 and no --log-level:

$ MCPORTER_DEBUG_HANG=1 node dist/cli.js call --config mcporter.json mem.create_entities 'entities:["a"]' --output json

Before (upstream/main aa8d0c5): exit 0, stdout {"count": 1}, stderr only:

[mcporter] [debug] forcibly kill-failed child pid=<pid> (runtime.finally)

After (this branch): exit 0, stdout still only {"count": 1}, stderr has the documented dump:

[mcporter] [debug] after call (formatted result): 4 active handle(s), 0 request(s)
[mcporter] [debug] handle => Socket addr=undefined:undefined keys=_hadError,_parent,_host,_closeAfterHandlingError
[mcporter] [debug] handle => ChildProcess (pid=<pid>)
[mcporter] [debug] beginning runtime.close()
[mcporter] [debug] before runtime.close: 4 active handle(s), 0 request(s)
[mcporter] [debug] runtime.close() completed in 43ms
[mcporter] [debug] after runtime.close: 2 active handle(s), 0 request(s)
[mcporter] [debug] forcibly kill-failed child pid=<pid> (runtime.finally)
[mcporter] [debug] after terminateChildProcesses: 2 active handle(s), 0 request(s)
(repeated Socket handle lines trimmed)

On main, --log-level info printed the same dump on stdout after the JSON result.

Tests:

  • New case in tests/cli-force-exit-behavior.integration.test.ts runs the built CLI with MCPORTER_DEBUG_HANG=1 and no MCPORTER_LOG_LEVEL. It asserts stdout parses as { ok: true } and stderr has the dump. It fails on main (stderr held only the kill line) and passes on the branch, 3 runs in a row.
  • tests/runtime-debug.test.ts now expects the dump on the warn logger. It fails on main and passes on the branch.
  • pnpm check (oxfmt, oxlint, typecheck) passes.
  • Full pnpm test: 2463 passed, 8 failed. All 8 failures are Bun compile cases in cli-generate-cli.integration.test.ts / generate-cli.test.ts. They are a known environment failure on this machine: its Bun 1.4.0 is older than the 1.4.4 those cases need. None of them touches the files in this PR.
  • Live-server check not run: the fixture is a local stdio MCP server.

@clawsweeper

clawsweeper Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T07:42:01.382859Z b7fed19 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 25, 2026
@clawsweeper

clawsweeper Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR sends opt-in hang diagnostics through the warning logger so they appear by default on stderr.

Example: Run MCPORTER_DEBUG_HANG=1 mcporter call mem.create_entities 'entities:["a"]' --output json.

  • Before: The default log level hides the handle dump; enabling info logging mixes diagnostics into stdout.
  • After: Stderr includes the handle dump and shutdown breadcrumbs while stdout contains only {"count":1}.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, source-verified repair with shipped-CLI output, meaningful regression coverage, passing head checks, and no findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied terminal output exercises the built CLI and real local stdio fixture through the changed diagnostic owner, showing handle and shutdown output on stderr with JSON-only stdout.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Users following the hang-debugging instructions cannot see the promised handle dump, and the info-level workaround contaminates JSON stdout.
Reason: The change restores the documented opt-in behavior with minimal production churn and preserves explicit error-level suppression.

Merge readiness

✅ Ready for maintainer review

Keep open for landing: this PR fixes a documented diagnostic path that remains broken on main, with focused changes, supplied CLI proof, and no actionable findings.

Reviewed head: b7fed197ccc855096423df2c2e51ab87eae35fe3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The CLI inspects Node handles after tool output and around runtime shutdown, then sends diagnostic descriptions through its shared logger.

flowchart TD
A[CLI tool call] --> B[JSON result on stdout]
A --> C[Runtime shutdown]
C --> D[Opt-in handle inspection]
D --> E[Shared warning logger]
E --> F[Diagnostics on stderr]
Loading

Technical review

Best possible solution:

Land the focused logger change with its CLI regression coverage and stderr documentation.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically filters the enabled info-level dumps at the default warn threshold; the contributor also supplies matching before/after CLI output, which this read-only review did not rerun.

Is this the best way to solve the issue?

Using the existing warning logger fixes both visibility and stream routing at their shared diagnostic owner without adding configuration or changing shutdown behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against aa8d0c5ac6cd.

Provenance checked

  • Handle dumps and runtime.close breadcrumbs keeps the original intent (fcd6f7c: Expose active handles and shutdown progress when debugging completed calls that leave Node running.)
  • Diagnostic severity and output stream changes intended behavior with a stated reason (cea53f3: Modularize CLI commands and logging; the extracted diagnostics retained info logging, while log-level controls defaulted to warn.)
  • Existing runtime-debug test expectations keeps the original intent (test: raise coverage to 85% and enforce it in CI #264: Increase behavioral coverage and enforce coverage thresholds; this PR updates those expectations for the corrected diagnostic route.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still hides the requested diagnostics: Main's dumpActiveHandles uses logInfo, while the shared logger defaults to warn and sends info messages to stdout. (src/cli/runtime-debug.ts:76, aa8d0c5ac6cd)
  • Small fix uses the existing stderr owner: The production hunks replace diagnostic logInfo calls with logWarn without changing inspection, cleanup, environment gating, or logger thresholds. (src/cli/runtime-debug.ts:76, b7fed197ccc8)
  • Supplied shipped-CLI proof: The fully read PR body records node dist/cli.js calling the local stdio-memory server before and after the fix: exit 0, unchanged JSON stdout, and handle plus shutdown diagnostics on stderr after the fix. (b7fed197ccc8)
  • Focused regression coverage: The added integration case invokes the built CLI without MCPORTER_LOG_LEVEL, parses stdout as JSON, and checks stderr diagnostics; the contributor reports failure on main and success on the branch. (tests/cli-force-exit-behavior.integration.test.ts:147, b7fed197ccc8)
  • Diagnostic intent predates the logger extraction: The original diagnostic commit documents enabling handle dumps with MCPORTER_DEBUG_HANG=1; the later modularization carries the info calls into runtime-debug.ts without recording a requirement to suppress them at the default threshold. Missing historical blobs limited local git show; REST commit patches supplied the relevant history. (docs/hang-debug.md:19, fcd6f7c6e93d)
  • Checks cover the reviewed head: GitHub reports successful platform build jobs and CodeQL for the reviewed SHA, with no failing checks; the Proof check was skipped, so behavior proof is assessed independently from the supplied terminal output. (b7fed197ccc8)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 25, 2026, 2:53 AM ET / 07:53 UTC.

This branch has not been deployed

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

Labels

impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant