Skip to content

Function runners and engines

Functions are first-party code the platform runs for you: small HTTP handlers addressed as {application}.{name}, published as immutable versions and switched with aliases. This page is about the machinery that runs them: the platform side that stores and wires them, the control plane, the runners and their engines.

flowchart LR
  CLI["fcdev fn, CI, console"] -->|"publish, promote"| P["Platform<br/>internal/platform/function"]
  P -->|"wiring at promote:<br/>subscriptions, scheduled jobs, pool"| P
  R["Runner (one deployment per pool)"] -->|"long-poll desired state,<br/>heartbeat, artifacts"| P
  RT["Router, scheduled jobs,<br/>API callers"] -->|"POST /fn/address/path"| R
  PUB["Public traffic by Host"] -->|"public entry"| R
  R -->|"emit, dispatch, token, trace"| P
Part Where Role
Platform internal/platform/function (API /api/functions, control plane /control/functions) Stores functions, versions, aliases, settings and routes; reads each artifact’s describe document at publish; materialises wiring at promote; serves each runner pool its desired state
Runner internal/functions/runner, the FC_FUNCTIONS_ENABLED subsystem Loads the versions its pool should run, serves invocations, provides the host capabilities, reports back
Engine internal/functions/engine Runs ABI v1 modules on wazero; knows nothing of HTTP, routing or auth
JVM host The ingestor runtime Runs jvm functions (jars) with the same control-plane contract

A runner needs no database: it talks to the platform over HTTP with client_credentials as a service account holding platform:function-runner (FC_FUNCTIONS_PLATFORM_URL, FC_FUNCTIONS_CLIENT_ID, FC_FUNCTIONS_CLIENT_SECRET). Each runner serves one pool (FC_FUNCTIONS_POOL, default default); run one deployment per pool and scale it horizontally.

