{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/withhuman-ai/json-schema/withhuman-ai-approval-routing-schema.json",
  "title": "ApprovalRouting",
  "description": "Who was asked to review a request when it entered human review. agent_owner sends it to the person who owns the agent instance that made it; escalated pins an escalation path revision and the people it reaches for this request; default_queue means any authorized reviewer.",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/withhuman-ai-openapi.yaml#/components/schemas/ApprovalRouting",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "outcome",
    "reason",
    "urgency",
    "targets",
    "added_reviewers",
    "team_policies",
    "escalation",
    "created_at"
  ],
  "properties": {
    "outcome": {
      "type": "string",
      "enum": [
        "agent_owner",
        "escalated",
        "default_queue"
      ],
      "description": "`agent_owner` when the agent's owner took the request; the path fields then describe the fallback pinned beside it. `escalated` when an escalation path took the request. `default_queue` when no path applied and every reviewer who can decide was asked."
    },
    "reason": {
      "type": "string",
      "enum": [
        "block_escalation",
        "pipeline_default",
        "no_escalation",
        "path_inactive",
        "evaluation_error"
      ],
      "description": "How the outcome came about. `block_escalation`: the pipeline block that asked for a person named the route. `pipeline_default`: the pipeline's default route took it. `no_escalation`: the pipeline named no path. `path_inactive`: the named path had no active revision. `evaluation_error`: the path could not be resolved. The last three mean no path applied."
    },
    "urgency": {
      "type": "string",
      "enum": [
        "standard",
        "interrupt"
      ],
      "description": "The urgency the request was routed with. Always `standard` today."
    },
    "escalation_path_key": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]{0,62}$",
      "description": "The path that took the request, or for `agent_owner` the fallback pinned beside the owner. Absent for `default_queue`."
    },
    "escalation_path_name": {
      "type": "string",
      "description": "The name of the path revision that took the request, or the fallback revision for `agent_owner`. Absent for `default_queue`."
    },
    "escalation_path_revision_id": {
      "type": "string",
      "format": "uuid",
      "description": "The path revision that was active at the time. Absent for `default_queue`, and for `agent_owner` when the fallback path had no active revision."
    },
    "pipeline_revision_id": {
      "type": "string",
      "format": "uuid",
      "description": "The pipeline revision that routed the request. Absent for `default_queue`."
    },
    "block_id": {
      "type": "string",
      "format": "uuid",
      "description": "The pipeline block that named the path. Present for `block_escalation` only."
    },
    "agent_owner": {
      "$ref": "#/$defs/ApprovalRoutingTarget",
      "description": "The person the request was sent to as the owner of the agent instance that made it. Present for `agent_owner` only."
    },
    "agent_owner_fallback": {
      "type": "string",
      "enum": [
        "no_agent_owner",
        "agent_owner_inactive",
        "agent_owner_cannot_decide"
      ],
      "description": "Why a route that asks the agent's owner went to its fallback path when the request arrived. `no_agent_owner`: a service agent made it. `agent_owner_inactive`: the owner was suspended or removed. `agent_owner_cannot_decide`: the owner may not decide requests."
    },
    "agent_owner_handed_off_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the agent's owner was suspended or removed and the fallback path took over the request. Present for `agent_owner` only."
    },
    "targets": {
      "type": "array",
      "description": "Who may claim or decide the request. For `agent_owner`, the owner alone until a handoff. Otherwise the people and teams the pinned path reaches for this request, in path order: the levels whose request conditions hold for it, plus both branches of any working-hours or urgency test, at every level regardless of timing. Only these people, and `added_reviewers`, may claim or decide. Empty for `default_queue`. Empty for `escalated` means the path reaches nobody for this request and only a break-glass reviewer may decide it.",
      "items": {
        "$ref": "#/$defs/ApprovalRoutingTarget"
      }
    },
    "added_reviewers": {
      "type": "array",
      "description": "People added to the request's routing after the snapshot was pinned, oldest first.",
      "items": {
        "$ref": "#/$defs/ApprovalReviewer"
      }
    },
    "team_policies": {
      "type": "array",
      "description": "The team escalation policy revisions pinned beside the path, one per team the path reaches for this request that had an active policy at routing time. A team absent here is notified all at once when a level reaches it. Empty for `default_queue`.",
      "items": {
        "$ref": "#/$defs/PinnedTeamPolicy"
      }
    },
    "escalation": {
      "description": "The escalation executor's current position. Null before its first tick and for `default_queue`.",
      "oneOf": [
        {
          "$ref": "#/$defs/EscalationProgress"
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the request entered human review."
    }
  },
  "$defs": {
    "ApprovalReviewer": {
      "type": "object",
      "additionalProperties": false,
      "description": "A person pulled into a pending request's routing after the fact by someone it was routed to.",
      "required": [
        "membership_id",
        "display_name",
        "added_by_membership_id",
        "added_by_display_name",
        "created_at"
      ],
      "properties": {
        "membership_id": {
          "type": "string",
          "format": "uuid"
        },
        "display_name": {
          "type": "string"
        },
        "added_by_membership_id": {
          "type": "string",
          "format": "uuid"
        },
        "added_by_display_name": {
          "type": "string"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "ApprovalRoutingTarget": {
      "type": "object",
      "additionalProperties": false,
      "description": "One person or team the pinned path reaches for the request.",
      "required": [
        "type",
        "id",
        "name"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "user",
            "team"
          ],
          "description": "`user` names a membership, `team` a team."
        },
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string",
          "description": "The person's display name or the team's name."
        }
      }
    },
    "EscalationPhase": {
      "type": "string",
      "enum": [
        "level",
        "deferred",
        "repeat_wait",
        "paused",
        "exhausted"
      ],
      "description": "Where a walker stands. `level`: a level is notified and its timer armed. `deferred`: waiting for a working hours window to open. `repeat_wait`: the program ran out and is waiting to repeat. `paused`: a claim holds escalation still. `exhausted`: nothing left to do."
    },
    "EscalationProgress": {
      "type": "object",
      "additionalProperties": false,
      "description": "Where the escalation machine stands after its latest tick. The organization path's walker is flattened onto the object; teams carries one entry per team policy running inline.",
      "required": [
        "sequence",
        "phase",
        "urgency",
        "level_ordinal",
        "level_count",
        "repeat",
        "updated_at",
        "teams"
      ],
      "properties": {
        "sequence": {
          "type": "integer",
          "format": "int64",
          "description": "Monotonic tick counter; a later tick always carries a higher value."
        },
        "phase": {
          "$ref": "#/$defs/EscalationPhase"
        },
        "urgency": {
          "type": "string",
          "enum": [
            "standard",
            "interrupt"
          ],
          "description": "The request's current urgency, raised by a level that asked to."
        },
        "current_node_id": {
          "type": "string",
          "format": "uuid",
          "description": "The path node the walker stands on; absent once exhausted."
        },
        "level_ordinal": {
          "type": "integer",
          "description": "1-based position of the current level in walk order; 0 before the first level."
        },
        "level_count": {
          "type": "integer",
          "description": "Level nodes in the path document."
        },
        "repeat": {
          "type": "integer",
          "description": "How many times the path has been repeated so far."
        },
        "next_escalation_at": {
          "type": "string",
          "format": "date-time",
          "description": "When the path walker's armed timer fires; absent while paused, exhausted, or waiting on nothing."
        },
        "updated_at": {
          "type": "string",
          "format": "date-time"
        },
        "teams": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/EscalationWalkerProgress"
          }
        }
      }
    },
    "EscalationWalkerProgress": {
      "type": "object",
      "additionalProperties": false,
      "description": "One team policy walker's position while its policy runs inline.",
      "required": [
        "team_id",
        "phase",
        "level_ordinal",
        "level_count",
        "repeat"
      ],
      "properties": {
        "team_id": {
          "type": "string",
          "format": "uuid"
        },
        "phase": {
          "$ref": "#/$defs/EscalationPhase"
        },
        "current_node_id": {
          "type": "string",
          "format": "uuid",
          "description": "The node the walker stands on; absent once exhausted."
        },
        "level_ordinal": {
          "type": "integer",
          "description": "1-based position of the current level in walk order; 0 before the first level."
        },
        "level_count": {
          "type": "integer",
          "description": "Level nodes in the document."
        },
        "repeat": {
          "type": "integer",
          "description": "How many times the program has been repeated so far."
        },
        "next_escalation_at": {
          "type": "string",
          "format": "date-time",
          "description": "When the armed timer fires; absent while paused, exhausted, or waiting on nothing."
        }
      }
    },
    "PinnedTeamPolicy": {
      "type": "object",
      "additionalProperties": false,
      "description": "One team escalation policy revision an escalated request runs inline when its pinned path reaches the team.",
      "required": [
        "team_id",
        "team_name",
        "policy_revision_id",
        "revision"
      ],
      "properties": {
        "team_id": {
          "type": "string",
          "format": "uuid"
        },
        "team_name": {
          "type": "string"
        },
        "policy_revision_id": {
          "type": "string",
          "format": "uuid"
        },
        "revision": {
          "type": "integer",
          "format": "int64",
          "minimum": 1
        }
      }
    }
  }
}