# Task Lifecycle Management

Understanding the lifecycle of a browser task in **Browser Swarm** is crucial for optimizing resource usage, ensuring reliability, and effectively debugging automation workflows.

***

### ⏱️ Task Termination Methods

Browser tasks can conclude through various mechanisms:

1. **Automatic Timeout**: Each task has a default timeout, configurable at the project level or overridden per task. Tasks exceeding this duration will automatically terminate.
2. **Manual Termination**: You can explicitly end tasks by:
   * Programmatically closing the browser (e.g., `browser.close()` or `driver.quit()`).
   * Using the Sessions API to terminate the task.
   * Releasing keep-alive tasks when they're no longer needed.
3. **Unhandled Errors**: Unexpected issues, such as network interruptions or uncaught exceptions in your automation code, can lead to premature task termination. Implement robust error handling to mitigate this risk.

***

### 🕒 Configuring Task Timeouts

Timeouts can be set at two levels:

* **Project-Level Timeout**: Defines the default timeout for all tasks within a project.[Browserbase](https://docs.browserbase.com/fundamentals/manage-browser-session?utm_source=chatgpt.com)
* **Task-Level Timeout**: Overrides the project default for individual tasks, allowing fine-grained control over task durations.

Adjust these settings based on the expected duration of your automation workflows to prevent unintended terminations.

***

### 🔍 Debugging Completed Tasks

Utilize the **Session Inspector** to analyze and debug completed tasks:

* **Session Replay**: Reconstruct and review browser interactions step-by-step.
* **Network Monitor**: Inspect HTTP requests, responses, and timings.
* **Console & Logs**: Examine JavaScript outputs and debug messages.
* **Performance Metrics**: Assess CPU, memory usage, and other vital statistics.

These tools provide comprehensive insights to identify and resolve issues effectively.

***

### 📊 Monitoring Task Usage

Track and analyze your browser task usage through:

* **Dashboard**: Access the Overview Dashboard to view total browser minutes, active tasks, usage trends, and billing information.
* **Sessions List**: Browse your task history to examine durations, statuses, and resource consumption.

For programmatic access to usage metrics, refer to the Measuring Usage Guide.

***

By effectively managing the lifecycle of your browser tasks, you can ensure optimal performance, cost-efficiency, and reliability in your automation processes.


---

# Agent Instructions: 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://browserswarm.gitbook.io/docs/task-lifecycle-management.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.
