# MCP task lifecycle

> Find an MCP task's next state, so a client that polls, updates or cancels it always sees the state the protocol would write.

Inspired by UOR-Foundation/MCP (https://github.com/UOR-Foundation/MCP). The Model Context Protocol 2026-07-28 server core in LexLean, with its tasks-extension state machine. Pattern: State machine, OMG UML 2.5.1 behavioral state machine. To write one of your own, follow How to build a state machine app (../../guides/state-machine/index.md). The prompt below is data, quoted from the example.

**Figure: The MCP task lifecycle state machine.** Each box is a state and each arrow a step a rule can take. A run starts at working and stops at completed or failed or cancelled. Dashed arrows go back to an earlier state.

| From | Link | To |
| --- | --- | --- |
| working | REQ-007 | input-required |
| working | otherwise | working |
| working | 2 rules | completed |
| working | 2 rules | failed |
| working | REQ-006 | cancelled |
| input-required | 2 rules | input-required |
| input-required | REQ-013 | working |
| input-required | REQ-011 | completed |
| input-required | REQ-012 | failed |
| input-required | REQ-006 | cancelled |
| completed | REQ-001 | completed |
| failed | REQ-002 | failed |
| cancelled | REQ-003 | cancelled |

Verified by prismpm verify in the pinned SDK. Fingerprint: 00ce88fdafb529dc1c82235c10eed269fdf603522d110588aae65f582aa14606. Acceptance vectors: 65. Claims: 12.

## The prompt

```json
{
  "schema": "prism/prompt/1",
  "pattern": "stateMachine",
  "machine": {
    "state": "state",
    "initial": "working",
    "final": [
      "completed",
      "failed",
      "cancelled"
    ]
  },
  "goal": "Find an MCP task's next state, so a client that polls, updates or cancels it always sees the state the protocol would write.",
  "repository": "UOR-Foundation/MCP",
  "app": {
    "name": "mcp-task-lifecycle",
    "title": "MCP task lifecycle",
    "purpose": "Give the next state of an io.modelcontextprotocol/tasks task from its current state, the step applied to it (settle, answer or cancel), what its plan still asks, the clock and how many input keys remain unanswered.",
    "limits": [
      "It does not create a task: a task starts working, as the seed of its tool's plan, when tools/call decides to answer a task.",
      "It does not expire a task: a task past its ttlMs is dropped from the host's table by the next request, outside this step.",
      "It does not check the host's clock or table; the host owes the core exactly the table it was given."
    ],
    "fields": [
      {
        "name": "state",
        "kind": "choice",
        "values": [
          "working",
          "input-required",
          "completed",
          "failed",
          "cancelled"
        ],
        "means": "the task's current status, as DetailedTask in src/Tasks.lex.tex"
      },
      {
        "name": "event",
        "kind": "choice",
        "values": [
          "settle",
          "answer",
          "cancel"
        ],
        "means": "the step: settle (tasks/get), answer (tasks/update with every given key) or cancel (tasks/cancel)"
      },
      {
        "name": "asks",
        "kind": "choice",
        "values": [
          "yes",
          "no"
        ],
        "means": "whether the task's plan still holds input requests to park on (parkedPlan empties them once it parks)"
      },
      {
        "name": "elapsed",
        "kind": "number",
        "min": 0,
        "means": "milliseconds since the task was created, now_ms less createdMs"
      },
      {
        "name": "deadline",
        "kind": "number",
        "min": 0,
        "means": "milliseconds after creation the plan's next step is due: parkAfterMs when it asks, finishAfterMs otherwise"
      },
      {
        "name": "outcome",
        "kind": "choice",
        "values": [
          "completes",
          "fails"
        ],
        "means": "how the plan concludes: PlanOutcome.completes with a result or PlanOutcome.fails with a JSON-RPC error"
      },
      {
        "name": "remaining",
        "kind": "number",
        "min": 0,
        "means": "input keys still unanswered after this answer"
      }
    ],
    "outcomes": [
      "working",
      "input-required",
      "completed",
      "failed",
      "cancelled"
    ],
    "meanings": {
      "working": "the task is running; tasks/get answers status working",
      "input-required": "the task waits for the client to answer its inputRequests through tasks/update",
      "completed": "terminal: the plan's result is the task's result",
      "failed": "terminal: the task carries the plan's JSON-RPC error",
      "cancelled": "terminal: the client cancelled the task before it finished"
    },
    "rules": [
      {
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "completed"
          }
        ],
        "then": "completed",
        "why": "src/Tasks.lex.tex: settle, answer and cancel keep a completed entry (kept entry)"
      },
      {
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "failed"
          }
        ],
        "then": "failed",
        "why": "src/Tasks.lex.tex: a failed task is terminal (isTerminal), and every step keeps it"
      },
      {
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "cancelled"
          }
        ],
        "then": "cancelled",
        "why": "src/Tasks.lex.tex: a cancelled task is terminal, and every step keeps it"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "cancel"
          },
          {
            "field": "state",
            "op": "is",
            "value": "working"
          },
          {
            "field": "asks",
            "op": "is",
            "value": "no"
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          },
          {
            "field": "outcome",
            "op": "is",
            "value": "completes"
          }
        ],
        "then": "completed",
        "why": "Tasks.cancel settles first: work that finished before the cancel stays completed (TASKS.md, What a task does)"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "cancel"
          },
          {
            "field": "state",
            "op": "is",
            "value": "working"
          },
          {
            "field": "asks",
            "op": "is",
            "value": "no"
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          },
          {
            "field": "outcome",
            "op": "is",
            "value": "fails"
          }
        ],
        "then": "failed",
        "why": "Tasks.cancel settles first: work that failed before the cancel stays failed"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "cancel"
          }
        ],
        "then": "cancelled",
        "why": "Tasks.cancelSettled: a working or input_required task becomes cancelled"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "settle"
          },
          {
            "field": "state",
            "op": "is",
            "value": "working"
          },
          {
            "field": "asks",
            "op": "is",
            "value": "yes"
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          }
        ],
        "then": "input-required",
        "why": "Tasks.settleWorking: a plan that parks moves to input_required once parkAfterMs has passed"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "settle"
          },
          {
            "field": "state",
            "op": "is",
            "value": "working"
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          },
          {
            "field": "outcome",
            "op": "is",
            "value": "completes"
          }
        ],
        "then": "completed",
        "why": "Tasks.settleWorking: with nothing to ask, the task concludes once finishAfterMs has passed (Tasks.due)"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "settle"
          },
          {
            "field": "state",
            "op": "is",
            "value": "working"
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          },
          {
            "field": "outcome",
            "op": "is",
            "value": "fails"
          }
        ],
        "then": "failed",
        "why": "Tasks.concluded: a plan that fails gives a failed task with its JSON-RPC error"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "answer"
          },
          {
            "field": "state",
            "op": "is",
            "value": "input-required"
          },
          {
            "field": "remaining",
            "op": "=",
            "value": 0
          },
          {
            "field": "asks",
            "op": "is",
            "value": "yes"
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          }
        ],
        "then": "input-required",
        "why": "Tasks.resume settles at once: a plan that still asks parks again"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "answer"
          },
          {
            "field": "state",
            "op": "is",
            "value": "input-required"
          },
          {
            "field": "remaining",
            "op": "=",
            "value": 0
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          },
          {
            "field": "outcome",
            "op": "is",
            "value": "completes"
          }
        ],
        "then": "completed",
        "why": "Tasks.answerInput: the last key answered resumes the task, which settles at once and completes if due"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "answer"
          },
          {
            "field": "state",
            "op": "is",
            "value": "input-required"
          },
          {
            "field": "remaining",
            "op": "=",
            "value": 0
          },
          {
            "field": "elapsed",
            "op": ">=",
            "value": {
              "field": "deadline"
            }
          },
          {
            "field": "outcome",
            "op": "is",
            "value": "fails"
          }
        ],
        "then": "failed",
        "why": "Tasks.answerInput: the last key answered resumes the task, which settles at once and fails if due"
      },
      {
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "answer"
          },
          {
            "field": "state",
            "op": "is",
            "value": "input-required"
          },
          {
            "field": "remaining",
            "op": "=",
            "value": 0
          }
        ],
        "then": "working",
        "why": "Tasks.resume: with every key answered and nothing due, the task returns to working"
      },
      {
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "input-required"
          }
        ],
        "then": "input-required",
        "why": "Tasks.settle keeps an input_required task, and answerInput keeps it while any key remains"
      }
    ],
    "otherwise": "working",
    "otherwiseWhy": "src/Tasks.lex.tex: a working task whose next step is not yet due, or that is answered, is kept as it is",
    "properties": [
      {
        "kind": "never",
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "cancel"
          }
        ],
        "then": "working",
        "why": "TASKS.md: a cancel never leaves a task running"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "event",
            "op": "is",
            "value": "cancel"
          }
        ],
        "then": "input-required",
        "why": "a cancel never leaves a task waiting for input"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "working"
          },
          {
            "field": "elapsed",
            "op": "<",
            "value": {
              "field": "deadline"
            }
          }
        ],
        "then": "completed",
        "why": "Tasks.due: no work concludes before finishAfterMs has passed"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "working"
          },
          {
            "field": "elapsed",
            "op": "<",
            "value": {
              "field": "deadline"
            }
          }
        ],
        "then": "failed",
        "why": "Tasks.due: no work fails before finishAfterMs has passed"
      },
      {
        "kind": "never",
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "input-required"
          },
          {
            "field": "event",
            "op": "is",
            "value": "answer"
          },
          {
            "field": "remaining",
            "op": ">=",
            "value": 1
          }
        ],
        "then": "working",
        "why": "Tasks.answerInput: a task resumes only once every key is answered"
      },
      {
        "kind": "always",
        "when": [
          {
            "field": "state",
            "op": "is",
            "value": "input-required"
          },
          {
            "field": "event",
            "op": "is",
            "value": "settle"
          }
        ],
        "then": "input-required",
        "why": "Tasks.settle: settling a task that waits for input changes nothing"
      }
    ],
    "examples": [
      {
        "request": "working settle no 1500 1000 completes 0",
        "response": "completed"
      },
      {
        "request": "working settle yes 500 1000 completes 0",
        "response": "working"
      },
      {
        "request": "working settle yes 1000 1000 completes 0",
        "response": "input-required"
      },
      {
        "request": "working settle no 2000 1000 fails 0",
        "response": "failed"
      },
      {
        "request": "input-required answer no 2000 5000 completes 1",
        "response": "input-required"
      },
      {
        "request": "input-required answer no 2000 5000 completes 0",
        "response": "working"
      },
      {
        "request": "input-required answer no 6000 5000 fails 0",
        "response": "failed"
      },
      {
        "request": "working cancel no 2000 1000 completes 0",
        "response": "completed"
      },
      {
        "request": "working cancel yes 10 1000 completes 0",
        "response": "cancelled"
      },
      {
        "request": "completed cancel no 0 0 completes 0",
        "response": "completed"
      },
      {
        "request": "working settle",
        "response": "invalid"
      }
    ]
  },
  "stakeholders": [
    {
      "name": "MCP client author",
      "text": "Polls a task through tasks/get, answers it through tasks/update and cancels it through tasks/cancel, and needs every answer to be the state the protocol allows.",
      "concerns": [
        "Correct answers",
        "Proved guarantees"
      ]
    },
    {
      "name": "Host adapter author",
      "text": "Holds the task table between requests for the stateless core (PrismPM issue 216) and needs a finished task to stay finished whatever arrives next.",
      "concerns": [
        "Terminal tasks stay terminal",
        "Refused malformed requests"
      ]
    }
  ],
  "concerns": [
    {
      "name": "Terminal tasks stay terminal",
      "text": "A completed, failed or cancelled task is never moved again by settle, answer or cancel.",
      "model": "quality"
    }
  ],
  "components": [
    {
      "name": "MCP client",
      "text": "The client that declares io.modelcontextprotocol/tasks in its request _meta and calls tasks/get, tasks/update and tasks/cancel.",
      "kind": "externalSystem"
    },
    {
      "name": "Host adapter",
      "text": "PrismPM's adapter (issue 216): it sends now_ms, the fresh task id and the task table in every request frame and stores the table the core returns.",
      "kind": "service"
    },
    {
      "name": "MCP conformance suite",
      "text": "modelcontextprotocol/conformance at cf022cbb, whose tasks scenarios drive the conformance build.",
      "kind": "externalSystem"
    }
  ],
  "threats": [
    {
      "name": "Terminal task revived",
      "text": "A step moves a completed, failed or cancelled task back to working, so a client sees finished work run again.",
      "stride": "tampering",
      "asset": "answer",
      "likelihood": "low",
      "impact": "critical",
      "control": {
        "name": "Final states proved",
        "text": "The machine declares completed, failed and cancelled final; the builder checks every sampled step keeps them and Lean proves it for every request.",
        "evidence": [
          {
            "kind": "proof",
            "reference": "McpTaskLifecycleProofs::inv007Holds"
          },
          {
            "kind": "review",
            "reference": "MCP src/TaskLaws.lex.tex"
          }
        ]
      }
    },
    {
      "name": "Cancel hides finished work",
      "text": "A cancel that arrives after the work finished reports cancelled, and the client loses a result it was owed.",
      "stride": "repudiation",
      "asset": "answer",
      "likelihood": "medium",
      "impact": "major",
      "control": {
        "name": "Settle before cancel",
        "text": "tasks/cancel settles first, so work already due concludes and the cancel leaves it.",
        "evidence": [
          {
            "kind": "proof",
            "reference": "McpTaskLifecycleProofs::inv001Holds"
          },
          {
            "kind": "gate",
            "reference": "MCP crates/lifecycle-oracle/tests/tasks.rs TK-01 to TK-16"
          }
        ]
      }
    },
    {
      "name": "Host clock or table substituted",
      "text": "The host sends a clock that runs backward or a table other than the one it was given, so a task concludes early or reappears.",
      "stride": "tampering",
      "asset": "request",
      "likelihood": "low",
      "impact": "major",
      "accepted": "The core keeps no state by design; TASKS.md puts the clock and the table in the host's custody, and the host owes the core exactly what it was given."
    }
  ],
  "quality": [
    {
      "characteristic": "Functional suitability",
      "subcharacteristic": "Functional correctness",
      "requirement": "Every step matches the core",
      "text": "Each acceptance vector answers the state Tasks.settle, Tasks.answer or Tasks.cancel writes.",
      "measure": "Vectors that disagree",
      "measureText": "Acceptance vectors whose replayed answer differs from the expected next state.",
      "threshold": 0
    },
    {
      "characteristic": "Reliability",
      "subcharacteristic": "Faultlessness",
      "requirement": "No final state is left",
      "text": "No step takes a completed, failed or cancelled task to another state.",
      "measure": "Final states left",
      "measureText": "Sampled steps from a final state whose answer is another state.",
      "threshold": 0
    }
  ],
  "journeys": [
    {
      "stakeholder": "MCP client author",
      "steps": [
        "otherwise",
        "REQ-007",
        "REQ-013",
        "REQ-008",
        "INV-005"
      ]
    },
    {
      "stakeholder": "Host adapter author",
      "steps": [
        "REQ-001",
        "REQ-006",
        "INV-007",
        "refuse"
      ]
    }
  ],
  "axioms": {
    "inv001Holds": [
      "Classical.choice",
      "Quot.sound",
      "propext"
    ],
    "inv002Holds": [
      "Classical.choice",
      "Quot.sound",
      "propext"
    ]
  },
  "license": "MIT OR Apache-2.0"
}
```

## Claims

- MT-01: The app never answers working when event is cancel
- MT-02: The app never answers input-required when event is cancel
- MT-03: The app never answers completed when state is working and elapsed is below deadline
- MT-04: The app never answers failed when state is working and elapsed is below deadline
- MT-05: The app never answers working when state is input-required and event is answer and remaining is at least 1
- MT-06: The app always answers input-required when state is input-required and event is settle
- MT-07: The app always answers completed when state is completed
- MT-08: The app always answers failed when state is failed
- MT-09: The app always answers cancelled when state is cancelled
- MT-10: The architecture description declares every stakeholder, concern, component, edge, viewpoint and view it references
- MT-11: The ISO/IEC 25010 quality model numbers every characteristic, subcharacteristic, requirement and measure, and every parent it names is declared
- MT-12: Every compliance obligation is numbered in order and names its evidence

## Pattern

State machine: OMG UML 2.5.1 behavioral state machine. The answer is the next state, given the current state and an event. This is a UML state machine written as one pure function. The state travels in the request, so the app keeps nothing between requests. The builder proves what holds over every run.

| Pattern | Standard | Answers |
| --- | --- | --- |
| State machine | OMG UML 2.5.1 behavioral state machine | working, input-required, completed, failed, cancelled |

**Figure: Rules for each answer.** Each bar counts the rules that give one answer. When no rule matches, the answer is working.

|  | rules |
| --- | --- |
| working | 1 |
| input-required | 3 |
| completed | 4 |
| failed | 4 |
| cancelled | 2 |

## Behavior

A request is state, event, asks, elapsed, deadline, outcome, remaining, separated by spaces. The first rule that matches decides. If none matches, the answer is working. A request over 184 bytes, or in any other form, is answered invalid.

| Rule | When | Answer | Why |
| --- | --- | --- | --- |
| REQ-001 | state is completed | completed | src/Tasks.lex.tex: settle, answer and cancel keep a completed entry (kept entry) |
| REQ-002 | state is failed | failed | src/Tasks.lex.tex: a failed task is terminal (isTerminal), and every step keeps it |
| REQ-003 | state is cancelled | cancelled | src/Tasks.lex.tex: a cancelled task is terminal, and every step keeps it |
| REQ-004 | event is cancel and state is working and asks is no and elapsed is at least deadline and outcome is completes | completed | Tasks.cancel settles first: work that finished before the cancel stays completed (TASKS.md, What a task does) |
| REQ-005 | event is cancel and state is working and asks is no and elapsed is at least deadline and outcome is fails | failed | Tasks.cancel settles first: work that failed before the cancel stays failed |
| REQ-006 | event is cancel | cancelled | Tasks.cancelSettled: a working or input\_required task becomes cancelled |
| REQ-007 | event is settle and state is working and asks is yes and elapsed is at least deadline | input-required | Tasks.settleWorking: a plan that parks moves to input\_required once parkAfterMs has passed |
| REQ-008 | event is settle and state is working and elapsed is at least deadline and outcome is completes | completed | Tasks.settleWorking: with nothing to ask, the task concludes once finishAfterMs has passed (Tasks.due) |
| REQ-009 | event is settle and state is working and elapsed is at least deadline and outcome is fails | failed | Tasks.concluded: a plan that fails gives a failed task with its JSON-RPC error |
| REQ-010 | event is answer and state is input-required and remaining equals 0 and asks is yes and elapsed is at least deadline | input-required | Tasks.resume settles at once: a plan that still asks parks again |
| REQ-011 | event is answer and state is input-required and remaining equals 0 and elapsed is at least deadline and outcome is completes | completed | Tasks.answerInput: the last key answered resumes the task, which settles at once and completes if due |
| REQ-012 | event is answer and state is input-required and remaining equals 0 and elapsed is at least deadline and outcome is fails | failed | Tasks.answerInput: the last key answered resumes the task, which settles at once and fails if due |
| REQ-013 | event is answer and state is input-required and remaining equals 0 | working | Tasks.resume: with every key answered and nothing due, the task returns to working |
| REQ-014 | state is input-required | input-required | Tasks.settle keeps an input\_required task, and answerInput keeps it while any key remains |
| otherwise | no rule matches | working | src/Tasks.lex.tex: a working task whose next step is not yet due, or that is answered, is kept as it is |

## State machine

The state is state, and the answer is the next state. A run feeds each answer back in as the next state, starting from working (OMG UML 2.5.1, clause 14). All 1620 requests of the spec's sample were stepped to find the states a run can reach. The invariants are INV-007, INV-008, INV-009. Each holds for one step, so by induction it holds over every run.

| State | Kind | Meaning |
| --- | --- | --- |
| working | initial, reachable | the task is running; tasks/get answers status working |
| input-required | reachable | the task waits for the client to answer its inputRequests through tasks/update |
| completed | final, reachable | terminal: the plan's result is the task's result |
| failed | final, reachable | terminal: the task carries the plan's JSON-RPC error |
| cancelled | final, reachable | terminal: the client cancelled the task before it finished |

## Transitions

Every step a reachable state can take, and the rule that takes it.

| From | To | By |
| --- | --- | --- |
| working | input-required | REQ-007 |
| working | working | otherwise |
| working | completed | REQ-004 |
| working | completed | REQ-008 |
| working | failed | REQ-005 |
| working | failed | REQ-009 |
| working | cancelled | REQ-006 |
| input-required | input-required | REQ-010 |
| input-required | input-required | REQ-014 |
| input-required | working | REQ-013 |
| input-required | completed | REQ-011 |
| input-required | failed | REQ-012 |
| input-required | cancelled | REQ-006 |
| completed | completed | REQ-001 |
| failed | failed | REQ-002 |
| cancelled | cancelled | REQ-003 |

## Properties Lean proves

Each property is a theorem about the same definitions the app is built from. It is proved for every request, not only the tested ones.

| Property | Statement | Theorem | Why |
| --- | --- | --- | --- |
| INV-001 | It never answers working when event is cancel. | McpTaskLifecycleProofs::inv001Holds | TASKS.md: a cancel never leaves a task running |
| INV-002 | It never answers input-required when event is cancel. | McpTaskLifecycleProofs::inv002Holds | a cancel never leaves a task waiting for input |
| INV-003 | It never answers completed when state is working and elapsed is below deadline. | McpTaskLifecycleProofs::inv003Holds | Tasks.due: no work concludes before finishAfterMs has passed |
| INV-004 | It never answers failed when state is working and elapsed is below deadline. | McpTaskLifecycleProofs::inv004Holds | Tasks.due: no work fails before finishAfterMs has passed |
| INV-005 | It never answers working when state is input-required and event is answer and remaining is at least 1. | McpTaskLifecycleProofs::inv005Holds | Tasks.answerInput: a task resumes only once every key is answered |
| INV-006 | It always answers input-required when state is input-required and event is settle. | McpTaskLifecycleProofs::inv006Holds | Tasks.settle: settling a task that waits for input changes nothing |
| INV-007 | It always answers completed when state is completed. | McpTaskLifecycleProofs::inv007Holds | completed is a final state (UML 2.5.1 FinalState): a run that reaches it stays there |
| INV-008 | It always answers failed when state is failed. | McpTaskLifecycleProofs::inv008Holds | failed is a final state (UML 2.5.1 FinalState): a run that reaches it stays there |
| INV-009 | It always answers cancelled when state is cancelled. | McpTaskLifecycleProofs::inv009Holds | cancelled is a final state (UML 2.5.1 FinalState): a run that reaches it stays there |

## Architecture

Stakeholders and the concerns each one views the app through (ISO/IEC/IEEE 42010).

| Stakeholder | Who they are | Concerns |
| --- | --- | --- |
| Host adapter author | Holds the task table between requests for the stateless core (PrismPM issue 216) and needs a finished task to stay finished whatever arrives next. | Terminal tasks stay terminal, Refused malformed requests |
| MCP client author | Polls a task through tasks/get, answers it through tasks/update and cancels it through tasks/cancel, and needs every answer to be the state the protocol allows. | Correct answers, Proved guarantees |
| Verifier | Anyone who loads the holo, checks its fingerprint and replays its acceptance vectors before trusting an answer. | Integrity of the published app, Refused malformed requests, Proved guarantees |

## Concerns

What the stakeholders care about, and the model each is viewed in.

| Concern | What it means | Model |
| --- | --- | --- |
| Correct answers | Every well-formed request is answered by the first rule that matches it, or working when none does, as the spec states. | quality |
| Integrity of the published app | What a visitor runs is the holo the build verified, with its fingerprint and signed provenance beside it. | security |
| Proved guarantees | Each of the 9 properties of the spec holds for every request, proved by the Lean kernel. | quality |
| Refused malformed requests | A request that is not the 7 fields in order, or is longer than 184 bytes, is answered invalid and never guessed. | security |
| Terminal tasks stay terminal | A completed, failed or cancelled task is never moved again by settle, answer or cancel. | quality |

## Components

9 components and 13 edges between them.

| Component | Kind | What it is |
| --- | --- | --- |
| Browser | externalSystem | The visitor's web browser, which loads the page and runs the MCP task lifecycle guest. |
| GitHub Pages | externalSystem | Serves the page and the holo from the repository Pages workflow. |
| Host adapter | service | PrismPM's adapter (issue 216): it sends now\_ms, the fresh task id and the task table in every request frame and stores the table the core returns. |
| MCP client | externalSystem | The client that declares io.modelcontextprotocol/tasks in its request \_meta and calls tasks/get, tasks/update and tasks/cancel. |
| MCP conformance suite | externalSystem | modelcontextprotocol/conformance at cf022cbb, whose tasks scenarios drive the conformance build. |
| MCP task lifecycle guest | service | The Core-Wasm guest built from the model: it answers one request of at most 184 bytes with one answer of at most 64. |
| MCP task lifecycle page | staticSite | The page the template publishes: the holo, its fingerprint, its provenance and its acceptance vectors. |
| Prism build | cliAdapter | prismpm verify in the SDK image prismpm.lock pins: it checks every theorem, builds the guest and replays every vector. |
| Source repository | externalSystem | The repository that holds the prompt, the model and its gate. |

## Design views

The SDK checks each view against the system model and draws it as OPL and PlantUML.

| View | Diagram | Viewpoint |
| --- | --- | --- |
| Deciding a MCP task lifecycle request | opmObjectProcess | MCP client author: Correct answers |
| Components of MCP task lifecycle | umlComponent | Verifier: Integrity of the published app |
| Answering a MCP task lifecycle request | umlSequence | MCP client author: Correct answers |
| States of the MCP task lifecycle guest | umlStateMachine | Host adapter author: Refused malformed requests |
| The MCP task lifecycle state machine | umlStateMachine | MCP client author: Correct answers |

## Features and journeys

25 features. Each names the definitions that do the work and the tests that accept it. Each stakeholder has one journey.

| Feature | Calls | Accepted by |
| --- | --- | --- |
| When state is completed, the answer is completed. | McpTaskLifecycle::rule1, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When state is failed, the answer is failed. | McpTaskLifecycle::rule2, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When state is cancelled, the answer is cancelled. | McpTaskLifecycle::rule3, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is cancel and state is working and asks is no and elapsed is at least deadline and outcome is completes, the answer is completed. | McpTaskLifecycle::rule4, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is cancel and state is working and asks is no and elapsed is at least deadline and outcome is fails, the answer is failed. | McpTaskLifecycle::rule5, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is cancel, the answer is cancelled. | McpTaskLifecycle::rule6, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is settle and state is working and asks is yes and elapsed is at least deadline, the answer is input-required. | McpTaskLifecycle::rule7, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is settle and state is working and elapsed is at least deadline and outcome is completes, the answer is completed. | McpTaskLifecycle::rule8, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is settle and state is working and elapsed is at least deadline and outcome is fails, the answer is failed. | McpTaskLifecycle::rule9, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is answer and state is input-required and remaining equals 0 and asks is yes and elapsed is at least deadline, the answer is input-required. | McpTaskLifecycle::rule10, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is answer and state is input-required and remaining equals 0 and elapsed is at least deadline and outcome is completes, the answer is completed. | McpTaskLifecycle::rule11, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is answer and state is input-required and remaining equals 0 and elapsed is at least deadline and outcome is fails, the answer is failed. | McpTaskLifecycle::rule12, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When event is answer and state is input-required and remaining equals 0, the answer is working. | McpTaskLifecycle::rule13, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When state is input-required, the answer is input-required. | McpTaskLifecycle::rule14, McpTaskLifecycle::judge | McpTaskLifecycle::application |
| When no rule matches, the answer is working. | McpTaskLifecycle::judge | McpTaskLifecycle::application |
| A request that is not state, event, asks, elapsed, deadline, outcome, remaining in order, separated by single spaces, or is over 184 bytes, is answered invalid. | McpTaskLifecycle::dispatch, McpTaskLifecycle::decodeField1 | McpTaskLifecycle::application |
| It never answers working when event is cancel. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv001Holds |
| It never answers input-required when event is cancel. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv002Holds |
| It never answers completed when state is working and elapsed is below deadline. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv003Holds |
| It never answers failed when state is working and elapsed is below deadline. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv004Holds |
| It never answers working when state is input-required and event is answer and remaining is at least 1. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv005Holds |
| It always answers input-required when state is input-required and event is settle. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv006Holds |
| It always answers completed when state is completed. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv007Holds |
| It always answers failed when state is failed. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv008Holds |
| It always answers cancelled when state is cancelled. | McpTaskLifecycle::judge | McpTaskLifecycleProofs::inv009Holds |

## Journeys

The ordered features each stakeholder takes.

| Stakeholder | Steps |
| --- | --- |
| Host adapter author | REQ-001 → REQ-006 → INV-007 → refuse |
| MCP client author | otherwise → REQ-007 → REQ-013 → REQ-008 → INV-005 |
| Verifier | refuse → INV-001 → INV-002 → INV-003 → INV-004 → INV-005 → INV-006 → INV-007 → INV-008 → INV-009 |

## Security and threat model

18 threats against 4 assets. Each has a STRIDE category, and either a control with evidence or a risk that is accepted on purpose.

| Threat | STRIDE | Asset | Risk | Answered by |
| --- | --- | --- | --- | --- |
| Answer that breaks INV-001 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-001: proof McpTaskLifecycleProofs::inv001Holds |
| Answer that breaks INV-002 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-002: proof McpTaskLifecycleProofs::inv002Holds |
| Answer that breaks INV-003 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-003: proof McpTaskLifecycleProofs::inv003Holds |
| Answer that breaks INV-004 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-004: proof McpTaskLifecycleProofs::inv004Holds |
| Answer that breaks INV-005 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-005: proof McpTaskLifecycleProofs::inv005Holds |
| Answer that breaks INV-006 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-006: proof McpTaskLifecycleProofs::inv006Holds |
| Answer that breaks INV-007 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-007: proof McpTaskLifecycleProofs::inv007Holds |
| Answer that breaks INV-008 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-008: proof McpTaskLifecycleProofs::inv008Holds |
| Answer that breaks INV-009 | repudiation | Answer | medium likelihood, critical impact | Proof of INV-009: proof McpTaskLifecycleProofs::inv009Holds |
| Cancel hides finished work | repudiation | Answer | medium likelihood, major impact | Settle before cancel: proof McpTaskLifecycleProofs::inv001Holds; gate MCP crates/lifecycle-oracle/tests/tasks.rs TK-01 to TK-16 |
| Granted capability | informationDisclosure | Answer | low likelihood, major impact | No capability granted: gate prism-code check refuses an ungranted guest import |
| Host clock or table substituted | tampering | Request bytes | low likelihood, major impact | accepted: The core keeps no state by design; TASKS.md puts the clock and the table in the host's custody, and the host owes the core exactly what it was given. |
| Malformed request | tampering | Request bytes | high likelihood, major impact | Strict decoder: gate malformed-request acceptance vectors, replayed in the compiled guest by prismpm verify |
| Oversized request | denialOfService | Request bytes | medium likelihood, minor impact | Bounded request: gate acceptance vectors at the request bound, one byte over it, and at the guest allocation bound, replayed by prismpm verify |
| Substituted holo | spoofing | Published holo | low likelihood, critical impact | Fingerprint and provenance: gate actions/attest-build-provenance in the pages workflow; gate prism-code check of the holo identities in the page |
| Substituted host | spoofing | Published holo | low likelihood, critical impact | accepted: A page cannot defend against its own host. The holo carries signed build provenance a visitor can check, and the app can be rebuilt from its prompt. |
| Tampered model | tampering | Model source | low likelihood, major impact | Regenerated from the prompt: gate prismpm verify in the SDK image prismpm.lock pins; review app/prompt.json |
| Terminal task revived | tampering | Answer | low likelihood, critical impact | Final states proved: proof McpTaskLifecycleProofs::inv007Holds; review MCP src/TaskLaws.lex.tex |

## Quality

ISO/IEC 25010:2023 requirements. Each has a measure and a threshold that a theorem pins.

| Requirement | Characteristic | Measure | Threshold |
| --- | --- | --- | --- |
| Bounded allocation: The guest allocates at most 368 bytes for one request. | Performance efficiency: Resource utilization | Guest allocation bytes | 368 |
| Bounded request: A request over 184 bytes is refused before any field is read. | Performance efficiency: Time behaviour | Request bytes read | 184 |
| Every property proved: All 9 properties are theorems the Lean kernel checks. | Security: Integrity | Unproved properties | 0 |
| Every request answered: Every request gets an answer: a rule, working otherwise, or invalid. | Functional suitability: Functional completeness | Unanswered requests | 0 |
| Every step matches the core: Each acceptance vector answers the state Tasks.settle, Tasks.answer or Tasks.cancel writes. | Functional suitability: Functional correctness | Vectors that disagree | 0 |
| Every vector replays: All 65 acceptance vectors replay in the compiled guest, the shortest 0 bytes long. | Reliability: Faultlessness | Failed vectors | 0 |
| Examples answered as stated: Every one of the 11 examples of the spec is answered as it states. | Functional suitability: Functional correctness | Example mismatches | 0 |
| No final state is left: No step takes a completed, failed or cancelled task to another state. | Reliability: Faultlessness | Final states left | 0 |

## Compliance

One obligation per standard, each naming its evidence.

| Standard | Subject | Evidence |
| --- | --- | --- |
| ISO/IEC/IEEE 42010:2022 | Architecture description | Architecture::architectureDescriptionHolds |
| ISO/PAS 19450:2015 and OMG UML 2.5.1 | Design views | Design::viewOpmDecide, Design::viewUmlComponents, Design::viewUmlRequest, Design::viewUmlStates, Design::viewUmlMachine |
| ISO/IEC 25010:2023 | Product quality | Quality::qualityModelHolds |
| ISO/IEC 27034-1:2011 and ISO/IEC 27005:2022 | Application security and risk | Security::controlSet |
| OMG UML 2.5.1 behavioral state machine | State machine | McpTaskLifecycle::judge, McpTaskLifecycleProofs::inv007Holds, McpTaskLifecycleProofs::inv008Holds, McpTaskLifecycleProofs::inv009Holds |
| OpenSpec | Requirements | McpTaskLifecycle::application |
| SPDX MIT OR Apache-2.0 | Licensing | McpTaskLifecycle::application |

## Rendered design views

Written by the SDK from the design records when it verified the app.

### design/Design.viewOpmDecide.opl

```
View: Design::viewOpmDecide
Title: Deciding a MCP task lifecycle request
Viewpoint: Architecture::viewpointMCPClientAuthorCorrectAnswers
Notation: ISO/PAS 19450:2015 OPM, Prism OPL profile

componentBrowser is an object.
componentMCPTaskLifecycleGuest is an object.
componentMCPTaskLifecycleGuest can be stateDeciding or stateIdle.
processDecide is a process.
processEncodeAnswer is a process.
processJudge is a process.
processParseRequest is a process.
componentMCPTaskLifecycleGuest handles processDecide.
processParseRequest requires componentBrowser.
processEncodeAnswer affects componentBrowser.
processJudge invokes processEncodeAnswer.
processParseRequest invokes processJudge.
processDecide zooms into processParseRequest, processJudge, and processEncodeAnswer, in that sequence.

```

### design/Design.viewUmlComponents.puml

```
@startuml
' UML 2.5.1 component diagram
' view: Design::viewUmlComponents
' viewpoint: Architecture::viewpointVerifierIntegrityOfThePublishedApp
title Components of MCP task lifecycle
component "componentBrowser" as c0
component "componentGitHubPages" as c1
component "componentHostAdapter" as c2
component "componentMCPClient" as c3
component "componentMCPConformanceSuite" as c4
component "componentMCPTaskLifecycleGuest" as c5
component "componentMCPTaskLifecyclePage" as c6
component "componentPrismBuild" as c7
component "componentSourceRepository" as c8
c0 --> c5 : edgeBrowserToMCPTaskLifecycleGuest
c1 --> c0 : edgeGitHubPagesToBrowser
c2 --> c5 : edgeHostAdapterToMCPTaskLifecycleGuest
c3 --> c5 : edgeMCPClientToMCPTaskLifecycleGuest
c4 --> c5 : edgeMCPConformanceSuiteToMCPTaskLifecycleGuest
c5 --> c0 : edgeMCPTaskLifecycleGuestToBrowser
c5 --> c2 : edgeMCPTaskLifecycleGuestToHostAdapter
c5 --> c3 : edgeMCPTaskLifecycleGuestToMCPClient
c5 --> c4 : edgeMCPTaskLifecycleGuestToMCPConformanceSuite
c6 --> c1 : edgeMCPTaskLifecyclePageToGitHubPages
c7 --> c5 : edgePrismBuildToMCPTaskLifecycleGuest
c7 --> c6 : edgePrismBuildToMCPTaskLifecyclePage
c8 --> c7 : edgeSourceRepositoryToPrismBuild
@enduml

```

### design/Design.viewUmlMachine.puml

```
@startuml
' UML 2.5.1 state machine diagram
' view: Design::viewUmlMachine
' viewpoint: Architecture::viewpointMCPClientAuthorCorrectAnswers
title The MCP task lifecycle state machine
state "stateMachineCancelled" as s0
state "stateMachineCompleted" as s1
state "stateMachineFailed" as s2
state "stateMachineInputRequired" as s3
state "stateMachineWorking" as s4
[*] --> s4
s4 --> s3 : processRule7
s4 --> s4 : processOtherwise
s4 --> s1 : processRule4
s4 --> s1 : processRule8
s4 --> s2 : processRule5
s4 --> s2 : processRule9
s4 --> s0 : processRule6
s3 --> s3 : processRule10
s3 --> s3 : processRule14
s3 --> s4 : processRule13
s3 --> s1 : processRule11
s3 --> s2 : processRule12
s3 --> s0 : processRule6
s1 --> s1 : processRule1
s2 --> s2 : processRule2
s0 --> s0 : processRule3
@enduml

```

### design/Design.viewUmlRequest.puml

```
@startuml
' UML 2.5.1 sequence diagram
' view: Design::viewUmlRequest
' viewpoint: Architecture::viewpointMCPClientAuthorCorrectAnswers
title Answering a MCP task lifecycle request
participant "componentBrowser" as p0
participant "componentMCPTaskLifecycleGuest" as p1
p0 -> p1 : processDecide
p1 --> p0 : processDecide
@enduml

```

### design/Design.viewUmlStates.puml

```
@startuml
' UML 2.5.1 state machine diagram
' view: Design::viewUmlStates
' viewpoint: Architecture::viewpointHostAdapterAuthorRefusedMalformedRequests
title States of the MCP task lifecycle guest
state "stateAnsweredCancelled" as s0
state "stateAnsweredCompleted" as s1
state "stateAnsweredFailed" as s2
state "stateAnsweredInputRequired" as s3
state "stateAnsweredWorking" as s4
state "stateDeciding" as s5
state "stateIdle" as s6
state "stateRefused" as s7
[*] --> s6
s6 --> s5 : processParseRequest
s6 --> s7 : processParseRequest
s5 --> s1 : processRule1
s5 --> s2 : processRule2
s5 --> s0 : processRule3
s5 --> s1 : processRule4
s5 --> s2 : processRule5
s5 --> s0 : processRule6
s5 --> s3 : processRule7
s5 --> s1 : processRule8
s5 --> s2 : processRule9
s5 --> s3 : processRule10
s5 --> s1 : processRule11
s5 --> s2 : processRule12
s5 --> s4 : processRule13
s5 --> s3 : processRule14
s5 --> s4 : processOtherwise
s4 --> s6 : processEncodeAnswer
s3 --> s6 : processEncodeAnswer
s1 --> s6 : processEncodeAnswer
s2 --> s6 : processEncodeAnswer
s0 --> s6 : processEncodeAnswer
s7 --> s6 : processEncodeAnswer
@enduml

```

## Prism source

Every file the builder wrote, laid out as a repository created from UOR-Foundation/template; the download prism-mcp-task-lifecycle.zip has them all.

- app/src/Architecture.lex.tex (434 lines)
- app/src/Compliance.lex.tex (56 lines)
- app/src/Design.lex.tex (941 lines)
- app/src/Features.lex.tex (270 lines)
- app/src/Quality.lex.tex (368 lines)
- app/src/Security.lex.tex (803 lines)
- app/src/McpTaskLifecycle.lex.tex (414 lines)
- app/src/McpTaskLifecycleProofs.lex.tex (513 lines)
- app/lexlean.toml (43 lines)
- app/prompt.json (729 lines)
- model/ids.toml (95 lines)
- features/suites/mcp\_task\_lifecycle.feature (74 lines)
- crates/conformance/tests/mcp\_task\_lifecycle.rs (182 lines)
- site/app.json (170 lines)
- openspec/specs/mcp-task-lifecycle/spec.md (357 lines)
