You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
impl(011): wire the embedding cache into the backend (3.14) - #490
Spec 011: the embedding cache wired into the backend (3.14, 3.7.1)
Wires the cache that increment 4 (#445) landed into EmbedLinearBackend. No file under src/cache.rs changes; the wiring lives in src/backend.rs and src/lib.rs.
EmbedConfig gains embedding_cache: Option<CacheLimits>, off when None. Setup builds the cache with the synthetic encoder's repeatability evidence for a synthetic bundle and none otherwise, so an onnx bundle with a cache configured is refused cache_not_equivalent (today it is refused unqualified_platform first).
Each prepared request is looked up on the caller, before any handoff, keyed by principal handle and post-truncation token ids and mask. A hit applies the head on the caller, reaches no worker, and is charged observed{units_per_call} (3.11.4).
A miss carries its ticket to the worker. The worker admits the embedding only when the run completed and its attempt was not cancelled or abandoned, so a late result is never cached (3.12.3, 3.14.4). A clear_cache or erase_principal during the run invalidates the ticket (3.14.5).
New methods: EmbedLinearBackend::cache_stats(), clear_cache() and erase_principal(handle). With the cache off, the counters stay zero.
#485 builds EmbedConfig with a struct literal in integrations/rustev-node/src/local_embed.rs and backends/rustev-backend-embed-linear/tests/support_routing/conformance.rs. Whichever of the two lands second must add embedding_cache: None to both literals. It is a compile error, not a silent change.
Tests
tests/backend/cache.rs (9 tests):
cache off by default
a hit's logits bitwise equal to the miss's and to an uncached backend's
principal isolation
eviction by entries (least recently used) and by bytes
clear_cache and erase_principal
erase_principal racing an in-flight run
cancelled, failed and abandoned runs not admitted
the cache configuration leaves the descriptor and cost bound unchanged (3.5.2)
Reviewing the diff across the five changed source files and the spec increment.
backend.rs — open refactor
The old Self::start(config, preparer.clone(), default_run(&preparer)?) cloned the Arc only to drop the original after the call. The new ordering (let run = default_run(&preparer)?; Self::start(config, preparer, run)) moves the Arc directly. Functionally identical; no defect.
backend.rs — open_cache
The #[cfg(feature = "synthetic")] arm on the EncoderKind match correctly maps to RepeatabilityEvidence::Synthetic only when the feature is compiled in; without it the _ arm produces Unproven, and EmbeddingCache::new will refuse with cache_not_equivalent. Consistent with the spec note.
backend.rs — hit path
The early return report(output, cost.units_per_call, false) on a cache hit exits before the Job is constructed. No miss ticket is created; no worker is involved. Charge is units_per_call only. Correct per 3.11.4.
backend.rs — admission condition in worker result.map(|(output, embedding)| { … admit … }) runs only on Ok; a failed run is Err and never reaches admit. For succeeded runs, j.abandoned || cancel.is_raised() gates the outcome. If abandoned, j.result = Some(result) is also skipped (separately guarded), but the map closure still executes, calling admit with RunOutcome::Cancelled — correctly voiding the ticket. Consistent with 3.14.4 and 3.12.3.
backend.rs — lock ordering drop(cancel) moved from before the state-lock acquisition to inside the locked block. cancel is an Arc wrapping a cancel signal (simple atomic); its drop just decrements the refcount and does not acquire any lock. No deadlock path introduced. The state→job→cache ordering is consistent: caller calls lock(cache).lookup with no other lock held; worker calls lock(cache).admit inside state+job locks but never the reverse.
backend.rs — erase_principal / clear_cache
These call lock(cache).{erase_principal,clear}() with no other lock held. The test erase_principal_racing_an_in_flight_run_is_not_stored correctly verifies the generation-stamp mechanism refuses the stale ticket.
tests/backend/cache.rs
Test coverage matches the spec's enumerated cases: off by default, bit-for-bit equality between hit/miss/uncached, principal isolation, entry-bound eviction, byte-bound eviction (1-byte limit ensures zero admitted), clear_cache and erase_principal, racing erase against in-flight run, cancelled/failed/abandoned not admitted, and descriptor/cost-bound independence.
specs/011-semantic-backend/spec.md
The increment 4 wiring note accurately describes the implementation. No claim about code is made as draft; the spec's status/implementation fields are not changed in the diff so no lifecycle issue is introduced. References to 3.5.2, 3.7.1, 3.11.4, 3.12.3, 3.14.x are internal section references, not cross-corpus spec ids.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spec 011: the embedding cache wired into the backend (3.14, 3.7.1)
Wires the cache that increment 4 (#445) landed into
EmbedLinearBackend. No file undersrc/cache.rschanges; the wiring lives insrc/backend.rsandsrc/lib.rs.EmbedConfiggainsembedding_cache: Option<CacheLimits>, off whenNone. Setup builds the cache with the synthetic encoder's repeatability evidence for a synthetic bundle and none otherwise, so anonnxbundle with a cache configured is refusedcache_not_equivalent(today it is refusedunqualified_platformfirst).observed{units_per_call}(3.11.4).clear_cacheorerase_principalduring the run invalidates the ticket (3.14.5).EmbedLinearBackend::cache_stats(),clear_cache()anderase_principal(handle). With the cache off, the counters stay zero.Interaction with #485
#485 builds
EmbedConfigwith a struct literal inintegrations/rustev-node/src/local_embed.rsandbackends/rustev-backend-embed-linear/tests/support_routing/conformance.rs. Whichever of the two lands second must addembedding_cache: Noneto both literals. It is a compile error, not a silent change.Tests
tests/backend/cache.rs(9 tests):clear_cacheanderase_principalerase_principalracing an in-flight run