Skip to content

Worker Variables

A worker that needs a setting shared by the whole context, such as a region or a venue's base URL, gets it by reference from the context's platform variables. CreateWorkerRequest.variables maps an attribute name to a platform variable's name:

{
  "mime_type": "application/x-dotnet-dll",
  "topics": ["x.myapp.requests"],
  "config":    { "symbols": "BTC/USD" },
  "variables": { "region": "REGION" }
}

With cfg.env holding {"REGION": "eu"}, the worker sees region=eu. ListWorkers shows the reference REGION, never the value.

Where the values live

The platform variables are one JSON object, name -> value, under the state key cfg.env in the context's shared state service (statestore), the one the operator clients keep their shared pages in. Admins edit them on the clients' Environment variables page (platform scope). The key's name comes from Domain.DevKit's virtufin.pages naming fragment (virtufin.pages/platform_variables). A string value is taken as it is; any other JSON value as its JSON text.

How it works

  1. CreateWorker validates the references and stores them with the worker.
  2. When the worker loads, the Runtime reads cfg.env and resolves every reference. If one is not there, the worker becomes LOAD_FAILED, and the load_failed event says platform variable '<NAME>' not found.
  3. When the worker starts (every activation, also after a move or a self-heal), the Runtime reads them again and gives them to the worker:
  4. as IWorkerContext.Variables (attribute name -> value);
  5. stamped onto every input as CloudEvent attributes, over the event's own attributes, like secrets.
  6. The Runtime drops the variable attributes from everything the worker returns or publishes.

A changed variable reaches a worker at its next start: stop and start it, or wait for its next activation. A worker never sees a variable change mid-activation.

Variables are not secret, but they are handled like secrets anyway: never stored with the worker, never in ListWorkers, never in outputs or logs. Use secrets for credentials.

In each engine

Engine The variables
C# source, .NET DLL (in-process and the bridge) context.Variables
Python ctx.variables (a dict)
TypeScript ctx.variables (an object)
Native (ABI v3) "variables" in the Start payload JSON (absent when there are none)

Every engine also gets them as input attributes.

Rules

What Rule
Name A CloudEvent extension attribute name: 1-20 lower-case letters or digits
Name Not a reserved attribute (CloudEvents core attributes, correlationid, replytopic, publishtopic, traceparent, tracestate)
Name Not also a config key or a secrets name
Reference A platform variable name: [A-Za-z_][A-Za-z0-9_]*

A request that breaks a rule fails with INVALID_ARGUMENT. Variables, like config, cannot be changed after creation: recreate the worker.

The rules, with their exact error messages, live in Virtufin.Worker.Host, so a local WorkManager applies the same ones as CreateWorker:

WorkerReferenceRules member What it does
Validate(config, secrets, variables) The first error in the secret and then the variable references, or null. CreateWorker calls it after WorkerEventRules.ValidateConfig.
ValidateSecrets(secrets, config), ValidateVariables(variables, config, secrets) The two halves on their own.
IsSecretKey(key), IsVariableName(name) The reference patterns.
ResolveVariables(references, platformVariables) Attribute name -> value; throws WorkerVariableNotFoundException (platform variable '<NAME>' not found) for an unknown name. The Runtime resolves through it.

The conformance vectors pin these rules for hosts in other languages: the reference_validation cases (every message) and the per-event vectors with variables (stamped, stripped, an unknown name failing the load).

Config stays the worker's own (see Platform settings or config): use config for a worker's own settings and variables for what the context shares.