Workflows (preview)
A workflow is a TypeScript file in your workspace repo, in the workflows/ folder, written with Hatchet’s own SDK. Commit it on main and it is deployed. Hatchet runs it: schedules, retries and timeouts are Hatchet’s.
Three things, each one verb. Test: mako workflow run <name> on your laptop, or Run → Sandbox (workflows_run with sandbox: true) for the same command in your sandbox, runs the workflow as it is in the checkout, uncommitted edits included, once, with real data, your own rights and no schedule. It runs in one process with no Hatchet engine; a sandbox run answers a run id at once and is followed until it ends. A sandbox run typechecks workflows/ first, as the deploy’s build does, and with a type error ends FAILED with the tsc output instead of running. Main: a commit on main is the deploy. An agent’s workflow_commit goes to a preview branch instead, workflow/<you>/<name>: main plus that workflow’s folder, replaced on each commit. Your checkout stays on main. You review the branch, and the agent merges it with workflow_merge_to_main when you say so. This is the agents’ default, not a lock: an admin’s own push to main still deploys. Active: a deployed workflow starts inactive, runnable with Run, schedule and webhook off; when a run looks right, an admin flips it to Active on its tab, and from then on it runs by itself. The same as testing and then activating an n8n workflow.
Preview. Workflows are optional: an installation without a Hatchet runs without them. With one, they have their own panel in Mako: the workflows, their files and their runs.
A workflow
Section titled “A workflow”A workflow is a folder: workflows/<name>/workflow.ts. The folder name is the workflow’s name.
workflows/ daily-digest/ workflow.tsThat file is all a workflow needs. ../hatchet (the Hatchet client) and ../lib/mako (Mako data access) are supplied when the workflow is built. Add your own workflows/hatchet.ts or workflows/lib/mako.ts only to replace them.
import { hatchet } from "../hatchet";
const dailyDigest = hatchet.workflow({ name: "daily-digest", // same as the folder on: { cron: "0 7 * * 1-5" }, // weekdays at 07:00 UTC});
dailyDigest.task({ name: "build-digest", retries: 1, fn: async () => ({ date: new Date().toISOString().slice(0, 10) }),});
export default dailyDigest;Every folder with a workflow.ts is picked up. There is no list to keep.
What starts a run
Section titled “What starts a run”| Trigger | How |
|---|---|
| Schedule | on: { cron: "0 7 * * 1-5" } in the workflow, in UTC |
| Webhook | Add webhook on a live workflow’s tab gives a URL. A POST to it starts a run with the JSON as input |
| A person | The Run button, with a JSON input |
| An agent | workflows_run |
Anyone with the member role writes workflows in their sandbox and tests them there; only workspace admins put them on main, activate them and add webhooks. A webhook is off until an admin adds it on the workflow’s tab. Its URL carries its own secret, so treat it like a password; removing the webhook and adding it again gives a new URL. The schedule and the webhook start runs only while the workflow is active; Run always works. The webhook URL with ?sandbox=<your user id> is a test URL: a POST to it runs your sandbox’s version with the body as input and answers its run id, whether or not the workflow is active.
Using Mako from a step
Section titled “Using Mako from a step”import { generateText } from "ai";import { agent, call, execute, model, query } from "../lib/mako";
// SQL on a workspace connection: run once, every row, with values exactly// as the database returns them. Name the row type for typed rows.const orders = await query<{ id: string; total: number }>( "<connectionId>", "select id, total from orders",);
// Writing needs the workflow on the connection's writers list (Access tab).// rowCount is the number of rows the write changed.const { rowCount } = await execute( "<connectionId>", "update mako_out.orders set flagged = true where total > 1000",);
// Any Mako tool by name: here, rebuild an app's data.await call("app_materialize", { appId: "<appId>", name: "orders_daily" });
// Mako's own agent, as in chat: a goal in, the answer out.const { text, toolCalls } = await agent( "Which accounts stopped using the product this week, and why?",);
// A plain model call, with Mako's tools if you pass them.const summary = await generateText({ model: model("anthropic/claude-haiku-4.5"), prompt: `Summarize in one line: ${text}`,});Calling a service through a connection
Section titled “Calling a service through a connection”connection(id) calls a source connection’s service (Close, Stripe, Wise, a Custom API) with the key Mako holds. The step never sees the key.
import { connection } from "../lib/mako";
const leads = await connection("ch_close").get("/lead/", { query: { _limit: 10 },});await connection("ch_close").post("/task/", { lead_id: "lead_1", text: "Call back",});get,post,put,patchanddeletereturn the body and throwConnectionErrorat a status of 400 or more (its message includes the start of the service’s answer).request(method, path, body, options)returns{ status, headers, body }whatever the status. Options:query, andheaderssuch asIdempotency-Key.- Reads need live reads on in the connection’s Access tab (and, if it lists who may read live, this workflow or All deployed workflows on that list, or on its writers list).
- A write needs this workflow, or All deployed workflows, on the connection’s writers list. A person’s own run (
mako workflow run, a sandbox run started from the app) writes as that person instead. - A run started by an agent (the in-product agent’s tool or an MCP client) writes like a run from the app: in the sandbox as the person the agent acts for, on the workers as the workflow, within the connection’s writers list. A run started with an API key (CI, a script) has its connection writes refused, so it fails.
- On the workers, a write must come from a run of that workflow that is still executing (queued, pending or running; an
onFailuretask counts). A write that names another workflow’s run, or a run that has ended, is refused and not sent, as is one when Mako cannot tell which run it comes from (for example Hatchet was unreachable); try again, and update the workflows runtime if it persists. - A dry run (
dryRun: trueonworkflows_runorPOST /workflows/{name}/run) records each connection call that writes instead of sending it: the call answers202with{ recorded: true, sent: false, wouldSend }, and the run’s status givesrecordedWriteCountand a page ofrecordedWrites(method, full URL, headers and body, credentials redacted), so an agent can check a Slack or email payload before sending it.wouldSend: falsemeans a real run would be refused by the writers list. A dry run’s SQL only reads. The run’s page in the app says how many writes were recorded. Recorded writes are kept 7 days, at most 200 per run.
Each workflow acts as itself
Section titled “Each workflow acts as itself”All of a workspace’s deployed workflows run in one worker pod, but workflow code never holds the pod’s key. The pod’s dispatcher, which runs no workflow code, asks Mako for a pass for each step it is about to run: a short-lived token for that workflow, that run and that step, given only for a run Hatchet says is a run of that workflow and executing now. The step runs in a program of its workflow, as a user of its own for that workflow, with the pass instead of the key. Steps of the same workflow share that program, several at a time, each with its own pass; steps of different workflows never do. Do not keep one run’s data in a module-level variable: another run of the same workflow may read it.
So a writers list or a live readers list can name one workflow: Mako believes the workflow a pass names, and nothing a request says about itself. A pass stops working when its run ends, when the worker key is replaced, and after 24 hours at the latest. A step program stays for 60 seconds after its step, so a workflow that runs every few seconds keeps one and a daily one does not.
The dispatcher keeps at most WORKFLOWS_MAX_STEPS step programs alive at once (default 8, busy or idle, about 120 MB each). A step waits for a free one; an idle program of another workflow is stopped to make room. The worker pod’s memory limit is 2 GiB.
What a step’s ctx offers: its input, its parents’ outputs, the run’s ids and metadata, logs, refreshTimeout, releaseSlot, putStream, cancel, runChild and spawnChild (by workflow name), and in a durable task sleepFor, sleepUntil, now and waitForEvent (key and expression). Task options that are not plain data (a waitFor, skipIf or cancelIf condition object) are refused when the workflows are loaded. A workspace’s own workflows/hatchet.ts is used to declare workflows only: the dispatcher connects to Hatchet with its own client.
Query results
Section titled “Query results”query() runs the statement once and returns all its rows. Nothing is shortened: long text and JSON values come back whole, and no LIMIT is added.
query(connection, sql, { database?, maxRows?, timeoutMs? })returns the rows as an array. A write sent throughquery()returns itsRETURNINGrows, or an empty array.execute(connection, sql, { database?, timeoutMs? })runs a write and returns{ rowCount }, the number of rows it changed.- A result over 100,000 rows (or
maxRows, if lower) or over 50 MB throws while it is being read: aggregate or filter in SQL, or read it in parts (for example by id range). - A statement still running after
timeoutMs(default 5 minutes, at most 15) is cancelled on the database and throws.
A query passes the same checks as the agent’s sql_execute_query: every workflow reads, and only the workflows on a connection’s writers list write. A refused or failed query throws with the reason. Workflow code calls the route POST /api/workflows/runtime/query with the worker’s key.
Rows are raw data. If a step passes them to a model, treat them as untrusted input: text in a row can carry instructions (prompt injection), and guarding against that is the workflow author’s job.
How a deploy works
Section titled “How a deploy works”- You commit a change to
workflows/onmain. Mako records the commit as the workspace’s target, durably (an Inngest function, like app deploys), and checks every deployed workspace againstmainonce an hour in case a push was missed. - Mako saves that commit as the one to run.
- The worker notices within ten seconds, typechecks the commit and starts it.
- Once the new code is up, the old code finishes its running tasks and stops.
If the commit does not typecheck, the worker reports the error and keeps running the previous commit. To roll back, revert the commit.
Set it up
Section titled “Set it up”Mako needs two things: a Hatchet API token, and a worker.
Try it locally
Section titled “Try it locally”-
In
.env, uncomment the workflows lines from.env.example. SetWORKFLOWS_WORKER_KEYto any value of your own that starts withrevops_. -
Start Hatchet and the worker:
Terminal window docker compose --profile workflows up -d -
Ask the agent for a workflow, or add
workflows/<name>/workflow.tsto the workspace repo onmain.
Hatchet dashboard: http://localhost:8086 (admin@example.com / Admin123!!). The link icon in the Workflows panel opens it. This bundled Hatchet is for testing, not for production.
Test from your checkout
Section titled “Test from your checkout”mako workflow run <name> --input '{"limit":3}' runs workflows/<name>/workflow.ts from your checkout, uncommitted edits included, in one Node process with no Hatchet engine. Steps run once each, parents first. Every Mako call is real and carries your mako login (or MAKO_API_KEY, which needs the workflows:run scope). The whole run is saved to .mako/runs/<name>.json, and --task <step> reruns one step from its saved outputs. See the CLI README for details.
When a person runs workflow code this way, calls to the worker’s SQL, model and agent routes act as that person, with exactly the rights they have over /api/mcp. The X-Mako-Workflow header grants nothing, from anyone. A deployed step has the workflow’s own rights through its pass (see “Each workflow acts as itself” below).
Production
Section titled “Production”-
Create an API token in Hatchet Cloud, or in a Hatchet you run yourself.
-
Set
HATCHET_CLIENT_TOKENon the Mako API. -
Choose a
WORKFLOWS_WORKER_KEY(long, random, starting withrevops_) and set it on the Mako API. -
Build the worker image from the Mako repository and run it anywhere that can reach Mako and Hatchet:
Terminal window docker build -f deploy/workflows/runtime/Dockerfile -t mako-workflows-runtime .docker run -e MAKO_URL=https://your-mako -e MAKO_API_KEY=$WORKFLOWS_WORKER_KEY \mako-workflows-runtime -
Turn workflows on for the workspace, as in step 3 above.
A worker run this way serves one workspace and has no sandbox: workflow code runs with the container’s access. Use it for your own team’s code.
Settings
Section titled “Settings”| Variable | Set on | What |
|---|---|---|
HATCHET_CLIENT_TOKEN |
API | One Hatchet tenant for the whole installation, so one workspace: the first to deploy keeps it, a second is refused. Multi-workspace installs set the admin variables below instead, and Mako makes a tenant per workspace |
HATCHET_DASHBOARD_URL |
API | Where Mako links admins to the Hatchet dashboard |
WORKFLOWS_WORKER_KEY |
API, and the worker as MAKO_API_KEY |
The worker’s Mako API key |
MAKO_URL, MAKO_API_KEY |
Worker | All the worker needs. It gets the Hatchet token from Mako. |
WORKFLOWS_MAX_STEPS |
Worker | Most step programs alive at once (default 8) |
HATCHET_API_URL, HATCHET_ADMIN_EMAIL, HATCHET_ADMIN_PASSWORD |
API | Only for a Hatchet you operate: lets Mako create a Hatchet tenant per workspace. Used by the local setup. |
With none of these set, Mako runs without workflows.
On a GKE worker, set WORKFLOWS_AUTOSCALE=on on the API and Mako sizes each workspace’s worker itself: one pod per 128 steps it has to run, up to 5, and none after 10 minutes without work. Starting a run, deploying a commit and switching a trigger wake a sleeping worker at once; a run started while no pod is up waits queued for about a minute. It is off by default, and then the pods a worker has stay. See deploy/workflows/README.md.
Bursts and limits
Section titled “Bursts and limits”A workflow runs at most 250 of its runs at once; more wait their turn in the order they came, so a thousand webhook calls in a minute become a queue. To choose your own number, declare it, and yours is kept:
import { ConcurrencyLimitStrategy } from "@hatchet-dev/typescript-sdk/v1";
const digest = hatchet.workflow({ name: "daily-digest", concurrency: { expression: "'all'", // one group; "input.customerId" limits per customer maxRuns: 10, limitStrategy: ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN, // wait, do not cancel },});Always name the limitStrategy: Hatchet’s default cancels the run in progress. A step waits up to a day for its turn before Hatchet cancels it (scheduleTimeout on the step sets another time).
For a provider with a quota, an operator names a rate limit for the installation (WORKFLOWS_RATE_LIMITS, for example model=300/minute), and a step takes from it:
digest.task({ name: "summarize", retries: 2, rateLimits: [{ staticKey: "model", units: 1 }], fn: async () => { /* one model call */ },});A step over the limit waits; it does not fail. A commit whose step names a limit the installation does not have does not build, and says which.
Give every step retries: 1 or more. A step is interrupted when its worker is replaced or Hatchet restarts, and with retries: 0 that ends the run.
Runs, retries and cost
Section titled “Runs, retries and cost”A workflow opens on its Runs tab: a table of its runs, newest start first, with status, start, duration, trigger, error and AI cost. Its Flow tab draws the workflow’s steps as the code defines them (each step, the steps it waits for, its retries and timeout), so it shows before any run. The triggers sit above the table: each schedule in plain words with its next run (the cron on hover; it is set in workflow.ts), the webhook, and one On/Off switch.
A run opens on where it failed: a failure card (step, error, the code line from the stack), the steps in the order they ran with the selected step’s log beside them, and Log, Output, Input and Flow tabs. Retry starts from the failed step (earlier steps keep their output), reruns the whole run, or starts a new run with other input.
AI cost
Section titled “AI cost”Every model call and agent() turn a deployed step makes is counted against its workflow, run and step. A run’s cost is the sum of its calls. Queries and compute are not counted. The run page shows the cost per step, the runs table has an AI cost column, and the workflow page shows the last 30 days. workflows_status returns each run’s cost and its cost per step to an agent.
Each call carries the run and step it comes from in the step’s pass. A person’s own run (mako workflow run, or a sandbox run) sends none, so it is not counted. Runs from before costs were recorded show none. To attribute older calls, a super admin can POST /api/admin/workflows/cost-backfill (body { workspaceId?, days?, dryRun? }; days is 1–90, default 30). It is a dry run unless dryRun: false, and answers per workspace the calls matched, ambiguous and unmatched with their cost, and how many it saved. It matches calls to the step they were made in by time and marks them as backfilled. Calls in overlapping runs are left alone. The script api/src/scripts/backfill-workflow-ai-costs.ts (--dry-run first) runs the same function from a shell with production access.
All under /api/workspaces/<workspaceId>/workflows:
| Route | Does |
|---|---|
GET / |
What is deployed, build errors, the workflows (with active), schedules and recent runs |
GET /runs/<id> |
One run: its steps in order, with status, output, error and logs |
GET /files, GET /files?path=<file> |
The files under workflows/, or one file’s contents |
POST /<name>/run |
Start a run: { input } answers runId; { input, sandbox: true } starts the caller’s checkout in their sandbox and answers its runId; GET /runs/{id}?wait=90 follows either |
PUT /<name>/triggers |
Change what starts it: { active } (its schedule and webhook), { webhook } (add: answers the new URL; remove). Admins |
POST /runs/<id>/retry |
Retry a deployed run in place: { step } runs that step and the ones after it again, on what the earlier steps kept; without step, the whole run. Members who may run may retry |
GET /<name>/flow |
The workflow’s steps as its code defines them: each with the steps it waits for, its retries and timeout |
GET /<name>/cost |
The workflow’s AI cost over the last days days (default 30, at most 365): the total and by day |
Over MCP, an API key needs the workflows:run scope to start runs or add webhooks; looking needs only mcp.