A signal lets a run wait for something outside it, such as a person’s approval. The workflow declares its signals, the body waits for one at a time, and a tool or a member answers.
Signal waits
A workflow declares the signals it may wait for under signals, each with the value type of its payload. A signal’s name is letters, digits, and _, starts with a letter or _, and has at most 64 characters, which publishing checks. step.waitForSignal(signal, { timeout }) waits for an answer to one of them:
import { boolean, object, workflow, WorkflowSignalTimeoutError } from "@buildr/sdk";
const approveChangeOrder = workflow(
{
description: "Escalates a change order nobody decides on",
input: object({}),
signals: { decision: object({ approved: boolean() }) },
},
async ({ step }) => {
try {
const { payload, sentBy } = await step.waitForSignal<{ approved: boolean }>("decision", {
timeout: "3 days",
});
return { approved: payload.approved, decidedBy: sentBy };
} catch (error) {
if (!(error instanceof WorkflowSignalTimeoutError)) throw error;
await step.do("escalate", async (s) => {
// Escalate through s.forge
});
return null;
}
},
);- Answer: The wait resolves to a
WorkflowSignal:payload, which Forge checked against the signal’s declared type, andsentBy, the id of the caller (member or extension) who answered. - Timeout:
timeoutis milliseconds or a unit string from 1 second to 365 days."1 year"is refused, because Forge counts a year as 365.25 days. Without a timeout, the wait lasts 365 days. When the time runs out,step.waitForSignalrejects with aWorkflowSignalTimeoutErrorwhosesignalproperty names the signal. The body can catch it and carry on; uncaught, it fails the run. - One wait at a time: While a run waits, its status is
waiting, itswaiting_for_signalnames the signal, and itssignal_sequencenumbers the wait, counting the run’s waits from 1. Starting a second wait before the first ends rejects with aTypeError, as does waiting for a signal the workflow doesn’t declare or waiting insidestep.do’swork.
Workflow signal answers
Any tool of the extension answers a run’s signal wait with ctx.workflows.signal:
const { runId, signal, sequence } = await ctx.workflows.signal({
run: runId,
signal: "decision",
payload: { approved: true },
});- Which runs a tool answers: A tool answers the runs that its extension started on the branch it reads. An installation’s tools answer that installation’s runs on
main; a run of another extension or branch fails withExtensionWorkflowRunNotFound. - Checked at the run’s version: The payload is checked against the signal as the run’s pinned version declares it, which may differ from the version the answering tool runs. A signal that version doesn’t declare fails with
ExtensionWorkflowSignalNotFound, a payload that doesn’t fit fails withExtensionWorkflowSignalPayloadDoesNotFitorExtensionWorkflowSignalPayloadDoesNotFitAt, and an answer over 1 MiB of JSON fails withExtensionWorkflowSignalPayloadTooLarge. - One answer per wait: Without
sequence, the answer is for the wait the run is on; with it, only for that wait, thesignal_sequencea read of the run shows. An answer to a wait that was already answered, a stalesequence, or a run that isn’t waiting for the signal fails withExtensionWorkflowSignalNotAwaited(409). - Who answered: The run’s body reads
sentByas the id of whoever the tool acts as: its caller or, for a schedule’s, trigger’s, webhook’s, or mailbox’s run, the extension itself.
Signal answers from a member
A member with signal on the workflow answers a waiting run through the API or the CLI, without a tool, so a person can approve or deny what a workflow waits for:
import { defineExtension, literal, object, string, tool, workflow } from "@buildr/sdk";
const approveChangeOrder = workflow(
{
description: "Waits for a member to approve or deny a change order",
input: object({ changeOrderId: string() }),
signals: { decision: object({ decision: literal("approve", "deny") }) },
},
async ({ step }, { changeOrderId }) => {
const { payload, sentBy } = await step.waitForSignal<{ decision: "approve" | "deny" }>(
"decision",
{ timeout: "3 days" },
);
return { changeOrderId, decision: payload.decision, decidedBy: sentBy };
},
);
const routeChangeOrder = tool(
{
description: "Routes a change order for approval",
input: object({ changeOrderId: string() }),
},
(ctx, input) => ctx.workflows.start("approveChangeOrder", input, { key: input.changeOrderId }),
);
export default defineExtension(
{},
{ tools: { routeChangeOrder }, workflows: { approveChangeOrder } },
);Once the run reads waiting, a member approves it:
forge extensions create-extension-installation-workflow-run-signal --repo "$OPS_REPO" \
--name project-controls.change-orders --run "$RUN_ID" --signal decision \
--data '{"payload":{"decision":"approve"}}'- Request:
POST /repos/:repo_id/extension-installations/:name/workflow-runs/:run_id/signals/:signalwith the body{ payload, sequence }, wheresequenceis optional. For a run that a tool started on a branch of the defining repo, usePOST /repos/:repo_id/branches/:branch/extensions/:name/workflow-runs/:run_id/signals/:signalorforge extensions create-branch-extension-workflow-run-signal --branch. The response is the run,runningagain. - Same checks as a tool’s answer: Forge checks the run, the signal, the payload, and the wait exactly as it checks
ctx.workflows.signal, and refuses with the same errors and statuses. A run of another installation, branch, or repo fails withExtensionWorkflowRunNotFound. - Who may answer: Answering takes
signalon the workflow (Actions), and the body reads the member assentBy. A workflow doesn’t name who may answer a specific signal, so any member whom policies allow tosignalthe workflow can answer it.