Skip to content

SQLITE_TOOBIG when sessions are larger than 2MB #240

@mhart

Description

@mhart

Describe the Bug

Cloudflare deployments can fail to persist agent sessions when session history contains large inline image content.

In Flue 0.11.0, image bytes are redacted from runtime events/run history, but persisted session history still stores the full SessionData object as a single JSON string in flue_sessions.data via SqlSessionStore.save():

INSERT OR REPLACE INTO flue_sessions (id, data, updated_at)
VALUES (?, ?, ?)

On Cloudflare Durable Object SQLite, a single string/blob value is limited to 2MB. If a session contains a large image, or enough accumulated history, JSON.stringify(sessionData) can exceed that limit and the session save fails with:

Error: string or blob too big: SQLITE_TOOBIG
    at SqlSessionStore.save

This can interrupt otherwise valid agent runs. The durable-session storage shape seems to need a more granular design, ideally one row per session entry plus externalized or chunked blob/image content for large attachments.

Expected Behavior

Flue should persist sessions containing large images or attachments without exceeding Cloudflare Durable Object SQLite’s per-cell string/blob limit.

A robust design might:

  • Store session metadata separately from session entries.
  • Store each SessionEntry as its own row instead of one JSON blob for the whole session.
  • Externalize or chunk large image/blob/document content referenced by an entry.
  • Rehydrate externalized content on session load so model context remains unchanged.
  • Delete associated externalized blobs when the session/session tree is deleted.

Steps to Reproduce

  1. Deploy a Cloudflare-target Flue agent using Durable Object SQLite persistence.
  2. Send a prompt/skill/task call with an attached image large enough that the persisted SessionData JSON exceeds Cloudflare’s 2MB string/blob limit.
  3. Observe session persistence fail with SQLITE_TOOBIG, for example:
Error: string or blob too big: SQLITE_TOOBIG
    at SqlSessionStore.save

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions