Commit Graph

2365 Commits

Author SHA1 Message Date
Steve Yegge
fcd6ca694e Document blocked_issues_cache architecture and behavior
Add comprehensive documentation for the blocked_issues_cache optimization
that improved GetReadyWork performance from 752ms to 29ms (25x speedup).

Documentation locations:
- blocked_cache.go: Detailed package comment covering architecture,
  invalidation strategy, transaction safety, edge cases, and future
  optimizations
- ready.go: Enhanced comment at query site explaining the optimization
  and maintenance triggers
- ARCHITECTURE.md: New section with diagrams, blocking semantics,
  performance characteristics, and testing instructions

Closes bd-1w6i

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 01:14:21 -08:00
Steve Yegge
88009830ee bd sync: 2025-11-24 01:10:27 2025-11-24 01:10:27 -08:00
Steve Yegge
125d02860c Implement transaction retry logic for SQLITE_BUSY (bd-ola6)
Add exponential backoff retry for BEGIN IMMEDIATE transactions to handle
concurrent write load without spurious failures.

Changes:
- Add IsBusyError() helper to detect database locked errors
- Add beginImmediateWithRetry() with exponential backoff (10ms, 20ms, 40ms, 80ms, 160ms)
- Update CreateIssue and CreateIssuesInBatch to use retry logic
- Add comprehensive tests for error detection and retry behavior
- Handles context cancellation between retry attempts
- Fails fast on non-busy errors

This eliminates spurious SQLITE_BUSY failures under normal concurrent usage
while maintaining proper error handling for other failure modes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 01:10:16 -08:00
Steve Yegge
a8919fde9f bd sync: apply DB changes after import 2025-11-24 01:08:26 -08:00
Steve Yegge
ab27064d28 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 01:08:25 -08:00
Steve Yegge
6340483bbf bd sync: 2025-11-24 01:08:25 2025-11-24 01:08:25 -08:00
Steve Yegge
34997034ce bd sync: 2025-11-24 01:08:19 2025-11-24 01:08:19 -08:00
Steve Yegge
e0e6dff87f docs: Complete import.orphan_handling documentation (bd-9cdc)
Added comprehensive documentation for import orphan handling configuration
across all relevant documentation files:

- AGENTS.md: Added "Import Configuration" section with detailed mode
  explanations and usage guidance
- README.md: Documented orphan handling in Export/Import section with
  examples of all four modes
- TROUBLESHOOTING.md: Added "Import fails with missing parent errors"
  troubleshooting section with resurrection examples and prevention tips
- CLI_REFERENCE.md: Expanded Import/Export section with --orphan-handling
  flag documentation and cross-references

Documented resurrection behavior:
- Tombstone creation (Status=Closed, Priority=4)
- JSONL history search for deleted parents
- Best-effort dependency resurrection
- Hierarchical ancestor chain handling

Closes bd-9cdc

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 01:08:08 -08:00
Steve Yegge
5d11cf1842 docs: Add antivirus false positive documentation (bd-t4u1)
Document known Kaspersky false positive issue with Go binaries and
provide user workarounds.

Changes:
- Add comprehensive docs/ANTIVIRUS.md with:
  - Explanation of why Go binaries trigger AV false positives
  - Step-by-step exclusion instructions for Kaspersky, Windows Defender
  - File integrity verification procedures
  - False positive reporting guide
  - FAQ section
- Update docs/TROUBLESHOOTING.md with quick reference section
- Close bd-t4u1: Kaspersky PDM:Trojan.Win32.Generic detection

Root cause: Kaspersky's heuristic detection flags Go binary patterns as
suspicious. This is an industry-wide issue affecting many Go projects.

Build already uses recommended optimizations (-s -w flags). Future
improvements (code signing, vendor whitelist) tracked separately.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 01:04:40 -08:00
Steve Yegge
55fdaf99e7 Centralize error handling patterns in storage layer (bd-bwk2)
Standardized error handling across the SQLite storage layer by
consistently using wrapDBError() helper functions that were already
defined in errors.go.

Changes:
- config.go: Applied wrapDBError to all config/metadata functions
- queries.go: Fixed bare 'return err' in CreateIssue, UpdateIssue, DeleteIssues
- store.go: Changed %v to %w for proper error chain preservation
- errors_test.go: Added comprehensive test coverage for error wrapping

All error paths now:
- Wrap errors with operation context using %w
- Convert sql.ErrNoRows to ErrNotFound consistently
- Preserve error chains for unwrapping and type checking

