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 }