Stop calling the PostgreSQL store SQLite, and stop guessing where it is

Two things that were only ever confusing, and one of them stopped a command
working on the cluster.

The store type was named SQLite and kept the name when PostgreSQL was added, so
OpenPostgres returned a *SQLite and all seventy-odd methods on the production
store were spelled after the database it was not running on. Nothing broke;
people did. Earlier today I added three methods to *SQLite for a table that on
this cluster only ever lives in PostgreSQL, and the name did not once look
wrong. It is a field, which is all it ever was.

`llmgw users` and `llmgw keys` defaulted --store to a SQLite path. On a
deployment whose store is PostgreSQL every one of them failed with "unable to
open database file" while the right answer sat in auth.store in the config file
beside them; the conclusion an operator draws is that the tool is broken, and
they are not far off. They now ask the server's own configuration before
falling back, and the error names which of the three sources chose the address
— the failure was never the path, it was which one picked it.

The single-machine default still applies last, so a deployment with no config
file keeps working with no flags.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5 committed 2026-09-27 12:20:40 +02:00
1 parent 3febb6ef63
commit ebce41e22d
32 files changed
+320 -140

No files matched your search

+5 -5
View File
@@ -74,7 +74,7 @@ func TestUsageReachesTheStoreWithoutBlockingRequests(t *testing.T) {
func TestRequestRateLimitsBindThroughTheGateway(t *testing.T) {
path, mint := provision(t)
key := mint(t, "burst")
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
rpm := 5
if err := s.PutLimits(context.Background(), store.Limits{
Scope: store.ScopeKey, ScopeID: "key-burst", RPM: &rpm,
@@ -107,7 +107,7 @@ func TestRequestRateLimitsBindThroughTheGateway(t *testing.T) {
func TestASpentBudgetRefusesAndDoesNotSuggestRetrying(t *testing.T) {
path, mint := provision(t)
key := mint(t, "broke")
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
// One micro-unit: the first request exhausts it.
budget := int64(1)
if err := s.PutLimits(context.Background(), store.Limits{
@@ -162,7 +162,7 @@ func TestBudgetSurvivesAGatewayRestart(t *testing.T) {
// A second gateway over the same store, with a budget just under what was
// already spent: it must refuse immediately rather than starting fresh.
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
budget := spent[0].CostMicros
if err := s.PutLimits(context.Background(), store.Limits{
Scope: store.ScopeKey, ScopeID: "key-persistent",
@@ -238,7 +238,7 @@ func TestASpentBudgetIsServedAnAffordableModel(t *testing.T) {
// guardrail rather than a wall.
path, mint := provision(t)
key := mint(t, "broke")
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
budget := int64(1) // one micro-unit: the first request exhausts it
if err := s.PutLimits(context.Background(), store.Limits{
Scope: store.ScopeKey, ScopeID: "key-broke",
@@ -276,7 +276,7 @@ func TestASpentBudgetWithNoFallbackStillRefuses(t *testing.T) {
// refused exactly as before, or a budget would stop meaning anything.
path, mint := provision(t)
key := mint(t, "broke")
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
budget := int64(1)
if err := s.PutLimits(context.Background(), store.Limits{
Scope: store.ScopeKey, ScopeID: "key-broke",
+5 -5
View File
@@ -66,7 +66,7 @@ func provision(t *testing.T) (string, func(t *testing.T, name string, tune ...fu
}
// withStore sets limits on an existing store.
func withStore(t *testing.T, path string, fn func(*store.SQLite)) {
func withStore(t *testing.T, path string, fn func(*store.DB)) {
t.Helper()
s, err := store.OpenSQLite(context.Background(), path)
if err != nil {
@@ -140,7 +140,7 @@ func TestRevocationTakesEffectWithinTheCacheTTL(t *testing.T) {
t.Fatal("the key did not work to begin with")
}
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if err := s.RevokeKey(context.Background(), "key-doomed", time.Now()); err != nil {
t.Fatal(err)
}
@@ -166,7 +166,7 @@ func TestAnAllowlistCoversEveryNameOfAModel(t *testing.T) {
byAlias := mint(t, "alias")
other := mint(t, "other")
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
for _, l := range []store.Limits{
{Scope: store.ScopeKey, ScopeID: "key-canonical", AllowedModels: []string{testModel}},
{Scope: store.ScopeKey, ScopeID: "key-alias", AllowedModels: []string{"alias-for-test-model"}},
@@ -317,7 +317,7 @@ func TestOnboardingAUserEndToEnd(t *testing.T) {
// The operator's side.
var link string
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
secret, k, err := store.NewKey("key-new", "ayse-laptop", "proj")
if err != nil {
t.Fatal(err)
@@ -396,7 +396,7 @@ func TestTheSelfDescriptionEndpointAnswersWithoutAnOperator(t *testing.T) {
// with access to the dashboard.
path, mint := provision(t)
key := mint(t, "curious")
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
rpm := 42
if err := s.PutLimits(context.Background(), store.Limits{
Scope: store.ScopeKey, ScopeID: "key-curious",
+1 -1
View File
@@ -101,7 +101,7 @@ func contextFallbackConfig(path string) func(*config.Server) {
// spendTheBudget exhausts a key so the next request falls back.
func spendTheBudget(t *testing.T, path, id string) {
t.Helper()
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
budget := int64(1)
if err := s.PutLimits(context.Background(), store.Limits{
Scope: store.ScopeKey, ScopeID: id,
+7 -7
View File
@@ -120,7 +120,7 @@ func TestAnAccountIsUselessUntilItIsApproved(t *testing.T) {
}
// Approve, and it all works.
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
users, err := s.Users(context.Background(), store.UserPending)
if err != nil || len(users) != 1 {
t.Fatalf("pending users: %v %v", users, err)
@@ -181,7 +181,7 @@ func TestAUserCannotRevokeSomeoneElsesKey(t *testing.T) {
ayseKey := extractKey(t, body)
var ayseKeyID string
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
users, _ := s.Users(context.Background(), store.UserActive)
for _, u := range users {
if u.Email == "ayse@example.com" {
@@ -249,7 +249,7 @@ func TestSuspensionClosesOpenSessions(t *testing.T) {
if code, _ := b.get("/profile"); code != http.StatusOK {
t.Fatalf("profile before suspension: %d", code)
}
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if err := s.SetUserState(context.Background(), id, store.UserSuspended); err != nil {
t.Fatal(err)
}
@@ -277,7 +277,7 @@ func TestSignupCanBeClosed(t *testing.T) {
}); code == http.StatusOK || code == http.StatusSeeOther {
t.Errorf("signup accepted a post although it is closed: %d", code)
}
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
users, err := s.Users(context.Background(), "")
if err != nil {
t.Fatal(err)
@@ -298,7 +298,7 @@ func signUpAndApprove(t *testing.T, b *browser, path, email string) string {
}
var id string
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
users, err := s.Users(context.Background(), store.UserPending)
if err != nil {
t.Fatal(err)
@@ -437,7 +437,7 @@ func TestTheClusterPageIsOnlyForAdmins(t *testing.T) {
t.Error("a non-admin is shown a link to the cluster")
}
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if err := s.SetAdmin(context.Background(), id, true); err != nil {
t.Fatal(err)
}
@@ -555,7 +555,7 @@ func TestChatObeysTheModelAllowlist(t *testing.T) {
b := newBrowser(t, h.router.URL)
signUpAndApprove(t, b, path, "ayse@example.com")
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if err := s.PutLimits(context.Background(), store.Limits{
Scope: store.ScopeProject, ScopeID: "proj",
AllowedModels: []string{"something-else"},
+6 -6
View File
@@ -57,7 +57,7 @@ func authConfig(path string) func(*config.Server) {
func enableThreads(t *testing.T, path string, hours int) {
t.Helper()
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if err := s.SetThreadRetention(context.Background(), "proj", hours); err != nil {
t.Fatal(err)
}
@@ -67,7 +67,7 @@ func enableThreads(t *testing.T, path string, hours int) {
func storedTurns(t *testing.T, path, thread string) []store.Message {
t.Helper()
var out []store.Message
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
msgs, err := s.Thread(context.Background(), "proj", thread)
if err != nil {
t.Fatalf("reading thread %q: %v", thread, err)
@@ -164,7 +164,7 @@ func TestOneProjectCannotReadAnothersThread(t *testing.T) {
enableThreads(t, path, 24)
// A key in a second project.
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if err := s.PutProject(context.Background(),
store.Project{ID: "other", TeamID: "team", Name: "Other"}); err != nil {
t.Fatal(err)
@@ -211,7 +211,7 @@ func TestWithoutAThreadNothingIsStoredAtAll(t *testing.T) {
t.Fatalf("%d %s", code, msg)
}
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
// Pruning with a cutoff far past every retention window deletes every
// thread there is, so a count of zero means none were created.
n, err := s.PruneThreads(context.Background(), time.Now().Add(1000*time.Hour))
@@ -258,7 +258,7 @@ func TestSomeoneCanUnsayWhatTheySaid(t *testing.T) {
if code := h.forget(t, key, "th1"); code != http.StatusNoContent {
t.Fatalf("deleting the thread returned %d", code)
}
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if _, err := s.Thread(context.Background(), "proj", "th1"); err == nil {
t.Error("the conversation survived being deleted")
}
@@ -272,7 +272,7 @@ func TestDeletingSomeoneElsesThreadLooksLikeDeletingNothing(t *testing.T) {
path, mint := provision(t)
mine := mint(t, "mine")
enableThreads(t, path, 24)
withStore(t, path, func(s *store.SQLite) {
withStore(t, path, func(s *store.DB) {
if err := s.PutProject(context.Background(),
store.Project{ID: "other", TeamID: "team", Name: "Other"}); err != nil {
t.Fatal(err)