Critical fix for silent data corruption where database created 173
duplicate issues with wrong prefix (beads- instead of bd-).
Root cause: When issue_prefix config was missing, CreateIssue fell
back to deriving prefix from database filename (beads.db → 'beads'),
while auto-import imported bd- issues from git with SkipPrefixValidation.
This created duplicates.
Changes:
1. Removed derivePrefixFromPath() - never derive prefix from filename
2. CreateIssue/CreateIssues now REJECT if issue_prefix config missing
- Fail-fast with clear error message
3. Auto-import now SETS issue_prefix from first imported issue if missing
- Handles fresh clone scenario safely
4. Added newTestStore() helper that sets issue_prefix for tests
5. Updated test setup in multiple files to prevent test failures
Follow-ups filed: bd-167, bd-168, bd-169
Closes bd-166
Amp-Thread-ID: https://ampcode.com/threads/T-b2ee0738-b90b-40ef-ae44-f2d93729842c
Co-authored-by: Amp <amp@ampcode.com>
- Create internal/configfile package for config.json handling
- bd init now creates .beads/config.json with database, version, and jsonl_export fields
- Database discovery checks config.json first, falls back to beads.db
- Update .gitignore to not ignore config.json (part of repo state)
- Update test to expect beads.db and config.json
- Backward compatible with existing beads.db-only setups
- Add OpStatus operation and StatusResponse type to RPC protocol
- Add workspacePath and dbPath fields to Server struct
- Implement handleStatus() handler with daemon metadata
- Track last activity time with atomic.Value
- Add client.Status() method
- Check for exclusive locks via ShouldSkipDatabase()
- Update all test files to use new NewServer signature
- Add comprehensive status endpoint test
Closes bd-148
- Increase flush debounce from 1s to 30s (provides transaction window for batch operations)
- Increase daemon poll from 2s to 5s (reduces commit spam)
- Agents should run 'bd sync' at end of session to force immediate commit
- Prevents creating dozens of commits when making multiple issue changes
- Reduce flush debounce from 5s to 1s (BEADS_FLUSH_DEBOUNCE)
- Reduce daemon poll interval from 10s to 2s
- Makes issue changes sync much faster to JSONL and git
- Set rpc.ServerVersion from Version in daemon startup
- Set rpc.ClientVersion from Version in main.go startup
- Eliminates need to manually update RPC versions
- Both now use 0.0.0 placeholder, overridden at runtime
Amp-Thread-ID: https://ampcode.com/threads/T-03c37f7f-f41e-4b87-8700-d346c21bad30
Co-authored-by: Amp <amp@ampcode.com>
- Extracted auto-import logic from cmd/bd/main.go to internal/autoimport
- Removed global dependencies (store, dbPath) by using parameters
- Uses callback pattern (ImportFunc) for flexible import implementation
- Both CLI and daemon can now call auto-import after detecting staleness
- Added detailed ID remapping output for collision resolution
- Improved error reporting for parse failures
- All tests passing
Amp-Thread-ID: https://ampcode.com/threads/T-b7faaa33-fc52-409f-82b3-28db143b335d
Co-authored-by: Amp <amp@ampcode.com>
Allow setting issue prefix via config.yaml that works independently
of --no-db mode. This provides a consistent way to set the prefix
across the entire repository.
Precedence order:
1. --prefix flag (highest)
2. issue-prefix in config.yaml
3. .beads/nodb_prefix.txt (no-db mode only)
4. Auto-detect from directory name (lowest)
Changes:
- Add issue-prefix to config defaults in internal/config/config.go
- Update cmd/bd/init.go to read from config before auto-detecting
- Update cmd/bd/nodb.go detectPrefix to check config.yaml
- Update .beads/config.yaml with documentation and example
Usage:
# .beads/config.yaml
issue-prefix: "myproject"
# Or via environment variable
BD_ISSUE_PREFIX=myproject bd init
This makes the prefix setting repository-scoped and automatically
respected by bd init in both normal and no-db modes.
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This allows users to set --no-db mode persistently via:
1. .beads/config.yaml file (no-db: true)
2. BD_NO_DB environment variable
3. --no-db command-line flag (highest precedence)
Changes:
- Add no-db to config defaults in internal/config/config.go
- Wire no-db flag to read from config in cmd/bd/main.go
- Create example .beads/config.yaml with documentation
The configuration precedence is:
CLI flag > Environment variable > Config file > Default
This makes no-db mode repository-scoped and automatically
respected by all bd commands and the beads-mcp service.
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
Implement --no-db mode to avoid SQLite database corruption in scenarios
where the same .beads directory is accessed from multiple processes
(e.g., host + container, multiple containers).
Changes:
- Add in-memory storage backend (internal/storage/memory/memory.go)
- Implements full Storage interface using in-memory data structures
- Thread-safe with mutex protection for concurrent access
- Supports all core operations: issues, dependencies, labels, comments
- Add JSONL persistence layer (cmd/bd/nodb.go)
- initializeNoDbMode(): Load .beads/issues.jsonl on startup
- writeIssuesToJSONL(): Atomic write-back after each command
- detectPrefix(): Smart prefix detection with fallback hierarchy
1. .beads/nodb_prefix.txt (explicit config)
2. Common prefix from existing issues
3. Current directory name (fallback)
- Integrate --no-db flag into command flow (cmd/bd/main.go)
- Add global --no-db flag to all commands
- PersistentPreRun: Initialize memory storage from JSONL
- PersistentPostRun: Write memory back to JSONL atomically
- Skip daemon and SQLite initialization in --no-db mode
- Extract common writeJSONLAtomic() helper to eliminate duplication
- Update bd init for --no-db mode (cmd/bd/init.go)
- Create .beads/nodb_prefix.txt instead of SQLite database
- Create empty issues.jsonl file
- Display --no-db specific initialization message
Code Quality:
- Refactored atomic JSONL writes into shared writeJSONLAtomic() helper
- Used by both flushToJSONL (SQLite mode) and writeIssuesToJSONL (--no-db mode)
- Eliminates ~90 lines of code duplication
- Ensures consistent atomic write behavior across modes
Usage:
bd --no-db init -p myproject
bd --no-db create "Fix bug" --priority 1
bd --no-db list
bd --no-db update myproject-1 --status in_progress
Benefits:
- No SQLite corruption from concurrent access
- Container-safe: perfect for multi-mount scenarios
- Git-friendly: direct JSONL diffs work seamlessly
- Simple: no daemon, no WAL files, just JSONL
Test Results (go test ./...):
- ✓ github.com/steveyegge/beads: PASS
- ✗ github.com/steveyegge/beads/cmd/bd: 1 pre-existing failure (TestAutoFlushErrorHandling)
- ✓ github.com/steveyegge/beads/internal/compact: PASS
- ✗ github.com/steveyegge/beads/internal/rpc: 1 pre-existing failure (TestMemoryPressureDetection)
- ✓ github.com/steveyegge/beads/internal/storage/sqlite: PASS
- ✓ github.com/steveyegge/beads/internal/types: PASS
- ⚠ github.com/steveyegge/beads/internal/storage/memory: no tests yet
All test failures are pre-existing and unrelated to --no-db implementation.
The new --no-db mode has been manually tested and verified working.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
- bd-159: Track last_import_time in metadata after auto-import
- bd-160: Add staleness check to daemon before serving requests
- Detects when JSONL mtime > last import time
- Currently logs warning (needs bd-166 for actual import trigger)
- Add lastImportTime field to RPC Server struct with getter/setter
- Add checkAndAutoImportIfStale() method to detect stale JSONL
This is part of bd-158 epic to fix daemon showing stale data after git pull.
Amp-Thread-ID: https://ampcode.com/threads/T-b554e049-aff8-4a24-8bf3-3305483b7f5a
Co-authored-by: Amp <amp@ampcode.com>
- Add SortPolicy type with hybrid, priority, oldest constants
- Add SortPolicy field to WorkFilter
- Implement buildOrderByClause() for SQL generation
- Add --sort flag to bd ready command
- Add comprehensive tests for all 3 sort policies
- Update RPC protocol to support sort policy
- Update documentation with sort policy examples
Enables autonomous systems like VC to use strict priority ordering
while preserving hybrid behavior for interactive use.
Amp-Thread-ID: https://ampcode.com/threads/T-9d7ea9db-8d6d-4498-9daa-48a7e104ce1f
Co-authored-by: Amp <amp@ampcode.com>
- Use windowsOS constant in reinit_test.go
- Use testIssueBD1 constant in compact_test.go and counter_sync_test.go
- Merged duplicate bd-126 into bd-116
- Added CheckpointWAL method to SQLite storage
- Import now checkpoints WAL after completion
- Updates main .db file modification time for staleness detection
- PRAGMA wal_checkpoint(FULL) flushes WAL to main database
- Changed file permissions from 0644 → 0600 for JSONL exports and config files
- Changed directory permissions from 0755 → 0750 in all test code
- Updated .golangci.yml with proper exclusions for false positives
- Reduced gosec warnings from 102 to 22 (all remaining are acceptable)
Closes bd-57
Amp-Thread-ID: https://ampcode.com/threads/T-f754d957-9e42-4e74-861e-57235c7e6436
Co-authored-by: Amp <amp@ampcode.com>
- Added testUserAlice constant for 'alice' in test files
- Added windowsOS constant for 'windows' in test files
- Added testIssueBD1/testIssueBD2 constants for 'bd-1'/'bd-2' in test files
- Added testVersion100 constant for '1.0.0' in version tests
- Added testIssueCustom1 constant for 'custom-1' in lazy init tests
Closes bd-54
Amp-Thread-ID: https://ampcode.com/threads/T-0a4e5d44-2d95-4948-8f4a-d8facf8657c7
Co-authored-by: Amp <amp@ampcode.com>
- Remove flaky MemoryAllocMB assertion that can be 0 due to GC timing on Linux CI
- Keep goroutine count check for basic validation
- Import latest issues from main with collision resolution
- Merge 13 duplicate issues created from parallel work into canonical versions
- Closes bd-100, bd-115, bd-230 (all same flaky test issue)
Amp-Thread-ID: https://ampcode.com/threads/T-50996f50-4b66-49ca-9db4-e1c3ef4d4bc3
Co-authored-by: Amp <amp@ampcode.com>
Fixed all unchecked error returns in production code:
- os.Remove() calls in cleanup paths
- cmd.Wait() in goroutines
- fmt.Fprintf() writes
- Type assertions with proper ok checks
Reduces linter issues from 99 to 88. CI should now pass linting.
- Write PID to daemon.pid when acquiring lock for Windows compatibility
- Increase socket cleanup timeout to 5s for Windows
- Windows can't read locked files, so PID file is required fallback
- Fix PID detection: Open lock file with O_RDWR for Windows LockFileEx
- Fix script tests: Increase timeout to 2-5s for Windows process startup
- Fix uptime test: Use math.Ceil with minimum 1 second to prevent flakiness
- Fix socket cleanup: Add done channel to wait for Start() cleanup completion
All 5 failing Windows tests should now pass.
- Added OpEpicStatus operation to protocol
- Implemented handleEpicStatus() in RPC server
- Added EpicStatus() method to RPC client
- Updated epic.go to use daemon RPC when available
- Server-side filtering for close-eligible reduces RPC payload
- Both 'bd epic status' and 'bd epic close-eligible' now work in daemon mode
Fixes#62
Closes bd-87
Amp-Thread-ID: https://ampcode.com/threads/T-44c6044e-de04-40a0-bac3-b26238c32a17
Co-authored-by: Amp <amp@ampcode.com>
Fixes#114 and #122 by adding --description/-d flag to bd update CLI
and description parameter to MCP update_issue tool.
Changes:
- CLI: Added --description flag to updateCmd
- RPC: Added Description field to UpdateArgs
- Daemon: Updated updatesFromArgs to handle description
- MCP: Added description to update_issue, UpdateIssueParams, and clients
- Storage: description already supported in allowedUpdateFields
Tested in both daemon and direct modes.
Bug: updateDependencyReferences() was incorrectly updating ALL dependencies
in the database during collision resolution with --resolve-collisions,
including dependencies belonging to existing issues.
Root cause: The function checked if dep.IssueID was in idMapping keys
(old imported IDs like 'bd-1'), but those are also the IDs of existing
database issues. This caused existing dependencies to be incorrectly
modified or deleted.
Fix: Changed logic to only update dependencies where IssueID is in
idMapping VALUES (new remapped IDs like 'bd-295'). This ensures only
dependencies from remapped issues are updated, not existing ones.
During normal import flow, this is effectively a no-op since imported
dependencies haven't been added to the database yet when RemapCollisions
runs (they're added later in Phase 5 of import_shared.go).
Changes:
- Updated updateDependencyReferences() in collision.go to build a set
of new remapped IDs and only update dependencies with those IDs
- Added comprehensive documentation explaining the correct semantics
- Added regression tests: TestRemapCollisionsRemapsImportedNotExisting
and TestRemapCollisionsDoesNotUpdateNonexistentDependencies
- Skipped 3 tests that expected the old buggy behavior with clear
notes about why they need to be rewritten
Real-world impact: In one case, 125 dependencies were incorrectly
deleted from 157 existing issues during collision resolution.
Fixes https://github.com/steveyegge/beads/issues/120
Fixes bd-56
- Change validateBatchIssues() to only set timestamps if IsZero()
- Preserves historical timestamps from external systems (Jira, GitHub)
- Fixes dirty git repo after importing unchanged JSONL
- New issues still get current timestamps as before
- Add daemon.lock to .gitignore
Closes bd-55
Fixes#121
Amp-Thread-ID: https://ampcode.com/threads/T-e53c4a96-38dd-440a-9b8d-824992d33a40
Co-authored-by: Amp <amp@ampcode.com>