Fix asset_type detection when recording runs from L1

Fetch media_type and ipfs_cid from L1's cache endpoint instead of
hardcoding asset_type to "video". This fixes images being incorrectly
displayed as videos.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-09 00:22:58 +00:00
parent 287ba0d6b1
commit a7dfdc8a39

View File

@@ -1731,6 +1731,22 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us
if not output_hash:
raise HTTPException(400, "Run has no output hash")
# Fetch media type from L1 cache
try:
cache_resp = requests.get(
f"{l1_url}/cache/{output_hash}",
headers={"Accept": "application/json"},
timeout=10
)
cache_resp.raise_for_status()
cache_info = cache_resp.json()
media_type = cache_info.get("media_type", "image")
ipfs_cid = cache_info.get("ipfs_cid")
except Exception as e:
logger.warning(f"Failed to fetch cache info from L1: {e}")
media_type = "image" # Default fallback
ipfs_cid = None
# Build provenance from run
provenance = {
"inputs": [{"content_hash": h} for h in run.get("inputs", [])],
@@ -1747,7 +1763,8 @@ async def record_run(req: RecordRunRequest, user: User = Depends(get_required_us
return await _register_asset_impl(RegisterRequest(
name=req.output_name,
content_hash=output_hash,
asset_type="video", # Could be smarter about this
ipfs_cid=ipfs_cid,
asset_type=media_type, # Detected from L1 cache
tags=["rendered", "l1"],
metadata={"l1_server": l1_url, "l1_run_id": req.run_id},
provenance=provenance