# Human in the Loop, Without the Hacks: Pausing an Agent Mid-Run for Approval (Workflows suspend/resume + Postgres for state)

- Date: 2026-07-28T10:51:37.130Z
- URL: https://render.com/articles/human-in-the-loop-without-the-hacks-pausing-an-agent-mid-run-for-approval-workfl

## Pausing an Agent Mid-Run for Approval: a suspend/resume pattern with Postgres checkpoints

## Why human approval steps break long-running agents

A human-in-the-loop workflow is a multi-step automated process that pauses execution until a person provides an explicit signal (typically an approval or rejection) before continuing. AI agents that send emails, move money, or modify production data commonly require this checkpoint. The core engineering challenge is not collecting the approval but keeping the workflow alive across an unbounded wait, which can span minutes or days. This article explains why blocking-wait implementations fail in production, what true suspend/resume semantics require, and how Postgres serves as the durable state layer that makes this pattern reliable on platforms like [Render](https://render.com/docs).

If the agent you're pausing follows a ReAct-style tool-use loop, the walkthrough on [building an agent with LangChain and Claude or OpenAI](https://render.com/articles/building-an-agent-with-langchain-and-claude-open-ai) covers that pattern in full, so this article assumes you already have an agent and focuses only on the pause.

## The problem with naive "wait for approval" code

The most common anti-pattern is a blocking wait. The agent process reaches the approval step and enters a loop such as `while not approved: sleep(5)`, or sets an in-memory flag that a handler flips later. This approach has three structural failure modes:

- *Process restarts destroy state.* In-memory workflow state doesn't survive a crash, a scale-down event, or a redeploy. Platforms with [zero-downtime deploys](https://render.com/docs/deploys) replace instances during each deploy, so any in-flight approval held in memory disappears silently.
- *Horizontal scaling duplicates work.* If two [background worker](https://render.com/docs/background-workers) replicas each hold a copy of the "waiting" loop, an approval can trigger the continuation twice, producing duplicate side effects.
- *No audit trail exists.* A sleeping process leaves no queryable record of what's pending, who approved it, or when.

The required mental shift is this: stop trying to keep the process alive and waiting. Instead, let the process exit and design the system so you can reconstruct the workflow later from persisted state.

## What "suspend and resume" actually means

Suspension is the act of capturing the minimum state required to reconstruct a workflow's execution context at a later time, then releasing the compute resources entirely. Resume is the act of re-entering that workflow at the specific step where it stopped, not restarting it from the beginning.

Three properties distinguish true suspension from blocking:

1. *Zero compute during the wait.* No process holds the workflow. The wait costs a database row, not a CPU.
2. *Durable checkpoint.* You persist the workflow's identifier, current step, and accumulated context outside any process's memory.
3. *Event-driven continuation.* An external event (a human clicking "approve" is conceptually identical to a webhook or a queued message) updates the checkpoint and triggers re-entry.

This is a pattern, not a product feature. [Render Workflows](https://render.com/docs/workflows) provides distributed task execution across independent instances, with managed queuing and automatic retries, as a managed primitive (currently in beta). For the platform-level reasoning behind why durable execution matters for LLM workloads specifically, see the overview of [durable workflow platforms for AI agents and LLM workloads](https://render.com/articles/best-durable-workflow-platforms-for-ai-agents-and-llm-workloads). The same model applies if you hand-roll it with a job queue plus a database: checkpoint the state, park the execution, and re-enter from the checkpoint when the signal arrives. The approval event is just an unblock signal addressed to a stored, paused execution.

## Postgres as the durability layer

A relational database is a natural fit for workflow state for three reasons:

- *Transactional guarantees.* You can write the checkpoint and record the triggering event atomically, eliminating states where a workflow is "half-suspended."
- *Queryable state.* Paused workflows are rows. You can find everything in `pending_approval` older than 24 hours with a `SELECT`, not a log-diving exercise.
- *Operational inspectability.* Support engineers can examine a stuck workflow directly, with standard tooling.

Conceptually, the checkpoint stores four things: a workflow identifier, the current step name, a serialized context payload, and a status field (`pending_approval`, `approved`, `rejected`). [Render Postgres](https://render.com/docs/postgresql) provides this durability: paid instances include [point-in-time recovery](https://render.com/docs/postgresql-backups), on-demand logical exports, encryption at rest, and expandable SSD storage. Connect from your services using [environment variables](https://render.com/docs/configure-environment-variables) for the connection string (for example, a `DATABASE_URL` populated from your database's `connectionString`).

A simplified schema to illustrate what a paused workflow's state might look like:

```sql runnable
CREATE TABLE workflow_checkpoints (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  workflow_name TEXT NOT NULL,
  current_step TEXT NOT NULL,
  -- Production: add constraints/enum, audit timestamps
  status TEXT NOT NULL DEFAULT 'pending_approval',
  -- Production: consider size limits or offloading large payloads
  context JSONB NOT NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
```

For production, add proper indexing on `status`, row-level locking or optimistic concurrency, and retention or cleanup policies. Code examples should demonstrate concepts, not provide production solutions, and this example requires adaptation for your specific workflow and agent logic. If your approval-gate queries need to stay fast under many concurrent agent runs, the guidance in [PostgreSQL performance optimization for web applications](https://render.com/articles/postgresql-performance-optimization-for-web-applications) applies directly to indexing and query planning for this table.

## A minimal suspend/resume flow

The lifecycle has five stages, each with a distinct owner:

1. *Reach the checkpoint.* The agent completes its automated steps and arrives at an action requiring approval.
2. *Suspend.* The agent writes a checkpoint row with `status = 'pending_approval'` and its full context, then exits or parks. No process waits.
3. *Signal.* A human approves via an internal endpoint (potentially a [private service](https://render.com/docs/private-services) reachable only over your private network), which updates the row to `approved`.
4. *Resume trigger.* The approval handler enqueues a resume, or a periodic reconciliation job finds newly approved rows.
5. *Re-enter.* A worker loads the checkpoint and continues execution *from the recorded step*.

This demonstrates the conceptual shape of a suspend/resume cycle, and is illustrative scaffolding rather than a copy-paste-ready implementation:

```javascript pseudocode
async function runAgent(input) {
  const draft = await generateAction(input);
  // Production: wrap in a transaction with the triggering event
  await db.insert("workflow_checkpoints", {
    current_step: "awaiting_approval",
    status: "pending_approval",
    context: { draft, input },
  });
  // Process exits here. Nothing waits.
}

// Production: add idempotency check to avoid duplicate side effects
async function resumeWorkflow(checkpointId) {
  const cp = await db.get("workflow_checkpoints", checkpointId);
  if (cp.status !== "approved") return;
  await executeStep(cp.current_step, cp.context); // continue, not restart
  await db.update(checkpointId, { status: "completed" });
}
```

For production, add error handling, retries, and a reconciliation job to catch approvals that never triggered a resume. This is illustrative scaffolding (not a queue or scheduler implementation), and this example requires adaptation for your specific workflow and agent logic. Code examples should demonstrate concepts, not provide production solutions.

## Guardrails for actions that touch production

The reason this pattern exists is that a paused action often carries real consequences: sending customer email, moving money, or changing production data. The pause is only as safe as the controls around it. The case study on [what Polsia learned running autonomous companies on Render](https://render.com/blog/a-sandbox-doesn-t-constrain-an-api-key-what-polsia-learned-running-autonomous-companies-on) is a useful companion here, because it covers guardrails and control mechanisms for production agents and reinforces a key point: a sandbox around the agent does not constrain what an approved action can actually do. Treat the approval gate as one layer, and scope the credentials and permissions available at the resume step as another.

## Common mistakes and troubleshooting

Four failure patterns account for most production incidents with this design:

- *In-memory state "just for now."* A prototype that holds state in a process variable often ships to production unchanged, and fails on the first redeploy. Persist from day one.
- *The lost-resume gap.* An approval row updates, but the resume trigger fails or never fires. Add a reconciliation safety net: a [cron job](https://render.com/docs/cronjobs) that runs on a schedule you define and periodically scans for `approved` rows without a corresponding completion.
- *Resume treated as restart.* Re-running the workflow from step one after approval re-executes earlier side effects, such as re-sending an email. Target the recorded step during resume, guarded by idempotency keys.
- *Unqueryable checkpoint tables.* Without an index on `status` and timestamps on state transitions, stuck workflows are effectively invisible. Under high approval volume, also review [connection pooling](https://render.com/docs/postgresql-connection-pooling) (which you can set up on Render using PgBouncer) so resume workers don't exhaust the limited number of simultaneous direct connections.

## The durable bridge between "now" and "next"

Suspend/resume separates two concerns that blocking code conflates: *what the workflow should do next* and *which process happens to be running*. Postgres is the durable bridge between them. The checkpoint outlives every deploy, crash, and scale event, and the approval is simply the event that carries execution across it.

## Frequently asked questions

###### Why does a redeploy break my in-memory approval workflow on Render?

[Zero-downtime deploys](https://render.com/docs/deploys) replace running instances with new ones during every deploy, so any variable or sleep loop holding "pending approval" state in process memory is discarded along with the old instance. The fix isn't to avoid deploys. It's to never rely on process memory for state that must survive longer than a single request. Persist the checkpoint to Postgres so the new instance can pick up exactly where the old one left off.

###### Should I use Render Workflows or build suspend/resume myself with Postgres?

[Render Workflows](https://render.com/docs/workflows) gives you managed queuing, distributed execution, and automatic retries out of the box, which removes the queue, retry, and worker plumbing described in this article, though it's currently in beta. It doesn't provide a suspend/wait primitive, so even on Workflows the approval wait still lives in the Postgres checkpoint row, and the resume runs as a new task after approval. Workflows replaces the plumbing, not the checkpoint table. Hand-rolling the full pattern with a job queue and Postgres gives you more control and works fine for simpler cases, but you own the reconciliation logic, idempotency, and retry handling yourself. Choose based on how much of that operational surface area you want to maintain.

###### How do I detect approvals that never triggered a resume?

Run a periodic [cron job](https://render.com/docs/cronjobs) that queries for rows with `status = 'approved'` but no matching `completed` record, and re-enqueue those for resumption. This reconciliation job is the safety net for the "lost-resume gap." It doesn't matter whether the original trigger was a webhook, a queue message, or an internal API call, because the query only cares about the durable state in Postgres.

###### How do I prevent a resumed workflow from re-running earlier side effects?

Always resume from the `current_step` recorded in the checkpoint rather than restarting the workflow from its entry point, and guard each step with an idempotency key so a duplicate resume trigger can't re-send an email or re-charge a payment. Wrapping the checkpoint update and the triggering event in a single transaction also helps eliminate the ambiguous "half-suspended" states that make duplicate execution more likely.

###### What should the workflow_checkpoints table look like in production?

Beyond the four core fields (workflow identifier, current step, context payload, and status), add an index on `status` (and on timestamp columns you use for auditing), row-level locking or optimistic concurrency to prevent two workers from resuming the same row, and a retention or cleanup policy so completed rows don't accumulate indefinitely. The example schema in this article is intentionally minimal and needs this hardening before production use.

###### Do I need connection pooling for a suspend/resume workflow on Render?

If approval volume is low, a direct Postgres connection is usually fine. But once you have many resume workers polling or reacting to checkpoint changes concurrently, you can hit the limited number of simultaneous direct connections on your plan, so set up [connection pooling](https://render.com/docs/postgresql-connection-pooling) with PgBouncer to keep resume workers from exhausting them.

###### Can the approval step itself run as a private endpoint instead of a public API?

Yes. Since the approval handler only needs to be reachable by trusted internal callers (like an internal dashboard or another service on your network), it's a good candidate for a [private service](https://render.com/docs/private-services) rather than a publicly exposed endpoint. It still just performs a status update on the checkpoint row, but keeping it off the public internet reduces the attack surface for an action that can trigger money movement or production changes.

