Skip to main content
A signal is a small message sent to an environment: every run executing there that listens for the signal’s name receives it. Each run that starts listening also gets the latest signal of that name sent before it started, so a run that starts late still learns the current state.
Signals need the next SDK release after 4.8.10: unstable_signals isn’t in @trigger.dev/sdk 4.8.10 or earlier.Signals are unstable. The SDK exports them as unstable_signals, and names and behavior may change before they are released as stable. Use the SDK rather than the HTTP routes behind it, which may also change.

Listen for a signal in a task

Call unstable_signals.on() inside run(). It returns a function that stops listening. This crawler pauses between URLs while crawl.pause says so, and carries on when it’s switched off:
/trigger/crawler.ts
While it’s paused, the run is still executing: it keeps its concurrency slot and its machine. A run that waits with wait.for() instead can be suspended and free them, but receives no signals until it resumes (how delivery works). The handler receives a Signal with name, payload, task (set when the signal was sent to one task), sentAt and seq. seq increases with every signal sent in the environment, but not by one: compare two values to tell which was sent later, don’t count with them.

A run that starts while paused

A crawler triggered after crawl.pause was sent with paused: true receives that signal without anything new being sent. It arrives once the run’s connection for signals opens, usually within a few seconds of the on() call, not during it. Work the run does before then isn’t paused: in the crawler above, the first URL can be fetched before the signal arrives.

Send a signal

Send from your backend with the secret key of the environment whose runs should receive it: the production key reaches production runs, and your development key reaches runs of your local trigger dev. The SDK reads TRIGGER_SECRET_KEY; to pass the key another way, call configure() first:
Your backend code
Response
send() returns { seq }, the sequence number of the signal. From inside another task, call send() without configure(): the run’s own credentials send to its environment.

Environment-wide and task-scoped signals are kept apart

The environment keeps the latest signal of each name, and separately the latest of each name and task pair. A send to one task replaces only that task’s latest; a send to everyone replaces only the environment-wide latest. A run that starts listening receives both that apply to it, in the order they were sent:
Your backend code
A crawler that starts after these two sends receives { paused: true } (seq 718) and then { paused: false } (seq 720), so it ends up running. A run of any other task receives only { paused: true }. Send { paused: true } to everyone again and every new crawler receives seq 720 and then the new one, and ends up paused. To stop a task-scoped signal from applying, clear it with { task }.

Read the latest signal

latest() reads the current latest signal of a name once, without listening. Use it to check the state before starting work, from a task or from your backend:
/trigger/crawler.ts
It returns the same Signal a listener receives, or undefined when none was sent or it was cleared. Inside a run, it returns the later of the environment-wide signal and the one sent to this run’s task, the last of what on() delivers when it starts. Outside a run, it returns the environment-wide signal, or with { task } the one sent to that task:
Your backend code

Clear a signal

clear() forgets the latest signal of a name, so runs that start listening afterwards don’t receive it, and the name stops counting toward the limit of 32.
Your backend code
cleared is false when there was nothing to clear. Runs that are already listening aren’t told: to switch something off for them, send a payload that means off.

How delivery works

  • Signals are scoped to one environment and delivered in the order they were sent.
  • A run receives signals only while it is executing. A run that is waiting (for example on wait.for()) receives nothing while it waits; when it resumes it gets the latest signal of each name it listens for.
  • A signal is a notification, not a queue. There is no acknowledgement and no per-run delivery record. For work that must happen exactly once, trigger a task.
  • A run that never calls unstable_signals.on() opens no connection for signals.

Authentication

A key limited to selected tasks can’t have Signals access: a signal reaches runs of every task in the environment.

Limits

The SDK checks names and payload size before sending. Other errors from send() and clear():
  • 503 means signals in the environment were busy (many concurrent sends) or briefly unavailable. Retry shortly (after the Retry-After delay when the response has one).
  • 501 means the instance has no realtime streams backend for signals. Self-hosted instances need the S2 streams backend.
The rate limit is there because each send goes to every listening run. Send when state changes, not as a stream of messages; for a stream of data from a run use Streams.

Reserved names

Names that start with trigger. are reserved for the platform. send() and clear() refuse them. Runs can listen for them: chat.agent listens for trigger.skew-protection-threshold to move a running turn to a newer version (see Mid-turn handover).

Data retention

An environment keeps the latest signal of each name until you clear it. When a project or organization is deleted, or a preview branch is archived, its environments’ signals are deleted.