Save plan_cid to database immediately after plan creation

- Add plan_cid column to pending_runs table schema
- Add update_pending_run_plan() function to save plan_cid
- Update get_pending_run() to return plan_cid
- Save plan_cid right after storing plan to IPFS (before execution)
- Plan is now available even if run fails

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gilesb
2026-01-13 04:13:10 +00:00
parent 7813eb081a
commit 2c3f943e5a
2 changed files with 31 additions and 1 deletions

View File

@@ -649,6 +649,24 @@ def execute_recipe(self, recipe_sexp: str, input_hashes: Dict[str, str], run_id:
plan_path = CACHE_DIR / plan_cid
CACHE_DIR.mkdir(parents=True, exist_ok=True)
plan_path.write_text(plan_sexp)
# Save plan_cid to database immediately so it's available even if run fails
if run_id:
import asyncio
import database
async def save_plan_cid():
if database.pool is None:
await database.init_db()
await database.update_pending_run_plan(run_id, plan_cid)
try:
loop = asyncio.get_event_loop()
if loop.is_running():
asyncio.ensure_future(save_plan_cid())
else:
loop.run_until_complete(save_plan_cid())
except RuntimeError:
asyncio.run(save_plan_cid())
logger.info(f"Saved plan_cid to pending run: {run_id}")
except Exception as e:
logger.warning(f"Failed to store plan to IPFS: {e}")