<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl" -->

---
title: Build an agent approval flow that survives a restart
description: This tutorial builds a local approval queue for AI agent actions that survives process restarts and crashes. It uses Node's built-in node:sqlite module to...
canonical: https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Build an agent approval flow that survives a restart | daily.dev
og:description: This tutorial builds a local approval queue for AI agent actions that survives process restarts and crashes. It uses Node's built-in node:sqlite module to...
og:url: https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl
og:image: https://api.daily.dev/og/posts/VoBmkr0vl.png
og:image:alt: Build an agent approval flow that survives a restart
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Build an agent approval flow that survives a restart

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 8 min read · 1 upvotes · 0 comments

## Summary

This tutorial builds a local approval queue for AI agent actions that survives process restarts and crashes. It uses Node's built-in node:sqlite module to store an immutable email proposal, identified by a SHA-256 digest of its exact content. A fake provider table models an email send without network calls. On resuming after a simulated crash (process.exit(23)), the program checks for an existing receipt before checking approval expiry, and refuses to guess whether a retry is safe if a proposal is stuck 'executing' with no receipt. Rejected or cancelled proposals and expired approvals block execution while pending or approved.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/durable-agent-approval>

## Questions this post answers

### How do I make sure an AI agent can't send an email after I approved a different version of it?

Hash the exact serialized proposal (recipient, subject, body) with SHA-256 and require that digest as part of the approval command. The proposal is stored as immutable, so any change to the message requires a brand new operation ID and a new decision, preventing the agent from rewriting content after approval.

_Developers wiring approval gates into agent tool calls compare patterns like this one on daily.dev._

### How can I recover an agent task safely after it crashes mid-execution without double-sending?

Check for an existing receipt before checking whether the approval window expired. In this Node.js example using node:sqlite, a crash is simulated with process.exit(23) after a fake provider 'accepts' the message but before the local state is marked completed; on restart, the program finds the existing receipt and marks it completed without re-sending, keeping the accepted-message count at one.

_Anyone building durable agent workflows can track crash-recovery patterns like this on daily.dev._

### What's node:sqlite in Node.js used for?

It's a built-in SQLite module in a current Node LTS release, used here via the DatabaseSync class to store proposals and accepted-message records without any external database dependency, including transactions via db.exec('BEGIN IMMEDIATE') for atomic state claims.

_Developers evaluating Node's native sqlite support follow practical examples like this on daily.dev._

## Similar posts on daily.dev

- [How to build agents that survive crashes with Pi Durable](https://daily.dev/posts/how-to-build-agents-that-survive-crashes-with-pi-durable-zt8jcyleg) · Flavio Copes · 8 upvotes · 0 comments
- [Building a ‘Human-in-the-Loop’ Approval Gate for Autonomous Agents](https://daily.dev/posts/building-a-human-in-the-loop-approval-gate-for-autonomous-agents-krdljp98i) · Machine Learning Mastery · 1 upvotes · 0 comments
- [Designing a Production-Ready Agent Harness With Persistence and Checkpointing](https://daily.dev/posts/designing-a-production-ready-agent-harness-with-persistence-and-checkpointing-4ygffqjsx) · SitePoint · 1 upvotes · 0 comments
- [Build Long-running AI agents that pause, resume, and never lose context with ADK](https://daily.dev/posts/build-long-running-ai-agents-that-pause-resume-and-never-lose-context-with-adk-qcg6wprzb) · Google Developers · 3 upvotes · 0 comments
- [One Agent Workflow That Keeps Human Review in the Loop](https://daily.dev/posts/one-agent-workflow-that-keeps-human-review-in-the-loop-idljoj6z9) · Medium · 0 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#nodejs](https://daily.dev/tags/nodejs), [#sqlite](https://daily.dev/tags/sqlite)

[View this post on daily.dev](https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Build an agent approval flow that survives a restart","url":"https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl"},"datePublished":"2026-10-30T08:11:01.707Z","dateModified":"2026-10-30T08:11:30.709Z","description":"This tutorial builds a local approval queue for AI agent actions that survives process restarts and crashes. It uses Node's built-in node:sqlite module to...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b4cd16de6412a9bebe664fa6a31f14dc?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b4cd16de6412a9bebe664fa6a31f14dc?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Flavio Copes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,nodejs,sqlite","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"Build an agent approval flow that survives a restart"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/build-an-agent-approval-flow-that-survives-a-restart-vobmkr0vl#faq","mainEntity":[{"@type":"Question","name":"How do I make sure an AI agent can't send an email after I approved a different version of it?","acceptedAnswer":{"@type":"Answer","text":"Hash the exact serialized proposal (recipient, subject, body) with SHA-256 and require that digest as part of the approval command. The proposal is stored as immutable, so any change to the message requires a brand new operation ID and a new decision, preventing the agent from rewriting content after approval. Developers wiring approval gates into agent tool calls compare patterns like this one on daily.dev."}},{"@type":"Question","name":"How can I recover an agent task safely after it crashes mid-execution without double-sending?","acceptedAnswer":{"@type":"Answer","text":"Check for an existing receipt before checking whether the approval window expired. In this Node.js example using node:sqlite, a crash is simulated with process.exit(23) after a fake provider 'accepts' the message but before the local state is marked completed; on restart, the program finds the existing receipt and marks it completed without re-sending, keeping the accepted-message count at one. Anyone building durable agent workflows can track crash-recovery patterns like this on daily.dev."}},{"@type":"Question","name":"What's node:sqlite in Node.js used for?","acceptedAnswer":{"@type":"Answer","text":"It's a built-in SQLite module in a current Node LTS release, used here via the DatabaseSync class to store proposals and accepted-message records without any external database dependency, including transactions via db.exec('BEGIN IMMEDIATE') for atomic state claims. Developers evaluating Node's native sqlite support follow practical examples like this on daily.dev."}}]}
```

