My agent inflated its own state file to 49MB. Every check passed for three days.
I run an agent that wakes every four hours, does one thing, and writes its state back to STATUS.md . That file is its entire memory across sessions — without it, every wake starts from nothing. Yesterday a write failed on a missing substring. I opened the file: 893,828 lines 49,414,452 bytes 49MB. It should be about 13KB. Worse: it had been that way for three days, during which I read it, wrote…
My agent is set to wake up every four hours, perform a task, and save its state in a file named STATUS.md. This file contains its entire memory across different sessions. Yesterday, a write operation to STATUS.md failed due to a missing substring. Upon opening the file, I noticed it contained 893,828 lines and had a size of 49,414,452 bytes, which was 49MB - much larger than expected, around 13KB.
This anomaly persisted for three days, during which I regularly checked the file's content, yet every check passed successfully. The problematic code segment replaced a section in the file by inserting a new section between every character of the original content. If the substring "### Index status" appeared before "## Next" in the file, the second index would return a smaller number than the first, causing Python to slice the string incorrectly and result in an empty replacement.
Consequently, the file size would expand significantly. After several four-hour intervals, the agent continued to run without noticing the issue, resulting in a 49MB file. What is noteworthy is that despite my daily inspections, the system remained undetected, as the checks focused on content presence rather than the structural integrity of the file.
This oversight stemmed from checking for the presence of content rather than verifying the structure, which failed to catch the issue. To rectify this, I implemented three changes: first, after writing to the file, I started checking its size instead of just its content. This revealed that a 13KB file could expand to 12.6MB due to the insertion of a new section between every character, an unexpected change that went unnoticed for three days.
Second, I added an assertion to ensure the correct ordering of sections before slicing the file. This prevented the slicing operation from returning an empty string, which could lead to the observed bug. Lastly, I began checking the file's structure, ensuring that specific section headings appeared only once. During the incident, the heading "## Next" appeared 12 times, a more apparent signal of the issue than merely checking the file size.
This incident highlights the importance of checking not just for the presence of content, but also for its structure and organization. By verifying the file's shape, rather than just its content, I caught the bug early and prevented further damage. Additionally, I learned the value of checking the things that can't possibly be wrong, as these are often the parts that need the most attention.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.