All guides
Updated
Reading
10 min
By
Anlyon Team

What happens when an AI agent's approval expires or the request changes before it runs

Where an approved agent action stops when its preview or approval expires, the request or action version changes, or the provider's state moves on, and how to recover without reusing an outdated decision.

  • approval expiry
  • previews
  • recovery
  • GitHub
  • stale state

When an approval expires before anyone decides, nothing runs: the approval and invocation are marked expired and the governed effect grades refused. When the request changes after review, Anlyon refuses it at admission with PREVIEW_MISMATCH before any effect exists. When the provider's state changes after review, the provider decides: GitHub refuses a write on a stale blob SHA, and the receipt grades failed.

In every case the recovery is the same shape. Confirm the task is still wanted, build a fresh preview from current state, and get a fresh decision. Never copy an old approval onto a new request.

TL;DR

  • A preview lasts one hour by default, 60 seconds to 7 days with ttlSeconds. An approval lasts 24 hours by default and never outlives its preview.
  • Expired, mismatched or already used previews are refused at admission with HTTP 409 and leave no receipt.
  • An approval that expires undecided grades refused. A denied approval grades denied. They are different events.
  • Editing the action while a request waits refuses the dispatch with action_changed.
  • A file changed at GitHub after review is refused by GitHub on the reviewed blob SHA. Anlyon's digest does not catch it.
  • A Stripe refund preview shows the refundable amount as of review, labelled freshness.

What exactly does a reviewer approve?

For a governed action (one with an adapter or a declaration), the reviewer approves one preview: the normalized request, the resolved target, the action and adapter versions, the preconditions observed at review, and an expiry. Anlyon hashes those into a bindingDigest, stores it on the approval, and recomputes it immediately before dispatch. Any difference refuses the dispatch.

That binding is to the request, not to the world. It does not freeze the provider's state between the decision and the call. For the design of the binding itself, read how to bind approval to the action an agent executes.

Where can an approved action stop?

A call can stop in three places, and each leaves a different record.

Where it stopsWhat the caller seesEffect created
Admission, when the invoke arrivesHTTP 409 with an error codeNo
Dispatch, after approval and before the writeHTTP 200, status: "failed", grade: "refused"Yes, stage: "rejected", zero attempts
The provider, after Anlyon sent the writeHTTP 200, status: "failed", grade: "failed"Yes, one attempt

The first troubleshooting step is always to find which of the three you are in. An application that assumes every error carries a receipt will break on admission errors, because there is no effect to look up.

What happens when the preview or the approval expires?

A preview you create with actions.preview lasts one hour by default. An invocation with no previewId builds its own preview, which lasts as long as the approval window, 24 hours by default. When the approval is created, its expiry is set to the earlier of the approval window and the preview's expiry, so a reviewer cannot approve after the reviewed evidence has expired.

There are two expiry paths:

  • Invoking with a previewId that has already expired. Refused at admission with HTTP 409 PREVIEW_EXPIRED and the message Preview <id> expired at <time>. Create a new preview. No effect, no receipt.
  • The approval expires undecided. The approval's status is expired, the invocation's status is expired, and the effect is rejected with rejectionReason: "approval_expired", which grades refused. A later attempt to decide it returns HTTP 409 APPROVAL_ALREADY_DECIDED. Nothing was sent.

A preview that expires between admission and dispatch is refused at dispatch with preview_expired, also graded refused.

Expiry is not denial. A denied approval grades denied and means an approver rejected the operation. Expiry means the decision window closed. Keep them separate in review-queue metrics and in what you tell the agent.

What happens when the request changes after review?

An invoke that carries a reviewed previewId must send the reviewed request. Add a recipient, change an amount or point at a different resource, and the invoke is refused at admission with HTTP 409 PREVIEW_MISMATCH. The message says which part differs: the request, the action, the action version, the adapter version, or the stored binding.

Two related admission refusals come from the same check. PREVIEW_ALREADY_USED means the preview is already bound to an effect, because one preview binds one effect. PREVIEW_EXPIRED is the expiry case above.

