Skip to content

fix(cli): respect sys.stdout.isatty() in stream renderer (#3265)#3271

Merged
Re-bin merged 3 commits intoHKUDS:mainfrom
pixan-ai:fix-cli-stream-isatty-3265
Apr 18, 2026
Merged

fix(cli): respect sys.stdout.isatty() in stream renderer (#3265)#3271
Re-bin merged 3 commits intoHKUDS:mainfrom
pixan-ai:fix-cli-stream-isatty-3265

Conversation

@pixan-ai
Copy link
Copy Markdown
Contributor

When stdout is not a TTY (e.g. docker exec -i, pipes), nanobot emitted
cursor-visibility escape sequences and braille spinner frames mixed into
the response output. Forcing force_terminal=True overrode Rich's isatty()
detection. Deferring to sys.stdout.isatty() keeps rich output in real
terminals and plain text everywhere else.

Co-authored with Claude Opus 4.7

@chengyongru chengyongru added the question Further information is requested label Apr 18, 2026
pixan-ai and others added 2 commits April 18, 2026 08:23
The old test `test_make_console_uses_force_terminal` hardcoded
`force_terminal is True`, which contradicts the fix: we now defer
to sys.stdout.isatty() so piped / non-TTY output gets plain text
instead of ANSI escape codes.

Split into two tests covering both branches:

- test_make_console_force_terminal_when_stdout_is_tty: TTY path
  (force_terminal=True, rich output)
- test_make_console_force_terminal_false_when_stdout_is_not_tty:
  non-TTY path (force_terminal=False, plain text) — regression
  guard for the bug reported in HKUDS#3265

Co-authored with Claude Opus 4.7
Copy link
Copy Markdown
Collaborator

@Re-bin Re-bin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right kind of fix.

The intent is narrow, the boundary is clear, and the implementation solves the actual problem without making the CLI renderer more complicated than it needs to be. Respecting sys.stdout.isatty() is the right way to avoid Rich control sequences leaking into piped or non-interactive output while keeping the existing rich rendering in real terminals.

I pulled in the latest main and reran the relevant tests locally:

  • pytest tests/cli/test_cli_input.py -q
  • pytest tests/cli -q
  • pytest -q

All of them passed locally.

From my side, this is clean, practical, and ready to merge.

@Re-bin Re-bin merged commit 2d04429 into HKUDS:main Apr 18, 2026
8 checks passed
@pixan-ai
Copy link
Copy Markdown
Contributor Author

Thanks @Re-bin

Really appreciate you pulling and rerunning the suite locally.
Good to see it land cleanly. Looking forward to more collaboration on the best repo.

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

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants