Skip to content
Anlyon
Esc
↑↓navigate↵open⌘Jpreview
On this page

When approval expires or changes

Handle an approved governed action that can no longer run as reviewed: an expired preview or approval, a changed request or action, a denial, a revoked credential or a change at the provider.

An approval of a governed action is an approval of one preview. The preview has an expiry and a bindingDigest. This page lists each way that approval can stop being valid, where the refusal happens, what your code sees, and what to do next.

Why Anlyon refuses instead of running a stale approval

A person approves what they saw. Minutes or hours later the request may differ, the action may have been edited, the user’s account may have been disconnected, or the limit may be full. Running the call anyway would turn the approval into a rubber stamp.

  • Risk. A request that no longer matches what was approved is refused with nothing sent, and the receipt says which check refused it.
  • Effort. You do not track approval freshness or re-validate requests yourself. You read one field, rejectionReason, or one error code.
  • Cost. A refusal costs no provider call. You ask again with a new preview when it still makes sense.

Where a call can stop

Where What your code sees Effect created
Admission, when the invoke request arrives HTTP 409 with an error code No
Dispatch, after approval and immediately before the write HTTP 200, status: "failed", grade: "refused" Yes, stage: "rejected", zero attempts
The provider, after Anlyon sent the write HTTP 200, status: "failed", grade: "failed" Yes, one attempt

For a parked call, “HTTP 200” is the answer to the approve request: the approve call succeeds, and the invocation inside its response carries the refusal.

How long a preview and an approval last

Default Range
A preview you create with actions.preview 1 hour ttlSeconds from 60 seconds to 7 days
A preview Anlyon creates when you invoke without one The approval window Bounded to 60 seconds to 7 days
The approval window 24 hours 1 to 168 hours, set per workspace in workspace defaults

The approval never outlives the preview. When an approval is created for a governed effect, its expiry is the earlier of the approval window and the preview’s expiry. A reviewer cannot approve after the reviewed evidence has expired.

When an approval expires undecided:

  • the approval’s status is expired, and a later attempt to decide it returns 409 APPROVAL_ALREADY_DECIDED
  • the invocation’s status is expired, and its decision.code is APPROVAL_EXPIRED
  • the effect is rejected with rejectionReason: "approval_expired", which grades refused
  • nothing was sent

Expiry is inside the digest. A preview whose stored expiry was altered no longer verifies, and dispatch refuses it.

Continue after an expiry

Create a new preview and a new invocation. Or refresh the old preview: Anlyon 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, and the new one needs its own approval.

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

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

const { data: fresh } = await agent.actions.refreshPreview('prv_01JABCDEF', { ttlSeconds: 600 });
console.log(fresh!.id, fresh!.supersedes, fresh!.bindingDigest);

// Invoke with the new preview and a new idempotency key: this is a new operation.
await agent.actions.invoke('send-email', { emailId: 'welcome-1', to: ['a@example.com'], subject: 'Welcome' }, {
  previewId: fresh!.id,
  idempotencyKey: 'welcome-1:retry-after-expiry',
});
curl -s -X POST https://api.anlyon.com/api/v2/actions/previews/prv_01JABCDEF/refresh \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "ttlSeconds": 600 }'
import os
from anlyon import Client

agent = Client(api_key=os.environ["ANLYON_API_KEY"])

fresh = agent.actions.refresh_preview("prv_01JABCDEF", ttl_seconds=600).data
print(fresh["id"], fresh["supersedes"], fresh["bindingDigest"])

A refresh keeps the action version the old preview reviewed. If the action changed since, invoking with the refreshed preview is refused with PREVIEW_MISMATCH: create a new preview instead.

A changed request: PREVIEW_MISMATCH

An invocation that carries a reviewed previewId must match the reviewed request. If the destination, resource, amount or content differs, the invoke is refused at admission.

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

const { data: preview } = await agent.actions.preview('send-email', {
  emailId: 'welcome-1', to: ['a@example.com'], subject: 'Welcome',
});

try {
  // One more recipient than the reviewer saw.
  await agent.actions.invoke(
    'send-email',
    { emailId: 'welcome-1', to: ['a@example.com', 'b@example.com'], subject: 'Welcome' },
    { previewId: preview!.id },
  );
} catch (error) {
  if (error instanceof AnlyonError && error.status === 409) console.log(error.code, error.message);
}
curl -s -w '\n%{http_code}\n' -X POST https://api.anlyon.com/api/v2/actions/send-email/invoke \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": { "emailId": "welcome-1", "to": ["a@example.com", "b@example.com"], "subject": "Welcome" },
    "previewId": "prv_01JABCDEF"
  }'
from anlyon import AnlyonError

