An agent sends an order. The external service executes it, but its reply is lost on the way back. The agent’s tool call fails. Did anything happen?

Yes, possibly: the order may exist. A failed call tells you that your code did not get an answer, not that the service did nothing. This article follows that case through Authority’s experimental SDK: what each result means (EFFECT_FAILED, EXECUTED, UNKNOWN_OUTCOME, ALREADY_REDEEMED), what the journal records, what a retry does, and why an idempotency key per ticket does not protect against a new business action. It also says which of its statements the tests do not directly demonstrate.

The scenario

A human, alice, delegates to an agent, agent-1, the right to create purchase orders: up to 2,500 EUR on its own, with a total budget of 5,000 EUR. The agent sends order po-42 (2,000 EUR, business reference ORDER-7) to an external ordering service. The service records the order, then the network drops the reply. The agent’s code gets a timeout.

09:00  ACTION_REQUESTED, CAPABILITY_ISSUED   po-42  authorize → AUTHORIZED, a single-use ticket
09:00  CAPABILITY_REDEEMED                   po-42  redeem → REDEEMED, the effect may start
09:00  the service records ORDER-7           ... and its reply is lost: the effect throws
09:00  ACTION_EXECUTED (EFFECT_FAILED)       po-42  guard reports it
       the agent retries (the same action, then a new action po-43)

From the agent’s side, this failure looks exactly like a service that refused the order. Authority sees only that the function it was given threw an exception.

Four results, four different meanings

  • EFFECT_FAILED (from guard, with code: "EFFECT_THREW" and ticketConsumed: true): the function you passed to guard threw, after the ticket had been redeemed. It says nothing about whether the external effect happened. A service that refused the call and a call that timed out give the same public result and the same journal code. The thrown value is not in the result (it goes to the diagnostics callback), and guard never runs the effect a second time.
  • EXECUTED (from guard): the function returned. If it returns a value that you consider a failure (for example { ok: false }), guard still reports EXECUTED and the journal records ACTION_EXECUTED with the code EXECUTED. The journal can say “executed” about an action that failed.
  • UNKNOWN_OUTCOME (code OUTCOME_UNCERTAIN, from the redemption): the call that redeems the ticket threw, for example because the connection to the store dropped after the commit. The effect was not started. The ticket may or may not be consumed; in the script below it was, and a second attempt shows it.
  • ALREADY_REDEEMED (a REFUSED result at redemption): a CAPABILITY_REDEEMED already exists for this ticket. It carries ticketConsumed: false, because that field describes this call: this call consumed nothing, although an earlier one did.

Three questions that look like one

  1. Did your function fail? Authority knows this: it saw the exception. That is EFFECT_FAILED.
  2. What did the external service really do? Only the service knows. Authority has no connection to it. The ordering service in the script is simulated, and its record is not visible to Authority.
  3. Are you sure? After a lost reply you are not, and neither is Authority. Treat EFFECT_FAILED as “unknown unless you check with the service”, not as “did not happen”.

Authority has no result for “the target confirmed that it did not do it”. A code of your own, such as TARGET_REJECTED, can be recorded by calling authorize, redeem and report yourself, but Authority gives that code no meaning: the engine never reads it, and it changes no later decision.

What is recorded, and what a retry does

The output of the script below, at the pinned commit, answers each point.

  • Journal after the failure: DELEGATION_CREATED, ACTION_REQUESTED, CAPABILITY_ISSUED, CAPABILITY_REDEEMED, ACTION_EXECUTED, and the ACTION_EXECUTED carries the code EFFECT_FAILED. The service holds one order.
  • The same action, again: guard returns BLOCKED at the redemption stage with ALREADY_REDEEMED, and the effect does not run (test). The ticket stays consumed.
  • A late report: if you learn afterwards that the order did go through and try to report EXECUTED, you get ALREADY_REPORTED. The first report of an action wins, and there is no way to correct it (test, and its PostgreSQL twin).
  • Asking for authorization again for the same action returns AUTHORIZED with the same ticket (test, for a redeemed ticket that was never reported). So AUTHORIZED does not mean “this ticket is still usable”.
  • A lost redemption reply (UNKNOWN_OUTCOME): the effect did not start, and a second attempt is refused with ALREADY_REDEEMED. The journal holds one redemption (test, and its PostgreSQL twin).

