Skip to content

graceful termination for atelet - #748

Merged
Haven Xia (HavenXia) merged 1 commit into
agent-substrate:mainfrom
shrutiyam-glitch:issue-719
Aug 5, 2026
Merged

Haven Xia (HavenXia) merged 1 commit into
agent-substrate:mainfrom
shrutiyam-glitch:issue-719

Conversation

@shrutiyam-glitch

@shrutiyam-glitch Shrutiya Mohan (shrutiyam-glitch) commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it:

atelet previously had no SIGTERM handling — main() ended in a bare svr.Serve(lis), so any pod eviction, DaemonSet rollout, or node drain killed the process instantly, aborting in-flight Run/Checkpoint/Restore RPCs mid-execution.

This PR adopts the same graceful-shutdown pattern ate-api uses: on SIGTERM, mark not-ready, stop accepting new RPCs, let in-flight RPCs finish, and force-stop after a deadline.

  • cmd/atelet/main.go:
    • signal.NotifyContext (kept separate from the work ctx so in-flight RPCs aren't cancelled the moment SIGTERM arrives) + a local drainOnShutdown mirroring ateapi's: MarkNotReady → sleep --drain-delay → GracefulStop() → force Stop() after --drain-timeout. /readyz and /healthz are wired into the metrics server (serverboot.Readiness), so readiness and liveness diverge correctly during the drain.
    • Flags: --drain-delay (default 0s — atelet is dialed directly by pod IP, no route-drain window is needed) and --drain-timeout (default 5m — Checkpoint/Restore stream multi-GiB snapshots to object storage and
      can take minutes; force-cancelling one mid-upload crashes the actor).
  • manifests/ate-install/atelet.yaml: terminationGracePeriodSeconds: 330 (drain-delay + drain-timeout + slack — the sum must fit inside the grace period or the kubelet SIGKILLs mid-drain), the drain flags, and /readyz readiness + /healthz liveness probes.

Test Scenarios Considered:

In-flight at SIGTERM Force-stop (past timeout)
Idle n/a
Checkpoint (suspend, external) upload aborted → CRASHED (#362)
Pause (local checkpoint) aborted → crash
Restore (resume) RPC fails → ateapi retries
Run (cold boot) RPC fails → retried
Multiple concurrent RPCs one shared timeout; stragglers cut
New RPC during drain rejected Unavailable → ateapi retries

Testing:

  • Unit (cmd/atelet/main_test.go): a loopback gRPC server with a blocking handler holds an RPC in-flight across the drain.
    • TestDrainOnShutdownInFlightFinishes — in-flight RPC completes during GracefulStop; readiness flips to not-ready.
    • TestDrainOnShutdownForceStopsAfterTimeout — an RPC running past drain-timeout is force-cancelled by Stop().
  • Live on a kind cluster (hack/install-ate-kind.sh --deploy-atelet, then kubectl delete pod to deliver SIGTERM, with --drain-delay=25s temporarily set to make the window observable):
    • Steady state: /readyz=200, /healthz=200 (old build had no /readyz at all).
    • During drain:/readyz=503 while /healthz=200 for the whole window — NotReady but alive.
    • Log sequence in order, with the 25s drain-delay honored exactly: Shutdown signal received; draining → (+25s) Starting gRPC drain → Drain completed within deadline → Shutdown complete.

Which issue(s) this PR is related to:

Fixes #719
Required for System Upgrade flow (#473)

  • Tests pass
  • Appropriate changes to documentation are included in the PR

@HavenXia Haven Xia (HavenXia) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@HavenXia
Haven Xia (HavenXia) merged commit 90bd78a into agent-substrate:main Aug 5, 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.

Graceful shutdown for Atelet

2 participants