Repository navigation
[FD-5916] fix(agents): a clocked agent's container exits when its server dies - #862
Merged
earakely-scale merged 1 commit intoNov 21, 2026
Merged
Conversation
…ver dies Before the clock work the A2A server was the agent container's main process, so when it died the container exited and the run failed fast. The clocked claude-code and opencode images run root's supervisord as PID 1 with [program:agent] autorestart=true, so a crashed server was restarted in place: the dead server's CLI kept writing, and the new server had lost its env MCP servers, config, peers and running tasks, so prompt_agent polled "Task not found" until its timeout. Each image's root.conf now never restarts the server (autorestart=false, startretries=0) and adds [eventlistener:agent-exit], a POSIX sh listener on PROCESS_STATE_EXITED and PROCESS_STATE_FATAL that sends SIGTERM to supervisord when the program is "agent". supervisord then stops the follower and the egress proxy and exits, and the container with it. The follower and the proxy keep their own restart policy. supervisord exits 0 however it stops. The unit test pins it per clocked image: the server's autorestart and startretries, the follower's and the proxy's restart, and the listener run as supervisord runs it under a stand-in parent that counts the SIGTERMs it gets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 21, 2026
earakely-scale
deleted the
edgararakelyan/agent-container-exits-with-server
branch
November 21, 2026 06:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Before the clock work, an agent container's main process was its A2A server: when the server died, the container exited and
prompt_agentgave up within about 60 s. The clocked images run root's supervisord as PID 1 instead, with[program:agent] autorestart=true, so supervisord restarted a crashed server in place. The dead server's CLI kept running and writing in its own session. The new server had lost everything it held in memory: the env's MCP servers, its config, its peers and its running tasks. Later turns then ran without the env's tools and nothing said so, andprompt_agentpolled "Task not found" until its full timeout.This puts back main's behaviour: when the server exits, the container exits.
What changes
The change is in the two clocked images on
main,claude-codeandopencode, each in its ownroot.conf. No shared file changes.[program:agent]now hasautorestart=falseandstartretries=0. Withoutstartretries=0, supervisord would still retry a server that dies in its first second.[eventlistener:agent-exit]listens forPROCESS_STATE_EXITEDandPROCESS_STATE_FATAL. It's a one-line POSIXshlistener that speaks supervisord's READY/RESULT protocol. When the program is exactlyagent, it writes one line to the container log and sends SIGTERM to supervisord (its parent). supervisord then stops the clock follower and the egress proxy and exits, and the container exits with it.autorestart=true. If either dies, it restarts in place and the container stays up.exited: agent (terminated by SIGKILL; not expected)and the listener writesthe A2A server exited (...): stopping the container.The five open clock PRs (#765 #768 #769 #770 #771) are getting the same
root.confchange for their images. The new tests run for every image whoseshared_sources.tomltakes the clock, so they will also check those five images once they merge.Neither image had an orphan-CLI sweep at startup, so there is no dead code to remove. Their lifespan's
kill_running_clis, which runs on a graceful stop, stays.Testing
Unit (
tst/unit/agents/test_agent_clock_images.py, run for each clocked image):autorestart=falseandstartretries=0, and the follower's and the proxy'sautorestart=true.root.confis read the way supervisord reads it, with;and#inline comments, and the_programhelper now uses the same reader.commandis split withshlex, under a stand-in parent that speaks supervisord's side of the protocol and counts the SIGTERMs it gets. Events forclock(EXITED),egress(FATAL) andagent-exit(EXITED) cause no SIGTERM. Events foragent(EXITED and FATAL) cause one each.autorestart=true, a listener that filters onclock, a looser*processname:agent*match (it would also matchagent-exit), and dropping FATAL fromevents.tst/unit/agents: 1172 passed on the VM (Linux). ruff is clean.supervisord 4.2.5 on the Mac, with claude-code's
root.confand its programs replaced bysleep:VM (x86_64, local Docker, a stand-in model, both images built from this branch, 10 runs):
kill -915 s into turn 2, clock armed at +75 d: time until the container exitedprompt_agentreported turn 2 failed (AgentUnreachableError: ... stopped answering: 5 polls in a row over 60s), measured from the killclaude -p) and its tool, mid-turn at the kill, were gone; no process left on the host;/appheld turn 1's writes only and was unchanged 75 s lateropencode runand its toolagent_clock)kill -9, then the egress proxydocker stopA2A_PORT=notaport,docker run)restarts=0, exit 0For (a), main before the clock work took about 60 s. That's
prompt_agent's own rule for an agent that stops answering (5 polls in a row over 60 s), and it now applies again. Before this change, a clocked image restarted the server, soprompt_agentkept polling until the step's timeout.Limits
prompt_agentstill takes its own ~60 s to give up on an agent that has stopped answering, as on main before the clock work. The container itself exits within about 2 s of the server.run.shruns uvicorn alone) and an image started as a non-root user (entrypoint.sh, the server alone) have no supervisord, and when their server dies their process exits, as before.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Both clocked agent images now stop the container when the A2A server exits, rather than restart a server that has lost its in-memory state.
earakely-scaleexplicitly acknowledges that crashes still produce container exit status 0 becausesupervisordexits that way; this is an intentional limit.Review used source inspection. No tests were run during this review.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[A2A server stops] --> B[Supervisor emits EXITED or FATAL] B --> C[Listener matches agent] C --> D[Listener sends SIGTERM to supervisord] D --> E[Supervisord stops its programs and exits] E --> F[Container exits] G[Clock or proxy stops] --> H[Supervisor restarts that helper]Reviews (1) · Last reviewed commit: "[FD-5916] fix(agents): a clocked agent's..." · Reviewed by Greptile