ductor icon indicating copy to clipboard operation
ductor copied to clipboard

Windows background task flashes console windows for some subprocess probes

Open Tony-ooo opened this issue 5 months ago • 1 comments

Summary

On Windows, a ductor instance installed with uv tool install ductor and run as a background Scheduled Task can still flash a short-lived console/Windows Terminal window during startup or common bot actions.

This appears to happen because ductor correctly starts the background bot with pythonw.exe -m ductor_bot, but several non-interactive subprocess calls still launch console-subsystem executables without CREATE_NO_WINDOW.

Environment

  • OS: Windows 11
  • ductor: 0.18.0
  • Python: 3.12.11
  • Install mode: uv tool install ductor
  • Background startup: Windows Task Scheduler

The scheduled task action is effectively:

%APPDATA%\uv\tools\ductor\Scripts\pythonw.exe -m ductor_bot

Actual behavior

While ductor is running in the background, a terminal/console window briefly flashes. I have noticed this around startup and common status/auth/model-check flows.

Expected behavior

When ductor is running as a background Windows task via pythonw.exe, non-interactive subprocesses should not create visible console windows.

Investigation notes

Some subprocess sites already pass the shared Windows creation flag:

creationflags=_CREATION_FLAGS

For example, the shared CLI executor and some provider subprocesses already do this.

However, several other non-interactive subprocess calls appear to omit it. Examples in 0.18.0:

  • ductor_bot/cli/auth.py
    • _claude_cli_logged_in() runs claude auth status
    • _antigravity_cli_logged_in() runs agy models
  • ductor_bot/cli/gemini_utils.py
    • npm root -g
    • node --input-type=module ...
  • ductor_bot/infra/pidlock.py
    • _is_process_alive_windows() runs tasklist
  • ductor_bot/infra/process_tree.py
    • _run_taskkill() runs taskkill
    • _kill_ductor_exe_windows() runs tasklist
    • _kill_venv_python_windows() runs powershell
  • ductor_bot/infra/updater.py
    • _run_upgrade_command() may run uv tool upgrade
    • get_installed_version() runs a child Python process

These are the kinds of console-subsystem child processes that can become visible when the parent is pythonw.exe and there is no inherited console.

Why this looks source-side rather than uv-side

The uv.exe and generated console-script launchers are console-subsystem executables on Windows, so they can trigger a console if launched from a GUI/no-console parent. But the scheduled task itself is already configured to use pythonw.exe, which is correct. The remaining visible flashes seem to come from ductor's own child process creation paths that do not consistently apply the Windows hidden-window flag.

Possible fix

Centralize subprocess creation for non-interactive commands and apply CREATE_NO_WINDOW on Windows by default, e.g. via a helper wrapping:

  • subprocess.run
  • subprocess.check_output
  • subprocess.Popen
  • asyncio.create_subprocess_exec

Interactive subprocesses could explicitly opt out.

This would make the existing pythonw.exe Scheduled Task behavior consistently windowless.

Tony-ooo avatar Jun 12 '26 15:06 Tony-ooo

Fixed in v0.18.1. All the non-interactive subprocess probes you listed (claude/agy auth checks, gemini npm/node discovery, pidlock tasklist, process_tree taskkill/tasklist/powershell, and the updater) now pass CREATE_NO_WINDOW via the shared infra/platform.py::CREATION_FLAGS, so a background bot started as pythonw.exe no longer flashes a console window. Your investigation notes made this a quick, targeted fix — thank you.

Release: https://github.com/PleasePrompto/ductor/releases/tag/v0.18.1

PleasePrompto avatar Jun 13 '26 05:06 PleasePrompto