Skip to content

sandbox edit: keep the file's line endings - #3567

Merged
BaseMax merged 2 commits into
mainfrom
fix/sandbox-edit-newlines
Nov 17, 2026
Merged

BaseMax merged 2 commits into
mainfrom
fix/sandbox-edit-newlines

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

The edit helper opened files in Python text mode, which turns CRLF into LF on read and rewrites the whole file with LF. It now opens with newline='' for read and write, so only the replaced text changes.

Examples: a CRLF file edited with old_text b and new_text X keeps a\r\nX\r\nc\r\n byte for byte (checked by running the helper's Python on such a file).

Tested: ran the embedded Python against a CRLF file and compared bytes; the test suite has no sandbox to run it through.

Summary by CodeRabbit

  • Bug Fixes
    • Text edits now preserve a file’s existing line-ending format, helping avoid unintended newline changes when replacing text. Existing behavior for missing files, unmatched text, and ambiguous matches remains unchanged.

@BaseMax
BaseMax requested a review from a team as a code owner November 17, 2026 11:24
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

EDIT_SCRIPT now opens files with newline='' for reading and writing. Its existing match checks, error exits, and replacement-count output remain unchanged.

Changes: Script Edit Behavior

Layer / File(s) Summary
Preserve newline sequences
ai/backend/cloud.salam
EDIT_SCRIPT reads and writes files with newline='' during text replacement.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Change: Bug fix

Suggested reviewers: bdadmehr0, erfangnu

Merge Risk: Low · up to 15712

Edits no longer convert CRLF files to LF, but multi-line edits written with LF will now fail to match in CRLF files, and a few edge cases can leave a stray CR or skip the ambiguity check. This is mergeable with awareness; consider normalized matching as a follow-up.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@BaseMax
BaseMax merged commit ebce9a6 into main Nov 17, 2026
4 of 5 checks passed
@BaseMax
BaseMax deleted the fix/sandbox-edit-newlines branch November 17, 2026 11:27
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