Skip to content

feat(auth): run on a Mistral subscription with lechat/ models - #1748

Open
spariev wants to merge 2 commits into
usestrix:mainfrom
spariev:feat/mistral-subscription
Open

spariev wants to merge 2 commits into
usestrix:mainfrom
spariev:feat/mistral-subscription

Conversation

@spariev

@spariev spariev commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

Adds a second model subscription next to ChatGPT. You sign in to Mistral once, and you can then run scans on lechat/<model> with no API key.

strix auth login mistral
export STRIX_LLM="lechat/mistral-large-latest"
strix -n --target https://example.com

mistral/<model> still goes through LiteLLM with LLM_API_KEY, as it does today.

Changes

  • strix/config/mistral.py (new): OIDC sign-in against auth.mistral.ai (Ory Hydra, public client, PKCE, loopback callback on 127.0.0.1:8766). Also handles refresh-token rotation under a file lock, shares the token store ~/.strix/subscription-auth.json, and provides an AsyncOpenAI client that sets the auth headers on every request.
  • Auth details that differ from ChatGPT:
    • api.mistral.ai authenticates the ID token. The access token (opaque ory_at_…) gets 401 Invalid API Key.
    • Requests also need x-external-organization-id and x-external-workspace-id. The tenant comes from GET /v1/users/me/workspaces once at sign-in and is carried across refreshes.
    • The ID token lives about 15 minutes, so the record expires with it and refreshes ahead of time.
  • Reasoning-model output: mistral-large-latest returns content as a list of thinking and text chunks. The Agents SDK expects a string and fails with ResponseOutputText … Input should be a valid string. _MistralChatModel turns text chunks into content and thinking chunks into reasoning_content, in both streamed and non-streamed responses.
  • strix/config/subscriptions.py (new): a small Subscription registry (ChatGPT, Mistral). It replaces the chatgpt/ prefix checks that were hardcoded in the CLI, environment checks, scan setup, report state and runner. strix auth login|status|logout now loops over the registry.
  • Context window: lechat/x looks up LiteLLM's model info under mistral/x and never sends the raw lechat/ name to LiteLLM.
  • LLM_DISABLE_STREAMING applies to lechat/ models.
  • README: documents the Mistral sign-in next to ChatGPT.

Reviewer notes

  • OIDC client. The client ID 829da7e7-… is the public client that Mistral's own CLI (Mistral Vibe) uses. Mistral doesn't publish a client for third-party tools that I know of. If you'd rather not ship it, this PR can wait until Mistral gives Strix its own client.
  • Why lechat/: mistral/ is already LiteLLM's API-key route, and reusing it would break existing configs.
  • Workspace. Strix uses the first workspace the API returns, which is the CLI's default. There is no override yet (Vibe has VIBE_CLI_OIDC_WORKSPACE_ID). I can add one if you want it.
  • Related: [BUG] ResponseOutputText mishandles thinking text in blocks #1357. That issue reports the same thinking/text content shape. This PR fixes it only for lechat/ models. The openai/<model> + LLM_API_BASE=https://api.mistral.ai/v1 route in [BUG] ResponseOutputText mishandles thinking text in blocks #1357 still goes through LiteLLM and isn't changed here.

Testing

  • New and updated tests:
    • tests/test_mistral_auth.py: sign-in exchange, tenant discovery, missing id_token and workspace, refresh and rotation races, request headers, and the client hook on real httpx requests.
    • tests/test_models.py: thinking content, streamed and non-streamed.
    • tests/test_auth_cli.py, tests/test_context_budget.py, tests/test_disable_streaming.py.
  • ruff check, ruff format --check and mypy are clean.
  • Pyright reports no new errors in the touched files. make check-all still fails at pyright because of errors already on main.
  • Full test suite: the same failures as on main (mostly _start_child_runner() missing … 'skills'). Nothing in this PR causes them.
  • Live runs against a real Mistral account:
    • Sign-in, auth status, a forced refresh (the refresh token rotated and the account was kept), and listing models.
    • A headless scan of a local SQL-injection target with lechat/mistral-large-latest: it found the injection, and all 36 LLM requests returned 200 from api.mistral.ai.
    • The same scan with LLM_DISABLE_STREAMING=1, after expiring the stored token: it refreshed, then made 9 non-streamed requests, all 200.

