fix(cli): reasoning tag suppression during streaming + fix fallback detection

Fixes two issues found during live testing:

1. Reasoning tag suppression: close tags like </REASONING_SCRATCHPAD>
   that arrive split across stream tokens (e.g. '</REASONING_SCRATCH' +
   'PAD>\n\nHello') were being lost because the buffer was discarded.
   Fix: keep a sliding window of the tail (max close tag length) so
   partial tags survive across tokens.

2. Streaming fallback detection was too broad — 'stream' matched any
   error containing that word (including 'stream_options' rejections).
   Narrowed to specific phrases: 'streaming is not', 'streaming not
   support', 'does not support stream', 'not available'.

Verified with real API calls: streaming works end-to-end with
reasoning block suppression, response box framing, and proper
fallback to Rich Panel when streaming isn't active.
This commit is contained in:
teknium1 2026-03-16 05:28:10 -07:00
parent 2219695d92
commit ac739e485f
2 changed files with 82 additions and 4 deletions

View file

@ -3209,10 +3209,13 @@ class AIAgent:
result["response"] = _call_chat_completions()
except Exception as e:
err_text = str(e).lower()
# Fall back to non-streaming if provider doesn't support it
# Fall back to non-streaming if provider doesn't support it.
# Be specific in matching — "stream" alone is too broad and
# catches unrelated errors like "stream_options" rejections.
stream_unsupported = any(
kw in err_text
for kw in ("stream", "not support", "unsupported", "not available")
for kw in ("streaming is not", "streaming not support",
"does not support stream", "not available")
)
if stream_unsupported:
logger.info("Streaming not supported by provider, falling back to non-streaming: %s", e)