> For the complete documentation index, see [llms.txt](https://docs.talus.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.talus.network/talus-docs-v2.1.0/reference/move/nexus_workflow/execution_settlement.md).

# execution\_settlement

* [Enum `ExecutionOutcome`](#enum-executionoutcome)
* [Constants](#constants)
* [Function `settle_task_execution`](#function-settle_task_execution)
* [Function `outcome_is_succeeded`](#function-outcome_is_succeeded)
* [Function `abort_expired_execution`](#function-abort_expired_execution)
* [Function `settle_committed_tool_result_for_walk_by_leader`](#function-settle_committed_tool_result_for_walk_by_leader)
* [Function `record_committed_tool_result_gas_charge_by_leader`](#function-record_committed_tool_result_gas_charge_by_leader)
* [Function `refill_tap_execution_payment`](#function-refill_tap_execution_payment)
* [Function `refill_tap_execution_payment_from_agent_vault`](#function-refill_tap_execution_payment_from_agent_vault)
* [Function `settle_committed_tool_result_for_walk`](#function-settle_committed_tool_result_for_walk)
* [Function `cleanup_broken_onchain_tool_result`](#function-cleanup_broken_onchain_tool_result)
* [Function `settle_onchain_tool_result_for_walk`](#function-settle_onchain_tool_result_for_walk)
* [Function `emit_payment_ready_walk_requests`](#function-emit_payment_ready_walk_requests)

### Enum `ExecutionOutcome`

Terminal result returned to the owning Task.

```move
public enum ExecutionOutcome has copy, drop
```

<details>

<summary>Variants</summary>

Variant `Succeeded`Variant `Failed`

</details>

#### Constants

```move
#[error]
const EExecutionMismatch: vector<u8> = b"Execution payment does not match scheduled reserve or execution";
```

```move
#[error]
const ECommittedSettlementHasOnchainToolResult: vector<u8> = b"Committed-result settlement cannot ignore an unconsumed on-chain tool result";
```

```move
#[error]
const EOnchainToolResultCleanupNotAllowed: vector<u8> = b"On-chain tool result cleanup is only allowed for insufficient stamps";
```

```move
#[error]
const EFailedOnchainToolResultMissingPrimary: vector<u8> = b"Failed on-chain tool settlement requires a provisional primary result";
```

```move
#[error]
const EFailedOnchainToolResultAlreadyRecorded: vector<u8> = b"Failed on-chain tool recording cannot merge a secondary result";
```

```move
const REFUND_REASON_EXECUTION_ABORTED: vector<u8> = vector[69, 120, 101, 99, 117, 116, 105, 111, 110, 32, 97, 98, 111, 114, 116, 101, 100];
```

```move
const REFUND_REASON_EXECUTION_FAILED: vector<u8> = vector[69, 120, 101, 99, 117, 116, 105, 111, 110, 32, 102, 97, 105, 108, 101, 100];
```

#### Function `settle_task_execution`

Settles a finished scheduled execution's payment from its reserve, refunding on abortion or failure and accomplishing on success, and returns whether a refund was issued. Aborts if the reserve's scheduled task id does not match the execution's ([`EExecutionMismatch`](#nexus_workflow_execution_settlement_EExecutionMismatch)).

```move
public fun settle_task_execution<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, reserve: &mut nexus_interface::payment::TaskPaymentReserve, execution: &mut nexus_workflow::execution::DAGExecution): std::option::Option<nexus_workflow::execution_settlement::ExecutionOutcome>
```

#### Function `outcome_is_succeeded`

Returns whether an outcome is successful.

```move
public fun outcome_is_succeeded(outcome: nexus_workflow::execution_settlement::ExecutionOutcome): bool
```

#### Function `abort_expired_execution`

Aborts an execution that has an expired active walk, applying the abort effects.

```move
public fun abort_expired_execution<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, dag: &nexus_interface::dag::DAG, execution: &mut nexus_workflow::execution::DAGExecution, clock: &sui::clock::Clock, ctx: &mut sui::tx_context::TxContext)
```

#### Function `settle_committed_tool_result_for_walk_by_leader`

Settles a leader result while keeping the shared priority-fee vault immutable.

```move
public fun settle_committed_tool_result_for_walk_by_leader<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, dag: &nexus_interface::dag::DAG, execution: &mut nexus_workflow::execution::DAGExecution, tool_registry: &nexus_tool::tool_registry::ToolRegistry, leader_registry: &nexus_registry::leader::LeaderRegistry, priority_fee_vault: &nexus_registry::priority_fee_vault::PriorityFeeVault, leader_cap: &nexus_primitives::owner_cap::CloneableOwnerCap<nexus_registry::leader_cap::OverNetwork>, walk_index: u64, expected_vertex: nexus_interface::graph::RuntimeVertex, failed_onchain_tool_reason: std::option::Option<vector<u8>>, commit_tx_digest: vector<u8>, commit_gas_charge: u64, settlement_gas_charge: u64, clock: &sui::clock::Clock, ctx: &mut sui::tx_context::TxContext)
```

#### Function `record_committed_tool_result_gas_charge_by_leader`

Records primary leader committed-result gas, creating provisional failed on-chain tool evidence when supplied.

```move
public fun record_committed_tool_result_gas_charge_by_leader<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, dag: &nexus_interface::dag::DAG, execution: &mut nexus_workflow::execution::DAGExecution, leader_registry: &nexus_registry::leader::LeaderRegistry, leader_cap: &nexus_primitives::owner_cap::CloneableOwnerCap<nexus_registry::leader_cap::OverNetwork>, walk_index: u64, expected_vertex: nexus_interface::graph::RuntimeVertex, failed_onchain_tool_reason: std::option::Option<vector<u8>>, commit_tx_digest: vector<u8>, commit_gas_charge: u64, settlement_gas_charge: u64, clock: &sui::clock::Clock, ctx: &mut sui::tx_context::TxContext)
```

#### Function `refill_tap_execution_payment`

Tops up the execution's TAP payment from the supplied coin and emits a refill event.

```move
public fun refill_tap_execution_payment<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, execution: &mut nexus_workflow::execution::DAGExecution, coin: sui::coin::Coin<sui::sui::SUI>, ctx: &mut sui::tx_context::TxContext)
```

#### Function `refill_tap_execution_payment_from_agent_vault`

Tops up the execution's TAP payment by the given amount from the agent's vault and emits a refill event.

```move
public fun refill_tap_execution_payment_from_agent_vault<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, agent: &mut nexus_interface::agent::Agent, execution: &mut nexus_workflow::execution::DAGExecution, amount: u64)
```

#### Function `settle_committed_tool_result_for_walk`

Permissionlessly settles a result while keeping the shared priority-fee vault immutable.

```move
public fun settle_committed_tool_result_for_walk<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, dag: &nexus_interface::dag::DAG, execution: &mut nexus_workflow::execution::DAGExecution, tool_registry: &nexus_tool::tool_registry::ToolRegistry, leader_registry: &nexus_registry::leader::LeaderRegistry, priority_fee_vault: &nexus_registry::priority_fee_vault::PriorityFeeVault, walk_index: u64, clock: &sui::clock::Clock, ctx: &mut sui::tx_context::TxContext)
```

#### Function `cleanup_broken_onchain_tool_result`

```move
public fun cleanup_broken_onchain_tool_result<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, dag: &nexus_interface::dag::DAG, execution: &mut nexus_workflow::execution::DAGExecution, tool_registry: &nexus_tool::tool_registry::ToolRegistry, result: nexus_interface::onchain_tool_result::OnchainToolResult, leader_registry: &nexus_registry::leader::LeaderRegistry, walk_index: u64, tool_witness_id: sui::object::ID, clock: &sui::clock::Clock)
```

#### Function `settle_onchain_tool_result_for_walk`

Consumes an on-chain tool result for a walk and then settles the resulting committed tool result.

```move
public fun settle_onchain_tool_result_for_walk<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, dag: &nexus_interface::dag::DAG, execution: &mut nexus_workflow::execution::DAGExecution, tool_registry: &nexus_tool::tool_registry::ToolRegistry, result: nexus_interface::onchain_tool_result::OnchainToolResult, leader_registry: &nexus_registry::leader::LeaderRegistry, priority_fee_vault: &nexus_registry::priority_fee_vault::PriorityFeeVault, walk_index: u64, expected_vertex: nexus_interface::graph::RuntimeVertex, tool_witness_id: sui::object::ID, clock: &sui::clock::Clock, ctx: &mut sui::tx_context::TxContext)
```

#### Function `emit_payment_ready_walk_requests`

Settles the finished invoker payment if ready, then emits execution requests for all payment-ready active walks.

```move
public fun emit_payment_ready_walk_requests<R>(_permit: &nexus_kernel::runtime_authority::RuntimePermit<R>, dag: &nexus_interface::dag::DAG, execution: &mut nexus_workflow::execution::DAGExecution, leader_registry: &nexus_registry::leader::LeaderRegistry, clock: &sui::clock::Clock, ctx: &mut sui::tx_context::TxContext)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.talus.network/talus-docs-v2.1.0/reference/move/nexus_workflow/execution_settlement.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
