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

# Threads and steps

> Model one execution without forcing the entire business process into one contract.

A thread records one execution, optionally governed by a contract version.
It can cross services. Keep its scope focused, such as refund approval;
references and entity profiles connect it to other runs.

* **Steps** record individual operations and their outcomes.
* **Sub-steps** capture details within an operation.
* **References** associate work with orders, customers, agents, or partners.
* **Tags** categorize the thread at creation.
* **Contracts** define the rules for its execution.

## Create and complete

[Connect an SDK](/core-concepts/connecting), then:

```javascript theme={null}
const thread = await connection.start('Order ORD-123');
await thread.addRefs({ order_id: 'ORD-123', customer_id: 'CUST-001' });
await thread.step('order_received').addContext({ quantity: 2 }).success();
await thread.complete('Recorded');
```

Free-form threads require explicit completion or cancellation. Contracted threads
complete when their terminal step successfully validates. A successful report
acknowledgement alone is not a completed validation result.

## Correlate traces

OTLP ingestion can use `threadify.external_ref` or `workflow.run_id` to combine
traces from the same run into one thread. Ordinary business refs do not merge
threads. See [OpenTelemetry](/opentelemetry) for precedence and opting out.

## Shared rules

Contracts validate submitted content and execution history. Use an explicit
[execution wait](/core-concepts/execution-waits) before an operation to enforce
flow permission. Even with a grant, your application owns execution, recovery,
and idempotency of external side effects.
