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

Governed effects

Turn an action into one recorded business operation: reserved against your limits, bound to its approval, graded, and recoverable when the provider's response is lost.

An action with no declaration sends one HTTP request and records what came back. A governed effect goes further. Anlyon knows how much the operation changes, which exact request was reviewed, and how to read the result back. So it can reserve the impact against shared limits, bind the approval to exactly that request, return a graded receipt, and recover safely when a response is lost.

Why govern an action

An agent that refunds, emails or edits files will meet timeouts, retries, stale state and people who approve one thing while the agent sends another. Handling that correctly means idempotency keys per provider, a reservation ledger, a read-back for each write, an evidence log and an operator queue.

  • Risk. One operation per request: a lost response is never sent again blind, a changed request never runs on an old approval, and a limit is reserved before the write.
  • Effort. You opt in per action with an adapter or a few declared fields. You do not write the reconciliation, the evidence store or the ledger.
  • Cost. An uncertain write is looked up with a read, and its allowance stays held, so it cannot free room for a duplicate.

Make an action governed

You opt in per action, in one of two ways:

  • Give the action an adapter. Three adapters exist: stripe.refund, github.file_update and resend.email_send.
  • Declare impact, verify or governed: true on an HTTP action of your own. That is a declared action. See Actions and Govern any HTTP API.

Nothing about an existing action changes unless you give it an adapter or a declaration.

How it works

  1. Admit. The invoke request is validated, its operationKey (or Idempotency-Key) identifies the operation, and an effect is recorded with a preview of the exact request.
  2. Gate. If approval is required, the effect waits in awaiting_approval, bound to the preview’s digest.
  3. Claim and reserve. Immediately before the write, in one transaction, Anlyon re-checks the binding, the approval, the action version, the halt switch, the requesting key, current policy and dependencies, and reserves every applicable limit.
  4. Dispatch once. The adapter sends the write with the provider idempotency key or precondition it supports.
  5. Settle. The response, a read-back or the provider’s own record sets the outcome. Confirmed impact is consumed, impact known not to have happened is released, and anything uncertain stays held while Anlyon reconciles.

The three adapters and declared actions, side by side

stripe.refund github.file_update resend.email_send A declared action
Operation A refund of an explicit amount on a payment intent An update to one existing text file on a designated branch One email from a designated sending domain The HTTPS request your definition describes
Counted as money in the action’s currency, plus one resource_mutations One resource_mutations emails, one per recipient across to, cc and bcc Your impact.amount, in your dimension
“Succeeded” means A Stripe Refund carrying this effect’s id reaches status succeeded A commit on that branch, created by this write, carries Anlyon-Effect: <effect id> Resend accepted the send and returned an email id The provider answered the write with a 2xx
confirmed means Every success is read from Stripe’s own record of the refund Every success is read from GitHub’s own record of the commit A read-back of the email id shows this effect’s tag A read-back matched your verify rule
Provider idempotency Yes. The adapter sends the effect’s Idempotency-Key and treats it as usable for 24 hours No. The adapter sends the reviewed blob SHA as a precondition instead Yes. The adapter sends the effect’s Idempotency-Key. Resend keeps a key for 24 hours No
Stale-state protection Not atomic. The adapter re-checks the account before dispatch and sends no conditional write Atomic. The write carries the reviewed blob SHA None. Resend has no conditional send None. Anlyon does not know the API’s preconditions
Lookup after a lost response By refund id, or by the anlyon_effect metadata on the payment intent By a commit whose message carries the effect trailer By email id, or by a bounded scan of recent sent emails for the anlyon_effect tag By repeating the read-back, when the verify rule does not need the response
Same-key replay Yes, within 24 hours No Yes, within 24 hours No. A replay is refused before any write
Later completion Tracked. A refund accepted as pending is read back up to 12 times. After that it stays unresolved until an operator resolves it The commit exists when GitHub answers Not tracked. Delivery, bounces and complaints happen after acceptance Not tracked. A 2xx is recorded as the result
Undo No. A refund cannot be reversed through the Stripe API Yes, by a new and separately reviewed file update No. A sent email cannot be recalled Not known to Anlyon. Define a separate governed action for the reversal

Statements about Resend’s API on this page are as of 2026-10-03.

Define an adapter action

