Add detailed logging to cache_manager put and get_by_cid

Debug why recipes are not found in cache after upload.
Logs now show each step of put() and get_by_cid().

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-12 21:07:09 +00:00
parent da4e2e9d3d
commit f67aacdceb

View File

@@ -404,6 +404,7 @@ class L1CacheManager:
local_hash = file_hash(source_path) local_hash = file_hash(source_path)
# Store in local cache # Store in local cache
logger.info(f"put: Storing in cache with node_id={node_id[:16]}...")
self.cache.put( self.cache.put(
node_id=node_id, node_id=node_id,
source_path=source_path, source_path=source_path,
@@ -413,9 +414,15 @@ class L1CacheManager:
) )
entry = self.cache.get_entry(node_id) entry = self.cache.get_entry(node_id)
logger.info(f"put: After cache.put, get_entry(node_id={node_id[:16]}...) returned entry={entry is not None}, path={entry.output_path if entry else None}")
# Verify we can retrieve it
verify_path = self.cache.get(node_id)
logger.info(f"put: Verify cache.get(node_id={node_id[:16]}...) = {verify_path}")
# Update content index (CID -> node_id mapping) # Update content index (CID -> node_id mapping)
self._set_content_index(cid, node_id) self._set_content_index(cid, node_id)
logger.info(f"put: Set content index {cid[:16]}... -> {node_id[:16]}...")
# Also index by local hash if cid is an IPFS CID # Also index by local hash if cid is an IPFS CID
# This ensures both IPFS CID and local hash can be used to find the file # This ensures both IPFS CID and local hash can be used to find the file
@@ -438,27 +445,31 @@ class L1CacheManager:
def get_by_cid(self, cid: str) -> Optional[Path]: def get_by_cid(self, cid: str) -> Optional[Path]:
"""Get cached file path by cid or IPFS CID. Falls back to IPFS if not in local cache.""" """Get cached file path by cid or IPFS CID. Falls back to IPFS if not in local cache."""
logger.info(f"get_by_cid: Looking for cid={cid[:16]}...")
# Check index first (Redis then local) # Check index first (Redis then local)
node_id = self._get_content_index(cid) node_id = self._get_content_index(cid)
logger.info(f"get_by_cid: Index lookup returned node_id={node_id[:16] if node_id else None}...")
if node_id: if node_id:
path = self.cache.get(node_id) path = self.cache.get(node_id)
logger.info(f"get_by_cid: cache.get(node_id={node_id[:16]}...) returned path={path}")
if path and path.exists(): if path and path.exists():
logger.debug(f" Found via index: {path}") logger.info(f"get_by_cid: Found via index: {path}")
return path return path
# For uploads, node_id == cid, so try direct lookup # For uploads, node_id == cid, so try direct lookup
# This works even if cache index hasn't been reloaded # This works even if cache index hasn't been reloaded
path = self.cache.get(cid) path = self.cache.get(cid)
logger.debug(f" cache.get({cid[:16]}...) returned: {path}") logger.info(f"get_by_cid: Direct cache.get({cid[:16]}...) returned: {path}")
if path and path.exists(): if path and path.exists():
self._set_content_index(cid, cid) self._set_content_index(cid, cid)
return path return path
# Scan cache entries (fallback for new structure) # Scan cache entries (fallback for new structure)
entry = self.cache.find_by_cid(cid) entry = self.cache.find_by_cid(cid)
logger.info(f"get_by_cid: find_by_cid({cid[:16]}...) returned entry={entry}")
if entry and entry.output_path.exists(): if entry and entry.output_path.exists():
logger.debug(f" Found via scan: {entry.output_path}") logger.info(f"get_by_cid: Found via scan: {entry.output_path}")
self._set_content_index(cid, entry.node_id) self._set_content_index(cid, entry.node_id)
return entry.output_path return entry.output_path