Skip to content

fix(cli): restore progress bars on human format and check tty in auto mode (#4860) - #4875

Closed
dlowzzxx wants to merge 2 commits into
huggingface:mainfrom
dlowzzxx:fix/cli-auto-mode-interactive-progress-4860
Closed

fix(cli): restore progress bars on human format and check tty in auto mode (#4860)#4875
dlowzzxx wants to merge 2 commits into
huggingface:mainfrom
dlowzzxx:fix/cli-auto-mode-interactive-progress-4860

Conversation

@dlowzzxx

@dlowzzxx dlowzzxx commented Sep 11, 2026

Copy link
Copy Markdown

Fixes #4860

Description

In auto output mode, AI agent detection (e.g. from terminals like Warp setting TERM_PROGRAM=WarpTerminal or other environment variables matching the agent harness registry) caused progress bars and ANSI colors to be silently disabled, even when running interactively in a user terminal. Additionally, when switching formats back to human via set_mode(OutputFormat.human), progress bars remained disabled because enable_progress_bars() was not called.

This PR addresses this with:

  1. Defensive interactive TTY check in auto mode:
    In Output.set_mode(), when mode == OutputFormat.auto, we check if sys.stderr is interactive via is_interactive = bool(getattr(sys.stderr, "isatty", lambda: False)()). We only select OutputFormat.agent if is_agent() and not is_interactive; otherwise, interactive terminals resolve to OutputFormat.human.
  2. Progress bar restoration:
    When mode == OutputFormat.human, enable_progress_bars() is called to re-enable progress bars if they had previously been disabled.
  3. Interactive terminal color preservation:
    In ANSI._format(), colors are preserved if the terminal is interactive, only suppressing colors for agents in non-interactive environments (is_agent() and not bool(getattr(sys.stderr, "isatty", lambda: False)())).
  4. Explicit set_mode(OutputFormat.agent) still forces agent mode regardless of TTY status.

Reproduction & Verification

  • Prior to the fix, running test_set_mode_human_reenables_progress_bars, test_auto_resolves_to_human_in_interactive_terminal_even_if_agent, and test_ansi_agent_interactive_preserves_color failed with progress bars remaining disabled and mode resolving to agent in interactive sessions.
  • Added comprehensive regression tests in tests/test_cli_output.py and tests/test_utils_terminal.py.
  • Verified all unit tests pass:
    • uv run pytest tests/test_cli_output.py (36 passed)
    • uv run pytest tests/test_utils_detect_agent.py (17 passed)
    • uv run pytest tests/test_utils_terminal.py (6 passed)
    • uv run --with ruff ruff check src tests (clean)
    • uv run --with ruff ruff format --check src tests (clean)

Note

Low Risk
CLI output and TTY detection only; no auth, data handling, or API behavior changes.

Overview
Fixes agent auto-detection treating interactive terminals (e.g. Warp) like headless agent sessions, which turned off progress bars and ANSI styling even for real users.

Auto format now picks agent only when is_agent() is true and stderr is not a TTY; interactive sessions stay on human mode. Explicit --format agent still forces agent mode and disables bars.

Adds a defensive is_terminal() helper (used by Output, StatusLine, and ANSI) so isatty() on missing/closed streams does not crash. Human mode calls enable_progress_bars() again when switching back (unless HF_HUB_DISABLE_PROGRESS_BARS is set). ANSI keeps color in interactive terminals even when is_agent() is true; colors stay suppressed only for non-interactive agent runs.

Regression tests cover mode resolution, progress bar toggling, and ANSI behavior.

Reviewed by Cursor Bugbot for commit 87c0fb8. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f333c9c. Configure here.

Comment thread src/huggingface_hub/cli/_output.py
@hanouticelina

Copy link
Copy Markdown
Collaborator

Hi @dlowzzxx, thanks for the PR! Closing in favor of #4878, which covers the progress bars / colors part in a slightly different way and we're not going with the tty check

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.

[CLI] auto mode picks agent for Warp users: progress bars and colors silently disabled (TERM_PROGRAM=WarpTerminal)

2 participants