Repository navigation
Description
Description
A flow method returns a Pydantic model, and its listener reads the model's attributes. The listener fails, and the flow is restored from its latest checkpoint and kicked off again.
The resumed run calls the listener again, but now with a plain dict instead of the model, so the listener's attribute access raises AttributeError and the run that was resumed to recover from a failure fails again, this time permanently. In the first run the listener received the model.
The same happens to every listener of a @human_feedback method: in the first run it receives a HumanFeedbackResult, after a restore a dict, so result.feedback raises AttributeError: 'dict' object has no attribute 'feedback'. The human's answer is lost to the code that was written to handle it.
Steps to Reproduce
- Define
price -> charge, wherepricereturnsQuote(amount=42)andcharge(quote)usesquote.amountand fails once. - Run it with
checkpoint=CheckpointConfig(location=..., on_events=["method_execution_finished"]). - Restore the latest checkpoint with
OrderFlow.from_checkpoint(CheckpointConfig(restore_from=...))and callkickoff().
Expected behavior
The resumed run calls charge with the same Quote as the first run, and the state is {'charged': 42}.
Screenshots/Code snippets
import glob
import os
import tempfile
from importlib.metadata import version
from pydantic import BaseModel
from crewai import CheckpointConfig
from crewai.flow.flow import Flow, listen, start
failures = [1]
class Quote(BaseModel):
amount: int
class OrderFlow(Flow):
@start()
def price(self):
return Quote(amount=42)
@listen(price)
def charge(self, quote):
print("charge received", type(quote).__name__)
if failures[0]:
failures[0] -= 1
raise RuntimeError("charge failed")
self.state["charged"] = quote.amount
location = tempfile.mkdtemp()
try:
OrderFlow(checkpoint=CheckpointConfig(location=location, on_events=["method_execution_finished"])).kickoff()
except RuntimeError as exc:
print("first run:", exc)
latest = max(glob.glob(f"{location}/**/*.json", recursive=True), key=os.path.getmtime)
try:
restored = OrderFlow.from_checkpoint(CheckpointConfig(restore_from=latest))
restored.kickoff()
print("resumed: charged =", restored.state.get("charged"))
except Exception as exc:
print("resume failed:", type(exc).__name__, exc)
print("crewai", version("crewai"))Operating System
Ubuntu 22.04
Python Version
3.12
crewAI Version
1.15.34
crewAI Tools Version
not installed
Virtual Environment
Venv
Evidence
charge received Quote
first run: charge failed
charge received dict
resume failed: AttributeError 'dict' object has no attribute 'amount'
crewai 1.15.34
The same on 1.15.28, on macOS and Ubuntu 22.04.
Possible Solution
The checkpoint stores each completed method's output as JSON (checkpoint_method_outputs), and _restore_from_checkpoint puts these JSON values back into _method_outputs as they are. When the resumed run reaches the completed start method, _execute_start_method does not run it again but calls its listeners with self.method_outputs[-1], which is now the JSON form of the output, not the object the method returned. Nothing records the output's type, so nothing can rebuild it.
Recording the type of a structured output beside its JSON in the checkpoint, and rebuilding it on restore (model_validate for a Pydantic model, the constructor for a dataclass), would hand listeners the same object as in the first run. HumanFeedbackResult is a dataclass, so rebuilding it from its fields restores .feedback, .output and .outcome for the listeners of @human_feedback methods.
Additional context
With @human_feedback, the listener of the reviewed method breaks the same way:
class ReviewFlow(Flow):
@start()
@human_feedback(message="Approve?", provider=Answer()) # Answer().request_feedback returns "approved"
def ask(self):
return "draft"
@listen(ask)
def record(self, result):
print("record received", type(result).__name__)
self.state["feedback"] = result.feedback # fails once, then the flow is restored from its checkpointrecord received HumanFeedbackResult
first run: record failed
record received dict
resume failed: AttributeError 'dict' object has no attribute 'feedback'
This is independent of the fixes in #8446, #8447, #8448, #8461, #8625, #8693 and #8750: with all of them applied the result is the same.
Activity
Kekdeng commentedon Nov 3, 2026
I'd like to work on this. Initial trace:
Flow._restore_from_checkpointrebuilds_method_outputsfrom the checkpoint's JSON-serializedcheckpoint_method_outputs, so a method that returned a Pydantic model comes back as a plain dict, and the resumed listener then receives that dict instead of the original model — which is also what breaks@human_feedbacklisteners expectingHumanFeedbackResult. I plan to revalidate restored outputs into their recorded types before they reach listeners, with regression tests covering both the attribute-access failure and the@human_feedbackcase.This looks related to #8980 (listener inputs on resume); I'll confirm whether one fix covers both once I can reproduce. I checked that no open PR references this issue. (Heads-up: this work is AI-assisted, so the PR will carry the
llm-generatedlabel.)Bmohmand commentedon Nov 10, 2026
Hi! I'd like to pick this up, since #8987 was closed without being merged. I plan to keep it narrow and fix only this issue, leaving #8980 (listeners of completed methods getting None) for a separate PR.
Plan: when writing a checkpoint, record the type of each Pydantic model or dataclass method output. On restore, rebuild that output with model_validate (or TypeAdapter for dataclasses), but only from modules that are already loaded, so a checkpoint can't make the process import arbitrary modules. If the type can't be resolved or validation fails, it logs a warning and keeps the plain dict, the same as today. Regression tests will cover the Quote repro and the @human_feedback → HumanFeedbackResult.feedback case.
Luckyou-d commentedon Nov 18, 2026
Confirmed on
main(435262c) with a realCheckpointConfig(location=..., on_events=["method_execution_finished"])run:price()returnsQuote(amount=42),chargefails once, and the restored run callschargewith{'amount': 42}->AttributeError: 'dict' object has no attribute 'amount', so the recovery run fails too. The checkpoint file itself stores{"method": "price", "output": {"amount": 42}}.Fix: re-validate each restored output against the method's annotated return type (resolved on the wrapped function, since
StartMethod/ListenMethodcarry their own generic annotations). Applied to both the checkpoint andfrom_pendingpaths; outputs that don't fit are kept as restored. PR incoming with a regression test that fails onmain.Please assign Harvey DU (@Luckyou-d) if available.