Skip to content

Add support for mistral AI provider - #796

Open
NeroReflex wants to merge 9 commits into
sashiko-dev:mainfrom
NeroReflex:main
Open

NeroReflex wants to merge 9 commits into
sashiko-dev:mainfrom
NeroReflex:main

Conversation

@NeroReflex

Copy link
Copy Markdown

Hi all,

I borrowed an API key for Mistral vibecode plan from friend of mine at OGC to review a large driver.

I have set out my glm to fix the issue about theirs response being incompatible with the format expected by the openai-compatible provider and now it works.

WARNING: Everything in here is fully AI written and only runtime tested (it did in fact review my driver and the review found real issues); that is I haven't looked at a single line with the intention of checking it beside making sure it didn't made others provided stopped working and checking for things too stupid to be proposed... so don't merge it.

If you say this is something you consider adding (done the right way) and you tell me what is the expectation to add support for this provider I will be available for implementing this the proper way.

Thank you!

@NeroReflex
NeroReflex marked this pull request as draft October 31, 2026 14:08
@sashiko-bot

sashiko-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

Sashiko review

Commit 1/8 — 0c62b601 ai: add a native Mistral provider

  • [LOW] src/ai/mistral.rs: MistralContent::Other is a unit variant inside an
    untagged enum, so serde only matches it against JSON null (which
    MistralResponseMessage.content already consumes as None). If a response
    carries an unrecognized non-null content shape or a content block whose
    fields do not match MistralBlock, MistralClient::post_request() fails to
    decode the 200 OK body and aborts the stage with a fatal parse error
    instead of dropping the unknown fragment in split_content(). Wrap
    serde::de::IgnoredAny (or serde_json::Value) in Other(IgnoredAny) so
    unknown shapes deserialize.

Commit 3/8 — 1e5412bd ai: keep Mistral chain of thought across tool rounds

  • [LOW] The commit message carries a Fixes trailer for "ai: add a native
    Mistral provider" with a stale pre-rebase SHA that does not exist in git
    history, and that commit is an unmerged patch earlier in the same series.
    Drop the Fixes trailer and fold this fix into the earlier patch, or drop
    the stale hash reference from the commit message.

