Skip to content

fix(whatsapp): spawn bridge with proper Windows detach flags to prevent console flash and STATUS_CONTROL_C_EXIT crashes - #60516

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-60508
Closed

fix(whatsapp): spawn bridge with proper Windows detach flags to prevent console flash and STATUS_CONTROL_C_EXIT crashes#60516
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-60508

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a Windows-specific issue where the WhatsApp bridge subprocess (node bridge.js) spawns with a visible console window and crashes every ~2 minutes with exit code 0xC000013A (STATUS_CONTROL_C_EXIT) on native Windows.

On Windows, start_new_session=True is a no-op for subprocess.Popen (per hermes_cli/_subprocess_compat.py). Without proper creationflags, the bridge process inherits the parent's console, causing:

  • A visible cmd.exe window that flashes briefly at startup
  • The bridge being killed by group console CTRL events, triggering endless reconnect/respawn loops

The fix adds creationflags=windows_detach_flags_without_breakaway(), which applies CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS | CREATE_NO_WINDOW on Windows to spawn the bridge as a true detached background daemon without a console window.

Sibling call sites at lines 91/102 already use windows_hide_flags() for short-lived console processes; the bridge spawn site (line ~656) was missed.

Related Issue

Fixes #60508

Type of Change

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

Changes Made

  • plugins/platforms/whatsapp/adapter.py: Import windows_detach_flags_without_breakaway and add creationflags parameter to the bridge subprocess.Popen() call

How to Test

This change is Windows-specific; the macOS host cannot reproduce the original symptom. The fix is a one-line addition of well-tested subprocess compatibility flags.

Verification path:

  1. Run Hermes on native Windows with WhatsApp platform enabled
  2. Observed result: no console window flashes when the bridge starts
  3. Observed result: the bridge remains stable without periodic STATUS_CONTROL_C_EXIT crashes
  4. Observed result: bridge reconnects happen only for actual network issues, not console signal propagation

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
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15.2 (cannot reproduce Windows symptom; fix uses established subprocess compat helpers)

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

…nt console flash and STATUS_CONTROL_C_EXIT crashes

On Windows, start_new_session=True is a no-op for subprocess.Popen.
Without proper creationflags, the bridge inherits the parent console,
causing a visible cmd window flash and periodic crashes from group
CTRL events (exit code 0xC000013A).

This fix adds creationflags=windows_detach_flags_without_breakaway()
which applies CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS |
CREATE_NO_WINDOW to spawn the bridge as a detached background daemon.

Sibling call sites already use windows_hide_flags() for short-lived
console processes; the bridge spawn site was missed.
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows P3 Low — cosmetic, nice to have labels Jul 7, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Competing with #59285 (vizi0uz) for the same issue (#60508). Both add Windows detach flags to the WhatsApp bridge spawn in plugins/platforms/whatsapp/adapter.py. This PR uses windows_detach_flags_without_breakaway() (no CREATE_BREAKAWAY_FROM_JOB), avoiding the PermissionError [WinError 5] that breakaway raises under a non-breakaway Task Scheduler job; #59285 additionally sets CREATE_BREAKAWAY_FROM_JOB. Same goal, different flag choice — flagging for a maintainer pick, not a duplicate.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

This PR is not a duplicate of #59285. While both address issue #60508 (WhatsApp bridge console window on Windows), they use different technical approaches:

Per the issue reporter's analysis:

CREATE_BREAKAWAY_FROM_JOB raises PermissionError [WinError 5] when the gateway runs inside a non-breakaway job (Task Scheduler → wscript → pythonw)

This PR implements the issue reporter's suggested fix to avoid that PermissionError scenario. The approaches target different Windows process spawning constraints and are not mutually exclusive duplicates — they represent alternative solutions for different deployment contexts.

@teknium1

teknium1 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for this PR — the underlying bug (WhatsApp bridge spawning Node with a visible console window on Windows) is now fixed on main via #60924, a salvage of #60647 which swaps the bare start_new_session=True for the shared windows_detach_popen_kwargs() helper. Several PRs targeted this same symptom; we merged the minimal variant that reuses the sanctioned helper. Your report/fix helped confirm the bug class — appreciated. Closing as superseded.

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

Labels

comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WhatsApp bridge spawn flashes a console window and crash-loops with STATUS_CONTROL_C_EXIT on native Windows

3 participants