Skip to content

fix(edit): validate args, preserve CRLF, allow truly-empty result (#401, #404, #409)#417

Merged
justrach merged 4 commits intomainfrom
fix/edit-batch
May 5, 2026
Merged

fix(edit): validate args, preserve CRLF, allow truly-empty result (#401, #404, #409)#417
justrach merged 4 commits intomainfrom
fix/edit-batch

Conversation

@justrach
Copy link
Copy Markdown
Owner

@justrach justrach commented May 5, 2026

Closes #401, #404, #409. Three coherent fixes to applyEdit's args validation, line-ending preservation, and zero-byte result handling. All 3 issue tests pass; full suite green.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 547150 563989 +3.08% +16839 OK
codedb_changes 60085 59795 -0.48% -290 OK
codedb_deps 9726 11185 +15.00% +1459 NOISE
codedb_edit 6354 6105 -3.92% -249 OK
codedb_find 67654 80198 +18.54% +12544 NOISE
codedb_hot 104418 113144 +8.36% +8726 OK
codedb_outline 297335 313643 +5.48% +16308 OK
codedb_read 92138 99945 +8.47% +7807 OK
codedb_search 178342 192099 +7.71% +13757 OK
codedb_snapshot 287793 286617 -0.41% -1176 OK
codedb_status 97546 93571 -4.08% -3975 OK
codedb_symbol 63591 67811 +6.64% +4220 OK
codedb_tree 70499 51242 -27.32% -19257 OK
codedb_word 73081 79454 +8.72% +6373 OK

justrach and others added 4 commits May 5, 2026 11:30
…suming seq

When applyEdit is called with op=.insert and after=null, the switch case
falls through without modifying the line buffer, but the function still
proceeds to atomically rewrite the file and call recordEdit. The result is
a phantom store entry (seq incremented, ChangeEntry recorded) for an
operation that did nothing visible. This pollutes changesSince() and
makes seq numbers unreliable as causality markers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…yEdit

When applyEdit operates on a CRLF file, splitScalar('\n') leaves the
trailing '\r' attached to each unchanged line. The new replacement line
inherits whatever line ending the caller supplied (typically none / LF),
and the rejoin uses bare '\n'. Result: the on-disk file has mixed CRLF
on unchanged lines and bare LF on changed lines, breaking tools that
detect file-wide line ending style.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When applyEdit replaces the only line of a file with empty content, the
post-processing unconditionally restores the source's trailing newline.
The result is that 'replace line 1..1 with ""' on file 'abc\n' leaves
'\n' on disk instead of an empty file. Callers asking for an empty file
get a non-empty file.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…, #404, #409)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@justrach justrach merged commit 940c38f into main May 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 516225 511635 -0.89% -4590 OK
codedb_changes 55860 52392 -6.21% -3468 OK
codedb_deps 9106 8910 -2.15% -196 OK
codedb_edit 5282 5673 +7.40% +391 OK
codedb_find 60566 59730 -1.38% -836 OK
codedb_hot 96990 97399 +0.42% +409 OK
codedb_outline 286111 278148 -2.78% -7963 OK
codedb_read 89366 90441 +1.20% +1075 OK
codedb_search 178656 175920 -1.53% -2736 OK
codedb_snapshot 272684 280948 +3.03% +8264 OK
codedb_status 204729 203174 -0.76% -1555 OK
codedb_symbol 66298 59590 -10.12% -6708 OK
codedb_tree 67332 48927 -27.33% -18405 OK
codedb_word 69759 72664 +4.16% +2905 OK

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.

edit: applyEdit insert with after=null silently consumes seq and rewrites file

1 participant