Canonical: https://www.startearly.ai/case-files/pydantic-ai/saved-repl-state-finding-to-fix/
Updated: 2026-11-14

# Pydantic AI Saved-State Bug: Early Finding and Fix PR

**Category:** Reliability and error handling

Early identified a saved-state bug in Pydantic AI, then generated a repair and test after user initiation. Follow the product flow into draft Fix PR #3.

## Failed load still overwrites saved REPL

**Early investigation priority:** P2

**Before:** A conversation already has valid saved variables, imports, and functions.

**After:** If loading fails but saving succeeds, the fresh REPL state can overwrite that saved conversation.

## Repair

**Status:** pr-opened

**Verification:** compile-only

**Verification Summary:** The fork PR reports a passing Python compilation check. Upstream automation reports reproducing the original state-loss failure, not verifying this repair. Behavioral tests for the proposed fix have not yet been executed. The explicit restart exception still needs dedicated test coverage. GitHub currently reports no CI checks for this proposal.

### Fix Pull Request

[Early-generated Fix PR #3](https://github.com/earlyai/pydantic-ai-pre-release/pull/3)

**PR number:** 3

### Commit

[Proposed fix ced2bfd](https://github.com/earlyai/pydantic-ai-pre-release/commit/ced2bfd25086a47e0e41ccf6e62baa0d176b2f79)

**Files:** 4

**Insertions:** 41

**Deletions:** 11

**Test added:** Yes

**Compile Command:** python3 -m py_compile src/pydantic_ai_harness/pydantic_ai_harness/code_mode/_repl_store.py tests/harness/code_mode/test_repl_store.py

**GitHub CI:** No checks reported

## Workflow

A temporary read failure could erase an agent's saved state. Early found the bug and created a Fix PR after user confirmation.

**Problem:** When loading failed, the agent continued with a fresh session. Saving it could overwrite the conversation's valid state.

**Repair:** The proposed change skips saving after a failed load, except after an explicit restart. It adds a state-preservation test and updates the documentation.

### Find the bug

The user inspects the finding and its evidence, then initiates the fix workflow.

### Create the Fix PR

The user confirms the repository and target branch. Early receives the authorized request to create the Fix PR.

### Review the draft PR

Early opens draft PR #3 with the proposed code change, test, and repair explanation. Engineering controls the merge.

### Review and merge the PR

Engineering reviews the proposed code and tests, then merges the approved fix. This illustrates the next step, not this case's current outcome: PR #3 is still a draft.

## Pending Evidence

- Executed behavioral test and corrected-run output for the proposed fix, pinned to the actual revisions and environment. Upstream automation reports reproducing the original failure, not verifying the repair.

- Dedicated coverage for the explicit restart exception.

- Human review and any amendments, acceptance, or upstream merge.

## Public Report

[Upstream issue #10693](https://github.com/pydantic/pydantic-ai/issues/10693)

**Disclosure:** Prepared by Early Technologies using its own open-source analysis and fork. Pydantic AI is not presented as an Early customer or endorser.

## Source and next step

[Read the canonical page and its evidence](https://www.startearly.ai/case-files/pydantic-ai/saved-repl-state-finding-to-fix/).
