T0ha666

T0ha666

A deploy killed my OTP processes but not my containers — writing a reconciler GenServer

A deploy killed my OTP processes but not the containers running my AI agents. That
mismatch kept a kanban card “executing” for eighteen hours after the work — and the
merged PR — was already done. It seems to be a lesson many Elixir projects eventually
need: OTP supervision stops at the edge of your VM.

The setup: each agent runs in its own Docker Swarm container, and a TaskRunner
GenServer per task watches it over an HTTP socket proxy. When I deploy, every
TaskRunner dies. The containers keep running, happily compiling somebody’s project,
with nobody left listening. The database still says status: :running. The world says
something else.

What I ended up writing is a small reconciler GenServer that ticks every sixty seconds
and asks, for each session that claims to be running: is this still true? A few things I
learned the hard way:

  • The row outlives the process. Anything that must survive a deploy has to be a
    Postgres row, not GenServer state. The GenServer is a fast index over the rows,
    rebuilt on boot.
  • Adopt, don’t fail. If the container is still alive, a fresh TaskRunner
    re-attaches to the run instead of throwing away thirty minutes of agent work because
    of a CSS deploy.
  • Every wait needs a deadline. My first adoption loop polled for an exit-code
    marker file inside the container — but a Swarm reschedule replaces the container, and
    the marker dies with the old one’s /tmp. The loop polled forever, and every other
    recovery sweep politely stepped around the “running” session. That was my
    eighteen-hour card.
  • Pull the decision out of the I/O. The give-up decision is now a pure function of
    four values — decide(container_started_at, session_started_at, elapsed_ms, budget_ms). The incident that cost me a day is a unit test with the real timestamps,
    no mocks, no Docker, milliseconds to run. If the live container started after the
    session’s exec, the marker is provably gone — give up now, don’t poll for it.

Full write-up with the code:
https://t0ha.dev/en/elixir/devops/2026/09/04/supervising-what-you-dont-own.html

Have you ended up writing your own restart strategy for work that lives outside the
BEAM? I’m curious how you bounded the waits.

Where Next?

Popular Backend topics Top

lpil
Shayne gave this excellent talk the other day on Gleam, so I thought I’d share it. From my point of view it was really interesting to se...
New
New
First poster: bot
We all know how to teach recursion. We’ve done it for decades. We pick some honored, time-tested examples—Fibonacci numbers and factorial...
New
First poster: AstonJ
Ten years without Elixir. I never got into Elixir, largely because it looked like Ruby. I was a Rubyist for a good while, spent time and...
New
First poster: bot
It’s easy to view yourself as “not a real programmer.” There are programs out there that everyone uses, and it’s easy to put their develo...
/c
New
paulanthonywilson
Post on using UDP multicasting with Elixir to broadcast presence, and listen for peers, on a local network. I have found this approach us...
New
First poster: bot
Just a small test with lists in cython. Considering echosystem, multithreading and ease of use, Julia is a clear winner here.
New
wolf4earth
Charles Max Wood takes the lead this week. He and Adi Iyengar discuss what Top End Devs are and what people should be doing to become Top...
New
MarcinKasprowicz
Elixir language viewed from the perspective of a JavaScript developer. I compared selected aspects of the two languages and touched on to...
New
penelopa
Learn how set up an RTMP server for free using the open-source Red5 software. This tutorial covers all steps from downloading the code fr...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
PragmaticBookshelf
Free and open source software is the default choice for the technologies that run our world, and it’s built and maintained by people like...
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
PragmaticBookshelf
From finance to artificial intelligence, genetic algorithms are a powerful tool with a wide array of applications. But you don't need an ...
New
PragmaticBookshelf
Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Programming Ruby is the most complete book on Ruby, covering both the language itself and the standard library as well as commonly used t...
New
PragmaticBookshelf
A concise guide to MySQL 9 database administration, covering fundamental concepts, techniques, and best practices. Neil Smyth MySQL...
New
PragmaticBookshelf
Write elegant Ruby code—not just correct, but idiomatic. Go beyond the vocabulary and syntax and learn to express yourself with eloquence...
New