Skip to content

fix(topic): stop writing 'Error: Reached max turns 1' as the topic when MCPs are configured#1

Merged
amunozdev merged 1 commit into
mainfrom
fix/topic-max-turns-error
Jun 6, 2026
Merged

fix(topic): stop writing 'Error: Reached max turns 1' as the topic when MCPs are configured#1
amunozdev merged 1 commit into
mainfrom
fix/topic-max-turns-error

Conversation

@amunozdev

Copy link
Copy Markdown
Owner

Problem

In sessions with MCP servers configured, the statusline topic sometimes showed the literal Error: Reached max turns 1 instead of a real title.

Root cause: the async topic refinement runs a headless claude -p --model haiku --max-turns 1. With MCP servers configured, that call loaded them and the model attempted a tool call that consumed the single allowed turn → the CLI emitted Error: Reached max turns 1 to stdout (not stderr, so 2>/dev/null didn't catch it). The permissive sanitizer (alphanumerics + spaces) let the string through, and it got written as the topic.

Fix (defense in depth)

  • Root cause: run the refinement with --strict-mcp-config and --allowedTools "" — zero MCP servers, no tools — so the single turn can't be burned on a tool call. --max-turns 1 (deliberate since v5.0.1) is always enough for a plain title.
  • Structured output: --output-format json, accepting .result only when is_error == false (via jq, an existing documented dependency; falls back to the old path when jq is absent).
  • Guard: discard any leftover CLI error string (Error:*, Reached max turns, Execution error). On failure refined is emptied, so the existing heuristic topic is kept.

Verification

  • Ran claude -p with the new flags against a real prompt: returns JSON with is_error:false and a clean title; jq extraction pipeline yields the title.
  • shellcheck --severity=warning clean, all 95 tests pass.
  • Bumped to 5.3.2, synced skill versions, added CHANGELOG entry.

…CPs are configured

The async claude -p refinement loaded MCP servers, letting a tool call burn
the single allowed turn; the CLI then emitted the max-turns error to stdout,
which slipped past 2>/dev/null and the permissive sanitizer to become the topic.

Run the refinement with --strict-mcp-config and no tools so the turn can't be
consumed, parse --output-format json accepting .result only when is_error is
false, and guard against any leftover CLI error string.
@amunozdev amunozdev merged commit c9b0a80 into main Jun 6, 2026
5 checks passed
@amunozdev amunozdev deleted the fix/topic-max-turns-error branch June 6, 2026 17:54
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.

1 participant