crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] SqliteProvider checkpoint writes fail on SQLite < 3.45 (no such function: jsonb)

Open AP24110011695 opened this issue 1 month ago • 1 comments

Description

SqliteProvider (the SQLite checkpoint backend, introduced in #5308) writes checkpoint data with SQLite's jsonb() function:

https://github.com/crewAIInc/crewAI/blob/97bbfb614a4ed0cf7e3f0ac8761f0d97b19c6ce7/lib/crewai/src/crewai/state/provider/sqlite_provider.py#L20-L25

_INSERT = (
    "INSERT INTO checkpoints (id, created_at, parent_id, branch, data) "
    "VALUES (?, ?, ?, ?, jsonb(?))"
)

jsonb() exists only in SQLite >= 3.45.0 (released 2024-01-15, see the official release notes). Nothing in the project declares that requirement, so on any Python whose bundled/system SQLite is older, every checkpoint write fails with:

sqlite3.OperationalError: no such function: jsonb

This affects common system Pythons, for example:

Platform Python Bundled/system SQLite Result
Ubuntu 22.04 LTS (python3) 3.10 3.37.2 broken
Debian 12 (bookworm) 3.11 3.40.1 broken
RHEL 9 3.11 3.34.6 broken
macOS /usr/bin/python3 (Sonoma/Sequoia) 3.9.x 3.39–3.43 broken
Windows python.org installer 3.12/3.13 >= 3.45 works

The failure surfaces when SqliteProvider checkpointing is enabled and a checkpoint event fires (e.g. CheckpointConfig(provider=SqliteProvider(), ...) on a Crew/Flow/Agent). With the auto-checkpoint listener it is logged as Auto-checkpoint failed ... and the run continues without working checkpoints; with explicit state.checkpoint() calls the OperationalError propagates. The same error hits the crewai checkpoint CLI whenever it writes.

Steps to Reproduce

  1. On a machine where Python's SQLite is older than 3.45.0 (verify with python -c "import sqlite3; print(sqlite3.sqlite_version)" — e.g. Debian 12 reports 3.40.1), install crewAI.
  2. Enable SQLite checkpointing and run anything that triggers a checkpoint:
from crewai import Crew, Agent, Task
from crewai.state.checkpoint_config import CheckpointConfig
from crewai.state.provider.sqlite_provider import SqliteProvider

crew = Crew(
    agents=[Agent(role="a", goal="g", backstory="b")],
    tasks=[Task(description="d", expected_output="e")],
    checkpoint=CheckpointConfig(
        provider=SqliteProvider(),
        location="./checkpoints.db",
    ),
)
crew.kickoff()
  1. Observe every checkpoint write fail with sqlite3.OperationalError: no such function: jsonb.

Equivalent minimal repro on any SQLite < 3.45 (no crewAI needed):

import sqlite3
print(sqlite3.sqlite_version)          # e.g. 3.40.1
conn = sqlite3.connect(":memory:")
conn.execute("SELECT jsonb('{}')")     # sqlite3.OperationalError: no such function: jsonb

On SQLite >= 3.45.0 (e.g. the Windows python.org builds) the same statements succeed, which is why CI does not catch this.

Expected behavior

The SQLite checkpoint provider should work on the SQLite versions shipped with the Pythons crewAI supports (>=3.10), not only on SQLite >= 3.45.

Screenshots/Code snippets

The two statements involved (lib/crewai/src/crewai/state/provider/sqlite_provider.py):

_INSERT = (
    "INSERT INTO checkpoints (id, created_at, parent_id, branch, data) "
    "VALUES (?, ?, ?, ?, jsonb(?))"     # requires SQLite >= 3.45.0
)
_SELECT = "SELECT json(data) FROM checkpoints WHERE id = ?"   # fine: built-in since 3.38.0 (JSON1 compiled in long before that on distro builds)

jsonb() was added in SQLite 3.45.0 (2024-01-15); JSON1 functions (json()) are built in since 3.38.0 and were already compiled into distro builds well before that. Sources: SQLite JSON functions doc, release history.

Possible Solution

Stop using jsonb() when writing and store the JSON string as plain text:

  • _INSERT: "VALUES (?, ?, ?, ?, ?)" (bind data directly — SQLite stores TEXT).
  • Keep _SELECT as SELECT json(data) FROM checkpoints WHERE id = ? so rows written by the old jsonb() path (binary JSONB blobs in existing checkpoint databases) remain readable after the upgrade.
  • Optionally declare the column as data TEXT NOT NULL instead of JSONB for new databases (column type is cosmetic in SQLite, but it avoids implying a JSONB requirement).

This restores compatibility down to SQLite ~3.34–3.38 (distro JSON1 builds) while keeping read compatibility with checkpoint databases written by the current implementation. Happy to open a PR with the change plus a regression test asserting checkpoint rows are stored as typeof(data) = 'text' and that legacy JSONB blob rows stay readable.

Additional context

  • OS: Windows 11 (analysis environment); affected systems are the Linux/macOS system Pythons listed above.
  • Python: 3.12; crewAI version: current main (97bbfb61), issue present since #5308 (merged 2026-04-07).
  • This report and the accompanying fix/tests were prepared with an AI coding assistant, so per CONTRIBUTING.md the PR should carry the llm-generated label (I can't set labels from my account — could a maintainer add it, and bug?).

AP24110011695 avatar Oct 30 '26 21:10 AP24110011695

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 30 '26 12:11 github-actions[bot]