Why one key per ticket does not protect a new action

guard hands your effect an idempotencyKey: it is the ticket’s identifier (in the code, and its test). A service that deduplicates on that key will ignore a second request carrying the same key. But Authority never sends the same ticket to your effect twice: guard does not retry, and an action holds at most one ticket, definitively (invariant I32, in SPEC.md). So the key can never deduplicate a retry made by guard.

The only way to try again after EFFECT_FAILED is a new action (here po-43, same content). It gets a new ticket and therefore a different idempotency key: the service sees a different request (test, and its PostgreSQL twin). In the script, if the first attempt did complete, the service now holds two orders for one business reference. Authority cannot prevent that. A new action may also need its own approval, and it spends budget of its own.

What protects you is a stable business key that you carry in the arguments (here orderRef) and that your target deduplicates on, plus a check with the target before retrying. The key Authority gives you identifies an attempt, not an order.

Reproduce it

The scripted demo covers authorization, approval and the effect; this script focuses on what happens when the reply is lost. It uses only the public entry point of the experimental SDK (not published to npm, not independently reviewed) and its event builders, with a clock you control. The ordering service is simulated in the script: it is a list, not a network call.

git clone https://github.com/theoadam2506-rgb/authority-graph.git
cd authority-graph
git checkout 1df9d7a8a9d1468d978f59b752c65ada38701f18
npm ci
# save the script below as lost-reply.ts, then:
npx tsx lost-reply.ts
import { createAuthority, createEventBuilders, memoryBackend, type Backend, type ToolCall } from "./src/sdk/index.js";

// A clock you control: Authority has no default clock.
let now = Date.parse("2026-06-01T09:00:00.000Z");
const clock = { now: () => new Date(now).toISOString() };
const events = createEventBuilders({ clock });

// The external service, simulated: it keeps what it was asked to do. Authority never sees this list.
const service: { key: string; orderRef: string }[] = [];
const sendOrder = (orderRef: string, loseTheReply: boolean) => async ({ idempotencyKey }: { idempotencyKey: string }) => {
  service.push({ key: idempotencyKey, orderRef }); // the service DOES execute the order...
  if (loseTheReply) throw new Error("timeout while waiting for the reply"); // ...but the reply never arrives.
  return "order accepted";
};

const authority = createAuthority({ backend: memoryBackend(), clock, enforcementPointId: "orders-gateway" });
await authority.record([events.delegation({
  delegationId: "d-1", grantor: "alice", grantee: "agent-1",
  capabilities: [{ resource: "purchase_order", action: "create" }], canDelegate: false, expiresAt: null,
  thresholds: { automaticMax: { value: 2500, currency: "EUR" }, approvalMax: { value: 5000, currency: "EUR" } },
  totalBudget: { value: 5000, currency: "EUR" },
})]);
const order = (actionId: string): ToolCall => ({ actionId, agentId: "agent-1", delegationId: "d-1",
  capability: { resource: "purchase_order", action: "create" },
  amount: { value: 2000, currency: "EUR" }, recipient: "vendor-1", args: { orderRef: "ORDER-7", sku: "A-100", qty: 7 } });
// Public results are plain data. The random diagnostic id is left out so that the output is the same on every run.
const show = (value: unknown) => JSON.stringify(value, (k, v) => (k === "diagnosticId" ? undefined : v));
const journal = async () => (await authority.events()) as unknown as { event_type: string; payload: { execution_result?: string } }[];
const types = async () => (await journal()).map((e) => e.event_type).join(", ");

// 1. The agent sends order po-42. The service executes it, then the reply is lost: the effect throws.
const first = await authority.guard(order("po-42"), sendOrder("ORDER-7", true));
if (first.status !== "EFFECT_FAILED") throw new Error("expected EFFECT_FAILED");
console.log("1. guard po-42                :", show({ status: first.status, code: first.code, ticketConsumed: first.ticketConsumed, report: first.report.status }));
console.log("   service holds              :", service.length, "order(s)");
console.log("   journal                    :", await types());
console.log("   ACTION_EXECUTED code       :", (await journal()).filter((e) => e.event_type === "ACTION_EXECUTED").map((e) => e.payload.execution_result).join(", "));

