Skip to content

A slow resume gets cancelled partway, and a task can end up running while ax says it is suspended #452

Open

Description

@mastersingh24

Since ac23328, ax-server reconciles inside the request handler, using the request's context (internal/server/server.go:288 for suspend and :336 for resume). The CLI gives SuspendTask and ResumeTask a 15-second deadline (cmd/ax/main.go:834 and :865). When the CLI gives up, the cancellation goes all the way down to Substrate, and anything still in flight is abandoned partway.

We hit this two ways on Agent Substrate v0.1.0-gke.1.

1. The first resume of a new task gets cancelled. The worker hadn't pulled the runner image yet, so the restore took longer than 15 seconds:

$ time ax resume task simple-task
Error: resuming task: rpc error: code = Internal desc = resuming task on substrate: resuming actor: resuming actor default/simple-task: rpc error: code = DeadlineExceeded desc = context deadline exceeded
real    0m15.045s

Substrate's API server logged the restore being abandoned:

"method":"/ateapi.Control/ResumeActor","err":"workflow failed at step CallAteletRestore: while restoring durable snapshot: rpc error: code = Canceled desc = context canceled","elapsed-time":"14.940267106s"

2. The task ends up running while ax says it's suspended. On a later attempt, ResumeActor finished in about 5 seconds, then the workspace readiness poll ran past the CLI's deadline. ax-server logged task successfully reconciled and running ... phase=Running, but the saved status stayed Suspended while the actor was running. After that, ax refused to work with it:

$ ax ssh simple-task -- uname -a
Error: task "simple-task" is in phase "Suspended" (must be Running to ssh)

Suggested fix

  • Run the reconcile on a context detached from the caller (context.WithoutCancel(ctx) plus its own timeout), so a client disconnect can't abort Substrate work or the status write.
  • Optionally return early with the current status and let ax watch follow progress, so slow restores don't block the RPC at all.
  • Give the CLI a longer default deadline for suspend and resume, or a --timeout flag.

Activity

  1. yjjnls commented on Nov 23, 2026

    @yjjnls

    Re-checked on main at 775f5ad (after #639/#688): the cancellation half is still there. ResumeTask passes the caller's context into the reconcile and the status write, so a cancel (the CLI deadline is now 5 minutes, but any disconnect or cancel still counts) cancels the Substrate ResumeActor call and the persist mid-flight. The stored-state symptom from the report is now masked by the actor-state overlay, but the outcome is still a failed resume on a task that runs.

    Repro (test-only branch, ran locally on 775f5ad, three identical runs — a fake runner accepts the push with 202, then the RPC context is canceled; go test ./internal/server -run TestReproResumeCanceledAfterPush):

    ResumeTask error after cancel: rpc error: code = Internal desc = updating task status: context canceled
    actor state on Substrate: ACTOR_STATE_RUNNING
    stored status: state=TASK_STATE_UNSPECIFIED conditions=[]
    observed status: state=TASK_STATE_WORKING ready=False reason=WorkspaceInitializing message="Waiting for workspace setup to complete"
    

    The task runs (push accepted, actor RUNNING), but nothing is persisted and the task reports Ready=False "Waiting for workspace setup to complete" until the next successful write; there is no background reconcile. When the cancel lands mid-push instead, the error is also wrong: runner at ... did not accept the task within 15s: ... context canceled, although the runner accepted.

    Detaching the reconcile and the status write (context.WithoutCancel + deadline for the push/wait, as prepareWorkspace already does in internal/server/workspace.go:162) would fix both.

    Repro branch: https://github.com/yjjnls/ax/tree/repro-452-canceled-resume

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions