datawhalechina/hello-agents · error · ValueError
diet run 不存在或缺少 input
Error message
diet run 不存在或缺少 input
What it means
ValueError raised by replay_diet_run when the stored row is missing (run id unknown) OR row['input'] is not a dict — i.e. the persisted input payload needed to re-execute the pipeline is absent/malformed. The route layer converts it to HTTP 400.
Source
Thrown at Co-creation-projects/Shawnxyxy-HealthRecordAgent/backend/service/diet_recommend_service.py:33
async def run(
self,
user_id: str,
context: Dict[str, Any],
*,
replayed_from_run_id: str | None = None,
) -> Dict[str, Any]:
pipeline = DietMultiAgentPipeline()
return await pipeline.run(
user_id, context, replayed_from_run_id=replayed_from_run_id
)
async def replay_diet_run(original_run_id: str) -> Dict[str, Any]:
"""阶段 3:用历史 run 的 input 重跑流水线(新 run_id;溯源 replayed_from)。"""
row = get_diet_run(original_run_id.strip())
if not row or not isinstance(row.get("input"), dict):
raise ValueError("diet run 不存在或缺少 input")
svc = DietRecommendService()
return await svc.run(
row["user_id"],
row["input"],
replayed_from_run_id=original_run_id.strip(),
)
View on GitHub (pinned to 606a07d341)
Solutions
- Replay only runs created by the current version, which persist input as a dict.
- If rows exist with stringified input, migrate them: parse the JSON string into a dict before replay.
- Create a new run via /diet/recommend with the same context if the original input is unrecoverable.
Example fix
# before
await replay_diet_run(old_run_id) # ValueError: input column is NULL
# after
row = get_diet_run(old_run_id)
inp = row['input'] if isinstance(row.get('input'), dict) else json.loads(row['input'])
if inp is None:
raise ValueError('original input not persisted; create a new run instead') Defensive patterns
Strategy: validation
Validate before calling
row = get_diet_run(run_id.strip())
if not row or not isinstance(row.get("input"), dict):
raise ValueError("cannot replay: run missing or input not persisted") Type guard
def is_replayable_run(row) -> bool:
return (
isinstance(row, dict)
and isinstance(row.get("input"), dict)
and bool(row.get("user_id"))
) Try / catch
try:
new_run = await replay_diet_run(rid)
except ValueError as e:
# route layer maps this to HTTP 400; distinguish missing-run vs missing-input
log.warning("replay rejected: %s", e)
raise Prevention
- Persist the pipeline input as a JSON dict on every run from day one.
- Migrate legacy rows: parse stringified inputs into dicts before replay.
- Surface both failure modes (row missing, input malformed) distinctly in callers.
When it happens
Trigger: POST /diet/runs/{run_id}/replay where the run row was deleted, or where the input column is NULL/JSON string instead of a dict (runs created before input persistence was added).
Common situations: Schema drift: old runs persisted before the 'input' column existed; storage writing input as a serialized string; deletion/cleanup jobs removing runs.
Related errors
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/6f4a0c3a294d2214.
Report an issue: GitHub.