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

# Temporal

> Stand up, connect, verify, and operate the Temporal service that Formation requires for agent execution.

Formation uses [Temporal](https://temporal.io) as its durable execution engine.
Every new agent run executes as a Temporal workflow, and every schedule fires
from one, so work survives process restarts, deployments, provider outages, and
long human waits. PostgreSQL remains the storage and authorization authority: requests,
receipts, allowances, and task state live there, and Temporal drives execution.

Temporal is required. There is no per-agent engine selection, no instance engine
selector, and no fallback to another engine. Without an active connection and a
connected worker, Formation still accepts inputs and stores them durably, and the
dashboard and repair API stay available, but no new work executes until Temporal
is ready. Instance setup's **Temporal** step cannot be deferred for the same
reason.

Any Temporal service works: Temporal Cloud or a self-hosted cluster. A Temporal
Cloud account is not required. Formation uses the Temporal Go SDK v1.51.0.

## What Formation needs from the service

* A host-and-port gRPC endpoint reachable from every Formation replica.
* One namespace for the installation. Formation registers its workflows on the
  task queue `formation/<instance-id>/execution-v1`. It creates no namespaces.
* A service principal authorized for that namespace, authenticated with an API
  key or an mTLS client certificate.
* Service-side namespace authorization (see [Production connection](#production-connection)).

Temporal infrastructure credentials never grant an agent any external acting
identity. Agents keep their own separately owned accounts.

## Local development

The repository ships an unauthenticated development server. From the
repository root:

```sh theme={null}
docker compose -f compose.temporal-dev.yml up -d
```

It runs the Temporal CLI's development server from the pinned image
`temporalio/temporal:1.6.2`, keeps histories in a named volume, listens for gRPC on `127.0.0.1:7233`, serves
the Temporal UI on `http://127.0.0.1:8233`, and creates the `formation-dev`
namespace. Run Formation on the host with:

```sh theme={null}
export MESH_ENV=development
export MESH_TEMPORAL_ADDRESS=127.0.0.1:7233
export MESH_TEMPORAL_NAMESPACE=formation-dev
export MESH_TEMPORAL_DEVELOPMENT=true
```

`MESH_TEMPORAL_DEVELOPMENT=true` is accepted only for a loopback endpoint with no
credentials or TLS overrides, and only when `MESH_ENV` is `development` or
`test`. It cannot reach a remote service, and restoring a development database
into production does not let production workers reuse its development
connection. Never enable it in production.

## Production connection

Provision the Temporal service, namespace, and service principal outside
Formation. You can supply the connection through deployment variables, enter it
in **Settings → Temporal**, or send it through the operator API. A saved
selection in settings takes precedence over deployment variables.

| Variable | Value |
| - | - |
| `MESH_TEMPORAL_ADDRESS` | Service host and port, without a URL scheme or path. |
| `MESH_TEMPORAL_NAMESPACE` | Full namespace identifier supplied by the service. |
| `MESH_TEMPORAL_API_KEY` | Service principal's API key, when using API-key authentication. |
| `MESH_TEMPORAL_TLS_CERTIFICATE_PEM` | PEM client certificate chain, for mTLS. |
| `MESH_TEMPORAL_TLS_PRIVATE_KEY_PEM` | PEM client private key, for mTLS. |
| `MESH_TEMPORAL_TLS_CA_PEM` | Optional PEM certificate authority bundle. |
| `MESH_TEMPORAL_TLS_SERVER_NAME` | Optional TLS server name override. |
| `MESH_TEMPORAL_DISABLE_CONSOLE_LINKS` | Optional `true` to omit Temporal console links for this connection. Defaults to `false`. |

PEM variables contain the PEM text itself, with real newlines, not file paths or
literal `\n` sequences. Production transport always verifies the certificate
chain and server name with TLS 1.2 or newer; there is no skip-verification
option. Authentication requires either an API key or a complete mTLS
certificate and private key.

Saving credentials requires `MESH_AGENT_MASTER_KEY`. Connection credentials are
stored encrypted and are never returned by the API or written to logs.

Configure namespace authorization on the service before activation. A
self-hosted cluster needs a frontend `ClaimMapper` and `Authorizer`, or an
equivalent enforcement layer; trusting a client certificate authority alone does
not restrict which namespaces a client can use. See the
[Temporal authorization documentation](https://docs.temporal.io/self-hosted-guide/security#authorization).
Formation's activation check confirms access to the configured namespace. It
does not audit every service policy, so the operator remains responsible for
enforcing namespace permissions on all execution APIs.

### Console links

Formation links workflow, history, and activity events to the console for
recognized Temporal Cloud endpoints. It never guesses a web UI address for a
self-hosted service. `disable_console_links` hides those links for one saved
connection; workflow and activity IDs remain visible. The setting is pinned when
the connection is saved: changing `MESH_TEMPORAL_DISABLE_CONSOLE_LINKS` affects
only newly adopted deployment connections, and historical work keeps the
visibility of its own connection.

## Save, test, and activate

Saving, testing, and activating are separate steps, in **Settings → Temporal**
or through the API. The dashboard and instance setup use the same owner-only
endpoints, and an operator token works as well as a dashboard session.

When the deployment supplies the connection (`MESH_TEMPORAL_*`), the dashboard
shows a single line, **Using the connection supplied by this deployment**, with
**Connecting** until boot has saved, verified and activated it and its worker
reports in, then **Connected**. Nothing needs choosing, saving or testing, and
instance setup continues once it is connected. **Use your own Temporal** opens
the form below for a different service; new work keeps the supplied connection
until that replacement is tested and activated.

1. **Save.** Choose **Use the connection supplied by this deployment** or
   **Connect to my own Temporal service**, then **Save connection**. Saving
   creates a complete new connection; it does not activate anything.
2. **Test.** **Test saved connection** checks transport connectivity,
   authentication, and access to the configured namespace, each reported
   separately. Each check has a ten-second total deadline. Provider error bodies
   are never returned or logged.
3. **Activate.** **Activate connection** is available for ten minutes after a
   successful test. Activation atomically selects that connection for all new
   work. A failed test or activation leaves the previous active connection in
   place.
4. **Confirm the worker.** The page shows **Connected** once a worker reports a
   healthy connection for the active credentials. Until then, new work waits.

| Method | Path | Behavior |
| - | - | - |
| `GET` | `/api/settings/temporal` | Read the revision, connections, check results, outstanding work, and execution readiness. |
| `PUT` | `/api/settings/temporal` | Save a complete candidate and its source. |
| `POST` | `/api/settings/temporal/test` | Check the selected saved candidate. |
| `POST` | `/api/settings/temporal/activate` | Activate a recently verified candidate for new work. |
| `POST` | `/api/settings/temporal/{connectionID}/credentials` | Repair a retained connection's credentials. |
| `GET` | `/api/settings/temporal/metrics` | Read process-local SDK and execution metrics. |

Every write includes the current `revision`. Read it again after each successful
write. A stale revision returns `409 temporal_revision_conflict` and changes
nothing.

Use the deployment-supplied connection without re-entering credentials:

```json theme={null}
{"revision": 0, "source": "deployment"}
```

Or supply your own:

```json theme={null}
{
  "revision": 0,
  "source": "configured",
  "connection": {
    "address": "temporal.example.com:7233",
    "namespace": "formation.example",
    "api_key": "<api key>"
  }
}
```

For mTLS, send `certificate_pem` and `private_key_pem` instead of `api_key`.
Optional fields are `ca_pem`, `server_name`, `disable_console_links`, and
`development` (loopback development servers only).

Then test and activate, each with the revision returned by the previous call:

```json theme={null}
{"revision": 1}
```

The test response's selected connection carries a `check` object with
`connectivity`, `authentication`, `namespace_authorization`,
`activation_allowed`, and a `reason` when a check fails. Activation returns
`409 temporal_unverified` when the selected connection has no successful test in
the last ten minutes.

### Headless installs and deployment variables

When no connection has ever been selected, Formation selects the complete
deployment connection automatically at boot, tests and activates it, and retries
every minute after a transient outage. Instance setup then lists Temporal under
**Provided by this deployment**. It never activates an owner's explicitly saved candidate on its own.

A selected deployment connection is an immutable snapshot. Changing deployment
variables later does not replace it, so replicas with different values during a
rolling deploy cannot keep overwriting each other's credentials. To adopt new
deployment values, save the deployment source again, test it, and activate it.

## Verify

* **Settings → Temporal** shows **Connected** with the active endpoint and
  namespace.
* `GET /api/settings/temporal` reports `execution.temporal_ready: true` and the
  active connection's `worker_status: "connected"`.
* Send a test message to an agent and confirm the run completes in the
  dashboard.

For automation, the management capability `temporal.deployment.v1` advertises
`GET /api/management/temporal`. An owner session or allowlisted management token
can read this redacted status without contacting Temporal. It returns
`deployment_available`, `selected_source` (`deployment`, `configured`, or
null), `selected_active`, `worker_connected`, `disable_console_links`,
`default_backend` (always `temporal`), and `instance_temporal_ready`. A storage
failure returns `503` rather than a guessed state. `worker_connected` means the
selected connection is active and a worker recently reported a healthy
connection for its current credentials; it does not prove every replica is
upgraded or that any workflow completed.

## Outages and configuration repair

Each connection in the settings response reports:

| Field | Meaning |
| - | - |
| `worker_status` | `connected`: a worker's namespace probe for the current credentials succeeded in the last 20 seconds. `unavailable`: a recent probe failed (unreachable service, rejected credentials, or denied namespace). `not_connected`: no recent report, including after a clean worker shutdown. |
| `pending_work` | Nonterminal runs owned by this connection. |
| `pending_events` | Accepted execution events not yet acknowledged by Temporal. |

`connected` is not a claim that every poller is running, that every RPC is
authorized, or that accepted work finished. Zero pending events does not prove a
reply was delivered: failed runs are not pending work. Check the run's outcome,
delivery error, and reply receipt separately.

During a Temporal outage, accepted inputs and their dispatch records stay in
PostgreSQL and resume when the service returns; nobody needs to resend a
message. A PostgreSQL outage stops progress at durable boundaries without
dispatching anything twice. Before resuming an externally ambiguous action,
inspect its original operation and delivery receipts. To contain an incident,
use the instance or agent pause controls; never start a duplicate execution
elsewhere to make stuck work look recovered.

## Rotation and recovery

Credentials belong to a connection generation. Existing work stays on the
connection and credentials that admitted it, and workers keep serving every
retained connection that still has outstanding work. Changing the active
connection affects only new work; it never moves an existing workflow to another
endpoint or namespace.

**Rotate a key or certificate in place.** Save and test a candidate with exactly
the same endpoint, namespace, and development mode as the retained connection,
then post the current revision to that connection's `credentials` endpoint:

```json theme={null}
{"revision": 4}
```

The connection keeps its ID and its workflows, receives a new credential
revision, and workers reconnect. A candidate for a different destination cannot
repair it. In the dashboard, a tested candidate shows **Repair credentials** for
each matching retained connection. Repair does not change the active connection.

**Move new work to another service or namespace.** Save, test, and activate the
new connection. Existing work finishes on the old one, so keep its service and
credentials available until its `pending_work` reaches zero.

### Backup set

Back up and restore these together as one recovery set:

* PostgreSQL;
* the Temporal service's state, using its operator's supported procedures;
* `MESH_AGENT_MASTER_KEY`, through a separate secure channel;
* referenced workspace and artifact storage.

Restore the original instance identity, connection generations, namespaces, and
workflow IDs together. Restoring only one store can leave a workflow pointing at
missing data, or an accepted event with no workflow history. Reconcile receipts
and unresolved external effects before resuming; a restore must not blindly
repeat actions whose outcome is unknown, and a missing reference is reported or
replanned rather than replaced by an invented result. See
[Secrets and recovery](https://docs.formation.texturehq.com/secrets-and-recovery.md) for the master key.

## Installs that predate the requirement

Installations that ran agents before Temporal became required keep their
earlier work on its recorded engine. Runs admitted under the
PostgreSQL executor drain through compatible workers; they are not replayed or
migrated to Temporal. New work always goes to Temporal.

The former engine-selection endpoints, `PUT /api/settings/temporal/execution`
and `POST /api/settings/temporal/promotion`, return
`410 temporal_execution_fixed`. They cannot restore a PostgreSQL default or
assign an agent to another engine.

Upgrade every Formation replica together. Stop admission, drain or stop the old
execution processes, apply migrations, and start only upgraded workers before
admitting new work; a rolling mixture with pre-requirement executors is
unsupported.

## Related

* [Installation](https://docs.formation.texturehq.com/operations/installation.md)
* [Operator API](https://docs.formation.texturehq.com/operator-api.md#temporal-execution-settings)
* [Temporal maintainer reference (repository)](https://github.com/TextureHQ/formation/blob/main/docs/contributing/temporal.md)


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