Skip to content

Commit dd51f16

Browse files
fluffy314cursoragent
authored andcommitted
fix(prefill): preserve unrelated snapshots during jobs
Reserve only the conservative final-snapshot estimate so atomic publication remains protected without erasing Generator or prior Critic snapshots needed for cold restore. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 62ba253 commit dd51f16

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

inference_engine/distributed/prefill_worker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ def _run(self, job_id: str) -> None:
267267
timer.daemon = True
268268
timer.start()
269269
try:
270-
# MLX workers are single-job. Reserve the full current budget
271-
# before model compute so adaptive resizing and unrelated
272-
# boundaries cannot evict the final snapshot before leasing.
270+
# Reserve a conservative estimate before model compute. Atomic
271+
# publish protects the final snapshot without evicting unrelated
272+
# content-addressed snapshots needed by later restore requests.
273273
self.cache_store.reserve(
274274
job.job_id,
275-
self.cache_store.max_bytes,
275+
len(job.token_ids) * self.estimated_snapshot_bytes_per_token,
276276
)
277277
blocks = tuple(self._engine_for_current_thread().compute_prefill(
278278
job.token_ids,

tests/inference_engine/distributed/test_prefill_worker.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,32 @@ def test_job_rejects_snapshot_capacity_before_model_compute():
256256
jobs.close()
257257

258258

259+
def test_job_reservation_preserves_unrelated_restore_snapshot():
260+
cache = PrefixCacheStore(COMPAT, max_bytes=100, node_id="shared")
261+
old = CacheBlock.create(b"z" * 32, 2, b"old-snapshot")
262+
cache.put(old)
263+
jobs = PrefillJobStore(
264+
_Engine(),
265+
cache,
266+
estimated_snapshot_bytes_per_token=10,
267+
)
268+
try:
269+
job = jobs.submit(
270+
request_id="new-prefix",
271+
tenant_id="tenant",
272+
token_ids=[1, 2],
273+
block_hashes=[b"a" * 32],
274+
compatibility=COMPAT,
275+
compression=CompressionCodec.NONE,
276+
)
277+
job.future.result(timeout=1)
278+
assert job.state == PrefillJobState.COMPLETED
279+
assert old.block_hash in cache.block_hashes()
280+
assert job.block_hash in cache.block_hashes()
281+
finally:
282+
jobs.close()
283+
284+
259285
def test_factory_engine_is_warmed_and_used_on_same_compute_thread():
260286
cache = PrefixCacheStore(COMPAT, max_bytes=1024, node_id="w")
261287
created_on = []

0 commit comments

Comments
 (0)