An adapter builds the request. You give it an explicit target and a vault secret name. There is no URL template, and no default account, branch or sending domain that could change after review.

Define actions with an operator key, never the agent’s. Storing a secret needs secrets:write, and referencing one from an action needs secrets:read; neither is in the default set. Creating an action needs actions:write. The secret’s allowedHosts must include the host the adapter calls, or the action is refused.

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

// Operator key: actions:write, secrets:write, secrets:read.
const operator = new Client({ apiKey: process.env.ANLYON_OPERATOR_KEY! });

await operator.secrets.put('STRIPE_SECRET_KEY', { value: process.env.STRIPE_SECRET_KEY!, allowedHosts: ['api.stripe.com'] });
await operator.secrets.put('GITHUB_TOKEN', { value: process.env.GITHUB_TOKEN!, allowedHosts: ['api.github.com'] });
await operator.secrets.put('RESEND_API_KEY', { value: process.env.RESEND_API_KEY!, allowedHosts: ['api.resend.com'] });

await operator.actions.create({
  name: 'refund',
  requiresApproval: true,
  adapter: {
    type: 'stripe.refund',
    config: { account: 'acct_1Nxyz', mode: 'live', currency: 'usd' },
    credentialSecret: 'STRIPE_SECRET_KEY',
  },
});

await operator.actions.create({
  name: 'update-fixture',
  adapter: {
    type: 'github.file_update',
    config: { owner: 'acme', repo: 'fixtures', branch: 'anlyon-test', pathPrefix: 'data/' },
    credentialSecret: 'GITHUB_TOKEN',
  },
});

await operator.actions.create({
  name: 'send-receipt',
  adapter: {
    type: 'resend.email_send',
    config: { domain: 'mail.example.com', fromAddresses: ['billing@mail.example.com'] },
    credentialSecret: 'RESEND_API_KEY', // a full access key: a sending access key cannot read back
  },
});
curl -s -X POST https://api.anlyon.com/api/v2/actions \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "refund",
    "requiresApproval": true,
    "adapter": {
      "type": "stripe.refund",
      "config": { "account": "acct_1Nxyz", "mode": "live", "currency": "usd" },
      "credentialSecret": "STRIPE_SECRET_KEY"
    }
  }'
import os
from anlyon import Client

operator = Client(api_key=os.environ["ANLYON_OPERATOR_KEY"])

operator.secrets.put("STRIPE_SECRET_KEY", value=os.environ["STRIPE_SECRET_KEY"], allowed_hosts=["api.stripe.com"])

operator.actions.create(
    name="refund",
    requires_approval=True,
    adapter={
        "type": "stripe.refund",
        "config": {"account": "acct_1Nxyz", "mode": "live", "currency": "usd"},
        "credentialSecret": "STRIPE_SECRET_KEY",
    },
)
  • stripe.refund takes mode: "live" or mode: "test" and a Stripe key that matches it: sk_live_ or rk_live_ for live, sk_test_ or rk_test_ for test. The payment intent must belong to the same mode. Amounts are exact integer minor units in the action’s one currency. Its input is paymentIntent (an id starting pi_), amount, currency and an optional reason. Its credentialSecret is the name of a secret in the environment’s own vault (a stored key or a connected Stripe account), never a {{connection:...}} reference, and that secret must exist even when every call is made for an end user. When it is a connected Stripe account, a call made for an end user uses that user’s own Stripe connection; when it is a stored key, every call uses that key.
  • github.file_update refuses the repository’s default branch unless the config says allowDefaultBranch: true. It refuses files it cannot read as UTF-8 text or that exceed 64 KB. It changes one existing file per effect.
  • resend.email_send needs an explicit sending domain. Every from address must be on it, and fromAddresses narrows that to a list. It refuses a credential that is not a Resend API key (starting re_). to takes 1 to 50 addresses, and cc and bcc take up to 50 each. The input needs html, text or both.

A declared action is defined like any other HTTP action, with its declarations. See Actions and Govern any HTTP API.

Invoke a governed action

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

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

const { data } = await agent.actions.invoke(
  'refund',
  { paymentIntent: 'pi_3Pabc', amount: 1250, currency: 'usd' },
  { operationKey: 'order-4411-refund' },
);

