clear_task_instances
Clear specific task instances in Airflow to reset their state and allow rerunning, supporting selective clearing by date range, task IDs, and dependency relationships.
Instructions
Clear a set of task instances
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dag_id | Yes | ||
| dry_run | No | ||
| end_date | No | ||
| include_downstream | No | ||
| include_future | No | ||
| include_parentdag | No | ||
| include_past | No | ||
| include_subdags | No | ||
| include_upstream | No | ||
| reset_dag_runs | No | ||
| start_date | No | ||
| task_ids | No |
Input Schema (JSON Schema)
{
"properties": {
"dag_id": {
"title": "Dag Id",
"type": "string"
},
"dry_run": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Dry Run"
},
"end_date": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "End Date"
},
"include_downstream": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Include Downstream"
},
"include_future": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Include Future"
},
"include_parentdag": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Include Parentdag"
},
"include_past": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Include Past"
},
"include_subdags": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Include Subdags"
},
"include_upstream": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Include Upstream"
},
"reset_dag_runs": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Reset Dag Runs"
},
"start_date": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Start Date"
},
"task_ids": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"default": null,
"title": "Task Ids"
}
},
"required": [
"dag_id"
],
"type": "object"
}
Implementation Reference
- src/airflow/dag.py:15-33 (registration)Function that returns the list of all MCP tools for registration, including the clear_task_instances tool tuple.def get_all_functions() -> list[tuple[Callable, str, str, bool]]: """Return list of (function, name, description, is_read_only) tuples for registration.""" return [ (get_dags, "fetch_dags", "Fetch all DAGs", True), (get_dag, "get_dag", "Get a DAG by ID", True), (get_dag_details, "get_dag_details", "Get a simplified representation of DAG", True), (get_dag_source, "get_dag_source", "Get a source code", True), (pause_dag, "pause_dag", "Pause a DAG by ID", False), (unpause_dag, "unpause_dag", "Unpause a DAG by ID", False), (get_dag_tasks, "get_dag_tasks", "Get tasks for DAG", True), (get_task, "get_task", "Get a task by ID", True), (get_tasks, "get_tasks", "Get tasks for DAG", True), (patch_dag, "patch_dag", "Update a DAG", False), (patch_dags, "patch_dags", "Update multiple DAGs", False), (delete_dag, "delete_dag", "Delete a DAG", False), (clear_task_instances, "clear_task_instances", "Clear a set of task instances", False), (set_task_instances_state, "set_task_instances_state", "Set a state of task instances", False), (reparse_dag_file, "reparse_dag_file", "Request re-parsing of a DAG file", False), ]
- src/airflow/dag.py:190-231 (handler)The core implementation of the clear_task_instances tool. It collects optional parameters into a dictionary, instantiates the ClearTaskInstances model, calls the Airflow DAG API to clear the task instances, and returns the response as text content.async def clear_task_instances( dag_id: str, task_ids: Optional[List[str]] = None, start_date: Optional[str] = None, end_date: Optional[str] = None, include_subdags: Optional[bool] = None, include_parentdag: Optional[bool] = None, include_upstream: Optional[bool] = None, include_downstream: Optional[bool] = None, include_future: Optional[bool] = None, include_past: Optional[bool] = None, dry_run: Optional[bool] = None, reset_dag_runs: Optional[bool] = None, ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]: clear_request = {} if task_ids is not None: clear_request["task_ids"] = task_ids if start_date is not None: clear_request["start_date"] = start_date if end_date is not None: clear_request["end_date"] = end_date if include_subdags is not None: clear_request["include_subdags"] = include_subdags if include_parentdag is not None: clear_request["include_parentdag"] = include_parentdag if include_upstream is not None: clear_request["include_upstream"] = include_upstream if include_downstream is not None: clear_request["include_downstream"] = include_downstream if include_future is not None: clear_request["include_future"] = include_future if include_past is not None: clear_request["include_past"] = include_past if dry_run is not None: clear_request["dry_run"] = dry_run if reset_dag_runs is not None: clear_request["reset_dag_runs"] = reset_dag_runs clear_task_instances = ClearTaskInstances(**clear_request) response = dag_api.post_clear_task_instances(dag_id=dag_id, clear_task_instances=clear_task_instances) return [types.TextContent(type="text", text=str(response.to_dict()))]
- src/airflow/dag.py:5-5 (schema)Import of the ClearTaskInstances Pydantic model used for input schema validation and serialization in the clear_task_instances handler.from airflow_client.client.model.clear_task_instances import ClearTaskInstances