Commit Graph

2394 Commits

Author SHA1 Message Date
Steve Yegge
ea4b7e94c7 bd sync: apply DB changes after import 2025-11-24 10:39:30 -08:00
Steve Yegge
a2e2c87cfd Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 10:39:29 -08:00
Steve Yegge
4a2ee066f8 bd sync: 2025-11-24 10:39:28 2025-11-24 10:39:28 -08:00
Steve Yegge
22ba6ae4a7 bd sync: apply DB changes after import 2025-11-24 10:38:11 -08:00
Steve Yegge
92958d0b93 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 10:38:11 -08:00
Steve Yegge
d3face3f86 bd sync: 2025-11-24 10:38:10 2025-11-24 10:38:10 -08:00
Steve Yegge
d05953df14 bd sync: 2025-11-24 10:33:02 2025-11-24 10:33:02 -08:00
Steve Yegge
30dfb247dc Fix bd-l0r: Skip export after ZFC import to preserve JSONL source of truth
## Problem
When bd sync detected stale DB (>50% divergence), it would import JSONL to fix the DB,
but then immediately export the DB back to JSONL. This caused the stale DB to overwrite
the JSONL after a git pull, undoing cleanup work.

Example scenario:
1. Clone has 688 stale issues in DB (628 closed)
2. git pull brings JSONL with 62 issues (cleanup applied)
3. bd sync detects 1009.7% divergence and imports JSONL (DB → 62 issues) ✓
4. bd sync exports DB to JSONL (JSONL still 62 issues) ✓
5. But this marks JSONL as "changed" and commits/pushes it ✗

## Solution
After ZFC (JSONL First Consistency) import, set skipExport flag to prevent the export step.
JSONL is the source of truth after import - DB should sync to match, not export back.

## Changes
- cmd/bd/sync.go: Add skipExport flag, set it after ZFC import
- cmd/bd/sync.go: Wrap export logic in `if !skipExport` block
- CHANGELOG.md: Update ZFC entry with accurate description
- cmd/bd/sync_test.go: Add TestZFCSkipsExportAfterImport

Fixes #bd-l0r

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 10:32:56 -08:00
Steve Yegge
d1eb9f4e06 bd sync: apply DB changes after import 2025-11-24 01:40:52 -08:00
Steve Yegge
b6f37169c9 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 01:40:51 -08:00
Steve Yegge
6986cd4ab0 bd sync: 2025-11-24 01:40:51 2025-11-24 01:40:51 -08:00
Steve Yegge
515a31f270 bd sync: apply DB changes after import 2025-11-24 01:37:03 -08:00
Steve Yegge
31e3a41942 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 01:37:03 -08:00
Steve Yegge
2cea04500c bd sync: 2025-11-24 01:37:02 2025-11-24 01:37:02 -08:00
Steve Yegge
a1191f0b4c bd sync: 2025-11-24 01:31:04 2025-11-24 01:31:04 -08:00
Steve Yegge
dcd7877d77 Close bd-9cdc: Documentation already complete
Documentation for import.orphan_handling was completed in commit e0e6dff.
All files (AGENTS.md, README.md, TROUBLESHOOTING.md, CLI_REFERENCE.md)
have comprehensive coverage of:
- Resurrection behavior and tombstones
- All 4 config modes (allow, resurrect, skip, strict)
- Troubleshooting guidance for missing parent errors

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 01:30:53 -08:00
Steve Yegge
d4205648ce bd sync: apply DB changes after import 2025-11-24 01:25:22 -08:00
Steve Yegge
0d86e2e2cf Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 01:25:22 -08:00
Steve Yegge
a833ba751e bd sync: 2025-11-24 01:25:21 2025-11-24 01:25:21 -08:00
Steve Yegge
196ce3a6f9 Fix bd-77gm: bd import silently ignores positional arguments
When users forget the -i flag and run 'bd import file.jsonl', the command
would silently read from stdin instead of the file, resulting in '0 created,
0 updated' output that was misleading.

Root cause: The import command doesn't validate positional arguments, so
'bd import file.jsonl' would be interpreted as 'bd import' with an ignored
argument, reading empty stdin.

Fix: Add validation at the start of the import command to detect positional
arguments and show a helpful error message with the correct syntax.

Closes bd-77gm
2025-11-24 01:25:09 -08:00
Steve Yegge
e21c7b1a25 bd sync: 2025-11-24 01:19:15 2025-11-24 01:19:15 -08:00
Steve Yegge
21954cf590 bd sync: apply DB changes after import 2025-11-24 01:17:35 -08:00
Steve Yegge
965a873558 Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 01:17:35 -08:00
Steve Yegge
7abb870a57 bd sync: 2025-11-24 01:17:34 2025-11-24 01:17:34 -08:00
Steve Yegge
3c7aac1778 bd sync: apply DB changes after import 2025-11-24 01:14:33 -08:00
Steve Yegge
f4e5c17cea Merge branch 'main' of https://github.com/steveyegge/beads 2025-11-24 01:14:33 -08:00
Steve Yegge
9a4487b0bc bd sync: 2025-11-24 01:14:32 2025-11-24 01:14:32 -08:00
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
a02995bae1 bd sync: 2025-11-24 01:12:43 2025-11-24 01:12:43 -08:00
Steve Yegge
78847147e1 Support --reason flag in daemon mode for reopen command (bd-r46)
The reopen command now properly adds the reason as a comment when
using daemon mode, matching the behavior of direct mode. Uses the
existing RPC AddComment operation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 01:12:33 -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