fix(daemon): prevent stack overflow on empty database path (#1288) (#1313)

When metadata.json has an empty database field and no beads.db file exists,
filepath.Dir("") returns "." which causes lock file operations to use the
current directory instead of the beads directory. This could lead to stack
overflow or unexpected behavior.

Add early validation in tryAutoStartDaemon to check if dbPath is empty and
return false gracefully, consistent with other early-return conditions.
This commit is contained in:
aleiby
2026-01-25 17:59:57 -08:00
committed by GitHub
parent 9e85b9f5d7
commit 028921b04a
2 changed files with 39 additions and 1 deletions

View File

@@ -256,6 +256,14 @@ func tryAutoStartDaemon(socketPath string) bool {
return false
}
// Empty dbPath causes filepath.Dir("") to return "." which breaks lock
// file operations. This can happen when metadata.json has an empty database
// field and no beads.db file exists. Skip daemon start gracefully.
if dbPath == "" {
debugLog("skipping auto-start: no database path configured")
return false
}
if !canRetryDaemonStart() {
debugLog("skipping auto-start due to recent failures")
return false