Skip to content

[FD-5916] fix(agents): a clocked agent's container exits when its server dies - #862

Merged
earakely-scale merged 1 commit into
mainfrom
edgararakelyan/agent-container-exits-with-server
Nov 21, 2026
Merged

earakely-scale merged 1 commit into
mainfrom
edgararakelyan/agent-container-exits-with-server

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Before the clock work, an agent container's main process was its A2A server: when the server died, the container exited and prompt_agent gave 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, and prompt_agent polled "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-code and opencode, each in its own root.conf. No shared file changes.

  • [program:agent] now has autorestart=false and startretries=0. Without startretries=0, supervisord would still retry a server that dies in its first second.
  • A new [eventlistener:agent-exit] listens for PROCESS_STATE_EXITED and PROCESS_STATE_FATAL. It's a one-line POSIX sh listener that speaks supervisord's READY/RESULT protocol. When the program is exactly agent, 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.
  • The clock follower and the egress proxy keep autorestart=true. If either dies, it restarts in place and the container stays up.
  • A normal stop works as before. supervisord moves the server to STOPPED, not EXITED, so the listener does nothing.
  • Exit status: 0, after a crash or a stop alike. supervisord 4.2.5 exits 0 however it stops and gives no way to set the status. The only way to get a non-zero status would be a wrapper shell as PID 1 that forwards signals, and this PR doesn't add one. The container log tells a crash from a stop: supervisord writes exited: agent (terminated by SIGKILL; not expected) and the listener writes the A2A server exited (...): stopping the container.

The five open clock PRs (#765 #768 #769 #770 #771) are getting the same root.conf change for their images. The new tests run for every image whose shared_sources.toml takes 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):

  • The server's autorestart=false and startretries=0, and the follower's and the proxy's autorestart=true. root.conf is read the way supervisord reads it, with ; and # inline comments, and the _program helper now uses the same reader.
  • The listener is run the way supervisord runs it: its command is split with shlex, under a stand-in parent that speaks supervisord's side of the protocol and counts the SIGTERMs it gets. Events for clock (EXITED), egress (FATAL) and agent-exit (EXITED) cause no SIGTERM. Events for agent (EXITED and FATAL) cause one each.
  • Mutation checks: each of these makes a test fail: autorestart=true, a listener that filters on clock, a looser *processname:agent* match (it would also match agent-exit), and dropping FATAL from events.
  • tst/unit/agents: 1172 passed on the VM (Linux). ruff is clean.

supervisord 4.2.5 on the Mac, with claude-code's root.conf and its programs replaced by sleep:

  • The follower killed: it restarts and supervisord stays up.
  • The server killed: supervisord exits 0 about 1 s later.
  • A server that fails at once: FATAL, no retry, then supervisord exits.
  • SIGTERM: a normal stop, with no listener line.

VM (x86_64, local Docker, a stand-in model, both images built from this branch, 10 runs):

Case claude-code opencode
(a) the server killed with kill -9 15 s into turn 2, clock armed at +75 d: time until the container exited 1.21 s 2.36 s
(a) the same with the clock off 2.22 s 1.40 s
(a) time until prompt_agent reported turn 2 failed (AgentUnreachableError: ... stopped answering: 5 polls in a row over 60s), measured from the kill 59.1 s / 59.0 s 59.0 s / 59.1 s
(a) after the exit exit 0; the CLI (claude -p) and its tool, mid-turn at the kill, were gone; no process left on the host; /app held turn 1's writes only and was unchanged 75 s later the same, with opencode run and its tool
(b) two turns with the clock off turn 2 had turn 1 in its history; shell date was real the same
(b) two turns with the clock opted in (agent_clock) turn 2 had turn 1 in its history; shell date was 2027-02-04 the same
(c) the follower killed with kill -9, then the egress proxy each restarted with a new pid; the container stayed up; the agent's user still read 2027-02-04; turn 2 worked the same
(d) docker stop 1.19 s, exit 0, no listener line 2.32 s, exit 0, no listener line
A server that fails at once (A2A_PORT=notaport, docker run) FATAL after one try (exit status 2); the container exited, restarts=0, exit 0 the same

For (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, so prompt_agent kept polling until the step's timeout.

Limits

  • prompt_agent still 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.
  • The exit status is 0 after a crash (see above).
  • Run on local Docker only. The VM had no Modal keys for this round. Modal ends a sandbox when its command exits, and supervisord is that command, but this wasn't run there.
  • Unchanged by this PR: install mode (run.sh runs 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

RetriggerView in GreptileConfidence 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.

  • A crashed clocked A2A server now stops its container.

earakely-scale explicitly acknowledges that crashes still produce container exit status 0 because supervisord exits 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]
Loading

Reviews (1) · Last reviewed commit: "[FD-5916] fix(agents): a clocked agent's..." · Reviewed by Greptile

…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>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 21, 2026 04:27
@earakely-scale
earakely-scale merged commit fe1454a into main Nov 21, 2026
61 of 63 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/agent-container-exits-with-server branch November 21, 2026 06:15
earakely-scale added a commit that referenced this pull request Nov 21, 2026
…s the container, as #862 has it (#866)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant