Skip to content

fix(mistral): bound image pruning memory and normalize malformed references - #8434

Merged
lidge-jun merged 14 commits into
lidge-jun:devfrom
luvs01:codex/propose-fix-for-mistral-image-limit-vulnerability
Nov 10, 2026
Merged

lidge-jun merged 14 commits into
lidge-jun:devfrom
luvs01:codex/propose-fix-for-mistral-image-limit-vulnerability

Conversation

@luvs01

@luvs01 luvs01 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Bound Mistral image-limit traversal bookkeeping by walking messages backwards instead of collecting a coordinate for every image. Keep the newest images, copy only changed messages/content, and replace missing or malformed image references without consuming the valid-image cap. Returned copy-on-write arrays still scale with input size.

Carries luvs01/opencodex#814 at 259d7471cabb849ddbc59d3cd11fd117ec43bc1b, including large frozen-input tests and corrected documentation for parser/media-guard boundaries in the canonical reference and seven translations. Commit history and authorship are preserved.

Verification

  • Source tests include a 10,000-image pruning case, original-input/untouched-turn identity checks, noncanonical-destination no-op, string-form URLs and malformed-reference handling through the native Chat builder.
  • At the exact source head, CI 42572308165 passed its changed-test suite, gates, docs build and executed smoke checks. CodeQL 42572304591 also passed. The full platform matrix was skipped.
  • Reviewed the final limiter diff and the latest documentation corrections. No code changes were made for this transfer.
  • An earlier fork run exposed a separate Claude test-fixture stdout truncation issue. That common fixture is not changed by this Mistral PR and is being tracked separately.
  • Remains draft for upstream checks/review; full Windows/macOS and real-provider acceptance are not claimed.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Co-authored-by: Epinephrine luvs01@hanmail.net
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

Summary by CodeRabbit

  • Bug Fixes
    • Mistral image limits now count only images with non-empty URL references and retain the newest valid images up to the configured limit. Missing or malformed references are replaced with a text note without using the limit.
    • Responses with image file IDs but no usable image URL are rejected before being sent to Mistral. Unusable image inputs in translated Responses requests are omitted.
  • Documentation
    • Updated provider references in multiple languages with details about Mistral image limits and image-reference handling. URL syntax and availability are not checked; other destinations are unchanged.

luvs01 and others added 14 commits November 7, 2026 17:26
Preserve both the current Mistral Chat wire-policy link and bounded image-pruning documentation.

Validated locally: 95 tests / 739 assertions; typecheck 2334 files; structure, privacy, diff checks.
Co-Authored-By: Epinephrine <luvs01@hanmail.net>

# Conflicts:
#	structure/providers-and-adapters.md
Co-Authored-By: Epinephrine <luvs01@hanmail.net>
Merging dev pushed the merged providers.md to 2004 lines, tripping the
file-size ratchet's NEW_OVERSIZED verdict. Condense the image-limit note
to two lines (same content) so the merged file stays below 2000.

Co-Authored-By: Epinephrine <luvs01@hanmail.net>
Devin Review flagged the new Mistral image-cap paragraph: it claimed a
file-ID-only input_image is always refused by the translated-adapter
media guard, but the guard only inspects message content, tool output
and top-level input blocks. A replayed agent_message is not scanned, so
the parser degrades a file-ID-only input_image inside it to an
[image: <file id>] text marker that reaches Mistral as ordinary text.

Scope the refusal claim to scanned positions and describe the
agent_message marker path in all eight locales.

Co-Authored-By: Epinephrine <luvs01@hanmail.net>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Mistral image limiter now counts only non-empty image URL strings and preserves the newest usable images within the configured cap. It replaces unusable or over-cap image parts in copied content. Tests and provider documentation cover these rules.

Changes: Mistral image-limit handling

Layer / File(s) Summary
Count usable images and preserve the newest
src/adapters/openai-chat/mistral-image-limit.ts, tests/providers/mistral-image-limit.test.ts, structure/providers-and-adapters.md, docs-site/src/content/docs/*/reference/configuration/providers.md
The limiter scans from newest to oldest and counts only non-empty URL strings in either supported image_url shape. It replaces malformed references without consuming the cap and replaces older usable images when the cap is reached. Tests cover large histories, immutability, and native Chat behavior. Provider documentation describes the counting and replacement rules. The translated documentation also describes Responses parsing and media-guard behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: fontanierh

Merge Risk: Minimal · up to 259d7

The image-limit change is mergeable after normal checks. The documentation could clarify that schema-invalid image inputs receive a 400 response rather than being omitted.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main change: reducing memory use during Mistral image pruning and normalizing malformed image references.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files. (9 skipped: 9 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f0f34d0 and 259d747.

Files selected for processing: 11

  • docs-site/src/content/docs/fr/reference/configuration/providers.md
  • docs-site/src/content/docs/ja/reference/configuration/providers.md
  • docs-site/src/content/docs/ko/reference/configuration/providers.md
  • docs-site/src/content/docs/reference/configuration/providers.md
  • docs-site/src/content/docs/ru/reference/configuration/providers.md
  • docs-site/src/content/docs/tr/reference/configuration/providers.md
  • docs-site/src/content/docs/zh-cn/reference/configuration/providers.md
  • docs-site/src/content/docs/zh-tw/reference/configuration/providers.md
  • src/adapters/openai-chat/mistral-image-limit.ts
  • structure/providers-and-adapters.md
  • tests/providers/mistral-image-limit.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 9, 2026
@luvs01
luvs01 marked this pull request as ready for review November 10, 2026 01:55
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ❌ Failed 2026-11-10T01:55:26.400643Z
We couldn’t complete this review. Comment @codex security review to try again.
259d747 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer judgment

Integrate at 259d7471cabb849ddbc59d3cd11fd117ec43bc1b, subject to unchanged head and mergeability. This addresses a real Mistral user problem: large image histories formerly needed bookkeeping proportional to every image, and malformed image references could be sent upstream. The limiter now keeps the newest usable images, substitutes notes for older or malformed image parts, and avoids collecting a coordinate per image. That substitution is an intended API-visible change; there is no dashboard or CLI layout change.

Existing first-party Mistral users retain the configured image cap and ordering, with malformed references normalized. Other destinations and persisted configuration are unaffected. The implementation is platform-neutral TypeScript; Windows and macOS shards were skipped, so no cross-platform execution is claimed. The structure documentation and translations were updated; the independent reviews checked file-size, Lab boundary and privacy.

Fresh independent code and separate security reviews passed this exact head. The code reviewer reported 10 focused tests passing, a base/head regression check and clean typecheck; the security reviewer reported hostile-input and boundary probes passing. I inspected the diff and verified CI run 42575505025 on this head: gates, test changed, docs build, structure and aggregate succeeded. No change-caused CI failure is known.

The security reviewer also reported 150 failures in a broad local adapters/providers run under contention, outside the changed Mistral area; one Kiro file passed alone. Those failures were not all reproduced on base and remain unclassified, so they are not represented as a passing run.

NOT RUN by maintainer: local test suite, full suite, Windows/macOS matrix and live Mistral request. Reviewer-reported local commands and broad-run failures were not independently rerun.

Maintainer integration decision: use the dev-only maintainer integration policy if GitHub blocks only on required approval; the two independent reviews remain separate from that decision.

@lidge-jun
lidge-jun merged commit 8090333 into lidge-jun:dev Nov 10, 2026
55 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants