# The Day a Scheduled AI Agent Erased 31,000 Lines — append-only discipline and verify-first detection

> Source: <https://dev.to/kanta13jp1/the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-verify-first-detection-2pj6>
> Published: 2026-11-28 15:34:28+00:00

**Recommendation:** Give scheduled agents append-only edit tools anchored on a unique tail string, and add a pre-receive or CI check that blocks any tracked file shrinking beyond a set line threshold.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

Automated AI agents are convenient — until a task as simple as "update a file" turns into a destructive operation. This post uses a real **ROADMAP truncation incident** from our operations to explain the **append-only discipline** that keeps scheduled agents from destroying large shared files, and the **verify-first** pattern that caught the damage immediately.

Our growth-strategy log, `GROWTH_STRATEGY_ROADMAP.md`, had grown to a single file of **31,323 lines**. Then, **52 seconds after** a PR was merged to main, a scheduled "roadmap update" agent fired an automated commit.

The commit looked like this:

```
1 insertion(+), 31,318 deletions(-)
```

The file was wiped down to a few header lines. The cause was simple: the agent wrote back an "updated" version with a **full Write (whole-file overwrite)** without reading the existing content first. Right after the merge its checkout hadn't caught up, so the agent treated near-empty content as the source of truth and overwrote everything.

What saved us was an operating rule: **treat the prompt's premises as hypotheses and always cross-check them against date / KPI / git / PR / issue state**. At the start of the next session, the state check flagged "the ROADMAP is abnormally short" instantly, and it was handled as an incident.

Recovery itself was a one-liner thanks to git:

```
# Restore the file from the last-good commit
git show <last-good-commit>:docs/GROWTH_STRATEGY_ROADMAP.md > docs/GROWTH_STRATEGY_ROADMAP.md
```

Rebuilding 31,000 lines by hand would be impossible. git's immutability is a textbook case of protecting "capital = time."

For large append-only record files (roadmaps, changelogs, ops logs), **never allow an automated agent to full Write**. Allow only tail appends.

| Operation | On a large shared file | 
|---|---|
| Tail append (anchored) | ✅ safe | 
| Local edit on a unique anchor | ⚠️ ok if the anchor is unique | 
| Whole-file overwrite (full Write) | ❌ forbidden (source of truncation) | 

In practice, restrict the agent's edit tool to "append anchored on a unique tail string." In the very session behind this post, the ROADMAP entry was written **without re-reading any of the 31,364 lines** — anchored on the unique last line and appended (no full read, no full Write).

Don't rely on human eyes — **mechanically reject mass deletions** in CI / a pre-receive hook.

```
# Example: fail if a tracked file shrinks by more than N lines
THRESHOLD=500
before=$(git show "$BASE:docs/GROWTH_STRATEGY_ROADMAP.md" | wc -l)
after=$(wc -l < docs/GROWTH_STRATEGY_ROADMAP.md)
if [ $((before - after)) -gt $THRESHOLD ]; then
  echo "::error::ROADMAP shrank by $((before - after)) lines — block destructive overwrite"
  exit 1
fi
```

Following an existing regression-guard pattern lets you stop the whole class of "a grown file shrinks by accident" across the repo.

A single 31,000-line markdown file is risky on every axis — editing, diffing, and blast radius when something goes wrong. Split by period (e.g. `ROADMAP_2026H1.md`) to keep the live file small and shrink the blast radius of any single incident.

Automation trades speed for the risk of a "self-driving destructive operation." Build the safety valve in two layers: a design that **limits the agent to appends only**, and a guard that **mechanically rejects anomalies**.
