{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/mobilerun-ai/json-schema/mobilerun-ai-flow-execution-detail-schema.json",
  "title": "FlowExecutionDetail",
  "x-generated": "2026-11-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/mobilerun-ai-openapi.json#/components/schemas/FlowExecutionDetail",
  "allOf": [
    {
      "$ref": "#/$defs/FlowExecution"
    },
    {
      "type": "object",
      "properties": {
        "createdBy": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "agentId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Current agent assignment of the owner-scoped parent flow; null when unassigned."
        },
        "recordings": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "flowActionId": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              },
              "stepIndex": {
                "type": "integer"
              },
              "parentIndex": {
                "type": "integer"
              },
              "iterationIndex": {
                "type": "integer"
              },
              "childIndex": {
                "type": "integer"
              },
              "attempt": {
                "type": "integer",
                "minimum": 0
              },
              "scope": {
                "type": "string",
                "enum": [
                  "flow",
                  "step"
                ]
              },
              "status": {
                "type": "string",
                "enum": [
                  "starting",
                  "recording",
                  "stopping",
                  "stopped",
                  "failed"
                ]
              },
              "recordingId": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              },
              "recordingDeviceId": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "uuid"
              },
              "startedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "stoppedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "lastError": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "flowActionId",
              "stepIndex",
              "parentIndex",
              "iterationIndex",
              "childIndex",
              "attempt",
              "scope",
              "status",
              "recordingId",
              "recordingDeviceId",
              "startedAt",
              "stoppedAt",
              "lastError"
            ]
          },
          "description": "Durable recording segments ordered by step/loop coordinate and retry attempt. Whole-flow recordings use -1 for every coordinate."
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ExecutionFile"
          },
          "description": "Files produced by files.upload steps, plus files an agent.run step reported on its terminal response (agent-created output or a workflow upload minted during the turn); derived server-side at read time."
        },
        "progress": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "total": {
              "type": "integer"
            },
            "currentIndex": {
              "type": [
                "integer",
                "null"
              ]
            },
            "steps": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "index": {
                    "type": "integer"
                  },
                  "name": {
                    "type": "string"
                  },
                  "service": {
                    "type": "string"
                  },
                  "method": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "pending",
                      "running",
                      "success",
                      "failed",
                      "skipped",
                      "cancelled"
                    ]
                  },
                  "attempt": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Zero-based retry attempt of the execution job during which this step last ran (0 = initial attempt). Not a per-step retry counter; may undercount after crash recovery."
                  },
                  "startedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "finishedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time"
                  },
                  "sessionId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "index",
                  "name",
                  "service",
                  "method",
                  "status",
                  "startedAt",
                  "finishedAt",
                  "sessionId"
                ]
              }
            }
          },
          "required": [
            "total",
            "currentIndex",
            "steps"
          ],
          "description": "Live progress; null for runs started before this feature."
        },
        "deliveries": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "artifact": {
                "type": "string",
                "enum": [
                  "recording",
                  "file",
                  "screenshot"
                ]
              },
              "stepIndex": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "destination": {
                "type": "string",
                "enum": [
                  "mobilerun",
                  "one_drive",
                  "google_drive"
                ]
              },
              "folder": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "filename": {
                "type": "string"
              },
              "status": {
                "type": "string",
                "enum": [
                  "waiting",
                  "uploading",
                  "succeeded",
                  "failed",
                  "unknown",
                  "cancelled"
                ]
              },
              "errorCode": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "webUrl": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "startedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "finishedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            },
            "required": [
              "artifact",
              "stepIndex",
              "destination",
              "folder",
              "filename",
              "status",
              "errorCode",
              "webUrl",
              "startedAt",
              "finishedAt"
            ]
          },
          "description": "OneDrive/Google Drive delivery lifecycle for this run's recording, file, and screenshot uploads, ordered by startedAt. Empty when the flow has no delivery configured."
        },
        "screenshots": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "source": {
                "type": "string",
                "enum": [
                  "task",
                  "agent",
                  "recording"
                ]
              },
              "stepName": {
                "type": "string"
              },
              "stepIndex": {
                "type": "integer"
              },
              "iterationIndex": {
                "type": "integer"
              },
              "seq": {
                "type": "integer"
              },
              "capturedAt": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "mimeType": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "source",
              "stepName",
              "stepIndex",
              "iterationIndex",
              "seq",
              "capturedAt",
              "mimeType"
            ]
          },
          "description": "Screenshots captured by tasks.run/agent.run steps and saved by scripts into the flow screenshots recording (source recording), ordered by seq. Image bytes are never returned here — fetch a fresh signed URL via GET /executions/{id}/screenshots/{screenshotId}."
        },
        "repair": {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "episode": {
              "type": "integer",
              "exclusiveMinimum": 0
            },
            "status": {
              "type": "string",
              "enum": [
                "pending",
                "running",
                "canary",
                "promoting",
                "repaired",
                "failed",
                "escalated"
              ]
            },
            "verdict": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "outcome": {
                  "type": "string",
                  "enum": [
                    "ok",
                    "flaky",
                    "broken"
                  ]
                },
                "summary": {
                  "type": "string"
                },
                "reason": {
                  "type": "string"
                }
              },
              "required": [
                "outcome",
                "summary"
              ]
            },
            "chatSessionId": {
              "type": [
                "string",
                "null"
              ],
              "format": "uuid"
            },
            "episodeId": {
              "type": "string",
              "format": "uuid"
            },
            "terminal": {
              "type": "boolean"
            }
          },
          "required": [
            "episode",
            "status",
            "verdict",
            "chatSessionId",
            "episodeId",
            "terminal"
          ]
        }
      },
      "required": [
        "createdBy",
        "agentId",
        "recordings",
        "files",
        "progress",
        "deliveries",
        "screenshots",
        "repair"
      ]
    }
  ],
  "$defs": {
    "ExecutionFile": {
      "type": "object",
      "properties": {
        "fileId": {
          "type": "string",
          "format": "uuid"
        },
        "filename": {
          "type": "string"
        },
        "mimeType": {
          "type": "string"
        },
        "sizeBytes": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "fileId",
        "filename",
        "mimeType",
        "sizeBytes"
      ]
    },
    "FlowExecution": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "flowId": {
          "type": "string",
          "format": "uuid"
        },
        "triggerId": {
          "type": "string",
          "format": "uuid"
        },
        "eventId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "invocationId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Client/verify invocation key this row belongs to. Set on live custom fires (one row per device fan-out) and on verification runs; null for event/schedule live rows."
        },
        "deviceId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Device this execution targets (the job's deviceId). Null for device-less (event-only) runs."
        },
        "flowName": {
          "type": [
            "string",
            "null"
          ]
        },
        "triggerName": {
          "type": [
            "string",
            "null"
          ]
        },
        "status": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "pending",
            "running",
            "success",
            "failed",
            "cancelled",
            "skipped",
            "invalid",
            null
          ]
        },
        "kind": {
          "type": "string",
          "enum": [
            "live",
            "dry_run",
            "verification"
          ]
        },
        "result": {
          "description": "Opaque per-step result blob ({ steps: [...] }). Each step additionally carries a `verdict` field ({ outcome, summary, reason? } | null) when it is an agent.run step that opted into a verdict — null otherwise. Steps of current executions also carry a `status` string (e.g. success/failed/stopped); it is optional and absent on older executions, so clients must not assume its presence."
        },
        "error": {
          "type": [
            "string",
            "null"
          ]
        },
        "recordingId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Device recording id for this execution, set once recording starts. Null when the flow has recording disabled, no device is bound, or the recording failed to start."
        },
        "recordingDeviceId": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "startedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "finishedAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      },
      "required": [
        "id",
        "flowId",
        "triggerId",
        "eventId",
        "invocationId",
        "deviceId",
        "flowName",
        "triggerName",
        "status",
        "kind",
        "error",
        "recordingId",
        "recordingDeviceId",
        "startedAt",
        "finishedAt"
      ]
    }
  }
}