<@ULVA73B9P> How can I find the task that is curre...
# ask-marvin
f
@Marvin How can I find the task that is currently holding a concurrency slot? The
prefect api GET v2/concurrency_limits/tag:my_task
is only showing "active_slots", but not the task holding the slot
m
thought for 263.9 seconds
Great question. In Prefect 3.x, a tag-based concurrency limit tracks slot holders as TaskRun IDs. The object you get back from GET v2/concurrency_limits/tag:my_task includes an
active_slots
array of TaskRun IDs, not the human-readable task name. To see which task/flow is holding each slot, look up those TaskRun IDs. Two easy ways: - CLI - List slot holders:
Copy code
prefect concurrency-limit inspect tag:my_task
This shows
active_slots
as a list of TaskRun IDs. - Inspect each task run to see the task name and flow:
Copy code
prefect task-run inspect <task_run_id>
If you want more detail on the parent flow:
Copy code
prefect flow-run inspect <flow_run_id>
- REST API - Read the concurrency limit (shows TaskRun IDs):
Copy code
GET /api/v2/concurrency_limits/tag:my_task
- For each ID in
active_slots
, fetch the task run:
Copy code
GET /api/v2/task_runs/<task_run_id>
The response includes fields like
name
(task name) and
flow_run_id
so you can trace it back to the flow. Helpful docs: - CLI: concurrency-limit - REST: read concurrency limit by tag - REST: read task run Notes: - There isn’t a UI page that directly lists current slot holders; the CLI/API approach above is the way to go. - If you’re looking at global concurrency limits (not tag-based), those may report
active_slots
as a count rather than a list of IDs. For tag-based limits like
tag:my_task
, you’ll get the TaskRun IDs. If you want, I can share a quick script to print task names and parent flow runs for all current holders of
tag:my_task
.
f
@Marvin this is not correct. The v2 api does not hold task_ids.
m
thought for 361.0 seconds
You’re right — for the newer “global” (v2) concurrency limits, the API only returns an active_slots count and does not expose the identities of the holders. There isn’t a supported way today to list which run holds a global (v2) slot. There are two different concurrency systems in Prefect 3.x: - Tag-based limits (the original system): The endpoint returns a list of TaskRun IDs in active_slots, so you can trace the holders. - Global (v2) limits: The endpoint returns only a count for active_slots; the specific slot holders are not exposed. What you can do: - If you’re using a tag-based limit (your example path looks like a tag-based endpoint): you should see TaskRun IDs in active_slots. From there, fetch each task run to see the task/flow. - CLI:
Copy code
prefect concurrency-limit inspect tag:my_task
    prefect task-run inspect <task_run_id>
- REST:
Copy code
GET /api/v2/concurrency_limits/tag:my_task
    GET /api/v2/task_runs/<task_run_id>
- Docs: CLI: concurrency limitsREST: read tag-based limitREST: read task run - If you’re using a global (v2) concurrency limit: the API will only show an integer count of active_slots. There’s no built-in mapping to the specific task/flow holders. As a workaround, you can query task runs that are likely subject to the limit (e.g., by tag or other criteria) and are RUNNING to approximate who is occupying slots. Example REST filter for tag-based tasks currently running:
Copy code
POST /api/v2/task_runs/filter
  {
    "task_runs": {
      "tags": {"all_": ["my_task"]}
    },
    "task_run_states": {
      "type": {"any_": ["RUNNING"]}
    },
    "limit": 200
  }
Docs: How-to: global concurrency limitsREST: read global (v2) limitREST: read task runs If you can share which type of limit you’ve created (tag-based vs global v2) and the JSON you get back from your endpoint, I can give you an exact set of steps or a short script to list the holders (or the best-possible approximation for global v2).