From faf794ef35adeaa4ab613528dc5c32ed15cf4698 Mon Sep 17 00:00:00 2001 From: gilesb Date: Mon, 12 Jan 2026 21:20:28 +0000 Subject: [PATCH] Use IPFS as universal fallback for content lookup When content isn't found in local cache, fetch directly from IPFS using the CID. IPFS is the source of truth for all content-addressed data. Co-Authored-By: Claude Opus 4.5 --- cache_manager.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/cache_manager.py b/cache_manager.py index d67de47..5b82c0a 100644 --- a/cache_manager.py +++ b/cache_manager.py @@ -496,13 +496,27 @@ class L1CacheManager: if legacy_path.exists() and legacy_path.is_file(): return legacy_path - # Try to recover from IPFS if we have a CID - ipfs_cid = self._get_ipfs_cid_from_index(cid) - if ipfs_cid: - logger.info(f"Recovering from IPFS: {cid[:16]}... ({ipfs_cid})") + # Fetch from IPFS - this is the source of truth for all content + if self._is_ipfs_cid(cid): + logger.info(f"get_by_cid: Fetching from IPFS: {cid[:16]}...") recovery_path = self.legacy_dir / cid - if ipfs_client.get_file(ipfs_cid, recovery_path): - logger.info(f"Recovered from IPFS: {recovery_path}") + recovery_path.parent.mkdir(parents=True, exist_ok=True) + if ipfs_client.get_file(cid, str(recovery_path)): + logger.info(f"get_by_cid: Fetched from IPFS: {recovery_path}") + self._set_content_index(cid, cid) + return recovery_path + else: + logger.warning(f"get_by_cid: IPFS fetch failed for {cid[:16]}...") + + # Also try with a mapped IPFS CID if different from cid + ipfs_cid = self._get_ipfs_cid_from_index(cid) + if ipfs_cid and ipfs_cid != cid: + logger.info(f"get_by_cid: Fetching from IPFS via mapping: {ipfs_cid[:16]}...") + recovery_path = self.legacy_dir / cid + recovery_path.parent.mkdir(parents=True, exist_ok=True) + if ipfs_client.get_file(ipfs_cid, str(recovery_path)): + logger.info(f"get_by_cid: Fetched from IPFS: {recovery_path}") + return recovery_path return recovery_path return None