What the agent does
The agent starts by finding out which services have a policy and which do not. In a repository like docker/awesome-compose there are thirty-nine Compose files, one per sample and all but two named compose.yaml, and twenty-six of them already set restart:, almost always always, with a handful of unless-stopped, two on-failure and one explicit "no". Thirteen samples set nothing at all: angular, apache-php, django, elasticsearch-logstash-kibana, flask, flask-redis, minecraft, nginx-flask-mongo, nginx-golang, react-nginx, sparkjava, traefik-golang and vuejs. The agent lists exactly those, with every service in each, before changing anything, because a policy that is missing on elasticsearch matters more than one missing on a one-off dev container.
It then picks a policy per service rather than one for all. Long-running infrastructure that other services depend on gets unless-stopped: elasticsearch, logstash and kibana in the ELK sample, mongo in nginx-flask-mongo, redis in flask-redis, the traefik:2.6 front end in traefik-golang and the itzg/minecraft-server game server that already carries a memory limit under deploy.resources. Application containers built from a Dockerfile with target: builder and a bind-mounted source tree, such as the web service in angular, vuejs, django, flask and apache-php, are development servers that a person starts and stops, so they get on-failure so that a crash comes back but docker compose stop stays stopped. The agent writes the reason for each choice into the pull request so a reviewer can disagree per service.
Two details in these files change what a policy means. flask and flask-redis set stop_signal: SIGINT because Flask needs it to stop cleanly; a restart policy does not interfere with that, and the agent keeps the comment that explains it. Services with depends_on but no condition, like web on backend on mongo in nginx-flask-mongo, will restart independently of their dependencies, and the agent notes where a healthcheck plus condition: service_healthy, the pattern nginx-golang-mysql already uses for its database, would make the restart useful. It does not add health checks here; that is a separate change.
Validation is Compose's own parser. The sandbox has no Docker, so the agent installs it with sudo apt-get install -y docker.io and starts dockerd; that package carries docker-compose v1 rather than docker compose v2, so it fetches the v2 plugin binary for docker compose config, then runs docker compose -f <sample>/compose.yaml config on each changed file to show the rendered policy and prove the YAML still parses. It brings one small sample up, flask-redis, kills the web container and shows docker compose ps reporting it running again, then takes it down.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add restart policies to the Docker Compose services in this repository that have none. Read every compose.yaml first and list the samples and services without a restart policy before editing. Give databases, caches, brokers, proxies and long-running servers unless-stopped, and development servers built with a builder target and a bind-mounted source on-failure, and keep every existing policy, comment and stop_signal as it is. Write the reason per service in the pull request and note where a healthcheck with depends_on condition would make the policy more useful, without adding health checks. Install Docker in the sandbox and run docker compose config on every changed file; bring up one small sample, kill its application container, show it restarted, and take it down. Open a pull request.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
What comes back is a pull request on its own branch that edits only the compose.yaml files that lacked a policy, one restart: line per service and nothing else: no reordering of keys, no reformatting, the existing comments kept. The samples that already set always or unless-stopped are not touched, and the description has a table of every changed service with its new policy and the one-line reason.
Under the table is the docker compose config output for each changed file, which proves the files parse and shows the policy where Compose put it, and the docker compose ps lines from the one sample the agent brought up before and after killing its container. The transcript at GET /o/{org}/sessions/{id}/messages keeps every command with its output, the Docker install included.
Before merging, a reviewer reads the per-service reasons and changes any policy they disagree with, decides whether the development samples should get a policy at all, and whether the health-check notes should become a follow-up issue. A follow-up message to the same session can add those health checks, or switch the chosen development services to unless-stopped.
Run it on every Compose repository you keep
A platform team that owns several repositories with Compose files starts one run per repository with one POST /o/{org}/sessions each, that repository in resources and this prompt as input. Each run clones through the GitHub App installation that covers it, installs Docker in its own sandbox and opens its own pull request, so the policy lands in every repository the same day.
A key may have at most max_concurrent runs in progress at once, four by default, so a script over more Compose repositories than that just sends them all: each extra run is created with 202 and status: "queued" and starts as a slot frees. Send a request_id, one UUID per repository, so a retried call returns the run it already started instead of opening a second pull request.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
The hard part of this change is not the YAML, it is reading dozens of files and deciding per service, then proving the files still parse. Running Compose on a laptop against thirteen samples means pulling images you do not want, and the one real check, that a killed container comes back, needs a daemon. The agent does all of that in a sandbox of its own, installs Docker there, and keeps the output.
The pull request carries the per-service table and the docker compose config output, so the review is a read of one line per service. Several repositories can be handled at once, each in its own sandbox with its own pull request, and the laptop stays free.
Frequently asked questions
Why not just set restart: always everywhere?
Because always brings a container back even after docker compose stop and after a host reboot, which is wrong for a development server someone started by hand. The agent uses unless-stopped for infrastructure and on-failure for development servers, and the pull request explains each choice so you can change it per service.
Will it touch services that already have a policy?
No. The twenty-six samples that already set restart: are left exactly as they are, including the one that sets it to "no" on purpose. Only services with no policy get a line, and only that line is added.
Does the sandbox have Docker?
Not by default. The agent installs it with sudo apt-get install -y docker.io and starts dockerd itself, and because that package ships docker-compose v1, it fetches the Compose v2 plugin so that docker compose config matches what the samples' READMEs tell people to run.
Does a restart policy fix a service that starts before its database is ready?
Not by itself. A restarting container does not wait for its dependencies unless depends_on has a condition and the dependency has a healthcheck, as nginx-golang-mysql already does for its database. The pull request points out each place where that would help, and a follow-up message can add it.