fix(topic): stop writing 'Error: Reached max turns 1' as the topic when MCPs are configured#1
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In sessions with MCP servers configured, the statusline topic sometimes showed the literal
Error: Reached max turns 1instead 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 emittedError: Reached max turns 1to stdout (not stderr, so2>/dev/nulldidn't catch it). The permissive sanitizer (alphanumerics + spaces) let the string through, and it got written as the topic.Fix (defense in depth)
--strict-mcp-configand--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.--output-format json, accepting.resultonly whenis_error == false(viajq, an existing documented dependency; falls back to the old path whenjqis absent).Error:*,Reached max turns,Execution error). On failurerefinedis emptied, so the existing heuristic topic is kept.Verification
claude -pwith the new flags against a real prompt: returns JSON withis_error:falseand a clean title;jqextraction pipeline yields the title.shellcheck --severity=warningclean, all 95 tests pass.