Repository navigation
perf: parallelize integration checks in step prune - #1890
Conversation
`step prune` checked each worktree and orphan branch for integration sequentially. With many local branches (100+), each hitting expensive git operations (merge-tree, patch-id at 500ms-2s each), this caused multi-minute runtimes. Parallelize both the worktree and orphan branch integration checks using rayon's `par_iter()`, matching the pattern already used by `wt list`. The integration results are computed in parallel, then processed sequentially for candidate selection and removal. Closes #1888 Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CLAUDE.md convention: .expect() in a Result-returning function should use ? or bail! instead. One instance on the new code.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
how does the parallelism work here? can we use a rayon thread pool to limit it? |
|
The parallelism uses rayon's
Each Currently it uses rayon's global thread pool, which defaults to the number of logical CPUs. A dedicated thread pool would give more control — something like: let pool = rayon::ThreadPoolBuilder::new()
.num_threads(8)
.build()?;
let results: Vec<_> = pool.install(|| {
wt_check_items.par_iter().map(|item| { ... }).collect()
});That would cap subprocess concurrency regardless of core count, which could matter on machines with many cores (spawning 64+ git processes at once might not help and could hurt with disk contention). Worth considering — happy to add it if you'd like a cap. |
|
what do we do elsewhere? can we follow that convention / possibly share code? |
|
Two existing conventions for limiting parallelism:
The prune case is closer to So the current approach already follows the existing convention. A dedicated thread pool would only help if we wanted to limit rayon task scheduling independently of subprocess concurrency, but since |
…ngle parallel pass Instead of two separate `par_iter()` calls — one for worktrees and one for orphan branches — collect all refs into a single `CheckItem` vec with an enum discriminant, then do one parallel `integration_reason()` pass. Results are dispatched by source type during sequential processing. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
|
All required CI checks pass. The
The actual new code (the |
|
do our tests include detached worktrees? run /simplify on this implementation |
…andling Merge the Prunable and Orphan match arms into shared branch-only logic, eliminating duplicated candidate construction and dry_run/remove dispatch. Store branch name directly in Prunable variant (removing impossible .context() error path). Collapse nested if-let per clippy. Trim comments that restated code. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Detached worktree tests: Yes, good coverage — 4 tests exercise detached HEAD in prune:
Simplify: Pushed f64e21e — net -30 lines. Changes:
|
|
do we have a snapshot test for the dry-run output? I'm impressed if nothing changed! |
## Summary - Add explicit dedup guidance for inline review comment replies in the `running-in-ci` skill - When replying to a review comment, the bot must now check for existing bot replies to the same `in_reply_to_id` before posting **Root cause:** A single PR review fires both `pull_request_review` and `pull_request_review_comment` events. The `handle` job's concurrency group correctly serializes these runs (the second queues until the first completes). However, the existing "Recheck Before Posting" section only checks total comment/review counts — too coarse to detect that the bot already replied to a specific inline comment. The second run's finer-grained check used a non-existent `GET /replies` endpoint that returned a 404, and the fallback output was ambiguous, making the bot conclude "No existing replies." **Evidence:** On [max-sixty/worktrunk PR #1890](max-sixty/worktrunk#1890), runs [23933934456](https://github.com/max-sixty/worktrunk/actions/runs/23933934456) (`pull_request_review`, handle 04:34:16–04:36:35) and [23933934467](https://github.com/max-sixty/worktrunk/actions/runs/23933934467) (`pull_request_review_comment`, handle 04:36:38–04:38:29) were correctly serialized by the concurrency group, but the second run's recheck failed to detect the first's reply and posted a duplicate. **Gate assessment:** - Evidence level: High — structural issue (the `/replies` GET endpoint always 404s, making the fallback output always ambiguous) - Classification: Structural — deterministic cause, will recur whenever dual events fire - Change type: Targeted fix — adds one subsection with an explicit, correct API command - Prior near-miss: [PRQL/prql runs 23831453414/23831453468](https://github.com/PRQL/prql/actions/runs/23831453414) had the same dual-trigger but avoided duplication due to timing ## Test plan - [ ] Verify the skill file parses correctly (valid markdown, consistent structure) - [ ] In future dual-event scenarios (`pull_request_review` + `pull_request_review_comment`), the second run should detect the first's reply and exit silently 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: continuous-bot <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: tend-agent <[email protected]>
|
Yes — there are 22 snapshot tests for prune, including That's because the refactor only changed the execution order (parallel vs sequential) — the output format, candidate selection, and summary messages are all unchanged. The |
Summary
step pruneusing rayon'spar_iter(), matching the pattern already used bywt listThe reporter had 112 local branches with
step prunetaking ~3 minutes. Each non-trivially-integrated branch hitsgit merge-treeandgit patch-id(500ms–2s each), and these were running sequentially. With parallelization, this should drop to seconds.Closes #1888
Test plan
🤖 Generated with Claude Code