{"record":{"id":"f3ed0b780484b08b","repo":"microsoft/autogen","slug":"failed-to-load-recorded-session-self-session-fi","errorCode":null,"errorMessage":"Failed to load recorded session: '{self.session_file_path}': {e}","messagePattern":"Failed to load recorded session: '(.+?)': (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/experimental/task_centric_memory/utils/chat_completion_client_recorder.py","lineNumber":81,"sourceCode":"        self.base_client = client\n        self.mode = mode\n        self.session_file_path = os.path.expanduser(session_file_path)\n        self.records: List[RecordDict] = []\n        self._record_index = 0\n        self._num_checked_records = 0\n        if self.mode == \"record\":\n            # Prepare to record the messages and responses.\n            self.logger.info(\"Recording mode enabled.\\nRecording session to: \" + self.session_file_path)\n        elif self.mode == \"replay\":\n            # Load the previously recorded messages and responses from disk.\n            self.logger.info(\"Replay mode enabled.\\nRetrieving session from: \" + self.session_file_path)\n            try:\n                with open(self.session_file_path, \"r\") as f:\n                    self.records = json.load(f)\n            except Exception as e:\n                error_str = f\"\\nFailed to load recorded session: '{self.session_file_path}': {e}\"\n                self.logger.error(error_str)\n                raise ValueError(error_str) from e\n\n        self.logger.leave_function()\n\n    async def create(\n        self,\n        messages: Sequence[LLMMessage],\n        *,\n        tools: Sequence[Tool | ToolSchema] = [],\n        json_output: Optional[bool | type[BaseModel]] = None,\n        extra_create_args: Mapping[str, Any] = {},\n        cancellation_token: Optional[CancellationToken] = None,\n        tool_choice: Tool | Literal[\"auto\", \"required\", \"none\"] = \"auto\",\n    ) -> CreateResult:\n        current_messages: List[Mapping[str, Any]] = [msg.model_dump() for msg in messages]\n        if self.mode == \"record\":\n            response = await self.base_client.create(\n                messages,\n                tools=tools,","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/experimental/task_centric_memory/utils/chat_completion_client_recorder.py#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the path exists and matches the path logged at record time ('Retrieving session from: ...').","Re-run the recording session to regenerate a valid JSON file if it is corrupted or truncated.","If the file lives elsewhere, pass the correct session_file_path for replay mode.","Ensure CI includes the recorded session file in the repo or artifacts."],"exampleFix":"# before\nclient = ChatCompletionClientRecorder(inner_client, mode=\"replay\", session_file_path=\"sessions/run1.json\")\n# ValueError: Failed to load recorded session ... FileNotFoundError\n\n# after\nfrom pathlib import Path\npath = Path(\"sessions/run1.json\")\nassert path.is_file(), f\"missing recorded session: {path}\"\nclient = ChatCompletionClientRecorder(inner_client, mode=\"replay\", session_file_path=str(path))","handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\ndef session_loadable(path: str) -> bool:\n    p = Path(path)\n    if not p.is_file():\n        return False\n    try:\n        json.loads(p.read_text())\n        return True\n    except json.JSONDecodeError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    recorder = ChatCompletionClientRecorder(client, mode=\"replay\", session_file_path=p)\nexcept ValueError as e:\n    if \"Failed to load recorded session\" in str(e):\n        raise SystemExit(f\"Missing/corrupt session file {p} - re-record with mode='record'\") from e\n    raise","preventionTips":["Commit recorded session files used by replay tests.","Validate the JSON parses before entering replay mode.","Regenerate recordings after changing prompts or flows."],"tags":["replay","testing","files","json"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}