preview = agent.actions.preview(
    "send-email", {"emailId": "welcome-1", "to": ["a@example.com"], "subject": "Welcome"}
).data

try:
    # One more recipient than the reviewer saw.
    agent.actions.invoke(
        "send-email",
        {"emailId": "welcome-1", "to": ["a@example.com", "b@example.com"], "subject": "Welcome"},
        preview_id=preview["id"],
    )
except AnlyonError as error:
    if error.status == 409:
        print(error.code, error)

The response is HTTP 409:

{
  "success": false,
  "error": {
    "code": "PREVIEW_MISMATCH",
    "message": "Preview prv_01JABCDEF does not match this invocation: the destination, resource, amount or content differs."
  },
  "requestId": "req_0123456789abcdef0123456789abcdef"
}

No effect is created, so there is no grade and no effectId. Nothing is sent to the provider. The SDKs throw: AnlyonError with status: 409 and code: "PREVIEW_MISMATCH".

PREVIEW_MISMATCH covers more than the request. The message after the colon says which part differs:

What differs Message ends with
The request the destination, resource, amount or content differs.
The action it previews another action.
The end user it was prepared for another end user, or for none.
The action version it reviewed <version>; this invocation runs <version>.
The adapter version the adapter has changed since review.
The stored binding its binding does not verify.

Two more codes come from the same check, both HTTP 409 at admission:

Code Message Meaning
PREVIEW_EXPIRED Preview <id> expired at <time>. Create a new preview. The reviewed preview is past its expiry.
PREVIEW_ALREADY_USED Preview <id> is already bound to <effect id>. A preview binds one effect. A second invocation with the same previewId is refused.

A changed action: action_changed

Every edit to an action’s request, approval requirement, adapter or declarations is a new immutable version. An effect is bound to the version that was reviewed. A rollback or a pin that moves the version the run’s agent resolves to counts as a change too.

If the action is edited while an invocation waits for its approval, approving it dispatches nothing. The approve call itself succeeds, and the invocation inside it reports the refusal.

// An operator key with approvals:decide, or a person in the console.
const operator = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });

const { data: decided } = await operator.approvals.approve('apr_01JABCDEF', { note: 'Checked the order.' });
console.log(decided!.invocation?.status);   // failed

const { data: effect } = await operator.actions.effect('eff_01JABCDEF');
console.log(effect!.rejectionReason, effect!.grade); // action_changed, refused
curl -s -X POST https://api.anlyon.com/api/v2/approvals/apr_01JABCDEF/approve \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "note": "Checked the order." }'

curl -s https://api.anlyon.com/api/v2/actions/effects/eff_01JABCDEF \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY"
operator = Client(api_key=os.environ["ANLYON_OPERATOR_KEY"])

decided = operator.approvals.approve("apr_01JABCDEF", note="Checked the order.").data
print(decided["invocation"]["status"])   # failed

effect = operator.actions.effect("eff_01JABCDEF").data
print(effect["rejectionReason"], effect["grade"])
{ "rejectionReason": "action_changed", "grade": "refused" }

The evidence says which version was reviewed and which version the action resolves to now. The same edit meets a reviewed previewId earlier: an invoke with a preview of the old version is refused at admission with PREVIEW_MISMATCH.

Every refusal at dispatch

Immediately before the write, in one transaction, Anlyon re-checks the binding and its expiry, the approval, the action version, the halt state, the requesting credential, current policy, dependencies and the limits. Any refusal rejects the effect. Each one has stage: "rejected", outcome: "not_dispatched", zero attempts and grade refused.

rejectionReason Cause What to do
binding_mismatch The stored preview, effect or approval no longer agree with the reviewed digest. Create a new preview and ask again.
binding_missing The effect has no reviewed preview. Create a new preview and ask again.
preview_expired The reviewed preview expired before dispatch. Refresh or create a preview, and ask again.
approval_expired The approval expired undecided. Ask again. Consider a longer approval window.
approval_missing The approval is not approved. Wait for a decision.
approval_required Policy now requires approval and the effect was admitted without one. Invoke again: the new call will be gated.
action_changed The action now resolves to another version. Preview the current version and ask again.
action_disabled The action is disabled or archived. Enable it, or stop calling it.
adapter_changed The adapter version that would run differs from the one reviewed. Preview again.
environment_halted The environment is halted. Resume it. See Environments.
authority_revoked The key that requested the effect is no longer active, or no longer holds actions:invoke. Invoke again with an active key.
policy_denies A policy now denies the operation. Review the policy.
dependency_unresolved An effect this one depends on is not in its required outcome. Wait for the dependency to settle.
credential_unavailable The secret could not be resolved, its host or placement binding no longer allows this request, or the end user’s account is no longer connected. Restore the secret, or have the user reconnect.
impact_limit_exceeded A shared limit has no room. See When the limit is hit.
impact_unbounded A limit applies and the call gives no evaluable amount. Make the amount’s input required.