This improves debugging by maintaining operation context throughout
the error chain and enables type-safe error checking with sentinel
errors.

All tests passing ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:59:49 -08:00
Steve Yegge
8d6696af40 docs: Complete error handling audit
- Add comprehensive audit document tracking all error patterns
- Update ERROR_HANDLING.md with metadata distinction guidelines
- Document init.go error handling patterns with metadata notes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:35:04 -08:00
Steve Yegge
44b578534f bd sync: apply DB changes after import 2025-11-24 00:34:55 -08:00
Steve Yegge
05a317306a bd sync: apply DB changes after rebase 2025-11-24 00:34:36 -08:00
Steve Yegge
b7f4d3f34b bd sync: apply DB changes after push 2025-11-24 00:34:26 -08:00
Steve Yegge
528f27c053 Add orphan detection migration (bd-3852)
Creates migration to detect orphaned child issues and logs them for user
action. Orphaned children are issues with hierarchical IDs (e.g., "parent.child")
where the parent issue no longer exists in the database.

The migration:
- Queries for issues with IDs like '%.%' where parent doesn't exist
- Logs detected orphans with suggested actions (delete, convert, or restore)
- Does NOT automatically delete or convert orphans
- Is idempotent and safe to run multiple times

Test coverage:
- Detects orphaned child issues correctly
- Handles clean databases with no orphans
- Verifies idempotency

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:34:26 -08:00
Steve Yegge
3037e6ddd5 docs: Add metadata distinction guidelines to ERROR_HANDLING.md
Expanded the Metadata Operations section to clearly distinguish:
- Configuration Metadata (Pattern A): issue_prefix, sync.branch
  → Fatal errors - these are prerequisites for basic operation
- Tracking Metadata (Pattern B): bd_version, repo_id, last_import_hash
  → Warnings - system degrades gracefully without these

Includes concrete examples, rationales, and cross-references to init.go
implementation.

Resolves: bd-pp3
2025-11-24 00:34:15 -08:00
Steve Yegge
836c731cbe docs: Clarify metadata error handling patterns in init.go
Add detailed comments distinguishing between:
- Configuration metadata (issue_prefix, sync.branch): Pattern A (fatal)
- Tracking metadata (bd_version, repo_id, clone_id): Pattern B (warnings)

The code already followed the correct patterns from ERROR_HANDLING.md,
but lacked explicit documentation explaining WHY different metadata types
use different error handling strategies.

Resolves: bd-b2c
2025-11-24 00:33:25 -08:00
Steve Yegge
aeffb8d0ac bd sync: 2025-11-24 00:29:04 2025-11-24 00:29:04 -08:00
Steve Yegge
5fec8b47c6 bd sync: apply DB changes after import 2025-11-24 00:25:27 -08:00
Steve Yegge
1fe88c2d9c bd sync: apply DB changes after import 2025-11-24 00:25:09 -08:00
Steve Yegge
76e3f27eb0 fix: CI test failures and lint errors
- Fixed test file naming: issues.jsonl -> beads.jsonl
  - beads_test.go: Update expected path in TestFindJSONLPath
  - internal/beads/beads_test.go: Update TestFindJSONLPathDefault
  - cmd/bd/main_test.go: Update TestAutoFlushJSONLContent

- Fixed lint errors (gosec):
  - G304: Added nosec comments for file operations with user-provided paths
  - G204: Added nosec comment for subprocess with controlled binary path

- Fixed lint errors (errcheck):
  - cmd/bd/test_wait_helper.go: Acknowledge error return values with _
  - cmd/bd/onboard.go: Handle fmt.Fprintf error return

All tests passing locally. All lint checks passing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:21:01 -08:00
Steve Yegge
ed3ddc0053 bd sync: 2025-11-24 00:12:24 2025-11-24 00:12:24 -08:00
Steve Yegge
3eec586a18 docs: Complete comprehensive v0.24.3 changelog
Thorough manual review of all 243 commits between v0.24.2 and v0.24.3:

- 10 major Added features with detailed sub-bullets
- 15 critical Fixed issues with technical context
- 4 Changed improvements to workflows
- 2 Testing enhancements
- 1 Performance optimization

Each entry includes:
- Commit hashes for traceability
- bd issue IDs where applicable
- User-focused descriptions
- Technical details and impact
- Follows Keep a Changelog format

