# Tasks: Outputs & Webhooks

> Save files written to /outputs as Assets, filter which files to keep with glob patterns, track output uploads and file limits, and receive signed completion webhooks.

Source: https://docs.meshive.ai/serverless/tasks/outputs/

Saving task output files to Assets, filtering outputs, handling file limits, and receiving webhooks or email notifications for [Serverless Tasks](/serverless/tasks/).

## Writing your script: outputs

Anything your program writes to `/outputs` is uploaded automatically after the container exits and becomes downloadable from the task's page in the console. In **Script** mode your script also starts with `/outputs` as its **working directory**; in **Project** mode the working directory is [your project folder](/serverless/tasks/projects/#run-a-project) instead.

- **Script mode:** relative writes (`open("result.csv", "w")`) already land in `/outputs` — no path handling needed.
- **Project mode:** relative writes land in the project folder, and files that are new there are moved to `/outputs` when the program exits. Write to `/outputs/...` explicitly for anything that must survive a Stop or a max run time.
- `_task.log` is added automatically: a tail of the run's log, archived alongside your files.
- To keep only some of the files, choose them in the **Output** card of the submit form — see [Choosing which files to save](#choosing-which-files-to-save). By default everything is kept.
- When the run ends, everything in `/outputs` (or only the files you chose to save) becomes an [asset](/assets/) in your workspace — kept until you delete it, and billed as storage if it lives in managed storage. **Each run becomes its own asset** — re-running the task creates a new one (`-2`, `-3`, and so on). Only `_task.log` follows the log retention policy.
- The upload **resumes after interruptions and retries automatically** for up to ~3 days (about 6 hours if the task ended on a platform fault or because credit ran out); the console shows how far it has got (see [Saving outputs](#saving-outputs)). If you don't need the files, **Discard outputs** on the task page stops the transfer and releases the storage.

| Output limit | Value |
| --- | --- |
| Max size per file | 5 GiB — where `/outputs` is billed as a volume, this cap doesn't apply |
| Max number of files | Usually 2,000 (see [Over the file limit](#over-the-file-limit)) |
| Output disk budget | 20 GiB — where `/outputs` is billed as a volume, it starts at 20 GiB and grows as the task writes, up to the task's share of the node's disk |

> **Caution:**
> Exceeding the **20 GiB output disk budget mid-run evicts the task** — it ends as a user fault and is charged in full. Where `/outputs` is billed as a volume, it grows instead, and writes to it fail only once it can't grow any further. Stream large intermediates elsewhere or clean up as you go.

### Choosing which files to save

In the **Output** card, click **All files** next to `/outputs`. Turn on any mix of **Images**, **Videos**, **Model files** and **Data & logs**, add your own patterns, or type a path under **Check a path** to see whether it would be saved. The example tree under `/outputs` marks what each choice keeps.

Your own patterns are globs, the same syntax as [watched-folder include rules](/assets/harvest/#watched-folders). Only files under `/outputs` that match are uploaded; the rest are deleted when the task ends. From code, pass the patterns as `output_include` (SDK and MCP) or `--output-include` (CLI).

| Pattern | Saves |
| --- | --- |
| `*.safetensors` | Every `.safetensors` file, in any subfolder |
| `samples/*.png` | PNGs directly inside `samples/` — not in its subfolders |
| `samples/**/*.png` | PNGs anywhere under `samples/` |
| `checkpoints/` | Every folder named `checkpoints`, at any depth, with everything inside (`/checkpoints/` only the one at the top) |

- Patterns are relative to `/outputs`: write `samples/*.png`, not `/outputs/samples/*.png` or `./samples/*.png`.
- A pattern that matches a folder saves everything inside it. `out/*` also matches the folder `out/sub`, so it saves all of `out`.
- Matching is case-sensitive (`*.png` doesn't match `A.PNG`). Brackets and braces (`[abc]`, `{png,jpg}`) aren't supported — add one pattern per alternative (`*.png`, `*.jpg`) and use `?` for a single character. Separate folders with `/`, not `\`. A leading `!` is reserved.
- In the submit form you can type several patterns separated by commas. From code, pass a list (or repeat `--output-include`) — there a comma is part of the pattern.
- `_task.log` is still added.
- **Files you don't save still take up `/outputs` while the task runs** — they count toward the output disk budget, and toward the disk charge where `/outputs` is billed as a volume. They are deleted, not uploaded, when the task ends.
- If no file matches, the task still succeeds and no output asset is created; the task page shows that nothing matched the filter.
- The [file-count limit](#over-the-file-limit) applies to the files that match.

### Saving outputs

Outputs are saved after the run ends. Until they're in Assets, the console shows how far saving has got:

- **Tasks list and task page** — a progress banner with the files, the size and the time left. A succeeded task's status badge shows **Uploading** until then.
- **Assets page** — a **Saving outputs** section lists each task that is still saving. While the Assets page is open, a notification appears when a task's outputs are saved.
- **Delete is disabled** on a task while its outputs are being saved.
- **A failed upload attempt is retried automatically.** The banner then says when the next attempt is, for example **Retrying upload · 48/126 files · next try in 3 min**.

Outputs usually appear in Assets within seconds after the upload finishes. For some runs they appear about 2 minutes after the last file, and in rare cases up to about 30 minutes after the task ends.

Once they're saved, the task page shows **Saved to Assets as `<asset name>` · `<time>` · never auto-deleted**, with an **Open asset** button. For a partial save, the time is replaced by how many files were saved (`N of M files`). Outputs saved to your connected bucket show the bucket path instead, still with **Open asset**.

Compute stops when your script ends; where `/outputs` is billed as a volume, it keeps billing as storage until saving finishes — see [Task billing & refunds](/serverless/tasks-billing/#how-billing-works).

### Over the file limit

A task saves a limited number of output files — usually 2,000. When files are left out because of the limit, the task page usually says how many and names the limit.

Going over the limit doesn't lose the whole run. Usually, the files closest to `/outputs` are kept first — shallower folders before deeper ones, then in path order — and the rest aren't saved. The task then shows an amber notice, for example "Only 2,000 of 2,431 output files were saved — 431 were over the 2,000-file limit." Files a [project](/serverless/tasks/projects/#how-a-project-runs) couldn't move to `/outputs` are listed only in the log.

To keep everything, zip many small files into one archive before the script exits, or narrow the task's [output include filter](#choosing-which-files-to-save), then re-run the task.

## Webhooks

Add a webhook to be notified when a task reaches a terminal state:

| Event | When |
| --- | --- |
| `task.succeeded` | Script exited with code 0 |
| `task.failed` | Script failed — non-zero exit, OOM, eviction, install failure, or a platform fault |
| `task.timed_out` | Max run time reached |
| `task.outputs_ready` | The output upload ended: every file was uploaded (`completed`), the upload ended before every file was saved — it ran out of time or couldn't continue (`failed`) — or you discarded the rest (`discarded`). It comes before the files are registered in Assets, and not every task sends it. |
| `task.outputs_saved` | The outputs were saved to Assets. Sent once per task, right after they are registered, even when no file was saved. |

The output events come after the terminal event — outputs can still be uploading when `task.succeeded` arrives. Apart from them, only terminal states send an event. A **manual Stop sends no terminal event**, but the output events still arrive for its outputs.

The payload envelope matches [inference webhooks](/serverless/webhooks/):

```json
{
  "id": "evt_3f9c1a2b4d5e6f70",
  "type": "task.succeeded",
  "created_at": 1780000000,
  "data": {
    "id": "task_abc123",
    "name": "nightly-batch-embed",
    "status": "succeeded",
    "fault_class": "none",
    "exit_code": 0,
    "failure_reason": null,
    "namespace_name": "my-workspace",
    "gpu_model": "RTX 4090",
    "created_at": 1779996400,
    "finished_at": 1779999998,
    "total_cost": "0.42000000"
  }
}
```

- `fault_class` — `none` (succeeded), `user`, or `platform`. This is what decides [whether anything is refunded](/serverless/tasks-billing/#who-pays-when-something-goes-wrong).
- `total_cost` — the final, trued-up charge in credit.
- Terminal payloads also carry `output_upload_state` — where the output transfer stands at that moment. Wait for `task.outputs_saved` before fetching files programmatically.

`task.outputs_saved` has its own `data`:

```json
{
  "id": "evt_5e6f708192030405",
  "type": "task.outputs_saved",
  "created_at": 1780001000,
  "data": {
    "id": "task_9f8e7d6c5b4a3210",
    "name": "batch-inference",
    "status": "succeeded",
    "namespace_name": "my-workspace",
    "asset_id": "asset_1a2b3c4d5e6f7081",
    "asset_name": "batch-inference",
    "files_saved": 2000,
    "files_not_saved": 37,
    "bytes_saved": 4831838208,
    "finished_at": 1780000390
  }
}
```

- `status` — the task's own terminal status, so this event alone tells you how the run ended.
- `asset_id` / `asset_name` — the asset the outputs became. Both are `null` when no file was saved.
- `files_not_saved` — files that weren't stored: files over the [file limit](#over-the-file-limit), plus files still incomplete when the upload ended. Only tasks that also send `task.outputs_ready` count them; for other tasks it is `0`.

`task.outputs_ready` carries `id`, `name`, `status`, `namespace_name`, `output_upload_state`, `output_files_declared`, `output_files_completed`, `output_bytes_completed`, `created_at` and `finished_at`.

Deliveries carry the same **`X-Meshive-Signature`** HMAC header as every other Meshive webhook — verify it exactly as described in [Webhooks → Verifying the signature](/serverless/webhooks/#verifying-the-signature). Retries, idempotency (dedupe on the event `id`), and security rules are also identical.

**No webhook, or one that can't be reached? You get an email.** When a task has no webhook for its event — no `webhook_url` on the task and no workspace endpoint subscribed to that event — the person who submitted it gets one email when it succeeds, fails, times out, or is stopped because the credit balance ran out. If the task has webhooks but none of them accepted the event after all retries, the same email goes out with the reason the delivery failed. A task you stop yourself sends no email.
