Repository navigation
feat(storage): add Cloudflare D1 conversation storage driver - #646
Conversation
Add a `d1` storage backend that persists conversations and the channel
session-group index to Cloudflare D1 over its HTTP query API. D1 is SQLite
under the hood, so the driver mirrors the SQLite backend method-for-method
and reuses the SQLite migrations verbatim; only the transport (HTTP instead
of a local file handle) differs. This lets headless `infer` on ephemeral CI
runners write to an external store that the control plane can read.
- internal/infra/storage/d1.go: D1Storage implementing ConversationStorage
and SessionGroupStorage over POST /accounts/{a}/d1/database/{d}/query
- config + factory wiring (StorageTypeD1, D1StorageConfig, D1Config, defaults)
- cmd/migrate.go: report D1 as auto-migrated (schema created on connect)
- d1_test.go: httptest mock backed by a real in-process SQLite DB so
round-trips exercise real SQL; plus a gated live test
Timestamps are stored as UTC RFC3339 for stable ORDER BY across runners and
unambiguous external reads.
Closes #645
|
@claude Can you create the follow-up for the docs repo? |
|
Claude finished @edenreich's task in 3m 38s —— View job Docs follow-up filed ✅Created the inference-gateway/docs#273 - [DOCS] Add Cloudflare D1 conversation storage backend to cli.md
The issue is scoped against the actual
It also captures the design notes worth surfacing in docs (SQLite schema parity, UTC RFC3339 timestamps,
|
## [0.123.0](v0.122.2...v0.123.0) (2026-06-24) ### 🚀 Features * **storage:** add Cloudflare D1 conversation storage driver ([#646](#646)) ([b6785ae](b6785ae)), closes [#645](#645) * **claude-code:** surface token usage and cost in headless mode ([#650](#650)) ([4e4f846](4e4f846)), closes [#649](#649) ### 🐛 Bug Fixes * set git identity for semantic release ([a03ed0b](a03ed0b)) ### ♻️ Code Refactoring * tighten inline diff context to 2 lines ([adcc17b](adcc17b)) ### 🔧 Build System * **deps:** bump the github-actions group with 3 updates ([#648](#648)) ([92784cd](92784cd)) * **deps:** bump the gomod group with 3 updates ([#647](#647)) ([a319eeb](a319eeb)) ### 🧹 Maintenance * **deps:** bump infer CLI v0.121.1 -> v0.122.2, infer-action v0.15.1 -> v0.15.4 ([#644](#644)) ([6befa6f](6befa6f))
|
🎉 This PR is included in version 0.123.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
Adds a
d1conversation storage backend that persists conversations and the channel session-group index to Cloudflare D1 over its HTTP query API (POST /accounts/{account}/d1/database/{database}/query).D1 is SQLite under the hood, so the driver mirrors the existing SQLite backend method-for-method and reuses the SQLite migrations verbatim - only the transport (HTTP instead of a local file handle) differs. This unblocks headless
inferon ephemeral GitHub Actions runners:sqlite/jsonl/memorylive on the runner's disk (wiped on recycle, unreadable externally) andpostgres/redisspeak wire protocols D1 doesn't, whereas D1 is external to the runner and the control plane can read it back via its native binding.Closes #645
What changed
internal/infra/storage/d1.go(new)D1StorageimplementingConversationStorage+SessionGroupStorage; thindo/exec/queryRowsHTTP layer over the D1/queryenvelope; param encoder + decode helpersinternal/infra/storage/d1_test.go(new)ListConversationsNeedingTitlestest, a request-shape/auth test, and a gated live testconfig/config.go,internal/infra/storage/interfaces.go,factory.goStorageTypeD1,D1StorageConfig/D1Config, defaults, and the two factory casescmd/migrate.go.infer/config.yamld1block (init --overwrite;agents.yamldiff discarded per CLAUDE.md)Configuration
Env overrides auto-derive:
INFER_STORAGE_D1_ACCOUNT_ID,_DATABASE_ID,_API_TOKEN,_BASE_URL.Design notes
migrations.GetSQLiteMigrations()over HTTP, soconversations/session_groupsstay byte-for-byte compatible with the SQLite backend - either side may initialise the database.ORDER BY updated_at DESCacross runners in any timezone and unambiguous external reads.ListConversationsstays lean whileListConversationsNeedingTitlescarriesModel/Tags/TitleGenerated/TitleInvalidated/TitleGenerationTime(the title-generation batch path needs them) - covered by a dedicated test.api_tokenfollows the existing plaintext-config + env-override convention (like the Postgres password) and is never logged.Testing
go build ./...✅go test ./...✅ (exit 0, 0 failures)task lint✅ (0 issues)INFER_TEST_D1_LIVE+INFER_STORAGE_D1_*are set)Cross-repo impact
Docs-only. No gateway/SDK/operator changes - the gateway already reads D1 via its native binding; this adds the CLI write path. A
[DOCS]follow-up forinference-gateway/docs→cli.md(add Cloudflare D1 to the storage-backends sections + config keys/env vars) should accompany this PR - happy to file it.