Add debug logging for plan loading
This commit is contained in:
18
server.py
18
server.py
@@ -1339,37 +1339,49 @@ def load_plan_for_run(run: RunStatus) -> Optional[dict]:
|
||||
"""Load plan data for a run, trying plan_id first, then matching by inputs."""
|
||||
PLAN_CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
logger.info(f"[load_plan] run_id={run.run_id[:16]}, plan_id={run.plan_id}, inputs={run.inputs}")
|
||||
logger.info(f"[load_plan] PLAN_CACHE_DIR={PLAN_CACHE_DIR}")
|
||||
|
||||
# First try by plan_id if available
|
||||
if run.plan_id:
|
||||
plan_file = PLAN_CACHE_DIR / f"{run.plan_id}.json"
|
||||
logger.info(f"[load_plan] Trying plan_id file: {plan_file}, exists={plan_file.exists()}")
|
||||
if plan_file.exists():
|
||||
try:
|
||||
with open(plan_file) as f:
|
||||
return json.load(f)
|
||||
except (json.JSONDecodeError, IOError):
|
||||
pass
|
||||
except (json.JSONDecodeError, IOError) as e:
|
||||
logger.warning(f"[load_plan] Failed to load plan file: {e}")
|
||||
|
||||
# List available plan files
|
||||
plan_files = list(PLAN_CACHE_DIR.glob("*.json"))
|
||||
logger.info(f"[load_plan] Available plan files: {len(plan_files)}")
|
||||
|
||||
# Fall back to matching by inputs
|
||||
for plan_file in PLAN_CACHE_DIR.glob("*.json"):
|
||||
for plan_file in plan_files:
|
||||
try:
|
||||
with open(plan_file) as f:
|
||||
data = json.load(f)
|
||||
plan_inputs = data.get("input_hashes", {})
|
||||
if run.inputs and set(plan_inputs.values()) == set(run.inputs):
|
||||
logger.info(f"[load_plan] Found matching plan by inputs: {plan_file}")
|
||||
return data
|
||||
except (json.JSONDecodeError, IOError):
|
||||
continue
|
||||
|
||||
# Try to load from plan_json in step_results (for IPFS_PRIMARY mode)
|
||||
if run.step_results:
|
||||
logger.info(f"[load_plan] Checking step_results for embedded plan, keys={list(run.step_results.keys())[:5]}")
|
||||
# Check if there's embedded plan data
|
||||
for step_id, result in run.step_results.items():
|
||||
if isinstance(result, dict) and "plan_json" in result:
|
||||
logger.info(f"[load_plan] Found embedded plan_json in step {step_id}")
|
||||
try:
|
||||
return json.loads(result["plan_json"])
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
pass
|
||||
|
||||
logger.warning(f"[load_plan] No plan found for run {run.run_id[:16]}")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user