console.log(data!.status);    // pending_approval, succeeded, running, unknown, failed
console.log(data!.grade);     // pending, confirmed, acknowledged, unknown, failed, refused or denied
console.log(data!.effectId);  // eff_ id
curl -s -X POST https://api.anlyon.com/api/v2/actions/refund/invoke \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-4411-refund" \
  -d '{ "input": { "paymentIntent": "pi_3Pabc", "amount": 1250, "currency": "usd" }, "operationKey": "order-4411-refund" }'
agent = Client(api_key=os.environ["ANLYON_API_KEY"])

result = agent.actions.invoke(
    "refund",
    {"paymentIntent": "pi_3Pabc", "amount": 1250, "currency": "usd"},
    operation_key="order-4411-refund",
)
print(result.data["status"], result.data["grade"], result.data["effectId"])

A gated call answers 202 with status: "pending_approval" and an approvalId. Invoking needs actions:invoke. To act in one of your users’ own accounts, build the client with forUser(userId); the effect then records endUserId, and per-user limits and approvals apply. See Workspace connections and end-user connections.

Operation identity. Repeating the same operationKey with the same request returns the existing operation, and nothing is sent again. Reusing it with a different request is refused with 409 OPERATION_KEY_REUSE. When you do not pass one, the Idempotency-Key is used, then a fresh key. Two different keys do not make two requests different business intent: two refunds of the same payment under two keys are two refunds. What bounds that is an impact limit, not identity. operationKey is 1 to 200 characters of letters, digits and . _ : -.

API reference: Invoke an action.

Read stage, outcome and verification

An effect has a stage (awaiting_approval, ready, dispatching, reconciling, settled or rejected) and an outcome (what happened in the world):

Outcome Meaning
not_dispatched Nothing has been sent, or nothing ever will be (a rejected effect).
pending The provider accepted the work and has not finished it (a Stripe refund in pending).
succeeded Evidence establishes the declared result.
failed Evidence establishes that the declared result did not happen. partialEffect says whether some of it might have (possible) or did (confirmed): a failure is not proof of zero impact.
unknown The available evidence cannot establish the result.

verification says who established the outcome: provider (the provider’s own evidence), manual (an operator’s resolution, never shown as provider verification), unverified, or not_dispatched.

Every effect also carries a grade, derived from the stage, the outcome and the verification: confirmed, acknowledged, unknown, failed, refused, denied or pending. See Receipts and grades.

Recover when the response is lost

A timeout, a reset connection, a 5xx, or a worker that dies after sending all end the same way. The outcome is unknown, never failed, and nothing is retried. Anlyon schedules a reconciliation with backoff. It reads and never writes, and it asks the provider:

  • Stripe: by refund id when the response arrived, otherwise by the anlyon_effect metadata every refund carries. Finding the refund settles the effect. Not finding it proves nothing, because metadata can be removed after the fact, so the effect stays unknown with its allowance held. The adapter offers a same-key replay for 24 hours. After that, an operator resolves it with evidence.
  • GitHub: by a commit on the branch whose message carries the effect trailer. Finding one confirms success. Not finding one never proves the write failed: a force-push can remove a commit that landed, and the search is bounded. Matching file content alone is never taken as proof that Anlyon made the change.
  • Resend: by email id when the response arrived. After a lost response Resend offers no lookup by idempotency key, so Anlyon lists recent sent emails and reads candidates by id for the anlyon_effect tag, bounded at 3 pages and 20 reads. Finding the email settles the effect. A same-key replay inside 24 hours is the other recovery, and a send recovered that way grades acknowledged.
  • A declared action: by repeating the read-back you declared. A match confirms the write. No match proves nothing, so the effect stays unknown. The write is never repeated. A verify rule that needs the provider response cannot run after that response was lost, and an action with no verify rule has nothing to read. Both stay unknown until an operator resolves them.

Lookups start 30 seconds after the unknown outcome, double each time up to one hour, and stop after 12 attempts. See When the outcome is unknown for each way out.

// Operator key with actions:resolve (reconcile alone needs actions:invoke).
const { data: open } = await operator.actions.effects({ unresolved: true });
const { data: effect } = await operator.actions.effect('eff_01JABCDEF');

for (const item of effect!.evidence) console.log(item.observedAt, item.source, item.summary);