Publish validates; promote materialises. Publishing uploads the artifact to the content-addressed store (FC_FUNCTIONS_ARTIFACT_STORE: file:// or s3://), reads its describe document and validates it, creating nothing else. For Wasm and JavaScript the platform instantiates the module with no capabilities just to call its describe export; for a jar it reads META-INF/flowcatalyst/function.json without executing anything. The version is PUBLISHED until a runner loads it, then READY (or FAILED).

Promoting a READY version to the live alias reconciles, in one transaction, the function’s own dispatch pool (fn-<address>), the subscriptions and scheduled jobs its describe document declares (targets FC_FUNCTIONS_RUNNER_URL with the pool substituted, plus /fn/<address><path>), and its settings. Promote refuses SETTINGS_MISSING when a declared config key, secret or database binding has no value, and POOL_LACKS_RUNTIME when no runner in the pool advertises the version’s runtime: it never falls back silently. Untagged versions beyond FC_FUNCTIONS_KEEP_VERSIONS (20) are pruned after each publish. Details: describe document and ABI.

Route (under the platform base URL) Purpose
GET /control/functions/desired?pool=&wait=&runtimes= The pool’s desired state, long-polled with If-None-Match (the ETag is the revision). The platform answers as soon as the revision moves (LISTEN fng_desired, with a 5-second re-check), so a promote reaches runners in milliseconds. runtimes= filters to what the runner can run
POST /control/functions/heartbeat Per-version state (LOADED, COMPILED, FAILED, RETRYING), the memory report and the runner’s capabilities. The first LOADED marks a version READY
GET /control/functions/artifacts/{digest} The artifact: a redirect to a presigned storage URL, or the bytes. Runners hold no storage credentials
POST /control/functions/events Emit an event on a function’s behalf
POST /control/functions/dispatch-jobs Create a dispatch job on a function’s behalf
POST /control/functions/token Mint a platform token for a function that declares it
POST /control/functions/trace-log Ship trace records

The desired document carries, per function, its address, limits, warm flag, settings (config, secrets, database DSNs), the webhook secret deliveries are signed with, its versions with their roles (live, candidate, alias:<name>) and the pool’s public routes. It holds secrets, so it is served only to the runner role and never logged. The full protocol is in the control-plane reference.

sequenceDiagram
  participant P as Platform
  participant R as Runner
  participant S as Artifact store
  loop long-poll
    R->>P: GET desired (If-None-Match)
    P-->>R: document at a new revision
  end
  R->>P: GET artifact by digest
  P-->>R: 302
  R->>S: download, verify sha256
  R->>R: compile (disk cache), module check
  R->>P: heartbeat LOADED
  Note over R: route to the new live version,<br/>drain and close the old one

Reconcile. For each version it does not hold, the runner downloads the artifact by digest, verifies it, compiles it (with a disk compilation cache) and checks the module. Failures are classified, because the platform latches the first FAILED report:

  • Transient (control-plane 5xx, 429, 408, 401 and 403 from an expired token or presigned URL, network errors, truncated downloads): retried inside the runner with backoff from 1 s to 30 s, for at most 5 minutes (FC_FUNCTIONS_LOAD_RETRY_*), reported as RETRYING meanwhile.
  • Permanent (artifact missing or rejected, digest mismatch, oversized, and every validation, describe, compile or instantiate error): reported FAILED at once.

A new live version takes traffic as soon as it is ready; the old one’s calls drain and then it closes. A platform outage never unloads anything: the runner keeps serving what it has. Warm functions load eagerly; others compile on first call and are evicted after FC_FUNCTIONS_IDLE_EVICT_SECONDS (30 minutes) without calls, recompiling from the disk cache (about 30 ms) when next called. Heartbeats go every 15 seconds and after every change.

Instances. A call takes an instance exclusively from the version’s pool, creating one if none is idle; instances are never shared by concurrent calls. An instance is retired after 10,000 calls (to bound slow leaks in guest allocators), when it breaks or grows too large, and after 60 seconds idle (one is kept for a warm function). Each function has its own concurrency permits (maxConcurrency, default 16 per runner); a call that cannot get one is refused at once with 429 FUNCTION_BUSY and Retry-After, rather than queued.

A version declares one runtime, fixed for the life of the function:

Runtime Artifact Runs on Status
wasm An ABI v1 WebAssembly module (Go, Rust, anything compiled) wazero, in the Go runner Built
js A bundled script The platform’s QuickJS engine (jsengine/engine.wasm, compiled once per runner) on wazero; each function’s script is loaded into its own instances Built
jvm A jar The ingestor runtime’s function host Built (JVM functions in the ingestor)
jsv8 A JavaScript bundle needing V8 and web-standard APIs workerd, as its own runner kind Planned: added only when a function needs it

The engine interface is the boundary: an engine takes a request frame and returns a response frame, and every capability goes through the fc host module. That keeps one contract over several engines (one function contract, several engines).

Routing deliveries per runtime uses FC_FUNCTIONS_RUNNER_URL_<RUNTIME> (for example FC_FUNCTIONS_RUNNER_URL_JVM), each templated with {pool}; a runtime without one uses FC_FUNCTIONS_RUNNER_URL (default http://127.0.0.1:8095).

The echo runner (internal/functions/echorunner) is a test fixture for a made-up echo runtime: it speaks the control protocol, applies desired state only when the revision moves, reports versions in heartbeats and echoes invocations. It proves the plumbing an out-of-process runner relies on, and is not a product.

Each call has a deadline (timeoutMs, default 30 seconds, per endpoint at most the function’s own). How it is enforced depends on who wrote the code:

Runtime Stopped by Cost
Author-compiled Wasm wazero, from outside: the module is compiled with checks at loop headers and function entries Significant on compute-heavy guests, paid only by Wasm functions
JavaScript (the platform’s own engine) The engine, from inside: a QuickJS interrupt handler checks a deadline the host arms before every call; the abort cannot be caught by try/finally Small

For JavaScript a host watchdog waits for the deadline plus a 2-second grace. A call still running then is abandoned: the caller gets 504 FUNCTION_TIMEOUT, the instance is marked broken and closed when the call finally returns, and fc_fn_stuck_calls counts it. Too many stuck calls make the runner report itself unhealthy. Every deadline outcome discards the instance. See JavaScript deadlines.

limit = FC_FUNCTIONS_MEMORY_LIMIT_MB, else the cgroup memory limit, else physical memory
reserve = FC_FUNCTIONS_MEMORY_RESERVE_MB, default max(128 MiB, 10% of limit)
budget = limit - reserve

Every page of guest linear memory is charged against the budget; a grow the budget cannot cover fails inside the guest instead of taking the process down. Compiled code is evicted least recently used (idle versions first, never warm ones) under memory pressure. Per-instance memory is capped by the function’s memoryMb (default 64), a cap charged by use. fcdev gives its in-process runner 256 MB.

A guest reaches the outside only through the fc host module, and only as far as its describe document declares and its settings bind:

Operation What it does Limits
log A log line at a level, written to the runner’s log with the function and invocation
config.get, secret.get Read a declared setting Values come from the platform’s settings
http.fetch Outbound HTTP Hosts must be on the function’s httpAllow list (exact host or *.suffix, default ports only unless a port is given); every dial, including redirects, goes through the outbound guard; no proxy; response size capped
event.emit Emit an event of a declared type Through the control plane
dispatch.create Create a dispatch job to a declared target The platform checks the declaration again and decides everything else: ownership, URL, signing identity
db.query, db.exec, db.begin, db.commit, db.rollback PostgreSQL through a declared binding One pool per distinct DSN on the runner; results capped; open transactions are rolled back when the call ends
platform.token A FlowCatalyst access token as the function’s application service account Cached per function while more than a tenth of its life remains; never logged
trace, tracing, trace.reference Trace records while a trace window is open No-ops otherwise; never block a call

Private entry (FC_FUNCTIONS_BIND:FC_FUNCTIONS_PORT, default 0.0.0.0:8095): /fn/{address}[@{alias}|@v{n}]/{path}. This is where subscriptions and scheduled jobs deliver and where API callers invoke. Each endpoint declares its own authentication: the platform’s delivery signature (verified against the function’s webhook secret), a platform bearer token (verified against the platform’s JWKS; only an API credential is accepted, the caller must reach the function’s client, and invoking an explicit version needs its own permission), or anonymous. A webhook that arrives before the runner has the function’s secret answers 503 WEBHOOK_SECRET_PENDING with Retry-After, and is retried.

Public entry (FC_FUNCTIONS_PUBLIC_PORT, off unless set; fcdev uses 8096): requests are routed by Host and path prefix to a function’s live version (or a route’s alias), using the pool’s public routes. A route’s hostname must be covered by a zone claimed by the function’s own client. A live route may opt into alias prefixes, so qa-<hostname> serves the qa alias. Explicit versions are not reachable here, and each endpoint’s own authentication still applies. X-Forwarded-For is honoured only through proxies listed in FC_FUNCTIONS_TRUSTED_PROXIES. Endpoints may declare a CORS policy, which the runner applies; the guest cannot override those headers.

Request bodies are capped by the endpoint’s maxBodyBytes (default 1 MiB) and never more than 32 MiB.

Every function is first-party code, written and published by the platform’s operators; customers never run their own code. The sandbox gives fault isolation and limited reach: a crashing, leaking or runaway function cannot take down the runner or reach what it did not declare. It is not hardened against a deliberately hostile author, and the engine must not be extended to run third-party code without a new decision. See functions are first-party and the security model.

Variable Default Effect
FC_FUNCTIONS_ENABLED false Run a runner in this process
FC_FUNCTIONS_POOL default The pool this runner serves
FC_FUNCTIONS_PLATFORM_URL, FC_FUNCTIONS_CLIENT_ID, FC_FUNCTIONS_CLIENT_SECRET none How the runner reaches the control plane
FC_FUNCTIONS_BIND, FC_FUNCTIONS_PORT, FC_FUNCTIONS_PUBLIC_PORT 0.0.0.0, 8095, off Listeners
FC_FUNCTIONS_MEMORY_LIMIT_MB, FC_FUNCTIONS_MEMORY_RESERVE_MB from the container, max(128 MiB, 10%) The memory budget
FC_FUNCTIONS_CACHE_DIR none (in memory) Artifact and compilation cache on disk
FC_FUNCTIONS_IDLE_EVICT_SECONDS 1800 Evict an idle lazy version
FC_FUNCTIONS_LOAD_RETRY_INITIAL_MS, _MAX_MS, _BUDGET_SECONDS 1 s, 30 s, 300 s Transient load retries
FC_FUNCTIONS_TRUSTED_PROXIES none Proxies trusted for X-Forwarded-For on the public entry
Platform side: FC_FUNCTIONS_ARTIFACT_STORE, FC_FUNCTIONS_RUNNER_URL, FC_FUNCTIONS_RUNNER_URL_<RT>, FC_FUNCTIONS_KEEP_VERSIONS, FC_FUNCTIONS_TRACE_* see the reference Storage, routing, pruning, traces

See the environment reference and running function runners.

Situation What happens
The platform is unreachable The runner keeps serving every loaded version; long-polls back off and resume
An artifact download fails transiently Retried up to 5 minutes, then FAILED with the attempt count; retried again later
A version fails to compile or validate FAILED at once; promote of that version is refused
A call exceeds its deadline 504 FUNCTION_TIMEOUT; the instance is discarded
A guest asks for more memory than the budget allows The grow fails inside the guest; the runner carries on
Too many calls for one function 429 FUNCTION_BUSY at the permit; other functions are unaffected
No runner in the pool has the runtime Promote answers POOL_LACKS_RUNTIME and a notice shows

fc_fn_invocations_total, fc_fn_duration_seconds, fc_fn_memory_budget_bytes, fc_fn_memory_used_bytes, fc_fn_memory_refused_total, fc_fn_evictions_total, fc_fn_stuck_calls, and the trace counters fc_fn_trace_records_total, fc_fn_trace_dropped_total and fc_fn_trace_flush_failures_total. See the metrics reference.