---
title: "Give every job a time limit · Agent Wranglers"
url: https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/job-time-limits
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Give every job a time limit

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Background jobs and queues](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- ID: SCL-18
- Level: Recommended
- Chapter: [Background jobs and queues](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues)
- Rule: Set a maximum run time on each job type. Keep the queue's lock or visibility time longer than that limit, so no second worker starts a job that still runs.
- How: A job stuck on a hung call holds a worker forever, and enough of them stop the queue. Set each limit to about twice the job's 99th percentile time, the same way [Set timeouts on every call](https://agentwranglers.se/playbook/api-design/reliability/timeouts) does for requests. When the visibility time is shorter than the job, the queue hands the job to a second worker while the first still runs. Some libraries renew the lock while a job runs, so read your library's settings. Retries and failed jobs follow [Set aside messages that keep failing](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/dead-letter-queue).
- Check: Every job type in the code sets a time limit, and the queue's visibility or lock time is longer. A test job that sleeps past its limit is stopped, retried, and lands in the dead letter queue after the attempt limit.

## Sources

- [Amazon SQS visibility timeout](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html)
- [BullMQ stalled jobs](https://docs.bullmq.io/guide/workers/stalled-jobs)

## Related rules

- [Set timeouts on every call](https://agentwranglers.se/playbook/api-design/reliability/timeouts) in API design
- [Set aside messages that keep failing](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/dead-letter-queue) in Scaling

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/job-time-limits">Agent Wranglers scaling playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Make every job safe to run twice](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/idempotent-jobs)
- Next: [Bound the backlog and push back on producers](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues/bounded-backlog)
- [Background jobs and queues](https://agentwranglers.se/playbook/scaling/background-jobs-and-queues)
