Human approval should not release a tool just because someone clicked "approve" hours ago. The payload may have changed, the target may have moved, or the policy may have changed while the agent was waiting.

Treat approval as a short-lived authorization for one concrete call. Store the tool, target, normalized arguments, policy version, and an expiresAt value. Before the external side effect, the executor checks that identity again and consumes the decision atomically. If the deadline passed or the payload changed, the call does not run. The guide to when an AI agent should ask for human approval explains which actions should pause; this article focuses on how long that pause remains valid.

The example uses a small Node.js fixture. It proves local expiry, payload binding, and one-time consumption. It is not a distributed approval service, does not authenticate reviewers, and does not prove a real database transaction.

Diagram shows an AI agent approval expiring before a recheck either releases or blocks the tool.

Key Takeaways

  • Store expiresAt, the call identity, and the policy version with every approval request.
  • Show the reviewer the payload that will actually run, not a summary the agent can change later.
  • Recheck expiry, arguments, target, permissions, and current state immediately before the tool.
  • An expired, changed, or already consumed approval must block the call and require a new request.

Why approval cannot be a boolean

A field such as approved: true only says that someone approved something. It does not say which call, which target, which arguments, which policy, or how long the decision lasts. That missing context creates an authorization that can outlive the object the reviewer actually saw.

The OpenAI Agents SDK human-in-the-loop flow pauses execution when a tool needs approval, exposes an interruption, and lets the application serialize RunState for a later resume. That solves process suspension. It does not turn an old approval into permanent authority. The application executor still has to decide whether the call is valid at resume time.

An approval should be tied to at least these fields:

Field What it protects When it changes
toolCallId The interrupted call Create a new pending request.
actionDigest Normalized tool, target, and arguments Reject the different payload.
policyVersion The rule that required review Re-evaluate if policy changed.
expiresAt The window in which the decision can be used Mark it expired and do not run.
status The pending, approved, rejected, expired, consumed lifecycle Allow only the intended transition.

The names can differ. The contract must answer, without asking the model, "what was approved, under which rule, and can it still be consumed?"

Show and freeze the call that will run

The reviewer should assess the concrete call: tool name, destination, arguments, requesting identity, and expected effect. The Pydantic AI approval documentation distinguishes the arguments sent by the model from the validated arguments the tool will receive. That difference matters when hooks add defaults, normalize values, or read context.

Do not store only the text shown in the UI. Compute the identity from the payload accepted by the execution boundary. For a send_email call, "send the report to operations" is not enough. The record must distinguish the recipient, subject, body or content reference, and any option that changes the effect.

If the runtime must fetch new data after the click, either send the new call through approval again or bind the approval to a state version that is checked before execution. Do not treat an old read as current state.

This binding also blocks a silent edit between the screen and the worker. The decision may still say approved, but consumption should fail with payload_changed. The agent can create a new proposal. It must not edit the call and reuse the same approval.

Expire and consume at the side-effect boundary

The deadline shown in the UI is only information until the code that executes the tool enforces it. A scheduled sweep should mark old requests, but the executor must compare the clock too. The sweep can be delayed, crash, or run in another region.

The Microsoft verify-before-approve pattern treats a decision arriving after expires_at as expired, retires the nonce, and requires a fresh request. The AWS guide to human approval for agent actions also separates logical expiry, physical retention, and the conditional claim that decides which worker may resume.

The consume path should look like this:

  1. Load the request and reject an unknown identifier.
  2. Compare the current time with expiresAt.
  3. Compare tool, target, arguments, and policy with the approved record.
  4. Perform a conditional update that changes approved to consumed once.
  5. Call the external tool only after the claim succeeds.
  6. Record the result and distinguish rejection, expiry, duplicate consumption, and dependency failure.

Steps 2 through 4 need one concurrency boundary in the storage layer. An in-memory if followed by a separate database command does not stop two workers from consuming the same approval.

Node.js fixture: an expired approval does not run

This fixture uses JSON.stringify as a deterministic digest because the object has a small, known shape. Production code needs canonical serialization that defines ordering, defaults, numbers, Unicode, and omitted fields. The point here is to test the policy, not to provide a cryptographic library.

import assert from "node:assert/strict";

function digest(call) {
  return JSON.stringify({
    tool: call.tool,
    target: call.target,
    arguments: call.arguments,
  });
}

class ApprovalStore {
  #rows = new Map();

  request(id, call, expiresAt) {
    this.#rows.set(id, {
      id,
      actionDigest: digest(call),
      expiresAt,
      status: "pending",
    });
  }

  approve(id, now) {
    const row = this.#rows.get(id);
    if (!row || now >= row.expiresAt) {
      if (row) row.status = "expired";
      return false;
    }
    row.status = "approved";
    return true;
  }

  consume(id, call, now) {
    const row = this.#rows.get(id);
    if (!row) return { allowed: false, reason: "unknown_approval" };
    if (now >= row.expiresAt) {
      row.status = "expired";
      return { allowed: false, reason: "expired" };
    }
    if (row.status !== "approved") {
      return { allowed: false, reason: "not_approved" };
    }
    if (row.actionDigest !== digest(call)) {
      return { allowed: false, reason: "payload_changed" };
    }
    row.status = "consumed";
    return { allowed: true };
  }
}

