◐ Off-By-One · answer catalog

bash-content-addressed-cache-race-recovery

1 answer(s)shellbash

bash-content-addressed-cache-race-recovery

📦 Source in repository (JSON)

Answer

Done. The verified solution is written to ~/cac/SOLUTION.md (self-contained; its code blocks were extracted and re-run to confirm 18/18 tests pass).

What was wrong (root causes)

Failure mode Naive bug Fix
Readers see partial objects writing directly to the final path stage in tmp/, publish with atomic rename(2)
Concurrent producers duplicate/overlapping writes per-digest mkdir producer lock
Stale locks PID-file reclaim has an ABA race serialize all lock-dir mutations with flock on a .guard file; owner = pid boot_id host starttime
Symlink / traversal digest interpolated into path strict ^[0-9a-f]{64}$ + component-by-component symlink checks; objects must be -f and ! -L
GC deletes in-use object check-then-unlink shared flock for readers/writers, exclusive -n for GC, re-check under the lock
Interrupted writes partial visible / garbage unique tmp names + grace-period GC of tmp/

Deliverables

Verification (extracted from the markdown and re-run)

== 1. concurrent producers, identical content ==    PASS x4
== 2. concurrent producers, distinct content ==     PASS x3
== 3. readers never observe a partial object ==     PASS x2  (91 reads, 0 partial)
== 4. interrupted writes leave no visible object == PASS x3
== 5. concurrent stale-lock recovery ==             PASS x3
== 6. symlink / traversal defenses ==               PASS x4
TOTAL: 18 passed, 0 failed

Notable results: 20 simultaneous producers of identical bytes materialized exactly one object; 15 producers racing to reclaim a planted stale lock all succeeded exactly once; and a 60 MB object read continuously by 4 readers across 5 concurrent publications never produced a partial read — only clean misses before publication.

One residual limit is documented: flock is host-local/advisory, so cross-host sharing relies on a single filesystem plus a conservative LOCK_TTL; the .guard protocol still prevents same-host ABA races.

Evidence & signatures

# Evidence
- Problem class: bash-content-addressed-cache-race-recovery
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-10-04T16:14:59.380Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Build a Bash command-line cache for immutable build artifacts keyed by a cryptographic digest, supporting concurrent producers, interrupted writes, and readers that must never observe partial objects. Specify and implement lock acquisition with stale-owner recovery, atomic publication, symlink/path-traversal defenses, and garbage collection that cannot delete an object in active use; test races using only common Linux utilities.", "environment": "bash", "language": "shell", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "bash-content-addressed-cache-race-recovery", "provider": "openrouter", "solved_at": "2026-10-04T16:14:59.381Z", "version": "5"}
Generated from the verified corpus · MIT licensedBack to the catalog