Skip to content

atelet: suspend actors on a draining image provider plugin - #4031

Draft
yuekui2 wants to merge 15 commits into
agent-substrate:mainfrom
yuekui2:ipp-upstream/8-drain
Draft

yuekui2 wants to merge 15 commits into
agent-substrate:mainfrom
yuekui2:ipp-upstream/8-drain

Conversation

@yuekui2

@yuekui2 yuekui2 commented Nov 20, 2026 •

Copy link
Copy Markdown

Part of #4023. Includes #4030. This PR's commit is from Nov 19, as first reviewed, the next commit has the review fixes for the whole stack, and the last commit follows the revised plugin API (ai-on-gke/image-provider-plugin#1). To see the final code, use Files changed.

Blocked on ai-on-gke/image-provider-plugin v0.1.0, which needs the API (ai-on-gke/image-provider-plugin#1) and the client. go-modules and licenses fail until it is tagged. The module is vendored, so build and tests run.

When the plugin reports it is draining, atelet suspends the actors that hold
its leases, so the plugin can exit without pulling layers from under running
actors. When a reconcile reports a lease lost that an overlay spec records,
atelet suspends the actor that holds it, and asks again at the next
reconcile if the lease is still lost.

Testing: go test -race ./cmd/atelet/....

I used an AI agent to port these commits from our fork, address review comments, and draft this description. I reviewed the code and commit messages.

Comment thread cmd/atelet/imageprovider_reconcile.go Outdated
if asked {
continue
}
wg.Go(func() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This starts a suspend, so a checkpoint and upload, for every streamed actor on the node at the same time. Can we bound it, e.g. an errgroup with SetLimit like the stats sweep uses? Otherwise a plugin rollout on a dense node checkpoints everything in parallel.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. Suspends now go through a pool of drainSuspendConcurrency (4) slots.

Comment thread cmd/atelet/imageprovider_reconcile.go Outdated
Actor: &ateapi.ObjectRef{Atespace: sample.GetAtespace(), Name: sample.GetActorName()},
ActorUid: actorUID,
})
if err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens when the control plane keeps refusing this actor, e.g. with FailedPrecondition? It looks like we re-request it every 2s, with a warn each time, for as long as the plugin drains. Could we back off per actor, or skip the retry on FailedPrecondition/NotFound?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

NotFound isn't retried. Other refusals back off per actor, 2s up to 1m, with a warn on the first failure and when the backoff hits the cap.

Comment thread cmd/atelet/imageprovider_reconcile.go Outdated
s.refreshProviderAuth(ctx, actorsDir)
lastRefresh = time.Now()
}
if info != nil && s.imageProviderDraining(ctx) && s.drainSuspending.CompareAndSwap(false, true) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Have you considered dropping the drainSuspending CAS and having each tick enqueue the actors not already in drainSuspended into a bounded pool? That would bound the fan-out and let failed or new actors get picked up on the next tick, with one guard instead of two.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. Each tick starts the actors that are due into the bounded pool. The CAS is gone.

