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

# Reconcile external results

> Recover a command whose reply was lost, and keep facts converging on their goal.

`Unknown` means two things, depending on where you meet it:

| Where | What it means | What to do |
| - | - | - |
| A call you made (`client.mutate`, the CLI, HTTP) | You lost the reply and the call may have committed | Inspect or resume the [retained submission](https://docs.bijection.com/clients/requests.md#retain-a-submission-before-sending). For ordinary mutations, use the same `once` and original request while recovery remains available. |
| A task's result (`then` receives `{ ok: false, code: "Unknown" }`) | The performer never heard the receiver; the command may have happened | Nothing will change it: the host never resends the task, and a submit with the same `once` returns the same settled task. Reconcile with the receiver, or record the uncertainty. |

Bijection sends each task at most once and records one result. `Unknown` is
final. To learn what happened, `@bijectionhq/library-recovery` submits a
separate read-only operation declared as the command's status.

## Declare the receiver's status

The receiver stores the receipt under the idempotency key egress derives
from the send's `once`. Its read-only status operation answers for that
same key. Declare a cutoff when the receiver refuses commands that arrive
after it.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
release: operation({
  method: "POST",
  args: { key: t.string, version: t.string, notAfter: t.instant },
  returns: t.json,
  status: {
    via: "releaseStatus",                    // a readOnly operation taking { key }
    revision: "erp-release-receipts-v1",
    until: ({ notAfter }) => notAfter,       // the receiver refuses the command after it
    conclude: (answer, key, args) => {
      const receipt = answer as { receiverKey?: unknown; outcome?: unknown; order?: unknown; version?: unknown };
      return receipt.outcome === "confirmed" && receipt.receiverKey === key &&
        receipt.order === args.key && receipt.version === args.version
        ? { ok: true, value: receipt }
        : null;
    },
  },
}),
```

Set the receiver's clock skew with `delivery: { skew }`. The default is 60 seconds.

## Submit the reconciled command

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { reconciled } from "@bijectionhq/library-recovery";

export const release = reconciled(erp.release);

// in a mutation
await ctx.submit(release, { key, version, notAfter: ctx.frame.now.entry.add({ hours: 1 }) }, {
  once: id,
  then: released.with({ id }),
});
```

`reconciled(target)` is a target with the same args, value and codes. Its
result follows the command. An `Unknown` or successful reply rejected by
`confirmReply(value, key, args)` starts status reads for the exact attempt.

* the original receipt (`conclude` answers a result) becomes the result;
* A miss stays inconclusive by default. To conclude `Failed` from a
  miss, declare `authoritativeAbsence(answer, key, args)`. The response
  must cover the original receiver and attempt in the journal that
  records the effect. The journal must give authoritative reads, retain
  evidence for the declared `once.retains`, and commit evidence with the
  effect or provide an equivalent guarantee. Reads also have to follow the
  cutoff plus skew, with the answer still inside retention.
* otherwise it reads again (`probes`, default 3, `every`, default one
  minute). Only when every read stayed inconclusive is the result
  `Unknown`, and that is final too.

`within` (default 7 days) bounds the command, the wait past its cutoff and
every read. It lowers to `submit` with `once`, `due` and `then`.

The status revision travels with outstanding work. Change it when the
receiver account, journal, or interpretation of evidence changes.
An outstanding command whose revision differs stays uncertain and needs
application review.

Use `reconciled(target, { answeredBy: route, resolutionUnder: label, onResolved })`
when the receiver can call a verified route. Its handler passes the task,
original receiver key, and result to `reconciliation(target).answer`.
After `Unknown` settles, a conclusive answer records one result at
`reconciliation(target).resolutions(task)` and triggers `onResolved`.
The task's original Fate stays final.

For ordered delivery, call `ordered` from the predecessor's `then`.
After `Unknown`, it schedules the next send at the predecessor's commit
plus the receiver's `delivery.requestExpiry` and `delivery.skew`.

The [purchase orders example](https://github.com/bijectionhq/bijection/tree/main/examples/purchase-orders)
holds a budget reservation while a release is uncertain and frees or
consumes it from the reconciled result.

## Converge a goal fact

`reconciler({ table, label, due, correct })` from `@bijectionhq/library-work`
drives a goal fact toward its desired state. Each current turn runs one
bounded page of corrections, keeps the next cursor in the fact's
`cursor` field (`t.maybe(t.string)`) and re-arms. `correct(ctx, fact, page)`
answers the next cursor, or `null` at the end of the pass. Submit each
correction with `once: page.once(instance)`, which is
`["reconcile", goal, instance, generation]`, so a replayed turn never
submits a correction twice. A reconciler is a [controller](https://docs.bijection.com/operations/durable-waits.md#controllers).


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