Skip to content

fix(windows): handle redirected stdout in _cprint fallback#28083

Closed
Grogger wants to merge 1 commit into
NousResearch:mainfrom
Grogger:fix/windows-cprint-console-fallback
Closed

fix(windows): handle redirected stdout in _cprint fallback#28083
Grogger wants to merge 1 commit into
NousResearch:mainfrom
Grogger:fix/windows-cprint-console-fallback

Conversation

@Grogger

@Grogger Grogger commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Wraps _pt_print in try/except with a print() fallback in _cprint. When a kanban worker's stdout is piped to a log file, prompt_toolkit raises NoConsoleScreenBufferError (Windows) or OSError (other) because there is no real console buffer. The fallback keeps worker output flowing instead of crashing.

Why

The _cprint function is used by kanban workers to print status messages. On Windows, git-bash sets TERM=xterm-256color, which causes prompt_toolkit to attempt terminal initialization and fail when stdout is redirected to a log file. This was discovered when kanban workers spawned by the gateway would crash silently.

How to test

On Windows 11: run a kanban worker via the dispatcher with stdout redirected to a log file. Without this fix, the worker crashes with NoConsoleScreenBufferError on the first _cprint call. With the fix, output falls through to print() and the worker continues normally.

Tests: pytest tests/cli/test_cprint_bg_thread.py — 13 passed. Full tests/cli/ suite: 634 passed, 7 pre-existing failures (tilde paths, secret capture — verified identical on main).

Wraps _pt_print in try/except with a print() fallback. When a
kanban worker's stdout is piped to a log file, prompt_toolkit
raises NoConsoleScreenBufferError (Windows) or OSError (other)
because there is no real console buffer. The fallback keeps
worker output flowing instead of crashing.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard labels May 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #22482 — same fix (try/except fallback in _cprint for NoConsoleScreenBufferError). Also overlaps #25340, #25556, #23011 which are already tracked as duplicates of #22482.

@BoardJames-Bot

Copy link
Copy Markdown

BoardJames CI triage (2026-05-18T16:46Z): I don’t see a PR-specific failure at the moment.

Evidence:

  • The PR only changes cli.py::_cprint to catch prompt_toolkit.print_formatted_text(ANSI(...)) failures in the no-active-app path and fall back to plain print(text).
  • Current check state for head 5868193: build-arm64 is now green (7m03s), build-amd64 green, lint/ruff/ty, Nix, supply-chain, history, attribution, and e2e are all green.
  • The only remaining non-green check is Tests / test job 76571078947, still in progress since 2026-05-18T16:26:09Z; GitHub does not expose the live log until that job completes. Its currently-running step is Run tests.
  • This looks consistent with the repo’s current full-suite CI churn rather than this one-line stdout fallback: nearby main/full-suite runs are also being cancelled/restarted by newer commits while their test jobs are running (e.g. main run 26047000589 test cancelled after a newer main run started; current main run 26047154669 has e2e green and test still in progress).

Local focused validation on a detached worktree at PR head:

  • Inline smoke test monkeypatching _pt_print to raise OSError: _cprint("hello fallback") called print("hello fallback") and did not raise.
  • python -m pytest tests/cli/test_stream_delta_think_tag.py tests/cli/test_cli_user_message_preview.py tests/tui_gateway/test_review_summary_callback.py -q → 13 passed in 1.83s.

No code push from me; recommendation is to let Tests / test finish (or rerun just that job if it times out/cancels) before treating this PR as broken.

@BoardJames-Bot

Copy link
Copy Markdown

Update: Tests / test later ended as cancelled, not failed. I pulled the now-available log: pytest was still progressing normally at 95% when GitHub terminated it with ##[error]The operation was canceled. at 2026-05-18T16:46:27Z; there is no assertion/error traceback in the tail. That reinforces the triage above: this PR currently has no PR-specific CI failure, just the shared full-suite cancellation/churn. All other checks, including build-arm64, are green.

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #28330 (cherry-picked onto current main with your authorship preserved via rebase-merge — commit 8bcb608). Thanks for the contribution!

@teknium1 teknium1 closed this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants