{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/codai-ro/json-schema/codai-ro-sandbox-exec-event-schema.json",
  "title": "Exec stream event",
  "description": "One SSE `data:` frame of an exec stream. The stream ends after `exit` or `error`.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/codai-ro-sandboxes-api-openapi.yml#/components/schemas/SandboxExecEvent",
  "oneOf": [
    {
      "type": "object",
      "title": "start",
      "required": [
        "type",
        "exec_id",
        "instance",
        "restored",
        "restore_ms"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "start"
          ]
        },
        "exec_id": {
          "type": "string"
        },
        "instance": {
          "type": "string"
        },
        "restored": {
          "type": "string",
          "enum": [
            "hot",
            "gcs",
            "empty"
          ]
        },
        "restore_ms": {
          "type": "integer"
        }
      }
    },
    {
      "type": "object",
      "title": "output",
      "required": [
        "type",
        "data"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "stdout",
            "stderr"
          ]
        },
        "data": {
          "type": "string"
        }
      }
    },
    {
      "type": "object",
      "title": "truncated",
      "required": [
        "type",
        "stream"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "truncated"
          ]
        },
        "stream": {
          "type": "string",
          "enum": [
            "stdout",
            "stderr"
          ]
        }
      }
    },
    {
      "type": "object",
      "title": "exit",
      "required": [
        "type",
        "exit_code",
        "timed_out",
        "duration_ms",
        "cpu_ms",
        "generation",
        "workspace_bytes",
        "changed",
        "receipt"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "exit"
          ]
        },
        "exit_code": {
          "type": [
            "integer",
            "null"
          ],
          "description": "The command's own exit status; `128 + n` when it was ended by signal `n`. `null` only when the exec timed out (`timed_out: true`) or the process could not be started."
        },
        "timed_out": {
          "type": "boolean"
        },
        "duration_ms": {
          "type": "integer"
        },
        "cpu_ms": {
          "type": "integer"
        },
        "generation": {
          "type": "integer"
        },
        "workspace_bytes": {
          "type": "integer"
        },
        "changed": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "receipt": {
          "$ref": "#/$defs/SandboxReceipt"
        }
      }
    },
    {
      "type": "object",
      "title": "error",
      "required": [
        "type",
        "code",
        "message"
      ],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "error"
          ]
        },
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        }
      }
    }
  ],
  "$defs": {
    "SandboxReceipt": {
      "title": "Reproducibility receipt",
      "description": "What ran and what it produced: image digest, hashes of the inputs and the command, every output file with its SHA-256, and the workspace generations before and after.",
      "type": "object",
      "required": [
        "image_digest",
        "template",
        "input_sha256",
        "command_sha256",
        "outputs",
        "generation_before",
        "generation_after"
      ],
      "properties": {
        "image_digest": {
          "type": "string"
        },
        "template": {
          "type": "string"
        },
        "input_sha256": {
          "type": "string"
        },
        "command_sha256": {
          "type": "string"
        },
        "outputs": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "path",
              "sha256",
              "bytes"
            ],
            "properties": {
              "path": {
                "type": "string"
              },
              "sha256": {
                "type": "string"
              },
              "bytes": {
                "type": "integer"
              }
            }
          }
        },
        "generation_before": {
          "type": "integer"
        },
        "generation_after": {
          "type": "integer"
        }
      }
    }
  }
}