feat: add BrainLayer queue merge utility#283
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
|
@codex review |
✅ Actions performedReview triggered.
|
|
I'll perform a thorough bugbot-style review of the queue merge utility implementation. Code Review: Queue Merge UtilityOverall AssessmentThe implementation is solid and well-designed. The code demonstrates careful attention to atomicity, idempotency, and edge cases. I found no critical bugs, but I have several recommendations for additional test coverage and minor improvements. ✅ Strengths
|
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Review follow-up pushed in 0d89b1e. Changes: added drain-race FileNotFoundError handling during destination hash scan, added collision rename reporting as old -> new, and expanded queue-merge tests from 4 to 9 cases covering validation, destination creation, cross-filename dedupe, and drain-consumed files.\n\nVerification after the follow-up:\n- pytest tests/test_queue_merge.py -q -> 9 passed\n- ruff check src/brainlayer/queue_merge.py scripts/merge_queue.py tests/test_queue_merge.py -> all checks passed\n- ./scripts/run_tests.sh -> BrainLayer test gate passed: 1848 passed, 9 skipped, 75 deselected, 1 xfailed; MCP registration 3 passed; isolated eval/hook routing 32 passed; bun 1 passed; regression shell passed.\n- pre-push hook reran ./scripts/run_tests.sh and passed again.\n\n@cursor @BugBot re-review\n@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d89b1e38e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| result = QueueMergeResult() | ||
| existing_hashes = _read_existing_hashes(dest_dir) |
There was a problem hiding this comment.
Acquire the drain lock while merging queues
When this is run against the live queue, drain_once() in src/brainlayer/drain.py serializes its glob/read/unlink work with an exclusive fcntl.flock on the queue directory, but the merge scans existing hashes and later writes files without taking that same lock. In the normal LaunchAgent-running environment, the drain can therefore consume destination files between _read_existing_hashes() and the later collision/copy decisions, so the merge can act on stale state despite BrainLayer's one-writer queue contract. Hold the same queue-dir lock around the merge scan and writes, or require/verify the drain is stopped before merging.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0d89b1e. Configure here.
|
|
||
| @property | ||
| def total_actions(self) -> int: | ||
| return len(self.copied) + len(self.skipped_exact) + len(self.skipped_non_jsonl) |
There was a problem hiding this comment.
Unused total_actions property never tested or called
Low Severity
The total_actions property on QueueMergeResult is defined but never used anywhere in the codebase — not in the CLI script scripts/merge_queue.py, not in the tests, and not by any other consumer. Grepping for total_actions returns only the definition itself. This is dead code that could silently rot without anyone noticing if the dataclass fields change.
Reviewed by Cursor Bugbot for commit 0d89b1e. Configure here.




Summary
scripts/merge_queue.pyto union an AirDrop'd M1 Pro BrainLayer queue directory into the live M4 Max~/.brainlayer/queue/without mirroring, deleting, or overwriting.brainlayer.queue_merge.merge_queue_dirs()logic with byte-hash idempotency, exact-content skip reporting, and same-filename/different-content collision renames.Operator Usage
This PR does not run the actual M1→M4 queue merge; Etan has not AirDropped the source queue yet.
Test Plan
pytest tests/test_queue_merge.py -qfailed withModuleNotFoundErrorbefore implementation.pytest tests/test_queue_merge.py -q→ 4 passed.ruff check src/brainlayer/queue_merge.py scripts/merge_queue.py tests/test_queue_merge.py→ all checks passed.python3 scripts/merge_queue.pyverified dry-run, first merge, and idempotent second run../scripts/run_tests.sh→ BrainLayer test gate passed: 1843 passed, 9 skipped, 75 deselected, 1 xfailed; MCP registration 3 passed; isolated eval/hook routing 32 passed; bun 1 passed; regression shell passed../scripts/run_tests.shand passed again with the same gate.Notes
cr review --plainwas attempted before commit but hung after setup for ~5 minutes and was killed; PR review bots are requested below.Note
Medium Risk
Introduces new filesystem merge logic for the write-arbitration queue; while append-only and well-tested, mistakes could duplicate events or affect drain behavior during a live merge.
Overview
Adds an operator-facing CLI (
scripts/merge_queue.py) to merge an AirDrop’d queue directory into the live BrainLayer queue, supporting--dry-run/--destand printing per-file actions plus a post-mergelaunchctlhint.Implements
brainlayer.queue_merge.merge_queue_dirs()to append-only copy.jsonlevents with SHA-256 deduping (skip byte-identical content across reruns or different filenames), deterministic collision renames (-merge-<hash>), and atomic temp-then-rename writes; non-.jsonlfiles are ignored and destination-file races during hash scanning are tolerated. Adds pytest coverage for dry-run, idempotency, collisions, non-JSONL skips, missing/equal dirs, dest creation, cross-filename dedupe, and drain-race handling.Reviewed by Cursor Bugbot for commit 0d89b1e. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add
merge_queue_dirsutility to safely merge AirDrop'd queue directories into the live queuesrc/brainlayer/queue_merge.pywithmerge_queue_dirs, which unions a source queue directory into a destination, copying only.jsonlfiles and skipping exact duplicates by SHA-256 content hash.-merge-<hash>suffix; no files are overwritten or deleted.scripts/merge_queue.pyas a CLI entrypoint with--dry-runsupport, printing a per-file action summary and alaunchctl kickstarthint after a live merge.tests/test_queue_merge.pycovers idempotency, deduplication, collision renaming, missing source/dest handling, and dry-run behaviour.Macroscope summarized 0d89b1e.