fix(tui): actionable File edit diagnostics and stale-line-number tolerance (#5003) - #5008
Merged
Merged
Conversation
…rance (Hmbown#5003) edit_file: - search==replace now sizes the payload and offers recovery guidance so the model self-corrects instead of retrying the same no-op call. - "Search string not found" previews the first lines of the search text so the model can compare it against the file's actual contents. - refuse payloads that would change the C/C++ preprocessor conditional balance (#if/#ifdef/#ifndef vs #endif), catching the #if 0 orphan-#endif corruption that previously applied with success. apply_patch: - when positional fuzz fails and the hunk carries enough anchor lines (>= MIN_ANCHOR_LINES), relocate to a unique whole-file context match, covering stale line numbers after earlier edits; ambiguous context is refused with the candidate lines listed instead of guessing. - NoMatch hints mention stale line numbers; relocation is reported in PatchResult/FileSummary and the summary message. Verified: cargo fmt clean; clippy adds no warnings; 1374 tools:: tests pass, including new relocation/ambiguity unit+integration tests and an end-to-end CRLF + Chinese-comment scenario.
SparkofSpike
force-pushed
the
fix/file-edit-reliability-5003
branch
from
July 31, 2026 16:12
db909e5 to
7698265
Compare
event-listener 5.4.1 has an unsound StackSlot Send/Sync advisory. Bumping it in this PR would change Cargo.lock's hash, which misses the rust-cache seeded by main and breaks the offline runtime-contract-budget gate (assert-json-diff download failure). Keep Cargo.lock byte-identical to main and track the dependency bump as a separate PR instead.
SparkofSpike
force-pushed
the
fix/file-edit-reliability-5003
branch
from
July 31, 2026 16:24
7698265 to
3554d9c
Compare
Contributor
Author
|
PTAL @Hmbown the Could you take a look when you have a moment? Happy to adjust if anything comes up. |
SparkofSpike
marked this pull request as ready for review
July 31, 2026 16:52
Fork branch now tracks latest main (incl. Hmbown#5001/Hmbown#4981) plus the Hmbown#5003 fix; measured owned Rust lines grew to 645329. Ratchet update: 644756 -> 645500.
This reverts commit 3554d9c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5003. The report described a model repeatedly failing to apply large
(100+ line) replacements to a C file with Chinese comments and CRLF line
endings: 15+ failed
Filetool attempts, 3 fullgit checkoutrollbacks,and an eventual workaround via an external Python script. All four failure
modes are addressed so the tools either succeed or fail with diagnostics the
model can act on.
Changes
search == replacenow sizes the payload and offers recovery —the error reports character/line counts, names the root cause (
replacecopied verbatim from
search), and recommendsapply_patchfor largemulti-line rewrites, so the model self-corrects instead of retrying the
same no-op call.
Search string not foundpreviews the search text — theerror shows the first 3 lines of the search payload (80 chars per line), so
the model can compare what it searched for against the file's contents.
must preserve the net
#if/#ifdef/#ifndefvs#endifbalance of thesearch span, catching the truncated
#if 0edit that previously appliedwith success and orphaned an
#endif. Balanced local edits (e.g. a one-line#if 0→#if 1toggle) are unaffected.and the hunk carries at least
MIN_ANCHOR_LINES(4) expected lines, thehunk is relocated to a unique whole-file context match; ambiguous context
(multiple matches) is refused with the candidate lines listed instead of
guessing.
NoMatchnow mentions that line numbers may be stale after earlier edits and
suggests re-reading the file; relocated hunks are reported in
PatchResult/FileSummaryand the summary message.Type of Change
Testing
cargo fmt— clean (no diffs)cargo clippy -p codewhale-tui --bin codewhale-tui --locked— no new warnings from this change (5 pre-existing warnings live incrates/tui/src/tui/views/fleet_setup.rs, untouched)cargo test -p codewhale-tui --bin codewhale-tui --locked tools::— 1374 passed, 0 failed (includes 6 new tests: relocation, ambiguous context, short-anchor no-relocation, and an end-to-end CRLF + Chinese-comment scenario)search==replacediagnostics, Chinese+CRLF replacement,#iftruncationrejection, search preview, stale-line relocation, ambiguous-context refusal
Note: the full
--workspacegate was not run in this session; the focusedcodewhale-tuitool gates above were executed and passed.Checklist
apply_patch.rs/file.rs)Related Issues
Closes #5003