Skip to content

bug(agents): created containers get restart=no — a third of the fleet silently does not survive a host reboot #2541

Closed

Description

@AndriiPasternak31

This has happened before and the fix is already written. See Prior art — commit 5aaf5791d on the unmerged branch fix/agent-restart-policy fixes 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_policy

containers_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_dormant operator-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 behind dev, 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 to no, and a regression test test_create_sets_unless_stopped_restart_policy in tests/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 on origin/dev @ a5ac3cf37
  • OS: Ubuntu (ASUS host), Docker Engine, docker compose prod overlay
  • Affected: all agents created through create_agent since 2026-07-24

Reproduce

  1. Create an agent through the normal path (UI or create_agent).
  2. docker inspect -f '{{.HostConfig.RestartPolicy.Name}}' agent-<name> → no.
  3. Reboot the host (or systemctl restart docker).
  4. 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

  1. added
    priority-p1
    type-bug
    theme-reliability
    complexity-low
    on Sep 6, 2026
  2. added
    status-ready
    on Sep 6, 2026
  3. added
    status-in-progress
    and removed
    status-ready
    on Sep 7, 2026
  4. AndriiPasternak31 commented on Sep 7, 2026

    @AndriiPasternak31
    ContributorAuthor

    /claim — starting now. Landing the prior-art branch fix/agent-restart-policy (5aaf5791d, mine, 2026-07-24) rebased onto current dev, plus the recreate path: lifecycle.py carries the old container's RestartPolicy forward, so already-created restart=no agents stay broken until reconciled.

  5. github-actions commented on Sep 7, 2026

    @github-actions

    @AndriiPasternak31 This issue is already assigned to AndriiPasternak31. Use /unclaim first if you want to take over.

  6. added
    status-in-dev
    and removed
    status-in-progress
    on Sep 8, 2026
  7. removed
    status-in-dev
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

complexity-lowpriority-p1theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions