Repository navigation
Description
Summary
Add a d1 conversation storage driver to infer so it can persist conversation history and the channel session-group index to a Cloudflare D1 database over D1's HTTP query API.
Why
infer is driven headless on ephemeral GitHub Actions runners (control plane dispatches it). The existing backends do not fit that model:
sqlite/jsonl/memorylive on the runner's ephemeral disk - wiped on every recycle, and unreachable by an external reader.postgres/redisneed a wire protocol Cloudflare D1 does not speak.
The infer can only read from D1 (native binding). So infer needs to write to D1 over its HTTP query API (POST /accounts/{account_id}/d1/database/{database_id}/query), which none of the current backends do. Because D1 is SQLite under the hood, the SQL is identical to the existing sqlite.go; only the transport (HTTP instead of a local file handle) differs.
Scope (in inference-gateway/cli)
internal/infra/storage/d1.go- newD1StorageimplementingConversationStorage+SessionGroupStorageover the D1 HTTP query API.config/config.go- registerStorageTypeD1("d1") and addD1StorageConfig+ theStorageConfig.D1field.internal/infra/storage/interfaces.go- addD1Configand theStorageConfig.D1field.internal/infra/storage/factory.go- add thed1case toNewStorageFromConfigandNewStorage.internal/infra/storage/d1_test.go- tests against anhttptestmock of the D1/queryenvelope, plus an optional gated live test.
The full driver source and the exact config.go / interfaces.go / factory.go edits are in the reference doc linked above.
Config
storage:
enabled: true
type: d1
d1:
account_id: "<cloudflare-account-id>"
database_id: "<d1-database-id>"
api_token: "<api-token-with-d1-edit>" # inject from a secret
base_url: "https://api.cloudflare.com/client/v4" # optionalSchema compatibility
D1 is SQLite, so the schema is infer's existing SQLite schema verbatim and the driver creates tables idempotently (CREATE TABLE IF NOT EXISTS). It MUST stay byte-for-byte compatible with internal/infra/storage/migrations/sqlite_migrations.go (conversations, session_groups) so either side may initialise the database.
Tests
Mirror sqlite_test.go, but stand up an httptest.Server that speaks the D1 /query envelope ({"success":true,"result":[{"results":[...],"meta":{"changes":N}}]}) and point D1Config.BaseURL at it. Assert:
SaveConversationthenLoadConversationround-trips entries and metadata.ListConversationsorders byupdated_at DESCand honours limit/offset.DeleteConversation/UpdateConversationMetadatareturn "not found" when no rows change.PutSessionGroup/GetSessionGroup/ListSessionGroupsround-trip the index.ListConversationsNeedingTitlescarriesModel/Tags/TitleGenerated/TitleInvalidated/TitleGenerationTime(mirrorsqlite.goexactly - do not route those rows through the lean summary mapper, or the title-generation batch path loses those fields).- Optional: an end-to-end test against a real D1, gated behind an env var.
Run go build ./... and go test ./internal/infra/storage/... in the cli module.
Acceptance criteria
storage.type: d1writes conversations and session groups to D1 over the HTTP API.- A later
infer agentrun reads back the same rows; an external D1 reader sees them too. - No data loss across a container / runner recycle (D1 is external to the runner).
- Tests pass against the
httptestmock.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
chore(release): 0.123.0 [skip ci]
inference-gateway-releaser commentedon Jun 24, 2026
🎉 This issue has been resolved in version 0.123.0 🎉
The release is available on:
Your semantic-release bot 📦🚀