Skip to content

Search/content cache cleanup judges a process-local index, not the disk — pre-restart files orphaned forever #5601

Description

@Ninthkitten

Prerequisites

  • I searched open issues and discussions and did not find an existing report of this bug.
  • This is not a security vulnerability.
  • I am running the latest code from the dev branch.

Install Method

Docker

Operating System

macOS (Apple Silicon), Docker Desktop

Steps to Reproduce

  1. Use web search / content fetching so the search and content caches fill.
  2. Restart the container.
  3. Keep using search normally, then inspect the cache directory.

Expected Behaviour

Entries past their max age are removed.

Actual Behaviour

cleanup_cache in services/search/cache.py evicts based on a process-local in-memory index. That index is empty after every restart, so every file written before the last restart becomes invisible to the cleaner and is never removed — permanently orphaned.

Found here: 158 orphaned content files (5.5 MB), days old, whose configured max age is 2 hours. The cleaner reported nothing to do, because as far as its index was concerned there was nothing there.

Compounding it: cleanup only runs on writes (throttled to at most 1/h for search, 1/2h for content), so a quiet instance never cleans at all.

Additional Information

Fix running here: the directory is the ground truth (glob("*.cache")); the index supplies the timestamp when it knows one, otherwise the file's mtime is used. Age and max-count semantics unchanged, signature unchanged (callers and tests unaffected), each deletion individually exception-wrapped so cleanup can never fail a search.

First run after the fix: evictions=158, content 158 → 0.

General shape worth applying to both caches: cache eviction must be judged against the filesystem, not against a data structure that dies with the process.

Are you willing to submit a fix?

Yes — the fix described above is running in production here and I can open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready for reviewDescription complete — ready for maintainer review

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions