zero gravitySOLUTIONS
← All insightsAI & AUTOMATION / CONCURRENCY GUIDE

Prevent AI actions from using stale approvals

QUICK ANSWER

An approval should authorize one immutable action under explicit time and version constraints. Check expiry and current preconditions atomically when admitting execution, consume the approval once, and define how queued or remote actions behave if validity changes after admission.

Inside this article 5 sections

An approval can become stale without anyone clicking reject. The target record changes, the approver loses authority, the policy is revised, or the allowed time window ends while a worker waits in a queue. A system that checks approval only when the button is pressed leaves all of those changes outside its control.

The execution protocol needs a precise question: was this exact action authorized under the required conditions at the moment it was admitted to execution? Answering that requires more than a timestamp attached to a chat message.

Bind the approval to an immutable proposal

Store the proposal identifier and version, canonical payload hash, target resource identity and version, tenant, approver identity, applicable policy version, issue time, expiry time, and consumption state. The payload hash detects changes only if canonicalization is defined; JSON key order and number representation should not accidentally change or conceal the meaning.

The approved payload must include material side effects. If the action updates an account and sends a customer message, both need to be represented in the reviewed proposal or separately authorized. A broad approval of “resolve this case” is a different delegation model and should not be mistaken for approval of one fixed action.

Keep the authoritative approval record on the server. A signed token can carry a reference or bounded capability, but signature validity does not prove that the approval is unrevoked, unexpired, or still applicable to the resource. The executor needs the current state required by the product's policy.

Choose what expiry means for execution

Three moments matter: human approval, execution admission, and effect completion. A practical policy may require approval to be valid at admission while allowing an already-admitted operation to finish later. Another action may require validity again immediately before dispatch. State the rule explicitly so operators do not infer it from implementation timing.

APPROVAL WINDOW / ADMISSION IS THE DECISION POINT
  1. 10:00Approval issued

    Proposal v7, account v31, expiry 10:05.

  2. 10:04Worker waits

    A queued item has not yet consumed authorization.

  3. 10:06Admission attempted

    The current server time exceeds the approval window.

  4. After rejectionRequest fresh review

    No action is dispatched using the expired approval.

The times are illustrative. Queue insertion before expiry does not establish permission to begin an action after expiry.

Do not use storage cleanup as the expiry check. DynamoDB time-to-live deletion can occur days after an item's timestamp. Similar background expiry mechanisms are useful for retention, but the application must compare the deadline directly when authorizing execution.

Use a trusted server clock and define the boundary convention. For example, valid means current time is strictly earlier than expires_at. Test equality explicitly. If clocks span services, choose one authoritative admission service or account for skew; do not let each client decide whether an approval still exists.

Consume approval and check preconditions together

For a local database action, use a transaction that locks or conditionally checks the approval and relevant resource, verifies current policy and authorization, performs the action, and marks the approval consumed. A separate read followed by an unconditional update leaves a race for another worker or a concurrent resource change.

The following SQL illustrates only the approval-claim portion. It assumes the same transaction has already acquired the approval and resource locks in a consistent order, then established the current authorization preconditions. Evaluate expiry after those potentially blocking lock acquisitions; a predicate evaluated before a lock wait is not a fresh admission decision. This statement is not sufficient by itself to authorize a business action.

UPDATE action_approvals
SET state = 'executing', admitted_at = clock_timestamp()
WHERE id = $1
  AND tenant_id = $2
  AND state = 'approved'
  AND proposal_version = $3
  AND payload_hash = $4
  AND expires_at > clock_timestamp()
RETURNING id, resource_id, resource_version;

Require exactly one returned row. Zero rows means the worker cannot proceed under that approval; it should determine whether the cause is expiry, consumption, mutation, or revocation without weakening the condition. Two competing workers must not both obtain execution authority.

Use a consistent lock order across approval and resource records, and handle deadlock or serialization retries by rerunning all validity checks. A retry must not reuse the earlier successful time comparison from application memory. Time and policy can change while the transaction waits.

Treat remote dispatch as another boundary

A local transaction cannot usually atomically consume approval and complete an action in an external system. Persist an execution intent with an idempotency key, then let a worker dispatch it under the defined admission policy. Record whether dispatch occurred and whether its outcome is known.

If the policy requires validity at dispatch, the outbox worker must recheck expiry and relevant preconditions before sending. A short-lived execution permit can separate reviewed proposal validity from dispatch authority, but it needs its own single-use and revocation semantics. Do not describe the permit as eliminating the interval between check and remote effect.

If the remote acknowledgement is lost, reconcile by operation key before trying again. The approval may have expired by then, but determining whether an already-admitted action completed is different from authorizing a new action. Keep recovery permissions narrow enough to inspect the existing operation without repeating it.

Test the races that a normal approval demo misses

Run cases where expiry occurs before admission, exactly at the deadline, and after admission but before completion. Change the target resource version while the worker waits. Revoke the approver's role, edit the proposed message, and deliver the same execution job twice. Each test should assert both the approval state and the number of business effects.

Include a crash after approval consumption but before dispatch, and another after dispatch before acknowledgement. The system should recover from the durable intent and effect ledger rather than requesting an unexplained second approval or silently repeating the action.

Record stale-approval reasons and the time spent waiting before admission. Frequent expiry may indicate an unrealistic validity window or an overloaded review queue. Fix the operating problem deliberately; extending every approval indefinitely removes the control rather than improving it.

The approval inbox guide covers review presentation, while tenant-scoped idempotency covers repeatable operation identity. Our AI integration services connect these mechanisms into a complete execution protocol.

FROM INSIGHT TO ACTIONAI-native implementation

Bind approval to the action that actually executes.

We help implement versioned approval records, atomic admission checks, and reconciliation for actions that cross service boundaries.

Explore AI implementationDiscuss your AI workflow

Start with your goals.
We’ll work through the next step together.