{
  "id": "workflows",
  "title": "Workflows",
  "eyebrow": "Onboarding dependencies and approvals",
  "summary": "Inspect unfinished onboarding prerequisites and distinguish approval from actual completion.",
  "businessQuestion": "What recorded predecessor is holding up onboarding, and which approved tasks still await execution?",
  "scopeNote": "Fictional, read-only employee onboarding at 2026-10-07 12:00 UTC. Queries inspect explicit immediate dependency links and recorded review states; they do not prove all prerequisites, validate approver authority, or execute tasks.",
  "keyDistinctions": [
    "A workflow definition describes a process; a workflow run is one execution of that version.",
    "A step definition is reusable; a task instance has an execution state.",
    "Approved means a review is recorded approved; completed means task execution is recorded completed.",
    "A listed incomplete predecessor explains one blocker. No listed blocker does not prove general readiness."
  ],
  "sources": [
    {
      "id": "process-catalog",
      "label": "Onboarding process catalog",
      "system": "Process documentation",
      "description": "Fictional versioned workflow and reusable step definitions."
    },
    {
      "id": "workflow-system",
      "label": "Ari onboarding run",
      "system": "Task management",
      "description": "Fictional execution, task status, and explicit immediate dependency records."
    },
    {
      "id": "approval-log",
      "label": "Onboarding review log",
      "system": "Approval workflow",
      "description": "Fictional task review states, separate from work execution."
    }
  ],
  "records": [
    {
      "id": "definition-onboarding-v1",
      "type": "workflow_definition",
      "label": "Employee onboarding v1",
      "properties": {
        "definition_id": "DEF-ONBOARDING",
        "name": "Employee onboarding",
        "version": "1.0"
      },
      "sourceId": "process-catalog"
    },
    {
      "id": "step-identity",
      "type": "step_definition",
      "label": "Verify identity",
      "properties": {
        "step_id": "STEP-IDENTITY",
        "name": "Verify identity"
      },
      "sourceId": "process-catalog"
    },
    {
      "id": "step-account",
      "type": "step_definition",
      "label": "Provision account",
      "properties": {
        "step_id": "STEP-ACCOUNT",
        "name": "Provision account"
      },
      "sourceId": "process-catalog"
    },
    {
      "id": "step-orientation",
      "type": "step_definition",
      "label": "Deliver orientation",
      "properties": {
        "step_id": "STEP-ORIENTATION",
        "name": "Deliver orientation"
      },
      "sourceId": "process-catalog"
    },
    {
      "id": "run-ari",
      "type": "workflow_run",
      "label": "Ari onboarding",
      "properties": {
        "run_id": "RUN-101",
        "status": "in_progress",
        "subject_name": "Ari Example"
      },
      "sourceId": "workflow-system"
    },
    {
      "id": "task-identity",
      "type": "task",
      "label": "Ari identity verification",
      "properties": {
        "task_id": "TASK-101",
        "status": "completed",
        "assigned_role": "people_operations"
      },
      "sourceId": "workflow-system"
    },
    {
      "id": "task-account",
      "type": "task",
      "label": "Ari account provisioning",
      "properties": {
        "task_id": "TASK-102",
        "status": "pending",
        "assigned_role": "IT_operations"
      },
      "sourceId": "workflow-system"
    },
    {
      "id": "task-orientation",
      "type": "task",
      "label": "Ari orientation",
      "properties": {
        "task_id": "TASK-103",
        "status": "pending",
        "assigned_role": "people_operations"
      },
      "sourceId": "workflow-system"
    },
    {
      "id": "approval-identity",
      "type": "approval",
      "label": "Identity review",
      "properties": {
        "approval_id": "APP-101",
        "status": "approved",
        "reviewer_role": "people_operations_manager"
      },
      "sourceId": "approval-log"
    },
    {
      "id": "approval-account",
      "type": "approval",
      "label": "Account access review",
      "properties": {
        "approval_id": "APP-102",
        "status": "approved",
        "reviewer_role": "IT_manager"
      },
      "sourceId": "approval-log"
    },
    {
      "id": "approval-orientation",
      "type": "approval",
      "label": "Orientation review",
      "properties": {
        "approval_id": "APP-103",
        "status": "pending",
        "reviewer_role": "people_operations_manager"
      },
      "sourceId": "approval-log"
    }
  ],
  "links": [
    {
      "id": "run-ari.instantiates",
      "from": "run-ari",
      "property": "instantiates",
      "to": "definition-onboarding-v1",
      "sourceId": "workflow-system"
    },
    {
      "id": "definition-onboarding-v1.includes_identity",
      "from": "definition-onboarding-v1",
      "property": "includes_step",
      "to": "step-identity",
      "sourceId": "process-catalog"
    },
    {
      "id": "run-ari.contains_identity",
      "from": "run-ari",
      "property": "contains_task",
      "to": "task-identity",
      "sourceId": "workflow-system"
    },
    {
      "id": "task-identity.implements_step",
      "from": "task-identity",
      "property": "implements_step",
      "to": "step-identity",
      "sourceId": "workflow-system"
    },
    {
      "id": "task-identity.has_approval",
      "from": "task-identity",
      "property": "has_approval",
      "to": "approval-identity",
      "sourceId": "approval-log"
    },
    {
      "id": "definition-onboarding-v1.includes_account",
      "from": "definition-onboarding-v1",
      "property": "includes_step",
      "to": "step-account",
      "sourceId": "process-catalog"
    },
    {
      "id": "run-ari.contains_account",
      "from": "run-ari",
      "property": "contains_task",
      "to": "task-account",
      "sourceId": "workflow-system"
    },
    {
      "id": "task-account.implements_step",
      "from": "task-account",
      "property": "implements_step",
      "to": "step-account",
      "sourceId": "workflow-system"
    },
    {
      "id": "task-account.has_approval",
      "from": "task-account",
      "property": "has_approval",
      "to": "approval-account",
      "sourceId": "approval-log"
    },
    {
      "id": "definition-onboarding-v1.includes_orientation",
      "from": "definition-onboarding-v1",
      "property": "includes_step",
      "to": "step-orientation",
      "sourceId": "process-catalog"
    },
    {
      "id": "run-ari.contains_orientation",
      "from": "run-ari",
      "property": "contains_task",
      "to": "task-orientation",
      "sourceId": "workflow-system"
    },
    {
      "id": "task-orientation.implements_step",
      "from": "task-orientation",
      "property": "implements_step",
      "to": "step-orientation",
      "sourceId": "workflow-system"
    },
    {
      "id": "task-orientation.has_approval",
      "from": "task-orientation",
      "property": "has_approval",
      "to": "approval-orientation",
      "sourceId": "approval-log"
    },
    {
      "id": "task-account.depends_on_identity",
      "from": "task-account",
      "property": "depends_on",
      "to": "task-identity",
      "sourceId": "workflow-system"
    },
    {
      "id": "task-orientation.depends_on_account",
      "from": "task-orientation",
      "property": "depends_on",
      "to": "task-account",
      "sourceId": "workflow-system"
    }
  ],
  "questions": [
    {
      "id": "incomplete_predecessors",
      "title": "Which pending tasks have recorded incomplete immediate predecessors?",
      "explanation": "Orientation depends on account provisioning, which is pending. Account provisioning depends on identity verification, which is completed. The query lists explicit blockers and does not certify all other tasks ready.",
      "arguments": {
        "runId": "run-ari"
      },
      "definition": {
        "artifactVersion": "t2k.graph-function.v1",
        "functionRef": "example.workflows:reasoning_function:incomplete_predecessors",
        "inputs": {
          "runId": "string"
        },
        "output": {
          "kind": "rows",
          "fields": {
            "taskId": "string",
            "predecessorId": "string",
            "predecessorStatus": "string"
          }
        },
        "maxAgeSeconds": 3600,
        "limits": {
          "maxRows": 100,
          "maxWork": 10000
        },
        "steps": [
          {
            "id": "run",
            "op": "lookup",
            "typeRef": "example.workflows:workflow_run",
            "as": "run",
            "entityId": {
              "argument": "runId"
            }
          },
          {
            "id": "tasks",
            "op": "traverse",
            "from": "run",
            "source": "run",
            "relation": "example.workflows:relation:workflow_run:contains_task:task",
            "direction": "outgoing",
            "as": "task"
          },
          {
            "id": "pending",
            "op": "filter",
            "from": "tasks",
            "all": [
              {
                "left": {
                  "binding": "task",
                  "property": "example.workflows:task.status"
                },
                "operator": "eq",
                "right": {
                  "literal": "pending"
                }
              }
            ]
          },
          {
            "id": "predecessors",
            "op": "traverse",
            "from": "pending",
            "source": "task",
            "relation": "example.workflows:relation:task:depends_on:task",
            "direction": "outgoing",
            "as": "predecessor"
          },
          {
            "id": "incomplete",
            "op": "filter",
            "from": "predecessors",
            "all": [
              {
                "left": {
                  "binding": "predecessor",
                  "property": "example.workflows:task.status"
                },
                "operator": "neq",
                "right": {
                  "literal": "completed"
                }
              }
            ]
          },
          {
            "id": "blockers",
            "op": "project",
            "from": "incomplete",
            "fields": {
              "taskId": {
                "entity": "task"
              },
              "predecessorId": {
                "entity": "predecessor"
              },
              "predecessorStatus": {
                "binding": "predecessor",
                "property": "example.workflows:task.status"
              }
            }
          }
        ],
        "return": "blockers"
      },
      "expected": {
        "status": "complete",
        "value": [
          {
            "taskId": "task-orientation",
            "predecessorId": "task-account",
            "predecessorStatus": "pending"
          }
        ]
      },
      "variants": [
        {
          "id": "identity_reopened",
          "label": "Reopen identity verification",
          "explanation": "Account provisioning also has an incomplete predecessor once identity verification is pending again.",
          "patches": [
            {
              "claimId": "task-identity.status",
              "value": "pending"
            }
          ],
          "expected": {
            "status": "complete",
            "value": [
              {
                "taskId": "task-orientation",
                "predecessorId": "task-account",
                "predecessorStatus": "pending"
              },
              {
                "taskId": "task-account",
                "predecessorId": "task-identity",
                "predecessorStatus": "pending"
              }
            ]
          }
        },
        {
          "id": "predecessor_status_missing",
          "label": "Remove the account task status",
          "explanation": "The missing status prevents a supported blocker answer; absence does not mean completed.",
          "patches": [
            {
              "claimId": "task-account.status",
              "remove": true
            }
          ],
          "expected": {
            "status": "needs_review",
            "value": null
          }
        }
      ]
    },
    {
      "id": "approved_unfinished_tasks",
      "title": "Which tasks have approved reviews but are not recorded completed?",
      "explanation": "Account provisioning is approved and still pending. Identity verification is already completed; orientation has only a pending review. The result describes recorded state, not permission to create an account.",
      "arguments": {
        "runId": "run-ari"
      },
      "definition": {
        "artifactVersion": "t2k.graph-function.v1",
        "functionRef": "example.workflows:reasoning_function:approved_unfinished_tasks",
        "inputs": {
          "runId": "string"
        },
        "output": {
          "kind": "rows",
          "fields": {
            "taskId": "string",
            "taskStatus": "string",
            "approvalStatus": "string"
          }
        },
        "maxAgeSeconds": 3600,
        "limits": {
          "maxRows": 100,
          "maxWork": 10000
        },
        "steps": [
          {
            "id": "run",
            "op": "lookup",
            "typeRef": "example.workflows:workflow_run",
            "as": "run",
            "entityId": {
              "argument": "runId"
            }
          },
          {
            "id": "tasks",
            "op": "traverse",
            "from": "run",
            "source": "run",
            "relation": "example.workflows:relation:workflow_run:contains_task:task",
            "direction": "outgoing",
            "as": "task"
          },
          {
            "id": "unfinished",
            "op": "filter",
            "from": "tasks",
            "all": [
              {
                "left": {
                  "binding": "task",
                  "property": "example.workflows:task.status"
                },
                "operator": "neq",
                "right": {
                  "literal": "completed"
                }
              }
            ]
          },
          {
            "id": "reviews",
            "op": "traverse",
            "from": "unfinished",
            "source": "task",
            "relation": "example.workflows:relation:task:has_approval:approval",
            "direction": "outgoing",
            "as": "approval"
          },
          {
            "id": "approved",
            "op": "filter",
            "from": "reviews",
            "all": [
              {
                "left": {
                  "binding": "approval",
                  "property": "example.workflows:approval.status"
                },
                "operator": "eq",
                "right": {
                  "literal": "approved"
                }
              }
            ]
          },
          {
            "id": "approved_work",
            "op": "project",
            "from": "approved",
            "fields": {
              "taskId": {
                "entity": "task"
              },
              "taskStatus": {
                "binding": "task",
                "property": "example.workflows:task.status"
              },
              "approvalStatus": {
                "binding": "approval",
                "property": "example.workflows:approval.status"
              }
            }
          }
        ],
        "return": "approved_work"
      },
      "expected": {
        "status": "complete",
        "value": [
          {
            "taskId": "task-account",
            "taskStatus": "pending",
            "approvalStatus": "approved"
          }
        ]
      },
      "variants": [
        {
          "id": "account_completed",
          "label": "Record account provisioning completed",
          "explanation": "The account task leaves the approved-but-unfinished list without changing its approval.",
          "patches": [
            {
              "claimId": "task-account.status",
              "value": "completed"
            }
          ],
          "expected": {
            "status": "complete",
            "value": []
          }
        },
        {
          "id": "approval_only_proposed",
          "label": "Keep the approval claim as a proposal",
          "explanation": "An unaccepted approval claim cannot establish the approved task list.",
          "patches": [
            {
              "claimId": "approval-account.status",
              "status": "proposed"
            }
          ],
          "expected": {
            "status": "needs_review",
            "value": null
          }
        }
      ]
    }
  ]
}
