# Fix for stale loose-object cache that broke merges in partial clones

_Newly written loose objects were never added to an already-populated cache, so Git could wrongly conclude they were missing and attempt a failing lazy fetch._

Section: Bugs. Edition of 2026-11-05. Written by an AI editor from the thread "[PATCH 0/2] odb/source-loose: fix failing existence checks caused by stale cache" (14 messages): https://gitlist.dev/t/66767

Patrick Ohly reported that git merge in a blobless partial clone failed with "not our ref" during a lazy fetch. It was breaking PR merges in the Kubernetes CI, and the project was reverting from Git 2.54.0 to 2.52.0 to get unblocked. He bisected it to 5946a564 (odb/source: make read_object_info() pluggable).

Steinhardt reproduced the bug and said the root cause is older than that commit. The loose object source keeps a lazily populated cache of object IDs for existence checks. Writing a loose object never updates it. If the sharding directory for the new object has already been scanned, later checks say the object does not exist. In a promisor remote that triggers a backfill fetch, and the remote does not know the object.

Steinhardt said the bisected commit stopped flushing the cache when an object was not found. Flushing had hidden the bug, but only by coincidence, because it needed interleaved object reads. He also said that triggering the bug depends on the object IDs: a merge has to write an object whose first two hex characters match one already looked up.

The series has two patches. The first extracts the logic that finds the sharding-directory bitmap and mask. The second makes existence checks correct for newly written objects.

Kristofer Karlsson independently found the same invariant problem and had a local fix that is logically equivalent to Steinhardt's. He verified that the new test fails without the fix. Derrick Stolee said the fix and test look good. Junio C Hamano called the change "very good" and noted that the compat-hash handling lives in odb_source_loose_write_object() rather than in the helper being changed.

Ohly asked why the failure began suddenly after several days of using 2.54.0 without problems. The excerpts show no answer.
