Skip to content

Commit f3fbc63

Browse files
fix: use absolute DB paths to prevent seed data loss across restarts
Root cause: MEMORY_DB_PATH and DOJO_CAS_PATH defaulted to relative paths ("dojo_memory.db", "dojo-skills.db"). When the VPS working directory changed between deploys, the relative path resolved to a new location — silently creating a fresh empty database while the old one sat orphaned. Fix: default to ~/.dojo/memory.db and ~/.dojo/skills.db (absolute paths under the user's home directory). The directory is created automatically by NewMemoryManager. Environment variables still override for custom paths. This explains why seeds planted via dojo_seed_create vanished after v3.1.1 deploy — the Gateway restarted from a different CWD and connected to a different (empty) database file. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a9d1e79 commit f3fbc63

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ func main() {
269269
"initiative", defaultDisp.Initiative)
270270

271271
// ─── Initialize Memory ───────────────────────────────────────────
272-
dbPath := getEnv("MEMORY_DB_PATH", "dojo_memory.db")
272+
// Default to ~/.dojo/memory.db (absolute) to prevent data loss when the
273+
// working directory changes between deploys. A relative default like
274+
// "dojo_memory.db" resolves differently per CWD, silently creating new
275+
// empty databases on VPS restarts.
276+
dbPath := getEnv("MEMORY_DB_PATH", filepath.Join(userHomeDir(), ".dojo", "memory.db"))
273277
memoryManager, err := memory.NewMemoryManager(dbPath)
274278
if err != nil {
275279
slog.Warn("memory manager initialization failed", "error", err)
@@ -520,7 +524,7 @@ func main() {
520524
// matches the dojo CLI default (DOJO_CAS_PATH env var or dojo-skills.db).
521525
var workflowCAS cas.Store
522526
{
523-
casPath := getEnv("DOJO_CAS_PATH", "dojo-skills.db")
527+
casPath := getEnv("DOJO_CAS_PATH", filepath.Join(userHomeDir(), ".dojo", "skills.db"))
524528
store, casErr := cas.NewSQLiteStore(casPath)
525529
if casErr != nil {
526530
slog.Warn("workflow CAS initialization failed — /api/skills and /api/workflows will be unavailable",
@@ -673,6 +677,14 @@ func getEnv(key, defaultValue string) string {
673677
return defaultValue
674678
}
675679

680+
// userHomeDir returns the user's home directory, falling back to "." if unknown.
681+
func userHomeDir() string {
682+
if h, err := os.UserHomeDir(); err == nil {
683+
return h
684+
}
685+
return "."
686+
}
687+
676688
// loadDotEnv reads key=value lines from path and calls os.Setenv for each.
677689
// Lines beginning with # and blank lines are ignored.
678690
// Existing environment variables are NOT overridden — shell env always wins.

0 commit comments

Comments
 (0)