Skip to content

Server lifecycle suspend resume - #639

Merged
itssimrank merged 9 commits into
mainfrom
server-lifecycle-suspend-resume
Nov 19, 2026
Merged

itssimrank merged 9 commits into
mainfrom
server-lifecycle-suspend-resume

Conversation

@itssimrank

Copy link
Copy Markdown
Collaborator

Summary

  • Reconciler (internal/controller/reconciler.go):
    • Provision shared ax-* profile templates (ensureProfileTemplate), look up pre-warmed workspace snapshot tags (WorkspaceManager.EnsureSnapshotTag), create actors via EnsureActorFromTag, and mark WorkspaceReady=True when seeded.
    • Always prepend substrate.RunnerEgressRule in bindGateway so task actors can reach :8081 even without a user Gateway.
    • Add IsMemoryFidelityTemplate helper.
  • gRPC Server (internal/server/server.go, internal/server/task_applier.go):
    • Wire :8080 CreateTask, SuspendTask, ResumeTask, and DeleteTask onto store.TaskApplier (with TaskApplierForStore adapter for store.Store test doubles).
    • Allow spec.profile.ateActorTemplate (keep spec.retry rejected as Unimplemented).
    • Record row.ActorUID in finalizeReconciledRow and reset RunnerTokenHash/RunnerTokenConfirmed/ClaimNonce on ActorUID change.
    • On ResumeTask: reject lifecycle.IsExecutionTerminal tasks, set Runnable=true before ResumeActor, and preserve concurrent :8081 terminal completions.
    • On SuspendTask: reject lifecycle.IsExecutionTerminal tasks, set Runnable=false, clear ActiveRunID and runner token state on non-MEMORY fidelity templates (preserving them on MEMORY templates, and rolling back if SuspendActor fails while the actor is still running).
  • Wiring (cmd/ax-server/main.go):
    • Wire RunnerEndpoint, RunnerAudience, GatewayStore, WorkspaceManager, and TaskApplier.

Test plan

  • go test -count=1 ./...
  • go build ./cmd/ax ./cmd/ax-server ./cmd/ax-task-runner
  • golangci-lint run ./... (0 issues)

Comment thread internal/controller/reconciler.go Outdated
// common path.
func (r *TaskReconciler) IsMemoryFidelityTemplate(ctx context.Context, atespace, templateName string) bool {
if templateName == "" || strings.HasPrefix(templateName, "ax-") {
return DefaultProfileSnapshotFidelity == ateapipb.SnapshotFidelity_SNAPSHOT_FIDELITY_MEMORY

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.

is there guarantee that ax- is reserved for ax created template?

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.

Removed the ax- prefix shortcut and now query GetActorTemplate directly whenever a template is set.

Comment thread internal/server/server.go
return nil, status.Errorf(codes.Internal, "updating task before suspend: %v", err)
}

if err := s.reconciler.Suspend(ctx, task, s.fetchWorkspace(ctx, atespace, task), s.fetchGateway(ctx, atespace, task)); err != nil {

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.

Suspend happens after committing clearing the ActiveRunID and etc, could be problematic if Suspend fails.

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.

Updated, pre-suspend now only sets Runnable = false, and ActiveRunID / runner token state are only cleared after reconciler.Suspend succeeds.

@itssimrank
itssimrank force-pushed the server-lifecycle-suspend-resume branch from 115be51 to eacd4c8 Compare November 18, 2026 20:39
@itssimrank

Copy link
Copy Markdown
Collaborator Author

/cc @siyuanfoundation @mayawang

@mayawang mayawang left a comment

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.

Nice work Simran, the token reset and terminal-state guards look great, and awesome to see E2E green.

Before merge: shouldDropPrivileges() (runner/pull.go:540) now skips the uid 1000 drop when CAP_SETUID/CAP_SETGID are missing, so the agent runs as root and can read /var/lib/ax/runner_token and report its own completion. Can we keep the default failing closed, and only allow root via an explicit DropPrivileges=false? If Kind E2E needed the fallback because the pod drops those caps, either adding them in the template or setting DropPrivileges=false just for E2E works for me.

Non-blocking, fine as follow-up issues:

  • SuspendTask treats a failed template lookup as non-MEMORY and clears the active run, so a transient Substrate error during suspend kills an in-flight MEMORY task on resume. Returning Unavailable there would be safer.
  • This turns on profile.ateTemplate with cross-atespace refs. Let's limit it to the task's own atespace for now, since cross-atespace sharing isn't settled on the Substrate side yet.

Happy to approve as soon as the privilege check is sorted.

@mayawang mayawang left a comment

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.

Thanks Simran, LGTM! Privilege drop fails closed again and the suspend path looks good. Please file the cross-atespace ateTemplate follow-up as an issue so it doesn't get lost

@mayawang

Copy link
Copy Markdown
Collaborator

Heads up, PureImageLauncher is failing on e297e49 (task ends FAILED). Let's get that green before merging

@itssimrank

Copy link
Copy Markdown
Collaborator Author

E2E is green now and filed #650 to follow-up.

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.

3 participants