Skip to content

fix: Release obsolete model caches across residency changes - #816

Draft
buildingjoshbetter wants to merge 1 commit into
fix/reranker-global-order-publish-735from
fix/model-residency-publish-297
Draft

buildingjoshbetter wants to merge 1 commit into
fix/reranker-global-order-publish-735from
fix/model-residency-publish-297

Conversation

@buildingjoshbetter

@buildingjoshbetter buildingjoshbetter commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Scope

A reviewed cache-lifetime step for #297, stacked on #813. Preserve embedding and reranker identities, dtypes, dimensions, batch limits, queue limits and result caps.

Reproduction and changes

Synthetic constructor and inference barriers reproduced overlapping obsolete model references during replacement and stale CPU cache retention after main-model changes. These are lifetime defects; the reproduction does not establish an unbounded leak or native byte cost.

  • Release the obsolete main embedding or reranker cache before constructing a distinct replacement. A failed replacement leaves the cache empty; requesting the old identity loads it again. Compatible aliases reuse their model.
  • Give each main embedding residency an opaque generation. Alias retags preserve it; A -> B -> A replacement creates a new generation.
  • Capture only identity and generation for CPU clone construction. A clone built across a main-generation change can finish its captured request but cannot become the current cache.
  • Retire idle stale CPU clones without waiting for active fast inference. An active owner retains its model through inference and retries retirement when its slot is released.
  • Use a short metadata lock for publication and retirement. Constructors, inference and model destruction remain outside it. Preserve main-state-to-residency and fast-to-residency ordering.

The existing target-model tests that required retention of the old warm cache now assert the explicit memory-first failure policy, weakref release and reload. Their configuration, in-flight identity and lock assertions remain. Existing microbatch tests receive only the AST fixture dependencies required by the actual methods; behavioral assertions remain unchanged.

Validation

  • Author: 110 focused tests across residency, allocation preflight, target model, ordering, deadlines and inference ownership.
  • Root: all 13 new stdlib tests passed against the actual extracted production methods.
  • Independent review: 49 focused tests plus three additional event-controlled race probes passed; no blocker. Original-source negative controls fail five assertions across four tests. Targeted mutations also reject retained snapshots, identity-only publication, omitted owner cleanup and publication/retirement races.
  • Integration-based author branch: 2,842 passed, 22 skipped, 3 deselected; 2,053 subtests passed, with actual sqlite-vec. Log SHA256: 5048bec8c709f9a14b3a588d57fa3a9a4461c13c9655626d70d08c2624e2e495.
  • Exact isolated publication branch: 2,224 passed, 22 skipped, 3 deselected; 563 subtests passed, with actual sqlite-vec. Log SHA256: 69427dc69358467b7c565222bbbafe39c3f0d9e02178d0adc7f5d4a99e48f28c.
  • Four code/test files match the reviewed author candidate byte-for-byte; documentation preserves the prerequisite branch. Ruff, Python 3.10 grammar, whitespace, scoped privacy and public commit-identity checks passed. All 34 hosted checks pass at 2824d3cc5d03ce948597fd51d404a89b4c3c0f30.

Limits and remaining work

This step limits obsolete Python cache references. It does not establish a whole-process memory budget, bound native allocator caches, eliminate active main/CPU overlap, change OOM fallback, or measure MPS memory, thermals or production latency. #297 remains open for the remaining admission and native validation work.

Only synthetic data was used in isolated tests. No personal memories, transcripts or credentials were exported. No main merge, release, package publication or issue closure.

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