AIChatAgent cleanup is per-DO and only triggered on local stream completion, which can leave cf_ai_chat_stream_* rows indefinitely for inactive DO instances
#809
Unanswered
Jerrynh770
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Cloudflare Agents team,
First of all, thank you for
@cloudflare/agentsand@cloudflare/ai-chat— they’ve been really helpful for building resumable streaming on Workers.I am using
AIChatAgentwith a common pattern: one Durable Object instance per chat (e.g. DO name =chatId). While reviewing storage growth, I noticed the built-in cleanup logic runs inside_completeStream()via_maybeCleanupOldStreams().From the current implementation, cleanup is:
CLEANUP_INTERVAL_MS(10 minutes)status = 'completed'streams older thanCLEANUP_AGE_THRESHOLD_MS(24 hours)cf_ai_chat_stream_chunksandcf_ai_chat_stream_metadataThis seems to imply the following behavior:
If a given DO instance (chatId) becomes inactive after a single conversation (i.e. no more stream completions happen in that DO), then its SQLite tables (
cf_ai_chat_stream_chunks,cf_ai_chat_stream_metadata) may never be cleaned up, because_maybeCleanupOldStreams()will not be called again for that DO.In our app, we persist final messages to Postgres as the source of truth, so we don’t need the DO to retain completed stream chunks long-term. We currently override
_completeStream()to delete that stream’s chunks/metadata immediately to keep DO storage bounded, but we’re not sure if that’s the recommended approach.Questions / request for guidance:
Beta Was this translation helpful? Give feedback.
All reactions