Skip to content

fix(chat): read Mistral's list-shaped content (thinking + text parts) - #204

Open
Nicolas Werner (nicolas-werner) wants to merge 1 commit into
microsoft:mainfrom
nicolas-werner:fix/mistral-list-content
Open

Nicolas Werner (nicolas-werner) wants to merge 1 commit into
microsoft:mainfrom
nicolas-werner:fix/mistral-list-content

Conversation

@nicolas-werner

Copy link
Copy Markdown

Linked issue

None: a small bug fix (a crash on one provider), so no prior issue.

What changed (Before / After)

  • Before: With openai-chat at https://api.mistral.ai/v1 and mistral-large-4, every run crashed on the first
    response with TypeError: can only concatenate str (not "list") to str in Chat.read_stream. When reasoning is on,
    Mistral streams delta.content as a list of parts ({"type": "thinking", "thinking": [{"type": "text", ...}]} and
    {"type": "text", ...}), and the reader assumed a string. freehand check mistral failed the same way.
  • After: List-shaped content is split. Text parts go to the reply, and thinking parts go to the reasoning, shown
    the same way as reasoning_content from other services. String content is handled as before. from_json (a service
    that ignores stream) gets the same treatment.

Nothing the model sees changes. Mistral is not an interleaved-reasoning host, so the reasoning is still not sent back.

Visual proof (UI / TUI / Web / Desktop / export changes)

Backend-only. Terminal output from a live run after the fix:

$ freehand check mistral
Freehand 0.1.3 check: openai-chat at https://api.mistral.ai/v1
  ✓ 63 models listed (...)
  model for the run: mistral-large-4 (reasoning effort low)
  ✓ agent run: status done after 2 model calls
  ✓ streaming: 2 completed responses, 37 events
  ✓ function tool call (bash) accepted and executed
  ✓ multi-turn tool + status round trip accepted (2 model calls)
All checks passed.

How you verified it

  • New test test_mistral_list_content_splits_thinking_from_text in tests/test_provider_conformance.py
    (streamed thinking and text parts mixed with a plain string delta, plus from_json). It fails without the fix.
  • uv run pyflakes src tests .github/scripts prints nothing.
  • tests/test_provider_conformance.py, tests/test_providers.py, tests/test_provider_http.py: 194 passed.
  • Core suite (ci.py parallel --shards 3 -- pytest -q --suite=core) passed locally.
  • Python 3.9 stdlib-only import check of src/freehand/runtime/ passes.
  • Live: freehand check mistral with mistral-large-4 passed several runs, and an interactive headless run showed the
    thinking in the reasoning display and the answer as text. mistral-small-2603 (no reasoning field) still passes.

AI disclosure & checklist

  • AI disclosure: AI-assisted (personally tested and verified)
  • uv run pyflakes src tests .github/scripts prints nothing and relevant tests pass locally (full suite runs in CI)
  • Left CHANGELOG.md untouched (maintainers update it at release time)
  • No change to what the model sees (prompt, tool descriptions, status line, notes), or benchmark evidence attached
  • src/freehand/runtime/ still uses only the standard library and imports on Python 3.9

🤖 Generated with Claude Code

Mistral reasoning models such as mistral-large-4 stream `delta.content` as a
list of parts when reasoning is on: text parts, and thinking parts whose text
sits one level deeper. The Chat Completions reader concatenated `content` as a
string, so every Mistral Large 4 run crashed with
"TypeError: can only concatenate str (not "list") to str".

Split such content: text parts go to the reply, thinking parts to the
reasoning, the same way `reasoning_content` from other services is shown.
String content is handled as before. The non-streaming reply gets the same
treatment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Thanks for the pull request! A few friendly reminders based on the files changed:

  • Model-facing / runtime core: This PR touches benchmark-sensitive or Python 3.9 stdlib runtime files (src/freehand/runtime/providers.py). Please make sure Python 3.9 stdlib imports still pass and attach benchmark evidence if model-visible behaviour changed.

(This comment updates automatically when you edit the PR description or push new commits.)

@nicolas-werner

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
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