Commit 76ff913
committed
fix(mlx): tools-aware prefix-cache boundary + incremental default-on
Agentic (tools) requests cold-re-prefilled the full ~48K system+tools
head on every client compaction. The tools path stored the full prompt
and matched via starts_with, so it only HIT on turn-to-turn extension;
a compaction (rewritten early messages -> divergent tail) missed and
re-prefilled from scratch (~98s for a 48K head).
Two-part fix:
- detect_system_tools_prefix_len[_from_turns]: snapshot the boundary at
the rendered system+tools head (~47980 tok) instead of system-only
(~22830), so the ~25K-token tool-schema block is inside the pinned
boundary. Wired into all 4 tools call sites; render_tools_system_block
made pub(crate). Safe: the store snapshots prompt_ids[..b] (real token
prefix), so an off-by-a-token boundary can only under/over-cache,
never corrupt KV.
- DEFAULT_INCREMENTAL false -> true: incremental boundary caching now
default-on (revert with LUMEN_MLX_PREFIX_INCREMENTAL=0).
Verified on live 35B: second same-system/same-tools request forks the
1733-token head and prefills only the 20-token divergent tail
(2357ms -> 102ms, 23x), output correct.1 parent 82be0a6 commit 76ff913
3 files changed
Lines changed: 62 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3449 | 3449 | | |
3450 | 3450 | | |
3451 | 3451 | | |
3452 | | - | |
| 3452 | + | |
3453 | 3453 | | |
3454 | 3454 | | |
3455 | 3455 | | |
| |||
3492 | 3492 | | |
3493 | 3493 | | |
3494 | 3494 | | |
3495 | | - | |
| 3495 | + | |
3496 | 3496 | | |
3497 | 3497 | | |
3498 | 3498 | | |
| |||
3528 | 3528 | | |
3529 | 3529 | | |
3530 | 3530 | | |
3531 | | - | |
| 3531 | + | |
3532 | 3532 | | |
3533 | 3533 | | |
3534 | 3534 | | |
| |||
3568 | 3568 | | |
3569 | 3569 | | |
3570 | 3570 | | |
3571 | | - | |
| 3571 | + | |
3572 | 3572 | | |
3573 | 3573 | | |
3574 | 3574 | | |
| |||
4194 | 4194 | | |
4195 | 4195 | | |
4196 | 4196 | | |
| 4197 | + | |
| 4198 | + | |
| 4199 | + | |
| 4200 | + | |
| 4201 | + | |
| 4202 | + | |
| 4203 | + | |
| 4204 | + | |
| 4205 | + | |
| 4206 | + | |
| 4207 | + | |
| 4208 | + | |
| 4209 | + | |
| 4210 | + | |
| 4211 | + | |
| 4212 | + | |
| 4213 | + | |
| 4214 | + | |
| 4215 | + | |
| 4216 | + | |
| 4217 | + | |
| 4218 | + | |
| 4219 | + | |
| 4220 | + | |
| 4221 | + | |
| 4222 | + | |
| 4223 | + | |
| 4224 | + | |
| 4225 | + | |
| 4226 | + | |
| 4227 | + | |
| 4228 | + | |
| 4229 | + | |
| 4230 | + | |
| 4231 | + | |
| 4232 | + | |
| 4233 | + | |
| 4234 | + | |
| 4235 | + | |
| 4236 | + | |
| 4237 | + | |
| 4238 | + | |
| 4239 | + | |
| 4240 | + | |
| 4241 | + | |
| 4242 | + | |
4197 | 4243 | | |
4198 | 4244 | | |
4199 | 4245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
0 commit comments