Skip to content

fix(windows): stop GUI update from stacking visible terminals#167

Closed
Wibias wants to merge 7 commits into
lidge-jun:mainfrom
Wibias:fix/update-restart-no-console-storm
Closed

fix(windows): stop GUI update from stacking visible terminals#167
Wibias wants to merge 7 commits into
lidge-jun:mainfrom
Wibias:fix/update-restart-no-console-storm

Conversation

@Wibias

@Wibias Wibias commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • GUI Update on Windows could open endless stacking terminals that never close.
  • Root cause: Task Scheduler ran opencodex-service.cmd as a visible console, and the wrapper :loop retried ocx start every ~5s when start failed mid-update (often port-busy).
  • Hide the wrapper via a WScript launcher (Run …, 0, False) and point the task at wscript.exe.
  • Re-land port-sticky post-update restart (ocx start --port + prefer-retry / wait-for-free) from closed fix: keep configured port after update restart #152 so restarts do not hop ports and fuel the loop.
  • Under the GUI update worker (OCX_SERVICE=1), use pipe stdio for npm/stop/service children so npm.cmd does not open stacked cmd windows.

Test plan

  • bun test tests/service.test.ts tests/update-job.test.ts tests/update-stop-first.test.ts tests/ports.test.ts
  • Windows: GUI Update with restart — no stacking terminals; proxy returns on configured port (e.g. 10100)
  • If ocx service install is in use: reinstall/update rewrites the hidden VBS+XML; only one wrapper runs

Wibias added 7 commits July 19, 2026 20:42
…le flashes

Pin post-update proxy restart to config.port, wait briefly for the listen socket to free, and avoid spawning visible PowerShell/icacls windows on the start hot path.
Port stickiness stays scoped to restart/port behavior; icacls ACL soft-fail lives elsewhere.
Hide the Task Scheduler wrapper via a WScript launcher (window style 0),
pipe npm/update child stdio under OCX_SERVICE=1, and keep post-update
restart pinned to config.port so failed starts do not fuel the :loop.
Keep main's absorbed port-stickiness + pid identity checks; retain
hidden WScript service launcher and quiet GUI-worker npm stdio.
WaitOnReturn=True so wscript stays alive for the batch lifetime; False made CI see Ready despite a healthy proxy.
lidge-jun added a commit that referenced this pull request Jul 20, 2026
…child stdio (port #167)

- ocx update --help printed nothing useful and ran the REAL self-update,
  stopping the proxy mid-stream. Both entry paths (Bun CLI and the npm bin
  launcher, which intercepts update before Bun starts) now print usage and
  exit 0. Verified live: both print usage, exit 0, no update side effects.
- Port the still-unique part of PR #167: under the GUI update worker
  (OCX_SERVICE=1, stdio ignored) the stop/installer/service-reinstall
  children now use pipe stdio with bounded output relay, so npm.cmd
  (shell:true) cannot open stacked visible consoles on Windows. Backend-
  preserving serviceReinstallArgs() is kept; the rest of #167 is already
  superseded by the dev Windows-service lane.
@lidge-jun

Copy link
Copy Markdown
Owner

Thanks for tracking down the console-storm root cause — the diagnosis in this PR (visible Task Scheduler console + wrapper retry loop) matches what we found independently, and it helped confirm the direction.

Since this PR opened, the dev branch landed its own Windows-service lane that covers most of this change, so I'm closing this as superseded rather than merging into main (our flow is dev → preview → main, and merging here would conflict with the next promotion):

  • Hidden VBS launcher — already on dev (77b966c), with UTF-16LE+BOM VBS/XML so non-ASCII profile paths survive, absolute wscript resolution, and VBS cleanup on uninstall.
  • Port-sticky restart — already on dev in src/update/job.ts (captured live port → configured port → 10100, wait-for-free before start), tightened by fec1e4c from your earlier work.
  • Service reinstall after update — dev goes further and preserves the selected backend (Scheduler vs the new opt-in WinSW --native service) via serviceReinstallArgs().

One part of this PR was still unique and valuable: piping child stdio under the GUI update worker (OCX_SERVICE=1) so npm.cmd doesn't open stacked consoles. That hunk has been ported onto dev in a4f06be with credit, extended to all three update children (stop / installer / service reinstall), keeping serviceReinstallArgs().

So: closed as superseded, with the stdio fix landed. Thanks again!

@lidge-jun lidge-jun closed this Jul 20, 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

Development

Successfully merging this pull request may close these issues.

2 participants