{
  "components": {
    "schemas": {
      "AcceptInviteRequest": {
        "properties": {
          "token": {
            "type": "string"
          }
        },
        "required": [
          "token"
        ],
        "type": "object"
      },
      "AcceptInviteResponse": {
        "properties": {
          "reset_token": {
            "example": "reset-token-value",
            "type": "string"
          },
          "reset_token_ttl_minutes": {
            "example": 30,
            "format": "int64",
            "type": "integer"
          },
          "role_id": {
            "example": "00000000-0000-0000-0000-00000000dddd",
            "format": "uuid",
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "target_email": {
            "description": "Email address bound to the accepted workspace invite.",
            "example": "invitee@example.com",
            "type": "string"
          },
          "tenant_id": {
            "example": "00000000-0000-0000-0000-00000000aaaa",
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "status",
          "reset_token",
          "reset_token_ttl_minutes",
          "target_email",
          "tenant_id",
          "role_id"
        ],
        "type": "object"
      },
      "AcceptProjectInviteRequest": {
        "properties": {
          "token": {
            "type": "string"
          }
        },
        "required": [
          "token"
        ],
        "type": "object"
      },
      "AcceptProjectInviteResponse": {
        "properties": {
          "project_id": {
            "example": "00000000-0000-0000-0000-00000000bbbb",
            "format": "uuid",
            "type": "string"
          },
          "project_name": {
            "example": "Project Alpha",
            "type": "string"
          },
          "reset_token": {
            "example": "reset-token-value",
            "type": "string"
          },
          "reset_token_ttl_minutes": {
            "example": 30,
            "format": "int64",
            "type": "integer"
          },
          "role_id": {
            "example": "00000000-0000-0000-0000-00000000dddd",
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "example": "Project Guest",
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "target_email": {
            "description": "Email address bound to the accepted project invite.",
            "example": "invitee@example.com",
            "type": "string"
          },
          "tenant_id": {
            "example": "00000000-0000-0000-0000-00000000aaaa",
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "status",
          "reset_token",
          "reset_token_ttl_minutes",
          "role_id",
          "role_name",
          "project_name",
          "target_email",
          "tenant_id",
          "project_id"
        ],
        "type": "object"
      },
      "ActivateTenantRequest": {
        "properties": {
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id"
        ],
        "type": "object"
      },
      "ActivateTenantResponse": {
        "properties": {
          "expires_in_secs": {
            "format": "int64",
            "type": "integer"
          },
          "permissions": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "uniqueItems": true
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "tenant_name": {
            "type": "string"
          },
          "token": {
            "type": "string"
          }
        },
        "required": [
          "token",
          "tenant_id",
          "tenant_name",
          "role_id",
          "role_name",
          "permissions",
          "expires_in_secs"
        ],
        "type": "object"
      },
      "ActivityAction": {
        "enum": [
          "CREATED",
          "UPDATED",
          "ASSIGNED",
          "LABELS_ADDED",
          "LABELS_REMOVED",
          "RELATION_ADDED",
          "RELATION_REMOVED",
          "COMMENT_ADDED",
          "DELETED",
          "RESTORED",
          "CUSTOM"
        ],
        "type": "string"
      },
      "ActivityEventResponse": {
        "properties": {
          "action": {
            "$ref": "#/components/schemas/ActivityAction"
          },
          "actor_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "payload": {},
          "request_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "resource_id": {
            "format": "uuid",
            "type": "string"
          },
          "resource_kind": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "resource_kind",
          "resource_id",
          "action",
          "created_at"
        ],
        "type": "object"
      },
      "AgentCodexPolicyResponse": {
        "properties": {
          "command": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "environment_allowlist": {
            "items": {
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "command",
          "environment_allowlist"
        ],
        "type": "object"
      },
      "AgentExecutionManifestResponse": {
        "properties": {
          "attachments": {
            "items": {
              "$ref": "#/components/schemas/AttachmentResponse"
            },
            "type": "array"
          },
          "clone_url": {
            "format": "uri",
            "type": "string"
          },
          "default_branch": {
            "type": [
              "string",
              "null"
            ]
          },
          "execution_policy": {
            "$ref": "#/components/schemas/AgentExecutionPolicyResponse"
          },
          "execution_policy_sha256": {
            "pattern": "^[0-9a-f]{64}$",
            "type": "string"
          },
          "installation_id": {
            "format": "int64",
            "type": "integer"
          },
          "manifest_version": {
            "format": "int32",
            "type": "integer"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "project_key": {
            "type": "string"
          },
          "project_name": {
            "type": "string"
          },
          "repository": {
            "type": "string"
          },
          "repository_id": {
            "format": "int64",
            "type": "integer"
          },
          "required_permissions": {
            "additionalProperties": true,
            "type": "object"
          },
          "required_workflows": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "run": {
            "$ref": "#/components/schemas/AgentRunResponse"
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "ticket_key": {
            "type": "string"
          },
          "ticket_title": {
            "type": "string"
          },
          "web_base_url": {
            "format": "uri",
            "type": "string"
          }
        },
        "required": [
          "manifest_version",
          "run",
          "attachments",
          "project_id",
          "project_key",
          "project_name",
          "ticket_id",
          "ticket_key",
          "ticket_title",
          "repository_id",
          "repository",
          "clone_url",
          "web_base_url",
          "installation_id",
          "required_workflows",
          "required_permissions",
          "execution_policy",
          "execution_policy_sha256"
        ],
        "type": "object"
      },
      "AgentExecutionPolicyResponse": {
        "properties": {
          "codex": {
            "$ref": "#/components/schemas/AgentCodexPolicyResponse"
          },
          "policy_version": {
            "format": "int32",
            "type": "integer"
          },
          "quality_gates": {
            "items": {
              "$ref": "#/components/schemas/AgentQualityGatePolicyResponse"
            },
            "type": "array"
          },
          "sandbox": {
            "$ref": "#/components/schemas/AgentSandboxPolicyResponse"
          },
          "timeout_seconds": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "policy_version",
          "codex",
          "quality_gates",
          "timeout_seconds",
          "sandbox"
        ],
        "type": "object"
      },
      "AgentGithubTokenResponse": {
        "properties": {
          "expires_at": {
            "format": "date-time",
            "type": "string"
          },
          "permissions": {
            "additionalProperties": true,
            "type": "object"
          },
          "repository": {
            "type": "string"
          },
          "token": {
            "description": "Secret returned once. Never persisted by RustGrid.",
            "type": "string",
            "writeOnly": true
          }
        },
        "required": [
          "token",
          "expires_at",
          "permissions",
          "repository"
        ],
        "type": "object"
      },
      "AgentModelOptionsResponse": {
        "properties": {
          "default_model": {
            "type": [
              "string",
              "null"
            ]
          },
          "models": {
            "items": {
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "default_model",
          "models"
        ],
        "type": "object"
      },
      "AgentPullRequestDiscardResponse": {
        "properties": {
          "message": {
            "type": "string"
          },
          "pull_request_number": {
            "format": "int64",
            "type": "integer"
          },
          "pull_request_url": {
            "format": "uri",
            "type": "string"
          },
          "repository": {
            "type": "string"
          },
          "state": {
            "type": "string"
          }
        },
        "required": [
          "repository",
          "pull_request_number",
          "pull_request_url",
          "state",
          "message"
        ],
        "type": "object"
      },
      "AgentPullRequestMergeResponse": {
        "properties": {
          "merged": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          },
          "pull_request_number": {
            "format": "int64",
            "type": "integer"
          },
          "pull_request_url": {
            "format": "uri",
            "type": "string"
          },
          "repository": {
            "type": "string"
          },
          "sha": {
            "type": "string"
          }
        },
        "required": [
          "repository",
          "pull_request_number",
          "pull_request_url",
          "sha",
          "merged",
          "message"
        ],
        "type": "object"
      },
      "AgentPullRequestStatusResponse": {
        "properties": {
          "draft": {
            "type": "boolean"
          },
          "mergeable": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "merged": {
            "type": "boolean"
          },
          "pull_request_number": {
            "format": "int64",
            "type": "integer"
          },
          "pull_request_url": {
            "format": "uri",
            "type": "string"
          },
          "repository": {
            "type": "string"
          },
          "state": {
            "enum": [
              "open",
              "closed",
              "merged"
            ],
            "type": "string"
          }
        },
        "required": [
          "repository",
          "pull_request_number",
          "pull_request_url",
          "state",
          "merged",
          "draft"
        ],
        "type": "object"
      },
      "AgentQualityGatePolicyResponse": {
        "properties": {
          "command": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "required": {
            "type": "boolean"
          },
          "timeout_seconds": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "id",
          "command",
          "timeout_seconds",
          "required"
        ],
        "type": "object"
      },
      "AgentQueueEventResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "data": {
            "additionalProperties": true,
            "type": "object"
          },
          "event_type": {
            "enum": [
              "work_available",
              "work_claimed",
              "work_requeued",
              "capacity_available",
              "capacity_changed"
            ],
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "run_id": {
            "format": "uuid",
            "nullable": true,
            "type": [
              "string",
              "null"
            ]
          },
          "sequence": {
            "format": "int64",
            "type": "integer"
          },
          "ticket_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "worker_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "sequence",
          "event_type",
          "data",
          "created_at"
        ],
        "type": "object"
      },
      "AgentQueueEventsResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/AgentQueueEventResponse"
            },
            "type": "array"
          },
          "next_sequence": {
            "format": "int64",
            "type": "integer"
          },
          "worker": {
            "$ref": "#/components/schemas/AgentWorkerResponse"
          }
        },
        "required": [
          "worker",
          "items",
          "next_sequence"
        ],
        "type": "object"
      },
      "AgentRunEventResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "data": {
            "additionalProperties": true,
            "type": "object"
          },
          "event_type": {
            "type": "string"
          },
          "run_id": {
            "format": "uuid",
            "type": "string"
          },
          "sequence": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "sequence",
          "run_id",
          "event_type",
          "data",
          "created_at"
        ],
        "type": "object"
      },
      "AgentRunEventsResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/AgentRunEventResponse"
            },
            "type": "array"
          },
          "next_sequence": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "next_sequence"
        ],
        "type": "object"
      },
      "AgentRunPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/AgentRunResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "AgentRunResponse": {
        "properties": {
          "attempt": {
            "format": "int32",
            "type": "integer"
          },
          "claim_expires_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "claim_released_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "claimed_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "ended_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "error_message": {
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "input_prompt": {
            "type": "string"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object"
          },
          "output_summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "started_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed",
              "cancelled"
            ],
            "type": "string"
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          },
          "worker_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "ticket_id",
          "status",
          "attempt",
          "input_prompt",
          "metadata",
          "created_at",
          "updated_at",
          "row_version"
        ],
        "type": "object"
      },
      "AgentRunStepPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/AgentRunStepResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "AgentRunStepResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "run_id": {
            "format": "uuid",
            "type": "string"
          },
          "status": {
            "enum": [
              "pending",
              "running",
              "completed",
              "failed"
            ],
            "type": "string"
          },
          "step_key": {
            "type": "string"
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "run_id",
          "step_key",
          "title",
          "status",
          "metadata",
          "created_at",
          "updated_at",
          "row_version"
        ],
        "type": "object"
      },
      "AgentRunTokenConsumptionResponse": {
        "properties": {
          "cached_input_tokens": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "input_tokens": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "output_tokens": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "provider": {
            "type": "string"
          },
          "run_id": {
            "format": "uuid",
            "type": "string"
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "total_tokens": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "run_id",
          "ticket_id",
          "provider",
          "input_tokens",
          "cached_input_tokens",
          "output_tokens",
          "total_tokens",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "AgentSandboxPolicyResponse": {
        "properties": {
          "approval_policy": {
            "enum": [
              "never",
              "on_request"
            ],
            "type": "string"
          },
          "mode": {
            "enum": [
              "read_only",
              "workspace_write"
            ],
            "type": "string"
          },
          "network_access": {
            "type": "boolean"
          },
          "writable_roots": {
            "items": {
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "mode",
          "network_access",
          "writable_roots",
          "approval_policy"
        ],
        "type": "object"
      },
      "AgentWorkerCredentialResponse": {
        "properties": {
          "api_key_id": {
            "format": "uuid",
            "type": "string"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "created_by": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "credential_prefix": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "credential_version": {
            "format": "int32",
            "minimum": 1,
            "type": "integer"
          },
          "expires_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "installation_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "label": {
            "type": "string"
          },
          "last_used_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "revocation_reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "revoked_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "revoked_by": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "worker_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "id",
          "worker_id",
          "api_key_id",
          "label",
          "created_at",
          "installation_id",
          "credential_version",
          "expires_at",
          "credential_prefix",
          "last_used_at",
          "revocation_reason"
        ],
        "type": "object"
      },
      "AgentWorkerResponse": {
        "properties": {
          "active_runs": {
            "format": "int64",
            "type": "integer"
          },
          "agent_version": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "architecture": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "available_slots": {
            "format": "int64",
            "type": "integer"
          },
          "capabilities": {
            "items": {},
            "type": "array"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "hostname": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "installation_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "kind": {
            "type": "string"
          },
          "last_seen_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "linked_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "linked_by": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "max_concurrency": {
            "format": "int32",
            "maximum": 100,
            "minimum": 1,
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "operating_system": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "enum": [
              "offline",
              "online",
              "busy",
              "disabled",
              "active",
              "revoked",
              "pending_upgrade"
            ],
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "kind",
          "capabilities",
          "status",
          "max_concurrency",
          "active_runs",
          "available_slots",
          "created_at",
          "updated_at",
          "installation_id",
          "hostname",
          "operating_system",
          "architecture",
          "agent_version",
          "linked_by",
          "linked_at"
        ],
        "type": "object"
      },
      "AgentWorkerRunPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/AgentWorkerRunResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "AgentWorkerRunResponse": {
        "properties": {
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "status": {
            "enum": [
              "running"
            ],
            "type": "string"
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "worker_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "id",
          "ticket_id",
          "project_id",
          "worker_id",
          "status",
          "row_version"
        ],
        "type": "object"
      },
      "AgentWorkersResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/AgentWorkerResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "items"
        ],
        "type": "object"
      },
      "ApiKeyResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "created_by_user_id": {
            "format": "uuid",
            "type": "string"
          },
          "expires_at": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "key_prefix": {
            "description": "Stable lookup prefix. The full API key is shown only once at creation time.",
            "type": "string"
          },
          "last_used_at": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "nullable": true,
            "type": "string"
          },
          "revoked_at": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "revoked_by": {
            "format": "uuid",
            "nullable": true,
            "type": "string"
          },
          "scope_version": {
            "description": "Monotonic version incremented whenever server-side scopes are replaced.",
            "format": "int32",
            "type": "integer"
          },
          "scopes": {
            "description": "Editable server-side API key scopes. The key secret never encodes scopes.",
            "items": {
              "enum": [
                "tickets:read",
                "tickets:write",
                "tickets:delete",
                "projects:read",
                "projects:write",
                "webhooks:read",
                "webhooks:write",
                "api_keys:read",
                "api_keys:write",
                "api_keys:create",
                "api_keys:update",
                "api_keys:revoke",
                "audit:read",
                "agents:read",
                "agents:write",
                "agents:workers:register",
                "agents:workers:heartbeat",
                "agents:workers:maintain",
                "agents:workers:credentials",
                "agents:runs:read",
                "agents:runs:create",
                "agents:runs:claim",
                "agents:runs:update",
                "agents:steps:read",
                "agents:steps:create",
                "agents:steps:update",
                "agents:steps:delete",
                "agents:links:read",
                "agents:links:create",
                "agents:links:update",
                "agents:links:delete",
                "agents:quality_gates:read",
                "agents:quality_gates:create",
                "agents:quality_gates:update",
                "agents:quality_gates:delete"
              ],
              "type": "string"
            },
            "type": "array"
          },
          "status": {
            "description": "Server-side API key status.",
            "enum": [
              "active",
              "disabled",
              "revoked"
            ],
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "name",
          "key_prefix",
          "scopes",
          "created_by_user_id",
          "created_at",
          "status",
          "scope_version",
          "updated_at"
        ],
        "type": "object"
      },
      "ApprovedWorkerDeviceAuthorization": {
        "properties": {
          "credential_id": {
            "format": "uuid",
            "type": "string"
          },
          "status": {
            "enum": [
              "approved"
            ],
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "worker_id": {
            "format": "uuid",
            "type": "string"
          },
          "worker_name": {
            "type": "string"
          }
        },
        "required": [
          "worker_id",
          "worker_name",
          "tenant_id",
          "credential_id",
          "status"
        ],
        "type": "object"
      },
      "AssignTicketRequest": {
        "description": "------------------------------\nAssign & Labels\n------------------------------",
        "properties": {
          "assignee_id": {
            "description": "`None` means unassign",
            "example": "c0a80101-0000-0000-0000-000000000002",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "AttachmentDownloadResponse": {
        "properties": {
          "expires_at": {
            "example": "2026-04-12T10:00:00Z",
            "type": "string"
          },
          "url": {
            "example": "https://example.invalid/download",
            "type": "string"
          }
        },
        "required": [
          "url",
          "expires_at"
        ],
        "type": "object"
      },
      "AttachmentResponse": {
        "properties": {
          "can_preview": {
            "type": "boolean"
          },
          "filename": {
            "type": "string"
          },
          "height": {
            "format": "int32",
            "type": [
              "integer",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "media_family": {
            "type": "string"
          },
          "mime": {
            "type": [
              "string",
              "null"
            ]
          },
          "page_count": {
            "format": "int32",
            "type": [
              "integer",
              "null"
            ]
          },
          "sha256": {
            "pattern": "^[0-9a-f]{64}$",
            "type": [
              "string",
              "null"
            ]
          },
          "size_bytes": {
            "format": "int64",
            "type": [
              "integer",
              "null"
            ]
          },
          "status": {
            "type": "string"
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "variants": {
            "items": {
              "$ref": "#/components/schemas/AttachmentVariantResponse"
            },
            "type": "array"
          },
          "virus_status": {
            "type": "string"
          },
          "width": {
            "format": "int32",
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "ticket_id",
          "filename",
          "media_family",
          "status",
          "virus_status",
          "variants",
          "can_preview"
        ],
        "type": "object"
      },
      "AttachmentVariantResponse": {
        "properties": {
          "height": {
            "format": "int32",
            "type": [
              "integer",
              "null"
            ]
          },
          "kind": {
            "type": "string"
          },
          "mime": {
            "type": "string"
          },
          "page_number": {
            "format": "int32",
            "type": [
              "integer",
              "null"
            ]
          },
          "ready": {
            "type": "boolean"
          },
          "size_bytes": {
            "format": "int64",
            "type": [
              "integer",
              "null"
            ]
          },
          "width": {
            "format": "int32",
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "required": [
          "kind",
          "mime",
          "ready"
        ],
        "type": "object"
      },
      "BillingCurrent": {
        "properties": {
          "account": {
            "$ref": "#/components/schemas/TenantBillingAccount"
          },
          "assignment": {
            "$ref": "#/components/schemas/TenantPlanAssignment"
          },
          "current_usage": {
            "items": {
              "$ref": "#/components/schemas/UsageCounter"
            },
            "type": "array"
          },
          "plan": {
            "$ref": "#/components/schemas/BillingPlan"
          }
        },
        "required": [
          "account",
          "plan",
          "assignment",
          "current_usage"
        ],
        "type": "object"
      },
      "BillingPaymentSession": {
        "properties": {
          "amount_due": {
            "description": "Invoice amount due in integer minor currency units, when Stripe provides it.",
            "format": "int64",
            "minimum": 0,
            "type": [
              "integer",
              "null"
            ]
          },
          "client_secret": {
            "description": "Short-lived secret used only by Stripe Payment Element. Do not log, cache, or persist it.",
            "type": "string"
          },
          "currency": {
            "description": "Lowercase ISO 4217 currency code, when Stripe provides it.",
            "pattern": "^[a-z]{3}$",
            "type": [
              "string",
              "null"
            ]
          },
          "publishable_key": {
            "description": "Stripe publishable key for initializing Stripe.js.",
            "type": "string"
          }
        },
        "required": [
          "client_secret",
          "publishable_key",
          "amount_due",
          "currency"
        ],
        "type": "object"
      },
      "BillingPlan": {
        "properties": {
          "code": {
            "example": "builder",
            "type": "string"
          },
          "display_name": {
            "example": "Builder",
            "type": "string"
          },
          "entitlements": {
            "additionalProperties": {
              "$ref": "#/components/schemas/BillingPlanLimit"
            },
            "type": "object"
          },
          "is_public": {
            "type": "boolean"
          },
          "sort_order": {
            "description": "Stable ascending display order for public plans.",
            "format": "int32",
            "type": "integer"
          },
          "stripe_price_id": {
            "example": "price_123",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "code",
          "display_name",
          "stripe_price_id",
          "entitlements",
          "is_public",
          "sort_order"
        ],
        "type": "object"
      },
      "BillingPlanLimit": {
        "oneOf": [
          {
            "format": "int64",
            "type": "integer"
          },
          {
            "type": "boolean"
          },
          {
            "type": "null"
          }
        ]
      },
      "BillingPlansResponse": {
        "properties": {
          "plans": {
            "items": {
              "$ref": "#/components/schemas/BillingPlan"
            },
            "type": "array"
          }
        },
        "required": [
          "plans"
        ],
        "type": "object"
      },
      "BootstrapTenantRequest": {
        "properties": {
          "name": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "BulkTicketUpdateItem": {
        "description": "------------------------------\nBulk update\n------------------------------\nRequest entry for a single ticket inside the bulk update.",
        "properties": {
          "id": {
            "description": "ID of the ticket to update.",
            "example": "c0a80101-0000-0000-0000-0000000000aa",
            "format": "uuid",
            "type": "string"
          },
          "patch": {
            "$ref": "#/components/schemas/UpdateTicketRequest",
            "description": "Partial update payload for that ticket."
          }
        },
        "required": [
          "id",
          "patch"
        ],
        "type": "object"
      },
      "BulkTicketUpdateItemErr": {
        "description": "Error result for one item in the bulk response.",
        "properties": {
          "code": {
            "description": "Stable machine-readable code (`not_found`, `bad_request`, etc.).",
            "example": "not_found",
            "type": "string"
          },
          "id": {
            "example": "c0a80101-0000-0000-0000-0000000000bb",
            "format": "uuid",
            "type": "string"
          },
          "message": {
            "description": "Human-readable message (`not found`, `forbidden`, etc.).",
            "example": "not found",
            "type": "string"
          },
          "ok": {
            "description": "Always `false` in this variant.",
            "example": false,
            "type": "boolean"
          }
        },
        "required": [
          "ok",
          "id",
          "code",
          "message"
        ],
        "type": "object"
      },
      "BulkTicketUpdateItemOk": {
        "description": "Success result for one item in the bulk response.",
        "properties": {
          "id": {
            "example": "c0a80101-0000-0000-0000-0000000000aa",
            "format": "uuid",
            "type": "string"
          },
          "ok": {
            "description": "Always `true` in this variant.",
            "example": true,
            "type": "boolean"
          },
          "ticket": {
            "$ref": "#/components/schemas/TicketResponse",
            "description": "The updated ticket after applying the patch."
          }
        },
        "required": [
          "ok",
          "id",
          "ticket"
        ],
        "type": "object"
      },
      "BulkTicketUpdateItemResult": {
        "description": "One entry of the bulk result array.\n\nThis is an untagged union of success and error. Wire format will look like:\n`{ \"ok\": true,  \"id\": \"...\", \"ticket\": {...} }`\nor `{ \"ok\": false, \"id\": \"...\", \"code\": \"not_found\", \"message\": \"not found\" }`",
        "oneOf": [
          {
            "$ref": "#/components/schemas/BulkTicketUpdateItemOk"
          },
          {
            "$ref": "#/components/schemas/BulkTicketUpdateItemErr"
          }
        ]
      },
      "BulkTicketUpdateRequest": {
        "description": "Top-level request body for PATCH /tickets/bulk.\n\n`updates` must contain between 1 and 100 patch operations.",
        "properties": {
          "updates": {
            "example": [
              {
                "id": "c0a80101-0000-0000-0000-0000000000aa",
                "patch": {
                  "priority": "high",
                  "status": "in_progress"
                }
              }
            ],
            "items": {
              "$ref": "#/components/schemas/BulkTicketUpdateItem"
            },
            "maxItems": 100,
            "minItems": 1,
            "type": "array"
          }
        },
        "required": [
          "updates"
        ],
        "type": "object"
      },
      "BulkTicketUpdateResponse": {
        "description": "Response body for PATCH /tickets/bulk.",
        "properties": {
          "results": {
            "items": {
              "$ref": "#/components/schemas/BulkTicketUpdateItemResult"
            },
            "type": "array"
          }
        },
        "required": [
          "results"
        ],
        "type": "object"
      },
      "ChangePasswordRequest": {
        "properties": {
          "current_password": {
            "type": "string"
          },
          "new_password": {
            "type": "string"
          }
        },
        "required": [
          "current_password",
          "new_password"
        ],
        "type": "object"
      },
      "ChangePasswordResponse": {
        "properties": {
          "success": {
            "type": "boolean"
          }
        },
        "required": [
          "success"
        ],
        "type": "object"
      },
      "ChangeSubscriptionRequest": {
        "additionalProperties": false,
        "properties": {
          "plan_code": {
            "description": "Self-service target paid plan code. Enterprise is negotiated and remains a contact flow.",
            "enum": [
              "builder",
              "scale"
            ],
            "type": "string"
          },
          "preview_token": {
            "description": "Short-lived quote token returned by the preview endpoint. Required for upgrades and omitted for downgrades.",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "plan_code"
        ],
        "type": "object"
      },
      "CheckoutRequest": {
        "additionalProperties": false,
        "properties": {
          "plan_code": {
            "description": "Self-service public paid plan to subscribe to. Free does not use Checkout and Enterprise remains a contact flow.",
            "enum": [
              "builder",
              "scale"
            ],
            "type": "string"
          }
        },
        "required": [
          "plan_code"
        ],
        "type": "object"
      },
      "CheckoutSession": {
        "properties": {
          "client_secret": {
            "description": "Short-lived secret used only to mount Stripe Embedded Checkout in AgentOps. Do not log, cache, or persist it.",
            "type": "string"
          },
          "id": {
            "description": "Stripe Checkout Session ID.",
            "type": "string"
          },
          "publishable_key": {
            "description": "Stripe publishable key for initializing Stripe.js for this embedded flow.",
            "type": "string"
          }
        },
        "required": [
          "id",
          "client_secret",
          "publishable_key"
        ],
        "type": "object"
      },
      "CheckoutSessionCancellationResult": {
        "properties": {
          "canceled": {
            "description": "True when the tenant has no active embedded Checkout reservation. Idempotent retries also return true once that desired state is reached.",
            "type": "boolean"
          }
        },
        "required": [
          "canceled"
        ],
        "type": "object"
      },
      "ClaimAgentRunRequest": {
        "properties": {
          "input_prompt": {
            "minLength": 1,
            "type": "string"
          },
          "lease_seconds": {
            "default": 900,
            "format": "int64",
            "maximum": 86400,
            "minimum": 1,
            "type": "integer"
          },
          "metadata": {
            "additionalProperties": true,
            "default": {},
            "type": "object"
          },
          "model": {
            "maxLength": 100,
            "type": [
              "string",
              "null"
            ]
          },
          "worker_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "worker_id",
          "input_prompt"
        ],
        "type": "object"
      },
      "ClaimNextAgentRunRequest": {
        "properties": {
          "input_prompt": {
            "minLength": 1,
            "type": "string"
          },
          "lease_seconds": {
            "default": 900,
            "format": "int64",
            "maximum": 86400,
            "minimum": 1,
            "type": "integer"
          },
          "metadata": {
            "additionalProperties": true,
            "default": {},
            "type": "object"
          },
          "model": {
            "maxLength": 100,
            "type": [
              "string",
              "null"
            ]
          },
          "project_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "required_capabilities": {
            "items": {
              "maxLength": 120,
              "minLength": 1,
              "type": "string"
            },
            "type": "array"
          },
          "statuses": {
            "default": [
              "backlog",
              "todo"
            ],
            "items": {
              "enum": [
                "backlog",
                "todo",
                "in_progress",
                "blocked"
              ],
              "type": "string"
            },
            "type": "array"
          },
          "worker_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "worker_id",
          "input_prompt"
        ],
        "type": "object"
      },
      "CommentListPageResponse": {
        "description": "Generic-ish page wrapper specialized for comments.\nIf you already have a shared Page<T> in `common` or similar,\njust `#[derive(Serialize, ToSchema)]` on that generic instead of redefining this.",
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/CommentResponse"
            },
            "type": "array"
          },
          "page": {
            "description": "current page number (1-based)",
            "example": 1,
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "description": "current page size",
            "example": 25,
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "description": "total number of comments across all pages",
            "example": 57,
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "total",
          "page",
          "size"
        ],
        "type": "object"
      },
      "CommentResponse": {
        "description": "Public-facing representation of a single comment.",
        "properties": {
          "author_id": {
            "example": "c0a80101-0000-0000-0000-000000000007",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "body": {
            "example": "Looks good to me!",
            "type": "string"
          },
          "created_at": {
            "description": "RFC3339 timestamp",
            "example": "2025-10-26T18:43:12Z",
            "type": "string"
          },
          "id": {
            "example": "c0a80101-0000-0000-0000-0000000000aa",
            "format": "uuid",
            "type": "string"
          },
          "ticket_id": {
            "example": "c0a80101-0000-0000-0000-0000000000bb",
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "description": "RFC3339 timestamp",
            "example": "2025-10-26T18:44:02Z",
            "type": "string"
          }
        },
        "required": [
          "id",
          "ticket_id",
          "body",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "CompleteAttachmentUploadRequest": {
        "type": "object"
      },
      "CompleteAttachmentUploadResponse": {
        "properties": {
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "virus_status": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "status",
          "virus_status"
        ],
        "type": "object"
      },
      "ConfirmEmailChangeRequest": {
        "properties": {
          "token": {
            "description": "Email change confirmation token",
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "token"
        ],
        "type": "object"
      },
      "ConfirmEmailChangeResponse": {
        "properties": {
          "status": {
            "example": "ok",
            "type": "string"
          }
        },
        "required": [
          "status"
        ],
        "type": "object"
      },
      "CreateAccountRequest": {
        "properties": {
          "company": {
            "example": "Lovelace Labs",
            "type": "string"
          },
          "email": {
            "example": "ada@example.com",
            "type": "string"
          },
          "full_name": {
            "example": "Ada Lovelace",
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        },
        "required": [
          "full_name",
          "email",
          "company",
          "password"
        ],
        "type": "object"
      },
      "CreateAccountResponse": {
        "properties": {
          "status": {
            "type": "string"
          }
        },
        "required": [
          "status"
        ],
        "type": "object"
      },
      "CreateAgentRunEventRequest": {
        "properties": {
          "data": {
            "additionalProperties": true,
            "type": "object"
          },
          "event_type": {
            "enum": [
              "progress",
              "message",
              "log"
            ],
            "type": "string"
          }
        },
        "required": [
          "event_type",
          "data"
        ],
        "type": "object"
      },
      "CreateAgentRunRequest": {
        "properties": {
          "attempt": {
            "default": 1,
            "format": "int32",
            "minimum": 1,
            "type": "integer"
          },
          "input_prompt": {
            "default": "Execute the assigned ticket.",
            "minLength": 1,
            "type": "string"
          },
          "lease_seconds": {
            "default": 900,
            "format": "int64",
            "maximum": 86400,
            "minimum": 1,
            "type": "integer"
          },
          "metadata": {
            "additionalProperties": true,
            "default": {},
            "type": "object"
          },
          "model": {
            "maxLength": 100,
            "type": [
              "string",
              "null"
            ]
          },
          "started_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "default": "queued",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed",
              "cancelled"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          },
          "worker_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "type": "object"
      },
      "CreateAgentRunStepRequest": {
        "properties": {
          "metadata": {
            "additionalProperties": true,
            "default": {},
            "type": "object"
          },
          "status": {
            "enum": [
              "pending",
              "running",
              "completed",
              "failed"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          },
          "step_key": {
            "maxLength": 160,
            "minLength": 1,
            "type": "string"
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "maxLength": 300,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "step_key",
          "title",
          "status"
        ],
        "type": "object"
      },
      "CreateAgentWorkerCredentialRequest": {
        "properties": {
          "expires_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "label": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "label"
        ],
        "type": "object"
      },
      "CreateApiKeyRequest": {
        "properties": {
          "expires_at": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "name": {
            "maxLength": 120,
            "minLength": 1,
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "nullable": true,
            "type": "string"
          },
          "scopes": {
            "description": "Server-side scopes to grant to the API key.",
            "items": {
              "enum": [
                "tickets:read",
                "tickets:write",
                "tickets:delete",
                "projects:read",
                "projects:write",
                "webhooks:read",
                "webhooks:write",
                "api_keys:read",
                "api_keys:write",
                "api_keys:create",
                "api_keys:update",
                "api_keys:revoke",
                "audit:read",
                "agents:read",
                "agents:write",
                "agents:workers:register",
                "agents:workers:heartbeat",
                "agents:workers:maintain",
                "agents:workers:credentials",
                "agents:runs:read",
                "agents:runs:create",
                "agents:runs:claim",
                "agents:runs:update",
                "agents:steps:read",
                "agents:steps:create",
                "agents:steps:update",
                "agents:steps:delete",
                "agents:links:read",
                "agents:links:create",
                "agents:links:update",
                "agents:links:delete",
                "agents:quality_gates:read",
                "agents:quality_gates:create",
                "agents:quality_gates:update",
                "agents:quality_gates:delete"
              ],
              "type": "string"
            },
            "minItems": 1,
            "type": "array",
            "uniqueItems": true
          }
        },
        "required": [
          "name",
          "scopes"
        ],
        "type": "object"
      },
      "CreateApiKeyResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiKeyResponse"
          },
          {
            "properties": {
              "key": {
                "description": "Full rgk_ API key. Returned only once from POST /api/v1/api-keys.",
                "type": "string"
              }
            },
            "required": [
              "key"
            ],
            "type": "object"
          }
        ]
      },
      "CreateCommentRequest": {
        "description": "------------------------------\nCreate\n------------------------------\nCreate a new comment on a ticket.\n`author_id` is optional (server may infer from auth); `body` must be non-empty.",
        "properties": {
          "author_id": {
            "description": "Optional author; if omitted, backend can use the authenticated user.",
            "example": "c0a80101-0000-0000-0000-000000000007",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "body": {
            "description": "Plain-text/markdown body",
            "example": "Looks good to me!",
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "body"
        ],
        "type": "object"
      },
      "CreateCustomFieldDefinitionRequest": {
        "properties": {
          "description": {
            "example": "Customer impact summary",
            "type": [
              "string",
              "null"
            ]
          },
          "field_type": {
            "$ref": "#/components/schemas/CustomFieldType"
          },
          "is_required": {
            "example": false,
            "type": [
              "boolean",
              "null"
            ]
          },
          "key": {
            "example": "impact",
            "type": "string"
          },
          "name": {
            "example": "Impact",
            "type": "string"
          },
          "options": {
            "items": {
              "$ref": "#/components/schemas/CustomFieldOptionRequest"
            },
            "type": "array"
          },
          "position": {
            "example": 10,
            "format": "int32",
            "minimum": 0,
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "required": [
          "key",
          "name",
          "field_type"
        ],
        "type": "object"
      },
      "CreateLabelRequest": {
        "properties": {
          "color": {
            "example": "#FF9900",
            "maxLength": 32,
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "example": "Incidents and platform work",
            "maxLength": 500,
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "example": "Backend",
            "maxLength": 100,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "CreateProjectRequest": {
        "properties": {
          "description": {
            "description": "Optional project description",
            "example": "This is where demo tickets go",
            "type": [
              "string",
              "null"
            ]
          },
          "key": {
            "description": "Ticket-compatible project key (2–10 uppercase letters or digits, starting with a letter)",
            "example": "DEMO",
            "maxLength": 10,
            "minLength": 2,
            "pattern": "^[A-Z][A-Z0-9]{1,9}$",
            "type": "string"
          },
          "name": {
            "description": "Human-readable project name",
            "example": "Demo Project",
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "tenant_id": {
            "description": "Explicit tenant ID (platform ops). If omitted, the current context tenant is used.",
            "example": "00000000-0000-0000-0000-00000000aaaa",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "key",
          "name"
        ],
        "type": "object"
      },
      "CreateQualityGateResultRequest": {
        "properties": {
          "checks": {
            "default": [],
            "items": {},
            "type": "array"
          },
          "run_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "enum": [
              "running",
              "passed",
              "failed"
            ],
            "examples": [
              "running",
              "passed",
              "failed"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "status"
        ],
        "type": "object"
      },
      "CreateSprintRequest": {
        "properties": {
          "ends_at": {
            "example": "2025-01-14T00:00:00Z",
            "type": [
              "string",
              "null"
            ]
          },
          "goal": {
            "example": "Ship onboarding flow",
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "example": "Sprint 1",
            "type": "string"
          },
          "starts_at": {
            "example": "2025-01-01T00:00:00Z",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "name",
          "starts_at",
          "ends_at"
        ],
        "type": "object"
      },
      "CreateTenantRequest": {
        "properties": {
          "name": {
            "description": "Human-readable tenant name (must be non-empty; unique server-side)",
            "example": "Acme Corp",
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "CreateTicketExternalLinkRequest": {
        "properties": {
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "examples": [
              "github_pr",
              "github_branch",
              "github_commit",
              "deployment",
              "log"
            ],
            "maxLength": 80,
            "minLength": 1,
            "type": "string"
          },
          "label": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "metadata": {
            "additionalProperties": true,
            "default": {},
            "type": "object"
          },
          "url": {
            "format": "uri",
            "maxLength": 2048,
            "type": "string"
          }
        },
        "required": [
          "kind",
          "label",
          "url"
        ],
        "type": "object"
      },
      "CreateTicketRelationRequest": {
        "properties": {
          "note": {
            "example": "This blocks deployment until bug is fixed",
            "type": [
              "string",
              "null"
            ]
          },
          "relation_type": {
            "$ref": "#/components/schemas/TicketRelationTypeDto"
          },
          "to_ticket_id": {
            "example": "c0a80101-0000-0000-0000-000000000123",
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "to_ticket_id",
          "relation_type"
        ],
        "type": "object"
      },
      "CreateTicketRequest": {
        "description": "------------------------------\nCreate\n------------------------------\nCreate a new ticket. Either `project_id` or `project_key` must be provided.",
        "properties": {
          "assignee_id": {
            "example": "c0a80101-0000-0000-0000-000000000001",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "description": "Optional markdown/plaintext description",
            "example": "Optional markdown description",
            "type": [
              "string",
              "null"
            ]
          },
          "due_date": {
            "description": "Due date in ISO \"YYYY-MM-DD\" (kept as `NaiveDate` internally)",
            "example": "2025-12-31",
            "format": "date",
            "type": "string"
          },
          "parent_id": {
            "example": "a9dbb3b1-3cf1-45b8-9b61-9f3d8c9b3a22",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "priority": {
            "$ref": "#/components/schemas/PriorityLevel",
            "description": "Priority (server default applies if omitted)"
          },
          "project_id": {
            "description": "Project selector (one of these must be present; rule enforced by `validate_project_selector`)",
            "example": "9eb20a5d-12cf-4c98-a392-3fd6dd7c1154",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "project_key": {
            "description": "Project short key (e.g., \"DEMO\")",
            "example": "DEMO",
            "maxLength": 10,
            "minLength": 2,
            "pattern": "^[A-Z][A-Z0-9]{1,9}$",
            "type": [
              "string",
              "null"
            ]
          },
          "reporter_id": {
            "example": "1c3c9baf-4c47-45e7-8a0e-3b2cf8b94d9d",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "sprint_id": {
            "example": "f7f9f2a1-0e11-4e4e-9e9a-33be5d2f4e77",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/TicketStatus",
            "description": "Initial status (server default applies if omitted)"
          },
          "story_points": {
            "description": "Decimal encoded as string (e.g., \"3.5\"); kept as `Decimal` internally",
            "example": "3.5",
            "type": "string"
          },
          "title": {
            "description": "Human-readable title",
            "example": "E2E: first ticket",
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "type": {
            "$ref": "#/components/schemas/TicketType",
            "description": "Ticket type (server default applies if omitted)"
          }
        },
        "required": [
          "title"
        ],
        "type": "object"
      },
      "CreateUserRequest": {
        "properties": {
          "email": {
            "example": "root@platform.test",
            "type": "string"
          },
          "is_active": {
            "description": "Defaults to true if omitted",
            "type": [
              "boolean",
              "null"
            ]
          },
          "name": {
            "example": "Platform Root",
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        },
        "required": [
          "email",
          "name"
        ],
        "type": "object"
      },
      "CreateWebhookRequest": {
        "properties": {
          "event_types": {
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "type": "array"
          },
          "name": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "project_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "url": {
            "maxLength": 2048,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "name",
          "url",
          "event_types"
        ],
        "type": "object"
      },
      "CreateWebhookResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/WebhookSubscriptionResponse"
          },
          {
            "properties": {
              "secret": {
                "type": "string"
              }
            },
            "required": [
              "secret"
            ],
            "type": "object"
          }
        ]
      },
      "CreatedAgentWorkerCredentialResponse": {
        "properties": {
          "api_key": {
            "description": "Plaintext rgk API key secret for the worker credential. Returned only once at creation time.",
            "type": "string"
          },
          "api_key_id": {
            "format": "uuid",
            "type": "string"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "created_by": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "credential_prefix": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "credential_version": {
            "format": "int32",
            "minimum": 1,
            "type": "integer"
          },
          "expires_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "installation_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "key_prefix": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "last_used_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "revocation_reason": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "revoked_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "revoked_by": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "worker_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "id",
          "worker_id",
          "api_key_id",
          "label",
          "created_at",
          "api_key",
          "key_prefix",
          "installation_id",
          "credential_version",
          "expires_at",
          "credential_prefix",
          "last_used_at",
          "revocation_reason"
        ],
        "type": "object"
      },
      "CustomFieldDefinitionPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/CustomFieldDefinitionResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "CustomFieldDefinitionResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "field_type": {
            "$ref": "#/components/schemas/CustomFieldType"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "is_archived": {
            "type": "boolean"
          },
          "is_required": {
            "type": "boolean"
          },
          "key": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "options": {
            "items": {
              "$ref": "#/components/schemas/CustomFieldOptionResponse"
            },
            "type": "array"
          },
          "position": {
            "format": "int32",
            "type": "integer"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "project_id",
          "key",
          "name",
          "field_type",
          "options",
          "is_required",
          "is_archived",
          "position",
          "row_version",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "CustomFieldOptionRequest": {
        "properties": {
          "color": {
            "example": "#E5484D",
            "type": [
              "string",
              "null"
            ]
          },
          "label": {
            "example": "High",
            "maxLength": 100,
            "minLength": 1,
            "type": "string"
          },
          "value": {
            "example": "high",
            "maxLength": 100,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "value",
          "label"
        ],
        "type": "object"
      },
      "CustomFieldOptionResponse": {
        "properties": {
          "color": {
            "type": [
              "string",
              "null"
            ]
          },
          "label": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        },
        "required": [
          "value",
          "label",
          "color"
        ],
        "type": "object"
      },
      "CustomFieldType": {
        "description": "Custom field type. Ticket custom_fields values are canonical by type: text is a non-blank string up to 2000 bytes; number is returned as a plain decimal string (clients should send exact decimal strings, integer JSON numbers are accepted only when unambiguous); date is a YYYY-MM-DD string only, with no time or timezone; boolean is a JSON boolean; single_select is an allowed option value string; multi_select is a unique allowed option value string array up to 100 items and is returned sorted.",
        "enum": [
          "text",
          "number",
          "date",
          "boolean",
          "single_select",
          "multi_select"
        ],
        "type": "string"
      },
      "DeactivateAccountRequest": {
        "properties": {
          "current_password": {
            "description": "Current password used to confirm deactivation.",
            "type": "string"
          }
        },
        "required": [
          "current_password"
        ],
        "type": "object"
      },
      "DeactivateAccountResponse": {
        "properties": {
          "success": {
            "type": "boolean"
          }
        },
        "required": [
          "success"
        ],
        "type": "object"
      },
      "EffectiveEntitlements": {
        "properties": {
          "entitlements": {
            "additionalProperties": {
              "$ref": "#/components/schemas/BillingPlanLimit"
            },
            "type": "object"
          },
          "plan_code": {
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id",
          "plan_code",
          "entitlements"
        ],
        "type": "object"
      },
      "ErrorEnvelope": {
        "description": "Standard error envelope your API returns.",
        "properties": {
          "code": {
            "description": "Machine-friendly code (snake_case)",
            "example": "validation_failed",
            "type": "string"
          },
          "message": {
            "description": "Human-friendly message",
            "example": "payload too large",
            "type": "string"
          },
          "request_id": {
            "description": "Correlation id (x-request-id)",
            "example": "04ab1641-e2ac-40fe-857b-9ef8306bbd7d",
            "type": [
              "string",
              "null"
            ]
          },
          "where_": {
            "description": "Internal error breadcrumb. Present in non-production responses and omitted in production.",
            "example": "http.tickets.create",
            "type": "string"
          }
        },
        "required": [
          "code",
          "message"
        ],
        "type": "object"
      },
      "ExtendAgentRunLeaseRequest": {
        "properties": {
          "lease_seconds": {
            "default": 900,
            "format": "int64",
            "maximum": 86400,
            "minimum": 1,
            "type": "integer"
          },
          "worker_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "worker_id"
        ],
        "type": "object"
      },
      "ForgotPasswordRequest": {
        "properties": {
          "email": {
            "type": "string"
          }
        },
        "required": [
          "email"
        ],
        "type": "object"
      },
      "ForgotPasswordResponse": {
        "properties": {
          "accepted": {
            "type": "boolean"
          },
          "target_email": {
            "description": "Normalized email address submitted for the reset request. This is echoed for client display and does not reveal whether an account exists.",
            "example": "user@example.com",
            "type": "string"
          }
        },
        "required": [
          "accepted",
          "target_email"
        ],
        "type": "object"
      },
      "HeartbeatAgentWorkerRequest": {
        "properties": {
          "max_concurrency": {
            "default": 1,
            "format": "int32",
            "maximum": 100,
            "minimum": 1,
            "type": "integer"
          },
          "status": {
            "default": "online",
            "enum": [
              "offline",
              "online",
              "busy",
              "disabled"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          }
        },
        "type": "object"
      },
      "InitiateAttachmentUploadRequest": {
        "properties": {
          "content_type": {
            "example": "application/pdf",
            "type": [
              "string",
              "null"
            ]
          },
          "filename": {
            "example": "invoice.pdf",
            "type": "string"
          },
          "size_bytes": {
            "example": 248392,
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "filename",
          "size_bytes"
        ],
        "type": "object"
      },
      "InitiateAttachmentUploadResponse": {
        "properties": {
          "attachment_id": {
            "format": "uuid",
            "type": "string"
          },
          "upload": {
            "$ref": "#/components/schemas/PresignedUploadResponse"
          }
        },
        "required": [
          "attachment_id",
          "upload"
        ],
        "type": "object"
      },
      "InviteProjectUserRequest": {
        "properties": {
          "email": {
            "example": "guest@example.com",
            "type": "string"
          },
          "name": {
            "example": "Guest User",
            "type": "string"
          },
          "role_id": {
            "example": "00000000-0000-0000-0000-00000000dddd",
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "email",
          "name",
          "role_id"
        ],
        "type": "object"
      },
      "InviteProjectUserResponse": {
        "properties": {
          "accepted": {
            "type": "boolean"
          }
        },
        "required": [
          "accepted"
        ],
        "type": "object"
      },
      "InviteTenantUserRequest": {
        "properties": {
          "email": {
            "example": "guest@example.com",
            "type": "string"
          },
          "name": {
            "example": "Guest User",
            "type": "string"
          },
          "role_id": {
            "example": "00000000-0000-0000-0000-00000000dddd",
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "email",
          "name",
          "role_id"
        ],
        "type": "object"
      },
      "InviteTenantUserResponse": {
        "properties": {
          "accepted": {
            "type": "boolean"
          }
        },
        "required": [
          "accepted"
        ],
        "type": "object"
      },
      "LabelPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/LabelResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "LabelResponse": {
        "properties": {
          "color": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "is_archived": {
            "type": "boolean"
          },
          "name": {
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "project_id",
          "name",
          "is_archived",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "ListAttachmentsResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/AttachmentResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "items"
        ],
        "type": "object"
      },
      "ListRolesResponse": {
        "properties": {
          "roles": {
            "items": {
              "$ref": "#/components/schemas/RoleResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "roles"
        ],
        "type": "object"
      },
      "LoginRequest": {
        "properties": {
          "email": {
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        },
        "required": [
          "email",
          "password"
        ],
        "type": "object"
      },
      "LoginResponse": {
        "properties": {
          "email": {
            "type": "string"
          },
          "expires_in_secs": {
            "description": "RFC3339 expiry (optional; clients can also decode token if they want exact exp)",
            "format": "int64",
            "type": "integer"
          },
          "memberships": {
            "items": {
              "$ref": "#/components/schemas/MembershipResponse"
            },
            "type": "array"
          },
          "name": {
            "type": "string"
          },
          "token": {
            "type": "string"
          },
          "user_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "token",
          "user_id",
          "name",
          "email",
          "memberships",
          "expires_in_secs"
        ],
        "type": "object"
      },
      "LogoutResponse": {
        "properties": {
          "success": {
            "type": "boolean"
          }
        },
        "required": [
          "success"
        ],
        "type": "object"
      },
      "ManageAgentWorkerRequest": {
        "minProperties": 1,
        "properties": {
          "name": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "status": {
            "enum": [
              "disabled",
              "offline"
            ],
            "type": "string"
          }
        },
        "type": "object"
      },
      "ManagedAgentWorkerResponse": {
        "properties": {
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "enum": [
              "offline",
              "online",
              "busy",
              "disabled",
              "active",
              "revoked",
              "pending_upgrade"
            ],
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "status"
        ],
        "type": "object"
      },
      "MarkStaleAgentWorkersOfflineRequest": {
        "properties": {
          "stale_after_seconds": {
            "default": 300,
            "format": "int64",
            "maximum": 86400,
            "minimum": 1,
            "type": "integer"
          }
        },
        "type": "object"
      },
      "MarkStaleAgentWorkersOfflineResponse": {
        "properties": {
          "updated": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "updated"
        ],
        "type": "object"
      },
      "MeResponse": {
        "properties": {
          "permissions": {
            "description": "Effective set of permissions for this user within this tenant",
            "example": [
              "tickets:READ",
              "projects:WRITE"
            ],
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "role_id": {
            "description": "The role assigned inside this tenant (if any)",
            "example": "00000000-0000-0000-0000-00000000bbbb",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "tenant_id": {
            "description": "The tenant the user is operating under",
            "example": "00000000-0000-0000-0000-00000000aaaa",
            "format": "uuid",
            "type": "string"
          },
          "user_id": {
            "description": "The authenticated user's ID",
            "example": "00000000-0000-0000-0000-000000000001",
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "user_id",
          "tenant_id",
          "permissions"
        ],
        "type": "object"
      },
      "MembershipResponse": {
        "properties": {
          "permissions": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "uniqueItems": true
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "tenant_name": {
            "type": "string"
          }
        },
        "required": [
          "tenant_id",
          "tenant_name",
          "role_id",
          "role_name",
          "permissions"
        ],
        "type": "object"
      },
      "MoveRequest": {
        "properties": {
          "target_sprint_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "ticket_id"
        ],
        "type": "object"
      },
      "Page": {
        "description": "Paged list response.",
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/SprintResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "Page_ActivityEventResponse": {
        "description": "Paged list response.",
        "properties": {
          "items": {
            "items": {
              "properties": {
                "action": {
                  "$ref": "#/components/schemas/ActivityAction"
                },
                "actor_id": {
                  "format": "uuid",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "created_at": {
                  "format": "date-time",
                  "type": "string"
                },
                "id": {
                  "format": "uuid",
                  "type": "string"
                },
                "payload": {},
                "request_id": {
                  "format": "uuid",
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "resource_id": {
                  "format": "uuid",
                  "type": "string"
                },
                "resource_kind": {
                  "type": "string"
                }
              },
              "required": [
                "id",
                "resource_kind",
                "resource_id",
                "action",
                "created_at"
              ],
              "type": "object"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "PendingChangeType": {
        "description": "Kind of unresolved self-service plan change. A scheduled downgrade can be undone; a payment-required upgrade can be completed in AgentOps or canceled.",
        "enum": [
          "scheduled_downgrade",
          "payment_required_upgrade"
        ],
        "type": "string"
      },
      "PresignedHeaderResponse": {
        "properties": {
          "name": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "value"
        ],
        "type": "object"
      },
      "PresignedUploadResponse": {
        "properties": {
          "expires_at": {
            "example": "2026-04-12T10:00:00Z",
            "type": "string"
          },
          "headers": {
            "items": {
              "$ref": "#/components/schemas/PresignedHeaderResponse"
            },
            "type": "array"
          },
          "method": {
            "example": "PUT",
            "type": "string"
          },
          "url": {
            "example": "https://example.invalid/upload",
            "type": "string"
          }
        },
        "required": [
          "method",
          "url",
          "headers",
          "expires_at"
        ],
        "type": "object"
      },
      "PreviewSubscriptionChangeRequest": {
        "additionalProperties": false,
        "properties": {
          "plan_code": {
            "description": "Self-service target paid plan code. Enterprise is negotiated and remains a contact flow.",
            "enum": [
              "builder",
              "scale"
            ],
            "type": "string"
          }
        },
        "required": [
          "plan_code"
        ],
        "type": "object"
      },
      "PriorityLevel": {
        "description": "Priority level",
        "enum": [
          "lowest",
          "low",
          "medium",
          "high",
          "highest"
        ],
        "example": "medium",
        "type": "string"
      },
      "ProjectAccessSummary": {
        "properties": {
          "permissions": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "uniqueItems": true
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "type": "string"
          }
        },
        "required": [
          "role_id",
          "role_name",
          "permissions"
        ],
        "type": "object"
      },
      "ProjectInviteResponse": {
        "description": "One pending project invite. Token material is never returned.",
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "email": {
            "example": "guest@example.com",
            "type": "string"
          },
          "expires_at": {
            "format": "date-time",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "invited_by_user_id": {
            "format": "uuid",
            "type": "string"
          },
          "invitee_name": {
            "nullable": true,
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "nullable": true,
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "project_id",
          "email",
          "invitee_name",
          "invited_by_user_id",
          "role_id",
          "role_name",
          "expires_at",
          "created_at"
        ],
        "type": "object"
      },
      "ProjectInvitesResponse": {
        "properties": {
          "invites": {
            "items": {
              "$ref": "#/components/schemas/ProjectInviteResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "invites"
        ],
        "type": "object"
      },
      "ProjectMemberDetailResponse": {
        "description": "Single project membership response with the current row version for optimistic concurrency.",
        "properties": {
          "created_at": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "type": "string"
          },
          "user_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id",
          "project_id",
          "user_id",
          "email",
          "name",
          "role_id",
          "role_name",
          "created_at",
          "updated_at",
          "row_version"
        ],
        "type": "object"
      },
      "ProjectMemberResponse": {
        "description": "One project member in a list response.",
        "properties": {
          "created_at": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "user_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id",
          "project_id",
          "user_id",
          "email",
          "name",
          "role_id",
          "role_name",
          "created_at",
          "row_version"
        ],
        "type": "object"
      },
      "ProjectPageResponse": {
        "description": "Page wrapper specialized for Projects (optional; you can also use Page<ProjectResponse>)",
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/ProjectResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "ProjectResponse": {
        "description": "Public response for a Project",
        "properties": {
          "created_at": {
            "description": "RFC3339 UTC",
            "example": "2025-10-17T10:02:00Z",
            "type": "string"
          },
          "current_user_access": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ProjectAccessSummary"
              },
              {
                "type": "null"
              }
            ]
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "is_archived": {
            "type": "boolean"
          },
          "key": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "description": "RFC3339 UTC",
            "example": "2025-10-17T10:03:00Z",
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "key",
          "name",
          "is_archived",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "QualityGateResultPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/QualityGateResultResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "QualityGateResultResponse": {
        "properties": {
          "checks": {
            "items": {},
            "type": "array"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "run_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "enum": [
              "running",
              "passed",
              "failed"
            ],
            "type": "string"
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "ticket_id",
          "status",
          "checks",
          "created_at",
          "updated_at",
          "row_version"
        ],
        "type": "object"
      },
      "RegisterAgentWorkerRequest": {
        "properties": {
          "capabilities": {
            "default": [],
            "items": {},
            "type": "array"
          },
          "kind": {
            "examples": [
              "codex",
              "claude_code",
              "github_copilot",
              "custom"
            ],
            "maxLength": 80,
            "minLength": 1,
            "type": "string"
          },
          "name": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "status": {
            "default": "online",
            "enum": [
              "offline",
              "online",
              "busy",
              "disabled"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "name",
          "kind"
        ],
        "type": "object"
      },
      "ReorderRequest": {
        "properties": {
          "ticket_ids": {
            "items": {
              "format": "uuid",
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "ticket_ids"
        ],
        "type": "object"
      },
      "ResetPasswordRequest": {
        "properties": {
          "new_password": {
            "description": "New password",
            "type": "string"
          },
          "tenant_id": {
            "description": "Optional tenant to scope the sign-in token after reset.",
            "example": "00000000-0000-0000-0000-00000000aaaa",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "token": {
            "description": "Raw token from the email link",
            "type": "string"
          }
        },
        "required": [
          "token",
          "new_password"
        ],
        "type": "object"
      },
      "ResetPasswordResponse": {
        "properties": {
          "expires_in_secs": {
            "format": "int64",
            "type": [
              "integer",
              "null"
            ]
          },
          "permissions": {
            "items": {
              "type": "string"
            },
            "type": [
              "array",
              "null"
            ],
            "uniqueItems": true
          },
          "role_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "role_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "success": {
            "type": "boolean"
          },
          "target_email": {
            "description": "Email address for the account whose password was reset.",
            "example": "user@example.com",
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "token": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "success",
          "target_email"
        ],
        "type": "object"
      },
      "RevokedCurrentWorkerCredentialResponse": {
        "properties": {
          "revoked": {
            "type": "boolean"
          }
        },
        "required": [
          "revoked"
        ],
        "type": "object"
      },
      "RoleResponse": {
        "properties": {
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "permissions": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "uniqueItems": true
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "scope": {
            "$ref": "#/components/schemas/RoleScope"
          }
        },
        "required": [
          "role_id",
          "name",
          "description",
          "scope",
          "permissions"
        ],
        "type": "object"
      },
      "RoleScope": {
        "enum": [
          "tenant",
          "project",
          "system"
        ],
        "type": "string"
      },
      "SignupRequest": {
        "properties": {
          "email": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "password": {
            "type": "string"
          }
        },
        "required": [
          "email",
          "name",
          "password"
        ],
        "type": "object"
      },
      "SignupResponse": {
        "properties": {
          "status": {
            "type": "string"
          }
        },
        "required": [
          "status"
        ],
        "type": "object"
      },
      "SprintBoardColumnResponse": {
        "properties": {
          "label": {
            "type": "string"
          },
          "tickets": {
            "items": {
              "$ref": "#/components/schemas/SprintBoardTicketResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "label",
          "tickets"
        ],
        "type": "object"
      },
      "SprintBoardTicketResponse": {
        "properties": {
          "assignee_id": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "key": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "title": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "key",
          "title",
          "status"
        ],
        "type": "object"
      },
      "SprintResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "created_by": {
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "ends_at": {
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "goal": {
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "starts_at": {
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "state": {
            "$ref": "#/components/schemas/SprintState"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "project_id",
          "name",
          "state",
          "created_at",
          "updated_at",
          "row_version"
        ],
        "type": "object"
      },
      "SprintState": {
        "enum": [
          "planned",
          "active",
          "closed"
        ],
        "type": "string"
      },
      "SprintVelocityResponse": {
        "properties": {
          "completed": {
            "format": "int64",
            "type": "integer"
          },
          "completed_points": {
            "format": "double",
            "type": [
              "number",
              "null"
            ]
          },
          "sprint_id": {
            "format": "uuid",
            "type": "string"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          },
          "total_points": {
            "format": "double",
            "type": [
              "number",
              "null"
            ]
          }
        },
        "required": [
          "sprint_id",
          "completed",
          "total"
        ],
        "type": "object"
      },
      "StartWorkerDeviceAuthorizationRequest": {
        "properties": {
          "agent_version": {
            "maxLength": 64,
            "minLength": 1,
            "type": "string"
          },
          "architecture": {
            "maxLength": 64,
            "minLength": 1,
            "type": "string"
          },
          "client_id": {
            "enum": [
              "rustgrid-agent"
            ],
            "type": "string"
          },
          "display_name": {
            "anyOf": [
              {
                "maxLength": 255,
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "hostname": {
            "maxLength": 255,
            "minLength": 1,
            "type": "string"
          },
          "installation_id": {
            "format": "uuid",
            "type": "string"
          },
          "operating_system": {
            "maxLength": 64,
            "minLength": 1,
            "type": "string"
          },
          "requested_scopes": {
            "items": {
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "client_id",
          "installation_id",
          "hostname",
          "operating_system",
          "architecture",
          "agent_version"
        ],
        "type": "object"
      },
      "StartedWorkerDeviceAuthorization": {
        "properties": {
          "device_code": {
            "description": "One-time high-entropy secret. Never log or display this value.",
            "type": "string"
          },
          "expires_in": {
            "format": "int64",
            "minimum": 1,
            "type": "integer"
          },
          "interval": {
            "format": "int32",
            "minimum": 1,
            "type": "integer"
          },
          "user_code": {
            "pattern": "^[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}-[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}$",
            "type": "string"
          },
          "verification_uri": {
            "format": "uri",
            "type": "string"
          },
          "verification_uri_complete": {
            "format": "uri",
            "type": "string"
          }
        },
        "required": [
          "device_code",
          "user_code",
          "verification_uri",
          "verification_uri_complete",
          "expires_in",
          "interval"
        ],
        "type": "object"
      },
      "SubscriptionChangeCancellationResult": {
        "properties": {
          "canceled": {
            "description": "True when a RustGrid-managed scheduled downgrade or pending-payment upgrade was canceled.",
            "type": "boolean"
          }
        },
        "required": [
          "canceled"
        ],
        "type": "object"
      },
      "SubscriptionChangeDirection": {
        "description": "Whether the target is above or below the current plan's stable sort order.",
        "enum": [
          "upgrade",
          "downgrade"
        ],
        "type": "string"
      },
      "SubscriptionChangePreview": {
        "properties": {
          "amount_due": {
            "description": "Invoice amount due in integer minor currency units.",
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "currency": {
            "description": "Lowercase ISO 4217 currency code.",
            "pattern": "^[a-z]{3}$",
            "type": "string"
          },
          "direction": {
            "$ref": "#/components/schemas/SubscriptionChangeDirection"
          },
          "effective_at": {
            "format": "date-time",
            "type": "string"
          },
          "plan_code": {
            "description": "Self-service target paid plan code.",
            "enum": [
              "builder",
              "scale"
            ],
            "type": "string"
          },
          "preview_token": {
            "description": "Tamper-evident short-lived upgrade quote token, or null for a downgrade.",
            "type": [
              "string",
              "null"
            ]
          },
          "proration_amount": {
            "description": "Net proration in integer minor currency units; it may be negative.",
            "format": "int64",
            "type": "integer"
          },
          "proration_date": {
            "description": "Unix timestamp fixed into an upgrade quote, or null for a downgrade.",
            "format": "int64",
            "type": [
              "integer",
              "null"
            ]
          },
          "recurring_amount": {
            "description": "Base renewal total for the retained subscription quantity in integer minor units, before taxes and discounts.",
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "recurring_currency": {
            "description": "Lowercase ISO 4217 currency code for the base renewal total.",
            "pattern": "^[a-z]{3}$",
            "type": "string"
          },
          "recurring_interval": {
            "description": "Stripe billing interval for the target recurring price.",
            "enum": [
              "day",
              "week",
              "month",
              "year"
            ],
            "type": "string"
          },
          "recurring_interval_count": {
            "description": "Number of recurring intervals between renewals.",
            "format": "int64",
            "minimum": 1,
            "type": "integer"
          }
        },
        "required": [
          "plan_code",
          "direction",
          "effective_at",
          "proration_date",
          "preview_token",
          "amount_due",
          "proration_amount",
          "currency",
          "recurring_amount",
          "recurring_currency",
          "recurring_interval",
          "recurring_interval_count"
        ],
        "type": "object"
      },
      "SubscriptionChangeResult": {
        "properties": {
          "direction": {
            "$ref": "#/components/schemas/SubscriptionChangeDirection"
          },
          "effective_at": {
            "format": "date-time",
            "type": "string"
          },
          "payment_client_secret": {
            "description": "Short-lived Payment Element client secret when status is `requires_payment`; otherwise null.",
            "type": [
              "string",
              "null"
            ]
          },
          "plan_code": {
            "description": "Self-service target paid plan code.",
            "enum": [
              "builder",
              "scale"
            ],
            "type": "string"
          },
          "publishable_key": {
            "description": "Stripe publishable key when status is `requires_payment`; otherwise null.",
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/SubscriptionChangeStatus"
          }
        },
        "required": [
          "plan_code",
          "direction",
          "status",
          "effective_at",
          "payment_client_secret",
          "publishable_key"
        ],
        "type": "object"
      },
      "SubscriptionChangeStatus": {
        "description": "Outcome of applying a subscription plan change.",
        "enum": [
          "applied",
          "scheduled",
          "requires_payment"
        ],
        "type": "string"
      },
      "SubscriptionLifecycleResult": {
        "properties": {
          "cancel_at": {
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "cancel_at_period_end": {
            "type": "boolean"
          }
        },
        "required": [
          "cancel_at_period_end",
          "cancel_at"
        ],
        "type": "object"
      },
      "TenantBillingAccount": {
        "properties": {
          "billing_email": {
            "format": "email",
            "type": [
              "string",
              "null"
            ]
          },
          "stripe_customer_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id"
        ],
        "type": "object"
      },
      "TenantInvitation": {
        "properties": {
          "accepted_at": {
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "email": {
            "format": "email",
            "type": "string"
          },
          "expires_at": {
            "format": "date-time",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "invited_by": {
            "format": "uuid",
            "type": "string"
          },
          "last_sent_at": {
            "format": "date-time",
            "type": "string"
          },
          "revoked_at": {
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "send_count": {
            "format": "int32",
            "minimum": 1,
            "type": "integer"
          },
          "status": {
            "enum": [
              "pending",
              "accepted",
              "revoked",
              "expired"
            ],
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "email",
          "role_id",
          "status",
          "invited_by",
          "created_at",
          "expires_at",
          "last_sent_at",
          "send_count"
        ],
        "type": "object"
      },
      "TenantInvitationPage": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/TenantInvitation"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "minimum": 1,
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "maximum": 100,
            "minimum": 1,
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "total_pages": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total",
          "total_pages"
        ],
        "type": "object"
      },
      "TenantMemberResponse": {
        "description": "One tenant member in a list response.",
        "properties": {
          "created_at": {
            "description": "When the membership was created (RFC3339)",
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "role_id": {
            "format": "uuid",
            "type": "string"
          },
          "role_name": {
            "type": "string"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "user_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id",
          "user_id",
          "email",
          "name",
          "role_id",
          "role_name",
          "created_at",
          "row_version"
        ],
        "type": "object"
      },
      "TenantPageResponse": {
        "description": "Page wrapper specialized for Tenant (optional; you can also use Page<TenantResponse>)",
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/TenantResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "TenantPlanAssignment": {
        "properties": {
          "cancel_at": {
            "description": "Scheduled Stripe cancellation time, when present.",
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "cancel_at_period_end": {
            "description": "Whether Stripe will cancel the subscription at the current period end.",
            "type": "boolean"
          },
          "current_period_end": {
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "current_period_start": {
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "pending_change_at": {
            "description": "When the pending change is scheduled to take effect or its payment window expires, when Stripe provides a timestamp.",
            "format": "date-time",
            "type": [
              "string",
              "null"
            ]
          },
          "pending_change_type": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/PendingChangeType"
              },
              {
                "type": "null"
              }
            ],
            "description": "Discriminator for the unresolved plan change, or null when no plan change is pending."
          },
          "pending_plan_code": {
            "description": "Target plan for a scheduled downgrade or payment-required upgrade.",
            "type": [
              "string",
              "null"
            ]
          },
          "plan_code": {
            "type": "string"
          },
          "source": {
            "enum": [
              "default",
              "migration",
              "stripe",
              "manual"
            ],
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "stripe_subscription_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id",
          "plan_code",
          "source",
          "stripe_subscription_id",
          "status",
          "current_period_start",
          "current_period_end",
          "cancel_at_period_end",
          "cancel_at",
          "pending_plan_code",
          "pending_change_type",
          "pending_change_at"
        ],
        "type": "object"
      },
      "TenantResponse": {
        "description": "Public response for a Tenant",
        "properties": {
          "created_at": {
            "description": "RFC3339 UTC",
            "example": "2025-10-17T10:02:00Z",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "row_version": {
            "description": "Current tenant row version for optimistic concurrency. Present on single-resource create, fetch, and update responses.",
            "format": "int64",
            "type": "integer"
          },
          "updated_at": {
            "description": "RFC3339 UTC",
            "example": "2025-10-17T10:03:00Z",
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "TenantUsersResponse": {
        "properties": {
          "users": {
            "items": {
              "$ref": "#/components/schemas/UserBasicResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "users"
        ],
        "type": "object"
      },
      "TicketExternalLinkPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/TicketExternalLinkResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "TicketExternalLinkResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object"
          },
          "row_version": {
            "format": "int64",
            "type": "integer"
          },
          "ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "ticket_id",
          "kind",
          "label",
          "url",
          "metadata",
          "created_at",
          "updated_at",
          "row_version"
        ],
        "type": "object"
      },
      "TicketLabelsRequest": {
        "properties": {
          "label_ids": {
            "description": "Must not be empty; membership enforced by UC/DB",
            "example": [
              "6b6f1b8f-6a4d-400c-83b8-0a6b0fca1d3b"
            ],
            "items": {
              "format": "uuid",
              "type": "string"
            },
            "maxItems": 100,
            "minItems": 1,
            "type": "array"
          }
        },
        "required": [
          "label_ids"
        ],
        "type": "object"
      },
      "TicketLabelsResponse": {
        "properties": {
          "labels": {
            "items": {
              "$ref": "#/components/schemas/LabelResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "labels"
        ],
        "type": "object"
      },
      "TicketListItemResponse": {
        "properties": {
          "assignee_id": {
            "description": "User currently assigned to the ticket.",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "example": "2025-10-17T10:02:00Z",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "key": {
            "type": "string"
          },
          "priority": {
            "$ref": "#/components/schemas/PriorityLevel"
          },
          "reporter_id": {
            "description": "User who reported the ticket.",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "row_version": {
            "description": "Optimistic-concurrency version. Clients may derive a strong ticket ETag when an intermediary does not expose the response header.",
            "format": "int64",
            "type": "integer"
          },
          "status": {
            "$ref": "#/components/schemas/TicketStatus"
          },
          "title": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "key",
          "title",
          "status",
          "priority",
          "row_version",
          "reporter_id",
          "assignee_id",
          "created_at"
        ],
        "type": "object"
      },
      "TicketListPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/TicketListItemResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "TicketRelationResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "created_by": {
            "format": "uuid",
            "type": "string"
          },
          "from_ticket_id": {
            "format": "uuid",
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "note": {
            "type": [
              "string",
              "null"
            ]
          },
          "relation_type": {
            "$ref": "#/components/schemas/TicketRelationTypeDto"
          },
          "to_ticket_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "id",
          "from_ticket_id",
          "to_ticket_id",
          "relation_type",
          "created_by",
          "created_at"
        ],
        "type": "object"
      },
      "TicketRelationTypeDto": {
        "enum": [
          "BLOCKS",
          "IS_BLOCKED_BY",
          "DUPLICATES",
          "IS_DUPLICATED_BY",
          "RELATES_TO",
          "PARENT_OF",
          "CHILD_OF"
        ],
        "type": "string"
      },
      "TicketResponse": {
        "properties": {
          "assignee_id": {
            "description": "User currently assigned to the ticket.",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "description": "RFC3339 UTC timestamp, e.g. \"2025-10-17T10:02:00Z\"",
            "example": "2025-10-17T10:02:00Z",
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "priority": {
            "$ref": "#/components/schemas/PriorityLevel"
          },
          "project_key": {
            "type": "string"
          },
          "reporter_id": {
            "description": "User who reported the ticket.",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/TicketStatus"
          },
          "title": {
            "type": "string"
          },
          "type": {
            "$ref": "#/components/schemas/TicketType"
          }
        },
        "required": [
          "id",
          "project_key",
          "title",
          "type",
          "status",
          "priority",
          "reporter_id",
          "assignee_id",
          "created_at"
        ],
        "type": "object"
      },
      "TicketStatus": {
        "description": "Workflow status",
        "enum": [
          "backlog",
          "todo",
          "in_progress",
          "pr_opened",
          "quality_gate_running",
          "needs_refinement",
          "awaiting_review",
          "ready_for_review",
          "blocked",
          "done",
          "cancelled"
        ],
        "example": "todo",
        "type": "string"
      },
      "TicketType": {
        "description": "Type of ticket",
        "enum": [
          "bug",
          "task",
          "story",
          "epic",
          "incident"
        ],
        "example": "task",
        "type": "string"
      },
      "TicketWatcherResponse": {
        "description": "------------------------------\nWatchers\n------------------------------\nA single watcher of a ticket.",
        "properties": {
          "added_at": {
            "description": "When they started watching, RFC3339 timestamp.",
            "example": "2025-10-26T18:43:12Z",
            "type": "string"
          },
          "user_id": {
            "description": "The user watching this ticket.",
            "example": "c0a80101-0000-0000-0000-000000000002",
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "user_id",
          "added_at"
        ],
        "type": "object"
      },
      "TicketWatchersListResponse": {
        "properties": {
          "watchers": {
            "items": {
              "$ref": "#/components/schemas/TicketWatcherResponse"
            },
            "type": "array"
          }
        },
        "required": [
          "watchers"
        ],
        "type": "object"
      },
      "UpdateAgentRunRequest": {
        "properties": {
          "ended_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Omit to leave unchanged; send null to clear the field."
          },
          "error_message": {
            "description": "Omit to leave unchanged; send null to clear the field.",
            "maxLength": 5000,
            "type": [
              "string",
              "null"
            ]
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object"
          },
          "output_summary": {
            "description": "Omit to leave unchanged; send null to clear the field.",
            "maxLength": 5000,
            "type": [
              "string",
              "null"
            ]
          },
          "started_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Omit to leave unchanged; send null to clear the field."
          },
          "status": {
            "description": "Next run status. Terminal runs cannot transition to a different status.",
            "enum": [
              "queued",
              "running",
              "succeeded",
              "failed",
              "cancelled"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          }
        },
        "type": "object"
      },
      "UpdateAgentRunStepRequest": {
        "properties": {
          "metadata": {
            "additionalProperties": true,
            "type": "object"
          },
          "status": {
            "enum": [
              "pending",
              "running",
              "completed",
              "failed"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "maxLength": 300,
            "minLength": 1,
            "type": "string"
          }
        },
        "type": "object"
      },
      "UpdateApiKeyRequest": {
        "properties": {
          "expires_at": {
            "format": "date-time",
            "nullable": true,
            "type": "string"
          },
          "name": {
            "maxLength": 120,
            "minLength": 1,
            "type": "string"
          },
          "project_id": {
            "format": "uuid",
            "nullable": true,
            "type": "string"
          },
          "scopes": {
            "description": "Server-side scopes to replace on the API key.",
            "items": {
              "enum": [
                "tickets:read",
                "tickets:write",
                "tickets:delete",
                "projects:read",
                "projects:write",
                "webhooks:read",
                "webhooks:write",
                "api_keys:read",
                "api_keys:write",
                "api_keys:create",
                "api_keys:update",
                "api_keys:revoke",
                "audit:read",
                "agents:read",
                "agents:write",
                "agents:workers:register",
                "agents:workers:heartbeat",
                "agents:workers:maintain",
                "agents:workers:credentials",
                "agents:runs:read",
                "agents:runs:create",
                "agents:runs:claim",
                "agents:runs:update",
                "agents:steps:read",
                "agents:steps:create",
                "agents:steps:update",
                "agents:steps:delete",
                "agents:links:read",
                "agents:links:create",
                "agents:links:update",
                "agents:links:delete",
                "agents:quality_gates:read",
                "agents:quality_gates:create",
                "agents:quality_gates:update",
                "agents:quality_gates:delete"
              ],
              "type": "string"
            },
            "minItems": 1,
            "type": "array",
            "uniqueItems": true
          }
        },
        "type": "object"
      },
      "UpdateCommentRequest": {
        "description": "------------------------------\nUpdate (partial)\n------------------------------\nPartial update. Only `body` is mutable for now.\nOmit to ignore; when present it must be non-empty.",
        "properties": {
          "body": {
            "example": "Minor edit after review.",
            "minLength": 1,
            "type": [
              "string",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "UpdateCustomFieldDefinitionRequest": {
        "properties": {
          "description": {
            "example": "Updated description",
            "nullable": true,
            "type": [
              "string",
              "null"
            ]
          },
          "is_archived": {
            "example": false,
            "type": [
              "boolean",
              "null"
            ]
          },
          "is_required": {
            "example": true,
            "type": [
              "boolean",
              "null"
            ]
          },
          "name": {
            "example": "Customer Impact",
            "type": [
              "string",
              "null"
            ]
          },
          "options": {
            "items": {
              "$ref": "#/components/schemas/CustomFieldOptionRequest"
            },
            "type": [
              "array",
              "null"
            ]
          },
          "position": {
            "example": 20,
            "format": "int32",
            "type": [
              "integer",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "UpdateLabelRequest": {
        "properties": {
          "color": {
            "example": "#0000FF",
            "maxLength": 32,
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "example": "Internal platform / SRE",
            "maxLength": 500,
            "type": [
              "string",
              "null"
            ]
          },
          "is_archived": {
            "example": false,
            "type": [
              "boolean",
              "null"
            ]
          },
          "name": {
            "example": "Platform",
            "maxLength": 100,
            "minLength": 1,
            "type": [
              "string",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "UpdateProjectRequest": {
        "properties": {
          "description": {
            "description": "Change description (omit / null / string)",
            "example": "Updated description",
            "type": [
              "string",
              "null"
            ]
          },
          "is_archived": {
            "description": "Archive / unarchive flag (omit => ignore)",
            "example": false,
            "type": [
              "boolean",
              "null"
            ]
          },
          "key": {
            "description": "Change project key",
            "example": "DEMO2",
            "maxLength": 10,
            "minLength": 2,
            "pattern": "^[A-Z][A-Z0-9]{1,9}$",
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "description": "Change project name",
            "example": "Updated Project Name",
            "maxLength": 200,
            "minLength": 1,
            "type": [
              "string",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "UpdateQualityGateResultRequest": {
        "properties": {
          "checks": {
            "items": {},
            "type": "array"
          },
          "status": {
            "enum": [
              "running",
              "passed",
              "failed"
            ],
            "maxLength": 40,
            "minLength": 1,
            "type": "string"
          },
          "summary": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "UpdateSprintRequest": {
        "properties": {
          "ends_at": {
            "example": "2025-01-14T00:00:00Z",
            "type": [
              "string",
              "null"
            ]
          },
          "goal": {
            "example": "Updated goal text",
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "example": "Sprint 1 - revised",
            "type": [
              "string",
              "null"
            ]
          },
          "starts_at": {
            "example": "2025-01-01T00:00:00Z",
            "type": [
              "string",
              "null"
            ]
          },
          "state": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/SprintState"
              }
            ]
          }
        },
        "required": [
          "starts_at",
          "ends_at"
        ],
        "type": "object"
      },
      "UpdateTenantRequest": {
        "description": "------------------------------\nUpdate Tenant (partial)\n------------------------------\nOnly name can change (non-nullable)",
        "properties": {
          "name": {
            "description": "New tenant name",
            "example": "Acme International",
            "maxLength": 200,
            "minLength": 1,
            "type": [
              "string",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "UpdateTicketExternalLinkRequest": {
        "properties": {
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "kind": {
            "maxLength": 80,
            "minLength": 1,
            "type": "string"
          },
          "label": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object"
          },
          "url": {
            "format": "uri",
            "maxLength": 2048,
            "type": "string"
          }
        },
        "type": "object"
      },
      "UpdateTicketRequest": {
        "description": "------------------------------\nUpdate (partial)\n------------------------------\nPartial update. Tri-state fields use: omitted=ignore, null=clear, value=set.",
        "properties": {
          "assignee_id": {
            "description": "Change assignee (omit/`null`/UUID)",
            "example": "c0a80101-0000-0000-0000-000000000002",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "description": {
            "description": "New description",
            "example": "New description",
            "type": [
              "string",
              "null"
            ]
          },
          "due_date": {
            "description": "Change due date (omit/`null`/\"YYYY-MM-DD\")",
            "example": "2026-01-31",
            "format": "date",
            "type": [
              "string",
              "null"
            ]
          },
          "parent_id": {
            "description": "Change parent (omit/`null`/UUID)",
            "example": "a9dbb3b1-3cf1-45b8-9b61-9f3d8c9b3a22",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "priority": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/PriorityLevel",
                "description": "Change priority"
              }
            ]
          },
          "reporter_id": {
            "description": "Change reporter (omit to ignore)",
            "example": "c0a80101-0000-0000-0000-000000000001",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "sprint_id": {
            "description": "Change sprint (omit/`null`/UUID)",
            "example": "f7f9f2a1-0e11-4e4e-9e9a-33be5d2f4e77",
            "format": "uuid",
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/TicketStatus",
                "description": "Change status"
              }
            ]
          },
          "story_points": {
            "description": "Change story points (omit/`null`/number)",
            "example": 5,
            "format": "double",
            "type": [
              "number",
              "null"
            ]
          },
          "title": {
            "description": "New title",
            "example": "Fix title",
            "maxLength": 200,
            "minLength": 1,
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/TicketType",
                "description": "Change ticket type"
              }
            ]
          }
        },
        "type": "object"
      },
      "UpdateUserRequest": {
        "properties": {
          "email": {
            "description": "Request a new login email; will only become effective after validation.",
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "description": "Only self or admins can change; enforced via RBAC",
            "type": [
              "string",
              "null"
            ]
          }
        },
        "type": "object"
      },
      "UpdateWebhookRequest": {
        "properties": {
          "enabled": {
            "type": "boolean"
          },
          "event_types": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "name": {
            "maxLength": 200,
            "minLength": 1,
            "type": "string"
          },
          "project_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "url": {
            "maxLength": 2048,
            "minLength": 1,
            "type": "string"
          }
        },
        "type": "object"
      },
      "UpsertAgentRunTokenConsumptionRequest": {
        "properties": {
          "cached_input_tokens": {
            "default": 0,
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "input_tokens": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "output_tokens": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          },
          "provider": {
            "maxLength": 80,
            "minLength": 1,
            "type": "string"
          },
          "total_tokens": {
            "format": "int64",
            "minimum": 0,
            "type": "integer"
          }
        },
        "required": [
          "provider",
          "input_tokens",
          "output_tokens",
          "total_tokens"
        ],
        "type": "object"
      },
      "UpsertProjectMemberBody": {
        "properties": {
          "role_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "role_id"
        ],
        "type": "object"
      },
      "UpsertTenantMemberBody": {
        "properties": {
          "role_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "role_id"
        ],
        "type": "object"
      },
      "UsageCounter": {
        "properties": {
          "billing_period_end": {
            "format": "date",
            "type": "string"
          },
          "billing_period_start": {
            "format": "date",
            "type": "string"
          },
          "metric": {
            "type": "string"
          },
          "quantity": {
            "format": "int64",
            "type": "integer"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "tenant_id",
          "metric",
          "billing_period_start",
          "billing_period_end",
          "quantity"
        ],
        "type": "object"
      },
      "UsageResponse": {
        "properties": {
          "counters": {
            "items": {
              "$ref": "#/components/schemas/UsageCounter"
            },
            "type": "array"
          }
        },
        "required": [
          "counters"
        ],
        "type": "object"
      },
      "UserBasicResponse": {
        "properties": {
          "created_at": {
            "type": "string"
          },
          "email": {
            "example": "owner@acme.test",
            "type": "string"
          },
          "id": {
            "example": "9eb20a5d-12cf-4c98-a392-3fd6dd7c1154",
            "format": "uuid",
            "type": "string"
          },
          "is_active": {
            "type": "boolean"
          },
          "name": {
            "example": "Owner Name",
            "type": "string"
          }
        },
        "required": [
          "id",
          "email",
          "name",
          "is_active",
          "created_at"
        ],
        "type": "object"
      },
      "UserListResponse": {
        "properties": {
          "avatar_url": {
            "description": "Optional avatar URL",
            "example": "https://example.com/avatar.png",
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "description": "RFC3339 UTC timestamp",
            "example": "2025-10-17T10:02:00Z",
            "type": "string"
          },
          "email": {
            "description": "Email address",
            "example": "alice@example.com",
            "type": "string"
          },
          "id": {
            "description": "User ID",
            "example": "c0a80101-0000-0000-0000-000000000123",
            "format": "uuid",
            "type": "string"
          },
          "is_active": {
            "description": "Whether the user is active",
            "example": true,
            "type": "boolean"
          },
          "name": {
            "description": "Display name",
            "example": "Alice Doe",
            "type": "string"
          },
          "rank": {
            "description": "Optional search rank (0.0 if not applicable)",
            "example": 0.97,
            "format": "float",
            "type": "number"
          },
          "updated_at": {
            "description": "RFC3339 UTC timestamp",
            "example": "2025-10-17T10:02:00Z",
            "type": "string"
          }
        },
        "required": [
          "id",
          "email",
          "name",
          "is_active",
          "created_at",
          "updated_at",
          "rank"
        ],
        "type": "object"
      },
      "UserPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/UserListResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "page",
          "size",
          "total"
        ],
        "type": "object"
      },
      "UserResponse": {
        "properties": {
          "avatar_url": {
            "description": "Public profile image (may be null)",
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "email": {
            "example": "owner@acme.test",
            "type": "string"
          },
          "id": {
            "example": "9eb20a5d-12cf-4c98-a392-3fd6dd7c1154",
            "format": "uuid",
            "type": "string"
          },
          "is_active": {
            "description": "Soft-active flag",
            "type": "boolean"
          },
          "name": {
            "example": "Owner Name",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          }
        },
        "required": [
          "id",
          "email",
          "name",
          "is_active",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "Vec": {
        "items": {
          "description": "One tenant member in a list response.",
          "properties": {
            "created_at": {
              "description": "When the membership was created (RFC3339)",
              "type": "string"
            },
            "email": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "role_id": {
              "format": "uuid",
              "type": "string"
            },
            "role_name": {
              "type": "string"
            },
            "tenant_id": {
              "format": "uuid",
              "type": "string"
            },
            "user_id": {
              "format": "uuid",
              "type": "string"
            }
          },
          "required": [
            "tenant_id",
            "user_id",
            "email",
            "name",
            "role_id",
            "role_name",
            "created_at"
          ],
          "type": "object"
        },
        "type": "array"
      },
      "VerifyEmailRequest": {
        "properties": {
          "token": {
            "type": "string"
          }
        },
        "required": [
          "token"
        ],
        "type": "object"
      },
      "VerifyEmailResponse": {
        "properties": {
          "status": {
            "type": "string"
          }
        },
        "required": [
          "status"
        ],
        "type": "object"
      },
      "WebhookDeliveryPageResponse": {
        "properties": {
          "items": {
            "items": {
              "$ref": "#/components/schemas/WebhookDeliveryResponse"
            },
            "type": "array"
          },
          "page": {
            "format": "int64",
            "type": "integer"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "total": {
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "items",
          "total",
          "page",
          "size"
        ],
        "type": "object"
      },
      "WebhookDeliveryResponse": {
        "properties": {
          "attempt_count": {
            "format": "int32",
            "type": "integer"
          },
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "dead_lettered_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "delivered_at": {
            "anyOf": [
              {
                "format": "date-time",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "event_id": {
            "format": "uuid",
            "type": "string"
          },
          "event_type": {
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "last_error_kind": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "last_error_message": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "next_attempt_at": {
            "format": "date-time",
            "type": "string"
          },
          "project_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "enum": [
              "pending",
              "delivering",
              "delivered",
              "retrying",
              "dead_lettered"
            ],
            "type": "string"
          },
          "subscription_id": {
            "format": "uuid",
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "subscription_id",
          "event_id",
          "event_type",
          "url",
          "status",
          "attempt_count",
          "next_attempt_at",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "WebhookSubscriptionResponse": {
        "properties": {
          "created_at": {
            "format": "date-time",
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          },
          "event_types": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "project_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          },
          "updated_at": {
            "format": "date-time",
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "tenant_id",
          "name",
          "url",
          "event_types",
          "enabled",
          "created_at",
          "updated_at"
        ],
        "type": "object"
      },
      "WorkerDeviceAuthorizationView": {
        "properties": {
          "agent_version": {
            "type": "string"
          },
          "architecture": {
            "type": "string"
          },
          "display_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "expires_at": {
            "format": "date-time",
            "type": "string"
          },
          "hostname": {
            "type": "string"
          },
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "installation_id": {
            "format": "uuid",
            "type": "string"
          },
          "operating_system": {
            "type": "string"
          },
          "previously_linked": {
            "type": "boolean"
          },
          "requested_scopes": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "status": {
            "enum": [
              "pending",
              "approved",
              "denied",
              "expired",
              "consumed"
            ],
            "type": "string"
          },
          "worker_id": {
            "anyOf": [
              {
                "format": "uuid",
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "id",
          "status",
          "installation_id",
          "hostname",
          "display_name",
          "operating_system",
          "architecture",
          "agent_version",
          "requested_scopes",
          "expires_at",
          "worker_id",
          "previously_linked"
        ],
        "type": "object"
      },
      "WorkerDeviceCredential": {
        "properties": {
          "access_token": {
            "description": "One-time worker API credential. Returned only by a successful token exchange.",
            "type": "string"
          },
          "expires_in": {
            "format": "int64",
            "minimum": 1,
            "type": "integer"
          },
          "instance": {
            "$ref": "#/components/schemas/WorkerDeviceTokenInstance"
          },
          "scopes": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "token_type": {
            "enum": [
              "Bearer"
            ],
            "type": "string"
          },
          "worker": {
            "$ref": "#/components/schemas/WorkerDeviceTokenWorker"
          }
        },
        "required": [
          "access_token",
          "token_type",
          "expires_in",
          "worker",
          "instance",
          "scopes"
        ],
        "type": "object"
      },
      "WorkerDeviceStatusResponse": {
        "properties": {
          "status": {
            "enum": [
              "denied"
            ],
            "type": "string"
          }
        },
        "required": [
          "status"
        ],
        "type": "object"
      },
      "WorkerDeviceTokenErrorResponse": {
        "properties": {
          "error": {
            "enum": [
              "authorization_pending",
              "slow_down",
              "access_denied",
              "expired_token",
              "consumed_token",
              "invalid_device_code"
            ],
            "type": "string"
          },
          "interval": {
            "format": "int32",
            "minimum": 1,
            "type": "integer"
          }
        },
        "required": [
          "error"
        ],
        "type": "object"
      },
      "WorkerDeviceTokenInstance": {
        "properties": {
          "url": {
            "format": "uri",
            "type": "string"
          }
        },
        "required": [
          "url"
        ],
        "type": "object"
      },
      "WorkerDeviceTokenRequest": {
        "properties": {
          "client_id": {
            "enum": [
              "rustgrid-agent"
            ],
            "type": "string"
          },
          "device_code": {
            "minLength": 1,
            "type": "string"
          }
        },
        "required": [
          "client_id",
          "device_code"
        ],
        "type": "object"
      },
      "WorkerDeviceTokenWorker": {
        "properties": {
          "id": {
            "format": "uuid",
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "tenant_id": {
            "format": "uuid",
            "type": "string"
          }
        },
        "required": [
          "id",
          "name",
          "tenant_id"
        ],
        "type": "object"
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "bearerFormat": "JWT or rgk API key",
        "description": "Use a tenant-scoped JWT returned by `/auth/activate-tenant`, or an API key using the `rgk_` prefix. Project-scoped API keys are accepted only on routes within their bound project scope.",
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "externalDocs": {
    "description": "Endpoint summary generated from this OpenAPI document",
    "url": "docs/api_endpoints.md"
  },
  "info": {
    "contact": {
      "email": "dev@rustgrid.com",
      "name": "RustGrid"
    },
    "description": "Headless, tenant-aware ticketing API for RustGrid.\n\nUse `Authorization: Bearer <tenant-scoped JWT>` for user traffic or `Authorization: Bearer rgk_<secret>` for API-key automation. Do not send `X-Tenant-Id`; tenant context is derived from credentials and tenant headers are rejected.\n\nMutating resource routes use strong ETags with `If-Match` where optimistic concurrency is required. Supported mutating routes accept `Idempotency-Key` so retries can replay the original outcome instead of duplicating side effects. Every response includes or propagates `x-request-id` for tracing and support.",
    "license": {
      "identifier": "MIT",
      "name": "MIT"
    },
    "title": "RustGrid API",
    "version": "v1"
  },
  "openapi": "3.1.0",
  "paths": {
    "/api/v1/account/deactivate": {
      "patch": {
        "description": "\nDeactivate the currently authenticated user account.\n\nBehavior:\n- Requires a valid Bearer JWT (authenticated user).\n- Requires the user's **current password** for confirmation.\n- Sets `is_active = FALSE` for the user in the database.\n",
        "operationId": "deactivateAccount",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeactivateAccountRequest"
              }
            }
          },
          "description": "Current password used to confirm account deactivation.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeactivateAccountResponse"
                }
              }
            },
            "description": "Account deactivated successfully.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request – invalid payload or password hash issues.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – current password mismatch or inactive user.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Deactivate the current user account",
        "tags": [
          "account"
        ]
      }
    },
    "/api/v1/account/me": {
      "get": {
        "description": "\nReturns information about the currently authenticated user derived from the JWT and request context.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- The JWT and associated middleware populate the `Ctx` (request context),\n  which includes user, tenant, role, and permissions information.\n\nBehavior:\n- No database lookup is performed; the data is fully derived from the request context.\n- Useful for clients to introspect which user and tenant are currently active,\n  as well as the permissions granted by the current role.\n\nResponse:\n- Returns `200 OK` with a `MeResponse` object describing the authenticated user.\n- Includes the user ID, tenant ID, role ID (if any), and a list of granted permissions.\n\nRate limiting:\n- Typically not rate limited, but may be subject to general request limits.\n",
        "operationId": "getCurrentUser",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MeResponse"
                }
              }
            },
            "description": "Authenticated user context successfully retrieved",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT token",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get current authenticated user",
        "tags": [
          "account"
        ]
      }
    },
    "/api/v1/account/password": {
      "patch": {
        "description": "\nChange the password of the currently authenticated user.\n\nRequirements:\n- Caller must be authenticated (valid Bearer JWT).\n- Caller must provide their **current password** and the desired new password.\n- The user must be active.\n",
        "operationId": "changePassword",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangePasswordRequest"
              }
            }
          },
          "description": "Current and new password.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangePasswordResponse"
                }
              }
            },
            "description": "Password changed successfully.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request – invalid payload or password hash issues.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – current password mismatch or inactive user.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Change the password of the current account",
        "tags": [
          "account"
        ]
      }
    },
    "/api/v1/account/roles": {
      "get": {
        "description": "\nRetrieve the list of roles available to the authenticated user in the current tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Behavior depends on the user's permissions:\n  - If the user has `roles:READ`, all roles in the tenant are returned.\n  - Otherwise, only the caller's own effective role is returned.\n\nMulti-tenancy:\n- Tenant is derived from the authenticated context (`Ctx`).\n- Cross-tenant access is not permitted.\n",
        "operationId": "listRoles",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListRolesResponse"
                }
              }
            },
            "description": "List of roles",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List roles within the current tenant",
        "tags": [
          "account"
        ]
      }
    },
    "/api/v1/account/users": {
      "get": {
        "description": "\nAuthorization:\n- Caller must have at least one of:\n  - `tenants:members:read`\n  - `users:read:self`\n- If the caller has `tenants:members:read` or `users:read:all`, they see the full roster.\n- Otherwise, they only see themselves.\n",
        "operationId": "listUsers",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantUsersResponse"
                }
              }
            },
            "description": "List of users",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List users within the current tenant, or just the caller",
        "tags": [
          "account"
        ]
      }
    },
    "/api/v1/activity": {
      "get": {
        "description": "\nList activity events for the caller's tenant, optionally scoped to a single resource.\n\nAuthorization:\n  - Requires Bearer JWT (`Authorization: Bearer <token>`).\n  - Requires RBAC `audit:logs:read`.\n  - Tenant guard: only events from the caller tenant are returned; cross-tenant is masked as 404.\n\nFiltering:\n  - Omit filters to get the full tenant feed.\n  - Provide **both** `resource_kind` and `resource_id` to scope to one resource (e.g., `ticket`).\n  - `resource_kind` is free-form in the query; it is stored internally in SCREAMING_SNAKE_CASE.\n\nPagination & ordering:\n  - 1-based `page`; `size` clamped to platform bounds (MAX_PAGE_SIZE_HARD).\n  - Sorted newest-first.\n\nResponse:\n  - `200 OK` with `Page<ActivityEventResponse> { items, page, size, total }`.\n  - Always includes `x-request-id` for audit/tracing.\n\nRate limiting:\n  - Standard per-route limits; `429 Too Many Requests` returns `x-ratelimit-*` headers (and `retry-after` when configured).\n\nExamples:\n  - Tenant feed: `GET /api/v1/activity?page=1&size=20`\n  - Ticket feed: `GET /api/v1/activity?resource_kind=ticket&resource_id=c0ffee00-0000-4000-9000-000000000123`\n",
        "operationId": "listActivity",
        "parameters": [
          {
            "description": "Page number (1-based)",
            "example": 1,
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size (1..=200)",
            "example": 20,
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Filter by resource kind (e.g., `ticket`, `label`, `user`)",
            "example": "ticket",
            "in": "query",
            "name": "resource_kind",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Filter by resource id",
            "example": "c0ffee00-0000-4000-9000-000000000123",
            "in": "query",
            "name": "resource_id",
            "required": false,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page_ActivityEventResponse"
                }
              }
            },
            "description": "Activity events",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid params",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (requires `audit:logs:read`)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Browse tenant activity feed",
        "tags": [
          "activity"
        ]
      }
    },
    "/api/v1/agent-runs": {
      "get": {
        "description": "Lists agent runs for a project within the authenticated tenant. Results can be filtered by run status and assigned worker.",
        "operationId": "listProjectAgentRuns",
        "parameters": [
          {
            "description": "Project identifier",
            "in": "query",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional agent run status",
            "in": "query",
            "name": "status",
            "required": false,
            "schema": {
              "enum": [
                "queued",
                "running",
                "succeeded",
                "failed",
                "cancelled"
              ],
              "type": "string"
            }
          },
          {
            "description": "Optional assigned worker identifier",
            "in": "query",
            "name": "worker_id",
            "required": false,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "default": 1,
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "default": 100,
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunPageResponse"
                }
              }
            },
            "description": "Project agent runs",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid query",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List project agent runs",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/claim-next": {
      "post": {
        "description": "Atomically claim the next eligible ticket for a worker and create a running leased agent run. Optional project, ticket status, and worker capability filters are applied before claiming.",
        "operationId": "claimNextAgentRun",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClaimNextAgentRunRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunResponse"
                }
              }
            },
            "description": "Agent run claimed",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the agent run row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Claim the next eligible agent run",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/models": {
      "get": {
        "description": "Lists the server-configured Codex models that can be selected when creating or claiming an agent run.",
        "operationId": "listAgentModels",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentModelOptionsResponse"
                }
              }
            },
            "description": "Selectable agent models",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied"
          }
        },
        "summary": "List selectable agent models",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}": {
      "patch": {
        "description": "Update the status and summary fields for an agent run in the current tenant.",
        "operationId": "updateAgentRun",
        "parameters": [
          {
            "description": "Agent run identifier",
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"agent-runs:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateAgentRunRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunResponse"
                }
              }
            },
            "description": "Agent run updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the agent run row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update an agent run",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/accept-pull-request": {
      "post": {
        "description": "Resolve the pull request from succeeded run metadata or its ticket link, verify its current open state through the tenant-owned GitHub App installation, and merge it.",
        "operationId": "acceptAgentRunPullRequest",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentPullRequestMergeResponse"
                }
              }
            },
            "description": "Pull request merged",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing run-update or GitHub-management permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run, repository binding, or associated pull request not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run is not succeeded, association is ambiguous, the pull request is not open, or App permissions are insufficient",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub merge failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Accept and merge an agent-run pull request",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/discard-pull-request": {
      "post": {
        "description": "Resolve the pull request from a succeeded run, verify it is open and unmerged through the tenant-owned GitHub App installation, and close it without merging.",
        "operationId": "discardAgentRunPullRequest",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentPullRequestDiscardResponse"
                }
              }
            },
            "description": "Pull request closed without merging",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing run-update or GitHub-management permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run, repository binding, or associated pull request not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run is not succeeded, association is ambiguous, the pull request is merged or not open, or App permissions are insufficient",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub pull request close failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Discard and close an agent-run pull request",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/events": {
      "get": {
        "description": "Replay durable agent-run events in ascending sequence order.",
        "operationId": "listAgentRunEvents",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "after_sequence",
            "required": false,
            "schema": {
              "default": 0,
              "format": "int64",
              "minimum": 0,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "default": 100,
              "format": "int64",
              "maximum": 500,
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunEventsResponse"
                }
              }
            },
            "description": "Sequenced event replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Replay agent-run events",
        "tags": [
          "agents"
        ]
      },
      "post": {
        "description": "Append a durable progress, message, or log event. Requires the bound worker credential and an active lease.",
        "operationId": "appendAgentRunEvent",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAgentRunEventRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunEventResponse"
                }
              }
            },
            "description": "Durable progress event",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid event",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not a bound worker credential",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run lease is not active",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Append an agent-run progress event",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/events/stream": {
      "get": {
        "description": "Stream durable agent-run events as SSE. Resume with Last-Event-ID or after_sequence.",
        "operationId": "streamAgentRunEvents",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "Last-Event-ID",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 0,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "after_sequence",
            "required": false,
            "schema": {
              "default": 0,
              "format": "int64",
              "minimum": 0,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "default": 100,
              "format": "int64",
              "maximum": 500,
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "description": "Server-sent agent-run event stream",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Stream agent-run events",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/github-token": {
      "post": {
        "description": "Issue a short-lived GitHub App installation token restricted to the claimed run repository. Requires the bound worker credential and an active lease.",
        "operationId": "issueAgentGithubToken",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentGithubTokenResponse"
                }
              }
            },
            "description": "Short-lived repository token",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "example": "no-store",
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not a bound worker credential",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run lease is not active",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub token issuance failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Issue a run-scoped GitHub token",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/lease": {
      "post": {
        "description": "Extend an active agent run claim lease for the worker that owns the run.",
        "operationId": "extendAgentRunLease",
        "parameters": [
          {
            "description": "Agent run identifier",
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExtendAgentRunLeaseRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunResponse"
                }
              }
            },
            "description": "Agent run lease extended",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the agent run row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Extend an agent run lease",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/manifest": {
      "get": {
        "description": "Resolve the claimed run to its project and single active GitHub App repository binding.",
        "operationId": "getAgentExecutionManifest",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentExecutionManifestResponse"
                }
              }
            },
            "description": "Worker execution manifest",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run or repository binding not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Repository binding is ambiguous",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get an agent execution manifest",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/pull-request": {
      "get": {
        "description": "Resolve the run-associated pull request and return its current state directly from the tenant-owned GitHub App installation.",
        "operationId": "getAgentRunPullRequestStatus",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentPullRequestStatusResponse"
                }
              }
            },
            "description": "Live pull request state",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing agent-run read permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run, repository binding, or associated pull request not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Association is ambiguous or App permissions are insufficient",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub lookup failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get live agent-run pull request state",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/steps": {
      "get": {
        "description": "List steps appended to an agent run in the current tenant.",
        "operationId": "listAgentRunSteps",
        "parameters": [
          {
            "description": "Agent run identifier",
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Page number (1-based)",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunStepPageResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List agent run steps",
        "tags": [
          "agents"
        ]
      },
      "post": {
        "description": "Append a step to an agent run in the current tenant.",
        "operationId": "appendAgentRunStep",
        "parameters": [
          {
            "description": "Agent run identifier",
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAgentRunStepRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunStepResponse"
                }
              }
            },
            "description": "Agent run step appended",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the agent run step row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Append an agent run step",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/steps/{step_id}": {
      "delete": {
        "description": "Delete an agent run step with optimistic concurrency. The step must belong to the run in the current tenant.",
        "operationId": "deleteAgentRunStep",
        "parameters": [
          {
            "description": "Agent run identifier",
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Agent run step identifier",
            "in": "path",
            "name": "step_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"agent-run-steps:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Agent run step deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete an agent run step",
        "tags": [
          "agents"
        ]
      },
      "patch": {
        "description": "Update an agent run step with optimistic concurrency. The step must belong to the run in the current tenant.",
        "operationId": "updateAgentRunStep",
        "parameters": [
          {
            "description": "Agent run identifier",
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Agent run step identifier",
            "in": "path",
            "name": "step_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"agent-run-steps:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateAgentRunStepRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunStepResponse"
                }
              }
            },
            "description": "Agent run step updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the agent run step row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update an agent run step",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-runs/{run_id}/token-consumption": {
      "get": {
        "description": "Read the canonical token consumption reported for an agent run tied to a ticket.",
        "operationId": "getAgentRunTokenConsumption",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunTokenConsumptionResponse"
                }
              }
            },
            "description": "Agent run token consumption"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run or token consumption report not found"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get agent run token consumption",
        "tags": [
          "agents"
        ]
      },
      "put": {
        "description": "Create or replace the canonical aggregate token consumption for an agent run tied to a ticket.",
        "operationId": "upsertAgentRunTokenConsumption",
        "parameters": [
          {
            "in": "path",
            "name": "run_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpsertAgentRunTokenConsumptionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunTokenConsumptionResponse"
                }
              }
            },
            "description": "Agent run token consumption stored"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid token counts"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Run not found"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Upsert agent run token consumption",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers": {
      "get": {
        "description": "List agent worker capacity",
        "operationId": "listAgentWorkers",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentWorkersResponse"
                }
              }
            },
            "description": "Tenant worker fleet with current capacity",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List agent worker capacity",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/device-authorizations": {
      "post": {
        "description": "Create a short-lived worker device authorization. The returned device_code is a one-time secret and responses are not cacheable.",
        "operationId": "startWorkerDeviceAuthorization",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartWorkerDeviceAuthorizationRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StartedWorkerDeviceAuthorization"
                }
              }
            },
            "description": "Device authorization started"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid client or device metadata"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many authorization attempts"
          }
        },
        "security": [],
        "summary": "Start worker device authorization",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/device-authorizations/token": {
      "post": {
        "description": "Poll with the opaque device code. A successful exchange returns the credential once and consumes the authorization.",
        "operationId": "exchangeWorkerDeviceAuthorization",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WorkerDeviceTokenRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkerDeviceCredential"
                }
              }
            },
            "description": "One-time worker credential"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkerDeviceTokenErrorResponse"
                }
              }
            },
            "description": "Stable device authorization state"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests"
          }
        },
        "security": [],
        "summary": "Exchange an approved worker device authorization",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/device-authorizations/{user_code}": {
      "get": {
        "description": "Return non-secret machine metadata for an operator with agents:workers:register.",
        "operationId": "getWorkerDeviceAuthorization",
        "parameters": [
          {
            "description": "Short-lived human-readable worker authorization code.",
            "in": "path",
            "name": "user_code",
            "required": true,
            "schema": {
              "pattern": "^[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}-?[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkerDeviceAuthorizationView"
                }
              }
            },
            "description": "Device authorization metadata"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid user code"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authorization not found"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Review worker device authorization metadata",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/device-authorizations/{user_code}/approve": {
      "post": {
        "description": "Atomically link the installation, rotate its prior device credential, and prepare one-time credential delivery.",
        "operationId": "approveWorkerDeviceAuthorization",
        "parameters": [
          {
            "description": "Short-lived human-readable worker authorization code.",
            "in": "path",
            "name": "user_code",
            "required": true,
            "schema": {
              "pattern": "^[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}-?[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApprovedWorkerDeviceAuthorization"
                }
              }
            },
            "description": "Device authorization approved"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid user code"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authorization not found"
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Expired, denied, consumed, or cross-tenant authorization"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Approve worker device authorization",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/device-authorizations/{user_code}/deny": {
      "post": {
        "description": "Deny a pending authorization without creating a worker credential.",
        "operationId": "denyWorkerDeviceAuthorization",
        "parameters": [
          {
            "description": "Short-lived human-readable worker authorization code.",
            "in": "path",
            "name": "user_code",
            "required": true,
            "schema": {
              "pattern": "^[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}-?[23456789ABCDEFGHJKLMNPQRSTUVWXYZ]{4}$",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkerDeviceStatusResponse"
                }
              }
            },
            "description": "Device authorization denied"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid user code"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authorization not found"
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authorization is no longer pending"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Deny worker device authorization",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/mark-stale-offline": {
      "post": {
        "description": "Mark online or busy workers offline when they have not heartbeated within the requested threshold.",
        "operationId": "markStaleAgentWorkersOffline",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MarkStaleAgentWorkersOfflineRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MarkStaleAgentWorkersOfflineResponse"
                }
              }
            },
            "description": "Workers updated",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Mark stale agent workers offline",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/register": {
      "post": {
        "description": "Register a stateless agent worker for the current tenant.",
        "operationId": "registerAgentWorker",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RegisterAgentWorkerRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentWorkerResponse"
                }
              }
            },
            "description": "Worker registered",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Register an agent worker",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/credentials": {
      "get": {
        "description": "List API key credentials associated with an agent worker in the current tenant. Plaintext API key secrets are never returned by this route.",
        "operationId": "listAgentWorkerCredentials",
        "parameters": [
          {
            "description": "Agent worker identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/AgentWorkerCredentialResponse"
                  },
                  "type": "array"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List agent worker credentials",
        "tags": [
          "agents"
        ]
      },
      "post": {
        "description": "Create a tenant-scoped rgk API key credential for an agent worker. The plaintext key is returned once in the creation response.",
        "operationId": "createAgentWorkerCredential",
        "parameters": [
          {
            "description": "Agent worker identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAgentWorkerCredentialRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedAgentWorkerCredentialResponse"
                }
              }
            },
            "description": "Agent worker credential created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create an agent worker credential",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/credentials/current/revoke": {
      "post": {
        "description": "Revoke the authenticated worker API credential. Intended for secure agent logout.",
        "operationId": "revokeCurrentWorkerCredential",
        "parameters": [
          {
            "description": "Agent worker identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RevokedCurrentWorkerCredentialResponse"
                }
              }
            },
            "description": "Current credential revoked"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Worker API key authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Credential is not bound to this worker"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Worker credential not found"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Revoke the current worker credential",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/credentials/{credential_id}": {
      "delete": {
        "description": "Revoke an agent worker credential and its underlying API key in the current tenant.",
        "operationId": "revokeAgentWorkerCredential",
        "parameters": [
          {
            "description": "Agent worker identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Agent worker credential identifier",
            "in": "path",
            "name": "credential_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentWorkerCredentialResponse"
                }
              }
            },
            "description": "Agent worker credential revoked",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Revoke an agent worker credential",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/heartbeat": {
      "post": {
        "description": "Update worker liveness and status for the current tenant.",
        "operationId": "heartbeatAgentWorker",
        "parameters": [
          {
            "description": "Agent worker identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HeartbeatAgentWorkerRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentWorkerResponse"
                }
              }
            },
            "description": "Worker heartbeat recorded",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Heartbeat an agent worker",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/manage": {
      "post": {
        "description": "Update a worker display name or set its operational state. Disabling is rejected while active runs exist; re-enabling requires a usable worker credential.",
        "operationId": "manageAgentWorker",
        "parameters": [
          {
            "description": "Agent worker identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ManageAgentWorkerRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ManagedAgentWorkerResponse"
                }
              }
            },
            "description": "Updated worker management state"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid name or status"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Authentication required"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Permission denied"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Worker not found"
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Active runs or missing usable credential block the transition"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Rename, disable, or re-enable a worker",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/queue": {
      "get": {
        "description": "Replay durable agent queue events",
        "operationId": "listAgentQueueEvents",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "after_sequence",
            "required": false,
            "schema": {
              "default": 0,
              "format": "int64",
              "minimum": 0,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "default": 100,
              "format": "int64",
              "maximum": 500,
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentQueueEventsResponse"
                }
              }
            },
            "description": "Queue events and current worker capacity",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Replay durable agent queue events",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/queue/stream": {
      "get": {
        "description": "Stream durable agent queue events",
        "operationId": "streamAgentQueueEvents",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "Last-Event-ID",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "after_sequence",
            "required": false,
            "schema": {
              "default": 0,
              "format": "int64",
              "minimum": 0,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "default": 100,
              "format": "int64",
              "maximum": 500,
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "description": "Replayable server-sent queue event stream",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Stream durable agent queue events",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/retire": {
      "post": {
        "description": "Retire an agent worker without deleting its historical records. Retirement rejects active leases, disables capacity, and revokes all worker credentials atomically. Supports Idempotency-Key for safe retries.",
        "operationId": "retireAgentWorker",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make this retirement request exactly-once.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "reason": {
                    "maxLength": 500,
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "type": "object"
              }
            }
          },
          "required": false
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentWorkerResponse"
                }
              }
            },
            "description": "Worker retired or idempotent retirement replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing agents:workers:maintain",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Worker not found in tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Worker still owns active runs",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Retire agent worker",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/agent-workers/{id}/runs": {
      "get": {
        "description": "List actively leased running agent runs assigned to one worker across all projects in the current tenant.",
        "operationId": "listAgentWorkerRuns",
        "parameters": [
          {
            "description": "Worker identifier bound to the worker credential",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "status",
            "required": false,
            "schema": {
              "default": "running",
              "enum": [
                "running"
              ],
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "default": 1,
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "default": 100,
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentWorkerRunPageResponse"
                }
              }
            },
            "description": "Actively leased worker runs across the tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid query",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Worker credential is not bound to this worker",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Worker not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Recover active runs assigned to a worker",
        "tags": [
          "agents"
        ]
      }
    },
    "/api/v1/api-keys": {
      "get": {
        "description": "Lists API-key metadata for the current tenant. Full keys and key hashes are never returned.",
        "operationId": "getApiKeys",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/ApiKeyResponse"
                  },
                  "type": "array"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List API keys",
        "tags": [
          "api-keys"
        ]
      },
      "post": {
        "description": "Creates a scoped machine credential. The full rgk_ key is returned only in this response.",
        "operationId": "createApiKeys",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateApiKeyRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateApiKeyResponse"
                }
              }
            },
            "description": "Created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create an API key",
        "tags": [
          "api-keys"
        ]
      }
    },
    "/api/v1/api-keys/{id}": {
      "delete": {
        "description": "Revoke an API key",
        "operationId": "deleteApiKeysId",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Revoke an API key",
        "tags": [
          "api-keys"
        ]
      },
      "patch": {
        "description": "Update API-key metadata such as name, project scope, granted scopes, or expiration. The key secret is never returned or rotated by this operation.",
        "operationId": "patchApiKeysId",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateApiKeyRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyResponse"
                }
              }
            },
            "description": "Updated",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update an API key",
        "tags": [
          "api-keys"
        ]
      }
    },
    "/api/v1/attachments/{attachment_id}": {
      "delete": {
        "description": "\nSoft-delete an attachment and attempt to remove the backing object from storage.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:attachment:delete`.\n- Caller must belong to the same tenant as the attachment.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Attachments from other tenants are masked as `404 Not Found`.\n- Delete mutations are tenant-scoped at the repository layer.\n\nDeletion semantics:\n- The database row is soft-deleted first by setting `status=deleted` and `deleted_at`.\n- The backing object delete is best-effort. Storage deletion failures are logged for operations follow-up\n  but do not roll back the soft delete.\n- Deleted attachments are excluded from list, lookup, completion, and download flows.\n\nResponse:\n- Returns `204 No Content` when the attachment is soft-deleted.\n\nRate limiting:\n- Subject to the attachment route timeout, concurrency, and global rate-limit layers.\n",
        "operationId": "deleteAttachment",
        "parameters": [
          {
            "description": "Attachment ID to delete",
            "in": "path",
            "name": "attachment_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Attachment soft-deleted successfully",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized - missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden - caller lacks `tickets:attachment:delete` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found - attachment does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete attachment",
        "tags": [
          "attachments"
        ]
      }
    },
    "/api/v1/attachments/{attachment_id}/complete": {
      "post": {
        "description": "\nConfirm that a previously initiated direct-to-storage upload has completed.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:attachment:upload`.\n- Caller must belong to the same tenant as the attachment.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Attachments from other tenants are masked as `404 Not Found`.\n- State transitions are tenant-scoped at the repository layer.\n\nUpload lifecycle:\n- The attachment must have been created by `POST /api/v1/tickets/{id}/attachments:initiate`.\n- The service verifies object existence and size through storage `HEAD` metadata.\n- The object size must be greater than zero and within the configured attachment limit.\n- Detected storage content type, when available, is reconciled with the originally requested filename/type policy.\n- On first successful completion, the attachment moves from `pending_upload` to `uploaded`\n  and an `attachment.scan.requested` job is enqueued.\n- Clean scan results enqueue `attachment.processing.requested`; processing extracts lightweight\n  metadata and then marks the attachment `ready`.\n- The operation is idempotent after the initial transition: repeated calls return the current attachment status.\n\nResponse:\n- Returns `200 OK` with the attachment ID, current status, and virus scan status.\n- A completed upload is not downloadable until asynchronous scanning and processing mark it `ready`\n  and `clean`.\n\nRate limiting:\n- Subject to the attachment route timeout, concurrency, and global rate-limit layers.\n",
        "operationId": "completeAttachmentUpload",
        "parameters": [
          {
            "description": "Attachment ID returned by initiate",
            "in": "path",
            "name": "attachment_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompleteAttachmentUploadRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompleteAttachmentUploadResponse"
                }
              }
            },
            "description": "Attachment completion accepted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Uploaded object is missing, empty, too large, or violates attachment policy",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized - missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden - caller lacks `tickets:attachment:upload` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found - attachment does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Complete ticket attachment upload",
        "tags": [
          "attachments"
        ]
      }
    },
    "/api/v1/attachments/{attachment_id}/download": {
      "get": {
        "description": "\nCreate a short-lived presigned URL for downloading a ready attachment.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:read`.\n- Caller must belong to the same tenant as the attachment.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Attachments from other tenants are masked as `404 Not Found`.\n- Repository reads are tenant-scoped and exclude soft-deleted rows.\n\nSafety and lifecycle:\n- The attachment must be `ready` and virus scan status must be `clean`.\n- Pending, uploaded, scanning, processing, quarantined, rejected, and deleted attachments are not downloadable.\n- The response contains a presigned storage URL only; the API does not proxy object bytes.\n- URLs are short-lived and include a content-disposition filename hint when supported by the storage backend.\n\nResponse:\n- Returns `200 OK` with the presigned URL and its expiration timestamp.\n- Clients should treat the URL as sensitive bearer material and avoid logging it.\n\nRate limiting:\n- Subject to the attachment route timeout, concurrency, and global rate-limit layers.\n",
        "operationId": "downloadAttachment",
        "parameters": [
          {
            "description": "Attachment ID to download",
            "in": "path",
            "name": "attachment_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AttachmentDownloadResponse"
                }
              }
            },
            "description": "Presigned download URL created successfully",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Attachment is not ready or has not passed virus scanning",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized - missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden - caller lacks `tickets:read` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found - attachment does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create attachment download URL",
        "tags": [
          "attachments"
        ]
      }
    },
    "/api/v1/attachments/{attachment_id}/variants/{kind}/download": {
      "get": {
        "description": "\nCreate a short-lived presigned URL for downloading a generated attachment variant such as\n`thumb_256` or `pdf_page_1_web`.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:read`.\n- Caller must belong to the same tenant as the parent attachment.\n\nSafety and lifecycle:\n- The parent attachment must be `ready` and virus scan status must be `clean`.\n- The requested variant must exist, be marked `ready`, and belong to the parent attachment.\n- The response contains a presigned storage URL only; the API does not proxy object bytes.\n",
        "operationId": "downloadAttachmentVariant",
        "parameters": [
          {
            "description": "Parent attachment ID",
            "in": "path",
            "name": "attachment_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Variant kind, for example `thumb_256` or `pdf_page_1_web`",
            "in": "path",
            "name": "kind",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AttachmentDownloadResponse"
                }
              }
            },
            "description": "Presigned variant URL created successfully",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid variant kind or parent attachment is not ready",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized - missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden - caller lacks `tickets:read` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found - attachment or ready variant does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create attachment variant download URL",
        "tags": [
          "attachments"
        ]
      }
    },
    "/api/v1/auth/activate-tenant": {
      "post": {
        "description": "\nMint a tenant-scoped JWT for a specific tenant membership.\n\nFlow:\n- Client logs in and receives a user-scoped token (no tenant_id).\n- Client selects a tenant and calls this endpoint with the selected tenant_id.\n- Server verifies membership and returns a new JWT with tenant_id and role_id embedded.\n\nAuthorization:\n- Requires a valid Bearer JWT from `/auth/login`.\n",
        "operationId": "activateTenant",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ActivateTenantRequest"
              }
            }
          },
          "description": "Tenant to activate for the current user",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ActivateTenantResponse"
                }
              }
            },
            "description": "Tenant activated; tenant-scoped JWT issued",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – invalid or missing JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – user not a member of the tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Activate a tenant and mint a tenant-scoped JWT",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/bootstrap-tenant": {
      "post": {
        "description": "\nCreate the first tenant for an account that has no tenant memberships and mint a tenant-scoped JWT.\n\nFlow:\n- Client signs in or creates an account and receives a user-scoped token without `tenant_id`.\n- Client submits the desired tenant name to bootstrap an Owner tenant.\n- Server rejects accounts that already have tenant context or any existing tenant membership.\n- On success, the response includes a fresh JWT scoped to the newly created tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT from `/auth/login` or another user-scoped auth flow.\n",
        "operationId": "bootstrapTenant",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BootstrapTenantRequest"
              }
            }
          },
          "description": "Tenant name to create for the current account.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ActivateTenantResponse"
                }
              }
            },
            "description": "Tenant created; tenant-scoped JWT issued",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request - malformed payload",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized - invalid or missing JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Account already has tenant context or tenant memberships",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Bootstrap the first tenant for the current account",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/create-account": {
      "post": {
        "description": "\nFull workspace bootstrap flow: create a user + tenant in a **pending** state and email a verification link.\n\nBehavior:\n- Normalizes email to lowercase and trims all fields.\n- Creates a pending user and pre-provisions a tenant; the requester will become the **Owner** once verified.\n- Sends a verification email containing a one-time token.\n- Returns `200` for valid payloads regardless of whether the email actually delivers; errors are reserved for invalid input or server issues.\n\nTypical client flow:\n- Collect name, company, email, password from a marketing/signup page.\n- POST here; render a \"check your email\" screen.\n- When the user clicks the verification link, POST the token to `/auth/verify-email` to activate both user and tenant.\n",
        "operationId": "createAccount",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAccountRequest"
              }
            }
          },
          "description": "Signup payload including the future tenant/company name.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateAccountResponse"
                }
              }
            },
            "description": "Account creation accepted; verification email is on the way.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid payload",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Create an account and receive a verification link",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/forgot-password": {
      "post": {
        "description": "\nRequest a password reset for the given email.\n\nSecurity / privacy:\n- This endpoint **always** returns success, even if the email does not exist or the user is inactive.\n- If a matching active user is found, a reset token is created and (later) emailed to the user.\n- The reset token is stored **hashed** in the database; the raw token is only shown to the client/email.\n\nTypical flow:\n- Client calls this with `{ \"email\": \"user@example.com\" }`.\n- If the user exists and is active, the server creates a single-use token that expires in 30 minutes.\n- The implementation is expected to send an email containing a link like:\n  `/auth/reset-password?token=<opaque-reset-token>&target_email=<url-encoded-email>`.\n",
        "operationId": "forgotPassword",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ForgotPasswordRequest"
              }
            }
          },
          "description": "Email of the account that wants to reset its password.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ForgotPasswordResponse"
                }
              }
            },
            "description": "Request accepted (does not reveal whether the email exists). Response echoes target_email for client display.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request – malformed payload",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Request a password reset email",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/login": {
      "post": {
        "description": "\nAuthenticate a user with email and password, and receive a short-lived JWT plus membership info.\n\nCredentials:\n- Expects a JSON body with `email` and `password`.\n- Passwords are verified using bcrypt against the stored `password_hash`.\n\nMulti-tenancy / memberships:\n- A user may belong to zero, one, or multiple tenants.\n- After successful login we load all memberships for the user (tenant, role, permissions).\n- JWT minting behavior:\n  - If the user has **exactly one** membership, that tenant_id and role_id are embedded directly in the token.\n    This produces a \"fully scoped\" token, ready for authenticated tenant calls.\n  - If the user has **zero or more than one** memberships, the token contains only the user_id.\n    The client will typically present this token and then choose/activate a tenant later.\n\nToken:\n- The token is signed server-side using the configured secret (HS256).\n- `expires_in_secs` tells the client how long this token is valid.\n\nSecurity notes:\n- If the email does not exist or the password is wrong, the server returns `401 Unauthorized`\n  with a generic `\"invalid credentials\"` message. We do not reveal whether the email exists.\n\nResponse:\n- Returns `200 OK` with `LoginResponse`, which includes:\n  - `token` (JWT),\n  - `user_id`, `email`, `name`,\n  - all discovered `memberships` (tenant/role/permissions),\n  - `expires_in_secs`.\n\nRate limiting:\n- This route may be rate limited / concurrency limited.\n- On abuse or too many attempts, you may receive `429 Too Many Requests`.\n",
        "operationId": "login",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LoginRequest"
              }
            }
          },
          "description": "User credentials (`email`, `password`).",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResponse"
                }
              }
            },
            "description": "Login successful; JWT issued",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request – e.g. invalid password hash format or malformed payload",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – invalid credentials (email/password mismatch)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit for auth attempts",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Authenticate and obtain a JWT",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/logout": {
      "post": {
        "description": "\nLog out the currently authenticated user.\n\nThis implementation is **stateless**:\n- The server does not maintain server-side sessions.\n- Logging out is effectively instructing the client to discard its JWT.\n- Future calls with the same JWT will still be technically valid until expiry.\n\nWhy still have this route?\n- It gives clients a canonical place to call \"logout\" for analytics/UI purposes.\n- It allows us to introduce server-side revocation / blacklisting in the future\n  without changing the API surface (e.g. invalidating refresh tokens, adding a JTI blacklist, etc.).\n",
        "operationId": "logout",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LogoutResponse"
                }
              }
            },
            "description": "Logout acknowledged; client should discard its JWT.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid Bearer token.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Logout current user (stateless)",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/oauth/{provider}/authorize": {
      "get": {
        "description": "Redirects the caller to the configured OAuth provider authorization page. Optional `return_to` is sealed into the OAuth state and validated on callback.",
        "operationId": "oauthAuthorize",
        "parameters": [
          {
            "description": "OAuth provider: `github` or `google`",
            "in": "path",
            "name": "provider",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirects to the provider authorization page",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unsupported provider",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Start OAuth authorization",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/oauth/{provider}/callback": {
      "get": {
        "description": "Handles the OAuth provider callback. Requests accepting JSON receive a login payload; browser requests are redirected to the configured frontend success URL.",
        "operationId": "oauthCallback",
        "parameters": [
          {
            "description": "OAuth provider: `github` or `google`",
            "in": "path",
            "name": "provider",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Authorization code returned by the provider",
            "in": "query",
            "name": "code",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Signed OAuth state returned by the provider",
            "in": "query",
            "name": "state",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginResponse"
                }
              }
            },
            "description": "OAuth login succeeded",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "302": {
            "description": "Redirects to the frontend sign-in page with login result in the URL fragment",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid OAuth callback payload",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "OAuth provider exchange failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Complete OAuth callback",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/oauth/{provider}/start": {
      "get": {
        "description": "Compatibility route for starting OAuth authorization. Redirects to the provider authorization page.",
        "operationId": "oauthStart",
        "parameters": [
          {
            "description": "OAuth provider: `github` or `google`",
            "in": "path",
            "name": "provider",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirects to the provider authorization page",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unsupported provider",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Start OAuth authorization",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/reset-password": {
      "post": {
        "description": "\nReset the user's password using a previously issued reset token.\n\nFlow:\n- Client calls `/auth/forgot-password` to request a reset.\n- Server generates a reset token and (eventually) emails it to the user.\n- Client submits the `token` and the new password here.\n- Optionally provide `tenant_id` to mint a tenant-scoped sign-in token after reset.\n\nToken:\n- The raw `token` is provided by the client.\n- The server hashes it and looks it up in `password_reset_tokens`.\n- Token must be unused and unexpired.\n- On success, the token is marked as used and the user's password is updated. The response includes `target_email` for client display and follow-up sign-in.\n\nSecurity notes:\n- If the token is invalid or expired, the server returns `400 Bad Request`\n  with a generic `\"invalid or expired reset token\"` message.\n",
        "operationId": "resetPassword",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResetPasswordRequest"
              }
            }
          },
          "description": "Reset token and new password (optionally include tenant_id to mint a scoped token).",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResetPasswordResponse"
                }
              }
            },
            "description": "Password reset successful. The response includes target_email and, if tenant_id is provided, a scoped token.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid or expired token; or invalid payload.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Reset password using a reset token",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/signup": {
      "post": {
        "description": "\nLightweight self-service signup for individual accounts.\n\nBehavior:\n- Accepts name, email, and password; the email is normalized to lowercase and trimmed.\n- Creates a user in **pending** state and sends a verification email containing a one-time token.\n- Does **not** create a tenant; use `POST /auth/create-account` for the full org bootstrap flow.\n- Returns `200` as long as the payload is valid; detailed errors are only surfaced for server issues.\n\nTypical client flow:\n- Call this endpoint.\n- Redirect user to a \"check your email\" screen.\n- When the user clicks the verification link, POST the token to `/auth/verify-email`.\n",
        "operationId": "signup",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SignupRequest"
              }
            }
          },
          "description": "User details used to create the pending account.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignupResponse"
                }
              }
            },
            "description": "Signup accepted (verification email will be sent).",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid payload",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Sign up and receive an email verification link",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/auth/verify-email": {
      "post": {
        "description": "\nConfirms ownership of the email used during signup or account creation.\n\nBehavior:\n- Accepts a single-use token that was emailed to the user.\n- On success, activates the user; if the signup came from `/auth/create-account`, the tenant is also activated and the user is made the Owner.\n- Rejects empty, malformed, or expired tokens.\n\nToken source:\n- Signup (`/auth/signup`) or full account creation (`/auth/create-account`).\n- The frontend typically builds a link like `/verify-email?token=<opaque-token>` and POSTs the token to this endpoint.\n",
        "operationId": "verifyEmail",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerifyEmailRequest"
              }
            }
          },
          "description": "Opaque verification token from the email link.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerifyEmailResponse"
                }
              }
            },
            "description": "Email verified",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid or expired token",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Verify email using a token",
        "tags": [
          "auth"
        ]
      }
    },
    "/api/v1/billing/checkout": {
      "post": {
        "description": "Starts the tenant's first self-service paid subscription. RustGrid creates a flexible-billing Stripe Checkout Session in `subscription` mode with `ui_mode=embedded`, `redirect_on_completion=never`, and payment methods restricted to card and Link. Mount the session inside AgentOps with the returned client secret and publishable key; do not navigate to Stripe or persist either value. Requires billing update permission and an `Idempotency-Key`.",
        "operationId": "billing_checkout",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Required retry key for this logical billing mutation. Reuse the same key only when retrying the same operation; use a new key for a new operation.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSession"
                }
              }
            },
            "description": "Embedded Checkout session configuration",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create embedded Stripe Checkout session",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/checkout/cancel": {
      "post": {
        "description": "Discards the tenant's active embedded Checkout without trusting a browser-supplied Stripe identifier. RustGrid resolves or recovers the reserved session, expires it only while open, and clears only that exact reservation after Stripe confirms it is expired. A successful response returns `canceled=true` and means no active Checkout reservation remains. If Checkout already completed, RustGrid reconciles the subscription and returns a conflict so the caller refreshes billing. Requires billing update permission and an `Idempotency-Key`.",
        "operationId": "billing_checkout_cancel",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Required retry key for this logical billing mutation. Reuse the same key only when retrying the same operation; use a new key for a new operation.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSessionCancellationResult"
                }
              }
            },
            "description": "Checkout reservation is no longer active",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Discard active embedded Checkout",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/current": {
      "get": {
        "description": "Returns the tenant billing account, current plan and usage, subscription lifecycle state, and any unresolved plan change. `pending_change_type` distinguishes a scheduled downgrade from an upgrade awaiting payment. Treat webhooks as authoritative and refresh this resource after an embedded Stripe flow. Requires billing read permission.",
        "operationId": "billing_current",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingCurrent"
                }
              }
            },
            "description": "OK",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get current tenant billing state",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/plans": {
      "get": {
        "description": "Returns public billing plans in stable `sort_order`, including their default entitlements and configured Stripe price mapping. Requires billing read permission.",
        "operationId": "billing_list_plans",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingPlansResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List billing plans",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/subscription/cancel": {
      "post": {
        "description": "Sets the Stripe subscription to cancel at the current period end. A visible pending upgrade or downgrade must first be completed or canceled; RustGrid only aborts a hidden, recoverable downgrade operation that cannot be exposed to the caller. Access continues through `cancel_at`; call the resume endpoint before then to reverse the cancellation. RustGrid re-retrieves Stripe state before confirming the requested lifecycle state. Requires billing update permission and an `Idempotency-Key`.",
        "operationId": "billing_subscription_cancel",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Required retry key for this logical billing mutation. Reuse the same key only when retrying the same operation; use a new key for a new operation.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionLifecycleResult"
                }
              }
            },
            "description": "Subscription cancellation state",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Schedule subscription cancellation",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/subscription/change": {
      "post": {
        "description": "Applies an upgrade immediately with invoiced proration or schedules a downgrade for the current period end without proration. Upgrades require the fresh `preview_token` returned by the preview endpoint. A `requires_payment` result supplies Payment Element configuration so customer action remains inside AgentOps. Requires billing update permission and an `Idempotency-Key`.",
        "operationId": "billing_subscription_change",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Required retry key for this logical billing mutation. Reuse the same key only when retrying the same operation; use a new key for a new operation.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangeSubscriptionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionChangeResult"
                }
              }
            },
            "description": "Applied, scheduled, or payment-required plan change",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Apply or schedule subscription plan change",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/subscription/change/cancel": {
      "post": {
        "description": "Cancels the current RustGrid-managed pending plan change without canceling the subscription. For a scheduled downgrade, RustGrid releases its Stripe subscription schedule. For a pending-payment upgrade, RustGrid voids the verified upgrade invoice so Stripe rolls back the pending update. RustGrid re-retrieves and reconciles Stripe state before responding: it returns `canceled=true` when the managed change is gone and the original plan remains, `canceled=false` when no managed change existed, or a conflict when the target plan already took effect. Requires billing update permission and an `Idempotency-Key`.",
        "operationId": "billing_subscription_change_cancel",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Required retry key for this logical billing mutation. Reuse the same key only when retrying the same operation; use a new key for a new operation.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionChangeCancellationResult"
                }
              }
            },
            "description": "Scheduled-change cancellation result",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Cancel scheduled subscription change",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/subscription/change/preview": {
      "post": {
        "description": "Returns the authoritative direction, effective time, prorated impact, and target recurring terms for changing the existing Stripe subscription. Upgrade previews include a short-lived quote token that is required when applying the change; downgrade previews take effect at the current period end. Amounts use integer minor currency units, and recurring amounts are base renewal totals before taxes and discounts. Requires billing update permission.",
        "operationId": "billing_subscription_change_preview",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PreviewSubscriptionChangeRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionChangePreview"
                }
              }
            },
            "description": "Subscription change preview",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Preview subscription plan change",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/subscription/payment": {
      "post": {
        "description": "Reconciles the latest Stripe subscription state, updates the actual open payable invoice to card and Link, verifies those methods, and returns its Payment Element configuration when customer action is still required. Complete payment inside AgentOps, then refresh current billing state; never log or persist the client secret. Requires billing update permission and an `Idempotency-Key`.",
        "operationId": "billing_subscription_payment",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Required retry key for this logical billing mutation. Reuse the same key only when retrying the same operation; use a new key for a new operation.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingPaymentSession"
                }
              }
            },
            "description": "In-app invoice payment configuration",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create in-app invoice payment session",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/billing/subscription/resume": {
      "post": {
        "description": "Clears a pending period-end cancellation on the existing Stripe subscription. Requires billing update permission and an `Idempotency-Key`.",
        "operationId": "billing_subscription_resume",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Required retry key for this logical billing mutation. Reuse the same key only when retrying the same operation; use a new key for a new operation.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionLifecycleResult"
                }
              }
            },
            "description": "Resumed subscription lifecycle state",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid billing request",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Billing lifecycle or quote conflict",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stripe request failed or returned an invalid response",
            "headers": {
              "Cache-Control": {
                "description": "Billing responses are private and must not be cached. The value is `no-store, private, max-age=0`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Resume scheduled subscription",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/comments/{id}": {
      "delete": {
        "description": "\nDelete an existing comment.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `comments:DELETE`.\n- Caller must belong to the same tenant that owns the comment.\n\nSemantics:\n- This endpoint is **idempotent** by contract.\n- Returns `204 No Content` even if the comment was already deleted or not visible in this tenant.\n\nETag:\n- If the comment existed at deletion time, the response includes a strong ETag\n  `\"comments:<uuid>:<row_version>\"` representing the removed version.\n\nRate limiting:\n- This route may be rate-limited and/or concurrency-limited.\n",
        "operationId": "deleteComment",
        "parameters": [
          {
            "description": "Comment identifier (UUID) to delete",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Comment successfully deleted (or already absent)",
            "headers": {
              "ETag": {
                "description": "Strong ETag of removed version: `\"comments:<uuid>:<version>\"` (present only if the comment existed at deletion time)",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `comments:DELETE` permission or cannot delete in this tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a comment",
        "tags": [
          "comments"
        ]
      },
      "get": {
        "description": "\nFetch a single comment by its unique identifier.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `comments:READ`.\n- Caller must belong to the same tenant as the comment.\n\nMulti-tenancy:\n- Tenant is derived from the authenticated context (`Ctx`).\n- Cross-tenant access is masked as `404 Not Found`.\n\nBehavior:\n- The service layer (`uc_get_comment`) validates existence & tenant scoping.\n- If found, returns the `CommentResponse`.\n- If not found, returns `404 Not Found`.\n\nResponse:\n- Returns `200 OK` with the full `CommentResponse` object.\n- Includes a strong `ETag` header of the form `\"comments:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for audit and tracing.\n\nRate limiting:\n- Subject to per-route concurrency and/or rate limits.\n- When exceeded, responds `429 Too Many Requests` with standard rate-limit headers.\n",
        "operationId": "getComment",
        "parameters": [
          {
            "description": "Unique comment identifier (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommentResponse"
                }
              }
            },
            "description": "Comment successfully retrieved",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"comments:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `comments:READ`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – comment does not exist in this tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a comment by ID",
        "tags": [
          "comments"
        ]
      },
      "patch": {
        "description": "\nUpdate the body text of an existing comment.\n\nConcurrency & Preconditions:\n- Uses **optimistic concurrency** with a required `If-Match` strong ETag header.\n- Send the last seen ETag (e.g. `\"comments:<uuid>:<row_version>\"`).\n- Server returns **428** if `If-Match` is missing, **412** if it doesn't match.\n\nAuthorization:\n- Requires one of: `comments:UPDATE` (edit any) or `comments:UPDATE_SELF` (edit own).\n- Caller must belong to the same tenant as the comment.\n\nRequest:\n- Body must conform to `UpdateComment` and MUST include `body`.\n\nResponse:\n- `200 OK` with updated resource, strong ETag, and `x-request-id`.\n",
        "operationId": "updateComment",
        "parameters": [
          {
            "description": "Comment ID",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag `\"comments:<uuid>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCommentRequest"
              }
            }
          },
          "description": "Partial update payload (body is required).",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommentResponse"
                }
              }
            },
            "description": "Updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"comments:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request (e.g. missing body)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found in tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed (ETag mismatch)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required (missing If-Match)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update an existing comment (If-Match required)",
        "tags": [
          "comments"
        ]
      }
    },
    "/api/v1/entitlements": {
      "get": {
        "description": "Get effective tenant entitlements",
        "operationId": "entitlements_current",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EffectiveEntitlements"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get effective tenant entitlements",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/integrations/github/app/webhook/sync": {
      "post": {
        "description": "Reconcile the GitHub App webhook configuration",
        "operationId": "syncGithubAppWebhook",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "GitHub App webhook configuration reconciled",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub App webhook configuration is incomplete",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub API failure",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Reconcile the GitHub App webhook configuration",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/integrations/github/deliveries": {
      "get": {
        "description": "List GitHub webhook delivery audit records",
        "operationId": "listGithubDeliveries",
        "parameters": [
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "default": 50,
              "maximum": 200,
              "minimum": 1,
              "type": [
                "integer",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tenant-scoped GitHub webhook delivery audit records",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List GitHub webhook delivery audit records",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/installations": {
      "get": {
        "description": "List active GitHub App installations owned by the authenticated tenant.",
        "operationId": "listGithubInstallations",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "properties": {
                      "account_login": {
                        "type": "string"
                      },
                      "account_type": {
                        "type": "string"
                      },
                      "claimed_at": {
                        "format": "date-time",
                        "type": "string"
                      },
                      "claimed_by": {
                        "format": "uuid",
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "installation_id": {
                        "format": "int64",
                        "type": "integer"
                      },
                      "permissions": {
                        "additionalProperties": true,
                        "type": "object"
                      },
                      "repository_selection": {
                        "type": "string"
                      },
                      "state": {
                        "type": "string"
                      },
                      "tenant_id": {
                        "format": "uuid",
                        "type": "string"
                      },
                      "updated_at": {
                        "format": "date-time",
                        "type": "string"
                      },
                      "verification_source": {
                        "type": "string"
                      },
                      "verified_at": {
                        "format": "date-time",
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "installation_id",
                      "tenant_id",
                      "account_login",
                      "account_type",
                      "repository_selection",
                      "permissions",
                      "state",
                      "verification_source",
                      "claimed_at",
                      "updated_at"
                    ],
                    "type": "object"
                  },
                  "type": "array"
                }
              }
            },
            "description": "Active tenant GitHub App installations."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden"
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List active GitHub App installations",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/installations/setup": {
      "post": {
        "description": "Begin tenant-bound GitHub App installation setup",
        "operationId": "beginGithubInstallationSetup",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "expires_at": {
                      "format": "date-time",
                      "type": "string"
                    },
                    "installation_url": {
                      "format": "uri",
                      "type": "string"
                    }
                  },
                  "required": [
                    "installation_url",
                    "expires_at"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "One-time tenant-bound GitHub App installation URL",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub App setup is not configured",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Begin tenant-bound GitHub App installation setup",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/installations/{id}": {
      "delete": {
        "description": "Disconnect one tenant-owned GitHub App installation and remove its active repository links while preserving RustGrid projects and history",
        "operationId": "disconnectGithubInstallation",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "properties": {
                    "disconnected": {
                      "type": "boolean"
                    },
                    "installation_account": {
                      "nullable": true,
                      "type": "string"
                    },
                    "installation_id": {
                      "format": "int64",
                      "type": "integer"
                    },
                    "preserved_projects": {
                      "format": "int64",
                      "minimum": 0,
                      "type": "integer"
                    },
                    "removed_project_links": {
                      "format": "int64",
                      "minimum": 0,
                      "type": "integer"
                    },
                    "removed_repositories": {
                      "format": "int64",
                      "minimum": 0,
                      "type": "integer"
                    }
                  },
                  "required": [
                    "disconnected",
                    "installation_id",
                    "installation_account",
                    "removed_project_links",
                    "removed_repositories",
                    "preserved_projects"
                  ],
                  "type": "object"
                }
              }
            },
            "description": "Installation disconnected and active repository links removed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid installation id",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Disconnect a GitHub App installation",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/installations/{id}/repositories": {
      "get": {
        "description": "List discovered GitHub installation repositories",
        "operationId": "listGithubInstallationRepositories",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Discovered installation repositories",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List discovered GitHub installation repositories",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/installations/{id}/sync": {
      "post": {
        "description": "Reconcile a GitHub App installation",
        "operationId": "syncGithubInstallation",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Installation repositories reconciled",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub App configuration or permissions are incomplete",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub API failure",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Reconcile a GitHub App installation",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/oauth/callback": {
      "get": {
        "description": "Complete GitHub App installation user authorization",
        "operationId": "completeGithubInstallationOAuth",
        "parameters": [
          {
            "in": "query",
            "name": "code",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "state",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "User-authorized installation ownership verified; redirect to the frontend console",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "OAuth code or setup state is invalid or expired",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "The authorized GitHub user cannot access the selected installation",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Installation setup is not configured or is already owned by another tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub OAuth or API verification failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Complete GitHub App installation user authorization",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/repositories": {
      "get": {
        "description": "List GitHub repository bindings",
        "operationId": "listGithubRepositories",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "type": "object"
                  },
                  "type": "array"
                }
              }
            },
            "description": "Tenant GitHub repository bindings",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List GitHub repository bindings",
        "tags": [
          "integrations"
        ]
      },
      "post": {
        "description": "Configure a GitHub repository binding",
        "operationId": "upsertGithubRepository",
        "parameters": [
          {
            "description": "Makes repository configuration retries exactly-once. Reusing a key with a different request is rejected.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "enabled": {
                    "default": true,
                    "type": "boolean"
                  },
                  "installation_account": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "installation_id": {
                    "description": "Verified tenant-owned GitHub App installation. Omit only for a standalone repository-secret binding.",
                    "format": "int64",
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "merge_policy": {
                    "default": "all_open_prs",
                    "enum": [
                      "all_open_prs",
                      "any_pr"
                    ],
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "project_id": {
                    "format": "uuid",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "pull_request_automation": {
                    "description": "Optional per-repository ticket status mappings for linked pull request lifecycle events. Status names are resolved case-insensitively; ready_to_review and Ready to review are accepted aliases for ready_for_review.",
                    "properties": {
                      "merged": {
                        "default": "done",
                        "type": "string"
                      },
                      "opened": {
                        "default": "ready_for_review",
                        "type": "string"
                      },
                      "reopened": {
                        "default": "ready_for_review",
                        "type": "string"
                      }
                    },
                    "required": [
                      "opened",
                      "reopened",
                      "merged"
                    ],
                    "type": [
                      "object",
                      "null"
                    ]
                  },
                  "repository": {
                    "example": "acme/rustgrid",
                    "type": "string"
                  },
                  "required_workflows": {
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "type": "array"
                  },
                  "web_base_url": {
                    "description": "GitHub or GitHub Enterprise web origin.",
                    "format": "uri",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "webhook_secret": {
                    "description": "Write-only secret encrypted at rest. Required for enabled standalone bindings and ignored as an App-ownership credential.",
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "repository",
                  "required_workflows"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Repository binding created or updated",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid repository binding",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Repository belongs to another tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Configure a GitHub repository binding",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/repositories/{id}": {
      "delete": {
        "description": "Delete a GitHub repository binding",
        "operationId": "deleteGithubRepository",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag returned by the repository binding API.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Repository binding deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stale or mismatched ETag",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a GitHub repository binding",
        "tags": [
          "integrations"
        ]
      },
      "patch": {
        "description": "Update a GitHub repository binding",
        "operationId": "updateGithubRepository",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag returned by the repository binding API.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "enabled": {
                    "default": true,
                    "type": "boolean"
                  },
                  "merge_policy": {
                    "enum": [
                      "all_open_prs",
                      "any_pr"
                    ],
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "project_id": {
                    "format": "uuid",
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "pull_request_automation": {
                    "description": "Optional replacement ticket status mappings for linked pull request lifecycle events. Status names are resolved case-insensitively; ready_to_review and Ready to review are accepted aliases for ready_for_review.",
                    "properties": {
                      "merged": {
                        "type": "string"
                      },
                      "opened": {
                        "type": "string"
                      },
                      "reopened": {
                        "type": "string"
                      }
                    },
                    "required": [
                      "opened",
                      "reopened",
                      "merged"
                    ],
                    "type": [
                      "object",
                      "null"
                    ]
                  },
                  "required_workflows": {
                    "items": {
                      "type": "string"
                    },
                    "minItems": 1,
                    "type": "array"
                  },
                  "webhook_secret": {
                    "description": "Optional replacement repository webhook secret.",
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "required_workflows"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Repository binding updated",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Stale or mismatched ETag",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a GitHub repository binding",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/setup/callback": {
      "get": {
        "description": "Begin GitHub App installation user authorization",
        "operationId": "completeGithubInstallationSetup",
        "parameters": [
          {
            "in": "query",
            "name": "state",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "installation_id",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "setup_action",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "Installation bound to setup state; redirect to GitHub user authorization",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Setup state or installation ID is invalid or expired",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Setup state is bound to another installation or user authorization is not configured",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "GitHub API verification failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Begin GitHub App installation user authorization",
        "tags": [
          "integrations"
        ]
      }
    },
    "/api/v1/integrations/github/webhook": {
      "post": {
        "description": "Verify and process GitHub pull request, review, check, workflow, and installation lifecycle events.",
        "operationId": "github_webhook",
        "parameters": [
          {
            "in": "header",
            "name": "x-github-event",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "x-github-delivery",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "x-hub-signature-256",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Event accepted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Malformed event",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing or invalid signature",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Integration is not configured",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Receive a GitHub webhook",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/internal/stripe/webhook": {
      "post": {
        "description": "Process Stripe webhook",
        "operationId": "stripe_webhook",
        "parameters": [
          {
            "in": "header",
            "name": "stripe-signature",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "No Content",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Process Stripe webhook",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/openapi.json": {
      "get": {
        "description": "Returns the committed RustGrid OpenAPI 3.1 document served by this deployment.",
        "operationId": "openApiJson",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            },
            "description": "OpenAPI document",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "OpenAPI serialization failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "OpenAPI JSON",
        "tags": [
          "docs"
        ]
      }
    },
    "/api/v1/projects": {
      "get": {
        "description": "\nRetrieve a paginated list of **projects** scoped to the caller's tenant.\n\nAuthorization:\n- Requires Bearer JWT.\n- Requires RBAC permission `projects:READ`.\n- Cross-tenant access is not allowed.\n\nQuery:\n- `ListProjectsQuery` carries pagination and optional filters (e.g., archived).\n\nBehavior:\n- Delegates to `uc_list_projects.execute(tenant_id, q)`.\n\nResponse:\n- `200 OK` with `ProjectPage` (items, page, size, total).\n- Includes `x-request-id` via middleware headers.\n",
        "operationId": "listProjects",
        "parameters": [
          {
            "description": "Free text query applied to key/name (ILIKE)",
            "in": "query",
            "name": "q",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Filter archived state",
            "in": "query",
            "name": "is_archived",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "description": "1-based page",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size (server clamps to hard max)",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectPageResponse"
                }
              }
            },
            "description": "Projects page",
            "headers": {
              "x-request-id": {
                "description": "Correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `projects:READ`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List projects in the current tenant",
        "tags": [
          "projects"
        ]
      },
      "post": {
        "description": "Create a new tenant-scoped project (unique `key` within the tenant).",
        "operationId": "createProject",
        "parameters": [
          {
            "description": "Provide to make creation exactly-once (handler-scoped)",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateProjectRequest"
              }
            }
          },
          "description": "Project creation payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectResponse"
                }
              }
            },
            "description": "Idempotent replay (existing project returned)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"projects:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the project",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectResponse"
                }
              }
            },
            "description": "Project created",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"projects:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the new project",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Duplicate in-flight or inconsistent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create project",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/invites/accept": {
      "post": {
        "description": "\nAccept a project invite using a token delivered by email.\n\nBehavior:\n- If the user does not yet exist, an account is created.\n- If the user is not a tenant member, a **Project Guest** tenant role is assigned.\n- A project membership is then upserted with the invite's role.\n- A password reset token is minted and returned for setting a new password. The response includes `target_email` for client display.\n\nThis endpoint is **public** (no auth required).\n",
        "operationId": "acceptProjectInvite",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AcceptProjectInviteRequest"
              }
            }
          },
          "description": "Invite acceptance token",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcceptProjectInviteResponse"
                }
              }
            },
            "description": "Invite accepted. Response includes the password reset token, target_email, and project role details.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id (if provided)",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid or expired token",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Accept a project invite with a token",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/key/{key}": {
      "get": {
        "description": "\nFetch a project by its **key** within the current tenant.\n\n- Requires JWT + `projects:READ`.\n- Cross-tenant access masked as 404.\n- Strong ETag: `\"projects:<uuid>:<row_version>\"`.\n",
        "operationId": "getProjectByKey",
        "parameters": [
          {
            "description": "Project key (e.g., RG)",
            "in": "path",
            "name": "key",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"projects:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `projects:READ`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found in this tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a project by key (tenant-scoped)",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/search": {
      "get": {
        "description": "\nPerforms **tenant-scoped** fuzzy search over project **key**, **name**, and **description**\nusing PostgreSQL trigram similarity.\n\n### Authorization\n- Requires Bearer JWT.\n- Requires RBAC permission `projects:LIST`.\n\n### Search semantics\n- `q` must be non-empty after trimming.\n- Results are ranked by trigram similarity (`rank` 0.0–1.0).\n- Pagination via `page` (1-based) and `size` (server-clamped).\n\n### Response\n- `200 OK` with [`ProjectPage`](#schema-ProjectPage):\n  - `items[]` include `id`, `key`, `name`, `description`, `is_archived`,\n    `created_at`, `updated_at`, and `rank`.\n- Includes `x-request-id`.\n\n### Rate limiting\n- Per-route concurrency/rate limits may apply (`429` on excess).\n",
        "operationId": "searchProject",
        "parameters": [
          {
            "description": "1-based page",
            "in": "query",
            "name": "page",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Non-empty query",
            "in": "query",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional archived filter when searching",
            "in": "query",
            "name": "is_archived",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectPageResponse"
                }
              }
            },
            "description": "Ranked paginated search results",
            "headers": {
              "x-request-id": {
                "description": "Correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `projects:LIST`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Search projects",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/{id}": {
      "delete": {
        "description": "\nDelete an existing project within the caller's tenant.\n\nAuthorization:\n- Requires JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `projects:DELETE`.\n- Project must belong to the caller's tenant; cross-tenant is masked as absent.\n\nSemantics:\n- **Idempotent** by contract: returns `204 No Content` even if the project is already gone\n  or not visible to the tenant.\n\nOptimistic concurrency:\n- Requires **strong** `If-Match` with format: `\"projects:<uuid>:<row_version>\"`.\n- `428` if missing, `412` if mismatch/stale.\n\nETag:\n- If the project existed at deletion time, response includes a strong ETag\n  `\"projects:<uuid>:<row_version>\"` representing the removed version.\n",
        "operationId": "deleteProject",
        "parameters": [
          {
            "description": "Project identifier (UUID) to delete",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"projects:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Project deleted (or already absent)",
            "headers": {
              "ETag": {
                "description": "Strong ETag of removed version: `\"projects:<uuid>:<version>\"` (present only if it existed at deletion time)",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `projects:DELETE` or cross-tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a project (tenant-scoped)",
        "tags": [
          "projects"
        ]
      },
      "get": {
        "description": "\nFetch a single **project** by its unique identifier (tenant-scoped).\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `projects:READ`.\n- Caller must belong to the same tenant as the project; cross-tenant access is masked as 404.\n\nBehavior:\n- Uses `uc_get_project.by_id(tenant, id)`.\n- If found, returns the `ProjectResponse`.\n- If not found (or different tenant), returns `404 Not Found`.\n\nResponse:\n- `200 OK` with `ProjectResponse`.\n- Strong `ETag` header: `\"projects:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for audit/tracing.\n",
        "operationId": "getProject",
        "parameters": [
          {
            "description": "Project identifier (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectResponse"
                }
              }
            },
            "description": "Project successfully retrieved",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"projects:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing/invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `projects:READ`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found in this tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a project by ID",
        "tags": [
          "projects"
        ]
      },
      "patch": {
        "description": "\nUpdate mutable fields on a project (tenant-scoped).\n\nOptimistic concurrency:\n- Requires **strong** `If-Match` with format: `\"projects:<uuid>:<row_version>\"`.\n- `428` if missing, `412` if mismatch/stale.\n\nAuthorization:\n- Requires `projects:UPDATE`.\n- Cross-tenant access is masked as 404.\n\nResponse:\n- `200 OK` with updated resource + strong `ETag`.\n",
        "operationId": "updateProject",
        "parameters": [
          {
            "description": "Project ID",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag `\"projects:<uuid>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateProjectRequest"
              }
            }
          },
          "description": "Partial update payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectResponse"
                }
              }
            },
            "description": "Updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"projects:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found in tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed (ETag mismatch)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required (missing If-Match)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a project (If-Match required)",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/{project_id}/backlog": {
      "get": {
        "description": "\nList backlog tickets for a project in a grouped board view.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:view`.\n- Tenant guard: project must belong to caller tenant; others are masked as 404.\n\nBehavior:\n- Default grouping is by ticket status.\n- `group=assignee` groups tickets under each assignee bucket.\n- Tickets are ordered by backlog ordering maintained by the backlog reorder API.\n\nResponse:\n- `200 OK` with `[SprintBoardColumnResponse]` containing grouped tickets.\n- `404 Not Found` when the project is missing or outside tenant scope.\n- Always emits `x-request-id`.\n\nRate limiting:\n- Standard per-route limits with `429` carrying `x-ratelimit-*`.\n    ",
        "operationId": "projectBacklog",
        "parameters": [
          {
            "description": "Project id",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "`assignee` to group by assignee, otherwise by status",
            "in": "query",
            "name": "group",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/SprintBoardColumnResponse"
                  },
                  "type": "array"
                }
              }
            },
            "description": "Backlog board",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:view` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Project backlog board",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/projects/{project_id}/backlog/move": {
      "post": {
        "description": "\nMove a ticket to a specific sprint or back to the backlog.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:manage`.\n- Tenant guard: ticket and sprint (when provided) must belong to caller tenant; cross-tenant is surfaced as 404.\n\nBehavior:\n- Provide `target_sprint_id` to assign and append ordering into that sprint.\n- Omit/null `target_sprint_id` to move the ticket back to backlog ordering.\n- Reorders underlying backlog/sprint lists atomically.\n\nResponse:\n- `204 No Content` when moved (idempotent if already in target).\n- `404` when ticket/project/sprint are missing or outside tenant scope.\n- `x-request-id` header is always present.\n\nRate limiting:\n- Standard per-route rate/concurrency limits; `429` returns `x-ratelimit-*`.\n    ",
        "operationId": "moveTicketBacklogSprint",
        "parameters": [
          {
            "description": "Project id",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MoveRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "204": {
            "description": "Moved",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:manage` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Ticket or project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Move a ticket between backlog and a sprint",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/projects/{project_id}/backlog/reorder": {
      "post": {
        "description": "\nPersist a new ordering for backlog tickets in a project.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:backlog:manage`.\n- Tenant guard: project must belong to caller tenant; otherwise masked as 404.\n\nBehavior:\n- Accepts the full ordered list of ticket ids; overwrites existing backlog ordering.\n- Idempotent when the same ordering is provided.\n- Tickets not present in the list remain in their previous relative order after the provided items.\n\nResponse:\n- `204 No Content` on success.\n- `404` when project/tickets are not in tenant scope.\n- Emits `x-request-id` for tracing.\n\nRate limiting:\n- Standard per-route limits; `429` returns rate-limit headers.\n    ",
        "operationId": "reorderBacklog",
        "parameters": [
          {
            "description": "Project id",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReorderRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "204": {
            "description": "Reordered",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:backlog:manage` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Reorder backlog tickets",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/projects/{project_id}/custom-fields": {
      "get": {
        "description": "Returns a paginated list of custom field definitions for a project. Requires Bearer credentials with `custom_fields:read` scope.",
        "operationId": "listProjectCustomFields",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Free text search on key/name/description",
            "in": "query",
            "name": "q",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Include archived definitions as well",
            "in": "query",
            "name": "include_archived",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "description": "Pagination page",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomFieldDefinitionPageResponse"
                }
              }
            },
            "description": "Paged custom field definitions",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List project custom fields",
        "tags": [
          "custom-fields"
        ]
      },
      "post": {
        "description": "Creates a custom field definition for a project. Project-scoped API keys may only create definitions in their bound project.",
        "operationId": "createProjectCustomField",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCustomFieldDefinitionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomFieldDefinitionResponse"
                }
              }
            },
            "description": "Custom field created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Custom field already exists",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create a project custom field",
        "tags": [
          "custom-fields"
        ]
      }
    },
    "/api/v1/projects/{project_id}/custom-fields/{id}": {
      "delete": {
        "description": "Archives a custom field definition within the project. Existing ticket custom field values are retained for ticket history; archived definitions are hidden from list responses unless include_archived=true.",
        "operationId": "deleteProjectCustomField",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Custom field definition ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for the custom field definition, for example \"custom-fields:{id}:{row_version}\".",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Custom field archived",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Custom field not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Archive/remove a project custom field",
        "tags": [
          "custom-fields"
        ]
      },
      "get": {
        "description": "Fetches one custom field definition by ID within a project.",
        "operationId": "getProjectCustomField",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Custom field definition ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomFieldDefinitionResponse"
                }
              }
            },
            "description": "Custom field found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Custom field not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a project custom field",
        "tags": [
          "custom-fields"
        ]
      },
      "patch": {
        "description": "Updates mutable custom field definition metadata, options, required/archive flags, or display position.",
        "operationId": "updateProjectCustomField",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Custom field definition ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for the custom field definition, for example \"custom-fields:{id}:{row_version}\".",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateCustomFieldDefinitionRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomFieldDefinitionResponse"
                }
              }
            },
            "description": "Custom field updated",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Custom field not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Custom field conflict",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a project custom field",
        "tags": [
          "custom-fields"
        ]
      }
    },
    "/api/v1/projects/{project_id}/invites": {
      "get": {
        "description": "\nList currently pending project invites persisted for a project.\n\nAuthorization:\n- Requires a valid Bearer JWT.\n- Requires `projects:MANAGE_MEMBERS`.\n\nMulti-tenancy:\n- The project must belong to the caller's tenant.\n- Cross-tenant access is masked as `404`.\n\nOnly active invites are returned: consumed and expired invites are omitted. Token material is never included.\n",
        "operationId": "listProjectInvites",
        "parameters": [
          {
            "description": "Project ID",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectInvitesResponse"
                }
              }
            },
            "description": "Pending project invites",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List pending project invites",
        "tags": [
          "projects"
        ]
      },
      "post": {
        "description": "\nInvite a user to join a specific project with a role scoped for project access.\n\nAuthorization:\n- Requires a valid Bearer JWT.\n- Requires `projects:MANAGE_MEMBERS`.\n\nMulti-tenancy:\n- The project must belong to the caller's tenant.\n- Cross-tenant access is masked as `404`.\n\nRole policy:\n- Any role except **SuperAdmin** is allowed.\n- Attempts to assign SuperAdmin return `400`.\n",
        "operationId": "inviteProjectUser",
        "parameters": [
          {
            "description": "Project ID",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InviteProjectUserRequest"
              }
            }
          },
          "description": "Invite payload: email, name, and role_id for the invitee",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InviteProjectUserResponse"
                }
              }
            },
            "description": "Invite created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid payload or role not allowed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Invite a user to a project (email-based token)",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/{project_id}/labels": {
      "get": {
        "description": "\nReturns a paginated list of labels for a project. Supports free-text search over name/description and an `include_archived` flag to surface archived labels.\n\n**Pagination & Filtering**\n- `page` is 1-based; `size` is clamped server-side.\n- `q` performs ILIKE search on name/description.\n- When `include_archived` is omitted, only active labels are returned.\n\n**Authorization**\n- Requires tenant context header and `labels:READ` permission.\n",
        "operationId": "listProjectLabels",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Free text search on name/description",
            "in": "query",
            "name": "q",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Include archived labels as well",
            "in": "query",
            "name": "include_archived",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "description": "Pagination",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabelPageResponse"
                }
              }
            },
            "description": "Paged labels",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List labels in a project",
        "tags": [
          "labels"
        ]
      },
      "post": {
        "description": "\nCreates a new label scoped to the given project. Names are unique per project (case-insensitive) and the request can be made idempotent by sending `Idempotency-Key`.\n\n**Behavior**\n- Trims whitespace from `name`, `color`, and `description`.\n- Fails with 409 on duplicate in-flight idempotency keys or mismatched replays.\n- Returns `Location` for the created label and replays with 200 if the same idempotent request already succeeded.\n\n**Authorization**\n- Requires tenant context header and `labels:CREATE` permission.\n",
        "operationId": "createProjectLabel",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make label creation exactly-once",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateLabelRequest"
              }
            }
          },
          "description": "Label creation payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabelResponse"
                }
              }
            },
            "description": "Idempotent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabelResponse"
                }
              }
            },
            "description": "Label created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Duplicate in-flight or inconsistent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create a project label",
        "tags": [
          "labels"
        ]
      }
    },
    "/api/v1/projects/{project_id}/labels/{id}": {
      "delete": {
        "description": "Removes a label from the project. The operation is idempotent: deleting a non-existent label returns 404 when the project/tenant check fails.",
        "operationId": "deleteProjectLabel",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Label ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Label deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Label not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a project label",
        "tags": [
          "labels"
        ]
      },
      "get": {
        "description": "Fetch a single label by ID within the given project. Returns the full label payload including archive flag and timestamps.",
        "operationId": "getProjectLabel",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Label ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabelResponse"
                }
              }
            },
            "description": "Label found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Label not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a project label",
        "tags": [
          "labels"
        ]
      },
      "patch": {
        "description": "\nPartial update for a label. Send only the fields you want to change; omitting a field leaves it unchanged, sending an empty string for `color` or `description` clears it.\n\n**Authorization**\n- Requires tenant context header and `labels:UPDATE` permission.\n",
        "operationId": "updateProjectLabel",
        "parameters": [
          {
            "description": "Project ID (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Label ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateLabelRequest"
              }
            }
          },
          "description": "Patch semantics: only provided fields are updated",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabelResponse"
                }
              }
            },
            "description": "Label updated",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Label not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a project label",
        "tags": [
          "labels"
        ]
      }
    },
    "/api/v1/projects/{project_id}/members/{user_id}": {
      "delete": {
        "description": "\nRemove (revoke) a user's membership from the given project.\n\nAuthorization:\n- Requires JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `projects:UPDATE` (or a dedicated `projects:members:manage` if you add it).\n- Project must belong to the caller's tenant; cross-tenant is masked as 404.\n\nSemantics:\n- **Idempotent** by contract: returns `204 No Content` even if the membership is already gone\n  or was never present for this (tenant, project, user) tuple.\n",
        "operationId": "removeProjectMember",
        "parameters": [
          {
            "description": "Project identifier (UUID)",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "User identifier (UUID) to remove from the project",
            "in": "path",
            "name": "user_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Membership deleted (or already absent)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks permission or cross-tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found in tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Remove a user from a project (membership)",
        "tags": [
          "projects"
        ]
      },
      "get": {
        "description": "\nRetrieve a single membership for a specific project and user in the caller's current tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `projects:READ`.\n- Tenant is derived from the authenticated context (`Ctx`); cross-tenant access is rejected.\n\nMulti-tenancy:\n- Tenant is derived from the authenticated context (`Ctx`) injected by middleware.\n- `project_id` must belong to the same tenant; otherwise the request fails.\n- Cross-tenant access is rejected.\n\nBehavior:\n- The service layer (`uc_get_project_member`) retrieves the membership belonging to the\n  given `(tenant_id from context, project_id, user_id)` triple.\n- If no membership exists for that project + user in the current tenant, returns `404 Not Found`.\n\nObservability:\n- Each request is correlated with an `x-request-id` header.\n- The handler records `tenant_id`, `user_id` (caller), `project_id`, and `member_id` (target user)\n  into the current tracing span for consistent logging and diagnostics.\n\nResponse:\n- Returns `200 OK` with a JSON `ProjectMemberResponse` on success.\n- Includes `x-request-id` for correlation and tracing (propagated by middleware/logging).\n\nRate limiting:\n- This route is subject to per-route concurrency and/or rate limits.\n- When exceeded, the server returns `429 Too Many Requests` with rate-limit headers.\n",
        "operationId": "getProjectMembership",
        "parameters": [
          {
            "description": "Project ID (UUID) within the current tenant",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "User ID (UUID) whose membership is being retrieved",
            "in": "path",
            "name": "user_id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectMemberDetailResponse"
                }
              }
            },
            "description": "Membership successfully retrieved for the project",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"project_members:<user_id>:<version>\"` for guarded role updates",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `projects:READ` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project or membership not found in the current tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a single membership for a project in the current tenant",
        "tags": [
          "projects"
        ]
      },
      "put": {
        "description": "\nAssign or update a user's role within a project (tenant-scoped).\n\nOptimistic concurrency:\n- Requires **strong** `If-Match` with format: `\"project_members:<user_id>:<row_version>\"`.\n- `428` if missing, `412` if mismatch/stale.\n- For first-time insert, clients may use version `0` in the ETag (e.g. `\"project_members:<user_id>:0\"`),\n  and the UC can treat `(not found + expected_ver == 0)` as \"create\".\n\nAuthorization:\n- Requires `projects:UPDATE` (or stronger, depending on your RBAC design).\n- Project must belong to the caller's tenant; cross-tenant access is masked as 404.\n\nResponse:\n- `200 OK` with the upserted membership + strong `ETag`.\n",
        "operationId": "upsertProjectMember",
        "parameters": [
          {
            "description": "Project ID",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "User ID whose membership is being set",
            "in": "path",
            "name": "user_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag `\"project_members:<user_id>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpsertProjectMemberBody"
              }
            }
          },
          "description": "Upsert project membership payload (role assignment)",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectMemberResponse"
                }
              }
            },
            "description": "Upserted membership",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"project_members:<user_id>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found in tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed (ETag mismatch)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required (missing If-Match)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Upsert a project member (If-Match required)",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/{project_id}/memberships": {
      "get": {
        "description": "\nRetrieve all memberships for a specific project in the caller's current tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `projects:READ`.\n- Caller must belong to the tenant whose project memberships are being listed (derived from context).\n\nMulti-tenancy:\n- Tenant is derived from the authenticated context (`Ctx`) injected by middleware.\n- `project_id` must belong to the same tenant; otherwise the request fails.\n- Cross-tenant access is rejected.\n\nBehavior:\n- The service layer (`uc_list_project_members`) retrieves memberships belonging to the\n  given `project_id` within the tenant in the caller's context.\n- Returns a flat list of project member records (`ProjectMemberRecord` mapped to `ProjectMemberResponse`).\n\nResponse:\n- Returns `200 OK` with a JSON array of `ProjectMemberResponse`.\n- Includes `x-request-id` for correlation and tracing (propagated by middleware/logging).\n\nRate limiting:\n- This route is subject to per-route concurrency and/or rate limits.\n- When exceeded, the server returns `429 Too Many Requests` with rate-limit headers.\n",
        "operationId": "listProjectMemberships",
        "parameters": [
          {
            "description": "Project ID (UUID) within the current tenant",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Vec"
                }
              }
            },
            "description": "List of memberships successfully retrieved for the project",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `projects:READ` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found in the current tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List memberships for a project in the current tenant",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/{project_id}/roles": {
      "get": {
        "description": "\nReturn roles that are **safe for project invites** (no elevated tenant permissions).\n\nAuthorization:\n- Requires a valid Bearer JWT.\n- Requires `projects:MANAGE_MEMBERS`.\n\nMulti-tenancy:\n- Project must belong to the caller's tenant; otherwise `404`.\n",
        "operationId": "listProjectInviteRoles",
        "parameters": [
          {
            "description": "Project ID",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListRolesResponse"
                }
              }
            },
            "description": "List of roles",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List project-safe roles for invites",
        "tags": [
          "projects"
        ]
      }
    },
    "/api/v1/projects/{project_id}/sprints": {
      "get": {
        "description": "\nPaginated list of sprints for a project, ordered by `starts_at` (NULLS LAST) then `created_at`.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:view`.\n- Tenant guard: project must belong to caller tenant; cross-tenant is masked as 404.\n\nRequest:\n- `page` and `size` are clamped to platform defaults (`page>=1`, `size` clamped to max).\n- Supports empty result sets; total still reported.\n\nResponse:\n- `200 OK` with `SprintPageResponse { items, page, size, total }`.\n- Always emits `x-request-id` for correlation.\n- `404` when the project is missing or outside the tenant.\n\nRate limiting:\n- Standard per-route concurrency/rate limits; `429` returns `x-ratelimit-*` headers and optional `retry-after`.\n    ",
        "operationId": "listSprints",
        "parameters": [
          {
            "description": "Project id",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Page (1-based)",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page"
                }
              }
            },
            "description": "Sprint page",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:view` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found / cross-tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List sprints for a project",
        "tags": [
          "sprints"
        ]
      },
      "post": {
        "description": "\nCreate a sprint within a project and return the created resource.\n\nAuthorization:\n- Requires Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC `projects:sprints:manage`.\n- Tenant guard: project must belong to caller tenant; cross-tenant projects are surfaced as 404.\n\nRequest semantics:\n- `state` defaults to `planned` when omitted.\n- `starts_at` / `ends_at` are optional; leave empty for evergreen/backlog-like sprints.\n- `goal` is free text; empty is allowed but trimmed server-side.\n\nResponse:\n- `201 Created` with `SprintResponse`.\n- Headers: `x-request-id` for correlation/audit.\n- Validation errors surface as structured 400 envelopes.\n\nRate limiting:\n- Subject to per-route concurrency and rate limits; `429 Too Many Requests` includes `retry-after` and `x-ratelimit-*` metadata.\n    ",
        "operationId": "createSprint",
        "parameters": [
          {
            "description": "Project id",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSprintRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SprintResponse"
                }
              }
            },
            "description": "Sprint created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid data",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:manage` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Project not found / cross-tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create a sprint",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/sprints/{id}": {
      "delete": {
        "description": "\nDelete a sprint using optimistic concurrency and return tickets to backlog ordering.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:manage`.\n- Tenant guard: sprint must belong to caller tenant; cross-tenant IDs are masked as 404.\n\nConcurrency:\n- Requires `If-Match: \"sprints:<id>:<row_version>\"`.\n- `428` when missing, `412` when version mismatches.\n\nBehavior:\n- All tickets in the sprint are unassigned back to backlog ordering.\n- Idempotent when the sprint is already deleted within the same version window.\n\nResponse:\n- `204 No Content` on success.\n- `404` when sprint does not exist in tenant scope.\n- Always emits `x-request-id` for audit.\n\nRate limiting:\n- Standard per-route limits with `429` carrying `x-ratelimit-*` headers.\n    ",
        "operationId": "deleteSprint",
        "parameters": [
          {
            "description": "Sprint id",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag \"sprints:<id>:<row_version>\"",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:manage` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "ETag mismatch",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing If-Match",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a sprint (If-Match)",
        "tags": [
          "sprints"
        ]
      },
      "get": {
        "description": "\nFetch a sprint by id and emit a strong ETag for optimistic concurrency.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:view`.\n- Tenant guard: sprint must belong to caller tenant; cross-tenant sprints are masked as 404.\n\nResponse:\n- `200 OK` with `SprintResponse`.\n- Headers: `ETag: \"sprints:<id>:<row_version>\"`, `x-request-id`.\n- `404 Not Found` when the sprint does not exist or belongs to another tenant.\n\nRate limiting:\n- Standard per-route limits; `429 Too Many Requests` returns `x-ratelimit-*` headers.\n    ",
        "operationId": "getSprint",
        "parameters": [
          {
            "description": "Sprint id",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SprintResponse"
                }
              }
            },
            "description": "Sprint",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"sprints:<id>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:view` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get sprint by id",
        "tags": [
          "sprints"
        ]
      },
      "patch": {
        "description": "\nPatch a sprint using optimistic concurrency (strong `If-Match` ETag).\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:manage`.\n- Tenant guard: sprint must belong to caller tenant; cross-tenant items surface as 404.\n\nConcurrency:\n- Requires `If-Match: \"sprints:<id>:<row_version>\"`.\n- Returns `412 Precondition Failed` on version mismatch; `428` when header missing.\n\nBehavior:\n- Allows partial updates of name/goal/state/dates.\n- Trims empty names and rejects blank values.\n\nResponse:\n- `200 OK` with updated `SprintResponse`.\n- Headers: new strong `ETag`, `x-request-id`.\n- `404` when sprint not found in tenant scope.\n\nRate limiting:\n- Standard per-route limits; `429` includes `x-ratelimit-*`.\n    ",
        "operationId": "updateSprint",
        "parameters": [
          {
            "description": "Sprint id",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag \"sprints:<id>:<row_version>\"",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateSprintRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SprintResponse"
                }
              }
            },
            "description": "Updated sprint",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"sprints:<id>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:manage` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "ETag mismatch",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Missing If-Match",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a sprint (If-Match)",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/sprints/{sprint_id}/board": {
      "get": {
        "description": "\nList the sprint board as grouped columns (status or assignee) within the caller's tenant.\n\nAuthorization:\n  - Requires Bearer JWT (`Authorization: Bearer <token>`).\n  - Requires RBAC `projects:sprints:view`.\n  - Tenant guard: sprints from other tenants are masked as 404.\n\nMulti-tenancy:\n  - Tenant context is derived from the Bearer JWT.\n  - Tickets belonging to other tenants never leak (404).\n\nBehavior:\n  - Default grouping is by ticket status; `group=assignee` groups by assignee buckets.\n  - Tickets are returned in sprint ordering inside each column.\n\nResponse:\n  - `200 OK` with `[SprintBoardColumnResponse]` (columns -> tickets).\n  - `404 Not Found` when the sprint is missing or cross-tenant.\n  - Always emits `x-request-id` for correlation/audit.\n\nRate limiting:\n  - Standard per-route limits; `429 Too Many Requests` returns `x-ratelimit-*` and `retry-after` when configured.\n    ",
        "operationId": "sprintBoard",
        "parameters": [
          {
            "description": "Sprint id",
            "in": "path",
            "name": "sprint_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "`assignee` to group by assignee, otherwise by status",
            "in": "query",
            "name": "group",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/SprintBoardColumnResponse"
                  },
                  "type": "array"
                }
              }
            },
            "description": "Board columns",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:view` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Sprint not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Sprint board grouped view",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/sprints/{sprint_id}/tickets/{ticket_id}": {
      "delete": {
        "description": "\nRemove a ticket from the sprint and place it back into the backlog ordering.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:manage`.\n- Tenant guard: sprint and ticket must belong to caller tenant; cross-tenant items are masked as 404.\n\nBehavior:\n- Ticket is removed from sprint ordering and appended to backlog ordering.\n- Safe to call repeatedly; no-op if already in backlog.\n\nResponse:\n- `204 No Content` on success.\n- `404 Not Found` when sprint/ticket missing or not part of the sprint.\n- Always emits `x-request-id` for audit.\n\nRate limiting:\n- Standard per-route rate/concurrency limits; `429` returns `x-ratelimit-*` headers.\n    ",
        "operationId": "unassignTicketFromSprint",
        "parameters": [
          {
            "description": "Sprint id",
            "in": "path",
            "name": "sprint_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Ticket id",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Unassigned",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:manage` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found / not in sprint",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Unassign a ticket from a sprint",
        "tags": [
          "sprints"
        ]
      },
      "post": {
        "description": "\nMove a ticket into the given sprint and append it at the end of the sprint ordering.\n\nAuthorization:\n- Bearer JWT (`Authorization: Bearer <token>`).\n- RBAC `projects:sprints:manage`.\n- Tenant guard: both sprint and ticket must belong to the caller tenant; cross-tenant attempts are masked as 404.\n\nBehavior:\n- Removes the ticket from any previous sprint/backlog ordering, then appends to this sprint.\n- Preserves optimistic concurrency for tickets themselves (ETag handled by ticket APIs).\n\nResponse:\n- `204 No Content` on success.\n- `404 Not Found` when sprint/ticket is missing or not in project/tenant scope.\n- Always returns `x-request-id` header for audit.\n\nRate limiting:\n- Standard per-route limits apply; `429 Too Many Requests` carries `x-ratelimit-*` metadata.\n    ",
        "operationId": "assignTicketToSprint",
        "parameters": [
          {
            "description": "Sprint id",
            "in": "path",
            "name": "sprint_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Ticket id",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Assigned",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:manage` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found / project mismatch",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Assign a ticket to a sprint",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/sprints/{sprint_id}/velocity": {
      "get": {
        "description": "\nReturn a velocity snapshot for a sprint (completed vs total tickets/story points).\n\nAuthorization:\n- Bearer JWT.\n- RBAC `projects:sprints:view`.\n- Tenant guard: sprint must belong to caller tenant; cross-tenant IDs are masked as 404.\n\nBehavior:\n- Counts tickets assigned to the sprint; includes story points when present.\n- Safe to call repeatedly; no side effects.\n\nResponse:\n- `200 OK` with `SprintVelocityResponse { completed, total, completed_points, total_points }`.\n- `x-request-id` header always present.\n\nRate limiting:\n- Standard per-route limits with `429` carrying `x-ratelimit-*`.\n    ",
        "operationId": "sprintVelocity",
        "parameters": [
          {
            "description": "Sprint id",
            "in": "path",
            "name": "sprint_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SprintVelocityResponse"
                }
              }
            },
            "description": "Velocity",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (`projects:sprints:view` required)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Sprint not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Sprint velocity snapshot",
        "tags": [
          "sprints"
        ]
      }
    },
    "/api/v1/tenants": {
      "get": {
        "description": "\nRetrieve a paginated list of **tenants**.\n\nAuthorization:\n- Requires Bearer JWT.\n- Requires RBAC permission `tenants:READ`.\n- Typically a platform-scope operation—adjust if you want to restrict to self-tenant only.\n\nQuery:\n- `ListTenantsQuery` provides pagination and optional filters.\n\nBehavior:\n- Delegates to `uc_list_tenants.execute(q)`.\n\nResponse:\n- `200 OK` with `TenantPage` (items, page, size, total).\n- Includes `x-request-id`.\n",
        "operationId": "listTenants",
        "parameters": [
          {
            "description": "Free text query (ILIKE name)",
            "in": "query",
            "name": "q",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "1-based page",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantPageResponse"
                }
              }
            },
            "description": "Tenants page",
            "headers": {
              "x-request-id": {
                "description": "Correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `tenants:READ`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List tenants",
        "tags": [
          "tenants"
        ]
      },
      "post": {
        "description": "Create a new tenant (platform-scope operation; RBAC required).",
        "operationId": "createTenant",
        "parameters": [
          {
            "description": "Provide to make creation exactly-once (handler-scoped)",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTenantRequest"
              }
            }
          },
          "description": "Tenant creation payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantResponse"
                }
              }
            },
            "description": "Idempotent replay (existing tenant returned)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tenants:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the tenant",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantResponse"
                }
              }
            },
            "description": "Tenant created",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tenants:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the new tenant",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Duplicate in-flight or inconsistent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create tenant",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/invites/accept": {
      "post": {
        "description": "\nAccept a tenant invite using a token delivered by email.\n\nBehavior:\n- A password reset token is minted and returned for setting a new password. The response includes `target_email` for client display.\n",
        "operationId": "acceptTenantInvite",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AcceptInviteRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcceptInviteResponse"
                }
              }
            },
            "description": "Invite accepted. Response includes the password reset token and target_email.",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid or expired token",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Accept a tenant invite with a token",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/name/{name}": {
      "get": {
        "description": "\nFetch a **tenant** by its `name` using case-insensitive match (CITEXT).\n\n- Requires JWT + `tenants:READ`.\n- URL-encode spaces or special characters (e.g., `Acme%20Inc.`).\n- Strong ETag: `\"tenants:<uuid>:<row_version>\"`.\n",
        "operationId": "getTenantByName",
        "parameters": [
          {
            "description": "Tenant name (case-insensitive)",
            "in": "path",
            "name": "name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tenants:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `tenants:READ`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Tenant not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a tenant by name (CITEXT, case-insensitive)",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/search": {
      "get": {
        "description": "\nPerforms ranked fuzzy search across **tenants** using PostgreSQL trigram similarity.\n\n### Authorization\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tenants:LIST`.\n\n### Search semantics\n- `q` (query) must be non-empty after trimming.\n- Matches are ranked by trigram similarity on tenant name.\n- Pagination via `page` (1-based) and `size` (clamped server-side, e.g. max 200).\n\n### Multi-tenancy\n- This endpoint searches across all tenants (platform scope).\n- Results are restricted by the caller’s role/permissions, not a single tenant.\n\n### Response\n- Returns `200 OK` with a paginated [`TenantPage`](#schema-TenantPage) object.\n- Includes `rank` (0.0–1.0 similarity score).\n- Includes `x-request-id` for audit correlation.\n\n### Rate limiting\n- Subject to per-route concurrency and rate limits.\n- Returns `429 Too Many Requests` if limits exceeded.\n",
        "operationId": "searchTenant",
        "parameters": [
          {
            "description": "1-based page",
            "in": "query",
            "name": "page",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Non-empty query",
            "in": "query",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantPageResponse"
                }
              }
            },
            "description": "Ranked paginated tenant search results",
            "headers": {
              "x-request-id": {
                "description": "Correlation ID for audit / tracing",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error (invalid or empty query)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized (missing or invalid JWT)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (caller lacks `tenants:LIST`)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency exceeded",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Internal server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Search tenants (platform-wide trigram search)",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{id}": {
      "delete": {
        "description": "\nDelete a tenant by id.\n\nAuthorization:\n- Requires JWT and RBAC permission `tenants:DELETE`.\n- **Be careful** with cascading deletes and data retention policies.\n\nSemantics:\n- **Idempotent** by contract: returns `204 No Content` even if already absent.\n\nETag:\n- If the tenant existed at deletion time, response includes a strong ETag\n  `\"tenants:<uuid>:<row_version>\"` representing the removed version.\n",
        "operationId": "deleteTenant",
        "parameters": [
          {
            "description": "Tenant identifier (UUID) to delete",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Tenant deleted (or already absent)",
            "headers": {
              "ETag": {
                "description": "Strong ETag of removed version: `\"tenants:<uuid>:<version>\"` (present only if it existed at deletion time)",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `tenants:DELETE`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a tenant (platform-scope)",
        "tags": [
          "tenants"
        ]
      },
      "get": {
        "description": "\nFetch a single **tenant** by its unique identifier.\n\nAuthorization:\n- Requires a valid Bearer JWT and RBAC permission `tenants:READ`.\n- Typically a platform-scope operation; adapt policy if you want \"only self-tenant\".\n\nBehavior:\n- Uses `uc_get_tenant.by_id(id)`.\n- If found, returns `TenantResponse`; otherwise `404`.\n\nResponse:\n- `200 OK` with `TenantResponse`.\n- Strong `ETag` header: `\"tenants:<uuid>:<row_version>\"`.\n- Includes `x-request-id`.\n",
        "operationId": "getTenant",
        "parameters": [
          {
            "description": "Tenant identifier (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantResponse"
                }
              }
            },
            "description": "Tenant successfully retrieved",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tenants:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing/invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `tenants:READ`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a tenant by ID",
        "tags": [
          "tenants"
        ]
      },
      "patch": {
        "description": "\nUpdate mutable fields on a tenant (platform-scope).\n\nOptimistic concurrency:\n- Requires **strong** `If-Match` with format: `\"tenants:<uuid>:<row_version>\"`.\n- `428` if missing, `412` if mismatch/stale.\n\nAuthorization:\n- Requires `tenants:UPDATE`.\n\nResponse:\n- `200 OK` with updated resource + strong `ETag`.\n",
        "operationId": "updateTenant",
        "parameters": [
          {
            "description": "Tenant ID",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag `\"tenants:<uuid>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateTenantRequest"
              }
            }
          },
          "description": "Partial update payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantResponse"
                }
              }
            },
            "description": "Updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"tenants:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed (ETag mismatch)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required (missing If-Match)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a tenant (If-Match required)",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{tenant_id}/invitations": {
      "get": {
        "description": "Lists tenant invitations with deterministic newest-first pagination. Pending invitations past `expires_at` are returned as `expired`. Requires `tenants:members:manage`.",
        "operationId": "listTenantInvitations",
        "parameters": [
          {
            "description": "Tenant ID",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "status",
            "required": false,
            "schema": {
              "enum": [
                "pending",
                "accepted",
                "revoked",
                "expired"
              ],
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "email",
            "required": false,
            "schema": {
              "format": "email",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "default": 1,
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "default": 20,
              "format": "int64",
              "maximum": 100,
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantInvitationPage"
                }
              }
            },
            "description": "Paginated tenant invitations",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid filter or pagination",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Tenant not found or inaccessible",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List tenant invitations",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{tenant_id}/invitations/{invitation_id}": {
      "delete": {
        "description": "Idempotently revokes an unaccepted tenant invitation and invalidates its active token. Accepted invitations return conflict. Requires `tenants:members:manage`.",
        "operationId": "revokeTenantInvitation",
        "parameters": [
          {
            "description": "Tenant ID",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Invitation ID",
            "in": "path",
            "name": "invitation_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Invitation revoked",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invitation not found in tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Accepted invitation cannot be revoked",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Persistence or audit failure",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Revoke a tenant invitation",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{tenant_id}/invitations/{invitation_id}/resend": {
      "post": {
        "description": "Atomically replaces the token hash, refreshes the seven-day expiration, increments `send_count`, and dispatches the existing invitation email. A configurable cooldown defaults to 60 seconds. Requires `tenants:members:manage`.",
        "operationId": "resendTenantInvitation",
        "parameters": [
          {
            "description": "Tenant ID",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Invitation ID",
            "in": "path",
            "name": "invitation_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantInvitation"
                }
              }
            },
            "description": "Invitation resent",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden"
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invitation not found in tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invitation lifecycle conflict",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invitation resend cooldown has not elapsed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Persistence, audit, or delivery failure",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Resend a tenant invitation",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{tenant_id}/invites": {
      "post": {
        "description": "Create an email-based tenant invitation for a user and role. The invitation token is accepted through `/api/v1/tenants/invites/accept`.",
        "operationId": "inviteTenantUser",
        "parameters": [
          {
            "description": "Tenant ID",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InviteTenantUserRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InviteTenantUserResponse"
                }
              }
            },
            "description": "Invite created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid payload",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Tenant not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Invite a user to a tenant (email-based token)",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{tenant_id}/members/{user_id}": {
      "delete": {
        "description": "\nRemove (revoke) a user's membership from the given tenant.\n\nAuthorization:\n- Requires JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tenants:members:manage` (mapped here as `perms::tenants::MANAGE_MEMBERS`).\n- Caller must belong to the same tenant as the path `tenant_id`; cross-tenant is forbidden.\n\nSemantics:\n- **Idempotent** by contract: returns `204 No Content` even if the membership is already gone\n  or was never present for this tenant/user pair.\n",
        "operationId": "removeTenantMember",
        "parameters": [
          {
            "description": "Tenant identifier (UUID)",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "User identifier (UUID) to remove from the tenant",
            "in": "path",
            "name": "user_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Membership deleted (or already absent)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks permission or cross-tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Remove a user from a tenant (membership)",
        "tags": [
          "tenants"
        ]
      },
      "get": {
        "description": "\nRetrieve a single membership for a given tenant and user.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- **Always** requires RBAC permission `tenants:VIEW_MEMBERS` to see any membership data.\n- If the requested `tenant_id` **matches** the caller's current tenant (`Ctx::tenant_id()`),\n  no additional tenant-level permission is required.\n- If the requested `tenant_id` **differs** from the caller's tenant, the caller must also have\n  RBAC permission **`tenants:READ`** to access cross-tenant membership data.\n\nMulti-tenancy:\n- The tenant and member are both provided explicitly as path parameters\n  (`/api/v1/tenants/{tenant_id}/members/{user_id}`).\n- The caller's own tenant is derived from the authenticated context (`Ctx`) injected by\n  middleware (e.g., decoded JWT, headers).\n- Cross-tenant access:\n  - Allowed only when the caller has both `tenants:VIEW_MEMBERS` and `tenants:READ`.\n  - Otherwise, the server returns `403 Forbidden`.\n\nBehavior:\n- The service layer (`uc_get_tenant_member`) retrieves the membership belonging to the\n  `tenant_id` and `user_id` provided in the URL path.\n- If no membership exists, returns **`404 Not Found`**.\n\nObservability:\n- Each request is correlated with an `x-request-id` header.\n- The handler records `tenant_id`, `user_id` (caller), and `member_id` (target user)\n  into the current tracing span for consistent logging and diagnostics.\n\nResponse:\n- Returns **`200 OK`** with a JSON `TenantMemberResponse` on success.\n- Includes `x-request-id` for correlation and tracing (propagated by middleware/logging).\n\nRate limiting:\n- This route is subject to per-route concurrency and/or rate limits.\n- When limits are exceeded, the server returns **`429 Too Many Requests`** with\n  standard rate-limit headers (`x-ratelimit-*`, `retry-after`).\n",
        "operationId": "getTenantMember",
        "parameters": [
          {
            "description": "Tenant that owns the membership",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "User whose membership is being retrieved",
            "in": "path",
            "name": "user_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantMemberResponse"
                }
              }
            },
            "description": "Membership successfully retrieved for the tenant + user",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"tenant_members:<user_id>:<version>\"` for guarded role updates",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tenants:VIEW_MEMBERS` and/or `tenants:READ` for cross-tenant access",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Membership not found for the given tenant + user",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a single membership for a tenant",
        "tags": [
          "tenants"
        ]
      },
      "put": {
        "description": "\nAssign or update a user's role within a tenant.\n\nOptimistic concurrency:\n- Requires **strong** `If-Match` with format: `\"tenant_members:<user_id>:<row_version>\"`.\n- `428` if missing, `412` if mismatch/stale.\n- For first-time insert, clients may use version `0` (e.g. `\"tenant_members:<user_id>:0\"`),\n  and the UC can treat `(not found && expected_ver == 0)` as \"create\".\n\nAuthorization:\n- Requires `tenants:members:manage` (here mapped as `perms::tenants::MANAGE_MEMBERS`).\n- Caller must belong to the same tenant as the path `tenant_id`; cross-tenant is forbidden.\n\nResponse:\n- `200 OK` with the upserted membership + strong `ETag`.\n",
        "operationId": "upsertTenantMember",
        "parameters": [
          {
            "description": "Tenant ID",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "User ID whose membership is being set",
            "in": "path",
            "name": "user_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag `\"tenant_members:<user_id>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpsertTenantMemberBody"
              }
            }
          },
          "description": "Upsert tenant membership payload (role assignment)",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TenantMemberResponse"
                }
              }
            },
            "description": "Upserted membership",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"tenant_members:<user_id>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found (if UC chooses to signal missing user/tenant)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed (ETag mismatch)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required (missing If-Match)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Upsert a tenant member (If-Match required)",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{tenant_id}/memberships": {
      "get": {
        "description": "\nRetrieve all memberships for a given tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- **Always** requires RBAC permission `tenants:VIEW_MEMBERS` to see any membership data.\n- If the requested `tenant_id` **matches** the caller's current tenant (`Ctx::tenant_id()`),\n  no additional tenant-level permission is required.\n- If the requested `tenant_id` **differs** from the caller's tenant, the caller must also have\n  RBAC permission **`tenants:READ`** to access cross-tenant membership data.\n\nMulti-tenancy:\n- The tenant whose memberships are being listed is provided explicitly as a path parameter\n  (`/api/v1/tenants/{tenant_id}/memberships`).\n- The caller's own tenant is derived from the authenticated context (`Ctx`) injected by\n  middleware (e.g., decoded JWT, headers).\n- Cross-tenant access:\n  - Allowed only when the caller has both `tenants:VIEW_MEMBERS` and `tenants:READ`.\n  - Otherwise, the server returns `403 Forbidden`.\n\nBehavior:\n- The service layer (`uc_list_tenant_members`) retrieves memberships belonging to the\n  `tenant_id` provided in the URL path.\n- Returns a flat list of membership records (`TenantMemberResponse`).\n\nObservability:\n- Each request is correlated with an `x-request-id` header.\n- The handler records `tenant_id` and `user_id` fields into the current tracing span\n  for consistent logging and diagnostics.\n\nResponse:\n- Returns **`200 OK`** with a JSON array of `TenantMemberResponse`.\n- Includes `x-request-id` for correlation and tracing (propagated by middleware/logging).\n\nRate limiting:\n- This route is subject to per-route concurrency and/or rate limits.\n- When limits are exceeded, the server returns **`429 Too Many Requests`** with\n  standard rate-limit headers (`x-ratelimit-*`, `retry-after`).\n",
        "operationId": "listTenantMemberships",
        "parameters": [
          {
            "description": "Tenant whose memberships are being listed",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Vec"
                }
              }
            },
            "description": "List of memberships successfully retrieved for the tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tenants:VIEW_MEMBERS` and/or `tenants:READ` for cross-tenant access",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List memberships for a tenant",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tenants/{tenant_id}/roles": {
      "get": {
        "description": "\nList roles available in the tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT.\n- If the caller has `roles:READ` or `tenants:INVITE_USER`, all roles are returned.\n- Otherwise only the caller's effective role is returned.\n\nMulti-tenancy:\n- `tenant_id` must match the caller's tenant; mismatches return `404`.\n",
        "operationId": "listTenantRoles",
        "parameters": [
          {
            "description": "Tenant ID",
            "in": "path",
            "name": "tenant_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListRolesResponse"
                }
              }
            },
            "description": "List of roles",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Tenant not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List roles for a tenant",
        "tags": [
          "tenants"
        ]
      }
    },
    "/api/v1/tickets": {
      "get": {
        "description": "\nRetrieve a paginated list of tickets for the current tenant.\n\n**Authorization**\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:LIST` (or `tickets:READ` if listing is merged with read).\n- Caller must belong to the same tenant as the tickets being listed.\n\n**Pagination & Filtering**\n- Query parameters are validated via `ListTicketsQuery`.\n- Supported params: `page` (≥ 1), `size` (clamped server-side, e.g. max 200).\n- The repository defensively clamps `size` even after validation.\n\n**Multi-tenancy**\n- Tenant context is derived from the Bearer JWT.\n- Data isolation is strict — tickets from other tenants are not visible.\n\n**Response**\n- Returns `200 OK` with a `TicketPage` object (`items`, `page`, `size`, `total`).\n- Set `include_total=false` to skip the count query; `total` will be `-1` when skipped.\n- Includes `x-request-id` header for correlation and audit tracing.\n\n**Rate limiting**\n- This route is subject to per-route concurrency / rate limits.\n- Exceeding limits yields `429 Too Many Requests` with `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "listTicket",
        "parameters": [
          {
            "description": "Free text query",
            "in": "query",
            "name": "q",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Filters",
            "in": "query",
            "name": "project_id",
            "required": false,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "reporter_id",
            "required": false,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "assignee_id",
            "required": false,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "status",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/TicketStatus"
            }
          },
          {
            "in": "query",
            "name": "type",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/TicketType"
            }
          },
          {
            "in": "query",
            "name": "priority",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/PriorityLevel"
            }
          },
          {
            "in": "query",
            "name": "label_id",
            "required": false,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "JSON array of custom field filters. Each item has key, optional op (eq or contains), and canonical value. Requires project_id. Values follow custom-field formats: text string, number exact decimal string, date YYYY-MM-DD string, boolean, single_select option value string, or multi_select option value array. contains is only valid for multi_select and its value is one option string.",
            "in": "query",
            "name": "custom_fields",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Pagination",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Include total count (set false to skip count query).",
            "in": "query",
            "name": "include_total",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketListPageResponse"
                }
              }
            },
            "description": "Paged ticket list for the tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error in query parameters",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:LIST` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List tickets",
        "tags": [
          "tickets"
        ]
      },
      "post": {
        "description": "Create a new ticket. Either `project_id` or `project_key` must be present.",
        "operationId": "createTicket",
        "parameters": [
          {
            "description": "Provide to make create exactly-once (handler-scoped)",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTicketRequest"
              }
            }
          },
          "description": "Ticket creation payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Idempotent replay (existing ticket returned)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the ticket",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Ticket successfully created",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the new ticket",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict (duplicate in-flight or inconsistent replay)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create ticket",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/bulk": {
      "patch": {
        "description": "\nApply partial updates to multiple tickets in a single request.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:BULK_UPDATE`.\n- Caller must belong to the same tenant as the tickets being modified.\n\nRequest semantics:\n- The request body is `BulkTicketUpdateRequest`.\n- Each element in `updates` contains:\n  - `id`: the ticket UUID to update.\n  - `patch`: a partial update payload (same shape as a single-ticket PATCH).\n- The same validation rules that apply to `PATCH /tickets/{id}` apply here. Invalid fields, illegal transitions, etc. are rejected at the per-item level.\n\nExecution model:\n- Each ticket is processed independently.\n- The operation is \"best effort\":\n  - Some tickets may update successfully.\n  - Others may fail (for example: not found, forbidden, validation error, rate limited).\n- The endpoint itself still returns HTTP 200 if the request was syntactically valid.\n\nResponse semantics:\n- Response body is `BulkTicketUpdateResponse`.\n- That response contains `results`, an array.\n- Each array entry is either:\n  - `Ok`: represented by `BulkTicketUpdateItemOk` (includes the updated ticket data)\n  - `Err`: represented by `BulkTicketUpdateItemErr` (stable short `code` + message)\n- The response includes a strong ETag that represents the full result set:\n  `\"bulk:tickets:<uuid>:<row_version>,...\"`. This changes whenever any included ticket version changes.\n- Provide optional `Idempotency-Key` to replay the exact prior bulk result\n  snapshot for identical retries without re-applying item updates.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Tickets from other tenants behave as failures for those specific items (for example, NotFound / Forbidden), but do not block other items.\n\nObservability:\n- Every request includes an `x-request-id` header in the response. Log this for audit / debugging.\n\nRate limiting:\n- This route is subject to per-route concurrency and rate limits.\n- If the overall request is rejected due to rate limiting, the server responds `429 Too Many Requests` and does not attempt any item updates. The response will include `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "bulkUpdateTicket",
        "parameters": [
          {
            "description": "Provide to make the bulk update exactly-once",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BulkTicketUpdateRequest"
              }
            }
          },
          "description": "List of ticket updates to apply. Each entry targets one ticket by id plus a partial update patch.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BulkTicketUpdateResponse"
                }
              }
            },
            "description": "Bulk update completed. Check per-item results for success / failure.",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the *entire* result set: `\"bulk:tickets:<uuid>:<version>,...\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Request was rejected before any updates ran (invalid body shape, missing fields, etc.)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:BULK_UPDATE` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "413": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Payload too large – request exceeds configured body limit",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit before execution",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Bulk update multiple tickets",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/search": {
      "get": {
        "description": "\nFull-text / trigram search across tickets in the current tenant.\n\n**Authorization**\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:SEARCH`.\n- Caller must belong to the same tenant as the tickets being searched.\n\n**Search semantics**\n- `q` is required and must be non-empty after trimming.\n- Filters: project_id, assignee_id, reporter_id, label_ids (AND semantics), status, type, priority, sprint_id, created/updated ranges.\n- Sort: relevance (default), updated_at_desc, created_at_desc, priority_desc, due_date_asc.\n- Pagination: 1-based `page`; `size` clamped (max hard cap).\n\n**Multi-tenancy**\n- Tenant context is derived from the Bearer JWT.\n- Results never include tickets from other tenants.\n\n**Response**\n- Returns `200 OK` with a `TicketPage` object:\n  - `items`: matching tickets in ranked order\n  - `page`, `size`: echo of your request / clamped values\n  - `total`: total matches for that query (set `include_total=false` to skip the count query; `total` will be -1)\n- Includes `x-request-id` header for correlation and audit support.\n\n**Rate limiting**\n- This route is subject to per-route concurrency / rate limits.\n- If limits are exceeded, you get `429 Too Many Requests` with `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "searchTicket",
        "parameters": [
          {
            "description": "1-based page number. Defaults to 1 if <1.",
            "in": "path",
            "name": "page",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size (max will be clamped server-side, e.g. 200).",
            "in": "path",
            "name": "size",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Free-text query. We'll rank by similarity / ts_rank.",
            "in": "path",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional project filter.",
            "in": "path",
            "name": "project_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional assignee filter.",
            "in": "path",
            "name": "assignee_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional reporter filter.",
            "in": "path",
            "name": "reporter_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Comma-separated label ids; ticket must have ALL listed labels.",
            "in": "path",
            "name": "label_ids",
            "required": true,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "status",
            "required": true,
            "schema": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/components/schemas/TicketStatus"
                }
              ]
            }
          },
          {
            "in": "path",
            "name": "type",
            "required": true,
            "schema": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/components/schemas/TicketType"
                }
              ]
            }
          },
          {
            "in": "path",
            "name": "priority",
            "required": true,
            "schema": {
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/components/schemas/PriorityLevel"
                }
              ]
            }
          },
          {
            "in": "path",
            "name": "sprint_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "created_from",
            "required": true,
            "schema": {
              "format": "date-time",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "created_to",
            "required": true,
            "schema": {
              "format": "date-time",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "updated_from",
            "required": true,
            "schema": {
              "format": "date-time",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "updated_to",
            "required": true,
            "schema": {
              "format": "date-time",
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "JSON array of custom field filters. Each item has key, optional op (eq or contains), and canonical value. Requires project_id. Values follow custom-field formats: text string, number exact decimal string, date YYYY-MM-DD string, boolean, single_select option value string, or multi_select option value array. contains is only valid for multi_select and its value is one option string.",
            "in": "query",
            "name": "custom_fields",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Sort mode: relevance|updated_at_desc|created_at_desc|priority_desc|due_date_asc",
            "in": "path",
            "name": "sort",
            "required": true,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Include total count (set false to skip count query).",
            "in": "path",
            "name": "include_total",
            "required": true,
            "schema": {
              "type": [
                "boolean",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketListPageResponse"
                }
              }
            },
            "description": "Ranked paginated search results for this tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error (e.g. empty `q`, invalid page/size)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:LIST` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Search tickets",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/{id}": {
      "delete": {
        "description": "\nDelete a ticket in the current tenant.\n\nAuth & RBAC:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Caller must have RBAC permission `tickets:DELETE`.\n- Caller must belong to the same tenant as the target ticket.\n\nSemantics:\n- This endpoint is **idempotent by contract**.\n- The server returns **204 No Content** even if the ticket was already deleted\n  or is no longer visible to this tenant.\n\nETag:\n- If the ticket exists at the time of deletion, the response includes a strong ETag\n  of the form `\"tickets:<uuid>:<row_version>\"` representing the version that was removed.\n\nObservability:\n- Each request includes an `x-request-id` header in the response for correlation.\n\nRate limiting:\n- This route may be protected by per-route concurrency / rate limits.\n- On limit exceeded, the server responds with `429 Too Many Requests` and standard rate-limit headers.\n",
        "operationId": "deleteTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) to delete",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Ticket deleted (or already absent for this tenant)",
            "headers": {
              "ETag": {
                "description": "Strong ETag of the removed version: `\"tickets:<uuid>:<version>\"` (present only if the ticket existed at deletion time)",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized. Missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden. Caller lacks `tickets:DELETE`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete ticket",
        "tags": [
          "tickets"
        ]
      },
      "get": {
        "description": "\nFetch a single ticket by ID within the caller's tenant.\n\n**Authorization**\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:READ`.\n- Caller must belong to the same tenant as the target ticket.\n\n**Multi-tenancy**\n- Tenant is derived from the Bearer JWT.\n- Tickets belonging to other tenants are masked as `404 Not Found`.\n\n**Response**\n- Returns `200 OK` with the full `TicketResponse` JSON object on success.\n- Includes a strong `ETag` header of the form `\"tickets:<uuid>:<row_version>\"`.\n- Includes the `x-request-id` header for correlation and audit.\n\n**Rate limiting**\n- Subject to per-route concurrency and rate limits.\n- When limits are exceeded, responds `429 Too Many Requests` with\n  standard `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "getTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) to retrieve",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Ticket retrieved successfully",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:READ` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get ticket",
        "tags": [
          "tickets"
        ]
      },
      "patch": {
        "description": "\nApply a partial update (PATCH semantics) to a ticket in the current tenant.\n\n**Authorization**\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:UPDATE`.\n- Caller must belong to the same tenant as the target ticket.\n\n**Partial update semantics**\n- Request body is an `UpdateTicket` patch object.\n- Only provided fields are updated; unspecified fields remain unchanged.\n- Validation (required formats, enum values, business rules) is enforced at extraction time via `ValidatedJson`.\n  Client-side mistakes surface as `400 Bad Request`, not `500`.\n\n**Multi-tenancy**\n- Tenant is derived from the Bearer JWT.\n- Tickets from other tenants are masked as `404 Not Found`.\n\n**Response**\n- Returns `200 OK` with the updated `TicketResponse`.\n- Includes a strong `ETag` of the form `\"tickets:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for correlation / audit.\n\n**Idempotency**\n- Provide optional `Idempotency-Key` header to make this update exactly-once.\n- Replays with the same key and identical payload will return the same logical\n  updated ticket without applying the patch twice.\n\n**Concurrency / conflict**\n- If the update violates constraints (e.g. illegal transition, optimistic check, etc.), you may receive `409 Conflict`.\n\n**Rate limiting**\n- This route is subject to per-route concurrency / rate limits.\n- If limits are exceeded, you get `429 Too Many Requests` with `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "updateTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) to update",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make this update exactly-once",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateTicketRequest"
              }
            }
          },
          "description": "Partial ticket update (only provided fields are applied)",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Updated ticket after applying the patch",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error in request body",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:UPDATE` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict – business rule, state conflict, or duplicate in-flight idempotent call",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update ticket",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/{id}/activity": {
      "get": {
        "description": "\nList all activity events for a specific ticket in the caller's tenant.\n\nAuthorization:\n- Bearer JWT (`Authorization: Bearer <token>`).\n- RBAC `tickets:read`.\n- Tenant guard: ticket must belong to the caller tenant; cross-tenant tickets are masked as 404.\n\nWhat you'll see:\n- Ticket lifecycle: create/update/delete, state/assignee/label/relation/watch changes.\n- Comment add/update/delete.\n- Other domain events logged against this ticket.\n\nPagination:\n- `page` is 1-based; `size` clamped server-side (max guardrail).\n- Sorted newest-first.\n\nResponse:\n- `200 OK` with `Page<ActivityEventResponse> { items, page, size, total }`.\n- Includes `x-request-id` for correlation / audit.\n\nRate limiting:\n- Standard per-route concurrency / rate limits; `429 Too Many Requests` includes `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "listTicketActivity",
        "parameters": [
          {
            "description": "Ticket id",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Page number (1-based)",
            "example": 1,
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size (1..=200)",
            "example": 20,
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page_ActivityEventResponse"
                }
              }
            },
            "description": "Activity events for ticket",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid params",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden (requires `tickets:read`)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Ticket activity timeline",
        "tags": [
          "tickets",
          "activity"
        ]
      }
    },
    "/api/v1/tickets/{id}/agent-runs": {
      "get": {
        "description": "List agent runs created for a ticket in the current tenant.",
        "operationId": "listTicketAgentRuns",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Page number (1-based)",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunPageResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List ticket agent runs",
        "tags": [
          "tickets",
          "agents"
        ]
      },
      "post": {
        "description": "Create an agent run for a ticket in the current tenant.",
        "operationId": "createTicketAgentRun",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAgentRunRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunResponse"
                }
              }
            },
            "description": "Agent run created",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the agent run row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create a ticket agent run",
        "tags": [
          "tickets",
          "agents"
        ]
      }
    },
    "/api/v1/tickets/{id}/agent-runs/claim": {
      "post": {
        "description": "Claim a ticket for a worker and create a running leased agent run. Active unexpired claims conflict; expired claims are released before a new claim is created.",
        "operationId": "claimTicketAgentRun",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClaimAgentRunRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentRunResponse"
                }
              }
            },
            "description": "Agent run claimed",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the agent run row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Claim a ticket with an agent run",
        "tags": [
          "tickets",
          "agents"
        ]
      }
    },
    "/api/v1/tickets/{id}/assign": {
      "post": {
        "description": "\nAssign or unassign a ticket's assignee.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:ASSIGN`.\n- Caller must belong to the same tenant as the target ticket.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Tickets from other tenants are masked as `404 Not Found`.\n\nOptimistic concurrency:\n- Requires `If-Match: \"tickets:<uuid>:<row_version>\"`.\n- Returns `428` when missing and `412` when the ETag targets another resource or the row version is stale.\n\nRequest body:\n- The request body is `AssignPayload`.\n- Typical shape:\n  - `assignee_id`: UUID of the new assignee.\n  - Or `null`/absence to unassign.\n- Input is validated at the HTTP edge (`ValidatedJson`), so malformed input is surfaced as `400 Bad Request`, not `500`.\n\nBehavior:\n- Updates the assignee for the given ticket.\n- May also record audit information (who reassigned, from what to what).\n- Returns the updated ticket.\n\nResponse:\n- Returns `200 OK` with the updated ticket as `TicketResponse`.\n- Includes a strong ETag of the form `\"tickets:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for correlation / audit tracing.\n\nRate limiting:\n- This route is subject to per-route concurrency and rate limits.\n- When limits are exceeded, responds `429 Too Many Requests` with\n  `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "assignTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) to assign or unassign",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make assignment exactly-once",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Required strong ETag for the target ticket, e.g. `\"tickets:<uuid>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AssignTicketRequest"
              }
            }
          },
          "description": "Assignment payload. Provide an assignee user id to assign, or no assignee to clear assignment.",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Ticket updated with new assignment state",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error in request body",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:ASSIGN` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict – assignment rejected by business rules (e.g., assigning to a user not in the project)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed - stale If-Match or ETag target mismatch",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required - missing If-Match",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Assign / unassign ticket (If-Match required)",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/{id}/attachments": {
      "get": {
        "description": "\nList all non-deleted attachments associated with a ticket in the caller's tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:read`.\n- Caller must belong to the same tenant as the ticket.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Tickets from other tenants are masked as `404 Not Found`.\n- Attachment rows are additionally tenant-scoped at the repository layer.\n\nLifecycle semantics:\n- Returns metadata only; this endpoint never returns object bytes or storage keys.\n- Includes pending, uploaded, scanning, processing, ready, quarantined, and rejected attachments.\n- Soft-deleted attachments are excluded.\n- Downloadability is governed by `GET /api/v1/attachments/{attachment_id}/download`.\n- `can_preview` is true only when the attachment is ready, clean, previewable, and has a ready preview variant.\n\nResponse:\n- Returns `200 OK` with stable attachment metadata ordered by creation time.\n- Each item includes client/detected MIME metadata, media family, dimensions/page count when known,\n  available variants, and preview eligibility.\n\nRate limiting:\n- Subject to the ticket attachment route timeout, concurrency, and global rate-limit layers.\n",
        "operationId": "listTicketAttachments",
        "parameters": [
          {
            "description": "Ticket ID whose attachments should be listed",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListAttachmentsResponse"
                }
              }
            },
            "description": "Ticket attachments listed successfully",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized - missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden - caller lacks `tickets:read` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found - ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List ticket attachments",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/{id}/attachments:initiate": {
      "post": {
        "description": "\nCreate an attachment record and return a short-lived presigned upload target.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:attachment:upload`.\n- Caller must belong to the tenant embedded in the Bearer JWT.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- The ticket must exist in the selected tenant.\n- Tickets from other tenants are masked as `404 Not Found`.\n\nAttachment policy:\n- `filename` is normalized and validated before any storage URL is issued.\n- `size_bytes` must be greater than zero and within the configured attachment limit.\n- `content_type`, when provided, must match the allowlist for the filename/type policy.\n- The storage key is generated server-side; clients must never choose object keys.\n\nUpload contract:\n- The response contains a presigned `PUT` URL, required request headers, and an expiry timestamp.\n- The client uploads the exact file bytes directly to object storage using that URL.\n- The presigned URL is single-purpose and should be used before `expires_at`.\n- After upload, call `POST /api/v1/attachments/{attachment_id}/complete` to verify the object\n  and enqueue asynchronous virus scanning and metadata processing.\n\nResponse:\n- Returns `200 OK` with the new attachment ID and upload instructions.\n- The attachment starts as `pending_upload`; it is not downloadable until completion, scanning,\n  and processing move it to `ready` with `virus_status=clean`.\n\nRate limiting:\n- Subject to the ticket route timeout, concurrency, and global rate-limit layers.\n",
        "operationId": "initiateTicketAttachmentUpload",
        "parameters": [
          {
            "description": "Ticket ID that will own the attachment",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InitiateAttachmentUploadRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InitiateAttachmentUploadResponse"
                }
              }
            },
            "description": "Attachment created and presigned upload instructions returned",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation or attachment policy error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized - missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden - caller lacks `tickets:attachment:upload` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found - ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Initiate ticket attachment upload",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/{id}/comments": {
      "get": {
        "description": "\nRetrieve all comments associated with a specific ticket.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `comments:READ`.\n- Caller must belong to the same tenant as the ticket.\n\nMulti-tenancy:\n- Tenant is derived from the authenticated context (`Ctx`) injected by middleware.\n- Cross-tenant access is rejected.\n\nQuery parameters:\n- Pagination parameters (`page`, `size`) are provided via `ListCommentsQuery`.\n- `page` is 1-based; defaults to 1 if <1.\n- `size` controls the number of comments per page (clamped to a server-side maximum).\n\nBehavior:\n- The service layer (`uc_list_comments`) retrieves comments belonging to the specified `ticket_id`\n  within the caller’s tenant.\n- Returns a paginated list of comments wrapped in `CommentPage`.\n\nResponse:\n- Returns `200 OK` with a paginated `CommentPage` object.\n- Includes `x-request-id` for correlation and tracing.\n\nRate limiting:\n- This route is subject to per-route concurrency and/or rate limits.\n- When exceeded, the server returns `429 Too Many Requests` with rate-limit headers.\n",
        "operationId": "listComments",
        "parameters": [
          {
            "description": "Ticket identifier (UUID) whose comments should be listed",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Page number (1-based)",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Page size (server will clamp to your hard max)",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommentListPageResponse"
                }
              }
            },
            "description": "List of comments successfully retrieved",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `comments:READ` permission or cannot list in this tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant or caller has no access",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List comments for a ticket",
        "tags": [
          "tickets"
        ]
      },
      "post": {
        "description": "Create a new comment on an existing ticket.",
        "operationId": "createComment",
        "parameters": [
          {
            "description": "Ticket identifier (UUID)",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make creation exactly-once (handler-scoped)",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateCommentRequest"
              }
            }
          },
          "description": "Comment creation payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommentResponse"
                }
              }
            },
            "description": "Idempotent replay (existing comment returned)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"comments:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the comment",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommentResponse"
                }
              }
            },
            "description": "Comment successfully created",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"comments:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the new comment",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Ticket not found in this tenant",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Duplicate in-flight or inconsistent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Add a comment to a ticket",
        "tags": [
          "tickets"
        ]
      }
    },
    "/api/v1/tickets/{id}/external-links": {
      "get": {
        "description": "List external links attached to a ticket in the current tenant.",
        "operationId": "listTicketExternalLinks",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Page number (1-based)",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketExternalLinkPageResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List ticket external links",
        "tags": [
          "tickets",
          "agents"
        ]
      },
      "post": {
        "description": "Attach an external link, such as a GitHub pull request, to a ticket.",
        "operationId": "createTicketExternalLink",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTicketExternalLinkRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketExternalLinkResponse"
                }
              }
            },
            "description": "External link attached",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the ticket external link row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Attach a ticket external link",
        "tags": [
          "tickets",
          "agents"
        ]
      }
    },
    "/api/v1/tickets/{id}/external-links/{link_id}": {
      "delete": {
        "description": "Delete a ticket external link with optimistic concurrency. The link must belong to the ticket in the current tenant.",
        "operationId": "deleteTicketExternalLink",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Ticket external link identifier",
            "in": "path",
            "name": "link_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"ticket-external-links:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Ticket external link deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a ticket external link",
        "tags": [
          "tickets",
          "agents"
        ]
      },
      "patch": {
        "description": "Update a ticket external link with optimistic concurrency. The link must belong to the ticket in the current tenant.",
        "operationId": "updateTicketExternalLink",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Ticket external link identifier",
            "in": "path",
            "name": "link_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"ticket-external-links:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateTicketExternalLinkRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketExternalLinkResponse"
                }
              }
            },
            "description": "Ticket external link updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the ticket external link row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a ticket external link",
        "tags": [
          "tickets",
          "agents"
        ]
      }
    },
    "/api/v1/tickets/{id}/labels": {
      "get": {
        "description": "\nFetch all labels currently assigned to a ticket.\n\n**Authorization**\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:READ`.\n- Caller must belong to the same tenant as the ticket.\n\n**Multi-tenancy**\n- Tenant is derived from the Bearer JWT.\n- Tickets from other tenants are masked as `404 Not Found`.\n\n**Response**\n- Returns `200 OK` with `{ \"labels\": [LabelResponse, ...] }`.\n- Includes `x-request-id` for correlation / audit.\n\n**Rate limiting**\n- Subject to per-route concurrency and rate limits.\n- When limits are exceeded, responds `429 Too Many Requests` with\n  standard `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "listTicketLabels",
        "parameters": [
          {
            "description": "Ticket ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketLabelsResponse"
                }
              }
            },
            "description": "Labels assigned to the ticket",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List ticket labels",
        "tags": [
          "labels"
        ]
      },
      "post": {
        "description": "\nReplace the full label set on a ticket.\n\n**Authorization**\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:SET_LABELS`.\n- Caller must belong to the same tenant as the ticket.\n\n**Multi-tenancy**\n- Tenant is derived from the Bearer JWT.\n- Tickets from other tenants are not visible and will behave as `404`.\n\n**Optimistic concurrency**\n- Requires `If-Match: \"tickets:<uuid>:<row_version>\"`.\n- Returns `428` when missing and `412` when the ETag targets another resource or the row version is stale.\n- Successful label replacement advances the ticket row version and returns the new ticket ETag.\n\n**Request body**\n- Body must match `TicketLabelsPayload`.\n- Validation (like required shape, label constraints, max length/count, etc.) is enforced at extraction via `ValidatedJson`.\n\n**Behavior**\n- Completely replaces the ticket's labels with the provided set.\n- All label IDs must exist under the same tenant/project as the ticket; otherwise the request is rejected with `404 Not Found`.\n- Returns the updated ticket representation.\n\n**Response**\n- On success returns `200 OK` with a `TicketResponse`.\n- Includes a strong `ETag` of the form `\"tickets:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for correlation / audit.\n\n**Idempotency**\n- Provide optional `Idempotency-Key` header to make this update exactly-once.\n- Replays with the same key will return the same logical outcome for this ticket\n  without applying the label update twice.\n\n**Rate limiting**\n- This route is subject to per-route concurrency / rate limits.\n- If limits are exceeded, you get `429 Too Many Requests` with `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "labelsTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) whose labels will be replaced",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make label replacement exactly-once",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Required strong ETag for the target ticket, e.g. `\"tickets:<uuid>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TicketLabelsRequest"
              }
            }
          },
          "description": "The full label set to apply to this ticket, replacing the current labels",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Updated ticket with new labels applied",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error in request body",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:SET_LABELS` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "examples": {
                  "label_wrong_project": {
                    "summary": "Label exists in different project",
                    "value": {
                      "code": "not_found",
                      "error": "label_wrong_project"
                    }
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket or labels do not exist in this tenant/project (codes: `ticket_missing`, `label_missing`, `label_wrong_project`)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict (duplicate in-flight or inconsistent replay)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed - stale If-Match or ETag target mismatch",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required - missing If-Match",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Replace ticket labels (If-Match required)",
        "tags": [
          "labels"
        ]
      }
    },
    "/api/v1/tickets/{id}/labels/{label_id}": {
      "delete": {
        "description": "\nRemoves a single label from a ticket. This is idempotent; removing a label that isn't present is treated as success as long as the ticket exists.\n\n**Authorization**\n- Requires `tickets:SET_LABELS`.\n- Tenant scope is derived from the Bearer JWT.\n",
        "operationId": "removeTicketLabel",
        "parameters": [
          {
            "description": "Ticket ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Label ID (UUID)",
            "in": "path",
            "name": "label_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Ticket with label removed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "examples": {
                  "ticket_missing": {
                    "summary": "Ticket not found",
                    "value": {
                      "code": "not_found",
                      "error": "ticket_missing"
                    }
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Ticket not found in this tenant (code: `ticket_missing`)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Remove a label from a ticket",
        "tags": [
          "labels"
        ]
      },
      "post": {
        "description": "\nAdds a single label to the ticket. Label must belong to the same tenant and project as the ticket; if it does not exist or is out of scope, the request returns `404`.\n\nIf the ticket already has this label, the server responds with `409 Conflict` so clients can surface “already assigned”.\n\n**Authorization**\n- Requires `tickets:SET_LABELS`.\n- Tenant scope is derived from the Bearer JWT.\n",
        "operationId": "addTicketLabel",
        "parameters": [
          {
            "description": "Ticket ID (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Label ID (UUID)",
            "in": "path",
            "name": "label_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketResponse"
                }
              }
            },
            "description": "Ticket with label assigned",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "examples": {
                  "label_wrong_project": {
                    "summary": "Label exists but in another project",
                    "value": {
                      "code": "not_found",
                      "error": "label_wrong_project"
                    }
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Ticket or label not found in this tenant/project (codes: `ticket_missing`, `label_missing`, `label_wrong_project`)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "examples": {
                  "duplicate": {
                    "summary": "Label already on ticket",
                    "value": {
                      "code": "conflict",
                      "error": "label_already_assigned"
                    }
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict – label already assigned (`label_already_assigned`)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Assign a label to a ticket",
        "tags": [
          "labels"
        ]
      }
    },
    "/api/v1/tickets/{id}/quality-gate-results": {
      "get": {
        "description": "List quality gate results reported for a ticket in the current tenant.",
        "operationId": "listTicketQualityGateResults",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Page number (1-based)",
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Page size",
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QualityGateResultPageResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List ticket quality gate results",
        "tags": [
          "tickets",
          "agents"
        ]
      },
      "post": {
        "description": "Report running, passed, or failed quality gate results for a ticket.",
        "operationId": "createTicketQualityGateResult",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateQualityGateResultRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QualityGateResultResponse"
                }
              }
            },
            "description": "Quality gate result reported",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the quality gate result row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Report a ticket quality gate result",
        "tags": [
          "tickets",
          "agents"
        ]
      }
    },
    "/api/v1/tickets/{id}/quality-gate-results/{result_id}": {
      "delete": {
        "description": "Delete a ticket quality gate result with optimistic concurrency. The result must belong to the ticket in the current tenant.",
        "operationId": "deleteTicketQualityGateResult",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Quality gate result identifier",
            "in": "path",
            "name": "result_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"quality-gate-results:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Quality gate result deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a ticket quality gate result",
        "tags": [
          "tickets",
          "agents"
        ]
      },
      "patch": {
        "description": "Update a ticket quality gate result with optimistic concurrency. The result must belong to the ticket in the current tenant.",
        "operationId": "updateTicketQualityGateResult",
        "parameters": [
          {
            "description": "Ticket identifier",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Quality gate result identifier",
            "in": "path",
            "name": "result_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"quality-gate-results:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateQualityGateResultRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QualityGateResultResponse"
                }
              }
            },
            "description": "Quality gate result updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag for the quality gate result row version.",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a ticket quality gate result",
        "tags": [
          "tickets",
          "agents"
        ]
      }
    },
    "/api/v1/tickets/{id}/relations": {
      "get": {
        "description": "\nList all relations where the ticket is either the source (`from`) or target (`to`).\n\nAuthorization:\n- Bearer JWT.\n- RBAC `tickets:relations:view`.\n- Tenant guard: ticket must belong to caller tenant; cross-tenant is masked as 404.\n\nPagination:\n- `page` is 1-based; `size` is clamped server-side (max guardrail).\n- Sorted by newest first.\n\nResponse:\n- `200 OK` with `TicketRelationPageResponse { items, page, size, total }`.\n- `404 Not Found` when the ticket is missing/out of tenant scope.\n- `x-request-id` header for correlation.\n\nRate limiting:\n- Standard per-route limits; `429` carries `x-ratelimit-*` headers.\n",
        "operationId": "listTicketRelations",
        "parameters": [
          {
            "description": "Ticket id",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page"
                }
              }
            },
            "description": "Relations page",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Ticket not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List relations for a ticket",
        "tags": [
          "tickets",
          "relations"
        ]
      },
      "post": {
        "description": "\nCreate a directed relation from one ticket to another (e.g., BLOCKS, DUPLICATES, PARENT_OF).\n\nAuthorization:\n- Bearer JWT.\n- RBAC `tickets:relations:manage`.\n- Tenant guard: both tickets must belong to the caller tenant; cross-tenant targets are masked as 404.\n\nBehavior:\n- Validates existence of both tickets; rejects self-relations (`from == to`).\n- Enforces uniqueness on (tenant, from, to, relation_type); duplicates return 409.\n- Optional note for human context is stored.\n- Supports idempotent creates via `Idempotency-Key` header.\n\nResponse:\n- `201 Created` with `TicketRelationResponse` on fresh create.\n- `200 OK` on idempotent replay with the prior payload.\n- Standard error envelope for 400/403/404/409.\n- Always emits `x-request-id` for tracing.\n\nRate limiting:\n- Standard per-route limits; `429` responses include `x-ratelimit-*` headers.\n",
        "operationId": "createTicketRelation",
        "parameters": [
          {
            "description": "Source ticket id",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional exactly-once semantics for create",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateTicketRelationRequest"
              }
            }
          },
          "description": "Relation target, type, and optional note",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketRelationResponse"
                }
              }
            },
            "description": "Idempotent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketRelationResponse"
                }
              }
            },
            "description": "Relation created",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Ticket(s) not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Duplicate relation",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create a ticket relation",
        "tags": [
          "tickets",
          "relations"
        ]
      }
    },
    "/api/v1/tickets/{id}/relations/{relation_id}": {
      "delete": {
        "description": "\nRemove a relation edge between two tickets.\n\nAuthorization:\n- Bearer JWT.\n- RBAC `tickets:relations:manage`.\n- Tenant guard: relation must belong to caller tenant; cross-tenant relations are masked as 404.\n\nBehavior:\n- Idempotent delete; missing relations return 404.\n- No ETag required (lightweight edge resource).\n\nResponse:\n- `204 No Content` on success.\n- `404 Not Found` when relation does not exist in tenant scope.\n- Always emits `x-request-id` for audit/tracing.\n\nRate limiting:\n- Standard per-route limits; `429` responses include `x-ratelimit-*`.\n",
        "operationId": "deleteTicketRelation",
        "parameters": [
          {
            "description": "Ticket id",
            "in": "path",
            "name": "ticket_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Relation id",
            "in": "path",
            "name": "relation_id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Relation not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a ticket relation",
        "tags": [
          "tickets",
          "relations"
        ]
      }
    },
    "/api/v1/tickets/{id}/watch": {
      "delete": {
        "description": "\nUnsubscribe the current user from watching a ticket.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:WATCHERS_SELF`.\n- Caller must belong to the same tenant as the target ticket.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Tickets from other tenants are masked as `404 Not Found`.\n\nBehavior:\n- This operation is **idempotent**: returns `204 No Content` even if the user was not watching.\n- No request body is required.\n\nResponse:\n- Returns `204 No Content` when the unsubscribe completes successfully.\n- Includes a strong `ETag` of the form `\"tickets:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for correlation / audit tracing.\n\nIdempotency:\n- Provide optional `Idempotency-Key` header to make this operation exactly-once.\n- Replays with the same key will return the same logical outcome without\n  re-running the unsubscribe UC.\n\nRate limiting:\n- This route is subject to per-route concurrency and rate limits.\n- When limits are exceeded, the server responds `429 Too Many Requests`\n  with `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "watchUnsubscribeTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) to unsubscribe from",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make unsubscribe exactly-once",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "User successfully unsubscribed (idempotent)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:WATCHERS_SELF` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "examples": {
                  "replay_conflict": {
                    "summary": "Idempotency collision",
                    "value": {
                      "code": "conflict",
                      "error": "idempotency_busy"
                    }
                  }
                },
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict – duplicate in-flight idempotent call or inconsistent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Unsubscribe from ticket",
        "tags": [
          "watchers"
        ]
      },
      "put": {
        "description": "\nSubscribe the current user as a watcher of the given ticket.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:WATCHERS_SELF`.\n- Caller must belong to the same tenant as the target ticket.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Tickets from other tenants are masked as `404 Not Found`.\n\nBehavior:\n- Calling this when already watching is a no-op and returns `204 No Content`.\n- No request body is required.\n\nResponse:\n- Returns `204 No Content` on success.\n- Includes a strong `ETag` of the form `\"tickets:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for correlation / audit tracing.\n\nIdempotency:\n- Provide optional `Idempotency-Key` header to make this operation exactly-once.\n- Replays with the same key will return the same logical outcome without\n  re-running the subscribe UC.\n\nRate limiting:\n- This route is subject to per-route concurrency and rate limits.\n- When limits are exceeded, responds `429 Too Many Requests` with\n  `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "watchSubscribeTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) to watch",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Provide to make subscribe exactly-once",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "User successfully subscribed to this ticket (idempotent)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"tickets:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:WATCHERS_SELF` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Conflict – duplicate in-flight replay or idempotency target mismatch",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Subscribe to ticket",
        "tags": [
          "watchers"
        ]
      }
    },
    "/api/v1/tickets/{id}/watchers": {
      "get": {
        "description": "\nList all users currently watching a specific ticket within the current tenant.\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `tickets:WATCHERS_READ`.\n- Caller must belong to the same tenant as the target ticket.\n\nMulti-tenancy:\n- Tenant context is derived from the Bearer JWT.\n- Tickets from other tenants are masked as `404 Not Found`.\n\nResponse:\n- Returns `200 OK` with a `WatchersList` object.\n- `WatchersList` contains an array named `watchers`, where each watcher entry includes:\n  - `user_id` (UUID of the watching user)\n  - `added_at` (timestamp when the watch was added)\n- Includes `x-request-id` for correlation / audit tracing.\n\nRate limiting:\n- This route is subject to per-route concurrency and rate limits.\n- When limits are exceeded, the server responds `429 Too Many Requests` with `retry-after` and `x-ratelimit-*` headers.\n",
        "operationId": "watchListTicket",
        "parameters": [
          {
            "description": "Ticket ID (UUID) whose watchers will be listed",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TicketWatchersListResponse"
                }
              }
            },
            "description": "List of watchers for this ticket",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit / support",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing or invalid tenant-scoped JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – caller lacks `tickets:WATCHERS_READ` permission",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found – ticket does not exist in this tenant scope",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited / concurrency limit hit",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is allowed",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-limit": {
                "description": "Requests allowed per window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining tokens in the current window",
                "schema": {
                  "type": "string"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp when the current window resets",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get ticket watchers",
        "tags": [
          "watchers"
        ]
      }
    },
    "/api/v1/usage/current": {
      "get": {
        "description": "Get current usage counters",
        "operationId": "usage_current",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get current usage counters",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/usage/history": {
      "get": {
        "description": "Get usage history as billing-period counters or calendar-day usage-event buckets. Daily buckets are derived from the timestamped usage ledger and are not interpolated from monthly totals.",
        "operationId": "usage_history",
        "parameters": [
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "format": "int64",
              "maximum": 500,
              "minimum": 1,
              "type": "integer"
            }
          },
          {
            "description": "History bucket granularity. Defaults to billing_period for backward compatibility.",
            "in": "query",
            "name": "granularity",
            "required": false,
            "schema": {
              "default": "billing_period",
              "enum": [
                "billing_period",
                "day"
              ],
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get usage counter history",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/usage/reconcile": {
      "post": {
        "description": "Rebuilds current-period usage counters for the tenant from source-of-truth tables and append-only usage events. Requires billing update privileges.",
        "operationId": "usage_reconcile_current_period",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UsageResponse"
                }
              }
            },
            "description": "OK",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Too many requests",
            "headers": {
              "retry-after": {
                "description": "Seconds until retry is recommended.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-limit": {
                "description": "Configured request limit for the bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-remaining": {
                "description": "Remaining requests in the current bucket.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-ratelimit-reset": {
                "description": "Unix timestamp or relative reset value emitted by the rate limiter.",
                "schema": {
                  "format": "int64",
                  "type": "integer"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Reconcile current usage counters",
        "tags": [
          "billing"
        ]
      }
    },
    "/api/v1/users": {
      "get": {
        "description": "\nRetrieve a paginated list of **users** across the platform.\n\nAuthorization:\n- Requires Bearer JWT.\n- Requires RBAC permission `users:read:all`.\n\nQuery parameters:\n- Pagination (`page`, `size`).\n- Optional filters such as `is_active` or search term `q`.\n\nBehavior:\n- Delegates to `uc_list_users.execute(q)`.\n- Returns a `UserPage` with pagination metadata.\n\nResponse:\n- `200 OK` with `UserPage` (items, page, size, total).\n- Includes `x-request-id` via middleware headers.\n",
        "operationId": "listUsers",
        "parameters": [
          {
            "description": "Optional text filter on email/name (ILIKE)",
            "in": "path",
            "name": "q",
            "required": true,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional filter on active status",
            "in": "path",
            "name": "is_active",
            "required": true,
            "schema": {
              "type": [
                "boolean",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "page",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "path",
            "name": "size",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserPageResponse"
                }
              }
            },
            "description": "Users page",
            "headers": {
              "x-request-id": {
                "description": "Correlation id for tracing",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `users:read:all`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List users (platform-scoped)",
        "tags": [
          "users"
        ]
      },
      "post": {
        "description": "Create a new platform-scoped user. Only admins or system roles may call this endpoint.",
        "operationId": "createUser",
        "parameters": [
          {
            "description": "Provide for exactly-once creation (effect-scoped)",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUserRequest"
              }
            }
          },
          "description": "User creation payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserResponse"
                }
              }
            },
            "description": "Idempotent replay (existing user returned)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"users:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the user",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserResponse"
                }
              }
            },
            "description": "User created",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"users:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "Location": {
                "description": "Canonical URL of the new user",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Duplicate in-flight or inconsistent replay",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create user",
        "tags": [
          "users"
        ]
      }
    },
    "/api/v1/users/email/confirm": {
      "post": {
        "description": "Confirm a pending email-change token and promote the requested email address to the user's active email.",
        "operationId": "confirmEmailChange",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConfirmEmailChangeRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConfirmEmailChangeResponse"
                }
              }
            },
            "description": "Email change confirmed",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Invalid or expired confirmation token",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Confirm pending email change",
        "tags": [
          "users"
        ]
      }
    },
    "/api/v1/users/me": {
      "get": {
        "description": "\nFetch the **currently authenticated user** (platform-scoped).\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Typically requires RBAC `users:read:self`.\n\nBehavior:\n- Uses `uc_get_me.execute(current_user_id)`.\n- Returns `UserDto` with a strong ETag for caching/If-Match.\n\nResponse:\n- `200 OK` with `UserDto`.\n- Strong `ETag` header: `\"users:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for audit/tracing.\n",
        "operationId": "getMe",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserResponse"
                }
              }
            },
            "description": "Current user successfully retrieved",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"users:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing/invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get current user (me)",
        "tags": [
          "users"
        ]
      }
    },
    "/api/v1/users/search": {
      "get": {
        "description": "\nPerforms **fuzzy full-text search** over user **email** and **name** fields using PostgreSQL trigram similarity.\n\n### Authorization\n- Requires Bearer JWT.\n- Requires RBAC permission `users:read:all`.\n\n### Search semantics\n- `q` must be non-empty after trimming.\n- Results are ranked by trigram similarity (`rank` 0.0–1.0).\n- Pagination uses `page` (1-based) and `size` (server-clamped).\n\n### Response\n- `200 OK` with [`UserPage`](#schema-UserPage):\n  - `items[]` include `id`, `email`, `name`, `is_active`,\n    `created_at`, `updated_at`, and `rank` (similarity score).\n- Includes `x-request-id` header for correlation.\n\n### Rate limiting\n- Per-route concurrency/rate limits may apply (`429` on excess).\n",
        "operationId": "searchUsers",
        "parameters": [
          {
            "description": "REQUIRED free text for similarity search (email/name)",
            "in": "path",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "page",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "path",
            "name": "size",
            "required": true,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserPageResponse"
                }
              }
            },
            "description": "Ranked paginated search results",
            "headers": {
              "x-request-id": {
                "description": "Correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `users:read:all`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Search users (platform-scoped)",
        "tags": [
          "users"
        ]
      }
    },
    "/api/v1/users/{id}": {
      "delete": {
        "description": "\nHard-delete an existing **user** (platform-scoped).\n\nAuthorization:\n- Requires JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `users:deactivate` (use your strongest admin-only permission for destructive ops).\n\nSemantics:\n- **Idempotent** by contract: always returns `204 No Content` even if the user\n  is already gone (or never existed).\n\nETag:\n- If the user existed at deletion time, response includes a strong ETag\n  `\"users:<uuid>:<row_version>\"` representing the removed version.\n",
        "operationId": "deleteUser",
        "parameters": [
          {
            "description": "User identifier (UUID) to delete",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "User deleted (or already absent)",
            "headers": {
              "ETag": {
                "description": "Strong ETag of removed version: `\"users:<uuid>:<version>\"` (present only if it existed at deletion time)",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `users:deactivate`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete a user (platform-scoped)",
        "tags": [
          "users"
        ]
      },
      "get": {
        "description": "\nFetch a single **user** by its unique identifier (platform-scoped).\n\nAuthorization:\n- Requires a valid Bearer JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `users:read:all` (reading others).\n- Handlers for `GET /users/me` cover self-reads.\n\nBehavior:\n- Uses `uc_get_user.execute(id)`.\n- Returns `UserDto` with strong ETag.\n\nResponse:\n- `200 OK` with `UserDto`.\n- Strong `ETag` header: `\"users:<uuid>:<row_version>\"`.\n- Includes `x-request-id` for audit/tracing.\n",
        "operationId": "getUser",
        "parameters": [
          {
            "description": "User identifier (UUID)",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserResponse"
                }
              }
            },
            "description": "User successfully retrieved",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"users:<uuid>:<row_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized – missing/invalid JWT",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `users:read:all`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get a user by ID",
        "tags": [
          "users"
        ]
      },
      "patch": {
        "description": "\nUpdate mutable fields on a **platform-scoped** user.\n\nOptimistic concurrency:\n- Requires **strong** `If-Match` with format: `\"users:<uuid>:<row_version>\"`.\n- `428` if missing, `412` if mismatch/stale.\n\nAuthorization:\n- If updating **self** (`id == me`): requires `users:update:self`.\n- If updating **others**: requires `users:update:others`.\n- If changing `is_active`, also requires `users:deactivate` (even if included here, prefer the `/users/{id}/deactivate` route).\n\nResponse:\n- `200 OK` with updated resource + strong `ETag`.\n",
        "operationId": "updateUser",
        "parameters": [
          {
            "description": "User ID",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Strong ETag `\"users:<uuid>:<row_version>\"`",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateUserRequest"
              }
            }
          },
          "description": "Partial update payload",
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UserResponse"
                }
              }
            },
            "description": "Updated",
            "headers": {
              "ETag": {
                "description": "Strong ETag `\"users:<uuid>:<version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Bad request",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed (ETag mismatch)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "428": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition required (missing If-Match)",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update a user (If-Match required)",
        "tags": [
          "users"
        ]
      }
    },
    "/api/v1/users/{id}/deactivate": {
      "post": {
        "description": "\nDeactivate (soft-delete) an existing **user** by marking it as inactive (`is_active = false`).\n\nAuthorization:\n- Requires JWT (`Authorization: Bearer <token>`).\n- Requires RBAC permission `users:deactivate`.\n\nConcurrency:\n- Requires `If-Match` header with a strong ETag (`\"users:<uuid>:<version>\"`).\n- Enforces optimistic concurrency via `row_version`.\n\nSemantics:\n- Idempotent: deactivating an already inactive user still returns `204 No Content`.\n- Response includes a new strong ETag for the updated (deactivated) version.\n\nETag:\n- Uses strong ETag `\"users:<uuid>:<row_version>\"` for concurrency control.\n",
        "operationId": "deactivateUser",
        "parameters": [
          {
            "description": "User identifier (UUID) to deactivate",
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Optional retry key for supported mutating routes. Reusing a key with the same semantic fingerprint replays the saved result; a different fingerprint returns conflict.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "maxLength": 255,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "description": "No body required. Operation is driven by path and headers."
        },
        "responses": {
          "204": {
            "description": "User successfully deactivated (or already inactive)",
            "headers": {
              "ETag": {
                "description": "Strong ETag: `\"users:<uuid>:<new_version>\"`",
                "schema": {
                  "type": "string"
                }
              },
              "x-request-id": {
                "description": "Request correlation id",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden – lacks `users:deactivate`",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "412": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Precondition failed – stale or missing If-Match header",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Deactivate a user (soft delete)",
        "tags": [
          "users"
        ]
      }
    },
    "/api/v1/webhook-deliveries/{id}": {
      "get": {
        "description": "Get webhook delivery. Webhook delivery is at-least-once: duplicate deliveries are possible, there is no global ordering guarantee, and subscribers must use RustGrid-Delivery-Id or RustGrid-Event-Id for idempotency.",
        "operationId": "getWebhookDelivery",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDeliveryResponse"
                }
              }
            },
            "description": "Webhook delivery",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get webhook delivery",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/webhook-deliveries/{id}/redeliver": {
      "post": {
        "description": "Reschedule webhook delivery. Supports Idempotency-Key; replay does not enqueue an additional redelivery. Webhook delivery is at-least-once: duplicate deliveries are possible, there is no global ordering guarantee, and subscribers must use RustGrid-Delivery-Id or RustGrid-Event-Id for idempotency.",
        "operationId": "redeliverWebhookDelivery",
        "parameters": [
          {
            "description": "Provide to make this webhook mutation exactly-once. Replays use the prior effect identity; create and rotate-secret replays do not re-expose one-time secrets.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDeliveryResponse"
                }
              }
            },
            "description": "Webhook delivery rescheduled",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Redeliver webhook delivery",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/webhooks": {
      "get": {
        "description": "List webhook subscriptions for the current tenant. Secret material is never returned after creation or rotation.",
        "operationId": "listWebhooks",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                  },
                  "type": "array"
                }
              }
            },
            "description": "Webhook subscriptions",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List webhook subscriptions",
        "tags": [
          "webhooks"
        ]
      },
      "post": {
        "description": "Create webhook subscription. Supports Idempotency-Key; replay returns the same subscription without re-exposing the one-time secret. Webhook delivery is at-least-once: duplicate deliveries are possible, there is no global ordering guarantee, and subscribers must use RustGrid-Delivery-Id or RustGrid-Event-Id for idempotency.",
        "operationId": "createWebhook",
        "parameters": [
          {
            "description": "Provide to make this webhook mutation exactly-once. Replays use the prior effect identity; create and rotate-secret replays do not re-expose one-time secrets.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWebhookRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/CreateWebhookResponse"
                    },
                    {
                      "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                    }
                  ]
                }
              }
            },
            "description": "Webhook subscription created with one-time secret; idempotent replay returns the subscription without the secret",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Create webhook subscription",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}": {
      "delete": {
        "description": "Delete webhook subscription. Supports Idempotency-Key so delete retries return the same no-content outcome without requiring the deleted row to still exist.",
        "operationId": "deleteWebhook",
        "parameters": [
          {
            "description": "Provide to make this webhook mutation exactly-once. Replays use the prior effect identity; create and rotate-secret replays do not re-expose one-time secrets.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Webhook subscription deleted",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Delete webhook subscription",
        "tags": [
          "webhooks"
        ]
      },
      "get": {
        "description": "Fetch a webhook subscription by ID within the current tenant. Secret material is redacted from the response.",
        "operationId": "getWebhook",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                }
              }
            },
            "description": "Webhook subscription",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Get webhook subscription",
        "tags": [
          "webhooks"
        ]
      },
      "patch": {
        "description": "Update webhook subscription. Supports Idempotency-Key for safe retry of the same patch.",
        "operationId": "updateWebhook",
        "parameters": [
          {
            "description": "Provide to make this webhook mutation exactly-once. Replays use the prior effect identity; create and rotate-secret replays do not re-expose one-time secrets.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Strong ETag for optimistic concurrency, for example `\"tickets:<uuid>:<row_version>\"`. Missing headers return `428`, stale or mismatched tags return `412`.",
            "in": "header",
            "name": "If-Match",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWebhookRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                }
              }
            },
            "description": "Webhook subscription updated",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Update webhook subscription",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/deliveries": {
      "get": {
        "description": "List webhook deliveries. Delivery records represent at-least-once attempts; subscribers should expect possible duplicates and no global ordering guarantee.",
        "operationId": "listWebhookDeliveries",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "size",
            "required": false,
            "schema": {
              "format": "int64",
              "type": "integer"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookDeliveryPageResponse"
                }
              }
            },
            "description": "Webhook deliveries",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "List webhook deliveries",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/rotate-secret": {
      "post": {
        "description": "Rotate webhook signing secret. Supports Idempotency-Key; replay does not rotate again and does not re-expose the one-time secret.",
        "operationId": "rotateWebhookSecret",
        "parameters": [
          {
            "description": "Provide to make this webhook mutation exactly-once. Replays use the prior effect identity; create and rotate-secret replays do not re-expose one-time secrets.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/CreateWebhookResponse"
                    },
                    {
                      "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                    }
                  ]
                }
              }
            },
            "description": "Webhook subscription with new one-time secret; idempotent replay returns the subscription without the secret",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Rotate webhook signing secret",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/api/v1/webhooks/{id}/unpause": {
      "post": {
        "description": "Unpause an auto-paused webhook subscription and allow delivery fanout to resume. Supports Idempotency-Key for safe retry of the same unpause request.",
        "operationId": "unpauseWebhook",
        "parameters": [
          {
            "description": "Provide to make this webhook mutation exactly-once. Replays use the prior effect identity.",
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          },
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookSubscriptionResponse"
                }
              }
            },
            "description": "Webhook subscription unpaused",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Validation error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Forbidden",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Not found",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Rate limited",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            },
            "description": "Server error",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "summary": "Unpause webhook subscription",
        "tags": [
          "webhooks"
        ]
      }
    },
    "/healthz": {
      "get": {
        "description": "\nBasic health check endpoint used by load balancers and orchestration systems.\n\nBehavior:\n- Always returns `200 OK` with body `\"ok\"` if the service process is alive.\n- Does **not** perform dependency checks (DB, cache, etc.).\n- Suitable for container liveness probes or uptime checks.\n",
        "operationId": "healthCheck",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "description": "Service is alive",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Liveness probe",
        "tags": [
          "ops"
        ]
      }
    },
    "/readyz": {
      "get": {
        "description": "\nReadiness endpoint verifying that the application is ready to serve traffic.\n\nBehavior:\n- Attempts a quick DB connection checkout and `SELECT 1`.\n- Succeeds fast or fails fast (short timeout, no blocking behind a saturated pool).\n- Returns `200 OK` with `\"ok\"` when ready.\n- Returns `503 Service Unavailable` with `\"unready\"` when dependencies are not ready or the check times out.\n\nIntended use:\n- Container/orchestrator readiness probes (e.g. Kubernetes `readinessProbe`).\n- Monitoring tools ensuring dependencies are operational.\n",
        "operationId": "readinessCheck",
        "parameters": [
          {
            "description": "Optional client-supplied correlation id. If omitted, RustGrid creates one and returns it in the response.",
            "in": "header",
            "name": "x-request-id",
            "required": false,
            "schema": {
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "description": "Application and DB are ready",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "description": "Dependencies not ready or timed out",
            "headers": {
              "x-request-id": {
                "description": "Request correlation id for audit and support.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [],
        "summary": "Readiness probe",
        "tags": [
          "ops"
        ]
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "servers": [
    {
      "description": "Local development",
      "url": "http://localhost:8080"
    },
    {
      "description": "Same-origin deployment",
      "url": "/"
    }
  ],
  "tags": [
    {
      "description": "Account bootstrap, login, tenant activation, password recovery, email verification, and OAuth redirects.",
      "name": "auth"
    },
    {
      "description": "Current-account profile, password, tenant roster, role introspection, and self-service deactivation.",
      "name": "account"
    },
    {
      "description": "Tenant and project-scoped machine credentials. Full `rgk_` secrets are returned only once at creation.",
      "name": "api-keys"
    },
    {
      "description": "Platform-scoped user administration, discovery, profile updates, email confirmation, and deactivation.",
      "name": "users"
    },
    {
      "description": "Tenant lifecycle, tenant lookup/search, invite flows, tenant role selection, and tenant memberships.",
      "name": "tenants"
    },
    {
      "description": "Tenant-scoped project lifecycle, lookup/search, project invites, and project membership management.",
      "name": "projects"
    },
    {
      "description": "Project labels and ticket label assignment. Label names are project-scoped and case-insensitive.",
      "name": "labels"
    },
    {
      "description": "Project custom-field definitions and metadata used by ticket create, update, list, and search workflows.",
      "name": "custom-fields"
    },
    {
      "description": "Sprint lifecycle, backlog ordering, board views, ticket assignment, and velocity snapshots.",
      "name": "sprints"
    },
    {
      "description": "Ticket creation, listing, search, updates, assignment, labels, attachments, relations, and activity.",
      "name": "tickets"
    },
    {
      "description": "Ticket comment creation, listing, reads, updates, deletes, and optimistic concurrency behavior.",
      "name": "comments"
    },
    {
      "description": "Direct-to-storage upload completion, attachment download URLs, variants, and deletion.",
      "name": "attachments"
    },
    {
      "description": "Directed ticket relationship edges such as blocking, duplicate, and parent-child links.",
      "name": "relations"
    },
    {
      "description": "Ticket watch subscription, unsubscription, and watcher roster inspection.",
      "name": "watchers"
    },
    {
      "description": "Tenant and resource activity timelines for audit, support, and user-visible history.",
      "name": "activity"
    },
    {
      "description": "Webhook subscriptions, signing secrets, delivery inspection, redelivery, and at-least-once delivery semantics.",
      "name": "webhooks"
    },
    {
      "description": "Agent worker registration, credentials, ticket claims, run steps, external links, and quality gate reporting.",
      "name": "agents"
    },
    {
      "description": "OpenAPI JSON and the interactive Redoc documentation surface.",
      "name": "docs"
    },
    {
      "description": "Liveness and readiness probes for load balancers and orchestration systems.",
      "name": "ops"
    }
  ],
  "x-tagGroups": [
    {
      "name": "Start Here",
      "tags": [
        "auth",
        "docs",
        "ops"
      ]
    },
    {
      "name": "Identity & Access",
      "tags": [
        "account",
        "api-keys",
        "users",
        "tenants"
      ]
    },
    {
      "name": "Work Management",
      "tags": [
        "projects",
        "labels",
        "custom-fields",
        "sprints",
        "tickets"
      ]
    },
    {
      "name": "Collaboration",
      "tags": [
        "comments",
        "attachments",
        "relations",
        "watchers",
        "activity"
      ]
    },
    {
      "name": "Automation",
      "tags": [
        "agents",
        "webhooks"
      ]
    }
  ]
}