Repository navigation
Description
This has happened before and the fix is already written. See Prior art — commit
5aaf5791don the unmerged branchfix/agent-restart-policyfixes exactly this. The value of this issue is landing that branch, not re-deriving it.
What happened
An unplanned host power-off took the ASUS deployment down at 2026-09-04T20:34:59Z; it came back at 2026-09-06T02:03:21Z. Docker restored 11 of 19 agents. The other 8 stayed dead for ~42 hours, including marshal, the fleet conductor.
The split was exactly along the container restart policy:
restart=unless-stopped -> trinity-system, cleon, cornelius-oracle, oracle-3..8,
osint-agent, polymarket-vybe (11, all recovered)
restart=no -> marshal, receptionist, brier-hq, oracle-2-markets,
polymarket-andrii, pm, tms-implementer, tms-reviewer (8, all dead)
All 8 exited at the same instant with code 137 and HostConfig.RestartPolicy.Name=no.
Mechanism
create_agent's container call passes no restart_policy, so Docker applies its default of no:
# src/backend/services/agent_service/crud.py:2003
return await containers_run(
config.base_image,
detach=True,
name=f"agent-{config.name}",
...
log_config=AGENT_LOG_CONFIG,
network='trinity-agent-network',
mem_limit=config.resources['memory'],
nano_cpus=...,
) # <-- no restart_policycontainers_run (services/docker_utils.py:515) is a bare passthrough to docker_client.containers.run with no default of its own, and system_agent_service.py:493 is the only site in the backend that sets unless-stopped — for trinity-system alone.
The recreate path does not correct it either; it carries the old container's policy forward, so no is sticky across every subsequent recreate:
# src/backend/services/agent_service/lifecycle.py
1087: restart_policy = old_host_config.get("RestartPolicy") or {}
1371: **({"restart_policy": restart_policy} if (restart_policy or {}).get("Name") else {}),That preserve-on-recreate behavior is also why the fleet was split rather than uniformly broken: the 11 healthy agents are carrying forward a manual docker update mitigation applied during the previous occurrence (see below), while every agent created after that point was born no.
Impact
The scheduler kept dispatching into dead containers for the full 42 hours and fast-failing:
marshal 48 failed "Agent unreachable — transport circuit breaker open"
polymarket-andrii 9 failed
oracle-2-markets 3 failed
brier-hq 2 failed
tms-implementer 2 failed
tms-reviewer 2 failed
pm 1 failed
marshal alone lost ~168 fleet-poll runs (*/15 * * * *) and 2 fleet-brief runs; 17 enabled schedules across the 5 agents that never self-recovered were dark the whole time.
What already protects us
Stated so this is not over-fixed:
- Each dead agent raised a
circuit_breaker_dormantoperator-queue alert, and they self-cleared once the agents came back. - Fleet health correctly reported the 5 remaining agents as
critical.
So detection exists — but it is per-agent and mis-framed. Eight separate "circuit breaker DORMANT" alerts read as a transport problem with individual agents, not as "the host rebooted and a third of the fleet is gone." Nothing correlates them into the one fact that matters, and nothing recovers them.
Prior art
This is the second occurrence. The first was 2026-07-23 (fleet dark ~10h), and the fix was written the next day but never merged:
- Commit
5aaf5791d— "agents: born with restart_policy=unless-stopped (survive reboot)", 2026-07-24 - Branch
fix/agent-restart-policy— never opened as a PR; now 671 commits behinddev, 1 ahead - Diff is 3 files / 22 lines:
restart_policy={"Name": "unless-stopped"}in the create path, the same re-baked on the recreate path so a config update cannot silently drop back tono, and a regression testtest_create_sets_unless_stopped_restart_policyintests/unit/test_1484_create_agent_characterization.py(fails without the fix:KeyError 'restart_policy')
Both prior and current incidents were mitigated the same way — docker update --restart unless-stopped on the live fleet — which does not survive a container recreate.
Current origin/dev still has the bug: the create path is unchanged, and dev's copy of the characterization test contains no restart_policy assertion.
Recommendation
Rebase 5aaf5791d onto dev and land it. Note the recreate path has since gained the conditional pass-through at lifecycle.py:1371 (from #1816), so the re-bake there should be reconciled with that rather than applied blindly — an unconditional set is still correct, since preserving a no inherited from a pre-fix container is never what an always-on agent wants.
Use unless-stopped, not always, so a deliberately stopped agent stays stopped across a reboot.
A one-off reconciliation is also needed for existing deployments, since the create-path fix only affects newly created containers: docker update --restart unless-stopped for any agent container still on no.
Environment
- Trinity version:
0.9.0(ASUS deployment); bug confirmed present onorigin/dev@a5ac3cf37 - OS: Ubuntu (ASUS host), Docker Engine,
docker composeprod overlay - Affected: all agents created through
create_agentsince 2026-07-24
Reproduce
- Create an agent through the normal path (UI or
create_agent). docker inspect -f '{{.HostConfig.RestartPolicy.Name}}' agent-<name>→no.- Reboot the host (or
systemctl restart docker). - The agent stays
Exited(137)and never returns; its schedules fast-fail with "Agent unreachable — transport circuit breaker open".
Expected: the agent restarts with the daemon, as trinity-system does.
Census across a fleet:
for c in $(docker ps -a --format '{{.Names}}' | grep '^agent-'); do
docker inspect -f '{{.Name}} {{.HostConfig.RestartPolicy.Name}}' $c
done
Activity
AndriiPasternak31 commentedon Sep 7, 2026
/claim — starting now. Landing the prior-art branch
fix/agent-restart-policy(5aaf5791d, mine, 2026-07-24) rebased onto currentdev, plus the recreate path:lifecycle.pycarries the old container'sRestartPolicyforward, so already-createdrestart=noagents stay broken until reconciled.github-actions commentedon Sep 7, 2026
@AndriiPasternak31 This issue is already assigned to AndriiPasternak31. Use
/unclaimfirst if you want to take over.fix(agents): agent containers are born unless-stopped (#2541) (#2591)