> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canary.effectiveai.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Safety for regulated operations

> How procedures keep approvals ahead of payments and notices, record what each run did, hold deadlines, keep repeated writes from applying twice, handle failures, ship changes and control access.

Cancellations, refunds, payouts and statutory notices move money and have legal deadlines. A
mistake can lead to a fine or a lawsuit. This page explains what a procedure does to keep these
operations correct, what it records, and what your own systems still have to do. Each section
links to the page with the exact rules.

## At a glance

| Concern | What Effective does | What you do |
| - | - | - |
| Approval before a write | Runs a write only on the path you put it on, such as after an approval | Put each payment and notice after the approval that must come first |
| Audit trail | Records each run's inputs, every step's inputs and outputs, each answer and who gave it | Keep your own systems' records, and the IDs the run returns |
| Deadlines | Holds a `wait` until an exact time, across restarts and deployments | Work out the deadline in the procedure, and watch approvals that are still open |
| Repeated writes | Never repeats a step whose result it has recorded; sends the same key on every retry of a step | Make each system you write to honour the key, or allow one attempt only |
| Failures | Ends the run `failed`, names the failed step, and keeps everything it recorded | Find failed runs, fix the cause and start a new run that is safe to repeat |
| Changes | Keeps every version unchanged; makes a version live on its own only if its inputs and output match | Review changes before they're published, and limit who can publish |
| Access | Checks who may publish, run, answer and control runs; never writes a secret's value to the record | Grant access to the right people and groups, set credentials in Effective, and keep secrets out of step results |

## Approvals before money moves or notices go out

