Skip to content

feat(gradient): range-aware file read deduplication#120

Merged
BYK merged 1 commit intomainfrom
feat/range-aware-read-dedup
May 2, 2026
Merged

feat(gradient): range-aware file read deduplication#120
BYK merged 1 commit intomainfrom
feat/range-aware-read-dedup

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 2, 2026

Summary

  • Replace path-only file dedup with range-aware coverage checks that consider offset/limit parameters on read tool inputs
  • Earlier reads are only collapsed when a later read covers the same or wider line range (full-file covers everything; ranged reads use interval superset check)
  • Prevents over-deduplication where a narrow later read would incorrectly collapse an earlier full-file read

New helpers

  • ReadRange type — { path, offset, limit } tuple for read tool inputs
  • extractReadRange() — parses tool input JSON to extract path + line range
  • laterReadCovers(later, earlier) — exported range coverage check with comprehensive edge case handling (full-file, open-ended, bounded intervals)
  • rangeLabel() — formats range info for dedup annotations (e.g., "lines 10-49")

Changes to deduplicateToolOutputs()

The simple fileLatest Map (path → latest index) is replaced with a per-file list of ReadRange entries. The second pass checks whether any later read covers the current read's range using laterReadCovers(), instead of just comparing latest message index by path.

Annotation text updated from "earlier version of" to "earlier read of" with optional range info.

Test coverage

  • 12 unit tests for laterReadCovers() covering all combinations: full-file ↔ full-file, full-file ↔ ranged, ranged ↔ ranged, non-overlapping, open-ended, different paths
  • 10 integration tests for range-aware dedup scenarios: full-file covers ranged, ranged doesn't cover full-file, wider covers narrower, non-overlapping both kept, annotation formatting, read_file tool name compatibility
  • All 5 existing dedup tests updated for new annotation text

Closes #117

Replace path-only file dedup with range-aware coverage checks that
consider offset/limit parameters. Earlier reads are only collapsed
when a later read covers the same or wider line range, preventing
over-deduplication where a narrow later read would incorrectly
collapse an earlier full-file read.

Closes #117
@BYK BYK enabled auto-merge (squash) May 2, 2026 23:23
@BYK BYK merged commit 45b3ee4 into main May 2, 2026
1 check passed
@BYK BYK deleted the feat/range-aware-read-dedup branch May 2, 2026 23:23
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.

feat: collapse duplicate file reads in gradient transform

1 participant