Skip to content

fix(engine): red review - model aliasing, KV cache safety, drop dead speculative - #6

Closed
hanzo-dev wants to merge 3 commits into
feat/anthropic-streamingfrom
fix/red-findings
Closed

hanzo-dev wants to merge 3 commits into
feat/anthropic-streamingfrom
fix/red-findings

Conversation

@hanzo-dev

Copy link
Copy Markdown
Member

Stacks on #5 (Anthropic SSE streaming).

Fixes

  • anthropic.rs: alias claude-* model ids to the loaded default
  • disk_kv_cache.rs save: unique per-process tmp name (race fix)
  • disk_kv_cache.rs load: bound text_len + payload_bytes against budget (OOM fix)
  • delete dead mistralrs/src/speculative.rs (upstream removed SpeculativePipeline from public re-exports; MTP is the new path)

Tests

  • 7/7 mistralrs-server-core::anthropic unit tests still pass
  • cargo check -p mistralrs clean after deleting speculative.rs
  • cargo check -p mistralrs-server --features cuda clean

hanzo-dev added 2 commits May 29, 2026 21:40
- anthropic.rs: alias any model id starting with "claude" to the loaded default
  so Claude Code requests (claude-sonnet-4-5-*, claude-opus-4-7-*, ...) don't
  get rejected by validate_model_name on a single-model engine.
- disk_kv_cache save: per-process unique tmp name ({key}.{pid}-{seq}.kv.tmp)
  instead of the shared {key}.kv.tmp, so two concurrent saves of the same
  key no longer truncate each other's in-flight payload.
- disk_kv_cache load: bound text_len and payload_bytes against cache budget
  before allocating, so a malformed/malicious file can't OOM the process.
- mistralrs/src/speculative.rs: delete. mistralrs-core stopped re-exporting
  SpeculativePipeline/SpeculativeLoader (only SpeculativeConfig and MtpConfig
  remain) when the API pivoted to MTP-based speculative decoding (gemma4 /
  deepseek v3 MTP heads). The old draft+target TextSpeculativeBuilder no
  longer compiles. Re-add a builder for the MTP path if there's demand.
These should have been in cc0e774 but a stray pathspec error in the
git add invocation dropped them.

- anthropic.rs: alias any model id starting with "claude" (case-insensitive)
  to the loaded default, so Claude Code's claude-sonnet-4-5-* / claude-opus-4-7-*
  ids don't get rejected by validate_model_name on a single-model engine.
- disk_kv_cache save: unique per-process tmp name ({key}.{pid}-{seq}.kv.tmp)
  via TMP_SEQ atomic counter, instead of the shared {key}.kv.tmp -- two
  concurrent saves to the same key no longer truncate each other.
- disk_kv_cache load: bound text_len and payload_bytes against the cache
  budget before allocating, so a malformed/malicious file can't OOM-kill
  the engine.
@github-actions

github-actions Bot commented May 29, 2026 •

Copy link
Copy Markdown
Code Metrics Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Language              Files        Lines         Code     Comments       Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 C Header                  5          305          210           52           43
 CSS                       5         1462         1288           39          135
 CUDA                     60        20622        16570         1656         2396
 Dockerfile                1           38           21            8            9
 JavaScript               19         3972         3089          488          395
 Jinja2                    7          694          656            5           33
 JSON                     27         9400         9397            0            3
 Makefile                  1            6            5            0            1
 MDX                       1          147            0          132           15
 Metal Shading Lan|       34        13466        10542         1117         1807
 PowerShell                1          300          227           30           43
 Python                  131        10161         8357          462         1342
 Shell                     4          948          765          106           77
 Plain Text                3         3723            0         2413         1310
 TOML                     30         1427         1237           46          144
 TypeScript               11         1607         1371           66          170
 YAML                      4           41           39            2            0
─────────────────────────────────────────────────────────────────────────────────
 HTML                      4          782          695           38           49
 |- CSS                    1          578          544           14           20
 |- JavaScript             1           24           23            0            1
 (Total)                             1384         1262           52           70
─────────────────────────────────────────────────────────────────────────────────
 Jupyter Notebooks         3          122           83           23           16
 |- Markdown               1           60           30           22            8
 |- Python                 1          122          113            1            8
 (Total)                              304          226           46           32
─────────────────────────────────────────────────────────────────────────────────
 Markdown                210        19178            0        13456         5722
 |- BASH                 123         1399         1090          190          119
 |- Dockerfile             3            6            6            0            0
 |- JSON                  35         1175         1175            0            0
 |- PowerShell             5            7            7            0            0
 |- Python                45         1717         1459           65          193
 |- Rust                  64         2423         2048           56          319
 |- TOML                  16          318          250            4           64
 |- YAML                   3           18           17            1            0
 (Total)                            26241         6052        13772         6417
─────────────────────────────────────────────────────────────────────────────────
 Rust                    602       259959       229293         6654        24012
 |- Markdown             400         9599          454         7977         1168
 (Total)                           269558       229747        14631        25180
─────────────────────────────────────────────────────────────────────────────────
 Svelte                   18         1831         1696           50           85
 |- CSS                    1            4            4            0            0
 |- JavaScript            18          876          727           24          125
 (Total)                             2711         2427           74          210
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Total                  1181       368517       293488        35197        39832
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

…ot post-parse

The earlier aliasing attempt set model_id=None for the routing call but left
openai_req.model = the claude id, so parse_request still rejected it
("Requested model 'claude-sonnet-4-5-...' is not available"). Map claude-* to
"default" inside anthropic_to_openai (before parse_request); the response still
echoes the originally requested id. Verified live: claude-sonnet-4-5-* and
claude-opus-4-7 now work both streaming and non-streaming against a single-model
engine.
@hanzo-dev

Copy link
Copy Markdown
Member Author

Merged to main via fast-forward (commits cc0e774, 170f624, 73195b1 are in origin/main @ 73195b1). Closing; not a separate merge commit.

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