An approval is a [`task`](https://docs.canary.effectiveai.app/procedures/reference/nodes/task) whose answer is a decision, followed by
a [`choice`](https://docs.canary.effectiveai.app/procedures/reference/nodes/choice) on that decision. Steps run in document order and
a `choice` runs only the section for its case. So a refund or a notice placed in the approved
section runs only after an approved answer. A rejection runs its own section and ends the run with
a result that says it was rejected. See
[Approvals](https://docs.canary.effectiveai.app/procedures/concepts/people-and-agents.md#approvals).

* **The approver sees the facts.** The task's title and instructions can show values from earlier
  steps, such as the policy, the dates and the amount. Data shown with the task is fixed when the
  task is created. See [`task`](https://docs.canary.effectiveai.app/procedures/reference/nodes/task#title-and-instructions).
* **Only assignees answer.** A task goes to people or groups. Only the task's assignees can
  answer it, in the Effective app or through the API. A procedure's task can't be reassigned by
  hand: its assignees are the ones the procedure names. A group stays assigned as a group, so
  changes to group membership still apply. See
  [Assignees](https://docs.canary.effectiveai.app/procedures/reference/nodes/task.md#assignees).
* **The answer must be complete.** An answer that doesn't match the task's form is refused. The
  first valid answer decides; a second answer can't move the run forward twice. See
  [On retry and resume](https://docs.canary.effectiveai.app/procedures/reference/nodes/task.md#on-retry-and-resume).
* **There is no timeout or automatic answer.** Neither a task nor an
  [agent step](https://docs.canary.effectiveai.app/procedures/reference/nodes/agent.md) has a timeout: a run waits until someone
  answers, or until the agent submits a result. If a deadline depends on the approval, watch open
  tasks from your system, as in [Answer a task](https://docs.canary.effectiveai.app/guides/procedures.md#answer-a-task).
* **Approvers are told.** When a task is created, each person it's assigned to, and each member of
  a group it's assigned to, gets a notification in Effective and an email. The email isn't sent
  to anyone who has already read the notification or turned that email off, and may be skipped
  for the person the run acts as. A task assigned to a person by name also gets a due date. If it is still open on
  that date, Effective reminds those people in Effective, and later tells the procedure's owner
  there. A task assigned only to a group gets no reminder, so watch its open tasks from your
  system.

## The audit trail

Every run keeps a record of what it did. The run's page in Effective shows:

* the inputs the run started with, and its output or why it failed;
* each step's inputs, output and status;
* each task, with the answer, the task and submission IDs, the note and attachments, who answered
  and when;
* each agent session, and child runs linked in both directions;
* the version the run ran.

A task's ID, the submission that answered it, who answered and when are never rewritten. See
[Runs and versions](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#who-can-see-a-run) and
[The answer envelope](https://docs.canary.effectiveai.app/procedures/reference/nodes/task.md#the-answer-envelope).

Through the API, a run gives its status, version, what started it (a person, a trigger or a
parent run), who it acts for, its output or failure, and its tasks. Open its `webUrl` for each
step. See [Read the result](https://docs.canary.effectiveai.app/guides/procedures.md#read-the-result).

Effective never writes a secret's value to the source, the version or the run record. Code that
reads a secret must not return it in a step's result, because results are recorded. A run also
never shows the message an effect's code threw. A thrown message could hold a secret, so a failed
run shows only the step and a failure code. Return a refusal you need to keep as part of a step's
result, and log details in your own systems.

To tie a run to your own records, have each write return the ID your system gave it, such as a
refund ID, and include it in the procedure's result. The
[Cancel a policy](https://docs.canary.effectiveai.app/procedures/tutorials/cancel-a-policy.md) tutorial does this.

A workspace administrator can permanently delete a finished run through the API, unless other
runs or records depend on it. Effective keeps a minimal record of each deletion: the run ID,
procedure, final status, who deleted it and when. The delete operation is deprecated: it keeps
working until at least 2027-03-01, then may be removed. After that, contact Effective support to
have a run deleted. See
[Delete a finished procedure run](https://docs.canary.effectiveai.app/api-reference/procedure-runs/delete-a-finished-procedure-run.md).

## Deadlines

A [`wait`](https://docs.canary.effectiveai.app/procedures/reference/nodes/wait) with `until` holds the run until an exact instant,
such as the date a cancellation notice must go out. It's a timer, not a loop that keeps checking
the clock:

* the run holds nothing open while it waits, for minutes or for days;
* the instant is read once, when the wait starts, and recorded with the run;
* after a restart or a deployment, the run resumes and wakes at the same instant;
* an instant that has already passed continues at once.

Work out the instant in a step, from the request's dates and your rules, so the run records it and
a task can show it to the approver. The [Cancel a policy](https://docs.canary.effectiveai.app/procedures/tutorials/cancel-a-policy.md)
tutorial works out the notice time with the return premium. A backdated request sends its notice
at once, so check dates in your own system before you start a run if that isn't what you want. See
[Instant form](https://docs.canary.effectiveai.app/procedures/reference/nodes/wait.md#instant-form).

A `wait` decides when the next step starts. The step that follows sends the request, and your
system or mail vendor delivers the notice; its own record shows when the notice went out.

A few more things matter for deadlines:

* A polling `wait` asks an outside system for a state, such as a payment being recorded, and has
  one `timeout`. When it runs out, the wait fails the run or continues with a value you choose.
  See [Polling form](https://docs.canary.effectiveai.app/procedures/reference/nodes/wait.md#polling-form).
* A schedule [trigger](https://docs.canary.effectiveai.app/procedures/reference/triggers.md#how-firings-behave) starts runs at set
  times. It doesn't replay firings missed while it was disabled, and it skips a firing while its
  previous run is still active. Keep scheduled runs short, or start one run for each item instead
  of working through every item in one run.
* A trigger runs as the person who enabled it. If that person can no longer run the procedure, or
  their authorization goes stale, the trigger stops starting runs. An event that arrives while it
  can't start a run isn't always reported in `lastError`. See
  [Create a trigger](https://docs.canary.effectiveai.app/procedures/reference/triggers.md#create-a-trigger).
* Watch triggers from your own systems: read each trigger's `nextRunAt`, `runCount` and
  `lastError`, or list [the runs it started](https://docs.canary.effectiveai.app/procedures/reference/triggers.md#find-a-triggers-runs),
  and act when a run you expected is missing.

## Writes that are safe to repeat

Effective doesn't guarantee that a write happens exactly once. A step whose result is recorded is
never run again, but a code step that was in progress when something failed can run again under
its retry policy. By default it gets three attempts. So a write can reach your system twice, or
reach it even though the answer never came back. See
[Writes to your systems](https://docs.canary.effectiveai.app/procedures/concepts/writes-to-your-systems.md).

What makes a repeat harmless is an **idempotency key**: a value sent with a write so that the
receiving system can recognize a repeat. Effective gives every attempt of one step the same key,
`operation.idempotencyKey`, and you can build your own. A system that honours the key applies the
first request and answers the others with the same result. Your systems have to honour it;
Effective can't do that for them.

* **Build keys from the business request.** A key such as `refund-CR-20931`, built from your own
  request ID, is the same in every run for that request. Then a second run for the same request
  gets the first refund back instead of a new one. See
  [Cancel, refund and notify, each with a key](https://docs.canary.effectiveai.app/procedures/tutorials/cancel-a-policy.md#cancel-refund-and-notify-each-with-a-key).
* **No key, one attempt.** For a system that can't honour a key, give the step a
  [retry policy](https://docs.canary.effectiveai.app/procedures/reference/nodes/retry.md) with one attempt. If the outcome is unknown,
  the run fails and a person checks, instead of retrying. This doesn't stop a second run for the
  same request from writing again; for that, look for the earlier write first. See
  [When your system has no idempotency key](https://docs.canary.effectiveai.app/procedures/concepts/writes-to-your-systems.md#when-your-system-has-no-idempotency-key).
* **Starting a run takes a key too.** A start request with the same key returns the run it
  already started. See [Start a run](https://docs.canary.effectiveai.app/guides/procedures.md#start-a-run).

## When something goes wrong

* **Retries first.** A code step that fails is retried under its policy. Code can stop at once
  when another attempt can't help, such as when your system refuses the request. See
  [Which failures retry](https://docs.canary.effectiveai.app/procedures/reference/nodes/retry.md#which-failures-retry).
* **The run fails, and says where.** When a step fails for good, the run ends `failed`. Its
  `failure` names the step and a code. Everything the run recorded before the failure stays. See
  [When a step fails](https://docs.canary.effectiveai.app/procedures/concepts/writes-to-your-systems.md#when-a-step-fails).
* **Writes that happened stay.** Failing a run doesn't undo a write that reached your system, and
  a procedure has no step that undoes earlier ones. Keep each write in its own step, so the
  record shows exactly which writes happened.
* **Recover with a new run.** A failed run's status is final, and the API has no way to resume
  it. Fix the cause and start a new run with the same inputs. Keys built from the request make
  your systems answer the writes that already happened with their first result. See
  [If a run fails partway](https://docs.canary.effectiveai.app/procedures/tutorials/cancel-a-policy.md#if-a-run-fails-partway).
* **Or start again from a checkpoint.** On a run's page in the Effective app, **Retry** on a
  run that didn't complete and **Run again** on a completed one start a new run from a checkpoint you pick, and
  **Restart** rewinds a run that hasn't finished to a checkpoint. The page shows what starts
  again from there. Calls, child runs, waits and tasks from that point run again, so a write among
  them reaches your system a second time. Use these only when your systems honour keys built from
  the request.
* **Expected refusals are results, not failures.** A policy that can't be cancelled, or a
  mismatch a person must explain, should come back as data the procedure routes on, so the run
  ends with a clear outcome.
* **Find failed runs.** List runs with `status=failed` from your own system. See
  [Read the result](https://docs.canary.effectiveai.app/guides/procedures.md#read-the-result). To act on each failure as it happens,
  use a [`procedure_run_terminal` trigger](https://docs.canary.effectiveai.app/procedures/reference/triggers#event) with
  `match.outcomes` set to `["failed"]` and `match.procedureId` set to the procedure you follow.

You can pause or resume a run in the Effective app, and cancel it there or through the API.
Cancelling is final. It also cancels the run's child runs and stops their open tasks and agent
sessions. See
[Pause, resume and cancel](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#pause-resume-and-cancel).

## Change control

* **Versions never change.** Each publish stores a new numbered version. A published version is
  never edited, and each run keeps the version it started with. See
  [Runs and versions](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#versions-never-change).
* **Publishing checks, and runs nothing.** Publishing refuses source that doesn't compile, and
  checks each declared capability and each secret declaration. It never runs the procedure's code.
* **Try a change as a draft.** A draft runs edited source without publishing it. It's private
  unless you share it, and a trigger never starts one. A draft can't declare secrets, so to try a
  procedure that reads credentials, run a stand-in copy without secrets. See
  [Drafts](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#drafts).
* **The live version moves on its own only when callers still fit.** Runs that don't name a
  version start the live one. A new version becomes live on its own only if its inputs and output
  match the live version's. Otherwise it waits until someone makes it live. You can also make an
  earlier version live again. If someone else changed the live version since you read it, your
  change is refused. See
  [The live version](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#the-live-version) and
  [Publish a new version](https://docs.canary.effectiveai.app/guides/procedures.md#publish-a-new-version).
* **Review before you publish.** Publishing a version with the same inputs and output makes it
  live at once. To stage a change, pin callers and triggers to an exact version, or publish it
  under a test `id` first.
* **Pin what must not move.** A run, a trigger or a child run can name an exact version instead
  of the live one. See
  [A run pins its version](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#a-run-pins-its-version).
* **Test against test systems.** Publish a copy with its own `id` whose code calls your test
  systems, with test credentials. See
  [Run it against your systems](https://docs.canary.effectiveai.app/procedures/tutorials/cancel-a-policy.md#run-it-against-your-systems).

Publishing has no separate sign-off step in Effective: anyone with permission to publish a
procedure can publish its next version. A publish can name the version it expects to be the
latest, so it's refused if someone else published first. Keep the source in source control,
review changes there before they're published, and give publish permission only to the people who
ship changes.

## Who can do what

| Action | Who |
| - | - |
| Publish a version | People with permission to publish the procedure. A new procedure belongs to the person who first published it. Only they can run it until they share it, unless they published it for the whole organization |
| Make a version live | People with permission to publish the procedure |
| Start a run | People with permission to run the procedure, and [triggers](https://docs.canary.effectiveai.app/procedures/reference/triggers.md) that one of them authorized |
| See a run | Everyone who can run the procedure, unless the run was started as private. A run in a Project also needs view access to that Project |
| Answer a task | The task's assignees only |
| Pause, resume or cancel | The person the run acts as, and workspace administrators |
| Enable a trigger | People with permission to manage the procedure. The trigger then runs as the person who enabled it |

See [Who can do what](https://docs.canary.effectiveai.app/guides/procedures.md#who-can-do-what).

* **A run acts as a person.** A run acts as the person who started it, or as the person who
  authorized its trigger. Each firing checks that person's access again. Child runs act as the
  same person. See [Who a run acts as](https://docs.canary.effectiveai.app/procedures/concepts/people-and-agents.md#who-a-run-acts-as).
* **Code can only do what it declares.** A pure function gets no network, secrets or clock. An
  effect declares what it may use: requests to public hosts, the secrets it names, or the exact
  Effective API operations it calls, each write named on its own. Publishing checks the
  declarations. See [Capabilities](https://docs.canary.effectiveai.app/procedures/reference/nodes/function-and-effect.md#capabilities).
* **Secrets stay out of the source and the record.** A procedure declares the credentials it
  needs; their values are set in Effective, as a shared value or a person's own. Effective never
  writes a secret's value to the source, the version or the run record. Code that reads a secret
  must not return it in a step's result, because results are recorded. See
  [Give a secret a value](https://docs.canary.effectiveai.app/procedures/reference/nodes/secret.md#give-a-secret-a-value).
* **Agents are bounded.** An agent step's tools and settings are fixed in the source, its input
  and result are checked, and your organization's policies on models, tools and budgets are
  checked when you publish and when a run starts. See
  [People and agents](https://docs.canary.effectiveai.app/procedures/concepts/people-and-agents.md#agents-agent-steps).

## Running many at once

Each request starts its own run, with its own record. Inside a run, a
[`for-each`](https://docs.canary.effectiveai.app/procedures/reference/nodes/for-each) works through up to 1,000 items, as many at a
time as its `concurrency` allows, and a [`parallel`](https://docs.canary.effectiveai.app/procedures/reference/nodes/parallel) runs a
fixed set of branches at the same time. Folder and event triggers start one run for each file or
event. See [Many runs at once](https://docs.canary.effectiveai.app/procedures/concepts/runs-and-versions.md#many-runs-at-once).

## Before you go live

* Run a stand-in copy without secrets as a draft, then the procedure against test systems with
  test credentials.
* Start a second run for the same request, and check that your systems wrote nothing twice.
* Make a step fail on purpose, and check that you can find the failed run and see which step
  failed.
* Check who can publish, who can run, and which groups answer each task.
* Decide which callers and triggers follow the live version and which pin an exact one.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.