Skip to content

Index cache is written under $TMPDIR and never pruned; prefer XDG_CACHE_HOME #303

Description

@WingedGuardian

Summary

ripwire writes its index cache under $TMPDIR. On systems where TMPDIR points at a small, separately-budgeted volume, the cache accumulates until that volume is exhausted — and because the artifacts are never pruned, the pressure is permanent rather than transient.

Version: ripwire 0.6.1 (Release, GNU 13.3.0, built_from=30f14a274)

What I measured

Running under Claude Code, which sets TMPDIR to a dedicated scratch volume per session:

$TMPDIR/ripwire/<2-hex>/ripwire-<16-hex>-lean.bin

6 files, 5 of them ~24MB each = ~117MB
mtimes spanning a single ~7-hour working session

Each distinct repository state appears to produce its own -lean.bin, keyed by a content hash. Over one long session across a few branches, five accumulated. Nothing removed the earlier ones — they are still there after the states they describe are gone.

On that host the scratch volume is budgeted at 500MB with a warning threshold at 375MB. Ripwire's 117MB alone was 23% of the budget, and removing just those stale caches took total usage from 410MB back to 293MB — i.e. from over-threshold to comfortably clear.

Why TMPDIR is the wrong home for this

A per-repository-state index is a cache: expensive to build, cheap to discard, valuable to keep across runs. TMPDIR is for ephemeral scratch that a process creates and removes within its own lifetime, and on many systems it is deliberately small, tmpfs-backed, or managed by an external janitor that assumes anything inside is disposable right now.

Storing a long-lived cache there gets the worst of both: it is large enough to matter, persistent enough to accumulate, and sitting in the one directory whose supervisor is most likely to delete it mid-use or to start reclaiming other things when it fills.

Suggested fix

The binary already references XDG_CACHE_HOME, so the smallest change is likely to prefer it for these artifacts:

  1. $RIPWIRE_CACHE_DIR if set — an explicit escape hatch is useful for exactly the constrained-TMPDIR case;
  2. else $XDG_CACHE_HOME/ripwire;
  3. else ~/.cache/ripwire;
  4. TMPDIR only for genuinely transient intermediates.

A retention bound would help independently of location — an LRU cap on total cache bytes, or eviction of entries whose repository state is no longer reachable. Right now the only bound is how many distinct states a user happens to index.

Impact as seen from outside

The failure is indirect and therefore hard to attribute. On the host above, the scratch volume's watchdog responded to the pressure by evicting idle editor sessions — which reclaimed nothing, because the sessions were not what filled the disk. From the user's side, unrelated work disappeared overnight and the cause was several layers away from the symptom. A cache in $XDG_CACHE_HOME would not have interacted with that supervisor at all.

Happy to test a patch against the same workload if useful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions