Skip to content

Handle list-shaped streamed content from Mistral reasoning models - #43

Merged
Zeptiny merged 2 commits into
mainfrom
claude/nifty-darwin-v7748p
Nov 7, 2026
Merged

Zeptiny merged 2 commits into
mainfrom
claude/nifty-darwin-v7748p

Conversation

@Zeptiny

@Zeptiny Zeptiny commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Problem

Chat turns failed after a successful Mistral request:

File "core/llm.py", line 154, in _stream_completion
    'content': ''.join(content) if content else None,
TypeError: sequence item 0: expected str instance, list found

With reasoning on (reasoning_effort is sent by default when LLM_REASONING_EFFORT is set), Mistral streams delta.content as a list of typed chunks, not a string:

[{"type": "thinking", "thinking": [{"type": "text", "text": "..."}]}]
[{"type": "text", "text": "Olá"}]

The OpenAI SDK passes stream chunks through without type checks, so the lists reached ''.join and crashed.

Changes

  • core/llm.py: a new _content_text() keeps only the text chunks as the answer. Plain strings work as before. Thinking chunks are dropped, not stored as reasoning_content, because that field is sent back to the provider on the next tool-loop turn.
  • api_logger.py: _fold_sse only folded string delta fields, so logged Mistral responses had no content. List content now folds into content (text) and a separate thinking key.

Tests

  • New tests/test_llm_stream_content.py builds chunks the way the SDK does. It fails with the production TypeError without the fix and passes with it.
  • tests/test_api_logger.py now also checks _fold_sse on a Mistral-shaped stream.
  • Full suite: 222 passed. ruff check . is clean.

Generated by Claude Code

Mistral streams delta.content as a list of typed chunks (thinking/text)
when reasoning is on, which made ''.join(content) raise TypeError and fail
the chat turn. Fold only the text chunks into the answer and drop thinking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GrLGiCjUbitdQqtZjkQa4j
Mistral reasoning streams send delta.content as typed chunks, which
_fold_sse skipped because it only folded string fields, so logged
responses had no content. Fold text chunks into content and thinking
chunks into a separate thinking key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GrLGiCjUbitdQqtZjkQa4j
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 877f96eb-4747-4d78-a282-dc5c2d4b4d48
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Zeptiny
Zeptiny merged commit 4bd2cea into main Nov 7, 2026
2 checks passed
@Zeptiny
Zeptiny deleted the claude/nifty-darwin-v7748p branch November 9, 2026 15:11
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