beads icon indicating copy to clipboard operation
beads copied to clipboard

bd sync creates sync_base.jsonl every time + db closed errors

Open Ghannodahn opened this issue 1 month ago • 0 comments

GitHub Issue: bd sync creates sync_base.jsonl every time + db closed errors

File this at: https://github.com/steveyegge/beads/issues/new


Title

bd sync always creates sync_base.jsonl (triggers doctor warning) + "database is closed" errors

Description

Two related issues with bd sync in sync-branch mode:

Issue 1: sync_base.jsonl always recreated

Every bd sync creates .beads/sync_base.jsonl. This file:

  • Is already in .beads/.gitignore
  • Triggers bd doctor warning about "multiple JSONL files"
  • Cannot be fixed by following bd doctor --fix instructions (git rm doesn't work since it's untracked, and sync recreates it anyway)

Issue 2: sync-state.json thrashing + db closed error

During bd sync, the file .beads/sync-state.json is:

  • Created and deleted approximately 10 times during a single sync operation
  • Ends up containing a "database is closed" error:
{
  "last_failure": "2026-01-11T19:58:30.689745-08:00",
  "failure_count": 1,
  "backoff_until": "2026-01-11T19:59:00.689745-08:00",
  "needs_manual_sync": false,
  "failure_reason": "failed to get sync branch: failed to get sync.branch from config: get config: sql: database is closed"
}

Environment

  • bd version: 0.47.0
  • Mode: sync-branch (beads-sync)
  • Daemon: running
  • OS: macOS

Steps to Reproduce

  1. Configure sync-branch: bd config set sync.branch beads-sync
  2. Run bd sync
  3. Observe: sync_base.jsonl created, sync-state.json thrashing
  4. Run bd doctor - see warning about multiple JSONL files
  5. Check sync-state.json - see "database is closed" error

Expected Behavior

  1. sync_base.jsonl should either:

    • Not trigger a doctor warning (recognized as internal file), OR
    • Not be created in the repo directory (use temp location)
  2. sync-state.json should not thrash or end with db closed errors

Actual Behavior

  • sync_base.jsonl always created, always triggers doctor warning
  • sync-state.json written/deleted ~10 times per sync
  • Sync completes but sync-state.json shows failure
  • Doctor warning cannot be resolved

Related Issues

  • #607 - "Potential race condition in FreshnessChecker causing intermittent 'database is closed' errors" (closed Dec 18, 2025)
    • That fix used sync.RWMutex to protect database operations during reconnection
    • The error I'm seeing may be a regression or different code path (reading sync.branch config)

Analysis

The error occurs when reading config:

failed to get sync.branch from config: get config: sql: database is closed

This suggests the race condition fix in #607 may not cover the config-reading code path, or there's a separate issue when accessing config during sync operations.

sync_base.jsonl purpose

Based on v0.47.0 release notes mentioning "pull-first sync with 3-way merge", sync_base.jsonl appears to be the base file for 3-way merge (comparing base/local/remote). This is expected behavior for 3-way merge - the issue is that:

  1. bd doctor doesn't recognize it as an internal working file
  2. It's always recreated even when no sync occurs

Workaround

Ignoring the doctor warning since sync actually works. But the UX is confusing.

Ghannodahn avatar Jan 12 '26 04:01 Ghannodahn