Skip to main content
The platform invokes the class at a few known points, and the class returns within a budget on each. The Agent class extends Edge Compute’s StatefulActor, and the platform calls it through the actor’s entries. One instance runs one of these at a time, so a handler never interleaves with another on the same conversation. Execution Model has the rest of the rules. A webhook is a request to fetch like any other, and what the function does with it is the function’s own code.

Activation

The platform constructs the class on every activation. The constructor opens the instance’s stores and re-arms the task scheduler before the instance takes a call.
  • StatefulActor receives ctx and env through super(ctx, env). It keeps them as this.ctx and this.env.
  • ctx.storage backs the task scheduler and the state store. The message log and the event log are built on it too.
  • ctx.blockConcurrencyWhile runs the store setup and the re-arm. Every other call waits until both finish. The callback has a 30-second budget.

The Fetch Entry

The class does not override the actor’s fetch. It inherits the default.
  • fetch(req) receives every request to the instance that is not an upgrade. A class that serves the streams and RPC over HTTP overrides it and passes the request to an AgentHttpServer.

The WebSocket Entry

The class overrides the actor’s webSocket and hands each socket to its socket server.
  • webSocket(ws, req) receives the accepted socket and the handshake request. A class that overrides none of the three seams throws before it touches the socket, so the socket is refused.

The Alarm Entry

The instance has one alarm. The task scheduler sets it through ctx.storage, to the earliest due task.
  • ctx.storage.setAlarm receives the earliest due time, in milliseconds since the epoch. Setting it again replaces the previous time, so every task shares the one alarm.
  • ctx.storage.deleteAlarm clears the alarm when no task is pending.
When the alarm fires, the class’s alarm drains every due task and re-arms.
  • alarm(info) is the entry the platform calls when the alarm fires. Every task the drain dispatches runs inside it, under the alarm’s time budget.