> For the complete documentation index, see [llms.txt](https://docs.podigee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.podigee.com/documentation/start-here/ai-agents/work-safely/follow-and-recover-long-running-operations.md). Agents can also search and read this documentation through its [MCP server](https://docs.podigee.com/~gitbook/mcp).

# Follow and recover long-running operations

Follow a publish, import, or password reset to its end, and resume or cancel it safely.

Some changes take longer than one request. `publish_episode`, `import_podcast`, and `send_listener_password_reset` return an `operation_id`. The operation continues in Podigee when the chat, the terminal, or the network connection ends. This page tells you how to follow an operation, what a waiting publish means, and what to do after a failure.

## Operation states

| State              | Meaning                                                             | What to do                                                                                      |
| ------------------ | ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `queued`           | Podigee accepted the work and did not start it yet.                 | Check the same operation again.                                                                 |
| `running`          | Podigee does the work.                                              | Check the same operation again. Do not start the work a second time.                            |
| `waiting`          | The operation waits, for example for the processing of a recording. | Read `waiting`. See [When a publish waits](#when-a-publish-waits).                              |
| `succeeded`        | The work is complete.                                               | Verify the result.                                                                              |
| `failed_retryable` | The work stopped, and a resume can be possible.                     | For a publish, follow `recovery`. For other operations, resume once when `retryable` is `true`. |
| `failed_terminal`  | The work stopped and cannot continue.                               | For a publish, follow `recovery`. For other operations, read `error.message`.                   |
| `cancelled`        | The work was canceled.                                              | Verify what was complete before the cancellation.                                               |

The terminal states are `succeeded`, `failed_terminal`, and `cancelled`.

## What an operation reports

| Field                                                                           | Meaning                                                                                           |
| ------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| `id`, `operation_type`                                                          | The operation ID and the type: `publish_episode`, `podcast_import`, or `listener_password_reset`. |
| `state`, `stage`                                                                | The state from the table above, and the step that the work is at.                                 |
| `retryable`                                                                     | `true` when `resume_operation` accepts this operation.                                            |
| `attempts`                                                                      | How many times Podigee started the work.                                                          |
| `podcast_id`, `episode_id`, `production_id`, `podcast_import_id`, `listener_id` | The objects that the operation works on.                                                          |
| `progress`                                                                      | Only for an import: `current`, `total`, `percent`, and the current episode.                       |
| `waiting`                                                                       | Only for a publish in the state `waiting`.                                                        |
| `recovery`                                                                      | Only for a publish that failed or stalled: the one next step.                                     |
| `result`, `error`                                                               | The result after success, or the code and the message of the failure.                             |

## Follow an operation

What you need:

* The `operation_id`.
* The same Podigee user and account that started the operation. Podigee shows an operation only to that user in that account.
* The read scope of the operation type: `mcp:podcasts:read` for a publish or an import, `mcp:listeners:read` for a password reset. See [Authorization and scopes](https://docs.podigee.com/documentation/start-here/ai-agents/mcp-reference/authorization-and-scopes.md).

Steps:

1. Ask the assistant for the state of the operation. It calls `get_operation` with the `operation_id`.
2. Read `state` and `stage`. For an import, also read `progress`, for example "112 of 340".
3. While the state is `queued` or `running`, check again later.
4. When the state is `waiting`, read the `waiting` object.
5. When the state is terminal, stop and verify the result.
6. Keep the result and the IDs of the episode, the import, or the listener.

Do not send the first request again only because the chat or the connection ended. The operation continues without you.

Expected result: you follow one operation to its end, and no work runs twice.

If Podigee returns `not_found`: check the `operation_id`, the user, and the account. Do not start a new operation before you know that the first one cannot continue.

Next step: verify the result as [Preview and confirm changes](https://docs.podigee.com/documentation/start-here/ai-agents/work-safely/preview-and-confirm-changes.md#verify-the-change) tells you.

## When a publish waits

A publish waits while Podigee encodes the audio or processes the video. Then `get_operation` returns the state `waiting` and a `waiting` object:

| Field                                           | Meaning                                                                                                    |
| ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `on`                                            | What the publish waits for: `audio_encoding` or `video_processing`.                                        |
| `recording_state`                               | `processing`, `ready`, `no_change_for_hours`, or `failed`.                                                 |
| `percent`                                       | The progress of the audio encoding, while Podigee has a value. There is no estimate of the remaining time. |
| `recording_uploaded_at`, `recording_changed_at` | When the recording was uploaded, and when it changed last.                                                 |
| `then`                                          | What happens when the wait ends: `publishes`, `publishes_at_scheduled_time`, or `stays_draft`.             |
| `continues_automatically`                       | `true`: the publish continues without a call. `false`: follow `recovery`.                                  |
| `poll_after_seconds`                            | When to check again. It is a hint, not an estimate.                                                        |
| `recovery`                                      | Only when `recording_state` is `no_change_for_hours` or `failed`.                                          |

While `continues_automatically` is `true`, the publish continues by itself. You can leave, and nobody has to keep asking. The assistant tells you what the publish waits for, when the recording was uploaded, if the recording still changes, and what happens at the end.

When `recording_state` is `ready`, the publish continues shortly. If a later check still shows `ready`, resume the operation once.

When `recording_state` is `no_change_for_hours` or `failed`, follow `waiting.recovery`:

* `resume_operation`: resume the operation once. This checks the recording and starts its processing again. Do not upload a new file. If the recording still does not change, contact Podigee Support with the operation ID and the link of the episode.
* `replace_recording`: the recording cannot be used, for example a video without sound. Cancel the operation with `cancel_operation`. Replace the recording on the episode page; `find_in_podigee` with the `episode_id` gives the link. Then send `publish_episode` again with a new idempotency key.

Expected result: the wait ends, and the publish reaches the stage of its mode. Or you follow the one `recovery` step and know what comes next.

## Follow the recovery action

A publish that failed contains `recovery` with one `action` and a `message`. Follow that action. Do not decide only from `retryable`.

| Action                 | What to do                                                                                                                                                                                                                                                                  |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `restore_access`       | Restore the access that `error.message` names, for example a revoked connection or a suspended subscription. Then resume the operation if `retryable` is `true`. Otherwise, send `publish_episode` again with a new idempotency key.                                        |
| `check_plan_allowance` | Run `doctor` to find the allowance that is used up, and get more allowance. Then resume the operation if `retryable` is `true`. Otherwise, send `publish_episode` again with a new idempotency key.                                                                         |
| `correct_request`      | Correct the request as `error.message` tells you. Send `publish_episode` again with a new idempotency key. Do not resume the operation.                                                                                                                                     |
| `replace_recording`    | Replace the recording on the episode page; `find_in_podigee` with the `episode_id` gives the link. Do not resume the operation. If `retryable` is `true`, cancel the operation with `cancel_operation` first. Then send `publish_episode` again with a new idempotency key. |
| `resume_operation`     | Resume the operation once. If it fails the same way again, do not resume it again. Contact Podigee Support with the operation ID.                                                                                                                                           |
| `contact_support`      | Do not retry, and do not upload a new file. Contact Podigee Support with the operation ID and the link of the episode.                                                                                                                                                      |

Never upload a new file or convert the file to another format unless the action is `replace_recording`.

`import_podcast` and `send_listener_password_reset` do not return `recovery`. For them, resume once when `retryable` is `true`. Otherwise, read `error.message`. For an import, see [Import a podcast](https://docs.podigee.com/documentation/start-here/ai-agents/media-and-publishing/import-a-podcast.md).

## Resume an operation

What you need:

* For a publish: `recovery.action` is `resume_operation`. Or `recovery.action` is `restore_access` or `check_plan_allowance`, you fixed the cause, and `retryable` is `true`.
* For an import or a password reset: `retryable` is `true`.
* A waiting publish at its encoding or processing step, or a waiting import at its encoding step, can also be resumed.
* The same user and account that started the operation.
* The write scopes of the operation type: `mcp:podcasts:write` and `mcp:media:write` for a publish or an import, `mcp:listeners:write` for a password reset.

Steps:

1. The assistant calls `resume_operation` with the `operation_id` and `dry_run: true`.
2. Read the operation in the preview.
3. Say yes in a later message.
4. The assistant sends `resume_operation` again with `dry_run: false` and the `confirm` value.
5. Follow the same `operation_id` to a terminal state.

A resume uses your current authorization. The operation keeps the record of the user, the account, and the credential that started it.

Expected result: the same operation continues. No second episode, upload, or import starts.

If the resume is refused:

* `operation_in_progress`: the operation still runs, waits, or is being canceled. Check it again later.
* "This operation cannot be resumed": only a publish, an import, and a password reset can be resumed. Changes that do not return an operation, for example `update_episode`, are not resumed. Request a new preview and confirm it with the same idempotency key.
* "Operation is not retryable": follow `recovery` or `error.message`. Do not start the first request again with the same idempotency key; Podigee returns the same operation.

Next step: follow the operation again.

## Cancel an operation

What you need:

* An operation that is not in a terminal state.
* The write scopes of the operation type, as for a resume. To cancel a publish, you also need the permission to publish in that show.

Steps:

1. The assistant calls `cancel_operation` with the `operation_id` and `dry_run: true`.
2. Read which operation will be canceled.
3. Say yes in a later message.
4. The assistant sends `cancel_operation` again with the `confirm` value.
5. Follow the operation until its state is `cancelled` or another terminal state.
6. Verify what was complete before the cancellation.

A canceled publish stops its encoding. A canceled import stops, and the episodes that it already brought in stay.

Expected result: the operation stops at a safe point, and its state becomes `cancelled`.

If the cancellation is refused:

* "Operation is already complete": the operation is in a terminal state. Read its result.
* "An active password reset cannot be cancelled safely": a running password reset continues to its end.
* `operation_in_progress` with "has not reached a terminal state": the cancellation continues. Check the operation again with `get_operation`. Do not start a replacement operation.

Next step: for a publish with the action `replace_recording`, replace the recording, then send a new `publish_episode` with a new idempotency key.

## Operations and authorization

An operation does not belong to one conversation. A new conversation can read it when the connection belongs to the same user and account and has the scope.

Podigee checks the authorization again at safe points while the work runs. When you revoke the connection, new calls stop, and running work stops at its next safe point with `authorization_revoked`. Drafts and imported episodes that are already complete stay. After you connect again, the assistant needs a new preview for a resume; an old `confirm` value does not work. See [Manage connected assistants](https://docs.podigee.com/documentation/start-here/ai-agents/connect-and-authorize/manage-connected-assistants.md).

Error codes and limits are in [Limits, errors, and recovery](https://docs.podigee.com/documentation/start-here/ai-agents/mcp-reference/limits-errors-and-recovery.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.podigee.com/documentation/start-here/ai-agents/work-safely/follow-and-recover-long-running-operations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
