Awaits every queued save, drains the queue, and returns failure diagnostics. Call at run/goal finalize.
Fires a step's "started" INSERT without awaiting (the caller continues immediately). The step's PK
must already be client-generated (NewRecord) so its id is valid before the INSERT lands.
The newly created step entity to INSERT.
Optionalprerequisites: AgentRunStepInsertPrerequisitesWhen provided, the INSERT is chained after all prerequisite steps' pending
work to satisfy self-referencing FK constraints (FK_AIAgentRunStep_ParentID and
FK_AIAgentRunStep_PayloadAtStartSourceStepID). Accepts either a single step or an array of steps.
OptionalbeforeInsert: (step: MJAIAgentRunStepEntity) => voidOptional callback invoked inside the queued INSERT task after all prerequisites
have settled and immediately before step.Save() runs. Useful for verifying that an in-flight
prerequisite step actually succeeded (prereq.IsSaved) and falling back (e.g., restoring inline
PayloadAtStart and clearing PayloadAtStartSourceStepID) if its INSERT failed.
Queues a fire-and-forget force-persisted UPDATE chained after the step's INSERT (and any prior
UPDATE). Pass applyMutation for any field change made after the INSERT was fired — it runs INSIDE
the post-INSERT task, so it can't be reverted by the INSERT's reload. Omitting it stays valid when
the fields are already set AND cannot race an in-flight INSERT.
OptionalapplyMutation: (step: MJAIAgentRunStepEntity) => void
Fire-and-forget save orchestration for agent-run steps — a thin, typed façade over the shared BaseEntitySaveQueue (
@memberjunction/core). Keeps step writes OFF the hot loop so a run that creates many steps (e.g. a goal-driven Computer Use loop with one prompt step per iteration) never pays N synchronous DB round-trips on its critical path, and inherits the queue's race-proofing:parentStepforFK_AIAgentRunStep_ParentIDand an in-flightpayloadAtStartSourcestep forFK_AIAgentRunStep_PayloadAtStartSourceStepID) plus an optionalbeforeInsertguard that runs after all prerequisites settle and immediately beforestep.Save()executes.IgnoreDirtyState) after the step's INSERT. ItsapplyMutationruns INSIDE the post-INSERT task — afterfinalizeSave'sinit()+SetManyreload — so it can't be reverted (the "step stuck at Running / null TargetLogID" bug is structurally impossible). Mutating the shared entity before the INSERT resolves is the race this prevents.Failures are logged, never thrown — persistence is observability and must not break the run.