feat(workers): V6 fingerprint-keyed representative cache (ADR 0113) #1269
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/rep-cache-worker"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Worker side of ADR 0113 V6 (fingerprint-keyed representative cache) — the biggest remaining per-run cost after the v3 graph optimization:
_person_representativeswas recomputed from scratch over the whole labeled library every run (~1–2 min at owner scale, pure deterministic waste on unchanged inputs).clustering.py:_representative_fingerprint(rows, split, model)— the pinned digest (sha256 over sorted pair-local usable face ids +:.3fsplit + model pair);_decompose_person_rows— the ADR 0108 per-person body extracted verbatim;_person_representatives_with_fingerprints(embeddings, assignments, split, *, persisted=None)— row selection performed ONCE, fingerprint computed inside that path (zero selection duplication), per person: fingerprint-equal persisted entry with non-empty reps → reuse verbatim (skips evenunit_rows, not just linkage); else recompute._person_representativesstays a thin full-recompute wrapper (signature/behavior unchanged).core_api.py:fetch_owner_face_embeddingsreturns a typedOwnerFaceFeed(embeddings, person_representatives)reading the new top-level response key (missing/non-list →[]= pure recompute for older Core).main.py: handler applies the cache method-independently (v2 AND v3) beforerun_clustering;_representative_cache_from_entriestreats every malformed row — including explicit JSONnullfingerprints from the API response — as a cache MISS, never an error;_person_representatives_payloadgains the additive optionalfingerprintso the envelope full-replaces with the reused-or-recomputed set + its digest.Test plan
test_representative_fingerprint_cache.py(15 tests): digest material + determinism/permutation/split/model-pair sensitivity, the V6 sub-gate (monkeypatch counter: zerocosine_distance_matrixcalls on hits, full recompute on miss), byte-identical hit parity through the envelope JSON round trip, handler-level hit/stale/v3-independence/empty-cache.test_multi_representant.pypins every shipped entry carries a non-empty fingerprint.feat/rep-cache-api: entry keys, 64-hex definition, null-as-miss. Merge order: API PR first, then this one.