crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG]Restoring a SQLite checkpoint fails when a parent directory contains #

Open subhashpolisetti opened this issue 1 month ago • 3 comments

Description

Crew.from_checkpoint (and RuntimeState.from_checkpoint / afrom_checkpoint) raises FileNotFoundError for a SQLite checkpoint whose database sits under a directory with # in its name, for example runs/exp#1/cp.db. Writing the checkpoint works; only restoring it fails.

SQLite checkpoint locations have the form db_path#checkpoint_id. SqliteProvider.extract_id, from_checkpoint and afrom_checkpoint, and the crewai checkpoint CLI all split that on the last #, but detect_provider splits on the first one. With runs/exp#1/cp.db#<id> it checks runs/exp for the SQLite header, doesn't find it, falls back to JsonProvider, and the JSON provider then tries to open the whole location as a file.

Steps to Reproduce

  1. Configure a crew with CheckpointConfig(location="<dir>/run#1/cp.db", provider=SqliteProvider()).
  2. Run crew.kickoff() so a checkpoint is written.
  3. Restore it with Crew.from_checkpoint(CheckpointConfig(restore_from="<dir>/run#1/cp.db#<checkpoint_id>")).

Expected behavior

The checkpoint restores, the same as when the directory name has no #.

Screenshots/Code snippets

import os
import sqlite3
import tempfile
from typing import Any

from crewai import Agent, Crew, Task
from crewai.llms.base_llm import BaseLLM
from crewai.state.checkpoint_config import CheckpointConfig
from crewai.state.provider.sqlite_provider import SqliteProvider


class FinalLLM(BaseLLM):
    def __init__(self) -> None:
        super().__init__(model="offline")

    def supports_function_calling(self) -> bool:
        return False

    def call(self, messages: Any, **kwargs: Any) -> str:
        return "Thought: done\nFinal Answer: ok"

    async def acall(self, messages: Any, **kwargs: Any) -> str:
        return self.call(messages, **kwargs)


db = os.path.join(tempfile.mkdtemp(), "run#1", "cp.db")
os.makedirs(os.path.dirname(db))
agent = Agent(role="Writer", goal="w", backstory="b", llm=FinalLLM())
crew = Crew(
    agents=[agent],
    tasks=[Task(description="Say ok", expected_output="ok", agent=agent)],
    checkpoint=CheckpointConfig(location=db, provider=SqliteProvider()),
)
crew.kickoff()

with sqlite3.connect(db) as conn:
    checkpoint_id = conn.execute(
        "SELECT id FROM checkpoints ORDER BY rowid DESC LIMIT 1"
    ).fetchone()[0]
Crew.from_checkpoint(CheckpointConfig(restore_from=f"{db}#{checkpoint_id}"))

Operating System

macOS Monterey

Python Version

3.12

crewAI Version

1.15.28 (main @ 570e26ac4)

crewAI Tools Version

N/A (not used in the repro)

Virtual Environment

Venv

Evidence

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.../run#1/cp.db#20261022T182336_ba2a4bcc'

The same script with the directory named run1 restores without error.

Possible Solution

Split on the last # in detect_provider (path.rsplit("#", 1)[0]), the same way SqliteProvider and the checkpoint CLI already parse the location.

Additional context

macOS 26. Reproduced on Python 3.13 with a uv-managed venv (3.13 is not in the version dropdown). Related in spirit to #8268 (checkpoint paths with glob characters).

subhashpolisetti avatar Oct 23 '26 06:10 subhashpolisetti

PR #8576 fixes this. detect_provider was the only consumer of the db_path#checkpoint_id location format splitting on the first #; SqliteProvider.extract_id, from_checkpoint, afrom_checkpoint and the crewai checkpoint CLI all split on the last. With a directory containing # (e.g. runs/exp#1/cp.db) it probed a truncated path, missed the SQLite header, and silently fell back to JsonProvider, whose restore then failed with FileNotFoundError.

Test added in lib/crewai/tests/test_state_provider_utils.py.

HhH666-ux avatar Oct 28 '26 03:10 HhH666-ux

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 27 '26 12:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Dec 02 '26 12:12 github-actions[bot]