const store = new ApprovalStore();
const originalCall = {
  tool: "send_email",
  target: "[email protected]",
  arguments: { subject: "Deploy", body: "Ready" },
};
let effects = 0;

store.request("a-1", originalCall, 100);
assert.equal(store.approve("a-1", 101), false);
assert.deepEqual(store.consume("a-1", originalCall, 101), {
  allowed: false,
  reason: "expired",
});

store.request("a-2", originalCall, 200);
assert.equal(store.approve("a-2", 150), true);
const changedCall = { ...originalCall, arguments: { ...originalCall.arguments, body: "Changed" } };
assert.deepEqual(store.consume("a-2", changedCall, 160), {
  allowed: false,
  reason: "payload_changed",
});

store.request("a-3", originalCall, 300);
assert.equal(store.approve("a-3", 250), true);
if (store.consume("a-3", originalCall, 260).allowed) effects += 1;
if (store.consume("a-3", originalCall, 261).allowed) effects += 1;
assert.equal(effects, 1);

console.log("approval expiry and payload binding passed");

Save it as approval-expiry.mjs and run:

node approval-expiry.mjs

The test confirms three properties of the fixture: an expired approval cannot be accepted, a changed payload cannot reuse the decision, and two consume attempts produce at most one local effect. It does not prove that a distributed database performed the same operation atomically. That storage-level test is still required.

What should happen when approval expires?

Expiry should be an explicit result, not a generic error that invites the agent to retry with the same identifier.

  • Mark the request expired idempotently.
  • Do not call the tool or automatically retry with the same approval.
  • Tell the agent that the decision expired without turning that message into a new authorization.
  • Keep the minimum audit record: call, digest, deadline, policy, decision, and block reason.
  • If the action still makes sense, create a new proposal with a new identifier and recheck current data.
  • If the action may have started before the timeout, treat the outcome as uncertain and query the external system before retrying.

A request nobody answered should fail closed. Silence is not consent. Escalation can create a new request, but it should not extend validity without a new decision and an accountable identity.

Resume, restart, and policy changes

Approval creates a pause. The worker that displayed the card may disappear during a deploy or restart. The pending request and the state needed to resume therefore have to be persisted before the card is shown. The OpenAI Agents SDK for JavaScript describes resuming the same RunState and running guardrails again after approval.

Approval should not be the only thing that survives a restart. Persist the run identity, policy version, and checkpoint reference too. The post about migrating AI agent checkpoints after a schema change explains why valid JSON can still have an incompatible meaning for a new runtime.

When policy changes, do not assume old pending requests remain valid. You can reject them in bulk, keep a decision only when policyVersion is compatible, or request a fresh review. The choice depends on risk, but it needs to be code rather than a prompt comment.

Mistakes that make timeout decorative

Expiring only in a cleanup job

The sweep reduces buildup, but the tool must check the deadline at consumption time. Without that second defense, a delayed queue can run an expired approval.

Showing one summary and running another payload

If the UI shows one recipient and the worker resolves another, the approval does not cover the real effect. Compute identity at the same boundary that validates and executes the call.

Using one approval for the whole run

Approval for send_email should not automatically authorize delete_record. Even when a policy offers sticky approval per tool, limit its scope and test handoffs and nested tools.

Trusting the client that submits the decision

Pydantic AI warns that human-in-the-loop does not replace adapter authentication or authorization inside the tool. A client that can construct message history is not automatically a trusted reviewer.

Retrying after an unknown outcome

If the worker died after sending the request and before saving the receipt, approval may still be valid while the effect is uncertain. Query by an idempotency key or reconcile the resource before issuing another call.

Checklist before releasing the tool

  • [ ] Approval identifies the tool, target, arguments, and toolCallId.
  • [ ] The reviewer sees the validated arguments the tool will receive.
  • [ ] expiresAt is enforced by the executor, not only the UI or cleanup job.
  • [ ] A changed payload, target, policy, or permission requires a new decision.
  • [ ] Consumption is a conditional transition to consumed and cannot happen twice.
  • [ ] Expiry, rejection, and timeout never call the tool.
  • [ ] Restart and resume use persisted state but pass through validation again.
  • [ ] An uncertain external effect has an idempotency key, state query, or reconciliation path.
  • [ ] The test exercises the boundary that actually authorizes the call.

Method and limits

Samuel Fajreldines is responsible for source selection, the fixture, and the writing. I reviewed the public OpenAI Agents SDK, Pydantic AI, AWS, and Microsoft documentation on 2026-11-27. I also checked current English, Portuguese, and Spanish results and recent public discussions for terms such as "stale approval", "expires_at", and "payload binding". Those discussions informed vocabulary and reported failure modes, not technical proof.

The fixture ran locally with Node.js v25.5.0 and uses only node:assert/strict. It proves in-memory rules for expiry, payload identity, and one-time consumption. It does not test PostgreSQL, queues, cross-process concurrency, reviewer authentication, a specific SDK, or an external side effect.

I used AI assistance to organize research, review the prose, and prepare the localizations. It did not run a production agent or provide operational experience. When I need continuity across long Codex and Claude Code sessions, I use RemoteCode, a tool I built. That does not replace runtime validation or human review.

Conclusion

Human approval should be a limited authorization for one concrete call. Store its deadline and action identity, recheck both before the side effect, and consume the decision once. If the approval expired or the world changed, create a new proposal. Do not turn an old click into permanent permission.

Sources consulted