Skip to content

Windows: Kanban worker crashes with NoConsoleScreenBufferError when stdout is redirected #22445

@forztf

Description

@forztf

Bug Description

On Windows 11, kanban workers crash immediately at startup when stdout is redirected to a log file. The crash occurs in _cprint() -> _pt_print() -> prompt_toolkit's create_output(), which raises NoConsoleScreenBufferError because there is no Win32 console buffer attached.

Environment

  • OS: Windows 11
  • Hermes Agent: v0.13.0 (2026.5.7)
  • Shell: git-bash (MSYS) — dispatcher runs here
  • Python: 3.12
  • prompt_toolkit: bundled venv

Reproduction Steps

  1. Create a kanban task: hermes kanban add "test task"
  2. Dispatch it: hermes kanban dispatch
  3. The spawned worker process (hermes chat -q "work kanban task ...") crashes immediately.

Stack Trace

File "cli.py", line 9602, in chat
    _cprint(f"{_DIM}Initializing agent...{_RST}")
File "cli.py", line 1480, in _cprint
    _pt_print(_PT_ANSI(text))
File "prompt_toolkit/shortcuts/utils.py", line 111, in print_formatted_text
    output = get_app_session().output
File "prompt_toolkit/application/current.py", line 67, in output
    self._output = create_output()
File "prompt_toolkit/output/defaults.py", line 91, in create_output
    return Win32Output(stdout, default_color_depth=color_depth_from_env)
File "prompt_toolkit/output/win32.py", line 115, in __init__
    info = self.get_win32_screen_buffer_info()
File "prompt_toolkit/output/win32.py", line 219, in get_win32_screen_buffer_info
    raise NoConsoleScreenBufferError
prompt_toolkit.output.win32.NoConsoleScreenBufferError: Found xterm-256color,
while expecting a Windows console.

Root Cause

The kanban dispatcher spawns workers via subprocess.Popen in _default_spawn() (hermes_cli/kanban_db.py, line 3760):

proc = subprocess.Popen(
    cmd,
    stdin=subprocess.DEVNULL,
    stdout=log_f,          # <-- redirected to file
    stderr=subprocess.STDOUT,
    env=env,
    start_new_session=True,
)

The child process has no Win32 console. When cli.py's chat() method calls _cprint("Initializing agent...") at line 9602, it invokes _pt_print(_PT_ANSI(text)). On Windows, prompt_toolkit's create_output() detects a non-console stdout and raises NoConsoleScreenBufferError.

_cprint() has no fallback for this exception — it propagates up and kills the worker before it can do any work.

Suggested Fix

Add a try/except around _pt_print calls in _cprint() (cli.py) to fall back to a plain print() when prompt_toolkit cannot create a Win32 console output:

def _cprint(text: str):
    _record_output_history(text)
    # ... existing imports ...
    try:
        _pt_print(_PT_ANSI(text))
    except Exception:
        # Windows: NoConsoleScreenBufferError when stdout is redirected
        # (kanban workers, piped output). Fall back to plain print.
        print(text)

This should wrap every _pt_print(_PT_ANSI(text)) call in _cprint() (lines 1480, 1504, 1516, 1524).

Impact

  • Severity: High — kanban is completely broken on Windows.
  • Scope: Only affects Windows when stdout is not a real console (kanban workers, redirected/piped output).
  • Normal interactive CLI: Not affected (has a real console).

Workaround

None currently. The worker crashes on every dispatch attempt, making kanban unusable on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/cliCLI entry point, hermes_cli/, setup wizardsweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions