Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Workflow

Workflow.Retarget (re-base the SLA clocks)

Workflow.Retarget()

Re-evaluates every SLA clock's budget on the current run against the now-updated entity, so a mid-run change to the SLA terms (e.g. re-grading a ticket's severity) takes effect from the change, not from the origin. Call it after writing the new terms in a handler body.

stable1 example compiled by CIworkfloweffect

Summary#

Workflow.Retarget() re-evaluates every live SLA clock on the current run — the whole-instance Deadline, the current state's Expire, and each milestone's Within — against the entity as it stands now. Use it when a handler body has just changed the values those budgets are computed from (a severity re-grade, a new contract), so the new, possibly tighter, terms apply immediately. The time already accrued is kept; only the remaining budget is re-based from the change point. It is a no-argument, fire-and-forget effect and returns nothing.

Signature#

Workflow.Retarget();

Description#

A workflow's SLA budgets are expressions over this.Item (Expire = this.Item.SlaResolveWithin, a milestone Within = this.Item.Foo). They are evaluated once, when the clock is armed. If a handler later rewrites those inputs, the armed clocks still hold the OLD budget — Workflow.Retarget() is how you make them reflect the new one.

For each live clock it: re-evaluates the clock's budget expression against the current this.Item; re-resolves the run's ServiceHours (SLA-accrual windows) schedule (which the same handler may also have changed); keeps the SLA time accrued so far; and re-bases the remaining budget from now (remaining = newBudget − accrued, walked through the new schedule). If the new budget is already exhausted the clock is due immediately. A paused clock (the run is in a non-accruing state) keeps its new budget and re-bases when it resumes.

Workflow.Retarget() is only valid inside a workflow handler body (it acts on the enclosing run). It runs on the same transaction as the body, so the new terms and the re-based clocks commit together.

Examples#

Re-grade a ticket and re-base its clocks in one route body:

enum Severity { Low, High }
enum TicketState { Open, Done }

entity SlaTarget {
  [Required] Severity Severity;
  TimeSpan RespondWithin;
  security { allow read, create when IsAuthenticated; }
}

entity Ticket {
  [Required, MaxLength(120)] string Title;
  Severity Severity = Severity.Low;
  TimeSpan SlaRespondWithin;
  TicketState State = TicketState.Open;
  security { allow read, create, update when IsAuthenticated; }
}

workflow TicketFlow {
  Tracks  = Ticket.State;
  Initial = Open;
  event Bump(Severity severity);
  state Open {
    subscribe Bump(Severity severity);
    on Bump(Severity severity) {
      this.Item.Severity         = severity;
      var target = SlaTarget.Single(t => t.Severity == severity);
      this.Item.SlaRespondWithin = target.RespondWithin;
            Workflow.Retarget();                                // the new terms take effect from here, not from the origin
    }
  }
  terminal success Done { }
}

See also#

Related

ServiceHours (SLA-accrual windows)

A schedule the SLA clock accrues within — the platform WALKS its weekly windows (and holiday exceptions) to advance…

Assigned / Finished (milestones)

A milestone puts an SLA on a slot's progress — Assigned (someone must PICK IT UP within Within) and Finished (it must…