{"slug": "the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-first", "title": "The Day a Scheduled AI Agent Erased 31,000 Lines — append-only discipline and verify-first detection", "summary": "An engineering team reported that a scheduled AI agent erased 31,318 lines from a 31,323-line shared roadmap file 52 seconds after a PR merge, because the agent performed a whole-file Write without reading existing content and its checkout had not caught up. The team recovered the file from the last-good git commit and now restricts automated agents to anchored tail appends, backed by a CI or pre-receive hook that rejects any tracked file shrinking by more than a set line threshold.", "body_md": "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.\n\nOur 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.\n\nThe commit looked like this:\n\n```\n1 insertion(+), 31,318 deletions(-)\n```\n\nThe 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.\n\nWhat 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.\n\nRecovery itself was a one-liner thanks to git:\n\n```\n# Restore the file from the last-good commit\ngit show <last-good-commit>:docs/GROWTH_STRATEGY_ROADMAP.md > docs/GROWTH_STRATEGY_ROADMAP.md\n```\n\nRebuilding 31,000 lines by hand would be impossible. git's immutability is a textbook case of protecting \"capital = time.\"\n\nFor large append-only record files (roadmaps, changelogs, ops logs), **never allow an automated agent to full Write**. Allow only tail appends.\n\n| Operation | On a large shared file | \n|---|---|\n| Tail append (anchored) | ✅ safe | \n| Local edit on a unique anchor | ⚠️ ok if the anchor is unique | \n| Whole-file overwrite (full Write) | ❌ forbidden (source of truncation) | \n\nIn 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).\n\nDon't rely on human eyes — **mechanically reject mass deletions** in CI / a pre-receive hook.\n\n```\n# Example: fail if a tracked file shrinks by more than N lines\nTHRESHOLD=500\nbefore=$(git show \"$BASE:docs/GROWTH_STRATEGY_ROADMAP.md\" | wc -l)\nafter=$(wc -l < docs/GROWTH_STRATEGY_ROADMAP.md)\nif [ $((before - after)) -gt $THRESHOLD ]; then\n  echo \"::error::ROADMAP shrank by $((before - after)) lines — block destructive overwrite\"\n  exit 1\nfi\n```\n\nFollowing an existing regression-guard pattern lets you stop the whole class of \"a grown file shrinks by accident\" across the repo.\n\nA 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.\n\nAutomation 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**.", "url": "https://wpnews.pro/news/the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-first", "canonical_source": "https://dev.to/kanta13jp1/the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-verify-first-detection-2pj6", "published_at": "2026-11-28 15:34:28+00:00", "updated_at": "2026-11-28 15:43:39.360226+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "mlops"], "entities": [], "also_reported_by": [], "takeaway": "Restrict scheduled agents to anchored tail appends instead of whole-file writes, and add a CI or pre-receive hook that fails when a tracked file shrinks by more than a threshold such as 500 lines.", "recommendation": {"advice": "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.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-first", "markdown": "https://wpnews.pro/news/the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-first.md", "text": "https://wpnews.pro/news/the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-first.txt", "jsonld": "https://wpnews.pro/news/the-day-a-scheduled-ai-agent-erased-31000-lines-append-only-discipline-and-first.jsonld"}}