This matches the quality and detail of previous changelog entries.
2025-11-24 00:12:17 -08:00
Steve Yegge
38a6ac95aa bd sync: apply DB changes after import 2025-11-24 00:07:34 -08:00
Steve Yegge
ed5a86b9e0 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 00:07:34 -08:00
Steve Yegge
ba153d0a9f bd sync: 2025-11-24 00:07:33 2025-11-24 00:07:33 -08:00
Steve Yegge
e05784f4a9 docs: Add v0.24.3 changelog entry
Properly documents all changes from v0.24.2 to v0.24.3:
- Version management and auto-migration features
- Data consistency and sync improvements
- Security enhancements
- Cross-platform bug fixes
- Web UI improvements
- Daemon and git hook enhancements
2025-11-24 00:06:25 -08:00
Steve Yegge
634b6a20f9 feat: Update bump-version.sh to handle CHANGELOG.md
- Automatically moves [Unreleased] section to [version] - date
- Creates new empty [Unreleased] section at top
- Includes CHANGELOG.md in version bump commit
- Follows Keep a Changelog format properly
2025-11-24 00:05:45 -08:00
Steve Yegge
f7f4822601 bd sync: apply DB changes after import 2025-11-24 00:03:21 -08:00
Steve Yegge
319f1adaeb Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 00:03:21 -08:00
Steve Yegge
dbb3000d69 bd sync: 2025-11-24 00:03:20 2025-11-24 00:03:20 -08:00
Steve Yegge
2560b11f80 feat: Add --start flag to bd daemon, show help with no args
Currently 'bd daemon' with no args immediately starts the daemon. This is
inconsistent with other daemon management commands like --stop, --status,
etc. and makes the command less discoverable for new users.

Changes:
- Add --start flag to explicitly start daemon
- Show help text when no operation flags provided
- Update auto-start logic to use --start flag
- Update startDaemon() to pass --start when forking
- Update all documentation to use 'bd daemon --start'
- Update MCP Python client error messages

The MCP docs already incorrectly showed 'bd daemon start' which doesn't
work, so this change fixes that documentation bug while improving UX.

Auto-start still works correctly - it now passes --start internally.

Fixes bd-gfu

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:03:07 -08:00
Steve Yegge
a5429195b7 bd sync: 2025-11-24 00:01:30 2025-11-24 00:01:30 -08:00
Steve Yegge
95b1577521 bd sync: 2025-11-23 23:52:35 2025-11-23 23:52:35 -08:00
Steve Yegge
e5ace6cf6e chore: Bump version to 0.24.3
Updated all component versions:
- bd CLI: 0.24.2 → 0.24.3
- Plugin: 0.24.2 → 0.24.3
- MCP server: 0.24.2 → 0.24.3
- npm package: 0.24.2 → 0.24.3
- Documentation: 0.24.2 → 0.24.3

Generated by scripts/bump-version.sh
2025-11-23 23:42:48 -08:00
Steve Yegge
bc5d3690ce bd sync: 2025-11-23 23:41:14 2025-11-23 23:41:14 -08:00
Steve Yegge
d45cff5085 feat: Handle FOREIGN KEY constraint violations gracefully during import (bd-koab)
When importing JSONL after merges that include deletions, FK constraint
violations can occur if an issue references a deleted issue. Previously,
import would fail completely. Now it continues and reports skipped dependencies.

Changes:
- Add SkippedDependencies field to Result/ImportResult structs
- Update importDependencies() to detect FK violations using IsForeignKeyConstraintError()
- Log warnings for each skipped dependency with issue IDs and type
- Continue importing remaining dependencies instead of failing
- Display summary of all skipped dependencies at end of import

Example output:
  Warning: Skipping dependency due to missing reference: bd-b → bd-a (blocks)

  ⚠️  Warning: Skipped 2 dependencies due to missing references:
    - bd-b → bd-a (blocks)
    - bd-c → bd-a (parent-child)

  This can happen after merges that delete issues referenced by other issues.
  The import continued successfully - you may want to review the skipped dependencies.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 23:32:34 -08:00
Steve Yegge
e2e04c011a bd sync: 2025-11-23 23:11:21 2025-11-23 23:11:21 -08:00
Steve Yegge
d1641c7d2e Fix bd-afd: Auto-fix metadata.json jsonl_export mismatch
## Summary

When metadata.json gets deleted (git clean, merge conflict, rebase), the
version tracking code auto-recreates it using DefaultConfig() which hardcoded
jsonl_export to 'issues.jsonl'. But many repos (including beads itself) use
'beads.jsonl', causing a mismatch between config and actual JSONL file.

