<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3" -->

---
title: Supervising What You Don't Own: A Controller Loop in OTP
description: A deploy killed OTP processes supervising AI coding agents but left their Docker Swarm containers running, leaving the database stuck showing a session as...
canonical: https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Supervising What You Don't Own: A Controller Loop in OTP | daily.dev
og:description: A deploy killed OTP processes supervising AI coding agents but left their Docker Swarm containers running, leaving the database stuck showing a session as...
og:url: https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3
og:image: https://api.daily.dev/og/posts/PAR6nwsl3.png
og:image:alt: Supervising What You Don't Own: A Controller Loop in OTP
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.

# Supervising What You Don't Own: A Controller Loop in OTP

**[ElixirStatus](https://daily.dev/sources/elixirstatus)** · 10 min read · 0 upvotes · 0 comments

## Summary

A deploy killed OTP processes supervising AI coding agents but left their Docker Swarm containers running, leaving the database stuck showing a session as 'running'. The fix is a Reconciler GenServer that ticks every 60 seconds, comparing the database's desired state against actual container state, similar to a Kubernetes controller loop. A pure 'decide' function checks if the container start time is after the session start time to detect replacement, falling back to a wall-clock timeout budget. Separating this decision logic from I/O made it testable with real incident timestamps in milliseconds, with no mocks or Docker required.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://t0ha.dev/en/elixir/devops/2026/09/04/supervising-what-you-dont-own.html>

## Questions this post answers

### How do you detect that a Docker container running a long task has been replaced since the task started?

Compare the container's start timestamp against the task's session start timestamp using DateTime.after?/2. If the container's start time comes after the session started, the original container (and any files written to its /tmp) is gone and the exec is provably unrecoverable. If either timestamp is missing, treat it as not replaced and keep polling, relying on a wall-clock timeout budget as backup.

_When reconciling process state against infrastructure you don't own, daily.dev surfaces more patterns like this for OTP and distributed systems._

### Why does OTP supervision fail to recover a process running inside an external Docker container after a deploy?

OTP supervisors only restart BEAM processes inside the VM; they cannot monitor a CLI running in a separate container, possibly on another machine, reached over a network through a proxy with no delivery guarantees. A deploy kills the GenServer watching the container but leaves the container itself running, so the database can show a session as 'running' indefinitely while nothing is actually watching it.

_Developers architecting OTP systems around external processes can track more lessons like this on daily.dev._

## Similar posts on daily.dev

- [Exploring OTP Patterns for Agentic Workflows](https://daily.dev/posts/exploring-otp-patterns-for-agentic-workflows-mxnghntup) · Erlang Solutions · 0 upvotes · 0 comments
- [Supervisors By Hand](https://daily.dev/posts/supervisors-by-hand-7fyabrefc) · ElixirStatus · 0 upvotes · 0 comments
- [The agent is not the system. Postgres is.](https://daily.dev/posts/the-agent-is-not-the-system-postgres-is--hqvmc46rn) · Planet PostgreSQL · 1 upvotes · 0 comments
- [Designing a Production-Ready Agent Harness With Persistence and Checkpointing](https://daily.dev/posts/designing-a-production-ready-agent-harness-with-persistence-and-checkpointing-4ygffqjsx) · SitePoint · 1 upvotes · 0 comments
- [Your agent loop is not a production system](https://daily.dev/posts/your-agent-loop-is-not-a-production-system-s0faarjcu) · LeadDev · 0 upvotes · 0 comments

---

Tags: [#authentication](https://daily.dev/tags/authentication), [#distributed-systems](https://daily.dev/tags/distributed-systems), [#elixir](https://daily.dev/tags/elixir), [#docker-swarm](https://daily.dev/tags/docker-swarm)

[View this post on daily.dev](https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3)

```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":"TechArticle","headline":"Supervising What You Don't Own: A Controller Loop in OTP","url":"https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3"},"datePublished":"2026-10-27T12:23:48.912Z","dateModified":"2026-10-27T12:24:18.951Z","description":"A deploy killed OTP processes supervising AI coding agents but left their Docker Swarm containers running, leaving the database stuck showing a session as...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6e3d9dc5a4f35fff533bc1a7617fb076?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/6e3d9dc5a4f35fff533bc1a7617fb076?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"ElixirStatus","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"ElixirStatus","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/22e4640538124187827caf8cc8e39190","url":"https://daily.dev/sources/elixirstatus"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"authentication,distributed-systems,elixir,docker-swarm","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"ElixirStatus","item":"https://daily.dev/sources/elixirstatus"},{"@type":"ListItem","position":3,"name":"Supervising What You Don't Own: A Controller Loop in OTP"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/supervising-what-you-don-t-own-a-controller-loop-in-otp-par6nwsl3#faq","mainEntity":[{"@type":"Question","name":"How do you detect that a Docker container running a long task has been replaced since the task started?","acceptedAnswer":{"@type":"Answer","text":"Compare the container's start timestamp against the task's session start timestamp using DateTime.after?/2. If the container's start time comes after the session started, the original container (and any files written to its /tmp) is gone and the exec is provably unrecoverable. If either timestamp is missing, treat it as not replaced and keep polling, relying on a wall-clock timeout budget as backup. When reconciling process state against infrastructure you don't own, daily.dev surfaces more patterns like this for OTP and distributed systems."}},{"@type":"Question","name":"Why does OTP supervision fail to recover a process running inside an external Docker container after a deploy?","acceptedAnswer":{"@type":"Answer","text":"OTP supervisors only restart BEAM processes inside the VM; they cannot monitor a CLI running in a separate container, possibly on another machine, reached over a network through a proxy with no delivery guarantees. A deploy kills the GenServer watching the container but leaves the container itself running, so the database can show a session as 'running' indefinitely while nothing is actually watching it. Developers architecting OTP systems around external processes can track more lessons like this on daily.dev."}}]}
```

