Skip to content

fix: readable CLI output and graceful context-overflow errors in non-TTY runs#51

Merged
mudler merged 1 commit into
masterfrom
fix/ci-friendly-output
Jul 8, 2026
Merged

fix: readable CLI output and graceful context-overflow errors in non-TTY runs#51
mudler merged 1 commit into
masterfrom
fix/ci-friendly-output

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Problem

Running nib --cli in CI (e.g. GitHub Actions) produced unreadable output. Two issues, both stemming from stdout not being a TTY:

  1. Spinner flood. The CLI spinner redraws a single line with a carriage return (\r) every 80 ms. Off a TTY the \r does nothing, so every frame lands on its own line — the log fills with hundreds of ⠋ thinking entries.

  2. Opaque context-overflow error. When the request exceeded the model's context window, the failure surfaced as a triple-wrapped, cryptic line:

    × failed to select tool: failed to pick tool: tool selection failed: failed to make a decision after 3 attempts: rpc error: code = Internal desc = request (9739 tokens) exceeds the available context size (8192 tokens), try increasing it
    

Changes

  • TTY-aware spinner (cmd/cli.go): on a TTY, unchanged animated spinner. Off a TTY, it prints each distinct status once (deduplicated), reprinting after tool-call boundaries so progress stays visible. A steady "thinking" state collapses to one line instead of hundreds.

  • humanizeError (chat/errors.go): rewrites known backend context-overflow errors (llama.cpp/LocalAI, OpenAI, and vLLM phrasings) into a short, actionable message with the token counts, e.g.:

    the request is larger than the model's context window (needs ~9739 tokens, model allows 8192). Increase the backend's context size, or reduce the enabled tools/MCP servers and clear the conversation ("clear"), then retry.

    The original error is preserved via Unwrap so errors.Is/As still work. Unrecognized errors pass through unchanged. Applied at the single error surface in SendMessage, so both the CLI and TUI benefit.

Tests

  • cmd/cli_spinner_test.go: non-TTY output contains no \r and deduplicates a repeated status to one line; status reprints across a stop/start boundary.
  • chat/errors_test.go: both backend phrasings (including OpenAI's reversed count order) yield correct request/limit numbers; unwrap chain intact; nil and unrelated errors pass through.

🤖 Generated with Claude Code

…TTY runs

Two fixes for running `nib --cli` in CI (e.g. GitHub Actions), where stdout
is not a TTY:

- Spinner: the animated spinner redraws one line with a carriage return every
  80ms. Off a TTY the `\r` does nothing, so every frame becomes its own log
  line and the log fills with hundreds of "thinking" entries. Make the spinner
  TTY-aware: on a non-TTY it prints each distinct status once (deduplicated),
  reprinting after tool-call boundaries so progress stays visible.

- Errors: a context-window overflow surfaced as a triple-wrapped, opaque
  "failed to select tool: ... failed to make a decision after 3 attempts:
  rpc error: ... exceeds the available context size" line. Add humanizeError,
  which rewrites known backend context-overflow errors (llama.cpp/LocalAI,
  OpenAI, vLLM phrasings) into a short, actionable message with the token
  counts, while preserving the original via Unwrap.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mudler mudler merged commit 9c55c17 into master Jul 8, 2026
2 checks passed
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.

2 participants