Skip to content

fix: keep one assignment per file when merging chunk groups - #68

Merged
vitali87 merged 7 commits into
mainfrom
fix/duplicate-file-assignments
Aug 31, 2026
Merged

fix: keep one assignment per file when merging chunk groups#68
vitali87 merged 7 commits into
mainfrom
fix/duplicate-file-assignments

Conversation

@vitali87

Copy link
Copy Markdown
Owner

Problem

For diffs that exceed the context window, _plan_split_chunked merges each chunk's groups into the running catalog with _merge_chunk_groups, which did existing.assignments.extend(cg.assignments). When chunk N+1 assigns more hunks of a file to a group id that already holds that file, the group ends up with two GroupAssignments for one path, e.g. f.py [0] and f.py [1].

validate_coverage passes (each hunk is claimed exactly once), but materialize_group_files did result[path] = apply_hunks(...) per assignment, so the second write replaced the first and hunk 0 was silently missing from the committed sub-PR branch. No error anywhere — the sub-PR just lacks part of the change.

Fix

  • _merge_chunk_groups now merges same-path assignments: union of hunk_indices, WHOLE_FILE wins over PARTIAL_HUNKS.
  • materialize_group_files groups assignments by path and writes each file once from the union of every assignment's hunks (_assigned_hunk_indices), so a duplicate from any source (chunk merge, LLM output, hand-edited plan) can no longer drop hunks. Base content is fetched once per file instead of once per assignment.

Tests

  • chunk merge: same file across chunks → one assignment [0, 1]; WHOLE_FILE + PARTIAL → WHOLE_FILE; unrelated files untouched
  • materialization: two assignments for one existing file apply both hunks (and git show runs once); duplicate assignments on a new file produce the full file

3 of 5 fail without the fix. 449 tests pass, ruff clean.

When a later diff chunk assigned more hunks of a file to a group that
already held that file, _merge_chunk_groups appended a second
GroupAssignment for the same path. validate_coverage accepted it (each
hunk claimed once) but materialize_group_files wrote the file once per
assignment, so the last assignment overwrote the first and the earlier
hunks were silently missing from the committed branch.

- _merge_chunk_groups merges same-path assignments (union of hunks,
  WHOLE_FILE wins).
- materialize_group_files groups assignments by path and writes each
  file once from the union of their hunks, so duplicates from any source
  can no longer drop changes.
@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 48 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 165da7cc-e4fc-47c2-8256-7266fead4636

📥 Commits

Reviewing files that changed from the base of the PR and between d14675a and 2ceadb8.

📒 Files selected for processing (4)
  • pr_split/diff_ops/reconstructor.py
  • pr_split/planner/client.py
  • tests/test_client.py
  • tests/test_reconstructor.py

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.

Seeding the per-path map with a dict comprehension kept only the last
existing assignment for a path, so duplicates already present in the
accumulated group (chunk 1 output is stored verbatim) lost hunks. Fold
every existing and incoming assignment through _merge_assignment.
@vitali87
vitali87 merged commit 7878a8d into main Aug 31, 2026
4 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.

1 participant