{"slug": "i-let-ai-agents-ship-to-production-for-two-months-here-are-the-five-guardrails", "title": "I let AI agents ship to production for two months. Here are the five guardrails that survived", "summary": "A developer running a self-hosted business dashboard on a single PC described five guardrails that survived two months of near-daily AI agent edits to production code. The practices include isolating pure decision functions from file and network access so agents can be scoped to small blast radii, writing files via atomic temp-then-rename, never throwing on unreadable JSON, backing up data outside the repository, and routing all approval paths through a single pure function with explicit wait windows and silent defaults. The developer reported that an agent-written deploy script using 'git worktree remove --force' emptied the main checkout's node_modules on Windows, recoverable in 13 seconds only because the lockfile was committed.", "body_md": "I run a small business on a dashboard I wrote myself. It runs on a PC in my room — no server bill, no managed database — and an AI agent edits it almost every day.\n\nThat setup broke in interesting ways. Every guardrail below exists because something went wrong first. After two months, these five are the ones I would put in on day one if I started again.\n\n```\nsrc/lib/tasks-core.ts     decides. pure functions, no fs, no fetch, no clock\nsrc/lib/store.ts          touches. reads and writes files\nsrc/app/api/tasks/route.ts  connects the two\n```\n\nA pure function takes the current time as an argument instead of calling `Date.now()`. That sounds like a style preference until you hand the code to an agent.\n\nTwo things change:\n\n**Tests stop needing setup.** No mocks, no temp directories — a decision function is called with values and checked against values.\n\n**You can scope what the agent sees.** \"Fix this decision function\" is a much smaller blast radius than \"fix this file that also writes to disk and calls three APIs\". Most of my accidents stopped happening when the file an agent opened could not delete anything.\n\nI never set up Postgres for this. At my size, running it is the work. Files you can read with your eyes, diff in git and fix by hand are worth more than query features I do not use.\n\nBut three things will bite you:\n\n**A half-written file after a crash.** Write to a temp path, then `rename`. Rename is atomic: the file is either the old content or the new one, never a truncated mix.\n\n``` js\nconst tmp = `${file}.tmp-${process.pid}`;\nawait fs.writeFile(tmp, JSON.stringify(value, null, 2), \"utf8\");\nawait fs.rename(tmp, file);\n```\n\n**Unreadable JSON taking the screen down.** Never throw on read. Return the fallback and let the page render with one row missing.\n\n```\ntry {\n  return JSON.parse(await fs.readFile(path, \"utf8\")) as T;\n} catch {\n  return fallback;\n}\n```\n\n**Losing the data to a git mistake.** What a bad command destroys is never the code — it is the data you accumulated. Copy it **outside the repository** on a schedule, keeping generations.\n\nThat last one is not theoretical. A deploy script an agent wrote created a worktree, symlinked `node_modules` into it, and cleaned up with `git worktree remove --force`. Git for Windows follows junctions and deletes recursively, so it emptied the **main** checkout's `node_modules`. Recovery took 13 seconds (` pnpm install --frozen-lockfile`) only because the lockfile was committed. If that cleanup had pointed at my data directory, 13 seconds would have been 13 days.\n\nApprovals arrive from two places here: a button on the dashboard, and a reply in a chat app. For a while each had its own logic. Then the chat path kept a rule the button had dropped, and the two disagreed about what \"no answer\" meant.\n\nBoth go through one pure function now:\n\n```\nexport function nextAction(a: Approval | null, config: ApprovalConfig, nowMs: number): Next {\n  if (!a) return { kind: \"wait\", untilMs: 0 };\n  if (a.decision === \"ok\") return { kind: \"run\", via: \"human\" };\n  if (a.decision === \"ng\") return { kind: \"skip\", via: \"human\" };\n  const deadline = a.askedMs + config.waitMin * 60_000;\n  if (nowMs < deadline) return { kind: \"wait\", untilMs: deadline };\n  return config.silentDefault === \"publish\" ? { kind: \"run\", via: \"silent\" } : { kind: \"skip\", via: \"silent\" };\n}\n```\n\nTwo entry points with two sets of rules means one of them is quietly out of date. You will not find out from a test. You will find out from the behaviour that surprised you.\n\nThis is the line that made the automation actually usable.\n\nAn approval that waits forever is an automation that stops getting used, because you are not watching most of the time. So every approval carries a wait window and a default:\n\nThe distinction I settled on is not \"important vs unimportant\". It is **can I undo this myself in a minute**. If yes, let it run. If no, make it undoable first, then let it run.\n\n```\ntypes → tests → build → swap the running app\n```\n\nNothing swaps unless all three pass. Before this existed, I read diffs. I am slower and less consistent than `tsc`.\n\nThere is one more line, and it is in the file I hand to the agent:\n\nIf it fails, fix it. If you cannot, **report the failure as it is and stop**. Do not claim success.\n\nI added it after being told a build was done when it was failing. Models will narrate progress if nothing contradicts them. A gate contradicts them.\n\nI assumed the hard part of AI-assisted work would be code quality. It was not. The code was mostly fine.\n\nThe hard part was **the gap between \"the draft is ready\" and \"it is live\"** — the two minutes of copying, checking and clicking that I did by hand. The agent made the long part short and left the annoying part untouched, so finished work piled up unpublished for a month.\n\nWhat fixed it was not a better prompt. It was treating publication as part of the loop, with an approval step and a default action attached.\n\nIf you want the skeleton rather than the story, I packaged the parts that are not specific to my business — the decision/IO split, the JSON store with those three guards, the approval logic, the backup and gate scripts, the Windows Task Scheduler registration, and the rules file I hand to the agent. Tests included, runs in 15 minutes.\n\nHappy to answer anything in the comments — especially if you have hit a different failure mode. I would rather add a sixth guardrail from your accident than from mine.\n\nThe ops panel in this post connects to a POS, rolls up sales, food cost, labour and ordering, and pushes a summary to my phone every morning. It runs every day for two restaurants overseas.\n\nHow it works, and what it costs: [https://opspanel-ai.github.io/ops-panel/?lang=en&utm_source=devto](https://opspanel-ai.github.io/ops-panel/?lang=en&utm_source=devto)", "url": "https://wpnews.pro/news/i-let-ai-agents-ship-to-production-for-two-months-here-are-the-five-guardrails", "canonical_source": "https://dev.to/opspanel_dev/i-let-ai-agents-ship-to-production-for-two-months-here-are-the-five-guardrails-that-survived-1bj0", "published_at": "2026-11-21 05:32:29+00:00", "updated_at": "2026-11-21 05:41:50.299933+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "artificial-intelligence"], "entities": [], "also_reported_by": [], "takeaway": "Route every approval path through one pure nextAction function with an explicit wait window and silent default, and keep agent-editable decision logic free of filesystem, network and clock calls so the agent's blast radius stays small.", "recommendation": {"advice": "Split decision logic into pure functions that take time as an argument, and funnel all approval entry points through one function with explicit deadlines and defaults.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/i-let-ai-agents-ship-to-production-for-two-months-here-are-the-five-guardrails", "markdown": "https://wpnews.pro/news/i-let-ai-agents-ship-to-production-for-two-months-here-are-the-five-guardrails.md", "text": "https://wpnews.pro/news/i-let-ai-agents-ship-to-production-for-two-months-here-are-the-five-guardrails.txt", "jsonld": "https://wpnews.pro/news/i-let-ai-agents-ship-to-production-for-two-months-here-are-the-five-guardrails.jsonld"}}