Skip to content

Preview cache hygiene: stale-signature prefetch containers, same-key put(), warm flat re-decode, inflight-latch audit #60

Description

@ben-dev-au

Pre-existing edges in the preview/prefetch caching (now fnd/tui/preview/ + fnd/tui/widgets/preview_container.py), surfaced by review on #51#54 and deferred to keep the decomposition PRs pure relocation:

  1. Stale-query containers can be cached. PrefetchEngine._mount_chunk_loop bails when the query signature changes, but its finally block still put()s a partially-mounted container if any chunk landed. Keyed by the old signature it can never be served, but it occupies the 1-slot LRU and can evict the fresh container.
  2. PreviewCache.put() does not surface a same-key replacement. Overwriting an existing (parent_doc_id, query_signature) entry returns the old container in neither evicted nor anywhere else, so the caller cannot remove the orphaned widget tree from the DOM.
  3. Warm flat results are re-decoded. prefetch_top_results filters candidates by preview_cache only; a flat file already warmed into flat_buffer_cache/prebuilt_cache is re-targeted and re-decoded each pass (the mount is then skipped by the cache-key check, so this is wasted decode work, not a correctness bug).
  4. Audit: inflight_target release on non-finalize completion paths. The dedup latch set by fire_pending_load() is released by _finalize_via_lock, on mount cancel (fix(tui): clear in-flight preview latch on mount cancel #42), and on query change. Review claims the flat and warm/instant structural completions may leave it set, suppressing an identical re-navigation. The area has dedicated tests (test_preview_load_debounce, test_preview_stuck_fast_nav lineage); verify with a characterization test before changing anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions