{"record":{"id":"4168ba69cf700ffd","repo":"microsoft/autogen","slug":"early-termination-only-self-num-checked-record","errorCode":null,"errorMessage":"\nEarly termination. Only {self._num_checked_records} of the {len(self.records)} recorded turns were checked.","messagePattern":"\nEarly termination\\. Only (.+?) of the (.+?) recorded turns were checked\\.","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":225,"sourceCode":"        \"\"\"\n        self.logger.enter_function()\n        if self.mode == \"record\":\n            try:\n                # Create the directory if it doesn't exist.\n                os.makedirs(os.path.dirname(self.session_file_path), exist_ok=True)\n                # Write the records to disk.\n                with open(self.session_file_path, \"w\") as f:\n                    json.dump(self.records, f, indent=2)\n                    self.logger.info(\"\\nRecorded session was saved to: \" + self.session_file_path)\n            except Exception as e:\n                error_str = f\"Failed to write records to '{self.session_file_path}': {e}\"\n                self.logger.error(error_str)\n                raise ValueError(error_str) from e\n        elif self.mode == \"replay\":\n            if self._num_checked_records < len(self.records):\n                error_str = f\"\\nEarly termination. Only {self._num_checked_records} of the {len(self.records)} recorded turns were checked.\"\n                self.logger.error(error_str)\n                raise ValueError(error_str)\n            self.logger.info(\"\\nRecorded session was fully replayed and checked.\")\n        self.logger.leave_function()\n","sourceCodeStart":207,"sourceCodeEnd":228,"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#L207-L228","documentation":"In 'replay' mode the recorder verifies that every recorded turn was consumed. If the agent session ends (close/save is called) after checking fewer records than exist in the session file, this ValueError signals the run terminated early relative to the recording.","triggerScenarios":"Calling the recorder's close/save in replay mode when _num_checked_records < len(records): the agent stopped making LLM calls sooner than the recorded run (fewer turns, early exit, exception swallowed upstream, truncated task list).","commonSituations":"Agent logic changed to finish in fewer turns; a task loop was shortened; an upstream exception ended the run before completion; test finished after the first assertion instead of the full scenario.","solutions":["Compare the number of checked turns vs total recorded turns in the message to see where the run stopped.","If the run legitimately ends earlier now, re-record the session so the recording matches the new turn count.","If the run should have continued, look for swallowed exceptions or early-return paths in agent code that ended the conversation prematurely.","Ensure the test executes the full scenario (all user turns / tasks) that was captured."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# before closing, confirm the scenario consumed the full recording\nexpected_turns = len(recorder.records)\nassert recorder._num_checked_records == expected_turns, (\n    f\"scenario finished early: {recorder._num_checked_records}/{expected_turns} turns\"\n)","typeGuard":null,"tryCatchPattern":"try:\n    await run_scenario()\n    await recorder.close()\nexcept ValueError as e:\n    if \"Early termination\" in str(e):\n        # run stopped before the recorded end; find the swallowed exception or re-record\n        ...\n    else:\n        raise","preventionTips":["Run the full scenario (all user turns) that the recording captured.","Don't wrap agent turns in broad except blocks that swallow errors and end the loop early.","Re-record after changing turn counts."],"tags":["autogen","replay","testing","session-lifecycle"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}