// 2. The agent tries again with the same action. Authority does not run the effect a second time.
let reruns = 0;
const second = await authority.guard(order("po-42"), async () => { reruns++; return "never runs"; });
console.log("2. guard po-42 again          :", show(second), "| effect runs:", reruns);

// 3. The agent learns that the order did go through, and reports it. The first report is final.
const ticket = (await authority.authorize(order("po-42")));
if (ticket.status !== "AUTHORIZED") throw new Error("expected the same ticket again");
console.log("3. authorize po-42 again      :", ticket.status, "| same ticket as the effect received:", ticket.ticket.capabilityId === service[0]!.key);
console.log("   report EXECUTED, late      :", show(await authority.report(ticket.ticket, { resultCode: "EXECUTED" })));

// 4. The agent retries through a NEW action, po-43, with the same business content.
const third = await authority.guard(order("po-43"), sendOrder("ORDER-7", false));
console.log("4. guard po-43 (new action)   :", third.status);
console.log("   service holds              :", service.length, "order(s), for", new Set(service.map((o) => o.orderRef)).size, "business order ref");
console.log("   idempotency keys differ    :", service[0]!.key !== service[1]!.key);

// 5. The failed attempt still holds budget: 2,000 (po-42) + 2,000 (po-43) of 5,000.
console.log("5. a third order, po-44       :", show(await authority.authorize(order("po-44"))));

// 6. Another failure: the redemption itself is lost after it was committed (the store's reply never arrives).
const lostAck: Backend = {
  build(ingestionClock) {
    const parts = memoryBackend().build(ingestionClock);
    let calls = 0;
    return { ...parts, redemption: { redeem: async (...args) => {
      const result = await parts.redemption.redeem(...args);
      if (calls++ === 0) throw new Error("connection reset after commit"); // only the first call loses its reply
      return result;
    } } };
  },
};
const other = createAuthority({ backend: lostAck, clock, enforcementPointId: "orders-gateway" });
await other.record([events.delegation({
  delegationId: "d-1", grantor: "alice", grantee: "agent-1",
  capabilities: [{ resource: "purchase_order", action: "create" }], canDelegate: false, expiresAt: null,
  thresholds: { automaticMax: { value: 2500, currency: "EUR" }, approvalMax: { value: 5000, currency: "EUR" } },
})]);
let started = 0;
const lost = await other.guard(order("po-50"), async () => { started++; return "never runs"; });
console.log("6. guard po-50, ack lost      :", show(lost), "| effect started:", started);
const lostAgain = await other.guard(order("po-50"), async () => { started++; return "never runs"; });
console.log("   guard po-50 again          :", show(lostAgain), "| effect started:", started);
console.log("   redemptions in the journal :", ((await other.events()) as unknown as { event_type: string }[]).filter((e) => e.event_type === "CAPABILITY_REDEEMED").length);

Expected output, identical on every run (the random diagnostic identifier is left out of the printed results):

1. guard po-42                : {"status":"EFFECT_FAILED","code":"EFFECT_THREW","ticketConsumed":true,"report":"REPORTED"}
   service holds              : 1 order(s)
   journal                    : DELEGATION_CREATED, ACTION_REQUESTED, CAPABILITY_ISSUED, CAPABILITY_REDEEMED, ACTION_EXECUTED
   ACTION_EXECUTED code       : EFFECT_FAILED
2. guard po-42 again          : {"status":"BLOCKED","stage":"redeem","result":{"status":"REFUSED","reason":"ALREADY_REDEEMED","ticketConsumed":false}} | effect runs: 0
3. authorize po-42 again      : AUTHORIZED | same ticket as the effect received: true
   report EXECUTED, late      : {"status":"ALREADY_REPORTED"}
4. guard po-43 (new action)   : EXECUTED
   service holds              : 2 order(s), for 1 business order ref
   idempotency keys differ    : true
