Repository navigation
fix(tools): stop file edits rewriting every line ending in the file - #4864
Conversation
`open()` in text mode, and `Path.read_text` / `Path.write_text`, use universal newlines by default. Reading turns every CRLF into LF; writing turns every LF into `os.linesep`. None of the text I/O sites in `file_io_tools.py` or `file_tools.py` passed `newline=`, so on Windows a one-line `edit_file` against an LF-terminated file wrote the whole file back as CRLF. The text is identical on screen, which is why this is easy to miss, but every byte-comparing tool disagrees: a three-line change to a 400-line file is reported as 400 lines changed. That is enough to bury the real edit in a review diff, and an agent re-reading the file afterwards no longer finds the text it remembers, so its next exact-match edit fails for a reason nothing reports. Reproduced with a 200-line LF file and a single `edit_file` call: 200 lines modified, expected 1. Every read and write that feeds a read/modify/write round trip now passes `newline=""`, so bytes go in and out untranslated and a file keeps the endings it already had. The `pathlib` sites cannot take `newline=`, so they go through small `_read_exact` / `_write_exact` helpers instead. `replace_function` splices in generated text that is always LF, so it now converts that block to the file's own endings rather than leaving the file with a mix of both. Reading exactly makes the match in `apply_unique_replacement` stricter, because `read_file` still normalises what it shows the model. A multi-line `old_content` copied from it is therefore LF even when the file is CRLF, and matching it byte-for-byte would refuse an edit that is correct in every way that matters. A failed match is now retried once with `old_content` rewritten to the file's own endings, and accepted only if that matches exactly one place, so nothing ambiguous is guessed at. The replacement text is rewritten the same way, so the repaired edit cannot reintroduce a mix. Tests assert on raw bytes, since the decoded text is the same either way, and cover both directions — an LF file must stay LF and a CRLF file must stay CRLF, so the fix cannot be "normalise everything to LF" — plus both directions of the retargeted match. ## Test plan - [x] `pytest tests/unit/test_file_io_line_endings.py tests/unit/agents/test_file_edit_semantics.py tests/unit/agents/test_read_file_line_ranges.py tests/unit/agents/test_file_tools_text_encoding.py` — 125 passed - [x] `pytest tests/unit -k "file or edit or text or io"` — no new failures against the same selection on `main` - [x] `python util/lint.py --black --isort` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Verdict: Request changes Agent file edits no longer rewrite every line ending in the file. Reads and writes now pass bytes through unchanged, and the tests check raw bytes in both directions. One gap remains: a CRLF file can still come out with mixed line endings after an ordinary edit, and the diff preview now has the whole-file problem this PR fixes elsewhere.
Real-world evidenceN/A: the evidence stage reports no CLI, API or MCP surface changed. The verdict rests on static review and the PR's unit-test runs. The Windows CI item in the PR's test plan is still unchecked, and Windows is the platform this bug affects. 🔍 Technical details🟡 New content is only converted to the file's endings on the retry path (
Also add a test: a CRLF file, single-line 🟡 Since this change, 🟢 Duplicated helpers
🟢 Behaviour change worth noting: Strengths
|
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# GAIA v0.25.0 Release Notes ## Breaking Changes - **`gaia chat` runs the flagship GAIA agent**, the same agent as the TUI and Agent UI, instead of the retired ChatAgent. `gaia chat -q "…"` queries it once. (PR [amd#4520](amd#4520)) - **`gaia talk` transcribes and speaks through Lemonade** — it uses Lemonade's Whisper and `kokoro-v1`, and stops with the reason if Lemonade is down. The `[audio]` extra is gone; `pip install amd-gaia[audio]` only warns. (PR [amd#4665](amd#4665)) - **The Agent UI runs only the GAIA agent** — the Agent Hub home, agent picker, and custom-agent export/import are removed from the UI. The CLI and eval harness can still run other agents. (PR [amd#4509](amd#4509)) - **The retired nomic embedder is removed** — memory saved with it is re-embedded on first start. (PR [amd#4489](amd#4489)) - **Indexed documents are re-indexed once** — the document cache is now keyed on chunking settings, so the first query after upgrading rebuilds it. (PR [amd#4624](amd#4624)) - **A skill that asks for more than its tier allows no longer loads** — the permission ceiling is checked at every load, so a skill already on disk that exceeds it is refused with the reason. (PR [amd#4849](amd#4849)) ## What's New - **A larger local model where the GPU holds it** — `gaia init` picks Qwen3.6-35B-A3B on a 64 GB+ Strix Halo or a 32 GB GPU and keeps Gemma-4-E4B elsewhere, with each context window sized to available memory. Qwen3.8 Flash Next is opt-in on 128 GB Strix Halo. (PRs [amd#4479](amd#4479), [amd#4670](amd#4670), [amd#4671](amd#4671), [amd#4658](amd#4658), [amd#4655](amd#4655)) - **The Agent UI opens straight to a chat and sets itself up** — a fresh install runs the same setup steps as the TUI in the window, with provider, key and model settings, permission modes, and revocable "always allow" grants. (PR [amd#4509](amd#4509)) - **A much smaller install** — PyTorch, transformers and accelerate are gone from the core, `[ui]` and `[talk]` installs; the desktop app's Python environment drops from ~0.9 GB to ~0.1 GB on Windows. (PRs [amd#4666](amd#4666), [amd#4621](amd#4621), [amd#4665](amd#4665)) - **One Windows installer for the desktop app and the terminal**, with a GAIA Windows Terminal profile. (PRs [amd#4720](amd#4720), [amd#4707](amd#4707)) - **A "no" holds** — a declined action isn't retried through another tool; the agent asks again with the exact command. The TUI gains Shift+Tab permission modes. (PRs [amd#4460](amd#4460), [amd#4461](amd#4461)) - **Answers are checked against what the tools actually did** — the agent looks at files you name before answering about them, and a short plain-English note appears only when work isn't confirmed. (PRs [amd#4532](amd#4532), [amd#4501](amd#4501), [amd#4508](amd#4508)) - **One shell session** — commands share a persistent shell, risky ones ask instead of being refused, and "full access" is one setting everywhere. (PR [amd#4408](amd#4408)) - **Memory surfaces what's relevant to each request, with its age**, keeps what fixed a failure as a lesson for that workspace, and extracts after the answer instead of before it. (PRs [amd#4061](amd#4061), [amd#4066](amd#4066), [amd#4406](amd#4406)) - **`gaia.log` stays bounded** — it rotates at 10 MB with three backups (`GAIA_LOG_MAX_MB`, `GAIA_LOG_BACKUPS`). (PRs [amd#4668](amd#4668), [amd#4760](amd#4760)) - **Child processes get a trimmed environment** — shell, MCP and skill children no longer inherit GAIA's internal credentials; `GAIA_NO_DOTENV` skips loading `.env`. (PRs [amd#4635](amd#4635), [amd#4659](amd#4659)) - **Every file tool checks the allowed-folders rule**, and paths inside an inline shell script are checked one by one. (PRs [amd#4656](amd#4656), [amd#4758](amd#4758)) ## Bug Fixes A selection of the user-visible fixes; the full list is in the changelog below. - **Local Qwen models no longer loop on repeated tool calls** — they run with their model card's sampling instead of near-greedy settings. (PR [amd#4655](amd#4655)) - **Qwen3.6 runs on a Strix Halo with an older AMD driver** — it used to crash on its first token, so `gaia init` failed; GAIA now turns off the Vulkan path that crashes on those drivers only, and newer drivers keep the faster path. (PR [amd#4674](amd#4674)) - **A long PDF no longer hangs or times out while indexing** — big documents index in the background, and PDFs that only carry owner-password restrictions now index. (PRs [amd#4754](amd#4754), [amd#4679](amd#4679), [amd#4734](amd#4734)) - **Document answers cite the right document and page**, and every chunk is embedded whole instead of its first 1,200 characters. (PRs [amd#4688](amd#4688), [amd#4723](amd#4723)) - **`gaia init` fails when model verification fails**, shows downloads live, and no longer hangs while Lemonade hashes a large model. (PRs [amd#4620](amd#4620), [amd#4564](amd#4564), [amd#4673](amd#4673)) - **`gaia init` adds a profile's extras without reinstalling GAIA**, which failed on Windows while `gaia.exe` was running. (PR [amd#4672](amd#4672)) - **Every SDK and CLI entry point starts GAIA's own Lemonade**, and every call goes to the resolved URL with its API key. (PRs [amd#4657](amd#4657), [amd#4627](amd#4627)) - **Local chat stays cached across turns** — the system prompt is fixed and side requests no longer evict the conversation. (PRs [amd#4698](amd#4698), [amd#4543](amd#4543)) - **A cloud model selection never preloads a local model**, and cloud models no longer get llama.cpp-only fields. (PRs [amd#4757](amd#4757), [amd#4709](amd#4709)) - **The Agent UI stops claiming "100% local" while chat goes to a cloud model**, and the chat header names the session's real model. (PRs [amd#4711](amd#4711), [amd#4550](amd#4550)) - **Enter can't approve a permission prompt**, and prompts wait 10 minutes before timing out. (PRs [amd#4700](amd#4700), [amd#4699](amd#4699)) - **Stopping a run keeps the turn and its steps visible.** (PR [amd#4743](amd#4743)) - **A file edit keeps the file's line endings** — a one-line edit on Windows used to rewrite every line ending, so a small change showed up as the whole file changed. (PR [amd#4864](amd#4864)) - **A broken agent install is reported as broken, not as missing** — the error names both package versions and the real import error, and suggests a reinstall that works. (PR [amd#4588](amd#4588)) - **A meeting or document summary is never cut off mid-sentence** — a thinking model used to spend the summary's output budget reasoning, so a long meeting lost its second half. (PR [amd#4827](amd#4827)) - **"What can you do?" gets an answer** instead of an attempt to generate an image of the question. (PR [amd#4809](amd#4809)) - **Writes and approved edits can't reach credential folders** (`~/.ssh`, `~/.aws`, `~/.kube` and others), and shell option values and script arguments get the same path check as plain paths. (PRs [amd#4848](amd#4848), [amd#4847](amd#4847)) - **`gaia connectors connect google --grant-agent installed:gaia` works** — it used to fail with no sign-in link for the shipped agent; it now asks for read-only Gmail and grants exactly that. (PR [amd#4859](amd#4859)) - **A "no" to creating a folder also covers writing into it** — GAIA no longer asks again to create the same folder a different way. (PR [amd#4857](amd#4857)) - **`gaia skill import` runs the same checks as a hub install** — https only, the audit, the permission ceiling, and an explicit opt-in for skills that ship code. (PR [amd#4849](amd#4849)) - **Memory off and private chats apply to scheduled and background runs too.** (PRs [amd#4842](amd#4842), [amd#4821](amd#4821)) - **Memory stops false apologies and reusing deleted values**, saves "remember this" requests, and skips loading the embedder when memory is off. (PRs [amd#4708](amd#4708), [amd#4756](amd#4756)) - **A reply cut off by the token limit is continued** instead of ending mid-sentence, and a tool call cut off at the output cap is retried shorter. (PRs [amd#4054](amd#4054), [amd#4556](amd#4556)) - **The TUI remembers the chosen model** across restarts and agent-process restarts. (PRs [amd#4497](amd#4497), [amd#4710](amd#4710)) - **`gaia uninstall --purge` removes installer binaries, PATH edits and daemon state.** (PR [amd#4413](amd#4413)) ## Contributors Thanks to the community members who contributed to this release: - [@itomek](https://github.com/itomek) — the flagship's browser and tool picker, one shell session, memory extraction off the answer path, stale tool-result eviction, the TUI's sourced Fireworks rankings, and `--purge` cleanup (PRs [amd#4407](amd#4407), [amd#4408](amd#4408), [amd#4406](amd#4406), [amd#4465](amd#4465), [amd#4414](amd#4414), [amd#4413](amd#4413)) - [@mikemikimike](https://github.com/mikemikimike) — chained shell command timeouts, bundled skills in frozen builds, and sidecar cleanup reporting (PRs [amd#4463](amd#4463), [amd#4467](amd#4467), [amd#4419](amd#4419)) - [@Hashim1999164](https://github.com/Hashim1999164) — honoring `GAIA_HOME` for cache, chat and index paths (PR [amd#4381](amd#4381)) - [@krtadev](https://github.com/krtadev) — `~` expansion in file and document tool paths (PR [amd#4576](amd#4576)) - [@aksh8b](https://github.com/aksh8b) — telling a broken agent install apart from a missing one, with a reinstall hint that works (PR [amd#4588](amd#4588)) - [@Dev-next-gen](https://github.com/Dev-next-gen) — numeric prerelease ordering in the hub (PR [amd#4517](amd#4517)) - [@vianmangal](https://github.com/vianmangal) — recording denied tool calls as unsuccessful in memory (PR [amd#4412](amd#4412)) - [@GaetanVDB07](https://github.com/GaetanVDB07) — links to upstream credential setup guides for connectors (PR [amd#4669](amd#4669)) - [@rradjabi](https://github.com/rradjabi) — moving self-hosted CI jobs to the xsj-dispatch runner pool (PR [amd#4534](amd#4534)) ## Also in this PR - **Hub floors raised to core 0.25.0** — the chat agent imports the allowed-folders check that only 0.25.0 ships (amd#4656), so `gaia-agent-chat` goes to 0.2.0 with `amd-gaia>=0.25.0`, and the flagship requires `amd-gaia>=0.25.0` and `gaia-agent-chat>=0.2.0`. - **Two follow-ups held back until that floor could rise** — `~/.gaia/logs/gaia-agent.log` now rotates like `gaia.log` (amd#4668), and the chat agent's Python runners and Windows notification start their children without GAIA's internal credentials (amd#4659). The full changelog (300 commits) is in `docs/releases/v0.25.0.mdx`. ## Test plan - [x] `util/validate_release_notes.py docs/releases/v0.25.0.mdx --tag v0.25.0` passes; narrative is 590 words (cap 600) - [x] `util/check_component_core_api.py --release-version 0.25.0` passes - [x] `pytest tests/unit/test_docs_json_release.py tests/unit/test_check_component_core_api.py hub/agents/chat/python/tests/test_chat_dependency_floor.py hub/agents/chat/python/tests/test_dependency_floor.py hub/agents/gaia/python/tests/test_gen_binaries_lock.py` (72 passed) - [x] `pytest hub/agents/gaia/python/tests/test_stdio.py` (91 passed, incl. the new rotation test); `pytest tests/unit/test_execute_python_file_cwd.py tests/unit/test_run_python_tool.py` (42 passed) - [ ] `mintlify validate` (docs CI job) — timed out locally, relying on CI - [x] Full flagship eval on main 9ce6598 (https://github.com/amd/gaia/actions/runs/37436249503): 181/308 scenarios pass vs 100/183 for the same categories in the baseline, 39 FAIL→PASS, 13 PASS→FAIL (two fixed in amd#4878, held until after rc1); retrieval lane still finishing at merge time - [ ] CI green ## Release checklist - [ ] Publish `gaia-agent-chat` 0.2.0 only after core 0.25.0 is on PyPI — it fails at import on an older core - [ ] Build Installers on the merged SHA (pre-tag verification) before pushing `v0.25.0` - [ ] terminal-hub 0.25.0 published before the flagship npm release consumes `binaries.lock.json` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
…edits (amd#6607) ## Summary Diff previews and `edit_file` now respect a CRLF file's line endings: a one-line change on a Windows-style file diffs as one line, and a direct-match edit no longer leaves the file with mixed endings. ## Why amd#4864 started reading files with their original endings, but two paths were left out: - `generate_diff` read the original with `newline=""` (CRLF kept) and diffed it against the model's LF `new_content`, so every line of a CRLF file showed as deleted and re-added. The counts were wrong too, so a one-line change looked like a full rewrite. - `apply_unique_replacement` converted `new_content` to the file's endings only inside the line-ending retry branch. When `old_content` matched as-is (any single-line `old_content`), a multi-line LF replacement went into a CRLF file unchanged. ## Linked issue Closes amd#4871 ## Changes - `file_io_tools.generate_diff`: read the original with universal newlines and normalise `new_content` to LF before diffing. A diff is a preview, not a write round trip, so nothing on disk changes. - `file_edit.apply_unique_replacement`: when a one-line `old_content` matches directly on a line that ends in CRLF, retarget `new_content` to CRLF. The decision follows the matched line, not the whole file, so LF edits in a mostly-LF file with one stray CRLF line stay LF. A multi-line `old_content` already shows which endings it matched and is left alone. If it spells out CRLF, it's a deliberate line-ending edit (e.g. `test_line_ending_only_edit_still_draws_a_card`). - `generate_diff` docstring: notes that an endings-only change now diffs as no change. - `tests/unit/test_file_io_line_endings.py`: 6 regression tests (a direct-match edit on a CRLF file, a deliberate CRLF→LF edit that must be kept, single- and multi-line LF edits in a mostly-LF file with one CRLF line, a diff of a CRLF file with one change, a diff of an unchanged CRLF file). ## Test plan - [x] `pytest tests/unit/test_file_io_line_endings.py`: 16 passed (3 of the new tests fail on `main`; the others guard the deliberate-edit and mixed-file cases) - [x] `pytest tests/unit/agents/test_file_edit_semantics.py tests/unit/chat/ui/test_edit_diff_card.py tests/unit/test_relative_write_workspace.py tests/unit/test_host_attr_contract.py`: pass - [x] `pytest -n auto tests/unit/` (macOS, Python 3.12): 34,971 passed. The only failures are 2 in `test_schedule_missed_runs.py`, which fail the same way on unmodified `main` on this machine. - [x] `python util/lint.py --black --isort`: pass ## Evidence Direct calls to the registered `generate_diff` and `edit_file` tools on a 6-line CRLF file: ``` ## BEFORE (main) generate_diff on a 6-line CRLF file, 1 line changed -> additions=6 deletions=6 edit_file single-line match, LF replacement -> status=success CRLF=6 lone LF=1 ## AFTER (this branch) generate_diff on a 6-line CRLF file, 1 line changed -> additions=1 deletions=1 edit_file single-line match, LF replacement -> status=success CRLF=7 lone LF=0 ``` - **Agent UI**: N/A. The change is inside the file tools and adds no UI. The tool-level before/after is above. - **MCP / CLI / HTTP**: N/A. None of these surfaces changed. ## Checklist - [x] I have linked a GitHub issue above (`Closes #N` / `Fixes #N` / `Refs #N`). - [x] I have described **why** this change is being made, not just what changed. - [x] I have run linting and tests locally (`python util/lint.py --all`, `pytest tests/unit/`). - [x] I have attached **real-world evidence matched to the surface I changed** (see Evidence above), or marked each surface N/A. - [x] I have updated documentation if user-visible behavior changed (no docs change needed).
Branch:
fix/preserve-line-endings-in-file-toolsBase:
e0fd6717f609a5be7ca8676a6be2c869fd4fe4b2(e0fd6717f)Commits:
acaf4f3920b4044d0d632f26f9a556fd9eb58b02The problem
open()in text mode, andPath.read_text/Path.write_text, use universalnewlines by default. Reading turns every CRLF into LF; writing turns every LF
into
os.linesep. None of the text I/O sites infile_io_tools.pyorfile_tools.pypassednewline=.On Windows that means a single one-line
edit_fileagainst an LF-terminatedfile writes the whole file back as CRLF.
Nothing about this is visible on screen — the decoded text is identical either
way — which is why it has survived. The damage only shows up in a byte
comparison, and that is where it matters most:
The real edit is buried in a review diff, and any size-capped diff view drops
it entirely.
remembers, so its next exact-match edit fails for a reason nothing reports.
git diff --check) emit one warning per addedline, which reads as "my edit is corrupt".
Reproduction
Create a 200-line LF-terminated file, call
edit_fileonce to change one line,and diff:
The fix
Every read and write that feeds a read/modify/write round trip now passes
newline="", so bytes go in and out untranslated and a file keeps whateverendings it already had. The
pathlibsites cannot takenewline=, so they gothrough small
_read_exact/_write_exacthelpers instead.replace_functionsplices in generated text that is always LF-terminated, so itnow converts that block to the file's own endings rather than leaving the file
carrying both.
The matching change this forces, and why it belongs here
Reading exactly makes the match in
apply_unique_replacementstricter, becauseread_filestill normalises what it shows. A multi-lineold_contentcopiedfrom it is therefore LF even when the file on disk is CRLF, and matching it
byte-for-byte would start refusing edits that are correct in every way that
matters.
So a failed match is retried once with
old_contentrewritten to the file'sown endings, and accepted only if that matches exactly one place — nothing
ambiguous is guessed at. The replacement text is rewritten the same way, so a
repaired edit cannot reintroduce a mix.
Without this half, the first half is a regression. They ship together.
Deliberately not changed
read_filestill normalises what it displays. That is a presentation choice, itis not part of any round trip, and changing it would alter what every caller
sees for no corruption-related gain.
Tests
tests/unit/test_file_io_line_endings.pyasserts on raw bytes, since thedecoded text is the same either way. It covers both directions — an LF file must
stay LF and a CRLF file must stay CRLF — so the fix cannot be "normalise
everything to LF", which would be the same bug pointed the other way. Both
directions of the retargeted match are pinned too.
Risk
Low. The change is confined to how bytes are decoded and encoded at the I/O
boundary plus one retry path that only runs after a match has already failed.
Test plan
pytest tests/unit/test_file_io_line_endings.py tests/unit/agents/test_file_edit_semantics.py tests/unit/agents/test_file_tools_text_encoding.py tests/unit/agents/test_read_before_edit.py tests/unit/agents/test_write_reports_syntax.py tests/unit/test_file_tools.py tests/unit/test_file_write_guardrails.py tests/unit/test_file_io_confinement.py tests/unit/agents/test_image_outcome_guard.py tests/unit/eval/test_flagship_tasks.py::test_an_adversarial_task_rejects_the_shortcuton this branch alone — 504 passed, 7 skipped
tests/unit— see belowpython util/lint.py --black --isortFull unit suite
tests/unit, Windows,--timeout=300, run on unmodifiedmain(e0fd6717f)and on a disposable build with all four open branches stacked (line endings in file tools, step-budget notices, post-edit
read-back, model-endpoint retry):
maine0fd6717fThe same five tests fail on both, and none of them is touched by this branch:
three installer TUI-detection tests,
test_file_access_scope.py::test_no_allowlist_still_defaults_to_cwd,and
test_lemonade_asr.py::TestRealServer::test_real_transcription_round_trip,which needs a live server. No test fails on the stacked build that passes on
main.Stacking with other open branches
Applies cleanly to
mainon its own. It touches no file any of the other open branches above touch, so it stacks with them in any order without conflict.🤖 Generated with Claude Code