> For the complete documentation index, see [llms.txt](https://docs.testvibe.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.testvibe.com/testvibe-api/api-reference/async-operations.md).

# Long-running operations

Two operations do real work in cloud sandboxes and take a while:

* **Generation** ([`generate_feature`](/testvibe-api/api-reference/generation/generate_feature.md)) — minutes, consumes AI credits.
* **Runs** ([`run_feature`](/testvibe-api/api-reference/runs/run_feature.md)) — typically \~30 seconds.

Neither blocks. The dispatch returns `202` immediately with an id, and you observe progress from there.

## The pattern

{% stepper %}
{% step %}

### Dispatch

```
POST …/features/12/run        → 202 { "runId": 214, "featureId": 12 }
POST …/features/12/generate   → 202 { "requestId": "a1b2…", "featureId": 12 }
```

A dispatch that can't start — feature already generating, tests not generated yet — fails fast with `409 conflict` instead.
{% endstep %}

{% step %}

### Poll

```
GET …/runs/214                → { "status": "running", … }
GET …/features/12/generation  → { "featureStatus": "generating", "sections": [...] }
```

A few seconds between polls is plenty. Runs finish as `passed`/`failed`; generation moves the feature to `generated`/`failed`/`cancelled`.
{% endstep %}

{% step %}

### Read the outcome

The same `GET` that told you it finished carries the full result — the [run digest](/testvibe-api/api-reference/runs/get_run.md) or the [generation status](/testvibe-api/api-reference/generation/get_generation_status.md). For a failed generation, drill into the [log](/testvibe-api/api-reference/generation/get_generation_log.md).
{% endstep %}
{% endstepper %}

## Let the tooling wait for you

| Surface | Convenience                                                                                                                                                                                                                              |
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| MCP     | [`wait_for_run`](/testvibe-api/api-reference/runs/wait_for_run.md) / [`wait_for_generation`](/testvibe-api/api-reference/generation/wait_for_generation.md) — poll server-side every 3 s; `timeoutSeconds` default **120**, max **170**. |
| CLI     | `testvibe run … --wait`, `testvibe generate … --watch`.                                                                                                                                                                                  |

{% hint style="info" %}
**Timeout ≠ failure.** If a `wait_*` tool returns while the work is still in flight, nothing was cancelled — call it again to keep waiting. This keeps each MCP call comfortably inside client tool-call timeouts.
{% endhint %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.testvibe.com/testvibe-api/api-reference/async-operations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
