Skip to content

fix(os): stop guest agent restarts from restarting the app - #1687

Open
kvinwang wants to merge 1 commit into
nextfrom
fix/app-compose-agent-restart
Open

kvinwang wants to merge 1 commit into
nextfrom
fix/app-compose-agent-restart

Conversation

@kvinwang

@kvinwang kvinwang commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Since #1324, app-compose.service has Requires=dstack-guest-agent.service. Requires= also propagates restarts: when the agent dies and Restart=always brings it back (crash or watchdog kill), systemd restarts app-compose.service too. Its ExecStop runs compose stop, so every agent restart stops all app containers and brings them back with compose up (followed by an image/volume prune). A manual systemctl restart dstack-guest-agent does the same.

#1625 fixed the watchdog probe race that was killing the agent on 0.6.5 guests. This PR removes the coupling, so an agent restart for any other reason no longer takes the app down with it.

Affected: v0.5.12+ and v0.6.0+.

Fix

Add dstack-guest-agent-wait.service, a oneshot that polls until the agent is active and gives up once it is failed or after 300s (reported through OnFailure=). app-compose, docker and containerd Require= it instead of the agent. It only Wants= the agent and has no Restart=, so agent restarts stop there. Like network-online.target, it marks that the agent came up during boot, not that it is up now.

  • Polling is needed because After= is satisfied by the agent's first failed attempt even when Restart= brings it up later.
  • The poll moves out of docker's drop-in, which had it already.
  • containerd now waits too: it starts the nerdctl-compose runner's restart-policy containers before app-compose runs, and nothing held it back before.

Alternatives that do not work:

  • RestartMode=direct on the agent stops the propagation on systemd 257 but not on 255, and does not cover a manual restart.
  • A target driven by the agent: with Wants=/Before= it is reached after the agent's first failed attempt; with Requires= on the agent it propagates restarts again.

Verification

Mock units on systemd 255 (Ubuntu): agent Type=notify, Restart=always; wait unit as in this PR; mock containerd, docker and app wired as in this PR, each logging whether the agent was active when it started.

Scenario Result
Agent killed with systemctl kill -s KILL containerd, docker and app untouched
systemctl restart agent containerd, docker and app untouched
Agent fails its first attempt, succeeds on retry all three start after the agent is up
Agent always exits 1 (hits start limit) none start, OnFailure= fires
Agent crashes after 3s each time (never hits start limit) wait unit times out, none start, OnFailure= fires
docker started on its own (e.g. socket activation) waits for the agent first

With the old Requires=, the kill case stops and restarts the app on both systemd 255 and 257 (debian:trixie).

I have not tested this on a real CVM image.

Requires=dstack-guest-agent.service on app-compose propagates restarts,
so every agent restart (crash, watchdog kill, manual restart) ran
app-compose's ExecStop and stopped all app containers.

Add dstack-guest-agent-wait.service, a oneshot that polls until the
agent is active, giving up once it is failed or after 300s. app-compose,
docker and containerd Require= it instead of the agent. It has no
Restart= and only Wants= the agent, so agent restarts stop there. Like
network-online.target, it marks that the agent came up during boot.

Polling is needed because After= is satisfied by the agent's first
failed attempt even when Restart= brings it up later. The poll moves
out of docker's drop-in. containerd now waits too: it starts
restart-policy containers of the nerdctl-compose runner before
app-compose runs, and nothing held it back before.

Signed-off-by: Kevin Wang <[email protected]>
@kvinwang
kvinwang force-pushed the fix/app-compose-agent-restart branch from 6bc4b95 to 5bc8928 Compare December 1, 2026 03:21
@kvinwang kvinwang changed the title fix(os): keep app containers running across guest agent restarts fix(os): stop guest agent restarts from restarting the app Dec 1, 2026

This branch has not been deployed

No deployments
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