Errors and Debugging¶
The most common type of errors at runtime stems from worker tasks. A first measure to preventing this is using the correct types, but still something might go wrong. In this example we will produce an error and investigate it with the debugging tools in tierkreis.
Worker Errors¶
Worker errors can occur in multiple ways. For python workers an error occurs when an uncaught exception raises. For other workers (including python) a non-zero exit code will also produce an error.
Defining a graph that will always run an error:
from error_worker import fail
from tierkreis.builder import Graph
from tierkreis.data.core import EmptyModel
from tierkreis.data.models import TKR
from tierkreis.data.types import Workflow
def error_graph() -> Workflow:
g = Graph(EmptyModel, TKR[str])
output = g.task(fail(), has_breakpoint=True)
return g.finish_with_outputs(output)
Breakpoints¶
Setting has_breakpoint=True pauses the run immediately before the task executes. wait_for returns when the run pauses, and get_summary reports the paused node location. We can inspect its state before deciding whether to resume it:
from tierkreis.runtime import new_default
runtime = await new_default()
with runtime:
workflow_id = await runtime.save_workflow("error handling", error_graph())
run_id = await runtime.start_new_run(workflow_id, {})
await runtime.wait_for(run_id)
summary = await runtime.get_summary(run_id)
print(summary.paused_locations)
states = await runtime.debug_read_node_states(run_id, 0, summary.paused_locations)
print(states)
['N0']
{'N0': NodeState(name=None, status="Paused", execution_context=None)}
Resuming execution¶
Calling unpause_nodes without a location resumes every paused node. You can instead pass a list from summary.paused_locations to resume selected nodes. After resuming, call wait_for again to wait for the next breakpoint or completion. Here the task deliberately fails, so wait_for raises a ValueError containing the worker diagnostic ("I refuse!"):
with runtime:
print(await runtime.unpause_nodes(run_id))
try:
await runtime.wait_for(run_id)
except ValueError as error:
print(error)
['N0']
Workflow failed
Debugging failures and restarting¶
The run remains inspectable after failure. get_summary identifies failed locations, and debug_read_node_states exposes their runtime state and execution context. Enable runtime debug logs with RuntimeConfig.set_log_level("debug") or tkr run -v.
summary = await runtime.get_summary(run_id)
print(summary.errored_locations)
states = await runtime.debug_read_node_states(run_id, 0, summary.errored_locations)
print(states)
['N0']
{'N0': NodeState(name=None, status="Error", execution_context=None)}
Restarting all failed nodes by omitting the location list creates a new attempt and preserves attempt zero. Breakpoint state is reset for invalidated nodes, so the restarted task pauses again before execution. After inspecting the new attempt, resume it with the same unpause_nodes API. This worker always fails, so the resumed attempt will also report an error.
with runtime:
new_attempt, invalidated = await runtime.restart_task(run_id)
await runtime.wait_for(run_id, new_attempt)
restarted_summary = await runtime.get_summary(run_id, new_attempt)
print(restarted_summary.paused_locations)
print(await runtime.unpause_nodes(run_id, attempt=new_attempt))
try:
await runtime.wait_for(run_id, new_attempt)
except ValueError:
pass
print(new_attempt, invalidated)
['N0']
['N0']
1 ['N0', 'N1']