Repository navigation
fix(security): refuse an overwrite when its backup can't be made - #4314
Conversation
Overwrites went ahead when the backup failed (full disk, unwritable cache), and the tool result looked identical to a backed-up write, even though the Agent UI auto-approves overwrites on the promise of that backup. Now the write is refused with an error naming the cause, and the file is left unchanged. - backup_file raises BackupError instead of returning None, so "nothing to back up" and "backup failed" are no longer the same answer; every file tool already turns the exception into a status=error result before writing. - Backup names carry microseconds and step past an existing name, so two edits in the same second keep two generations instead of clobbering one. The prune pattern still matches the older second-resolution names. Fixes amd#4232
Verdict: Request changesGood fix, and the right instinct: an overwrite auto-approved on the promise of a backup must not proceed when that promise can't be kept. One follow-on effect needs handling before merge. The blocking issue — a full disk teaches the agent a permanent lie. The new refusal comes back as a plain error, and GAIA's memory layer can't tell "this tool is refusing, nothing ran" from "this tool ran and failed." So a one-off disk-full or unwritable-cache moment gets written into the agent's long-term memory as a durable "writing this file is broken" lesson, replayed into every later prompt long after the disk is freed. Refusals elsewhere in these same tools already declare themselves as not-executed; this one needs to as well. Two smaller things worth fixing in the same pass: a copy that dies partway through leaves a truncated backup file sitting in the keep-the-newest-five rotation, where it can push out a good backup and later look like a valid restore point; and the new "no backup, no write" guarantee is documented for some of the file tools but not the others that now behave the same way. Real-world evidenceN/A — no evidence bundle was produced for this run, and the change is a core library behaviour with no new CLI, REST, or Agent UI surface. The verdict rests on static review plus the unit tests the PR adds; I could not execute them here (no pytest in this environment), so the PR's own "166 passed" result is the only test signal. The unchecked 🔍 Technical details🟡 A backup refusal is stored as durable agent knowledge
The except BackupError as e:
path_validator.audit_write("write", str(file_path), 0, "denied", str(e))
return {**NOT_EXECUTED, "status": "error", "error": str(e)}All eight call sites: Worth a test asserting 🟡 A half-written backup survives the failure it caused (src/gaia/security.py:1093)
(needs 🟢 The linked doc section doesn't carry the new guarantee
🟢 Four write tools changed behaviour without a doc update
🟢 Only the
|
A full disk taught the agent a lasting lie. The refusal came back as a plain
{"status": "error"}, and check_was_executed defaults a result with no executed
key to "it ran and failed" — so MemoryMixin stored a one-off ENOSPC under
"Known errors to avoid" and replayed it into every later prompt, long after
the disk was freed. Neither "No space left on device" nor "Permission denied"
matches a transient marker, so nothing filtered it out.
All eight tools that back up before writing now spread NOT_EXECUTED into the
refusal, the same as the validate_write denial directly above each of them.
A copy that died mid-stream also left a truncated .bak behind. It still
matched the rotation glob, so it counted as a generation and could evict a
good backup, leaving the user restoring from a silently truncated file.
|
The blocking issue was real and is fixed: a one-off full disk really would have been written into the agent's long-term memory as a durable "writing this file is broken" lesson. I traced the whole path before changing anything. The refusal returned a bare Also fixed the truncated-backup case — a copy that died mid-stream left a Docs: rather than repeating the sentence per tool, the link target that was missing the guarantee ( Test evidenceEleven tests fail on the pre-fix branch and pass after — the eight tool paths, the truncated backup, and the two existing refusal tests now that they assert the memory gate: Broader sweep (13 files — file tools, security, memory, verification): 797 passed, 7 skipped, 1 failure unrelated and pre-existing ( 🔍 Technical detailsAll eight In The new test class assert result["executed"] is False
assert not check_was_executed(result)
I did not take the suggestion to collapse the edit-path tests into one parametrized case separate from the write paths; the single parametrization above covers all eight in one test instead. |
Before: when the backup failed (full disk, or a cache directory GAIA can't write), the overwrite went ahead anyway. The tool result looked exactly like a backed-up write, even though the Agent UI auto-approves overwrites because it expects a backup. After: the write is refused, the file is left unchanged, and the error names the cause and the fix. Backup names also carry microseconds now, so two edits in the same second keep two backups instead of one overwriting the other.
Overlaps with #4029, which edits nearby lines in
file_io_tools.pybut doesn't change backup behaviour. Whichever merges second needs a small rebase.Test plan
pytest tests/unit/test_file_write_guardrails.py tests/unit/test_security_edge_cases.py -q→ 166 passed, 7 skipped. 4 new tests fail onmain: a failed backup raises,write_filerefuses (tested in both file-tool mixins), and two same-second backups don't collide.test_file_tools.py,test_file_io_confinement.py, andagents/test_file_write_state.py) → 716 passed, 7 skippedsecurity.py(exit 0)gaia eval agent: a failed backup now returns a different tool result to the modelFixes #4232