microsoft/autogen · error · ValueError

Failed to load recorded session: '{self.session_file_path}':

Error message

Failed to load recorded session: '{self.session_file_path}': {e}

What it means

Raised by ChatCompletionClientRecorder in 'replay' mode when the JSON session file at session_file_path cannot be loaded (missing, invalid JSON, permission denied). The recorder replays recorded LLM calls for deterministic tests, so an unreadable session file aborts initialization with ValueError chaining the original exception.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/experimental/task_centric_memory/utils/chat_completion_client_recorder.py:81

        self.base_client = client
        self.mode = mode
        self.session_file_path = os.path.expanduser(session_file_path)
        self.records: List[RecordDict] = []
        self._record_index = 0
        self._num_checked_records = 0
        if self.mode == "record":
            # Prepare to record the messages and responses.
            self.logger.info("Recording mode enabled.\nRecording session to: " + self.session_file_path)
        elif self.mode == "replay":
            # Load the previously recorded messages and responses from disk.
            self.logger.info("Replay mode enabled.\nRetrieving session from: " + self.session_file_path)
            try:
                with open(self.session_file_path, "r") as f:
                    self.records = json.load(f)
            except Exception as e:
                error_str = f"\nFailed to load recorded session: '{self.session_file_path}': {e}"
                self.logger.error(error_str)
                raise ValueError(error_str) from e

        self.logger.leave_function()

    async def create(
        self,
        messages: Sequence[LLMMessage],
        *,
        tools: Sequence[Tool | ToolSchema] = [],
        json_output: Optional[bool | type[BaseModel]] = None,
        extra_create_args: Mapping[str, Any] = {},
        cancellation_token: Optional[CancellationToken] = None,
        tool_choice: Tool | Literal["auto", "required", "none"] = "auto",
    ) -> CreateResult:
        current_messages: List[Mapping[str, Any]] = [msg.model_dump() for msg in messages]
        if self.mode == "record":
            response = await self.base_client.create(
                messages,
                tools=tools,

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Verify the path exists and matches the path logged at record time ('Retrieving session from: ...').
  2. Re-run the recording session to regenerate a valid JSON file if it is corrupted or truncated.
  3. If the file lives elsewhere, pass the correct session_file_path for replay mode.
  4. Ensure CI includes the recorded session file in the repo or artifacts.

Example fix

# before
client = ChatCompletionClientRecorder(inner_client, mode="replay", session_file_path="sessions/run1.json")
# ValueError: Failed to load recorded session ... FileNotFoundError

# after
from pathlib import Path
path = Path("sessions/run1.json")
assert path.is_file(), f"missing recorded session: {path}"
client = ChatCompletionClientRecorder(inner_client, mode="replay", session_file_path=str(path))
Defensive patterns

Strategy: validation

Validate before calling

import json
from pathlib import Path

def session_loadable(path: str) -> bool:
    p = Path(path)
    if not p.is_file():
        return False
    try:
        json.loads(p.read_text())
        return True
    except json.JSONDecodeError:
        return False

Try / catch

try:
    recorder = ChatCompletionClientRecorder(client, mode="replay", session_file_path=p)
except ValueError as e:
    if "Failed to load recorded session" in str(e):
        raise SystemExit(f"Missing/corrupt session file {p} - re-record with mode='record'") from e
    raise

Prevention

When it happens

Trigger: Creating the recorder wrapper with mode='replay' when session_file_path does not exist, points to a truncated/corrupted JSON file, or is unreadable; the file was moved or renamed between record and replay runs.

Common situations: Replay path configured differently from the record path, partially written files after a crashed record session, JSON broken by hand-editing, cross-platform path differences, session file not checked into the repo for CI replay tests.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/f3ed0b780484b08b. Report an issue: GitHub.