microsoft/autogen · error · ValueError

Early termination. Only {self._num_checked_records} of the

Error message

Early termination. Only {self._num_checked_records} of the {len(self.records)} recorded turns were checked.

What it means

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.

Source

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

        """
        self.logger.enter_function()
        if self.mode == "record":
            try:
                # Create the directory if it doesn't exist.
                os.makedirs(os.path.dirname(self.session_file_path), exist_ok=True)
                # Write the records to disk.
                with open(self.session_file_path, "w") as f:
                    json.dump(self.records, f, indent=2)
                    self.logger.info("\nRecorded session was saved to: " + self.session_file_path)
            except Exception as e:
                error_str = f"Failed to write records to '{self.session_file_path}': {e}"
                self.logger.error(error_str)
                raise ValueError(error_str) from e
        elif self.mode == "replay":
            if self._num_checked_records < len(self.records):
                error_str = f"\nEarly termination. Only {self._num_checked_records} of the {len(self.records)} recorded turns were checked."
                self.logger.error(error_str)
                raise ValueError(error_str)
            self.logger.info("\nRecorded session was fully replayed and checked.")
        self.logger.leave_function()

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Compare the number of checked turns vs total recorded turns in the message to see where the run stopped.
  2. If the run legitimately ends earlier now, re-record the session so the recording matches the new turn count.
  3. If the run should have continued, look for swallowed exceptions or early-return paths in agent code that ended the conversation prematurely.
  4. Ensure the test executes the full scenario (all user turns / tasks) that was captured.
Defensive patterns

Strategy: validation

Validate before calling

# before closing, confirm the scenario consumed the full recording
expected_turns = len(recorder.records)
assert recorder._num_checked_records == expected_turns, (
    f"scenario finished early: {recorder._num_checked_records}/{expected_turns} turns"
)

Try / catch

try:
    await run_scenario()
    await recorder.close()
except ValueError as e:
    if "Early termination" in str(e):
        # run stopped before the recorded end; find the swallowed exception or re-record
        ...
    else:
        raise

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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