Commit 4/8 — a606263e ai: mirror sibling providers' transport error formatting

  • [LOW] src/ai/mistral.rs: the commit message for the change in
    MistralClient::post_request() has a Fixes: 05c292328c91 ("ai: add a native
    Mistral provider") trailer that points to a non-existent pre-rebase hash of
    the earlier "ai: add a native Mistral provider" patch in this same unmerged
    series. Drop the Fixes: trailer or squash this change into that patch.

Commit 5/8 — e621e28a ai: harden Mistral transport and key diagnostics

  • [LOW] The commit message carries Fixes: 05c292328c91 ("ai: add a native
    Mistral provider"), which points to a non-existent pre-rebase hash of an
    unmerged patch in this series ("ai: add a native Mistral provider"). This
    leaves a dangling commit reference in git history. Drop the Fixes trailer
    or squash the fixup into that patch.

Commit 6/8 — 33af1fbb ai: pin Mistral key resolution and redirect failure tests

  • [LOW] src/ai/mistral.rs: MistralClient::resolve_api_key(): the commit
    message carries a Fixes trailer for "ai: add a native Mistral provider"
    with a stale commit hash that does not exist in git history, and that patch
    is an unmerged commit in the same series rather than an already-merged
    commit. The message body is also written as a reply to an automated review
    pass instead of a standalone description of the change. Squash this fixup
    into "ai: add a native Mistral provider", or drop the Fixes trailer and
    rewrite the commit message as a self-contained description.

Commit 7/8 — 058cc9e1 workflow: repair common LLM JSON malformations as a last resort

  • [MEDIUM] src/utils.rs, src/workflow/output.rs: in repair_json_with(), once
    byte_pos reaches error_offset, quotes before commas and colons never
    terminate a string for the rest of the document. When a field has balanced
    unescaped inner quotes, the mixed variant escapes the field's closing quote
    and swallows all following fields or array elements up to the closing brace
    or bracket, and escapes closing quotes on any later object keys. Because
    repair_json_candidates() orders mixed before pairs and
    find_json_candidates() stops on the first untyped Value that parses, callers
    accept the truncated mixed object or fail typed deserialization when pairs
    would have parsed cleanly.

  • [MEDIUM] src/workflow/output.rs, src/utils.rs: parse_json_from_text() and
    find_json_candidates() run clean_json_string() before
    repair_json_candidates(). Because clean_json_string() toggles in_string on
    every unescaped quote, an odd number of unescaped inner quotes flips
    in_string for the rest of a multi-line payload and turns structural newlines
    between fields into literal \n sequences outside strings, while an even
    number of inner quotes leaves literal newlines or tabs between them
    unescaped. Both cases still fail strict JSON parsing after quote repair.

  • [LOW] src/workflows/linux_patch_review.rs: rewriting
    test_stage_outputs_do_not_match_inner_location_on_malformed_outer_json()
    into test_unescaped_quotes_repair_outer_object_not_other_stage_shapes()
    drops test coverage for the inner-object fallback path. Because
    find_json_candidates() now repairs the outer object at the start of the
    string and skips to the end, the test never extracts the nested location
    object. Keep a test with an unrecoverable outer syntax error so the
    inner-location rejection stays covered.

Full review and stage logs on sashiko.sashiko.dev

@rgushchin

Copy link
Copy Markdown
Member

Thanks for the PR! Please, rebase and address Sashiko's comments. Thanks

@NeroReflex

Copy link
Copy Markdown
Author

Sure thing! Together with friend of mine we identified a problem with caching I am solving. Will jump on findings after, thank you!

@sashiko-bot

sashiko-bot Bot commented Nov 7, 2026

Copy link
Copy Markdown

Sashiko review — v2

Commit 1/9 — 0c62b601 ai: add a native Mistral provider

  • [LOW] src/ai/mistral.rs: MistralContent declares Other as a unit variant on
    an untagged enum to catch unrecognized content shapes, but in serde a unit
    variant only matches JSON null (which Option already turns
    into None). If a reply contains a non-string, non-array content value or a
    block whose fields do not match MistralBlock, post_request() fails to parse
    MistralResponse and returns a fatal ApiError(200) instead of falling back to
    Other in split_content(). Give Other a serde_json::Value or
    serde::de::IgnoredAny payload so it accepts arbitrary JSON.

Commit 3/9 — 1e5412bd ai: keep Mistral chain of thought across tool rounds

  • [LOW] The commit message carries Fixes: 05c292328c91 ("ai: add a native
    Mistral provider"), which cannot be resolved in the repository (or only
    exists in an unfetched tree) and points to an unmerged patch in the same
    series. Drop the Fixes trailer or fold this change into "ai: add a native
    Mistral provider".

Commit 4/9 — a606263e ai: mirror sibling providers' transport error formatting

  • [LOW] src/ai/mistral.rs: the commit message for this change to
    MistralClient::post_request() carries Fixes: 05c292328c91 ("ai: add a
    native Mistral provider"), which cannot be resolved in the repository and
    refers to an unmerged patch earlier in this series. Drop the Fixes trailer
    or fold this change into "ai: add a native Mistral provider".

Commit 5/9 — e621e28a ai: harden Mistral transport and key diagnostics

  • [LOW] src/ai/mistral.rs: the commit message for the MistralError and
    MistralClient::new() changes carries Fixes: 05c292328c91 ("ai: add a native
    Mistral provider"), which cannot be resolved in the repository and points
    to an unmerged patch in the same series. Drop the Fixes trailer or fold
    these changes into "ai: add a native Mistral provider".

Commit 6/9 — 33af1fbb ai: pin Mistral key resolution and redirect failure tests

  • [LOW] src/ai/mistral.rs: the commit message for MistralClient::new() and
    MistralClient::resolve_api_key() carries a Fixes trailer for 05c292328c91
    ("ai: add a native Mistral provider"), which cannot be resolved in the
    repository and targets an unmerged patch in the same series, and frames
    the commit body as a reply to an earlier automated review pass. Drop the
    Fixes trailer and rewrite the commit message as a standalone description,
    or squash this change into "ai: add a native Mistral provider".

Commit 7/9 — 058cc9e1 workflow: repair common LLM JSON malformations as a last resort

  • [MEDIUM] src/utils.rs: repair_json_with() in mixed mode disables comma and
    colon string termination for the entire remainder of the input once
    byte_pos reaches error_offset. When a string field contains balanced
    unescaped quotes followed by more string fields or array elements, the
    mixed variant escapes the field's closing quote before the comma and merges
    all trailing fields into that string until a quote precedes a closing brace
    or bracket, and escapes closing quotes on subsequent object keys before a
    colon. Because repair_json_candidates() orders mixed before pairs and
    find_json_candidates() in src/workflow/output.rs breaks on the first
    variant that parses as an untyped serde_json::Value, parse_json_from_text()
    accepts the field-swallowed output or fails typed deserialization when the
    pairs variant would have repaired the object cleanly.

  • [MEDIUM] src/workflow/output.rs: parse_json_from_text() and
    find_json_candidates() run clean_json_string() before calling
    repair_json_candidates(). Because clean_json_string() toggles in_string on
    every unescaped quote, an odd number of unescaped inner quotes in
    multi-line JSON flips in_string for the rest of the document and rewrites
    structural newlines between fields into literal \n sequences outside
    strings, while an even number of inner quotes leaves enclosed control
    characters unescaped. Neither repair variant can then parse the corrupted
    multi-line output. Run quote repair on the raw input before or together
    with control-character cleaning.

  • [LOW] src/workflows/linux_patch_review.rs:
    test_unescaped_quotes_repair_outer_object_not_other_stage_shapes() replaces
    test_stage_outputs_do_not_match_inner_location_on_malformed_outer_json(),
    removing coverage for inner location fallback rejection. Because
    find_json_candidates() repairs the outer object at the start of the string
    and skips past the end, it never extracts the nested location object. Keep
    a separate test with an unrecoverable outer syntax error to verify that the
    inner location object is rejected as a stage output.

Commit 9/9 — f7957141 ai: route Mistral requests to the prompt cache with prompt_cache_key

  • [LOW] The commit message carries a Fixes trailer pointing to "ai: add a
    native Mistral provider", which is an unmerged patch earlier in this
    series. Fixes trailers must only reference commits already merged prior to
    the series. Drop the Fixes trailer or fold this change into that patch.

Full review and stage logs on sashiko.sashiko.dev

Add provider = "mistral" for the Mistral chat completions API and
Mistral-shaped gateways, keyed off MISTRAL_API_KEY (or LLM_API_KEY).

The API is close to the OpenAI one but not close enough for the generic
compatible client: replies carry the assistant text as an array of typed
content blocks, where the chain of thought arrives as thinking blocks
next to text blocks instead of a reasoning_content string. The provider
parses every reply shape: plain strings, typed content blocks, null,
and anything it does not recognize, which it drops instead of failing
the reply. Thinking blocks map to the response thought, and the chain
of thought stays in the conversation across tool rounds without
per-provider settings.

Requests use plain string content for every role, tool results travel as
role "tool" with tool_call_id, and JSON mode reuses the json_object
response_format with a "Respond in JSON format." nudge appended when a
prompt does not name JSON. reasoning_effort follows a stage's own
request and falls back to [ai.mistral] effort. The context window
defaults to 1M tokens for the hosted zai-glm-*/glm-* models and 128k
otherwise; 429, auth failures, and 5xx classify through the shared
retry machinery.

The cache identity includes max_tokens, base_url, and the configured
effort: a call that hit the output cap comes back empty with
finish_reason "length", and raising the cap has to miss that entry
rather than replay it.

[ai.mistral] accepts base_url, max_tokens, context_window_size, and
effort; base_url accepts the API host, any .../v1 root, or the full
chat completions URL and rejects every other path at startup.

Signed-off-by: Denis Benato <denis.benato@linux.dev>

# Conflicts:
#	docs/llm-providers.md
@sashiko-bot

sashiko-bot Bot commented Nov 7, 2026

Copy link
Copy Markdown

Sashiko review — v3

Commit 3/9 — 7bb8f7f3 ai: keep Mistral chain of thought across tool rounds

  • [LOW] src/ai/mistral.rs: the commit message carries a Fixes: trailer for
    "ai: add a native Mistral provider", which is an unmerged patch earlier in
    this series rather than a commit already in the tree. Drop the Fixes:
    trailer or fold the fix into that patch.

Commit 4/9 — c6ab0d13 ai: mirror sibling providers' transport error formatting

  • [LOW] The commit message includes a Fixes: trailer pointing to "ai: add a
    native Mistral provider", which is an unmerged commit in the same patch
    series. Fixes: trailers must only reference commits already merged prior to
    the series baseline because same-series hashes become invalid when the
    series is rebased or amended. Drop the Fixes: trailer or fold these changes
    into the earlier patches in the series.

Commit 5/9 — daee8c37 ai: harden Mistral transport and key diagnostics

  • [LOW] The commit message carries a Fixes: trailer pointing to "ai: add a
    native Mistral provider", which is an unmerged commit in this same series
    (and also amends changes from "ai: keep Mistral chain of thought across
    tool rounds" in the same series). Unmerged commit hashes change on rebase
    or application, so Fixes: trailers must only reference commits already in
    repository history. Drop the Fixes: trailer or fold these fixes into the
    earlier patches in the series.

Commit 7/9 — 711d0852 workflow: repair common LLM JSON malformations as a last resort

  • [MEDIUM] src/utils.rs: in repair_json_with(), once byte_pos reaches
    error_offset, quotes followed by a comma or colon stop terminating strings
    for the rest of the document. In the prose reading (mixed), the derailed
    field's own closing quote before a comma is escaped, swallowing trailing
    fields into that string or failing when the object ends with a non-string
    value. Even if the broken string closes before a brace or bracket, every
    later object key has its closing quote before the colon escaped as well, so
    the key never closes and parsing fails. In addition, find_json_candidates()
    in src/workflow/output.rs breaks on the first repair variant that parses as
    an untyped serde_json::Value, discarding the second variant before typed
    deserialization checks whether required fields were swallowed.

  • [MEDIUM] src/utils.rs: repair_json_candidates() parses input and the
    structural candidate (pairs) with serde_json::from_str() before
    clean_json_string() escapes literal control characters inside strings. When
    a malformed response also contains a raw newline or tab inside a string
    literal, serde_json::from_str(&pairs) fails on the control character even
    though clean_json_string(&pairs) is valid JSON. repair_json_candidates()
    then places the prose reading (mixed) ahead of pairs, so
    parse_json_from_text() and find_json_candidates() in src/workflow/output.rs
    accept mixed first and silently swallow trailing fields. Computing
    error_offset on uncleaned input also places the offset at an earlier raw
    newline or tab rather than the actual syntax error, escaping valid string
    terminators in the prefix. Run clean_json_string() on each candidate before
    testing whether pairs parses.

  • [MEDIUM] src/workflow/output.rs: find_json_candidates() requires
    find_matching_brace() to locate the closing brace on the unrepaired text
    before calling repair_json_candidates(). Because find_matching_brace()
    flips in_string on every unescaped quote, an odd number of unescaped inner
    quotes leaves in_string inverted at the closing brace and returns None.
    When the output is wrapped in markdown fences or prose, both
    find_json_candidates() and the full-string repair loop in
    parse_json_from_text() fail to recover the object. On unfenced JSON with an
    odd number of unescaped quotes, running find_json_candidates() before
    top-level repair skips the outer object and extracts nested brace objects,
    which can match permissive stage output types before top-level repair runs.

Commit 9/9 — 819b8c6b ai: route Mistral requests to the prompt cache with prompt_cache_key

  • [LOW] The commit message carries a Fixes: trailer pointing to "ai: add a
    native Mistral provider", which is an unmerged patch earlier in this same
    series. Fixes: trailers must only reference commits already merged prior to
    the series baseline; drop the trailer or fold this change into that patch.

Full review and stage logs on sashiko.sashiko.dev

A newer clippy flags the hand-rolled comparators and the loop-around-
let-else pop patterns that this tree used so far, and make check-pr
builds with -D warnings fail on them. Sorting by key states the
ordering directly, and while let with a block scrutinee is the pop loop
clippy asks for; on edition 2024 the block drops its lock guard before
the body runs, so the queue is never held across a review job.

Signed-off-by: Denis Benato <denis.benato@linux.dev>
The stage-1 self-review of a48379e flagged that thinking
blocks were parsed out of replies but never re-sent, contradicting
the documented behavior. An assistant turn that carries a kept chain
of thought now re-emits it as a thinking content block ahead of the
answer text; the Mistral chat completions schema accepts that shape
for request assistant messages.

Also from the review:
- refuse an API key that cannot form a valid HTTP header value at
  construction instead of silently degrading to unauthenticated
  requests; a missing key still builds for keyless gateways but logs
  a warning naming MISTRAL_API_KEY
- attribute the post_request error and rate-limit log lines to the
  patch and stage via the shared log prefix
- cover the HTTP failure paths (429 with and without Retry-After,
  401, 5xx, malformed 2xx body, transport failure) with stub-server
  tests

Fixes: a48379e ("ai: add a native Mistral provider")
Signed-off-by: Denis Benato <denis.benato@linux.dev>
The stage-1 self-review of the chain-of-thought fix flagged two
leftovers. The Mistral transport and body-read failures log plain
Display strings for the underlying reqwest error, dropping the
cause chain that the Claude and Gemini providers preserve with
anyhow alternate formatting; both sites now match that convention.

The round-trip test now also sends the reply back as a follow-up
turn and asserts the captured request re-emits the chain of thought
as thinking blocks shaped exactly like the blocks the API emits in
replies. The request-side shape is additionally verified against
the live chat completions endpoint: an assistant message carrying a
thinking block plus a text block is accepted with HTTP 200 by both
mistral-small-latest and magistral-small-latest.

Fixes: a48379e ("ai: add a native Mistral provider")
Signed-off-by: Denis Benato <denis.benato@linux.dev>
The final stage-1 self-review pass over the two provider commits
flagged three findings and two provider concerns; all are addressed
here.

- A MISTRAL_API_KEY set to the empty string shadowed a valid
  LLM_API_KEY and the new warning named the wrong cause; an empty
  value now falls through to the shared key and the warning says
  "not set or is empty".
- Builder and redirect transport failures are permanent, so they now
  fail fast as a fatal PermanentError instead of climbing the
  backoff ladder like retryable failures; connection refused and
  other retryable causes stay transient.
- The tool-round wire shape (block-form content next to tool_calls
  on one assistant turn) is now pinned by a unit test, and the
  per-response token log line carries the shared patch/stage
  attribution prefix.
- The transport-failure test connects to loopback port 1 instead of
  racing concurrent binds for a dropped ephemeral port.

The uncapped response body read matches the openai and gemini
providers and is left for a cross-provider follow-up; the GitLab
webhook replay-timestamp concern is a pre-existing forge issue
outside this series.

Fixes: a48379e ("ai: add a native Mistral provider")
Signed-off-by: Denis Benato <denis.benato@linux.dev>
The Mistral client resolved its API key inline in the constructor,
and two behaviors existed only as untested code paths: a
MISTRAL_API_KEY set to the empty string must fall through to
LLM_API_KEY instead of shadowing it, and a self-redirecting endpoint
must exhaust reqwest's redirect budget into the permanent fast-fail
arm of post_request instead of climbing the backoff ladder.

Key resolution moves into a pure resolve_api_key helper whose rules
a unit test pins, keeping process-global environment mutation out of
the parallel suite, and the redirect loop is exercised end to end
against a self-redirecting stub server. The per-request info log
line now carries the shared patch/stage attribution prefix, matching
the response lines.

Signed-off-by: Denis Benato <denis.benato@linux.dev>
Stage outputs from weaker models fail strict JSON parsing on
unescaped double quotes inside string values (serde reports
'expected , or ]' right after an inner quote ends the string
early) and on trailing commas. Three validation retries cannot
fix what the model keeps rewriting the same way, so a parallel
stage dies under BestEffort and its findings are lost.

Add utils::repair_json_candidates: quotes are escaped as content
unless the next non-whitespace character is a structural token,
and commas directly before } or ] are dropped. A quote followed
by a comma or colon is ambiguous - it separates real elements
but also appears inside quoted prose - and no local rule tells
them apart, so two readings are produced. In the prose reading
the first syntax error localizes the derailment and comma- or
colon-preceded quotes at or after it are escaped as content,
while in the structural reading every such quote terminates its
string and keeps the fields after it intact; the prose reading
can swallow those fields into the derailed value, so the
structural reading is preferred whenever it strictly parses and
the prose reading covers the inputs where terminating quotes
cannot parse at all, such as prose that embeds key-colon pairs.
parse_json_from_text applies the variants only after the strict
parse, the raw text, and the brace-candidate extraction all
failed, and only accepts a variant when a strict parse of it
succeeds, so an unrepaired or still-broken output surfaces the
original error instead of silently misreading the input.

The repair runs on the raw text and clean_json_string escapes
control characters on each repaired variant: the cleaner tracks
string state by quote count, so an odd unescaped quote would
flip it and turn the structural newlines between fields into
literal \n sequences outside strings that survive no repair.

Signed-off-by: Denis Benato <denis.benato@linux.dev>
A parallel analysis stage that emits a dismissed_concerns entry
without description or reasoning fails validate_concerns_output,
and after three validation attempts the whole stage dies under
BestEffort, losing every real concern it reported. Seen reviewing
HID: asus gamepad configuration with a flash model at low effort:
the model kept emitting the same stub until the retry budget ran
out and the resources and hardware stages failed.

A contentless dismissal asserts nothing about why the candidate
concern fails to apply, so dropping it is lossless: downstream
stages keep treating the candidate as unresolved, which is the
conservative outcome. Skip such entries in the four per-project
validators and filter them in the shared reducer so they never
reach review state or threads. Dismissals that carry content are
still required to prove themselves with verbatim locations.

Fixes: 3c83b32 ("workflows: require concrete code proof for dismissed concerns")
Signed-off-by: Denis Benato <denis.benato@linux.dev>
Mistral chat completions route prompt caching by a client-chosen
prompt_cache_key: requests carrying the same key land where their shared
prefix is already cached, and the cached prefix bills at 10% of the
input token price. The Mistral provider never sent one, so every tool
round of a review session re-billed the whole conversation prefix at
full input price, and costs exploded relative to the sibling providers,
whose prompt caching defaults on.

The key is a SHA-256 digest of the model, the system prompt, and the
tool definitions: the part of the prompt every tool round of a session
repeats and every session of a review stage repeats across patchsets.
Patch text and kept chains of thought stay out of it, so keys do not
churn per round, and the value is a digest, so no prompt content
travels inside it. The key is derived at translate time, so the local
response cache key and the cache identity are untouched, matching how
Claude keeps prompt_caching out of its identity.

Caching defaults on like the sibling providers; [ai.mistral]
prompt_caching = false drops the field from the wire entirely for
gateways that reject it. MistralSettings loses its derived Default so a
constructed settings value cannot quietly disagree with the serde
default on the new knob, the way Gemini keeps its explicit default
consistent on both paths.

Fixes: a48379e ("ai: add a native Mistral provider")
Signed-off-by: Denis Benato <denis.benato@linux.dev>
@NeroReflex
NeroReflex marked this pull request as ready for review November 7, 2026 03:05
@sashiko-bot

sashiko-bot Bot commented Nov 7, 2026

Copy link
Copy Markdown

Sashiko review — v4

Commit 1/9 — a48379ee ai: add a native Mistral provider

  • [LOW] The commit message ends with a leftover git conflict block
    (# Conflicts: docs/llm-providers.md) in a separate paragraph after the
    Signed-off-by trailer. Because git trailer parsers and
    trailer_paragraph_start_index() in src/worker/fixes_check.rs inspect the
    final paragraph of a commit message, trailing conflict comments push the
    Signed-off-by trailer out of the trailer block. Strip the trailing
    conflict lines so Signed-off-by remains at the end of the commit message.

  • [LOW] src/ai/mistral.rs: MistralClient::post_request() parses the HTTP
    Retry-After header into a Duration without clamping it to
    crate::ai::quota::MAX_RETRY_AFTER, unlike claude::retry_after_header() and
    gemini::valid_retry_after_secs(). On 5xx responses, that uncapped duration
    is passed into MistralError::TransientError and used directly by
    BackoffProvider::generate_content(), which stalls the worker for the full
    header value or panics on Duration addition overflow near u64::MAX. Clamp
    retry_after_duration to crate::ai::quota::MAX_RETRY_AFTER.

  • [LOW] src/ai/mistral.rs: MistralClient::generate_content() and
    MistralClient::post_request() log every outbound request and response
    token count with tracing::info!() instead of tracing::debug!(). Every
    other provider in src/ai/ logs per-turn traffic at debug level so runs at
    the default info log level are not flooded with hundreds of lines per
    patchset review. Use tracing::debug!() at both sites.

Commit 2/9 — 79e53ea6 clippy: satisfy the 1.96 lints that -D warnings turns into errors

  • [HIGH] src/reviewer.rs: Reviewer::drain_review_queue() holds the queue
    tokio::sync::MutexGuard across the entire while let loop body because an
    unbraced while let scrutinee only drops its temporaries before the else
    branch, even on Rust 2024. The first worker holds the queue lock across
    process_patch_review_contained(), which blocks all other intra-patchset
    workers in review_patchset_task(), and any cancellation or claim-check
    error that re-locks the queue to call clear() or drain() deadlocks the
    task forever, leaking its concurrency permit and worktree. Bind the guard
    inside a block scrutinee ({ let mut q = queue.lock().await; q.pop() }) so
    the lock drops before the loop body runs.

Commit 3/9 — f1e4105f ai: keep Mistral chain of thought across tool rounds

  • [LOW] The commit message carries a Fixes trailer citing the earlier
    "ai: add a native Mistral provider" patch from this same unmerged series. A
    Fixes trailer must only point to commits already merged in repository
    history before the series baseline, because same-series hashes change on
    rebase. Drop the Fixes trailer or fold this fixup into the earlier patch.

Commit 4/9 — e922eee8 ai: mirror sibling providers' transport error formatting

  • [LOW] The commit message carries a Fixes: trailer pointing to "ai: add a
    native Mistral provider", which is an unmerged patch earlier in the same
    series. A Fixes: tag must only cite commits already in repository history,
    as same-series hashes become invalid when the series is rebased or
    amended. Drop the Fixes: trailer or squash these changes into the earlier
    patches in the series.

Commit 5/9 — aae77d64 ai: harden Mistral transport and key diagnostics

  • [LOW] The commit message carries a Fixes: trailer pointing to "ai: add a
    native Mistral provider", which is an unmerged patch earlier in this series.
    Unmerged commit hashes are not stable across rebases or patch application.
    Drop the Fixes: trailer or fold these fixes into the earlier patches in the
    series.

Commit 7/9 — 49b6e414 workflow: repair common LLM JSON malformations as a last resort

  • [MEDIUM] src/utils.rs: in repair_json_with(), the prose repair reading
    disables comma and colon string terminators for every byte_pos at or after
    error_offset through the end of the document. When a string with an
    unescaped quote before a comma or colon is not the final field before a
    closing brace or bracket, its own closing quote before the comma is escaped
    as content, Either swallowing trailing string fields into the broken value
    or leaving the string unclosed when the object ends with a non-string field.
    Even when the broken string closes at a brace or bracket, every subsequent
    object key has its closing quote before the colon escaped, so the rest of
    the payload fails to parse. In addition, find_json_candidates() in
    src/workflow/output.rs breaks on the first repair variant that parses as an
    untyped serde_json::Value, discarding the second variant before typed
    deserialization into T checks for swallowed required fields.

  • [MEDIUM] src/utils.rs: repair_json_candidates() runs serde_json::from_str()
    on the raw input and on the structural pairs candidate before
    clean_json_string() escapes literal control characters inside strings. When
    a malformed response also contains a raw newline, carriage return, or tab in
    a string value, serde_json::from_str() rejects pairs on the control
    character and places the field-swallowing mixed reading first, and computes
    error_offset at an earlier control character rather than at the syntax
    error. Clean control characters on the candidate before checking whether
    pairs parses, and pass the cleaned string when computing error_offset.

  • [MEDIUM] src/workflow/output.rs: parse_json_from_text() runs
    find_json_candidates() before top-level repair and passes raw_text instead
    of unfenced to repair_json_candidates(). Because find_matching_brace()
    toggles in_string on every unescaped quote without repair lookahead, any
    JSON object with an odd number of unescaped inner quotes leaves in_string
    inverted at the closing brace and returns None. Fenced or prose-wrapped
    outputs with an odd number of unescaped quotes then fail both
    find_json_candidates() and the final repair pass, while unfenced outputs
    skip the outer object in find_json_candidates() and can match nested brace
    objects against permissive stage schemas before top-level repair runs. Run
    the repair pass on unfenced before falling back to find_json_candidates(),
    and repair before scanning for matching braces.

Commit 9/9 — b3a73571 ai: route Mistral requests to the prompt cache with prompt_cache_key

  • [LOW] The commit message carries a Fixes: trailer referencing "ai: add a
    native Mistral provider", which is an earlier unmerged commit in the same
    patch series. Fixes: trailers must only reference commits already merged
    prior to the series; drop the Fixes: line.

Full review and stage logs on sashiko.sashiko.dev

@rgushchin

Copy link
Copy Markdown
Member

Please, rebase and address sashiko's comments. Thanks

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