---
slug: "TaskLifecycle"
name: "TaskLifecycle"
type: "Primitives"
layer: "Infrastructure"
ref: "TaskLifecycle#5591"
sema_id: "sema:TaskLifecycle#mh:SHA-256:559124d595219af971fe018e4709077bbe77f3ce7e1769a058cbeffd4a11c38b"
tags: ["Infrastructure","Primitives"]
updated: 2026-11-11
mindscape: "bootstrap"
index_url: https://mindscape.world/scapes/bootstrap.json
url: https://mindscape.world/bootstrap/TaskLifecycle/
related: ["StateTransition","Agent","Event","Exception","Heartbeat","Risk","Task","Result"]
---

# TaskLifecycle

Formal state machine governing task progression

Layer: Infrastructure · Category: Primitives

## Mechanism

Explicit [StateTransition](https://mindscape.world/scapes/bootstrap/StateTransition.md) machine governing [Task](https://mindscape.world/scapes/bootstrap/Task.md) progression through five states: PENDING (created, awaiting assignment), ASSIGNED (claimed by an [Agent](https://mindscape.world/scapes/bootstrap/Agent.md)), RUNNING (actively executing, emitting [Heartbeat](https://mindscape.world/scapes/bootstrap/Heartbeat.md)), COMPLETED (successfully finished, [Result](https://mindscape.world/scapes/bootstrap/Result.md) attached), FAILED (terminated with [Exception](https://mindscape.world/scapes/bootstrap/Exception.md), retry decision required). Each transition requires a typed [Event](https://mindscape.world/scapes/bootstrap/Event.md): assign, start, complete, fail, cancel. Invalid transitions are rejected. RUNNING state requires periodic [Heartbeat](https://mindscape.world/scapes/bootstrap/Heartbeat.md); timeout triggers automatic FAILED transition. The attached [Risk](https://mindscape.world/scapes/bootstrap/Risk.md) profile informs retry and escalation policy on failure.

## Invariants

- Forward-Only: Tasks must not regress (no COMPLETED to RUNNING via [StateTransition](https://mindscape.world/scapes/bootstrap/StateTransition.md))
- Single Owner: Exactly one [Agent](https://mindscape.world/scapes/bootstrap/Agent.md) owns a [Task](https://mindscape.world/scapes/bootstrap/Task.md) in ASSIGNED or RUNNING state
- FAILED tasks must include an [Exception](https://mindscape.world/scapes/bootstrap/Exception.md) describing the failure
- RUNNING tasks must emit [Heartbeat](https://mindscape.world/scapes/bootstrap/Heartbeat.md) within configured interval

## Preconditions

- [Task](https://mindscape.world/scapes/bootstrap/Task.md) exists in PENDING state

## Postconditions

- [Task](https://mindscape.world/scapes/bootstrap/Task.md) in terminal state (COMPLETED, FAILED, or CANCELLED)

## Failure modes

- Heartbeat timeout (agent dies silently — task stuck in RUNNING without timeout enforcement).
- State desync (two agents believe they own the same task due to network partition).
- Zombie tasks (FAILED tasks never retried or escalated — accumulate in queue).

## Parameters

- `heartbeat_interval_seconds` (Integer, [5, 300]): Maximum seconds between heartbeats before RUNNING task is marked FAILED

## Signature

- `StateTransition(Task)`

## Builds on

- [StateTransition](https://mindscape.world/scapes/bootstrap/StateTransition.md) (Infrastructure; Composes with)
- [Agent](https://mindscape.world/scapes/bootstrap/Agent.md) (Mind; References)
- [Event](https://mindscape.world/scapes/bootstrap/Event.md) (Infrastructure; References)
- [Exception](https://mindscape.world/scapes/bootstrap/Exception.md) (Infrastructure; References)
- [Heartbeat](https://mindscape.world/scapes/bootstrap/Heartbeat.md) (Infrastructure; References)
- [Risk](https://mindscape.world/scapes/bootstrap/Risk.md) (Infrastructure; References)
- [Task](https://mindscape.world/scapes/bootstrap/Task.md) (Infrastructure; References)
- [Result](https://mindscape.world/scapes/bootstrap/Result.md) (Infrastructure; Yields)

## Used by

—

## Identity

- Sema ID: `sema:TaskLifecycle#mh:SHA-256:559124d595219af971fe018e4709077bbe77f3ce7e1769a058cbeffd4a11c38b`
- Ref: `TaskLifecycle#5591`
- Supersedes:
  - `sema:TaskLifecycle#mh:SHA-256:ecd8d6da7668a91bd65d1b20beaf58e8e300f418cb40d00a3453535dfb4bedda`
  - `sema:TaskLifecycle#mh:SHA-256:3a3ece262c27914b8ff68afdf259cff4f046bf495558a190a43e32d6ee7dd5b8`
  - `sema:TaskLifecycle#mh:SHA-256:d935155779f500df5554666848f4360d5eba80b106a40b7a4580ce848f420d33`
  - `sema:TaskLifecycle#mh:SHA-256:6fdd40efd45e106daf0135bb05976d13856a62e681099cfe9b465bf13bd1260d`
  - `sema:TaskLifecycle#mh:SHA-256:efdc92e2f37217c2a4e04fc94850993dfb6dc3b68458abedd2be1d0c68897cd6`

## Links

- [Pattern page](https://mindscape.world/bootstrap/TaskLifecycle/)
- [View in the interactive graph](https://mindscape.world/bootstrap/#TaskLifecycle)
- [JSON](https://mindscape.world/scapes/bootstrap/TaskLifecycle.json)
- [Index of all patterns](https://mindscape.world/scapes/bootstrap.json)