Comment thread cmd/atelet/imageprovider_reconcile.go Outdated
// Suspends can take minutes; the monitor keeps reconciling and
// refreshing meanwhile.
go func() {
defer s.drainSuspending.Store(false)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The CAS stays held until every suspend in the sweep returns, so one slow checkpoint (up to 10m) delays the retry of the ones that failed fast, and of actors that took a lease after the sweep started. Does that fit within the plugin's termination grace period?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

A slow suspend now only holds its slot, so retries and newly leased actors start on the next tick. Timing: suspend timeout 10m, plugin drain timeout 30m, grace period 60m.

Comment thread cmd/atelet/imageprovider_reconcile.go Outdated
if _, err := os.Stat(workerSocketPath(podUID)); err != nil {
continue
}
worker, err := s.dialWorker(ctx, podUID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is the same worker walk as statspoller.collect, but serial and without the bound on the dial. Have you considered sharing a helper between the two, maybe as a follow-up?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed. Tracking it in #4105. This PR puts one statsRPCTimeout over the dial and the call, as collect does.

yuekui2 added a commit to yuekui2/substrate that referenced this pull request Nov 24, 2026
yuekui2 added a commit to yuekui2/substrate that referenced this pull request Nov 24, 2026
yuekui2 added a commit to yuekui2/substrate that referenced this pull request Nov 24, 2026
yuekui2 added a commit to yuekui2/substrate that referenced this pull request Nov 24, 2026
CachedImage returns a digest-pinned image that is complete in the store
without contacting the registry, and nil otherwise. A caller can then
serve such images locally and send the rest elsewhere.
An image provider plugin will prepare some images' layers under a lease
that atelet must release on checkpoint and terminate, also after an
atelet restart. The overlay spec now records the image ref and the
plugin's lease ID, for the rootfs and for each image volume.
Image.LeaseID carries the lease from the image lookup.
The worker derived each lowerdir as <layer>/fs, so only Store layers
could be mounted. The overlay spec now records each image's lowerdirs,
and its Store layers when it came from the Store. The worker mounts
the lowerdirs as they are, and finalizes and repairs only the Store
layers. GC roots only Store layers.

Image.ProviderDirs holds lowerdirs that an image provider plugin
returns. ReadFile reads such lowerdirs directly and treats 0:0
character devices as whiteouts. It cannot see their opaque dirs, since
reading trusted.* xattrs needs CAP_SYS_ADMIN.

A spec without lowerdirs stays at version 1, so older workers still
read it. A spec with lowerdirs is version 2, which older workers
reject. atelet writes only Store images for now, so it still writes
version 1.
atelet will ask an image provider plugin to prepare image layers and fall
back to the image cache when the plugin declines or fails, and will
refresh the registry credentials of plugin leases. Add the
ate.imageprovider.requests counter and the ate.imageprovider.duration
histogram, labeled by provider and outcome, and the
ate.imageprovider.auth_refresh.failures counter, labeled by provider, to
the registry, ateattr, atelet's instruments and the observability guide.
atelet will talk to image provider plugins through the client in
github.com/ai-on-gke/image-provider-plugin. Require v0.1.0 and vendor
its API package.

RegistryAuth carries registry credentials, so protoredact_test lists the
imageprovider proto and pins its debug_redact fields.
A node can run an image provider plugin that prepares image layers
itself, for example by lazy loading them. atelet now asks the plugin
behind --image-provider-socket for each container and image volume
image, and pulls into the image cache when the plugin declines or fails.
Digest refs already in the cache skip the plugin.

atelet names each lease after the actor, the container and, for an image
volume, the volume. The overlay spec records the image ref, the lease ID
and the plugin's directories as lowerdirs, so a plugin image gets a
version 2 spec. A failed bundle prepare releases the leases it took. A
failed PrepareImage releases its lease without a digest, since the
plugin may have taken it. Each request records
ate.imageprovider.requests and ate.imageprovider.duration.
atelet looks for the node's image provider plugin at
/run/ate/image-provider.sock, the --image-provider-socket default.
Mount the node's /run/ate into atelet so it can reach the socket.
Document --image-provider-socket, the fallback to the image cache, how
atelet releases, reconciles and refreshes leases, and the suspend of
actors while the plugin drains. Link to the plugin repository for the
API.
The plugin was on whenever its socket existed. It is a preview feature,
so atelet now prepares images through it only when the
ImageProviderPlugin preview gate is on. With the gate off, atelet pulls
every image into the image cache and takes no new plugin leases. It
still releases, reconciles and refreshes the leases its actors hold, and
suspends them when the plugin drains.

ateworker needs no gate. Its version 2 overlay spec reader only runs for
specs that a gated atelet writes. The guide says to turn the gate on
only after every WorkerPool has rolled, so no older worker sees a
version 2 spec, and that ate-setup rolls the WorkerPools when the gate
changes.

It also says to turn the gate off before rolling atelet back, since an
older atelet cannot read version 2 specs.
…estore

Each image the image provider plugin prepares holds a lease until atelet
releases it. atelet now releases the leases that an actor's overlay
specs record when the actor checkpoints or terminates, and when a Run or
Restore fails. It removes each spec after releasing it, so a second call
releases nothing.

Run and Restore release them too before they reset an actor's dirs,
since the reset deletes the specs of an earlier activation.
An image provider plugin keeps a lease per image use, and atelet may
restart, or the plugin may restart, while actors still use their layers.
Whenever the plugin socket appears or is replaced, at atelet startup or
after a plugin restart, atelet sends ReconcileImages with the leases
that the overlay specs on the node record. A failed reconcile is retried
on the next check. An unreadable spec fails the reconcile, because the
plugin would otherwise drop its leases and unmount layers that actors
use.

Bundle prepares and releases hold providerLeaseMu for reading, and the
reconcile holds it for writing, so the plugin never learns a lease set
that misses a lease taken but not yet recorded in a spec.

Each ReconcileImages call is bounded by a 30s timeout, since it holds
the lock that bundle prepares wait on.
A plugin that reads the registry lazily keeps using the credentials
from PrepareImage, which can expire while the lease is held. It reports
AUTH_REFRESH_REQUIRED for such a lease.

atelet remembers what the plugin reported for each lease, and treats a
lease it has no answer for as required. Every minute, and right after a
reconcile, it resolves fresh credentials for those leases and sends
them with RefreshAuth. A lease the plugin does not hold is skipped
until the next reconcile.
An image provider plugin that receives SIGTERM reports
PLUGIN_STATE_DRAINING and waits for its leases to go before it exits. A
running actor keeps its leases until it checkpoints or terminates.

While the plugin reports PLUGIN_STATE_DRAINING, atelet asks the control
plane to suspend each running actor on the node that holds a lease, with
WorkerService.RequestActorSuspend. The suspend checkpoints the actor and
releases its leases, and the actor resumes later from its snapshot.

The suspends run in the background, one batch at a time, so the monitor
keeps reconciling and refreshing credentials meanwhile.
yuekui2 added a commit to yuekui2/substrate that referenced this pull request Nov 25, 2026
yuekui2 added a commit to yuekui2/substrate that referenced this pull request Nov 25, 2026
yuekui2 added a commit to yuekui2/substrate that referenced this pull request Nov 25, 2026
@yuekui2
yuekui2 force-pushed the ipp-upstream/8-drain branch from 1332cfc to 98b2272 Compare November 25, 2026 00:39
@yuekui2

yuekui2 commented Nov 25, 2026

Copy link
Copy Markdown
Author

Rebased onto main to resolve a go.mod conflict. No other changes. The review fixes are still in the last commit.

The image provider plugin API changed in review. The plugin reports its
state through GetPluginInfo, and ReconcileImages returns the leases it
could not restore.

Suspend the actors that hold the leases a reconcile reports lost, through
the drain suspender, and ask again if a later reconcile still reports
them. Ignore a lost lease that is still being taken, since its
PrepareImage takes it. Refresh credentials per auth key, and release and
reconcile leases by ID. Vendor the revised API and client.

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.

2 participants