await operator.actions.reconcileEffect('eff_01JABCDEF');          // read-only, now
await operator.actions.addEffectNote('eff_01JABCDEF', 'Asked Stripe support, ticket 81233.');
await operator.actions.resolveEffect('eff_01JABCDEF', {           // manual, labelled as such
  outcome: 'failed',
  reason: 'No refund exists for pi_3Pabc in the Stripe dashboard.',
});
curl -s -X POST https://api.anlyon.com/api/v2/actions/effects/eff_01JABCDEF/reconcile \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY"

curl -s -X POST https://api.anlyon.com/api/v2/actions/effects/eff_01JABCDEF/resolve \
  -H "Authorization: Bearer $ANLYON_OPERATOR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "outcome": "failed", "reason": "No refund exists for pi_3Pabc in the Stripe dashboard." }'
open_effects = operator.actions.effects(unresolved=True).data
effect = operator.actions.effect("eff_01JABCDEF").data

operator.actions.reconcile_effect("eff_01JABCDEF")
operator.actions.add_effect_note("eff_01JABCDEF", "Asked Stripe support, ticket 81233.")
operator.actions.resolve_effect(
    "eff_01JABCDEF",
    outcome="failed",
    reason="No refund exists for pi_3Pabc in the Stripe dashboard.",
)

Evidence is append-only: every observation keeps its source (preview, provider_response, provider_lookup, system, operator_note or manual_resolution), time, provider ids and redacted details, and a later observation never erases an earlier one. A confirmed outcome is never rewritten, including when the file or payment changes later.

A resolution’s reason is 10 to 2000 characters. To record a failure that partly happened, pass partialEffect: "confirmed" with actualImpact, the quantities that did happen; those are consumed and the rest released.

Rehearse a lost response with the Stripe fault drill

You cannot make Stripe lose a response on demand, so stripe.refund can do it for you. The drill needs mode: "test" and a test key. Give an action faultDrill: "drop_response_after_send" and Anlyon sends the refund to Stripe as usual, then discards Stripe’s answer, exactly as a connection lost after the write would. The effect is recorded unknown, its allowance stays held, nothing is sent again, and the reconciler settles it from Stripe’s record on its normal schedule (the first lookup is about 30 seconds later).

await operator.secrets.put('STRIPE_TEST_KEY', { value: process.env.STRIPE_TEST_KEY!, allowedHosts: ['api.stripe.com'] });

await operator.actions.create({
  name: 'refund-drill',
  adapter: {
    type: 'stripe.refund',
    config: { account: 'acct_1Nxyz', mode: 'test', currency: 'usd', faultDrill: 'drop_response_after_send' },
    credentialSecret: 'STRIPE_TEST_KEY',
  },
});

The drill is part of the action’s versioned config and every preview of it says “Fault drill”, so nobody approves a drill without seeing it is one. A replay of a drilled effect is drilled too. Keep drills on their own action: every invocation of a drilled action loses its response.

Replay a lost write under the same identity

Replay (replayEffect) repeats a lost write under the same provider identity. It needs a provider idempotency key, so two adapters offer it: Stripe and Resend, each within a 24-hour window. GitHub file updates do not: the reviewed blob SHA cannot tell a file someone restored from one that was never written, so a repeat could apply the change twice. A declared action does not either. It has no provider idempotency key, so a replay is refused with replay_unsupported before anything is sent.

A replay is a write, and it passes every control an original dispatch passes: the reviewed preview must still be current, the approval must hold, the action must still resolve to the reviewed version, the environment must not be halted, the requesting credential must still be active, and current policy must still allow it. A refusal answers 409 REPLAY_REFUSED with a message that begins Replay refused (<reason>):. The reasons include replay_unsupported, not_unknown, replay_window_passed, credential_unavailable, allowance_released and write_in_flight, or the dispatch control that failed. It is recorded in the effect’s evidence and sends nothing.

Two refusals come earlier and are not recorded on the effect. During a halt the call answers 409 ENVIRONMENT_HALTED. The key that requested the effect cannot replay it and gets 403. Replaying needs actions:resolve.

A replay that is admitted but fails describes that attempt, not the original write. The effect stays unknown and its allowance stays held. One write may be in flight at a time, and a replay never creates a second effect.

After the original dispatch, the provider’s own record of the operation in a failed state is what settles an effect failed without a person. Failing to find the operation, or failing to repeat it, never does: releasing allowance for an operation that may have happened is the error Anlyon is built to avoid. Reconcile, notes and resolve stay available while the environment is halted. Replay does not.

