Member Junction
    Preparing search index...

    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:

    • Insert fires a step's "started" INSERT without awaiting; the step instance is the serialization key, so a later QueueUpdate chains after it (an UPDATE never races its INSERT).
    • Insert also accepts one or more prerequisite steps (such as parentStep for FK_AIAgentRunStep_ParentID and an in-flight payloadAtStartSource step for FK_AIAgentRunStep_PayloadAtStartSourceStepID) plus an optional beforeInsert guard that runs after all prerequisites settle and immediately before step.Save() executes.
    • QueueUpdate chains a force-persisted UPDATE (IgnoreDirtyState) after the step's INSERT. Its applyMutation runs INSIDE the post-INSERT task — after finalizeSave's init() + SetMany reload — 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.
    • Flush awaits every queued save, drains, and reports failure counts. Call it at run/goal finalize.

    Failures are logged, never thrown — persistence is observability and must not break the run.

    Index

    Constructors

    Methods

    Constructors

    Methods

    • 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.

      Parameters

      • step: MJAIAgentRunStepEntity

        The newly created step entity to INSERT.

      • Optionalprerequisites: AgentRunStepInsertPrerequisites

        When 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) => void

        Optional 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.

      Returns void