Cue

Engine

Apply the section your change touches. Done when the code and that section describe the same behavior.

Flow

The engine rereads a restricted TypeScript flow from the start. The function may open a step, open an optional step, open a detached step, open child entities from the typed body, wait for a group, choose one named arm, finish, or declare failure. It reads sealed reports. The client database, secrets, and the clock stay outside the function.

The same sealed reports open the same steps. An opening already made stays in place. A choice records its arms in the order they are written. One name takes one arm. The other arms name their steps as discarded. A discarded step is not opened: it sends no job, and silence does not send it again.

Step and group

One step resumes when its result is there. openStep does this. A failed required step ends the run in failure and does not open the continuation. A not finished required step ends the run not finished.

openOptionalStep waits the same way. A failed result and a not finished result are returned and do not stop the run. openDetachedStep enqueues the job and does not wait. Its result does not stop the run. A result that arrives after the run has ended is recorded on that step and does not reread the function.

Several openings form a group. The group waits until every required member is done. A required member is an openStep or a child opening. An optional step is waited on and does not count. Success is a result whose status is done, a single child run whose status is success, or an array of children whose report is sealed. The first required failure ends the run in failure. The first required not finished, when nothing has failed, ends the run not finished. Inside the group, openStep and openOptionalStep open steps, and openChildren and openOptionalChildren open child entities. A group does not open a detached step.

When the group is satisfied the report is sealed: end reason, counts, and the discriminant of each member already returned. A child member contributes one element per child, with that child's flow. A late result is recorded on its step. The sealed report stays as sealed. When the run stops because a required member failed or is not finished, still-open required and optional steps close as not finished with discriminant ended. Detached steps stay open.

A step declares the shape of its body and of the payload that opens it. A body outside that shape ends the step as failed. A payload outside its shape does not open the step. A later reread compares the same payload. The worker receives it with the step. finish keeps its discriminant and stores a body checked by the flow's return schema.

One child opened on the flow resumes when that child's result is there. A failed required child ends the parent in failure. A not finished required child ends the parent not finished. An optional child returns that result and does not stop the parent. Several child entities opened together carry one rule, the same on openChildren and openOptionalChildren. The omitted rule is that every child run succeeds. The call may pass a quota: a count, capped at the number of children, or a proportion, whose target is that proportion of the children rounded up. Either form may name withinMin, whole minutes from the moment the children open. Only a successful child run counts toward the target. A required opening seals when the target is met. It stops the parent when the target can no longer be met, or when withinMin is reached with the target unmet. Before that time, a failure stops a required all as failure, and a not finished child stops it as not finished. An optional opening seals and the parent continues: quota when the target is met or can no longer be met, deadline when withinMin is reached first, and all when every child of an all opening has ended. A failure does not seal an optional all early. Children still open stay out of the sealed report. A result that arrives later does not change it. A child takes the identity and starting data of its element. The parent reads the child's typed body.

Run

Success: the function runs to the end, by returning or by finish(). finish may name the flow's return and store a body. A parent of one child reads that name as the discriminant and reads the body. Without a name, the discriminant stays success.

Failure: a required step or a single required child failed, a required array of children missed its rule, or the function declares failure.

Not finished: a required step or a single required child is not finished, before the children's duration. An optional step does not do that. A detached step does not do that. An optional child does not do that. A quota does not treat not finished as success.

Entity

The entity key is organization, flow, and identity. One run at a time. Other requests wait. The run keeps the first request's starting data.

Two identical lines of one list join that one execution and receive the same result.

Validity duration

Validity duration is on the flow.

On success, the duration runs from the end. A request inside the duration receives the recorded result, starts no run, and leaves the client database unread.

The next request starts a run with its own starting data when the run is a failure, not finished, the duration has passed, or the flow has no duration. Passing the duration leaves the displayed run in place until that request.

A parent whose run has ended stays ended when another requester starts a new run of a child.

The entity shows the current run and the validity end. Until a new run starts, an expired run stays displayed with its end in the past.