For a refusal at dispatch, the invocation’s error has the form Dispatch refused (<reason>): <message>. An approval that expires undecided sets the invocation’s status to expired and writes no such error.

Two refusals and the values they return. A secret whose allowed host was changed after review:

{ "stage": "rejected", "rejectionReason": "credential_unavailable", "grade": "refused" }

An approval whose stored digest is not the effect’s digest:

{
  "stage": "rejected",
  "outcome": "not_dispatched",
  "rejectionReason": "binding_mismatch",
  "grade": "refused",
  "attempts": []
}

The API offers no way to make the stored preview, effect and approval disagree, so you will not trigger binding_mismatch by hand. It guards stored state. A changed request sent through the API is caught earlier, at admission, as PREVIEW_MISMATCH.

Duplicate approval callbacks cannot run the operation twice. Consuming the approval and claiming dispatch are one conditional database write. A callback that arrives before the decision commits is not a refusal: the effect stays claimable, and the approved call runs once.

A denied approval

A denial is not a refusal by Anlyon. It has its own grade.

{ "stage": "rejected", "rejectionReason": "approval_denied", "grade": "denied" }

The invocation’s status is denied. The destination saw no request. A denied effect is final. Ask again with a new invocation if the request should be reconsidered.

await operator.approvals.deny('apr_01JABCDEF', { note: 'Wrong customer.' });

const { data: denied } = await operator.actions.effects({ grade: 'denied' });
curl -s -X POST https://api.anlyon.com/api/v2/approvals/apr_01JABCDEF/deny \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "note": "Wrong customer." }'

curl -s "https://api.anlyon.com/api/v2/actions/effects?grade=denied" \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY"
operator.approvals.deny("apr_01JABCDEF", note="Wrong customer.")

denied = operator.actions.effects(grade="denied").data

When your user decides

For a call made for one of your users under a policy with decidedBy: end_user, the user approves or declines in your app, and your server relays it with endUsers.approvals.decide(userId, approvalId, { decision }). Every rule on this page applies the same way: the user’s approval binds one preview, it expires with the same window, and a decline grades denied. If the user disconnects their account while the approval waits, approving refuses the effect with credential_unavailable. See Bound approvals and previews.

When the provider’s state changes

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

github.file_update: the provider refuses a stale write. The preview records the file’s blob SHA. The write sends that SHA, and GitHub refuses it when the file has changed since. Anlyon did send the request, with the reviewed SHA attached, and GitHub said no.

{ "outcome": "failed", "partialEffect": "none", "verification": "provider" }

This receipt grades failed, not refused. There is no rejectionReason. The evidence carries details.staleVersion: true with this summary:

GitHub refused the write (HTTP 409): the file no longer matches the reviewed version.

The file keeps the other writer’s content. The write carried the blob SHA the reviewer saw and GitHub refused it.

stripe.refund: the refundable amount is as of review. The account is re-checked immediately before dispatch, and Stripe refuses a refund above what remains refundable. The preview labels this freshness.

A declared action: the binding is the request. A preview of a declared action shows the request and reads nothing from the provider. Provider state between review and dispatch is outside the binding. See Govern any HTTP API.

Errors you may see

Status and code Where What to do
409 PREVIEW_MISMATCH Admission Preview the request you mean to send, and ask again.
409 PREVIEW_EXPIRED Admission Refresh or create a preview.
409 PREVIEW_ALREADY_USED Admission Create a new preview for a second operation.
409 APPROVAL_ALREADY_DECIDED Deciding an approval that is approved, denied or expired Read the approval. For an expired one, ask again with a new invocation.
403 SELF_APPROVAL_NOT_ALLOWED Deciding your own request Have another approver, or a separate approver key, decide.
200, grade: refused Dispatch Read rejectionReason and use the table above.
200, grade: failed The provider Read the evidence. For GitHub, preview the file’s current content and ask again.

How it behaves

  • Governed means an adapter or a declaration. A governed action gets a digest-bound approval that is checked again at dispatch. An action with no declaration gets a snapshot-bound approval.
  • The binding is the exact request. A change in provider state is caught by the provider where it has a conditional write, as GitHub does.
  • Capacity is checked at dispatch. A limit can fill after review, and an approval holds no allowance.
  • Who decides is set by role and policy. Team approvals are decided in the console by members with the admin, member or approver role in that environment, or by an API key with approvals:decide. A key never decides an approval it requested.
  • The approval and the receipt are database records with provider evidence.

Was this page helpful?