cd /news/ai-agents/i-let-ai-agents-ship-to-production-f… Β· home β€Ί topics β€Ί ai-agents β€Ί article
[ARTICLE Β· art-173646] src=dev.to β†— pub= topic=ai-agents verified=true sentiment=↑ positive

I let AI agents ship to production for two months. Here are the five guardrails that survived

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.

recommendation

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.

more in playbook: Designing agent systems
by read5 min views1 publishedNov 21, 2026

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.

That 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.

src/lib/tasks-core.ts     decides. pure functions, no fs, no fetch, no clock
src/lib/store.ts          touches. reads and writes files
src/app/api/tasks/route.ts  connects the two

A 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.

Two things change:

Tests stop needing setup. No mocks, no temp directories β€” a decision function is called with values and checked against values.

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.

I 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.

But three things will bite you:

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.

const tmp = `${file}.tmp-${process.pid}`;
await fs.writeFile(tmp, JSON.stringify(value, null, 2), "utf8");
await fs.rename(tmp, file);

Unreadable JSON taking the screen down. Never throw on read. Return the fallback and let the page render with one row missing.

try {
  return JSON.parse(await fs.readFile(path, "utf8")) as T;
} catch {
  return fallback;
}

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.

That 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.

Approvals 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.

Both go through one pure function now:

export function nextAction(a: Approval | null, config: ApprovalConfig, nowMs: number): Next {
  if (!a) return { kind: "wait", untilMs: 0 };
  if (a.decision === "ok") return { kind: "run", via: "human" };
  if (a.decision === "ng") return { kind: "skip", via: "human" };
  const deadline = a.askedMs + config.waitMin * 60_000;
  if (nowMs < deadline) return { kind: "wait", untilMs: deadline };
  return config.silentDefault === "publish" ? { kind: "run", via: "silent" } : { kind: "skip", via: "silent" };
}

Two 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.

This is the line that made the automation actually usable.

An 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:

The 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.

types β†’ tests β†’ build β†’ swap the running app

Nothing swaps unless all three pass. Before this existed, I read diffs. I am slower and less consistent than tsc.

There is one more line, and it is in the file I hand to the agent:

If it fails, fix it. If you cannot, report the failure as it is and stop. Do not claim success.

I 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.

I assumed the hard part of AI-assisted work would be code quality. It was not. The code was mostly fine.

The 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.

What 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.

If 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.

Happy 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.

The 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.

How it works, and what it costs: https://opspanel-ai.github.io/ops-panel/?lang=en&utm_source=devto

── more in #ai-agents 4 stories Β· sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/i-let-ai-agents-ship…] indexed:0 read:5min 2026-11-21 Β· β€”