# How can we retry jobs only when the agent is gracefully terminated?

**URL:** <https://forum.buildkite.community/t/how-can-we-retry-jobs-only-when-the-agent-is-gracefully-terminated/1831>\
**Category:** Pipelines\
**Created:** [December 17, 2021, 6:08am UTC](https://forum.buildkite.community/t/how-can-we-retry-jobs-only-when-the-agent-is-gracefully-terminated/1831 "2021-12-17T06:08:53Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![tfuji](https://avatars.discourse-cdn.com/v4/letter/t/958977/32.png) [@tfuji](https://forum.buildkite.community/u/tfuji)\
**Post date:** [December 22, 2021, 12:05pm UTC](https://forum.buildkite.community/t/how-can-we-retry-jobs-only-when-the-agent-is-gracefully-terminated/1831/7 "2021-12-22T12:05:10Z")

</div>

I’m not sure why but I couldn’t change the signal by setting `cancel-signal` to the agent… But anyway, I found a feature request which will solve my problem. I’ll wait for that.

> [@Automatically retry failed steps on AGENT\_STOP](https://forum.buildkite.community/t/automatically-retry-failed-steps-on-agent-stop/1443):
>
> Hey folks, I’d like to submit a feature request where steps that fail because of an AGENT\_STOP exit code are automatically retried. When an agent is stopped, we see Received cancellation signal, interrupting in the log. As this can happen at any time, this can interrupt any hook, plugin, or command that runs. This makes it tricky to implement with the automatic\_retry logic at a step level. Looking at the timeline of such affected steps, it looks like Buildkite knows when a agent is stopped: C…

Thank you so much for helping me!

---

_[View the full topic](https://forum.buildkite.community/t/how-can-we-retry-jobs-only-when-the-agent-is-gracefully-terminated/1831)._