The SDK surfaces the server's error code on the thrown AnlyonError, so branch on it rather than on the message text:

import { AnlyonError, Client } from '@anlyonhq/sdk';

const agent = new Client({ apiKey: process.env.ANLYON_AGENT_KEY! });

const input = { paymentIntent: 'pi_3Pabc', amount: 1250, currency: 'usd' };

// The reviewer sees this preview. 600 seconds is the review window you choose.
const { data: preview } = await agent.actions.preview('refund', input, { ttlSeconds: 600 });

try {
  const { data } = await agent.actions.invoke('refund', input, {
    previewId: preview!.id,
    operationKey: 'refund-request-42',
  });
  console.log(data!.status, data!.approvalId, data!.effectId);
} catch (error) {
  if (error instanceof AnlyonError && error.status === 409) {
    switch (error.code as string) {
      case 'PREVIEW_EXPIRED':      // build a fresh preview and ask again
      case 'PREVIEW_MISMATCH':     // the input drifted from what was reviewed
      case 'PREVIEW_ALREADY_USED': // this preview already bound an effect: look that effect up
        console.log(error.code, error.message);
        break;
      default:
        throw error;
    }
  } else {
    throw error;
  }
}

Pass the same input you previewed. preview.request is the normalized request, not the input.

What happens when the action is edited while a request waits?

Every edit to an action's request, approval requirement, adapter or declarations creates a new immutable version, and an effect is bound to the version that was reviewed. If the action is edited while an invocation waits for its approval, approving it dispatches nothing. The approve call succeeds, the invocation inside it reports failed, and the effect carries rejectionReason: "action_changed". An invoke that sends a preview of the old version is refused earlier, at admission, with PREVIEW_MISMATCH.

The same dispatch-time check also refuses on a halted environment, a revoked requesting key, a policy that now denies, a secret whose host binding no longer allows the request (credential_unavailable), and a shared limit that filled up after review. An approval holds no allowance. For the credential case, see how to rotate a provider key behind agent actions.

What if the provider's state changed after review?

Everything above concerns what Anlyon stored. A change at the provider after review is a different case: the digest covers the preconditions observed at review and does not watch the provider afterwards, so the binding check passes. What happens next depends on the adapter.

AdapterStale-state protectionWhat you see
github.file_updateAtomic: the write carries the reviewed blob SHAGitHub refuses with HTTP 409, grade failed, evidence details.staleVersion: true
stripe.refundNot atomic: account re-checked before dispatchStripe refuses a refund above what remains refundable
resend.email_sendNone: Resend has no conditional sendThe reviewed send goes out as reviewed
A declared actionNone: Anlyon does not know the API's preconditionsThe reviewed request goes out as reviewed

The GitHub case in detail

The preview of a github.file_update records the file's blob SHA. The write sends that SHA, and GitHub refuses it when the file has changed since. The evidence summary reads GitHub refused the write (HTTP 409): the file no longer matches the reviewed version. The receipt grades failed, not refused, and has no rejectionReason, because Anlyon did send the request. The other writer's content stays in place.

State it precisely. The write carried the blob SHA the reviewer saw, and GitHub refused it. It is not the case that Anlyon's digest detected the remote edit. On 2026-10-04 a file changed at GitHub after review was refused by GitHub on the reviewed blob SHA, and a reviewed write landed as a commit carrying the effect id.

You can reproduce it on a disposable repository and a designated branch that is not the default branch. Choose one existing UTF-8 text file under the action's pathPrefix, up to 64 KB. Create a preview of a small change, then modify the file through a separate authorized path before the approval is decided. Approve, then read the effect: the grade is failed, the stale version is recorded, and the intervening change is intact.

The Stripe case

A stripe.refund preview shows the refundable amount as of review and labels it freshness. Stripe has no compare-and-set on a payment intent. The adapter re-checks the account immediately before dispatch and relies on Stripe to refuse a refund above what remains refundable. Another actor can still refund part of the payment between review and dispatch.

