{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/shardflux-dev/json-schema/shardflux-dev-operation-schema.json",
  "title": "Operation",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/shardflux-dev-openapi.json#/components/schemas/Operation",
  "type": "object",
  "required": [
    "id",
    "kind",
    "state",
    "workspace_id",
    "created_at",
    "updated_at"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "UUIDv7, lowercase canonical form."
    },
    "kind": {
      "type": "string",
      "enum": [
        "open",
        "suspend",
        "resume",
        "fork",
        "snapshot",
        "restore",
        "delete",
        "move",
        "resize",
        "upgrade",
        "volume_create",
        "volume_attach",
        "volume_detach",
        "volume_delete",
        "reset",
        "layer_snapshot"
      ]
    },
    "state": {
      "type": "string",
      "enum": [
        "queued",
        "capacity_pending",
        "running",
        "succeeded",
        "failed",
        "canceled"
      ]
    },
    "workspace_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid",
          "description": "UUIDv7, lowercase canonical form."
        },
        {
          "type": "null"
        }
      ]
    },
    "volume_id": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid",
          "description": "UUIDv7, lowercase canonical form."
        },
        {
          "type": "null"
        }
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "description": "RFC 3339 UTC timestamp with Z."
    },
    "updated_at": {
      "type": "string",
      "format": "date-time",
      "description": "RFC 3339 UTC timestamp with Z."
    },
    "started_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time",
          "description": "RFC 3339 UTC timestamp with Z."
        },
        {
          "type": "null"
        }
      ],
      "description": "When the cell started executing the operation: set once, in the transaction that first moves it to `running`, and never changed afterwards (it stays set if the operation later returns to `capacity_pending`, e.g. when a host rejects the start). null while the operation is `queued`, or `capacity_pending` before it ever ran, and on an operation canceled before it started. An operation the cell finishes without running it (e.g. `dependency_failed`) gets started_at = completed_at. created_at to started_at is the time queued; started_at to completed_at the time running."
    },
    "completed_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time",
          "description": "RFC 3339 UTC timestamp with Z."
        },
        {
          "type": "null"
        }
      ]
    },
    "state_reason": {
      "anyOf": [
        {
          "type": "string",
          "description": "Closed reason code while waiting (e.g. capacity_pending: no_ready_host)."
        },
        {
          "type": "null"
        }
      ]
    },
    "input": {
      "type": "object",
      "properties": {},
      "additionalProperties": true
    },
    "error": {
      "type": "object",
      "properties": {},
      "additionalProperties": true
    },
    "result": {
      "type": "object",
      "properties": {
        "durable": {
          "type": "boolean",
          "description": "suspend and fork: whether the capture is in durable storage. false while `durability.state` is pending (the suspend completed on its host) or lost; true once it committed. Absent on other kinds."
        },
        "suspend_path": {
          "type": "string",
          "description": "suspend: `local_commit` when the suspend completed on its host and the durable copy followed in the background."
        },
        "durability": {
          "type": "object",
          "required": [
            "state"
          ],
          "properties": {
            "state": {
              "type": "string",
              "enum": [
                "pending",
                "durable",
                "lost"
              ],
              "description": "pending: sealed on its host, the durable copy is being written; durable: the copy committed; lost: the copy could not be made and the previous recovery point stays current."
            },
            "checkpoint_id": {
              "type": "string",
              "description": "The checkpoint being made durable."
            },
            "generation_id": {
              "type": "string",
              "description": "Its generation on the host."
            },
            "local_commit_at": {
              "type": "string",
              "description": "RFC 3339: when the suspend (or fork) completed on its host."
            },
            "durable_by": {
              "type": "string",
              "description": "RFC 3339: when the durable copy is expected to have committed (local_commit_at + the deadline)."
            },
            "durable_at": {
              "type": "string",
              "description": "RFC 3339 (state durable): when the durable copy committed."
            },
            "local_commit_to_durable_ms": {
              "type": "number",
              "description": "State durable: local_commit_at to durable_at, in milliseconds."
            },
            "overdue_at": {
              "type": "string",
              "description": "RFC 3339: set once durable_by passed while the copy was still pending; it keeps retrying."
            },
            "reason": {
              "type": "string",
              "description": "State lost: why, e.g. host_lost."
            },
            "code": {
              "type": "string",
              "description": "State lost: the error code of the failed copy."
            },
            "recovery_point_checkpoint_id": {
              "anyOf": [
                {
                  "type": "string",
                  "description": "State lost: the durable checkpoint that stays the recovery point (null when there is none)."
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "additionalProperties": true
        },
        "lost_suspend": {
          "type": "object",
          "required": [
            "checkpoint_id"
          ],
          "properties": {
            "checkpoint_id": {
              "type": "string",
              "description": "The suspend checkpoint whose durable copy was lost."
            },
            "generation_id": {
              "type": "string",
              "description": "Its generation on the host."
            },
            "reason": {
              "type": "string",
              "description": "Why it was lost, e.g. host_lost."
            },
            "suspended_at": {
              "type": "string",
              "description": "RFC 3339: when that suspend captured the workspace."
            },
            "restored_checkpoint_id": {
              "type": "string",
              "description": "The earlier durable checkpoint this resume restored."
            },
            "state_as_of": {
              "type": "string",
              "description": "RFC 3339: when the restored checkpoint committed; the workspace state is as of then."
            }
          },
          "additionalProperties": true
        },
        "host_lost": {
          "type": "object",
          "required": [
            "detected_at"
          ],
          "properties": {
            "detected_at": {
              "type": "string",
              "description": "RFC 3339: when the host failure was detected; the workspace was suspended then."
            },
            "restored_from": {
              "type": "string",
              "enum": [
                "disk",
                "checkpoint"
              ],
              "description": "resume and open: disk when the workspace booted from its disk (files kept, processes and memory not); checkpoint when it was restored from its newest checkpoint (see state_as_of). Absent on a suspend."
            },
            "restored_checkpoint_id": {
              "type": "string",
              "description": "restored_from checkpoint: the checkpoint this resume restored."
            },
            "state_as_of": {
              "type": "string",
              "description": "restored_from checkpoint, RFC 3339: when that checkpoint committed; the workspace state is as of then."
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    },
    "progress": {
      "$ref": "#/$defs/SuspendProgress"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "SuspendProgress": {
      "type": "object",
      "required": [
        "operation_id",
        "state",
        "workspace_state",
        "phase",
        "cancelable",
        "supported",
        "safe_action"
      ],
      "properties": {
        "operation_id": {
          "type": "string",
          "format": "uuid",
          "description": "UUIDv7, lowercase canonical form."
        },
        "state": {
          "type": "string",
          "enum": [
            "queued",
            "capacity_pending",
            "running",
            "succeeded",
            "failed",
            "canceled"
          ]
        },
        "workspace_state": {
          "type": "string",
          "enum": [
            "creating",
            "starting",
            "running",
            "suspending",
            "suspended",
            "resuming",
            "forking",
            "stopping",
            "failed",
            "deleting",
            "deleted"
          ]
        },
        "phase": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "pattern": "^[a-z][a-z0-9_]*$",
          "description": "Actual snapshot preparation/capture phase, or an explicitly unavailable control status."
        },
        "cancelable": {
          "type": "boolean",
          "description": "True only while the host can acknowledge cancellation before its capture cut."
        },
        "supported": {
          "type": "boolean"
        },
        "safe_action": {
          "type": "string",
          "enum": [
            "wait_for_terminal",
            "resume",
            "retry_tools",
            "inspect_failure"
          ]
        },
        "phase_started_at": {
          "type": "string",
          "format": "date-time",
          "description": "RFC 3339 UTC timestamp with Z."
        },
        "deadline_at": {
          "type": "string",
          "format": "date-time",
          "description": "RFC 3339 UTC timestamp with Z."
        },
        "accepted": {
          "type": "boolean"
        }
      },
      "additionalProperties": false
    }
  }
}