Commit 4f0f7fa
Closes #500 (customer-module timeouts) and #593 (the impl itself);
completes the mitigation cluster for #463 alongside the already-shipped
#590 (adaptive rate limit), #591 (bulk upsert), and #592 (filtered
write-through).
The SQLite-backed typed cache is persistent across MCP sessions, so the
expensive case is the very first run or one after long idleness. Today
the first tool call that needs a cold entity pays the full sync RTT,
which under Katana's 60/min rate limit can exceed the MCP client's
~60s request timeout — surfacing as opaque `-32001` errors. There is
typically a gap between Claude/MCP startup and the first user-facing
tool call; this PR uses that gap.
In `server.lifespan`, after `typed_cache.open()`, schedule
`_warm_caches_in_background(client, typed_cache)` via
`asyncio.create_task` and yield immediately. The task fans out 16
`ensure_*_synced` calls through `asyncio.gather(...,
return_exceptions=True)` so a transient failure on one entity never
blocks the others or crashes the server. On lifespan exit the task is
cancelled cleanly before `typed_cache.close()` so writes can't race a
closed engine. `manufacturing_order_recipe_row` is pulled implicitly
via `MANUFACTURING_ORDER_SPEC.related_specs` and intentionally absent
from the explicit warmup list.
Tool calls that arrive mid-warmup serialize on each entity's
`cache.lock_for(...)` and wait the same amount of time they would have
waited without warmup, with the warmup's incremental progress
available on later calls — no extra cost in the worst case.
Set `MCP_DISABLE_CACHE_WARMUP=1` to skip (used by the new conftest
autouse fixture so tests that don't intentionally exercise the warmup
don't kick off async tasks against a mock client). Tests that want the
real warmup path opt in with `@pytest.mark.cache_warmup_enabled`.
Tests:
- `test_disable_env_var_skips_warmup` — pins that the autouse fixture
works; future refactors decoupling the env-var check from the task
creation will fail this test.
- `test_warmup_task_scheduled_when_enabled` — pins fire-and-forget
semantics + name-based task lookup + clean cancellation on exit.
- `test_warmup_failure_does_not_crash_server` — a raising warmup body
doesn't propagate out of the lifespan.
- `test_warm_caches_in_background_swallows_per_entity_errors` — pins
the `return_exceptions=True` gather contract directly.
Bundles the uv.lock sync to mcp v0.69.1 from the auto-release after
PR #678 merged.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c329345 commit 4f0f7fa
5 files changed
Lines changed: 391 additions & 0 deletions
File tree
- katana_mcp_server
- src/katana_mcp
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
| |||
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
47 | 142 | | |
48 | 143 | | |
49 | 144 | | |
| |||
109 | 204 | | |
110 | 205 | | |
111 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
112 | 221 | | |
113 | 222 | | |
114 | 223 | | |
| |||
120 | 229 | | |
121 | 230 | | |
122 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
123 | 257 | | |
124 | 258 | | |
125 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
10 | 40 | | |
11 | 41 | | |
12 | 42 | | |
| |||
0 commit comments