How do you recover from an expired or stale approval?

Work through it in order.

  1. Confirm the business task is still wanted. An hour or a day later, a refund may no longer be appropriate. If it is not, stop.
  2. Read the existing effect, if there is one. An expired approval leaves an effect with stage: "rejected", outcome: "not_dispatched" and zero attempts. That is your evidence nothing was sent.
  3. Build a fresh preview from current state. refreshPreview re-reads the provider into a new preview that supersedes the old one. Its binding differs, so an approval of the old preview never carries over. A refresh binds the version the old preview reviewed. If the action itself changed, call actions.preview again instead.
  4. Show the reviewer the new preview. New expiry, current target, current provider observation time and, for a file, the new before-and-after diff.
  5. Invoke under a new operation key. The same operationKey with the same request returns the existing, rejected effect. A rejected effect is final, so the replacement attempt needs its own key, recorded in your database against the same business request.

This runs in your application's worker, with a key that holds actions:invoke and actions:read:

import { Client } from '@anlyonhq/sdk';

const worker = new Client({ apiKey: process.env.ANLYON_WORKER_KEY! });

async function retryAfterExpiry(oldEffectId: string, oldPreviewId: string, input: Record<string, unknown>) {
  // Step 2: prove nothing left Anlyon before starting over.
  const { data: old } = await worker.actions.effect(oldEffectId);
  if (old!.grade !== 'refused' || old!.outcome !== 'not_dispatched') {
    throw new Error(`Effect ${oldEffectId} is ${old!.grade}; reconcile it instead of retrying.`);
  }

  // Step 3: a new preview, new evidence, new binding.
  const { data: fresh } = await worker.actions.refreshPreview(oldPreviewId, { ttlSeconds: 1800 });

  // Step 5: a new attempt of the same business request, under its own key.
  return worker.actions.invoke('refund', input, {
    previewId: fresh!.id,
    operationKey: 'refund-request-42:attempt-2',
  });
}

Never resend the old content with the latest GitHub SHA swapped in. That erases the intervening change while presenting it as the edit that was reviewed. Resolve the content conflict, show the new diff, and get a new decision.

Never generate a fresh operation key to get past an error you have not read. If the original effect is unknown rather than refused, something may have reached the provider, and the right next step is reconciliation, not a second attempt.

How do you make expiry rarer?

Measure how long requests wait for review. Route clearly forbidden work to a deterministic policy denial and keep the review queue for decisions that need judgment. A longer window gives approvers more time and makes the reviewed evidence older.

Put the expiry, the provider observation time and the limitations block on the review screen, so the approver knows how fresh the evidence is. Show reviewers the operation that will run covers that screen. The full list of dispatch refusals is in When approval expires or changes.

Frequently asked questions

What happens when an approval for an AI agent's action expires?
In Anlyon, the approval's status becomes expired, the invocation's status becomes expired, and the governed effect is rejected with rejectionReason approval_expired, which grades refused. Nothing is sent to the provider. To continue, create a new preview and a new invocation and get a new decision; an old approval never carries over.
How long does an approval or a preview last?
A preview created with actions.preview lasts one hour by default, and between 60 seconds and 7 days when you pass ttlSeconds. An approval expires after 24 hours by default. An approval never outlives its preview: its expiry is the earlier of the approval window and the preview's expiry.
What if the agent changes the request after the reviewer approved it?
An invoke that carries a reviewed previewId and sends a different destination, resource, amount or content is refused at admission with HTTP 409 PREVIEW_MISMATCH. No effect is created, so there is no receipt, and nothing is sent.
What if a GitHub file changes after review?
The github.file_update write carries the blob SHA the reviewer saw, and GitHub refuses it when the file has changed since. The receipt grades failed, not refused, because Anlyon did send the request and GitHub said no. The other writer's content is not overwritten.

Let your agent act for your users, safely.

A few lines of server code, then send a user a connect link. Nothing to host.

$ claude mcp add --transport http anlyon https://api.anlyon.com/mcp