Silence

Silence is per opened step. The silence duration and the resend maximum come from the entity's starting data.

Without a result at that time, the orchestrator sends the same job again. At the resend maximum the step result is not finished.

An array of children whose rule names withinMin is judged when that duration is reached. A required opening fails when the target is still unmet. An optional opening seals with end reason deadline.

Rate limit

A rate limit is on the step definition: max jobs and a duration durationMs. bindOrganization copies it onto every bound step of that definition. Aliases share the definition and the kind, so they share the limit. The kind is one queue for that organization and that step definition, so every flow that opens the step shares the limit. A step definition with no rate limit has no limit.

The orchestrator sends the job when the step opens. The limit gates when a worker starts it. createStepWorker passes BullMQ limiter with that max and with duration set to durationMs. BullMQ keeps one counter in Redis for that queue. Every worker of the kind increments the same counter when it moves a job to active. The first start in a window sets the counter to expire after durationMs. At max, further jobs stay waiting until the key expires and the next window starts.

Concurrency is how many jobs one worker runs at once. The rate limit is how many jobs the kind starts during one window, across every worker of that kind. Ten workers, each with concurrency 1, and a rate limit of 8 jobs per 1000 ms, start at most 8 jobs of that kind in the window. A concurrency override on a worker changes only that worker's concurrency. The limit stays the one on the step definition. The shared count holds when every worker of the kind is started with that same limit.

Starts at the end of one window and the start of the next can land close together. A job that keeps running past the window still counts as one start. Jobs already active run to the end.

Each environment has its own queue, and that queue has its own counter.

Silence runs from the opening. A job that stays waiting until the silence duration elapses is sent again. At the resend maximum the step result is not finished.

Job and storage

BullMQ only transports the job. The job is organization, entity, and step. Secrets stay off the job. The worker loads that organization's secrets once when it starts and writes them into the environment. The dispatch value carries the starting data and the time, and it carries no secret. A step implementation reads one name with environment in packages/contract/src/environment.ts. A log replaces the value with ••••. A secret added or deleted is visible at the next start of the worker. Each bound step names a kind. The orchestrator sends that job to the Redis queue for that kind. A worker pulls. It does not push when a worker appears, and the HTTP server does not start a worker. Connected workers are presence, not a condition for opening a step. Silence, a resend, and not finished stay on the opened step: a resend is a new job, and the queue does not retry. Postgres keeps the current flow run, one row per entity, plus parent and child links, memberships, and secrets. Each row is carried by its organization. The application stores each secret as given. A transition loads that entity, the children named in its tree, and its running parents. The HTTP server reads that entity row on each read. Entity counts and running counts are cached for a few seconds. After the commit, each new flow metric and step metric is appended to Redis and inserted into ClickHouse in batches. The engine rereads the result on the entity row. It does not reread the metric.

A step may write a transient file for a later step of the same run. The names it writes travel with the result and stay on the step. A replay from a step copies those kept names into the new generation before that generation's jobs are sent. A full replay starts empty and does not copy. It receives the time the orchestrator runs the job. A second run of that step keeps a single effect. The orchestrator records the step when it accepts the result. When a step throws, that result is failed and its discriminant is the error message. A held step stays open.

Person

Tests start the first run through the internal function startRun. A run starts from that function.

A person sees entities, the operation tree, steps and their progress, the current wait, children, the validity end, the flow source, and the transient files of a stored flow run. The Secrets page lists that organization's secrets. A person can add one and delete one. Entity, source, and flow reads do not include a secret. A discarded step stays in that tree and is marked discarded. The Flows page shows flow runs and step runs for a period: counts, failure rate, p50, and the trend come from ClickHouse, and the entity count and running come from Postgres. A person can open the first entity of a flow, replay a flow, replay from a step, resend a job, run a step without applying its result, cancel a run or an open step, and end a validity. The first opening is that request: an open run waits, and inside the validity duration the recorded result is returned.