{
  "topic": "scheduled-tasks",
  "path": [
    "scheduled-tasks"
  ],
  "title": "scheduled-tasks — the tenant's scheduled-transition tasks",
  "synopsis": "A scheduled workflow transition arms a task each time the entity enters the transition's source state. `GET /scheduled-tasks` lists the caller's tenant's scheduled-transition tasks that still exist: `WAITING`, `RUNNING` or `FAILED`. A task that fired, was declined, expired or was cancelled is removed; its outcome is in the entity's audit trail (see the `audit` topic), not here.",
  "body": "# scheduled-tasks\n\n## NAME\n\nscheduled-tasks — the tenant's scheduled-transition tasks: list the tasks a scheduled workflow transition has armed and that still exist.\n\n## SYNOPSIS\n\n```\nGET  /api/scheduled-tasks\n```\n\nContext path prefix is `CYODA_CONTEXT_PATH` (default `/api`). Requires `Authorization: Bearer <token>` except when `CYODA_IAM_MODE=mock`. HTTP only — there is no gRPC equivalent.\n\n## DESCRIPTION\n\nA scheduled workflow transition arms a task each time the entity enters the transition's source state. `GET /scheduled-tasks` lists the caller's tenant's scheduled-transition tasks that still exist: `WAITING`, `RUNNING` or `FAILED`. A task that fired, was declined, expired or was cancelled is removed; its outcome is in the entity's audit trail (see the `audit` topic), not here.\n\nWith clock control on, a move of the clock fires each due task at its due time, within about one scan interval times the rate; due order holds for due times further apart than that (see `cyoda help clock`).\n\nResults are sorted by `scheduledTime`, then `taskId`, ascending, and paged with an opaque cursor. Filters combine with AND. A `modelName`, `modelVersion` or `entityId` naming an unknown model or entity, or one of another tenant, returns an empty list rather than an error. Any caller of the tenant whose token holds `ROLE_M2M` may call this endpoint; the tenant is always the token's — no parameter selects a different one.\n\n## PARAMETERS\n\nAll are optional query parameters.\n\n- `status`: return tasks in any of these statuses. Repeat the parameter for several. Accepted values: `WAITING`, `RUNNING`, `FAILED`. Any other value is rejected with `400`.\n- `modelName`: return tasks of entities of this model. 1 to 256 characters of valid UTF-8, without NUL.\n- `modelVersion`: return tasks of entities of this model version. Only together with `modelName` — alone it is rejected with `400`.\n- `entityId`: UUID — return the tasks of this entity.\n- `cursor`: opaque, at most 256 characters. Pass `nextCursor` from the previous response to fetch the next page; omit for the first page. A cursor that cannot be read is rejected with `400`, and its value is never echoed back.\n- `limit`: integer, 1 to 1000 (default 20). A value outside the range is rejected with `400`, not clamped.\n\n## RESPONSE\n\n`200 OK`, `application/json` — `ScheduledTaskPageDto`:\n\n```json\n{\n  \"items\": [\n    {\n      \"taskId\": \"3f9b6a106f5e11f08f3a0242ac110002\",\n      \"entityId\": \"74807f00-ed0d-11ee-a357-ae468cd3ed16\",\n      \"modelName\": \"order\",\n      \"modelVersion\": 1,\n      \"sourceState\": \"PENDING\",\n      \"transition\": \"escalate\",\n      \"status\": \"WAITING\",\n      \"scheduledTime\": \"2025-08-01T10:05:00.000000000Z\",\n      \"armedTime\": \"2025-08-01T09:05:00.000000000Z\",\n      \"attempts\": 0,\n      \"lostOwners\": 0,\n      \"nextAttemptTime\": \"2025-08-01T10:05:00.000000000Z\"\n    }\n  ],\n  \"pagination\": {\n    \"hasNext\": false\n  }\n}\n```\n\n**ScheduledTaskDto** fields. Claim tokens, arm tokens and node identities are never returned.\n\n- `taskId`: opaque, stable identifier. The same (entity, source state, transition) keeps the same id when it is armed again.\n- `entityId`: UUID.\n- `modelName`, `modelVersion`: the entity's model.\n- `sourceState`: the state the entity must be in for the transition to fire.\n- `transition`: the transition's name.\n- `status`: open value set; accept a value not listed here. Known values: `WAITING` — due at `nextAttemptTime`; `RUNNING` — a node has claimed it and is running it; `FAILED` — it will not run again and never moves the entity (see `failureReason`). A write to the entity in `sourceState` arms it again; the entity leaving `sourceState` removes it.\n- `scheduledTime`: when the transition is due.\n- `armedTime`: when the task was last armed.\n- `expiresTime`: present when the transition's schedule sets `timeoutMs` — `scheduledTime` plus `timeoutMs`.\n- `attempts`: failed attempts recorded since the task was last armed.\n- `lostOwners`: times the node running the task was lost since the task was last armed.\n- `nextAttemptTime`: present when `status` is `WAITING` — the earliest time the next attempt may start.\n- `lastAttemptTime`: present after a failed attempt.\n- `lastError`: for a `FAILED` task, present with the failure's text (pairs with `failedTime`), even when the text is empty. For every other status, present when `lastAttemptTime` is set, paired with it. Client-safe text — a `CODE: detail` message, a compute node's own message, or `internal error [ticket: <uuid>]`.\n- `failureReason`: present when `status` is `FAILED`. Open value set; accept a value not listed here. Known values: `UNSAFE_WORK_NOT_COMPLETED` — a processor not declared `idempotent` was handed to a compute node and the run did not commit, so it is not repeated; `OWNER_LOST_REPEATEDLY` — the node running the task was lost too many times; `EXPIRED_AFTER_FAILED_ATTEMPTS` — `expiresTime` passed after a failed attempt or a lost node; `RUN_PANICKED` — the run failed with an internal error; `STOPPED_AFTER_PARTIAL_COMMIT` — the run committed the entity into another state and then stopped.\n- `failedTime`: present when `status` is `FAILED`.\n- `armedBy`: the attributed principal of the write that armed the task — `{id, kind}`, `kind` one of `user`, `service`, `system`. For an on-behalf-of write this is the on-behalf-of user, never the client that holds the token. Present when known.\n\n## ERRORS\n\n- `errors.BAD_REQUEST` — `400` — an invalid `status`, an invalid `modelName`, a `modelVersion` without `modelName`, an out-of-range `modelVersion` or `limit`, or an unreadable `entityId` or `cursor`\n- `errors.UNAUTHORIZED` — `401` — missing or invalid bearer token\n- `errors.FORBIDDEN` — `403` — the token lacks `ROLE_M2M` (a `cyoda token` signed without `--roles ROLE_ADMIN,ROLE_M2M`, for example)\n- `errors.SERVER_ERROR` — `500` — internal failure; the response carries a ticket id, never the cause\n- `errors.STORAGE_UNAVAILABLE` — `503` — a transient storage outage; retryable\n\n## EXAMPLES\n\n**List the first page of WAITING tasks:**\n\n```\ncurl -s \\\n  -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?status=WAITING\"\n```\n\n**List the tasks of one entity:**\n\n```\ncurl -s \\\n  -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?entityId=$ENTITY_ID\"\n```\n\n**Filter to one model version and page through the results:**\n\n```\nNEXT=$(curl -s -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?modelName=order&modelVersion=1&limit=10\" \\\n  | jq -r '.pagination.nextCursor')\n\ncurl -s \\\n  -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?modelName=order&modelVersion=1&limit=10&cursor=$NEXT\"\n```\n\n## SEE ALSO\n\n- workflows\n- audit\n- openapi\n- errors.BAD_REQUEST\n- errors.UNAUTHORIZED\n- errors.SERVER_ERROR\n- errors.STORAGE_UNAVAILABLE\n",
  "sections": [
    {
      "name": "NAME",
      "body": "scheduled-tasks — the tenant's scheduled-transition tasks: list the tasks a scheduled workflow transition has armed and that still exist."
    },
    {
      "name": "SYNOPSIS",
      "body": "```\nGET  /api/scheduled-tasks\n```\n\nContext path prefix is `CYODA_CONTEXT_PATH` (default `/api`). Requires `Authorization: Bearer <token>` except when `CYODA_IAM_MODE=mock`. HTTP only — there is no gRPC equivalent."
    },
    {
      "name": "DESCRIPTION",
      "body": "A scheduled workflow transition arms a task each time the entity enters the transition's source state. `GET /scheduled-tasks` lists the caller's tenant's scheduled-transition tasks that still exist: `WAITING`, `RUNNING` or `FAILED`. A task that fired, was declined, expired or was cancelled is removed; its outcome is in the entity's audit trail (see the `audit` topic), not here.\n\nWith clock control on, a move of the clock fires each due task at its due time, within about one scan interval times the rate; due order holds for due times further apart than that (see `cyoda help clock`).\n\nResults are sorted by `scheduledTime`, then `taskId`, ascending, and paged with an opaque cursor. Filters combine with AND. A `modelName`, `modelVersion` or `entityId` naming an unknown model or entity, or one of another tenant, returns an empty list rather than an error. Any caller of the tenant whose token holds `ROLE_M2M` may call this endpoint; the tenant is always the token's — no parameter selects a different one."
    },
    {
      "name": "PARAMETERS",
      "body": "All are optional query parameters.\n\n- `status`: return tasks in any of these statuses. Repeat the parameter for several. Accepted values: `WAITING`, `RUNNING`, `FAILED`. Any other value is rejected with `400`.\n- `modelName`: return tasks of entities of this model. 1 to 256 characters of valid UTF-8, without NUL.\n- `modelVersion`: return tasks of entities of this model version. Only together with `modelName` — alone it is rejected with `400`.\n- `entityId`: UUID — return the tasks of this entity.\n- `cursor`: opaque, at most 256 characters. Pass `nextCursor` from the previous response to fetch the next page; omit for the first page. A cursor that cannot be read is rejected with `400`, and its value is never echoed back.\n- `limit`: integer, 1 to 1000 (default 20). A value outside the range is rejected with `400`, not clamped."
    },
    {
      "name": "RESPONSE",
      "body": "`200 OK`, `application/json` — `ScheduledTaskPageDto`:\n\n```json\n{\n  \"items\": [\n    {\n      \"taskId\": \"3f9b6a106f5e11f08f3a0242ac110002\",\n      \"entityId\": \"74807f00-ed0d-11ee-a357-ae468cd3ed16\",\n      \"modelName\": \"order\",\n      \"modelVersion\": 1,\n      \"sourceState\": \"PENDING\",\n      \"transition\": \"escalate\",\n      \"status\": \"WAITING\",\n      \"scheduledTime\": \"2025-08-01T10:05:00.000000000Z\",\n      \"armedTime\": \"2025-08-01T09:05:00.000000000Z\",\n      \"attempts\": 0,\n      \"lostOwners\": 0,\n      \"nextAttemptTime\": \"2025-08-01T10:05:00.000000000Z\"\n    }\n  ],\n  \"pagination\": {\n    \"hasNext\": false\n  }\n}\n```\n\n**ScheduledTaskDto** fields. Claim tokens, arm tokens and node identities are never returned.\n\n- `taskId`: opaque, stable identifier. The same (entity, source state, transition) keeps the same id when it is armed again.\n- `entityId`: UUID.\n- `modelName`, `modelVersion`: the entity's model.\n- `sourceState`: the state the entity must be in for the transition to fire.\n- `transition`: the transition's name.\n- `status`: open value set; accept a value not listed here. Known values: `WAITING` — due at `nextAttemptTime`; `RUNNING` — a node has claimed it and is running it; `FAILED` — it will not run again and never moves the entity (see `failureReason`). A write to the entity in `sourceState` arms it again; the entity leaving `sourceState` removes it.\n- `scheduledTime`: when the transition is due.\n- `armedTime`: when the task was last armed.\n- `expiresTime`: present when the transition's schedule sets `timeoutMs` — `scheduledTime` plus `timeoutMs`.\n- `attempts`: failed attempts recorded since the task was last armed.\n- `lostOwners`: times the node running the task was lost since the task was last armed.\n- `nextAttemptTime`: present when `status` is `WAITING` — the earliest time the next attempt may start.\n- `lastAttemptTime`: present after a failed attempt.\n- `lastError`: for a `FAILED` task, present with the failure's text (pairs with `failedTime`), even when the text is empty. For every other status, present when `lastAttemptTime` is set, paired with it. Client-safe text — a `CODE: detail` message, a compute node's own message, or `internal error [ticket: <uuid>]`.\n- `failureReason`: present when `status` is `FAILED`. Open value set; accept a value not listed here. Known values: `UNSAFE_WORK_NOT_COMPLETED` — a processor not declared `idempotent` was handed to a compute node and the run did not commit, so it is not repeated; `OWNER_LOST_REPEATEDLY` — the node running the task was lost too many times; `EXPIRED_AFTER_FAILED_ATTEMPTS` — `expiresTime` passed after a failed attempt or a lost node; `RUN_PANICKED` — the run failed with an internal error; `STOPPED_AFTER_PARTIAL_COMMIT` — the run committed the entity into another state and then stopped.\n- `failedTime`: present when `status` is `FAILED`.\n- `armedBy`: the attributed principal of the write that armed the task — `{id, kind}`, `kind` one of `user`, `service`, `system`. For an on-behalf-of write this is the on-behalf-of user, never the client that holds the token. Present when known."
    },
    {
      "name": "ERRORS",
      "body": "- `errors.BAD_REQUEST` — `400` — an invalid `status`, an invalid `modelName`, a `modelVersion` without `modelName`, an out-of-range `modelVersion` or `limit`, or an unreadable `entityId` or `cursor`\n- `errors.UNAUTHORIZED` — `401` — missing or invalid bearer token\n- `errors.FORBIDDEN` — `403` — the token lacks `ROLE_M2M` (a `cyoda token` signed without `--roles ROLE_ADMIN,ROLE_M2M`, for example)\n- `errors.SERVER_ERROR` — `500` — internal failure; the response carries a ticket id, never the cause\n- `errors.STORAGE_UNAVAILABLE` — `503` — a transient storage outage; retryable"
    },
    {
      "name": "EXAMPLES",
      "body": "**List the first page of WAITING tasks:**\n\n```\ncurl -s \\\n  -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?status=WAITING\"\n```\n\n**List the tasks of one entity:**\n\n```\ncurl -s \\\n  -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?entityId=$ENTITY_ID\"\n```\n\n**Filter to one model version and page through the results:**\n\n```\nNEXT=$(curl -s -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?modelName=order&modelVersion=1&limit=10\" \\\n  | jq -r '.pagination.nextCursor')\n\ncurl -s \\\n  -H @- <<<\"Authorization: Bearer $TOKEN\" \\\n  \"http://localhost:8080/api/scheduled-tasks?modelName=order&modelVersion=1&limit=10&cursor=$NEXT\"\n```"
    },
    {
      "name": "SEE ALSO",
      "body": "- workflows\n- audit\n- openapi\n- errors.BAD_REQUEST\n- errors.UNAUTHORIZED\n- errors.SERVER_ERROR\n- errors.STORAGE_UNAVAILABLE"
    }
  ],
  "see_also": [
    "workflows",
    "audit",
    "openapi",
    "errors.BAD_REQUEST",
    "errors.UNAUTHORIZED",
    "errors.SERVER_ERROR",
    "errors.STORAGE_UNAVAILABLE"
  ],
  "stability": "stable",
  "actions": []
}