5. a third order, po-44       : {"status":"DENIED","reason":"C9_TOTAL_BUDGET_EXCEEDED"}
6. guard po-50, ack lost      : {"status":"BLOCKED","stage":"redeem","result":{"status":"UNKNOWN_OUTCOME","code":"OUTCOME_UNCERTAIN"}} | effect started: 0
   guard po-50 again          : {"status":"BLOCKED","stage":"redeem","result":{"status":"REFUSED","reason":"ALREADY_REDEEMED","ticketConsumed":false}} | effect started: 0
   redemptions in the journal : 1

Step 5 shows the budget: the failed attempt still holds its 2,000 EUR, so 2,000 (po-42) plus 2,000 (po-43) leaves no room for a third order of 2,000 out of 5,000, and po-44 is DENIED with C9_TOTAL_BUDGET_EXCEEDED. Step 6 uses a store whose first redemption reply is lost after the commit, to produce UNKNOWN_OUTCOME.

Evidence

All links point to commit 1df9d7a of authority-graph, the merge of pull request #39, which added these tests and the documentation.

What the tests do not show

  • That the external service executed the order. That is the premise of the scenario. The service in the script is simulated, and no test in the repository calls a real service.
  • The script itself is not part of the test suite. The step in which a retry through a new action leaves two orders at the service is shown by the script; the tests show only that the two keys differ.
  • The budget in step 5 uses different amounts from the test (5,000 against 3,000); it is the same mechanism, but the script’s numbers are not asserted by a test.
  • That asking for authorization again after an EFFECT_FAILED that was reported returns the same ticket: the test covers a redeemed ticket that was never reported. The script shows the reported case.

For these reasons this article carries no “Demonstrated” status. The facts about what Authority returns and records are pinned by tests; the claim about what a real service does is not something a test of Authority can show.

Mutation check

In a temporary copy of the repository at 1df9d7a, with 17 passing tests in tests/sdk/effectOutcomes.test.ts, four changes to src/sdk/authority.ts each make tests fail: the idempotency key given to the effect is no longer the ticket id (2 failed); an effect that throws is reported as EXECUTED instead of EFFECT_FAILED (2 failed); every refusal reports ticketConsumed: true (1 failed); an effect that returns is reported as EFFECT_FAILED instead of EXECUTED (1 failed). The repository itself was not changed.

Limits

  • The first report is final. If you learn later that the effect did happen, Authority offers no way to record it. Keep that knowledge in your own system.
  • Budget stays engaged. A ticket that was issued, redeemed or reported holds its share of the budget, whatever the result code. This is deliberate prudence; the cost is availability.
  • There may be no report at all. If the process stops between the redemption and the report, the journal holds a redemption and no ACTION_EXECUTED, and nothing in the results says that the effect may be pending.
  • No exactly-once guarantee. Authority bounds authorization: one successful redemption per ticket. It never performs the action and cannot know whether it happened. Only your target system can deduplicate or confirm an effect.
  • Identity comes from the host. Authority does not authenticate alice or the agent.
  • The clock is the host’s. Time is the instant you supply.
  • The journal is trusted. Events are asserted and unauthenticated, and completeness is not established. The in-memory backend used by the script is lost with the process.
  • No independent review. The engine is experimental, has not been independently reviewed or audited, is not published to npm, and is not for real payments or sensitive actions. No security guarantee is claimed.
  • This article describes what the code does today, including the parts that are imperfect. It is not a promise to change them.

Read next

Try it and tell us

Run the script, and tell us what was unclear and whether this matches a situation you have met. The way to do it today is to open an issue on the project’s GitHub repository: there is no form on this site and nothing is collected from this page.

Open questions

  • Should guard let the effect say “failed, confirmed” as opposed to “failed, unknown”? What would a host do with the difference?
  • Should a later report be able to add to a first one without replacing it?
  • Have you met a retry that duplicated an effect because the key changed between attempts?

Counterexamples that do not describe an unfixed exploitable flaw can be discussed in public on the repository. Anything exploitable should be reported privately: see the security page.