← Back to Pull requests

fix(cli): strip supervisor node IPC channel vars from spawned node envs #139582

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 16, 2026 03:02 UTC
Author

What does this PR do?

When the dashboard runs under a fork-mode supervisor like pm2, the supervisor injects NODE_CHANNEL_FD / NODE_CHANNEL_SERIALIZATION_MODE into the Python process it manages. Every node child the dashboard then spawns — the chat PTY's TUI entry, the freshness.mjs probe, node-deps.mjs — inherits those variables, sees a node IPC channel is declared, and tries to adopt the named fd. Python spawns with the default close_fds=True, so that fd is already closed in the child and its number gets reused by node's own internals (eventfd/epoll); libuv registers it twice and aborts at exit (uv__io_poll ... Assertion errno == EEXIST, SIGABRT). The user-visible symptom in #139556 is the Chat page stuck on "connection interrupted, reconnecting…" forever (PTY dies before writing its session file), plus thousands of aborts in the pm2 error log.

Hermes never makes its children IPC-channel peers of an external supervisor, so the two channel variables have no valid meaning in any child env this repo builds. This PR strips them at the two child-env exits every affected spawn flows through:

  • hermes_cli/web_server_chat.py _resolve_chat_argv — the chat PTY env (PtyBridge.spawn consumes it verbatim).

  • pm/package.py compose_env — the single composition exit behind pm.env_for("node") (the freshness.mjs probe) and ensure("npm", ...).env (the node-deps.mjs / build chain).
  • build_subprocess_env itself is deliberately left byte-preserving on its no-scrub path (its existing contract, locked by test_no_scrub_is_byte_preserving_except_explicit_extra); the strip happens at the dashboard caller where the node-child policy belongs.

    Related Issue

    Fixes #139556

    Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • Changes Made

  • hermes_cli/web_server_chat.py: _resolve_chat_argv pops NODE_CHANNEL_FD / NODE_CHANNEL_SERIALIZATION_MODE from the chat PTY env before it is returned to the spawn site.

  • pm/package.py: compose_env pops the same two variables right after the base snapshot, so every PM-composed child env (node/npm probes and builds) is clean.

  • tests/hermes_cli/test_web_server_profile_unification.py: regression test — _resolve_chat_argv must not carry the supervisor's channel vars.

  • tests/pm/test_pm_core.py: regression test — compose_env strips the channel vars both from a base dict and from the os.environ snapshot path env_for("node") uses.
  • How to Test

    1. uv run pytest tests/pm/test_pm_core.py::test_compose_env_strips_node_ipc_channel_vars "tests/hermes_cli/test_web_server_profile_unification.py::TestProfileScopedChatPty" tests/tools/test_build_subprocess_env.py -q — Observed result: 14 passed (new tests included; the byte-preserving no-scrub contract still passes).
    2. uv run pytest tests/pm/test_pm_core.py tests/hermes_cli/test_source_build.py tests/hermes_cli/test_web_server_pty_reconnect.py tests/hermes_cli/test_pty_keepalive_ws.py tests/hermes_cli/test_web_server_pty_idle_backoff.py -q — Observed result: 58 passed, 12 skipped (environment-dependent skips), 0 failed.
    3. Manual equivalent of the production path: NODE_CHANNEL_FD=13 node -e '0' aborts with the libuv EEXIST assertion (per #139556); with this change the dashboard-built child envs no longer contain the variable, so the spawned node processes are unaffected by the supervisor's leftover channel vars.

    Checklist

    Code

  • I've read the Contributing Guide

  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)

  • I searched for existing PRs to make sure this isn't a duplicate

  • My PR contains only changes related to this fix/feature (no unrelated commits)

  • I've run pytest tests/ -q and all tests pass (targeted suites: the pm core, source-build, PTY/chat env suites listed under How to Test — all green)

  • python scripts/check passes (the blocking lint and code-health checks CI runs) (ruff/format green on the touched files; blob-size/health could not be evaluated faithfully in the local shared-object clone and are left to CI)

  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)

  • I've tested on my platform: macOS 15 (arm64); the failing path itself is Linux/pm2 per #139556
  • Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A

  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A

  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A

  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A

  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A
  • For New Skills

    N/A — this is a bug fix, no skill added.

    Screenshots / Logs

    N/A — env-level fix; the reproduction and libuv assertion output are documented in #139556.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: PRATHAMESH75 Review duration: 70413m
    All Vouch review confidence checks passed
    Residual risk 0.35 = Change Risk (0.59) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #139582"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 34.8% · Safe to merge
    34.8%