T0ha666
Docker Swarm assumes containers are interchangeable — an agent session is a stateful 40-minute pin
I run AI coding agents on a Docker Swarm cluster, and one afternoon a 40-minute
agent run exited 0 and lost 100% of its output. The poll loop saw ExitCode 0 and
reported success, while an intermediary had severed the idle stdout stream.
--output-format json prints nothing until the very end, so the buffer was
empty and parsing it errored the task with “empty output”. The identical
3-minute planning run on the same code path was fine. Duration-dependent data
loss, with no error anywhere in the logs.
That incident is what the post is about, but the real subject is one mismatch:
Swarm assumes containers are interchangeable, and an agent session is a stateful
40-minute pin. Once I looked at the cluster through that lens, almost every
infrastructure bug of the last six months turned out to be the same assumption.
Exec was routed by Status.State, not DesiredState, so it happily attached to
a task Swarm had already given up on, while the reconciler in the same codebase
had been filtering on desired-state correctly all along. An amd64-only image
on a mixed ARM/x86 cluster with no placement constraint dies at exit 255 on
ARM; with MaxFailureRatio=0, FailureAction=pause, a paused start-first update
never runs its “stop the old container” step, and the stranded orphan went on to
hold every slot of a 25-connection managed Postgres with a leftover
POOL_SIZE=100. The correctly configured new container could not boot, and prod
crash-looped for five hours. Rebuilding the swarm regenerates the captain-salt,
which in one move locks you out of the dashboard (the stored hash no longer
verifies), breaks the encrypted registry credentials (403 denied on every pull,
looks exactly like an expired token), and wipes the node labels the runners are
pinned to (0/1 Pending, “no suitable node”).
Two more Elixir-specific notes. The raw Docker API will not resolve a bare tag
to a digest (only the CLI does, client-side), so the app resolves ghcr
manifests itself with Req (401, parse WWW-Authenticate, fetch the token, read
Docker-Content-Digest), because the socket-proxy blocks /distribution. And the
whole thing is held together from Elixir, so every one of these workarounds is
plain application code, not a shell script.
The fix for the lost output: every agent invocation now tees to a file inside
the container, and the app fetches that file after exit. The stream is a
nice-to-have for live UI, the file is the truth. The closing rules: bound every
wait, never keep your only copy in a stream, and assume you will not finish in
the container you started in.
Full write-up with the code:
If you run long stateful jobs on Swarm, how do you pin them, and where do you
keep their output so a severed stream cannot lose it?
Popular Backend topics
Other popular topics
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /java
- /clojure
- /typescript
- /emacs
- /haskell
- /svelte
- /onivim
- /kotlin
- /react
- /c-plus-plus
- /crystal
- /tailwind
- /gleam
- /ocaml
- /elm
- /vscode
- /flutter
- /html
- /ash
- /deepseek
- /zig
- /opensuse
- /php
- /centos
- /react-native
- /scala
- /lisp
- /textmate
- /sublime-text
- /nixos
- /debian
- /agda
- /deno
- /django
- /nodejs
- /kubuntu
- /arch-linux
- /ubuntu
- /spring
- /revery
- /manjaro
- /quarkus
- /julia
- /diversity
- /lua
- /laravel