`strix auth login mistral` signs in with Mistral's OIDC issuer (Ory Hydra,
public CLI client, PKCE) and `STRIX_LLM=lechat/<model>` runs inference on
the subscription through api.mistral.ai's chat completions, with no API key.

The API authenticates the ID token, not the access token, and needs the
caller's organization and workspace in x-external-* headers; the tenant is
discovered once at sign-in and the record expires with the ID token.
Reasoning models answer with thinking/text content chunks, which the
Mistral chat model reshapes into the text and reasoning_content the SDK
reads, streamed or not.

A Subscription registry (subscriptions.py) replaces the codex-only prefix
checks at every call site; mistral/ stays LiteLLM's API-key route.
@spariev
spariev marked this pull request as ready for review November 16, 2026 11:24
@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR adds a Mistral subscription path to scan setup and model calls.

Lock shared credential changes before merging so signing out of one provider cannot break another provider's scans.

Findings

  1. P1 Logout overwrites refreshed credentials ▶
Fix with agent prompt
### Issue 1
strix/config/mistral.py:104-109
`logout()` rewrites the shared store without taking the refresh lock. If Mistral logout reads the store just before a running ChatGPT scan saves a rotated refresh token, logout writes the old ChatGPT token back. The next refresh fails because that token has already been spent, forcing the user to sign in again.

Use one shared lock for every provider's store changes, including login and logout, not just refresh.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds Mistral subscription sign-in and the lechat/ model route.

  • Mistral users can sign in and save their subscription account.
  • Mistral subscription scans send replies Strix can use.
  • Scan setup and reports now recognize both subscription providers.

Acknowledged by spariev in the supplied PR description:

  • Reusing Mistral's public CLI client is intentional pending a Strix-specific client.
  • Choosing the first workspace is intentional; a workspace override is deferred.
  • Fixing thinking/text replies for the existing openai/ plus Mistral endpoint route is outside this PR.

Reviews (1) · Last reviewed commit: "feat(auth): run on a Mistral subscriptio..." · Reviewed by Greptile

Comment thread strix/config/mistral.py Outdated
Comment on lines +104 to +109
data = _read_store()
if PROVIDER not in data:
return
del data[PROVIDER]
if data:
_write_store(data)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Logout overwrites refreshed credentials

logout() rewrites the shared store without taking the refresh lock. If Mistral logout reads the store just before a running ChatGPT scan saves a rotated refresh token, logout writes the old ChatGPT token back. The next refresh fails because that token has already been spent, forcing the user to sign in again.

Use one shared lock for every provider's store changes, including login and logout, not just refresh.

Prompt To Fix With AI
This is a comment left during a code review.
Path: strix/config/mistral.py
Line: 104-109

Comment:
**Logout overwrites refreshed credentials**

`logout()` rewrites the shared store without taking the refresh lock. If Mistral logout reads the store just before a running ChatGPT scan saves a rotated refresh token, logout writes the old ChatGPT token back. The next refresh fails because that token has already been spent, forcing the user to sign in again.

Use one shared lock for every provider's store changes, including login and logout, not just refresh.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 2b6ebed. The store, its path, and its lock moved into strix/config/subscription_store.py. save_record, logout, and token refresh for both providers now hold the same locked() (thread lock + flock), so a Mistral logout or login blocks until an in-flight ChatGPT refresh has saved its new token. Regression test: test_logout_waits_for_a_chatgpt_refresh_and_keeps_its_rotated_token.

ChatGPT and Mistral records share subscription-auth.json, but only token
refresh took a lock, and each provider had its own copy of it. A logout or
login that read the file before a peer saved a rotated refresh token wrote
the spent token back, forcing a fresh sign-in.

The store, its path and a single locked() guard (thread lock + flock) move
to subscription_store.py. save_record, logout and refresh for both
providers now hold it.

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