Skip to main content
Work outside the transaction, such as an HTTP call, a person’s approval or a second transaction, is a target: a contract for work. A mutation commits intent toward a target with ctx.submit, atomically with its writes. The committed intent is a task. The task runs after the commit, and the task settles with a Result. A continuation named by then receives that result in a later transaction. This example sends a contact to a CRM and records the CRM’s key.

Declare a target

bijection/crm.ts
http(url, { bearer }) sends each task as one JSON POST of its args to the URL, with Authorization: Bearer <secret> when configured. Redirects fail. For another method, path or headers, use a receiver from @bijectionhq/bijection as shown in Integrations.

Submit from a mutation

bijection/contacts.ts
The fact and the task commit together: if the mutation refuses, no task exists. ctx.submit(target, args, { once, then, due, within }) returns the Task. A once built from the call’s own once, its arguments, or ids your handler minted is stable across retries and successor restores. A store counter or another read that a restore can rewind can produce a different once. A continuation reads the task whose result it receives from ctx.frame.on.task after narrowing ctx.frame.on.kind to "then". It is an ordinary mutation and needs no allow.

Read a task

A task is a point in sys.tasks. Its address is sys.tasks/<id>, where the kernel mints the opaque id. Store the handle in a t.task(target) field. ctx.get(task) returns its state or null when the task is absent.
sys.tasks holds every task’s facts, so a query can select them: ctx.list(sys.tasks.where({ target: createContact, state: "pending" }).first(50)). To find a task by its original once, use a selection such as bijection list sys.tasks --where target=payments.charge --where once=charge-1 --first 1.

Run a mutation later

A mutation is a target too. Submit it to run it in its own transaction after this one commits, and add due to run it later:
For work that recurs, declare a reaction on every(duration) or cron(expression, zone) instead.

Submit work at a higher label

A public request can queue a protected review. The submission records the request at public and returns its task handle. The review later reads and writes at review, in its own transaction. Set the submit’s under to the label the mutation declares.
bijection/reviews.ts
Give the submitter a live requester grant at public. The app’s site can invoke the internal checkCase. The deferred claim re-forms the submitter’s frame and is offered only the grants recorded when the request was admitted at public that are still live. A target mutation with allow can narrow those offers. Reading the outcome through checkOutcome requires a live reviewer grant at review. Role grants For a task from this submission, ctx.get(task) at public answers { state: "withheld" } before and after settlement. The result, including any refusal, sits at review. A then handler also runs there and can declare result: t.result(checkCase) to receive it. Use a single higher entry when the protected change and a lower publication must commit together. Atomic decisions and lower publication

Running a task with a mutation

via: mutation runs a mutation for the target. The host runs it in its own transaction with the task’s args, and its value or refusal settles the task. A mutation that starts work it cannot finish in one transaction returns its own task from ctx.frame.on.task, which leaves the task open. A function placed in the subtree that holds the target answers it later with ctx.answer, within the target’s within.
bijection/jobs.ts

Answers from people and agents

via: [roles] waits for a principal holding one of the roles to answer the task. Such a target declares within, since nobody may ever answer.
bijection/approvals.ts
ctx.answer(task, result) settles a pending task with a result, and ctx.withdraw(task, { message }) settles it as Withdrawn. Both are grave acts.

What a task’s result can be

A refused result is the same flat refusal a call answers (refusals): its host code with its public reason and retryAfter, or one of the target’s declared codes with its data. Unknown means something else on a call. A caller that lost the reply to its own call (client.mutate, the CLI, HTTP) calls again with the same once, and the host answers the original commit’s result.

When a task settles Unknown

The reply may have been lost. On a successor restore, an unfinished send with a custody dispatch settles Unknown with reason InstallationRestored. The archive may show it as waiting for dispatch if the dispatch happened after the cut. A send with no custody entry stays pending. Bijection orders one dispatch per receiver key across the installation’s lineage. Custody acknowledges that dispatch before any byte can leave. Every HTTP send carries that key and Bijection-Fencing-Token. Set receiver({ once: { header } }) for a header other than the default Idempotency-Key. Use receiver({ once: { field } }) to place the key in a top-level field of an inline JSON body. Leave that field out of the operation’s args and request body so the host can fill it before signing. GET requests to a body-keyed receiver carry the key in Idempotency-Key. An ordinary Bijection HTTP reaction uses this header as its once. Set receiver({ delivery: { timeout } }) to bound the wait for an answer. If the send times out, it settles Unknown. The task deadline remains within. The same effect keeps its receiver key across retries, deploys and successor incarnations. A fenced receiver, including the managed provider, refuses a kept key presented with a different request digest. A task’s Unknown result is final. To reconcile it, declare how the receiver answers for the send’s idempotency key with operation({ status }) and submit reconciled(target) from @bijectionhq/library-recovery. The library’s task can return the receiver’s conclusive answer about that key. See Reconcile external results. The kernel decides a send, run, landing, inbox call or clock tick again at claim, offered only the submitter’s grants recorded at submit that are still live. A send that loses an admitting grant settles Disallowed and records why. Submit admits then as an obligation at the join of the submitter’s commit label and the target label. The obligation receives the task’s final result using its recorded authority. Acts inside the continuation decide against live grants when they run. A refused act leaves the obligation stuck.

Reply custody

Every external task reply is sealed under its own erasure unit and the request’s units. The delivering continuation can close the reply’s unit with ctx.erase(task). A target or receiver operation can set reply: { erasable: true, lifetime: { minutes: 30 } }. The lifetime uses the same fixed durations as table lifetime and starts when the task settles. External replies have their own unit even when reply is omitted or erasable is false. After the reply closes, task status stays settled and its result reads as null in every version.

Tasks in a branch

A task submitted in a branch stays there: external sends occur only at the head. Landing the branch submits it at the head. To send a request to a real receiver, use the head of a separate development deployment.

Test it

The test kernel simulates receiver replies and the clock: it answers tasks and advances time.
bijection/contacts.test.ts
See Testing for the test kernel.