## Changes

1. **bd doctor --fix auto-detection** (cmd/bd/doctor/fix/database_config.go)
   - New DatabaseConfig() fix function that auto-detects actual JSONL file
   - Prefers beads.jsonl over issues.jsonl (canonical name)
   - Skips backup files and merge artifacts
   - Wired into doctor.go applyFixes()

2. **Version tracking auto-detection** (cmd/bd/version_tracking.go)
   - trackBdVersion() now scans for existing JSONL files before defaulting
   - Prevents mismatches when metadata.json gets recreated
   - Added findActualJSONLFile() helper function

3. **Canonical default name** (internal/configfile/configfile.go)
   - DefaultConfig() changed from issues.jsonl to beads.jsonl
   - Aligns with canonical naming convention

4. **FindJSONLPath preference** (internal/beads/beads.go)
   - Now prefers beads.jsonl over issues.jsonl when scanning
   - Default changed from issues.jsonl to beads.jsonl

5. **Test coverage**
   - Added comprehensive tests for DatabaseConfig fix
   - Updated configfile tests for new default
   - Verified backup file skipping logic

## Testing

- All existing tests pass
- New tests verify auto-fix behavior
- Integration tested with simulated mismatches

Closes: bd-afd
2025-11-23 23:11:08 -08:00
Steve Yegge
bee0e44187 bd sync: apply DB changes after import 2025-11-23 23:05:29 -08:00
Steve Yegge
2f7f77055f Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-23 23:05:29 -08:00
Steve Yegge
3006e67eef bd sync: 2025-11-23 23:05:28 2025-11-23 23:05:28 -08:00
Steve Yegge
153f724e95 Fix Windows CI test failures
Two Windows-specific test failures:

1. TestNewSQLiteStorage - File locking on temp cleanup
   - Windows couldn't delete temp database file because connection was still open
   - Added defer store.Close() to properly cleanup the database connection
   - Without this, Windows file locking prevents TempDir cleanup

2. TestFindAllDatabases - Unexpected nil slice return
   - FindAllDatabases could return nil instead of empty slice when os.Getwd() fails
   - Changed from var databases to explicit empty slice initialization
   - Ensures function always returns non-nil slice, matching test expectations

Both issues are more pronounced on Windows due to stricter file locking
and different filesystem behavior.

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 23:01:55 -08:00
Steve Yegge
e5bb6ed6dc bd sync: 2025-11-23 22:55:37 2025-11-23 22:55:37 -08:00
Steve Yegge
21d246f502 bd sync: apply DB changes after import 2025-11-23 22:54:16 -08:00
Steve Yegge
0e956d733b Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-23 22:54:16 -08:00
Steve Yegge
7e41f2b4a5 bd sync: 2025-11-23 22:54:08 2025-11-23 22:54:08 -08:00
Steve Yegge
dfcbb7d3af Optimize sync_test.go: eliminate redundant git init calls
- Add setupGitRepo(), setupGitRepoWithBranch(), and setupMinimalGitRepo() helpers
- Refactor 19 test functions to use shared git repo setup
- Reduces duplicate git initialization boilerplate by ~300 lines
- All tests pass with improved maintainability

Related to bd-ktng
2025-11-23 22:54:05 -08:00
Steve Yegge
c9a2e7a8b2 Fix bd-v0y: Remove mtime fast-path in hasJSONLChanged
Git doesn't preserve mtime on checkout, causing false negatives where
hasJSONLChanged() incorrectly returns false after git pull updates JSONL.
This caused bd sync to overwrite pulled JSONL instead of importing it,
resurrecting deleted issues.

Solution: Always compute content hash for comparison (Option 1).
Performance impact is minimal (~10-50ms for sync operations).

Changes:
- cmd/bd/integrity.go: Remove mtime fast-path, always compute hash
- cmd/bd/sync.go: Remove mtime storage after import
- cmd/bd/import.go: Remove mtime storage after import
- cmd/bd/daemon_sync.go: Remove mtime storage and update comments
- cmd/bd/daemon_sync_test.go: Remove mtime assertions from tests

All tests pass. Existing test 'mtime changed but content same - git
operation scenario' verifies the fix works correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 22:53:54 -08:00
Steve Yegge
7491c142d4 bd sync: 2025-11-23 22:47:28 2025-11-23 22:47:28 -08:00