Skip to content

controlapi: refactor workflows to typed ensure-steps - #797

Open
Troy Chiu (troychiu) wants to merge 5 commits into
agent-substrate:mainfrom
troychiu:refactor/ensure-step-workflows
Open

controlapi: refactor workflows to typed ensure-steps#797
Troy Chiu (troychiu) wants to merge 5 commits into
agent-substrate:mainfrom
troychiu:refactor/ensure-step-workflows

Conversation

@troychiu

Copy link
Copy Markdown
Contributor

Fixes #554

Each workflow becomes a plain method orchestrating typed, idempotent ensureX steps, e.g.:

func (w *ActorWorkflow) ResumeActor(ctx, ref, boot) (*Actor, bool, error) {
    // acquire actor lock, metrics defer — unchanged
    actor, tmpl, snapSrc, err := w.loadActorForResume(ctx, ref, boot)
    if actor.Status == RUNNING { return actor, false, nil }        // explicit no-op
    actor, err         = w.ensureVolumesCreated(ctx, actor, tmpl)
    actor, worker, err = w.ensureWorkerAssigned(ctx, actor, tmpl)
    err                = w.ensureVolumesAttached(ctx, actor, worker, tmpl)
    tele, err          = w.ensureAteletRestored(ctx, actor, worker, tmpl, snapSrc)
    actor, err         = w.finalizeRunning(ctx, ref)
    return actor, true, nil
}

Each ensureX

  • early-returns if its postcondition already holds, which is derived from persisted state only, replacing IsComplete
  • validates the state machine edge internally, replacing CheckPrerequisite
  • takes explicit typed inputs and returns what it produced.
  • persists what it changed before returning, returning the stored copy so the optimistic lock version threads forward. No shared *ResumeState.

There is one behavioral change: worker ownership/eligibility validation for a re-entered resume now runs before volumes are attached (it used to run in CallAteletRestoreStep's prerequisite, after attach), so a resume that is about to crash on a reassigned/ineligible worker no longer attaches volumes to it first.

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

@troychiu
Troy Chiu (troychiu) force-pushed the refactor/ensure-step-workflows branch 2 times, most recently from 39faf35 to 4b3fffb Compare August 7, 2026 21:11
@troychiu
Troy Chiu (troychiu) force-pushed the refactor/ensure-step-workflows branch from 4b3fffb to 6c1a66f Compare August 7, 2026 22:05
@troychiu
Troy Chiu (troychiu) force-pushed the refactor/ensure-step-workflows branch from 6c1a66f to 4f7d649 Compare August 7, 2026 22:35
@troychiu Troy Chiu (troychiu) changed the title Refactor workflows controlapi: refactor workflows to typed ensure-steps Aug 7, 2026
@troychiu
Troy Chiu (troychiu) marked this pull request as ready for review August 7, 2026 22:52
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.

Actor's suspend / resume / pause workflows need to be clearly reentrancy safe

1 participant