Skip to content

Handle graceful termination in gvisor ateom - #764

Merged
Benjamin Elder (BenTheElder) merged 4 commits into
agent-substrate:mainfrom
sfunkenhauser:ateom_gt_gvisor
Aug 11, 2026
Merged

Benjamin Elder (BenTheElder) merged 4 commits into
agent-substrate:mainfrom
sfunkenhauser:ateom_gt_gvisor

Conversation

@sfunkenhauser

Copy link
Copy Markdown
Collaborator

Part of #23

Trap SIGTERM in the ateom, and forward SIGTERM to all application containers.
Once all application containers exit, ateom will exit itself.

@sfunkenhauser
Scott Funkenhauser (sfunkenhauser) force-pushed the ateom_gt_gvisor branch 2 times, most recently from 2849b1d to 997cd04 Compare August 6, 2026 13:44

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review skill pass

[needs rebase as well, sorry, these files are high churn]

Comment thread demos/counter/counter.go Resolved
Comment thread cmd/ateom-gvisor/main.go Outdated
// If the wait completed because the container actually exited (but with an error),
// we shouldn't send SIGKILL.
if !errors.Is(err, context.DeadlineExceeded) && !errors.Is(err, context.Canceled) {
slog.InfoContext(ctx, "Container exited with error status", slog.String("container", name), slog.Any("err", err))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 should-fix 🟡 – A failed runsc wait is indistinguishable from a clean exit here. Any non-context error from cmdWait reaches this branch and returns nil, so gracefulShutdown logs "All application containers stopped" and ateom exits without ever sending SIGKILL.

That is correct for a container that exited with a non-zero status. It is wrong when the wait itself failed and the container is still running: a runsc error, a container name that no longer exists, or the spurious ECHILD that cmdWait maps to success at cmd/ateom-gvisor/runsc.go:388. In those cases the actor loses the remainder of its grace period to the kubelet's SIGKILL, which is the outcome this PR exists to prevent.

Consider having cmdWait return a typed error that separates "container exited" from "wait failed", and escalating to SIGKILL on the latter.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't true. A clean exit would not return an error and be handled above. Any error returned from runsc wait is a failure to wait on the process, not a non-zero container status code.

That being said we probably should be returning an error here instead of nil, not that it changes the current behavior, but it's more appropriate if we want to add retry logic later.

Comment thread cmd/ateom-gvisor/main.go
s.shuttingDown = true
session := s.activeSession
// Release the lock so that AteomService and respond to new RPCs.
s.lock.Unlock()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 should-fix 🟡 – Dropping the lock lets CheckpointWorkload run during drain, which is the stated intent, but the two paths are not coordinated. By the time a suspend arrives, killContainer has already sent SIGTERM to every application container, and it will send SIGKILL once workloadGracePeriod expires — including in the middle of an in-flight runsc checkpoint.

CheckpointWorkload clears activeSession at cmd/ateom-gvisor/main.go:674, but gracefulShutdown captured the session pointer above, so it goes on to signal containers that were just checkpointed. TestGracefulWorkerTerminationSuspend only exercises a suspend that completes well inside the grace period, so neither case is covered.

Consider having the checkpoint path cancel the kill timer, or re-checking activeSession in killContainer before escalating.

Separately, the comment on the line above reads "so that AteomService and respond to new RPCs" — presumably "can respond".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-setting the grace period during a checkpoint defeats the purpose. Even if we are checkpointing the container shouldn't be allowed to run for longer than the grace period.

Comment thread cmd/ateom-gvisor/main.go Resolved
Comment thread cmd/ateom-gvisor/runsc.go Resolved
@BenTheElder
Benjamin Elder (BenTheElder) merged commit 01b26e8 into agent-substrate:main Aug 11, 2026
13 of 15 checks passed
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.

2 participants