# `Continuum.Runtime.Journal.Postgres`
[🔗](https://github.com/Yyeger/Continuum/blob/main/lib/continuum/runtime/journal/postgres.ex#L1)

Durable journal adapter backed by Postgres via Ecto.

Implements the `Continuum.Runtime.Journal` behaviour. Every append
operation is transactional and CAS-guarded by the lease state on the
run row. Appends lock the run row, validate the lease token, assign a
sequence number, and insert the event in one transaction.

The replay loop and engine code are identical whether this adapter or
`InMemory` is in use — the only difference is durability and the
fencing-token enforcement on writes.

# `await_child_terminal!`

Resolve a child's terminal state into the parent's history.

Locks the parent (CAS by lease). If the child run is terminal, appends the
matching `child_completed`/`child_failed`/`child_cancelled` event to the
parent and returns the decoded outcome; otherwise returns `:pending`.

# `cancel_run!`

# `clear_next_wakeup!`

# `complete_activity_task!`

# `complete_compensation_task!`

# `consume_signal`

# `continue_as_new!`

Complete the current run as `{:continued, next_run_id}` and insert the fresh
continuation run, in one lease-CAS-guarded transaction.

The new run carries `continued_from_run_id`, the chain's `correlation_id`
(the chain root's id), and any `parent_run_id`/`parent_command_id` so a
continued child stays a child.

# `deliver_signal!`

# `fail_activity_task!`

# `fail_compensation_task!`

# `fire_timer!`

# `get_activity_result`

# `release_unknown_version!`

Release a run whose version is not loaded on this node.

Clears the lease and leaves the run `suspended` so another node that has
the version loaded can claim it — an unknown version is a per-node fact,
not a global one. Runs are no longer marked `stuck_unknown_version`;
`Continuum.VersionRegistry.upsert_instance/2` recovers legacy stuck rows.

# `resolve_chain_tip`

Resolve a run id to the live tip of its `continue_as_new` chain.

External callers hold the chain-root id; a run with no successor resolves
to itself. Used by signal delivery, cancel, and await so operations on a
continued run reach the current incarnation instead of the dead root.

# `resolve_signal_await`

# `retry_activity_task!`

# `schedule_activity!`

# `schedule_compensation!`

Schedule a compensation activity task.

Reuses the activity-task append path: the `compensation_scheduled` event and
the worker task are inserted under the run lease in one transaction. The task
carries `kind: :compensation` and `target_activity_id` so the worker journals
`compensation_completed`/`compensation_failed` on completion.

# `schedule_compensations!`

# `schedule_signal_await!`

# `schedule_timer!`

# `start_child!`

Start a child workflow run and journal `child_started` to the parent.

In one transaction (CAS-guarded by the parent's lease): insert the child run
row with `parent_run_id`/`parent_command_id`/`correlation_id` set and append
the `child_started` event to the parent's history. The child run is left
runnable for the dispatcher to claim.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
