fix(cloudflare-d1): deleteMessages fails for 99 or more ids (D1 parameter limit)
PR Checklist
- The commit message follows our guidelines
Bugs / Features
- Related issue(s) linked (none filed; repro below)
- Tests for the changes have been added
- Docs have been added / updated (no API change)
- Changesets have been added
What is the current behavior?
D1 accepts at most 100 bound parameters per statement (D1 limits). D1MemoryAdapter.deleteMessages() binds conversation_id, user_id and every message id in one DELETE ... IN (...), so 99 or more ids fail and nothing is deleted.
Repro with @voltagent/cloudflare-d1@2.1.2 on a Miniflare D1 binding:
deleteMessages(120 ids) -> D1_ERROR: too many SQL variables at offset 284: SQLITE_ERROR
What is the new behavior?
The ids are split into statements of at most 98 ids (98 + the 2 fixed params = 100) and sent with db.batch(), which D1 runs as one transaction, so a delete is still all-or-nothing.
Notes for reviewers
- New
memory-adapter.delete.spec.tsruns the adapter against in-memory SQLite (node:sqlite) through a small D1 stand-in that, like D1, rejects more than 100 bound parameters. The 99 and 250 cases fail onmain; 1, 98, 99 and 250 pass here. vitest run --typecheck packages/cloudflare-d1(5 passed) andbiome check packages/cloudflare-d1are clean.- Independent of #1553 (message order); the two specs are separate files so the PRs don't conflict.
- Written with Claude Code; I reviewed the change and ran the checks.
🤖 Generated with Claude Code
Summary by cubic
Fixes deleteMessages in the @voltagent/cloudflare-d1 adapter so deleting 99 or more messages no longer fails. D1 rejects statements with more than 100 bound parameters, and deleteMessages bound the conversation id, user id, and every message id in one DELETE ... IN (...), so 99+ ids errored with too many SQL variables and nothing was deleted. The ids are now split into statements of up to 98 ids and sent with db.batch(), which D1 runs as one transaction, so deletes remain all-or-nothing. The batch is wrapped in the same retry logic as the other batch writers.
Summary by CodeRabbit
- Bug Fixes
- Fixed an issue that could prevent deleting 99 or more messages at once. Large deletions now complete successfully, while messages outside the deletion request remain intact.