An invocation governed by an effect is resolved through its effect, never through POST /api/v2/actions/invocations/{id}/resolve, which refuses it with 409 EFFECT_RESOLUTION_REQUIRED: settling only the invocation would leave the effect unknown and its allowance held.

Operation Scope for a key In the console
Reconcile actions:invoke Admin or member
Add a note actions:resolve Admin
Resolve actions:resolve Admin
Replay actions:resolve Admin

The key that requested an effect can never resolve or replay it.

Make one operation depend on another

Where one operation must follow another, say so. Pending and unknown outcomes never satisfy a dependency, and neither does a failure that may have partly happened:

await agent.actions.invoke(
  'update-fixture',
  { path: 'data/refunds.txt', content: 'order-4411: refunded\n', message: 'Record refund' },
  { dependsOn: [{ effect: 'eff_01JABCDEF', outcome: 'succeeded' }] },
);
curl -s -X POST https://api.anlyon.com/api/v2/actions/update-fixture/invoke \
  -H "Authorization: Bearer $ANLYON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": { "path": "data/refunds.txt", "content": "order-4411: refunded\n", "message": "Record refund" },
    "dependsOn": [{ "effect": "eff_01JABCDEF", "outcome": "succeeded" }]
  }'
agent.actions.invoke(
    "update-fixture",
    {"path": "data/refunds.txt", "content": "order-4411: refunded\n", "message": "Record refund"},
    depends_on=[{"effect": "eff_01JABCDEF", "outcome": "succeeded"}],
)

An unmet dependency answers 409 DEPENDENCY_UNRESOLVED at admission, naming each effect, the outcome it needs and the outcome it has. Up to 10 dependencies per call. Dependencies are checked again at dispatch.

A compensation (undoing an effect) is a new governed effect with its own preview, approval, impact and outcome. Invoke the compensating action with compensates: 'eff_01JABCDEF'.

Errors you may see

Status and code When What to do
202, status: pending_approval The action or a policy requires approval. Wait for the decision, or poll the invocation.
200, status: failed, grade: refused A dispatch control refused the effect. rejectionReason says which. See When approval expires or changes and When the limit is hit.
200, status: unknown The response was lost or the provider answered 5xx. Do not invoke again. See When the outcome is unknown.
409 OPERATION_KEY_REUSE The operationKey already names a different request. Use the same request to repeat it, or a new key for a new operation.
409 DEPENDENCY_UNRESOLVED A dependsOn effect is not in its required outcome. Wait for it to settle.
409 PREVIEW_MISMATCH, PREVIEW_EXPIRED, PREVIEW_ALREADY_USED The previewId does not describe this call. See Bound approvals and previews.
409 REPLAY_REFUSED A replay failed a control. The message names the reason. Reconcile or resolve instead.
409 ENVIRONMENT_HALTED The environment is halted. Resume it, or wait. See Environments.
409 END_USER_NOT_CONNECTED, END_USER_RECONNECT_REQUIRED A call for an end user whose account is missing or broken. Send the user the connectUrl.

How it behaves

stripe.refund

  • One currency per action, and every refund carries an explicit amount.
  • The refundable amount in a preview is as of review. The adapter re-checks the account before dispatch.

github.file_update

  • One existing UTF-8 text file per effect, up to 65536 bytes.
  • The write carries the reviewed blob SHA as its precondition.
  • A commit that lookup cannot find leaves the effect unknown until an operator resolves it with evidence.

resend.email_send

  • One sending domain per action, and one email per effect.
  • The vault secret is a full access key. The read-back and the lookup use it.
  • Confirmed is Resend’s record of the send, not inbox delivery.

A declared action

  • The write is sent once, with no provider idempotency key. A replay is refused before anything is sent.
  • A 2xx with a matching read-back grades confirmed. A 2xx with no verify rule grades acknowledged.
  • A verify URL that reads {{response.*}} needs the provider response. After a lost response an operator resolves that effect.
  • A verify rule can match a resource that already existed. Write a rule that distinguishes this write.

Every governed effect

  • A lost response that lookup cannot find stays unknown, with its allowance held, until a replay inside the provider’s window or an operator’s resolution. An operator’s resolution is labelled manual.
  • A receipt is a database record with provider evidence.

Was this page helpful?