← Back to Pull requests

Suppress Windows console windows for console-subsystem children (#9430) #9435

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 25, 2026 11:56 UTC
Author

Fixes #9430

Problem

On Windows, loopx flashes black console windows while running, and the detached usage observer intermittently fails with error 2147942632 (0x800700E8) (Win32 232, ERROR_NO_DATA, "The pipe is being closed") when launching python.exe -P -m loopx.usage_goal.

Windows allocates a visible conhost window for every console-subsystem child (node.exe, python.exe, git.exe) whose parent has no console. A single goal start from a console-less host (bootstrap, agent registration, requirement/todo writes, quota guards) runs dozens of such children. The 0x800700E8 failure is the detached-observer pipe race: a child that exits before reading (for example a suppressed observer) closes its stdin pipe first, and the parent's write then fails with ERROR_NO_DATA.

Affected sites enumerated on current main

Reporter's v2.4.1 list, verified against this main:

| Site | Child | Change |
| --- | --- | --- |
| loopx/control_plane/runtime/node_probe.py probe_node | node | CREATE_NO_WINDOW via shared helper |
| loopx/control_plane/effect_runtime.py _start_runtime Popen | node (long-lived runtime host) | CREATE_NO_WINDOW via shared helper |
| loopx/usage_ping.py control() | node | CREATE_NO_WINDOW via shared helper |
| loopx/usage_ping.py _detach() | node / loopx.usage_goal | Flags already correct (DETACHED_PROCESS \| CREATE_NEW_PROCESS_GROUP, no console); the stdin write/close is now tolerant of the child-closed pipe (the 0x800700E8 race) |

Cross-check additions in the same goal-start/turn/quota flow on current main:

| Site | Child | Change |
| --- | --- | --- |
| loopx/registry.py run_git (todo/status readback probes) | git | CREATE_NEW_PROCESS_GROUP \| CREATE_NO_WINDOW (group flag kept for tree termination) |
| loopx/control_plane/agents/workspace_guard.py (2 git probes, agent registration) | git | CREATE_NO_WINDOW |
| loopx/control_plane/todos/completion_validation.py _git_workspace_is_clean | git | CREATE_NO_WINDOW |
| loopx/control_plane/goals/planning_batch.py CliPlanningBatchBackend._call | loopx CLI | CREATE_NO_WINDOW |
| loopx/control_plane/status/goal_source.py _run | declared source command / ssh | CREATE_NO_WINDOW |
| loopx/control_plane/runtime/validation_command.py _direct_validation | caller-declared validator | CREATE_NO_WINDOW (the supervised POSIX flock path is POSIX-only by design and untouched) |
| loopx/control_plane/quota/scheduler_ack.py _run_native_followup | node (heartbeat follow-up) | CREATE_NO_WINDOW |
| loopx/entrypoint.py Windows native follow-up re-exec | node | CREATE_NO_WINDOW (Windows-only branch) |
| loopx/control_plane/heartbeat/installed_prompt_update.py prompt sync | loopx CLI | CREATE_NO_WINDOW |
| loopx/control_plane/turn_driver/host_process_transport.py bridge Popen | node | CREATE_NO_WINDOW |
| loopx/control_plane/turn_driver/codex_stdio.py StdioNativeGoalTransport.spawn | host process | CREATE_NO_WINDOW |
| loopx/control_plane/turn_driver/command_validation.py turn validator | validator command | CREATE_NO_WINDOW |
| loopx/control_plane/turn_driver/codex_execution_preparation.py _default_runner | launcher | CREATE_NO_WINDOW |
| loopx/control_plane/state_recovery_io.py _audit_owners | node recovery worker | CREATE_NO_WINDOW |

TypeScript hosts that spawn console children and were missing the existing windowsHide precedent (host_process.ts, zcode_goal_mode/*, effect_runtime_snapshot.ts already had it):

| Site | Child | Change |
| --- | --- | --- |
| loopx/pi_goal_mode/loopx-goal.ts (2 execFile sites) | loopx CLI | windowsHide: true |
| loopx/control_plane/coordination/shadow_drain_files.ts | python shadow-lock host | windowsHide: true |
| loopx/control_plane/capabilities/explore_research_terminal.ts | python snapshot host | windowsHide: true |
| loopx/control_plane/coordination/nokv_jsonl_transport.ts default factory | NoKV helper | windowsHide: true |

Implementation

  • One shared helper no_console_creationflags() in loopx/extensions/process_runtime.py: returns subprocess.CREATE_NO_WINDOW only on Windows and only when the parent has no console, which is the one case in which Windows allocates a new console for a child. It returns 0 (subprocess's default) for an attached parent, on every other platform, and when the console query cannot be answered. A child of an attached parent inherits its console and opens no window, so every site keeps exactly its previous behavior there; passing the flag to an attached parent would instead detach the child from the console its output is read on. Non-Windows behavior is byte-for-byte unchanged.

  • Console query: the parent counts as attached when either GetConsoleCP() or GetConsoleWindow() succeeds (a console-less process fails both). Any success counting as attached is the safe direction — the only cost of a wrong "attached" is an unsuppressed window, never a lost receipt.

  • The helper is imported lazily at each call site (in-function or via the existing _PROCESS_RUNTIME_EXPORTS lazy reexport in validation_command.py) so the repo's cold-import contracts (tests/test_process_runtime_loading.py: loopx.contract, loopx.doctor_git, validation_command, host_bridge_transport must not load the process transport at import) keep holding.

  • _detach() keeps DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP (the observer is deliberately console-free) with fully redirected stdio (PIPE/DEVNULL/DEVNULL); the fix makes the parent's write-and-close non-fatal when the child wins the race, matching the documented best-effort telemetry contract. This one change is not Windows-only: on POSIX the same early child exit previously surfaced as BrokenPipeError from the write-and-close; it now returns normally (verified with real child processes on macOS: normal reads pass before and after; an early-closing child raised on the previous behavior and returns cleanly now).

  • DETACHED_PROCESS and CREATE_NO_WINDOW are mutually exclusive creation flags; no site combines them.
  • Windows-only default-behavior disclosure

    The console-suppression change is Windows-only, and on Windows it is confined to a console-less parent (apart from the _detach() write-and-close behavior above, which applies everywhere): children spawned by the listed sites no longer allocate a console host window there, and the detached observer's early-exit race no longer surfaces as an error. A parent attached to a console (a user running loopx in PowerShell or cmd) and all other platforms pass creationflags=0 / omit the option, which is identical to the previous behavior.

    Windows verification status: the reviewer ran the previous head on a real Windows 10 host and measured that the suppression works (the child gets no console) and that the flag, applied unconditionally, silently removed the foreground receipt of the one site that does not redirect its streams (loopx/entrypoint.py:155). That finding is what the attached-parent rule above fixes. The fix itself has not been run on Windows — I have no Windows host. It rests on the reviewer's two measured cells (attached without the flag keeps the receipt; console-less with the flag opens no window); a two-line check for both branches is in the review reply. The visible window and pipe behavior is otherwise owned by CI's Windows lanes; the host-agnostic tests below prove the flags are computed and passed on the spawn-option objects.

    Out of scope (follow-up candidates using the same helper)

    Dev/CI tooling (loopx/canary/, loopx/control_plane/testing/, benchmark_toolkit, experiments), capability adapters wrapping interactive external CLIs, MCP/collaboration daemon spawns (operation_wake, collaboration_mcp, remote_authority_gateway, delegation_preview_transport), SSH lifecycle transports, self-update/installer flows (already detached where relevant), and stdio_transport.py (POSIX-only by design).

    Test evidence (all on macOS)

  • New tests/test_child_console_suppression.py (30 tests): each site's spawn options (creationflags equals the helper value on POSIX; equals CREATE_NO_WINDOW under an emulated Windows os.name on a console-less parent, via a module-scoped proxy that also answers the console query), the registry's composed CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW, the detached observer's Windows flags, and the pipe-closed write race staying non-fatal. Added for the attached-parent rule: the helper across three hosts (POSIX → 0, Windows console-less → CREATE_NO_WINDOW, Windows attached → 0); the _console_attached truth table (both queries failing → not attached, either succeeding → attached); the reported site with an attached parent passing creationflags == 0 and redirecting nothing, and with a console-less parent passing the flag; a redirected receipt on a console-less host still arriving through capture_output=True.

  • tests/extensions/test_process_runtime.py: helper computation (0 off Windows, 0x08000000 emulated on a console-less parent, 0 without the constant, 0 on an attached parent, 0 and no exception when the console query is unanswerable).

  • Touched-module suites: 1143 passed / 0 failed across usage_ping/usage_goal, registry, effect_runtime node probe, scheduler_ack, completion validation (4 files + MCP), planning batch, goal source, execution preparation, workspace guard, state recovery, leased host process, host launch authority, process runtime (4 files), entrypoint and core distribution contract tests.

  • TypeScript: npm run typecheck:control-plane clean; node test suites for the touched TS modules (nokv transport, shadow drain, explore research execution): 421 passed. loopx/pi_goal_mode/loopx-goal.ts is outside the repo's tsconfig (host-provided dependencies); a direct tsc comparison shows the identical pre-existing error set before/after, i.e. no new type errors.

  • ruff check on all touched files: clean.

  • After merging current main 811c1a1f6 (74a33c350; all six files touched by both sides merged cleanly): the two test files above 95 passed / 1 skipped; the 51 test files of every touched module 1355 passed / 0 failed / 8 skipped (two test_effect_runtime_equivalence.py cases first failed only because this worktree's local origin/main ref was eight days stale — they load origin/main:…effect_runtime.py as their baseline and pass 10/10 once the ref is refreshed; _uses_stdio_runtime comes from main's #9140, not from this PR).

  • uv run --extra test loopx canary premerge --from-git-diff --git-diff-base 811c1a1f6: 18 checks passed, 0 failures.

  • Pre-existing failures unrelated to this change: tests/control_plane/test_native_user_completion_update.py (12 parametrizations, HTTP 404s) fail identically on pristine main at the merge base (verified in a throwaway worktree).
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: BigDataDZ Review duration: 8181m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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%
    46%
    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 #9435"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 27.7% · Safe to merge
    27.7%