{
  "handle": "TaskLifecycle",
  "mechanism": "Explicit {{state_transition}} machine governing {{task}} progression through five states: PENDING (created, awaiting assignment), ASSIGNED (claimed by an {{agent}}), RUNNING (actively executing, emitting {{heartbeat}}), COMPLETED (successfully finished, {{result}} attached), FAILED (terminated with {{exception}}, retry decision required). Each transition requires a typed {{event}}: assign, start, complete, fail, cancel. Invalid transitions are rejected. RUNNING state requires periodic {{heartbeat}}; timeout triggers automatic FAILED transition. The attached {{risk}} profile informs retry and escalation policy on failure.",
  "gloss": "Formal state machine governing task progression",
  "invariants": [
    "Forward-Only: Tasks must not regress (no COMPLETED to RUNNING via {{state_transition}})",
    "Single Owner: Exactly one {{agent}} owns a {{task}} in ASSIGNED or RUNNING state",
    "FAILED tasks must include an {{exception}} describing the failure",
    "RUNNING tasks must emit {{heartbeat}} within configured interval"
  ],
  "preconditions": [
    "{{task}} exists in PENDING state"
  ],
  "postconditions": [
    "{{task}} 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": [
    {
      "name": "heartbeat_interval_seconds",
      "type": "Integer",
      "range": "[5, 300]",
      "description": "Maximum seconds between heartbeats before RUNNING task is marked FAILED"
    }
  ],
  "signature": [
    "StateTransition(Task)"
  ],
  "_meta": {
    "ring": 1,
    "tier": 1,
    "related": [],
    "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"
    ],
    "path": [
      "Infrastructure",
      "Primitives"
    ]
  },
  "sema_ref": "TaskLifecycle#5591",
  "sema_id": "sema:TaskLifecycle#mh:SHA-256:559124d595219af971fe018e4709077bbe77f3ce7e1769a058cbeffd4a11c38b",
  "sema_stub": "5591",
  "dependencies": {
    "composes_with": {
      "state_transition": "sema:StateTransition#mh:SHA-256:bdc0c1988a26e15a4e90bb79b214e4bebe630bc53f758ca67c6e1148aa802686"
    },
    "references": {
      "agent": "sema:Agent#mh:SHA-256:e127459069739fffc96a71d54ef6e8c97ca53471d5349c16aa72a092a33756cd",
      "event": "sema:Event#mh:SHA-256:36757bd8344e1fd7161bd2f23d6588180fbaaf9cff5ef8be8a205effbf4438b6",
      "exception": "sema:Exception#mh:SHA-256:ae9485039008abed9587e74c05a8c31c37d9a8f70347a11c0630fe87673fb7bb",
      "heartbeat": "sema:Heartbeat#mh:SHA-256:c5dfefe91d5460716f19e001290b47c3853173b17f0b6914793f6f51a41903ef",
      "risk": "sema:Risk#mh:SHA-256:e7f601ff0058d606ea87ab5f196f78f469a3133f8324617ff8a25d8072422e91",
      "task": "sema:Task#mh:SHA-256:a85010f508f85055170c396c8fa390125c1206888c565ac10651f3969a339f8d"
    },
    "yields": {
      "result": "sema:Result#mh:SHA-256:c02a8d6817c2f0e14d5a9360824240f135905e8be25fd659feb76d1f44e274c6"
    }
  },
  "sema_layer": "Infrastructure",
  "sema_category": "Primitives",
  "used_by": {}
}
