Skip to content

[Bug]: RevertActor discards local/PENDING snapshots from async SuspendActor and behaves inconsistently on SUSPENDED actors #2983

Open

Description

@zoez7

Summary

Following the removal of PauseActor in favor of SuspendActor (with DURABILITY_MODE_ASYNCHRONOUS as the default and DURABILITY_MODE_SYNCHRONOUS also retaining node-local snapshots after #2883), RevertActor still relies on legacy PAUSED assumptions where a node-local / PENDING snapshot is treated as uncommitted state to be destroyed rather than a valid snapshot to revert to.

This causes two concrete bugs in cmd/ateapi/internal/controlapi/workflow_revert.go:


Bug 1: Reverting a RUNNING or CRASHED actor destroys its latest snapshot if that snapshot is still node-local / PENDING

When an actor is suspended with the default SuspendActor mode (DURABILITY_MODE_ASYNCHRONOUS), resumed, and then reverted while atelet's background upload of that snapshot is still PENDING (default upload delay is 5 minutes), RevertActor destroys the snapshot it should be reverting to:

  1. CreateActor → ResumeActor → SuspendActor (default async mode). This mints generation G in status.snapshots with locality = <node> and durable_snapshot.status = SNAPSHOT_STORAGE_STATUS_PENDING.
  2. ResumeActor restores the actor on <node> from generation G's node-local snapshot (ACTOR_STATE_RUNNING). The actor then either continues running or enters ACTOR_STATE_CRASHED before generation G's background upload finishes.
  3. Calling RevertActor to roll the actor back to generation G:
    • ensureWorkerDiscarded (cmd/ateapi/internal/controlapi/workflow_revert.go:188-209) calls ensureAteletTerminated → atelet Terminate (cmd/atelet/main.go:1745-1755), which calls s.snapshots.Forget(actorUID) (canceling the background upload) and snapshottracker.PruneLocalCheckpoints (deleting generation G's node-local checkpoint files on disk).
    • ensureInProgressSnapshotDiscarded (cmd/ateapi/internal/controlapi/workflow_revert.go:220-258) deletes from object storage every snapshot with durable_snapshot.status == SNAPSHOT_STORAGE_STATUS_PENDING, which includes generation G's durable upload.
    • ensureRevertedFinalized (cmd/ateapi/internal/controlapi/workflow_revert.go:289) calls pruneSnapshots(toUpdate.Status, nil), which drops generation G from status.snapshots because pruneSnapshots only retains local (passed as nil) and the latest COMPLETED durable snapshot.

Result: Instead of reverting the RUNNING / CRASHED execution back to generation G (whether local or durable), RevertActor permanently deletes generation G and rolls the actor back to an even older COMPLETED durable snapshot (or leaves status.snapshots empty so the next ResumeActor cold-boots from the template).

Even when generation G is already COMPLETED durable and also has a node-local copy (locality != ""), RevertActor's Terminate call deletes the node-local checkpoint on atelet and clears locality / assigned_node, forcing the next ResumeActor to restore from remote object storage instead of the local copy.


Bug 2: isRevertable on ACTOR_STATE_SUSPENDED depends on internal upload/detach timing

In cmd/ateapi/internal/controlapi/workflow_revert.go:46-50:

func isRevertable(actor *ateapipb.Actor) bool {
	state := actor.GetStatus().GetState()
	return slices.Contains(revertableStates, state) ||
		(state == ateapipb.ActorState_ACTOR_STATE_SUSPENDED && latestSnapshotIsLocal(actor.GetStatus()))
}

Because both synchronous SuspendActor (since #2883) and asynchronous SuspendActor now leave a SUSPENDED actor with locality != "" until detach, calling RevertActor on an ACTOR_STATE_SUSPENDED actor produces three different behaviors depending on internal background upload and detach timing:

  1. Before background upload completes (locality != "", durable_snapshot.status == PENDING): RevertActor is accepted, deletes generation G (both node-local and PENDING durable), and rolls the actor back to generation G-1 (or to no snapshot if G was the first suspend).
  2. After sync SuspendActor or after async background upload completes, before detach (locality != "", durable_snapshot.status == COMPLETED): RevertActor is accepted (because latestSnapshotIsLocal is still true), does not revert to generation G-1 (which SuspendActor already pruned/released or pruneSnapshots(toUpdate.Status, nil) drops in favor of generation G), and merely deletes the node-local cache copy on atelet while keeping generation G's COMPLETED durable snapshot.
  3. After detach (locality == "", durable_snapshot.status == COMPLETED): RevertActor is rejected with FAILED_PRECONDITION.

Expected Behavior

  • Reverting an actor should revert to its target snapshot smoothly regardless of whether that snapshot is currently node-local (PENDING upload) or COMPLETED durable, without destroying a valid node-local snapshot from a completed SuspendActor.
  • The precondition and semantics of RevertActor on ACTOR_STATE_SUSPENDED should not depend on whether atelet has finished its background upload or detached the local copy.

Activity

  1. added
    kind/bug
    on Oct 20, 2026
  2. chw120 commented on Oct 28, 2026

    @chw120
    Collaborator

    Another case of Bug 1, on the #3094 path: a revert deletes a complete upload after a failed resume.

    Generation 1 is durable. Generation 2 is local on node-3 with a PENDING upload.

    1. atelet on node-3 finishes the upload, but node-3 is deleted before the report lands.
    2. Resume restores generation 2 from the upload on node-2. The restore reads the upload and then fails, for example on a failed wakeup probe, so the actor goes CRASHED. Generation 2 is still marked PENDING, because resume only marks the upload complete at its very end (recordRestoredUpload in finalizeRunning).
    3. Revert treats every PENDING upload as unfinished and deletes it, including this complete one (ensureInProgressSnapshotDiscarded). The next resume falls back to generation 1, and generation 2 is lost.

    Only a NotFound from Restore (crashMessageLocalSnapshotNodeGone) shows the upload is missing. After any other failure, the upload may be the only copy of generation 2.

    Neither open PR covers this. #3041 clears the locality of snapshots on the deleted node, then deletes the upload. #3079 only records an upload that the atelet on the assigned node reports, and the uploading atelet was on node-3.

    I added the test below to cmd/ateapi/internal/controlapi. It fails on main (7a19374) and on #3041 (40dc5fc):

    workflow_revert_gone_node_test.go:100: revert deleted generation 2's upload, which the failed restore had read in full
    workflow_revert_gone_node_test.go:110: second resume restored generation 1 ("durable-1"), want generation 2
    
    Test

    On #3041 (40dc5fc), replace SnapshotStorageState_SNAPSHOT_STORAGE_STATE_COMPLETED with SnapshotStorageStatus_SNAPSHOT_STORAGE_STATUS_COMPLETED, the enum's name before main renamed it.

    package controlapi
    
    import (
    	"context"
    	"testing"
    
    	"go.ate.dev/substrate/api/ateapi/v1"
    	"go.ate.dev/substrate/cmd/ateapi/internal/store/storetest"
    	"go.ate.dev/substrate/internal/apierror"
    	"go.ate.dev/substrate/internal/objectstore/objectstoretest"
    	"go.ate.dev/substrate/internal/objectstoreplugin/objectstoreplugintest"
    	"go.ate.dev/substrate/internal/resources"
    )
    
    // TestRevertActor_KeepsUploadRestoredAfterNodeGone resumes a suspended actor
    // whose node was deleted after atelet uploaded the actor's latest snapshot but
    // before it reported the upload. Resume restores the upload on another node,
    // and the restore fails after atelet has read it, so the actor crashes. The
    // upload is complete, so a revert must keep it and return the actor to it.
    func TestRevertActor_KeepsUploadRestoredAfterNodeGone(t *testing.T) {
    	ctx := context.Background()
    	st := newTestPersistence(t)
    	actorRef := resources.ActorRef{Atespace: "team-a", Name: "id1"}
    
    	storetest.MustCreateAtespace(t, ctx, st, "ns")
    	tmpl, err := st.CreateActorTemplate(ctx, &ateapi.ActorTemplate{
    		Metadata:       &ateapi.ResourceMetadata{Atespace: "ns", Name: "tmpl1"},
    		SnapshotConfig: &ateapi.SnapshotConfig{StorageLocation: testStorageLocation},
    	})
    	if err != nil {
    		t.Fatalf("create template: %v", err)
    	}
    	seedRuntimeWorker(t, ctx, st, "pod-2", "node-2", testSandboxRuntime())
    	seedWorkflowActor(t, ctx, st, actorRef, "ns", "tmpl1", ateapi.ActorState_ACTOR_STATE_SUSPENDED)
    	actor, err := st.GetActor(ctx, actorRef)
    	if err != nil {
    		t.Fatalf("GetActor: %v", err)
    	}
    
    	// Generation 1 is durable. Generation 2 was checkpointed on node-3, and
    	// atelet uploaded it in full before the node was deleted with its report.
    	memory := ateapi.SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY
    	completed := ateapi.SnapshotStorageState_SNAPSHOT_STORAGE_STATE_COMPLETED
    	olderURI := mustActorSnapshotURI(t, tmpl, actor, "durable-1")
    	uploadURI := mustActorSnapshotURI(t, tmpl, actor, "pending-2")
    	objects := objectstoretest.New()
    	objects.PutSnapshot(t, olderURI, "manifest.json")
    	objects.PutSnapshot(t, uploadURI, "manifest.json", "memory.zst")
    	pending := newPausedSnapshot(t, 2, memory, "", "pending-2", "node-3")
    	pending.DurableSnapshot.Object.SnapshotUri = uploadURI.String()
    	mustUpdateActorStatus(t, ctx, st, actor, func(s *ateapi.ActorStatus) {
    		s.AssignedNode = "node-3"
    		s.LastAssignedGeneration = 2
    		s.Snapshots = []*ateapi.Snapshot{
    			newDurableSnapshot(1, ateapi.SnapshotOwner_SNAPSHOT_OWNER_ACTOR, memory, "", "durable-1", olderURI.String(), completed),
    			pending,
    		}
    	})
    
    	w, atelet := newDetachTestWorkflow(t, ctx, st)
    	w.objectStorePlugin = objectstoreplugintest.ControlClient(objects)
    	addAteletOnNode(t, w, "node-2")
    	// node-3 no longer exists.
    	WithNodeGetter(nodeGetter(nil, "node-1", "node-2"))(w.dialer)
    	// atelet on node-2 read the upload, then the workload failed to come up.
    	atelet.restoreErr = apierror.Internal("while waiting for container wakeup probe: container exited")
    
    	if _, _, err := w.ResumeActor(ctx, actorRef); err == nil {
    		t.Fatal("ResumeActor succeeded, want the restore failure")
    	}
    	if restore, _ := atelet.requests(); restore.GetSnapshot().GetObject().GetSnapshotUri() != uploadURI.String() {
    		t.Fatalf("Restore read %q, want the upload %q", restore.GetSnapshot().GetObject().GetSnapshotUri(), uploadURI)
    	}
    	crashed, err := st.GetActor(ctx, actorRef)
    	if err != nil {
    		t.Fatalf("GetActor: %v", err)
    	}
    	if got := crashed.GetStatus().GetState(); got != ateapi.ActorState_ACTOR_STATE_CRASHED {
    		t.Fatalf("after the failed restore: state %v, want CRASHED", got)
    	}
    
    	if _, err := w.RevertActor(ctx, actorRef); err != nil {
    		t.Fatalf("RevertActor: %v", err)
    	}
    	if len(objects.Snapshot(t, uploadURI)) == 0 {
    		t.Error("revert deleted generation 2's upload, which the failed restore had read in full")
    	}
    
    	atelet.mu.Lock()
    	atelet.restoreErr = nil
    	atelet.mu.Unlock()
    	if _, _, err := w.ResumeActor(ctx, actorRef); err != nil {
    		t.Fatalf("second ResumeActor: %v", err)
    	}
    	if restore, _ := atelet.requests(); restore.GetSnapshot().GetGeneration() != 2 {
    		t.Errorf("second resume restored generation %d (%q), want generation 2", restore.GetSnapshot().GetGeneration(), restore.GetSnapshot().GetSnapshotUuid())
    	}
    }

    cc igooch (#3094) Luomu (@cloudonly) (#3041) Zoe Zhao (@zoez7)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/api-machineryarea/storagekind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions