Triggers, Kickoff Patterns & Cancellation
How jobs are triggered
There are two primary ways to start a K12 workflow:
-
HTTP tool kickoff (EOP) —
k12-annex-editing-kickoff/k12-qrg-editing-kickoffinvoked over the Mastra HTTP API or APIM. This is the canonical external trigger and accepts the validated payload, responds withrequestId/sessionId, and either returnsaccepted(async) orsuccess(sync wait). -
Internal runner / CLI/test harness — The
annex-editing-workflow-runner(EOP runner) exposesrunAnnexWorkflowKickoffused by integration scripts and unit tests to execute synchronously without going through the tool wrapper.
Synchronous vs asynchronous modes
waitForResult: truemakes the kickoff attempt to finish and return thesuccessenvelope (useful for tests or APIs that want immediate results). Beware of timeouts in HTTP/APIM in this mode.- Default mode returns
acceptedand leaves the job to complete in the background; consumers poll status/result tools to obtain the final payload.
Cancellation behavior
k12-cancel-task-requestmarkslog_EOP_TaskStatusandlog_EOP_TaskRequestsascancelled(and writes timestamps). It is a DB-driven cancellation and returnsstatus: successorstatus: errorwhen rows weren't affected.- If
K12_ENABLE_WORKFLOW_CANCELLATIONis enabled, the cancellation tool also attempts to stop in-progress Mastra workflow runs via API/handle. Workflow cancellation is best-effort; always verify DB rows after cancelling.
Practical tips
- For long-running LLM operations, prefer async kickoff and poll; this avoids APIM/HTTP timeouts and provides better observability.
- When cancelling, check both
log_Jobs(job row) andlog_EOP_TaskStatusto confirm the run has been marked cancelled.