Skip to content

Comments

Fix Beads sync to use --flush-only flag to prevent data loss#316

Merged
subsy merged 4 commits intomainfrom
claude/investigate-issue-314-Wkux9
Feb 18, 2026
Merged

Fix Beads sync to use --flush-only flag to prevent data loss#316
subsy merged 4 commits intomainfrom
claude/investigate-issue-314-Wkux9

Conversation

@subsy
Copy link
Owner

@subsy subsy commented Feb 18, 2026

Summary

Updated the Beads tracker plugin to use bd sync --flush-only instead of bd sync to prevent data loss when syncing on branches without upstream tracking references.

Key Changes

  • Modified BeadsTrackerPlugin.sync() to call bd sync --flush-only instead of bd sync
  • Updated sync result message from "Beads synced with git" to "Beads tracker data flushed to JSONL"
  • Added detailed code comments explaining why --flush-only is necessary to avoid silent data destruction
  • Updated all documentation references to use the safer --flush-only flag
  • Added explicit git commands in documentation for manual sync workflow (git add .beads/ && git commit -m "Update beads" && git push)

Implementation Details

The --flush-only flag ensures that only the tracker state is exported to JSONL without performing git pull/push operations. This prevents a critical issue where bd sync could silently destroy locally-created beads when the current branch has no upstream tracking reference (see issue #314).

The change maintains the same sync interface while making the operation safer by:

  1. Exporting tracker state to JSONL (the primary goal)
  2. Avoiding automatic git operations that could cause data loss
  3. Allowing users to manually control git operations with explicit commands

https://claude.ai/code/session_01HWPpSnncVC4cvKjCpHBLeU

Summary by CodeRabbit

  • Bug Fixes

    • Beads tracker now uses a flush-only sync to export tracker data to JSONL, avoiding automatic git operations that could cause data loss on branches without upstream refs.
  • Documentation

    • Updated Beads tracker docs and examples to show the flush-only workflow and guidance for manual git steps when needed.
  • Tests

    • Added a comprehensive test suite covering detection, sync, task operations, status mappings and error handling for the Beads tracker.

bd sync (without --flush-only) triggers git pull internally, which silently
destroys locally-created beads when the branch has no upstream tracking ref.
This matches the safe pattern already used by the beads-rust tracker (br).

Fixes #314

https://claude.ai/code/session_01HWPpSnncVC4cvKjCpHBLeU
@vercel
Copy link

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
ralph-tui Ignored Ignored Preview Feb 18, 2026 8:06am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Walkthrough

The Beads tracker plugin's sync now runs bd sync --flush-only to export tracker state to JSONL without performing git pull/push. Documentation and examples updated accordingly. A comprehensive test suite for the Beads plugin was added covering CLI interactions and plugin behaviour.

Changes

Cohort / File(s) Summary
Beads tracker sync implementation
src/plugins/trackers/builtin/beads/index.ts
Changed sync invocation to bd sync --flush-only; updated success message and added comments explaining rationale and linking to issue.
Beads tracker documentation
website/content/docs/plugins/trackers/beads.mdx
Replaced bd sync examples with bd sync --flush-only, added explanation that flush-only exports JSONL without git operations, and adjusted manual git instructions where appropriate.
Beads tracker tests
src/plugins/trackers/builtin/beads/index.test.ts
Added extensive test suite with mocked CLI/fs interactions covering detection, readiness, sync, task listing/retrieval, status mapping, epics, templates, labels, error cases, and factory behaviour.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: updating the Beads sync functionality to use the --flush-only flag to prevent data loss, which directly aligns with the core objective of the pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/investigate-issue-314-Wkux9

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.93%. Comparing base (2b171fa) to head (d8712c8).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/plugins/trackers/builtin/beads/index.ts 33.33% 4 Missing ⚠️

❌ Your patch status has failed because the patch coverage (33.33%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #316      +/-   ##
==========================================
+ Coverage   44.76%   44.93%   +0.17%     
==========================================
  Files          97       97              
  Lines       30543    30546       +3     
==========================================
+ Hits        13673    13727      +54     
+ Misses      16870    16819      -51     
Files with missing lines Coverage Δ
src/plugins/trackers/builtin/beads/index.ts 70.32% <33.33%> (+8.18%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
website/content/docs/plugins/trackers/beads.mdx (1)

296-306: ⚠️ Potential issue | 🟡 Minor

Stale "Automatic" label in the comparison table after this change.

Line 300 still describes Beads' git sync as "Automatic", but this PR explicitly moves all git operations (add / commit / push) to a manual user step. Only the JSONL flush is now automatic. The table entry is now misleading for users choosing between trackers.

📝 Suggested fix
-| Git sync | Manual | Automatic |
+| Git sync | Manual | JSONL auto, git manual |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/content/docs/plugins/trackers/beads.mdx` around lines 296 - 306, The
"Git sync" comparison row currently reads "Git sync | Manual | Automatic" and is
stale; update that table row so Beads' column reflects manual git operations
(e.g., change "Git sync | Manual | Automatic" to "Git sync | Manual | Manual" or
"Git sync | Manual (manual add/commit/push)" ) to accurately represent that only
JSONL flushing remains automatic and all git add/commit/push for Beads are
manual.
🧹 Nitpick comments (1)
src/plugins/trackers/builtin/beads/index.ts (1)

486-491: Address non-evergreen comment reference in the sync method.

The --flush-only flag is a valid and confirmed feature (documented in community Beads guides for exporting to JSONL while skipping git operations), but the comment on line 489 references an external GitHub issue URL which violates the coding guideline "Avoid temporal context in comments; make them evergreen." Replace the issue reference with a self-contained description of the failure mode:

Suggested change
-    // Export tracker state to JSONL only. Use --flush-only to avoid git
-    // operations (pull/push) which can silently destroy locally-created beads
-    // when the branch has no upstream tracking ref.
-    // See: https://github.com/subsy/ralph-tui/issues/314
+    // Export tracker state to JSONL only. Use --flush-only to avoid git
+    // operations (pull/push) which can silently destroy locally-created beads
+    // on branches that have no upstream tracking ref (i.e. not yet pushed).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/plugins/trackers/builtin/beads/index.ts` around lines 486 - 491, The
comment above the execBd(['sync', '--flush-only']) call references an external
GitHub issue; replace that temporal link with a concise, self-contained
explanation: state that the '--flush-only' flag exports tracker state to JSONL
and skips git operations (pull/push) because performing pull/push when the
current branch lacks an upstream can silently overwrite or lose locally-created
beads; update the comment near execBd/ sync/ '--flush-only' to document this
failure mode and rationale without external links.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@website/content/docs/plugins/trackers/beads.mdx`:
- Around line 296-306: The "Git sync" comparison row currently reads "Git sync |
Manual | Automatic" and is stale; update that table row so Beads' column
reflects manual git operations (e.g., change "Git sync | Manual | Automatic" to
"Git sync | Manual | Manual" or "Git sync | Manual (manual add/commit/push)" )
to accurately represent that only JSONL flushing remains automatic and all git
add/commit/push for Beads are manual.

---

Nitpick comments:
In `@src/plugins/trackers/builtin/beads/index.ts`:
- Around line 486-491: The comment above the execBd(['sync', '--flush-only'])
call references an external GitHub issue; replace that temporal link with a
concise, self-contained explanation: state that the '--flush-only' flag exports
tracker state to JSONL and skips git operations (pull/push) because performing
pull/push when the current branch lacks an upstream can silently overwrite or
lose locally-created beads; update the comment near execBd/ sync/ '--flush-only'
to document this failure mode and rationale without external links.

…age)

67 tests covering sync, detection, getTasks, getTask, completeTask,
updateTaskStatus, getNextTask, getEpics, isComplete, getPrdContext,
getTemplate, and factory. Includes explicit test that sync uses
--flush-only flag (issue #314 regression guard).

https://claude.ai/code/session_01HWPpSnncVC4cvKjCpHBLeU
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/plugins/trackers/builtin/beads/index.test.ts (1)

19-19: mockReadFilePaths is captured but never asserted.

This array is populated in the readFile mock (line 101) but no test ever reads it. Consider either adding assertions that verify the correct file paths are passed to readFile (e.g. in the getPrdContext tests), or removing it to reduce dead code in the test infrastructure.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/plugins/trackers/builtin/beads/index.test.ts` at line 19, The test
defines mockReadFilePaths and populates it in the readFile mock but never
asserts it; either remove mockReadFilePaths to eliminate dead test state or add
assertions in the relevant tests (e.g., the getPrdContext tests) to verify the
expected file paths were requested. Locate the readFile mock in this test file
and either delete the mockReadFilePaths declaration and its push usage, or add
assertions that compare mockReadFilePaths to the expected array of paths after
calling getPrdContext (or other functions under test) so the mock is actually
validated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/plugins/trackers/builtin/beads/index.test.ts`:
- Line 19: The test defines mockReadFilePaths and populates it in the readFile
mock but never asserts it; either remove mockReadFilePaths to eliminate dead
test state or add assertions in the relevant tests (e.g., the getPrdContext
tests) to verify the expected file paths were requested. Locate the readFile
mock in this test file and either delete the mockReadFilePaths declaration and
its push usage, or add assertions that compare mockReadFilePaths to the expected
array of paths after calling getPrdContext (or other functions under test) so
the mock is actually validated.

The new beads/index.test.ts (67 tests, 91% coverage) was not being
picked up by CI because test batches are explicit. Add it as an
isolated batch (mocks node:child_process and node:fs) and include
its lcov in the Codecov upload.

https://claude.ai/code/session_01HWPpSnncVC4cvKjCpHBLeU
@subsy subsy merged commit 8852886 into main Feb 18, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants