From 4bc0b698a8b222cb6f97d37291812dec0675e872 Mon Sep 17 00:00:00 2001 From: beads/crew/emma Date: Sun, 18 Jan 2026 16:39:48 -0800 Subject: [PATCH] fix(staleness): skip auto-import when store is read-only (GH#1089) Track whether the store was actually opened read-only (vs just requested) since the fallback logic may change opts.ReadOnly. Use this to skip auto-import in staleness checks - importing would fail anyway if the store is read-only. Co-Authored-By: Claude Opus 4.5 --- cmd/bd/main.go | 9 +++++++-- cmd/bd/staleness.go | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/bd/main.go b/cmd/bd/main.go index c630b2b2..a9f406e6 100644 --- a/cmd/bd/main.go +++ b/cmd/bd/main.go @@ -76,8 +76,9 @@ var ( sandboxMode bool allowStale bool // Use --allow-stale: skip staleness check (emergency escape hatch) noDb bool // Use --no-db mode: load from JSONL, write back after each command - readonlyMode bool // Read-only mode: block write operations (for worker sandboxes) - lockTimeout time.Duration // SQLite busy_timeout (default 30s, 0 = fail immediately) + readonlyMode bool // Read-only mode: block write operations (for worker sandboxes) + storeIsReadOnly bool // Track if store was opened read-only (for staleness checks) + lockTimeout time.Duration // SQLite busy_timeout (default 30s, 0 = fail immediately) profileEnabled bool profileFile *os.File traceFile *os.File @@ -787,6 +788,10 @@ var rootCmd = &cobra.Command{ } } + // Track final read-only state for staleness checks (GH#1089) + // opts.ReadOnly may have changed if read-only open failed and fell back + storeIsReadOnly = opts.ReadOnly + if err != nil { // Check for fresh clone scenario if handleFreshCloneError(err, beadsDir) { diff --git a/cmd/bd/staleness.go b/cmd/bd/staleness.go index 67e9c94d..a66185c2 100644 --- a/cmd/bd/staleness.go +++ b/cmd/bd/staleness.go @@ -46,7 +46,8 @@ func ensureDatabaseFresh(ctx context.Context) error { // Database is stale - auto-import to refresh (bd-9dao fix) // For read-only commands running in --no-daemon mode, auto-import instead of // returning an error. This allows commands like `bd show` to work after git pull. - if !noAutoImport { + // Skip auto-import if store is read-only - it can't write anyway (GH#1089) + if !noAutoImport && !storeIsReadOnly { autoImportIfNewer() return nil }