Skip to content

Commit b012ba8

Browse files
committed
feat(memory_store): auto-fallback to SQLite when DATABASE_URL absent
Completes the Glama-inspectability work paired with commit A (plugin.json env schema). When Cortex launches with no DATABASE_URL (sandbox inspection, CI smoke, first-glance experimenter), the factory now logs a warning and drops to the existing SQLite backend rather than raising RuntimeError. Behaviour matrix: DATABASE_URL set + reachable → PostgreSQL (unchanged) DATABASE_URL set + unreachable → raise (unchanged — signals real config error) DATABASE_URL unset / empty → SQLite with loud warning (was: raise) CORTEX_ALLOW_SQLITE_FALLBACK=1 → SQLite even if PG fails Rationale: real production users who ran /cortex-setup-project have DATABASE_URL set to a reachable Postgres, so their path is unchanged. Misconfigured Postgres still raises loudly. The only path that flips is "no DATABASE_URL at all," which today leaves users with an unbootable server — now it boots against SQLite so tools are discoverable and the install can be tried before wiring Postgres. Unlocks Glama's sandbox inspector → expected Quality grade lift C → B/A once their next evaluation runs.
1 parent 04a48dd commit b012ba8

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

mcp_server/infrastructure/memory_store.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,36 @@ def __new__(
7070
store, err = None, "DATABASE_URL not set"
7171
if store is not None:
7272
return store
73+
# Inspection-mode fallback — Glama's sandbox, CI smoke
74+
# tests, and first-glance experimenters launch Cortex with
75+
# no DATABASE_URL. Rather than hard-fail and leave them
76+
# unable to even see the tool surface, drop to SQLite with
77+
# a loud warning. Real production users who have
78+
# configured Postgres will see the PG connect succeed;
79+
# only unset/unreachable installs trip this path.
80+
allow_fallback = (
81+
not url
82+
or os.environ.get("CORTEX_ALLOW_SQLITE_FALLBACK", "").lower()
83+
in ("1", "true", "yes")
84+
)
85+
if allow_fallback:
86+
logger.warning(
87+
"PostgreSQL unavailable (%s); falling back to SQLite. "
88+
"This is expected for inspection/sandbox launches; "
89+
"production installs should set DATABASE_URL.",
90+
err,
91+
)
92+
return _make_sqlite(
93+
db_path or settings.SQLITE_FALLBACK_PATH, embedding_dim
94+
)
7395
raise RuntimeError(
7496
f"PostgreSQL connection failed (url={url or '<unset>'}): {err}\n"
7597
"Cortex requires PostgreSQL in CLI mode.\n"
7698
"Run: bash setup.sh to configure PostgreSQL.\n"
7799
"If DATABASE_URL is set, verify it points to a reachable Postgres instance "
78100
"(host/port/credentials/database exists).\n"
79-
"Or set CORTEX_RUNTIME=cowork to allow SQLite fallback."
101+
"Or set CORTEX_RUNTIME=cowork (or CORTEX_ALLOW_SQLITE_FALLBACK=1) "
102+
"to allow SQLite fallback."
80103
)
81104

82105
# "auto" in cowork mode: try PG, fall back to SQLite

0 commit comments

Comments
 (0)