<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-cleanup-step-killed-the-job-it-was-running-inside--y6ntqdpr9" -->

---
title: The cleanup step killed the job it was running inside.
description: A systemd oneshot job self-destructed because its own cleanup routine, a reconcile sweep that disables any unit not present in a registry file, ran after the...
canonical: https://daily.dev/posts/the-cleanup-step-killed-the-job-it-was-running-inside--y6ntqdpr9
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The cleanup step killed the job it was running inside. | daily.dev
og:description: A systemd oneshot job self-destructed because its own cleanup routine, a reconcile sweep that disables any unit not present in a registry file, ran after the...
og:url: https://daily.dev/posts/the-cleanup-step-killed-the-job-it-was-running-inside--y6ntqdpr9
og:image: https://api.daily.dev/og/posts/y6ntqDPr9.png
og:image:alt: The cleanup step killed the job it was running inside.
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The cleanup step killed the job it was running inside.

**[AlphAI](https://daily.dev/sources/alphai)** · [@mikhailmakeev](https://daily.dev/mikhailmakeev) · 2 min read · 0 upvotes · 0 comments

## Summary

A systemd oneshot job self-destructed because its own cleanup routine, a reconcile sweep that disables any unit not present in a registry file, ran after the job had already deleted its own registry entry, causing the sweep to SIGTERM its own PID mid-loop. A first attempted fix, which deferred cleanup and polled `systemctl is-active --quiet`, failed identically because oneshot units stay in 'activating' (not 'active') for their entire ExecStart, so the wait condition never held. The actual fix reads ActiveState instead, where 'activating' counts as alive. Lessons: a process reconciling a set it belongs to must know its own identity (via /proc/self/cgroup, since $INVOCATION_ID doesn't help here), and never poll is-active on a oneshot unit.

## Content

A scheduled one-shot job of mine did its whole job last week, sent its report, and then killed itself two minutes in. The log was zero bytes and the unit ended `Result: signal`, `ExecMainStatus=15`. Nothing in the report itself was wrong.

The contract for these jobs is that after reporting they clean up after themselves: delete their own row from the registry file, then run the reconcile sweep. The sweep walks every `skill-*.timer` and `skill-*.service` and does `systemctl --user disable --now` on anything not in the registry.

Its own row was already gone, one step earlier. So the sweep reached the `.service` it was executing inside and stopped it. SIGTERM to its own PID, on that line, mid-loop. The `rm` on the next line never ran. So the orphaned unit file survived the cleanup whose whole purpose was to remove it.

Glob order is the only reason this wasn't worse. Timers sort before services, and this was the first non-registry service in the list, so the loop died on itself with the other 19 units untouched.

Then the first fix failed in a more interesting way than the bug. It deferred the removal to a small job that waits for the run to end, and it waited with `systemctl is-active --quiet`. A `Type=oneshot` unit stays in `activating` for the entire `ExecStart`, so "is it active" is false the whole time it is running. The waiter waited for nothing and killed the run exactly as before. It reads `ActiveState` now, where activating still counts as alive.

Two things I'd take anywhere: a process that reconciles a set it belongs to has to know its own name, and `/proc/self/cgroup` gives it to you where `$INVOCATION_ID` does not. And never poll `is-active` on a oneshot.

## Similar posts on daily.dev

- [Manticore Search under systemd: beyond fork, PID files, and guesswork](https://daily.dev/posts/manticore-search-under-systemd-beyond-fork-pid-files-and-guesswork-q3ifd25lz) · Manticore · 0 upvotes · 0 comments
- [Tracing a memory leak bug in PID 1 and contributing an upstream fix: a Linux support story](https://daily.dev/posts/tracing-a-memory-leak-bug-in-pid-1-and-contributing-an-upstream-fix-a-linux-support-story-acqq4ixcg) · Ubuntu · 2 upvotes · 0 comments
- [Did My Test Suite Just Kill the GitHub Actions Runner\!?](https://daily.dev/posts/did-my-test-suite-just-kill-the-github-actions-runner--socinxsca) · ITNEXT · 2 upvotes · 0 comments
- [You Don't Love systemd Timers Enough](https://daily.dev/posts/you-don-t-love-systemd-timers-enough-x0ogcxoqr) · Lobsters · 1 upvotes · 0 comments
- [Nobody’s agent fleet fails the way the vendors say it will](https://daily.dev/posts/nobody-s-agent-fleet-fails-the-way-the-vendors-say-it-will-tvfxicgff) · InfoWorld · 0 upvotes · 0 comments

---

Tags: [#linux](https://daily.dev/tags/linux)

[View this post on daily.dev](https://daily.dev/posts/the-cleanup-step-killed-the-job-it-was-running-inside--y6ntqdpr9)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/the-cleanup-step-killed-the-job-it-was-running-inside--y6ntqdpr9","headline":"The cleanup step killed the job it was running inside.","text":"A systemd oneshot job self-destructed because its own cleanup routine, a reconcile sweep that disables any unit not present in a registry file, ran after the job had already deleted its own registry entry, causing the sweep to SIGTERM its own PID mid-loop. A first attempted fix, which deferred cleanup and polled `systemctl is-active --quiet`, failed identically because oneshot units stay in 'activating' (not 'active') for their entire ExecStart, so the wait condition never held. The actual fix reads ActiveState instead, where 'activating' counts as alive. Lessons: a process reconciling a set it belongs to must know its own identity (via /proc/self/cgroup, since $INVOCATION_ID doesn't help here), and never poll is-active on a oneshot unit.","url":"https://daily.dev/posts/the-cleanup-step-killed-the-job-it-was-running-inside--y6ntqdpr9","datePublished":"2026-09-08T04:29:43.847Z","dateModified":"2026-09-13T21:34:19.827Z","author":{"@type":"Person","name":"Mikhail Makeev","url":"https://daily.dev/mikhailmakeev","image":"https://lh3.googleusercontent.com/a/ACg8ocIjcvDU1gmJ9-KJDeTYqY2rMdl5QxcWYtLTGSXrj8ubF4nwar_w=s96-c","description":"Owner of alphai.io","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":5500}},"image":"https://media.daily.dev/image/upload/s--I8XGPWE5--/f_auto/v1789276673/posts/y6ntqDPr9?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/alphai","name":"AlphAI"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"AlphAI","item":"https://daily.dev/squads/alphai"},{"@type":"ListItem","position":3,"name":"The cleanup step killed the job it was running inside."}]}
```

