ADR 0135: Supervisor Instances and Start Arguments
Status
Implemented (2026-10-21) — BT-3963 (instance-side configuration, args into init) and BT-3962 (spawn family, nesting, discovery) done 2026-10-20 under epic BT-3957; BT-4033 amendment done 2026-10-21. Accepted (2026-10-20); amended 2026-10-21 (BT-4033, hang rule (b) covers every actor child). Extends and amends ADR 0059 and delivers ADR 0080 § Future Work #4 ("anonymous supervisor start"). Specifies BT-3962 and BT-3963.
Context
What a supervisor is today
ADR 0059 made supervisors classes whose configuration is a set of class-side methods: class strategy, class children (static) or class childClass (dynamic), class maxRestarts, class restartWindow, later class initialize: sup (BT-1285), class maxChildren (BT-3964) and class childShutdown (BT-3965). Starting one is MySup supervise, which the runtime turns into
supervisor:start_link({local, 'bt@MySup'}, 'bt@MySup', []) % supervisor_codegen.rs generate_sup_start_link
so every supervisor class is a singleton per node, registered under its module name, supervise is idempotent (ADR 0080's "idempotent-startup convention": Ok(sup) whether this call started it or it was already running), and MySup current is whereis(Module) (beamtalk_supervisor:current/1). The generated init/1 ignores its argument and reads the class-side methods by direct module call (static_init/2, dynamic_init/2). supervise runs in the class gen_server, so a top-level supervisor is linked to the class process.
ADR 0059 was explicit about the consequence: "only one instance of WebApp can run at a time … If two instances of the same topology are needed, define two classes." It also said that an ad-hoc DynamicSupervisor new supervise would use anonymous registration; that was never implemented. ADR 0080 listed the gap as Future Work #4: "Anonymous supervisor start — supervisor:start_link/2 without {local, Name}. Enables per-tenant / per-request supervision trees where the same Supervisor subclass is instantiated multiple times. Requires a companion ADR on how auto-registration-by-class-name interacts with explicit anonymous starts."
This is that ADR.
Why "define two classes" stops working
The Thousand Island port (Catalina, beamtalk-catalina/PLAN.md) needs this tree per running server, with numAcceptors (default 100) copies of the middle layer:
ServerSupervisor (restForOne) args: ServerConfig
├── Listener
├── AcceptorPoolSupervisor (oneForOne) children: 1..numAcceptors
│ └── AcceptorSupervisor[i] (restForOne) args: {i, server, config}
│ ├── ConnectionSupervisor (dynamic) childClass: config handler maxChildren / shutdown: per server
│ └── Acceptor[i] holds its parent AcceptorSupervisor's handle
└── ShutdownListener
Nothing here can be a class-per-instance: the count comes from an option, the handler class is the user's, num_connections and shutdown_timeout are per-server options, and a node may run several servers plus a test suite that starts one per test. Thousand Island also passes each supervisor's own pid down to its children ({server_pid, self(), config}), which a class-side configuration method has no way to express. Today's runtime hard-wires a nested supervisor child to {Module, start_link, []} with id => Class (build_child_spec/2 and the is_supervisor branch of spec_to_otp/2), so a parent cannot even hold two children of one supervisor class, and a DynamicSupervisor whose child class is a supervisor can start only one child.
The same shape already exists in first-party code: beamtalk-exdura's ActivityWorkerSupervisor is a singleton shared by every ActivityWorkerPool ("maxRestarts => 1000 since all pools share this singleton supervisor") where one supervisor per pool is what the design wants; beamtalk-watcher/src/watcher.bt avoids Supervisor because "two Watchers ended up silently sharing one Dashboard"; and the supervisor tests in stdlib/test run serial because each supervise starts the one name-registered process for its class (e.g. dynamic_supervisor_max_children_test.bt, dynamic_supervisor_start_child_name_test.bt).
Constraints
- The post-start hook (today
class initialize: sup) runs in the caller's process. ADR 0080 Option 3 (a helper process) was rejected because it deadlocks against the class gen_server. Any new start path keeps the hook in the caller, and the BT-3759 init gate (keyed by pid) must keep working. - Configuration is read in the supervisor's
init/1, not through the class gen_server (deadlock, see thestatic_init/2doc). Args must reach that path. spawn/spawnWith:are compiler intrinsics for actors.dispatch_codegen.rstry_handle_spawn_awaitlowersClassRef spawn/ClassRef spawnWith: xstraight to actor spawn;self spawn/self spawnWith:in a class method lower tobeamtalk_class_instantiation:class_self_spawn; andtype_checker/validation.rschecksspawnWith:map keys against the class'sstate:fields. None of these look at whether the receiver is a supervisor class.- Instance-side
childrenmeans live children. BT-3966 makesSupervisor>>childrenreturn the running child objects, likeDynamicSupervisor>>children. Whatever replacesclass childrenas the child-spec list must not also be calledchildren. - Class-side configuration cannot see start args or its own process. A class method running in
init/1has no argument and no Beamtalkself(); Thousand Island's tree needs both (init(arg)andself()ininit/1). - Atoms are not collected. Per-instance names must come from a bounded, statically-known namespace (ADR 0079, language-features §
spawnAs:); per-instance ids in a parent must not mint atoms, and neither may per-server names used only to pass a handle down. - Top-level use must not change for the three packages that use supervisors today (their configuration methods may move, mechanically, with a compiler fix-it): exdura (
ExduraSupervisor supervise valueOrDo:relies on idempotence;[application] supervisor =), symphony (class initialize: sup, computedchildrenthat read files), watcher ((MonitorSupervisor supervise) unwrap). - Tooling finds standalone supervisors by registered name.
beamtalk_process_navigation:default_root_pids/0roots the default walk at the app root, the workspace supervisors and every registered Beamtalk supervisor. An anonymous top-level instance is in none of these, soNode current supervisors(ADR 0092) would not see it without a change. [application] supervisor = "X"andbeamtalk_supervisor:register_root/1keep working: the app root stays a named singleton.
Decision
Three changes, one of them breaking: supervisor classes gain the spawn family (§1); configuration moves from class-side methods to instance-side methods read from the instance being started (§2, breaking but mechanical, with a compiler fix-it); and supervisor classes answer supervisionSpec with integer ids allowed (§3). Two narrow behaviour changes ride along: supervise no longer links the tree to the class process (§1), and bare nested supervisor classes become anonymous children (§3).
1. Supervisor classes gain the Actor spawn family; supervise becomes sugar over it
| Message (class side) | Registration | Returns | Exists today? |
|---|---|---|---|
supervise | {local, Module}, idempotent, unlinked | Result(Self, Error) | yes; now sugar over the spawn start helper, no longer linked to the class process |
spawn | none (anonymous), unlinked | Self | new |
spawnWith: args | none, unlinked | Self | new |
spawnAs: name | {local, name}, unlinked | Result(Self, Error) | new |
spawnWith: args as: name | {local, name}, unlinked | Result(Self, Error) | new |
named: name | lookup + class check | Result(Self, Error) | new (mirrors Actor named:) |
current | lookup by Module | Self | Nil | yes, unchanged |
The vocabulary and semantics are Actor's (actor.bt): spawn/spawnWith: raise on start failure, as actor spawn does, with kind #supervisor_start_failed (the kind supervise already uses, where actor spawn uses #instantiation_error). supervise keeps meaning "ensure the application-level instance of this class is running"; spawn means "make one". That is OTP's own split between supervisor:start_link/3 with a name and start_link/2 without.
Named instances. The as: forms return a Result because a name can be taken; a taken name gives #name_registered, the kind actors return. named: returns Result(Self, Error) with the same error kinds as Actor named:: #name_not_registered for an unknown name, #wrong_class for a process that is not a supervisor of this class or a subclass, and #type_error for a non-Symbol name. Names come from a bounded, statically known namespace (ADR 0079): a per-server or per-tenant name must be one of a fixed set, never built from runtime data. Named instances are what observer, a remote shell and sys:get_state see by name, so an operator can find a running Catalina server without holding its handle.
supervise is not a second mechanism. It is defined as the spawn start helper, registered under the class's own module name and made idempotent:
// Supervisor / DynamicSupervisor (class side), in effect:
class supervise -> Result(Self, Error) =>
// the spawn start helper, registered as {local, <module name>}; if already started, answer the running instance
It goes through the same runtime start helper as spawn/spawnWith: (see "Single source of truth"), keeps the two properties nothing else provides (idempotence and a class-derived name that mints no atom and that current finds), and keeps the initialize gate (await_initialized). OTP has no idempotent start; Beamtalk keeps one because re-evaluating MySup supervise in a REPL or workspace, and the [application] boot path, must not fail on the second run. So there is one way to start a supervisor plus one convenience, and the docs' rule supervise ensures, spawn creates describes a single concept.
srv := ServerSupervisor spawnWith: config // anonymous, one per Catalina start:
srv2 := ServerSupervisor spawnWith: otherConfig // a second one on the same node
http := (ServerSupervisor spawnWith: cfg as: #http_server) unwrap // registered; the name must be bounded
(ServerSupervisor named: #http_server) unwrap == http // => true
ExduraSupervisor supervise // still the idempotent singleton
srv stop // per instance; srv2 keeps running
- Compiler carve-out. When the receiver class is a
SupervisororDynamicSupervisorsubclass (class_hierarchy.is_supervisor_subclass || is_dynamic_supervisor_subclass, aspatterns/type_tests.rsalready checks),try_handle_spawn_awaitand theclass_self_spawnarm lowerClassRef spawn,ClassRef spawnWith:,ClassRef spawnAs:,ClassRef spawnWith:as:and theselfforms to a direct call of the runtime start helper in the caller's process (as actor spawn is lowered), not to ordinary class-method dispatch. Ordinary dispatch on a non-sealed supervisor class would run the whole tree start inside the class gen_server, assupervisedoes today: everyspawnWith:,named:,superviseandcurrenton that class would queue behind tree starts, and any child that sent to the class during start would deadlock. Dynamic sends (cls spawnWith: xwithclsunknown at compile time) take the same route actorspawnWith:does inbeamtalk_class_dispatch:class_send/3, which hands the start to the runtime helper rather than running it in the class process. The stdlib spawn-family methods exist for documentation, reflection andrespondsTo:, and delegate to the same helper.superviseuses the same helper, so it too stops running the tree start in the class process. The type checker skips thespawnWith:key check againststate:fields for supervisor receivers: supervisors have nostate:and their args are free-form. Constructor inference (spawn→ instance of the class) is unchanged and already matches-> Self. - Not linked. A top-level supervisor started by
spawn*orsuperviseis unlinked from the caller and from the class process, likeActor spawn(beamtalk_actor:safe_spawn/2). To tie its lifetime to something, nest it viasupervisionSpecorstopit. Forsupervisethis is a behaviour change: todaysuperviseruns in the class gen_server, soproc_lib:start_linklinks the tree to the class process. That link was never designed and has already done harm: exdura documents that exhaustingExduraSupervisor's restart intensity "took the whole class down with it" (beamtalk-exdura/src/http/exdura_http_server.bt,startListeningdoc). No package relies on the class process dying with its supervisor (grepped exdura, symphony, watcher). - Discoverable. Every anonymous top-level instance joins the
pggroupbeamtalk_supervisor_instances(defaultpgscope, already started inbeamtalk_bootstrap). It joins from its owninit/1, beforestart_linkreturns, so there is no window in which the instance runs but is not listed. The start helper tellsinit/1that this is a top-level start through the init arg (a wrapper term the generatedinit/1unwraps before reading configuration); nested and dynamically started instances do not join, because the parent walk already reaches them.default_root_pids/0addspg:get_local_members(beamtalk_supervisor_instances)(this node's instances only: the default scope is synced across connected nodes, see ADR 0126 §4); the existing pid dedup covers instances that are also nested.pgdrops a member when its process exits, soNode current supervisorslists a spawned instance while it runs and not afterstop. Named instances are found by the existing registered-name scan. initializebecomes an instance method (wasclass initialize: sup). It fires once for every top-level start (superviseand every spawn-family message), in the caller's process, through the existingbeamtalk_supervisor_newpost-dispatch hook, which now sendsinitializeto the new instance instead ofinitialize:to the class. That is where supervisor instance methods already run (beamtalk_message_dispatch:send/3), so inside itselfis the new supervisor andself argsits start args, and messages toselfwork (the supervisor is pastinit/1). It does not fire for a nested instance or when OTP restarts one (same rule as today).await_initializedstayssupervise-only. The default is a no-op onSupervisor/DynamicSupervisor. Actors already spell their hookinitialize; supervisors now match.
2. Configuration moves instance-side and is read from the instance being started
Supervisor configuration stops being class-side. Each setting is an instance method, and the runtime calls it on the supervisor being started, from inside that supervisor's init/1. So self is the supervisor's own handle and self args is its start args. There is one form per setting, with the default on the base class:
// Supervisor (stdlib/src/supervisor.bt), instance side
childSpecs -> List => self subclassResponsibility // was: class children
strategy -> SupervisionStrategy => #oneForOne // was: class strategy
maxRestarts -> Integer => 10 // was: class maxRestarts
restartWindow -> Integer => 60 // was: class restartWindow
args -> Object => ... // new: the start args, nil for supervise / spawn
// DynamicSupervisor (stdlib/src/dynamic_supervisor.bt), instance side
childClass -> Class => self subclassResponsibility // was: class childClass
maxChildren -> Integer | Symbol => #infinity // was: class maxChildren
childShutdown -> ShutdownTimeout | Nil => nil // was: class childShutdown
maxRestarts -> Integer => 10
restartWindow -> Integer => 60
(The literal defaults are today's class-side defaults, moved unchanged.)
A static supervisor reads exactly as before, without class:
Supervisor subclass: WebApp
strategy => #oneForAll
childSpecs => #(DatabasePool HTTPRouter)
The Catalina tree:
Supervisor subclass: AcceptorPoolSupervisor
childSpecs =>
((1 to: (self args at: #config) numAcceptors) collect: [:i |
AcceptorSupervisor supervisionSpec withId: i
withArgs: #{#id => i, #server => (self args at: #server), #config => (self args at: #config)}]) asList
Supervisor subclass: AcceptorSupervisor
strategy => #restForOne
childSpecs => #(
(ConnectionSupervisor supervisionSpec withId: #connections withArgs: (self args at: #config)),
(Acceptor supervisionSpec withId: #acceptor withRestart: #permanent
withArgs: #{#id => (self args at: #id), #parent => self, #config => (self args at: #config)}))
DynamicSupervisor(Handler) subclass: ConnectionSupervisor
childClass => self args handler
maxChildren => self args numConnections
childShutdown => self args shutdownTimeout
-
Why instance side. Configuration is a property of a running supervisor, and every input it needs (start args, its own identity) belongs to the instance. Class-side methods had neither, which is why the earlier draft needed a keyword variant of every method (
childSpecsFor: args), a second variant carrying the handle (childSpecsFor: args supervisor: sup), a compile error for classes that defined two forms, and a pre-start check that evaluated the methods a second time. Instance-side methods need none of that:self argsreplaces the argument,selfreplaces the handle, and there is one method per setting. -
Names.
childSpecs, notchildren: instance-sidechildrenreturns the live children (BT-3966). The other settings keep their names. -
How they are called. The generated
init(Args)passesArgstostatic_init/3/dynamic_init/3. These store the args in the process dictionary ('$beamtalk_sup_args'), build the handle{beamtalk_supervisor, ClassName, Module, self()}, and send each setting to it through ordinary instance dispatch (beamtalk_message_dispatch:send/3→beamtalk_dispatch:lookup/5, which already serves supervisor instance methods in the caller's process). User overrides, inherited defaults and ADR 0084 runtime overrides all resolve as for any instance method. This replacescall_class_method_directfor configuration; the class gen_server is still not involved. -
Args path.
X spawnWith: a,spawnWith: a as: nand a parent'sX supervisionSpec withArgs: areach OTPinit(a);supervise,spawn, a bare nested class and a spec withoutwithArgs:givenil. OTP restart replays the same args, so a restarted instance recomputes the same children, child class and limits.DynamicSupervisor startChild: awith a supervisor child class passesaas that child's args.sup argsalso works from outside: it reads'$beamtalk_sup_args'viaerlang:process_info/2(the pattern ofmax_children/1) and returns#stale_handlefor a dead process. -
Calling
selfduring configuration fails fast. The configuration methods run inside the supervisor's owninit/1. Readingself argsis a process-dictionary read, but any message that reaches the supervisor process (self count,self childWithId:) is agen_server:callto itself, which OTP rejects at once withcalling_self. The runtime maps that exit to#supervisor_start_failedwith the hint "configuration methods run inside the supervisor's init; useself argsand return specs, do not send messages toself". Passingselfas a value (#parent => self) is the intended use. -
Parent handle and the hang rule.
self, passed down in a child's args, is how a child gets its parent; nothing else is needed (no hook variant, no ancestor lookup), and replaying it on restart is safe because a child never outlives its parent. The rule: never synchronously call a supervisor from code that supervisor is waiting on. A supervisor waits on (a) its own configuration methods and those of every nested supervisor child (they run inside its synchronousinit/1or thestart_linkof that child;supervisorcalls useinfinity, so a call to the parent or any further ancestor hangs for ever; a call toselffails fast as above); (b) theinitializeof every actor child (as amended by BT-4033 below; originally only awithName:orwithClassMethod:actor child), started throughsafe_spawn_named/safe_spawn→await_initialize(sys:get_state(Child, 5000)), so a call back stalls 5 s and then fails the start. This applies during the initial start, every OTP restart and everyDynamicSupervisor startChild:: the supervisor blocks in the child's start function in all three. (The original text excepted an unnamed actor child, whoseinitializethen ran afterstart_linkhad returned; BT-4033 removed that exception, see the amendment below.) A child's first parent call belongs in acontinueWith:step (BT-3968), as Catalina's acceptor does. The rule goes in thechildSpecsdoc and the language-features section; the compiler cannot check it.Amendment (2026-10-20, BT-3992): (b) covers
initializeitself, not the continuations it requests. A child's start now ends wheninitializereturns: the actor pushes an ack to the starter from theinitializestep ofhandle_continue/2, andawait_initialize/3waits on that ack (or the child's'DOWN') instead ofsys:get_state, which queued behind the whole continuation chain. As with OTP's{continue, _}afterinit/1, continuations requested ininitialize(continueWith:, BT-3968) run after the supervisor's start of the child has returned, still before any later message. They do not count against the 5 s limit, and a synchronous parent call from them neither hangs nor fails the start: acontinueWith:step requested ininitializeis the documented place for a child's first parent call. A call frominitializeitself still stalls 5 s and fails the start. The flip side: a continuation that crashes or stops the child no longer fails the start; the supervisor sees it as an ordinary post-start exit, restarted per the child's restart policy and counted against restart intensity.Amendment (2026-10-21, BT-4033): awaited start for every supervised actor child. Rule (b) now covers every actor child, not just
withName:/withClassMethod:ones: the start of an anonymous static child (X supervisionSpec,withArgs:) and of aDynamicSupervisorpool child (startChild,startChild:) also returns only once the child'sinitializehas returned, exactly likespawn(BT-3992) and like OTP, whereinit/1returning{stop, Reason}failsstart_link. Every supervised actor child that is not awithClassMethod:factory starts through one helper,beamtalk_supervisor:start_actor_child/2,3(beamtalk_actor:safe_spawn_linked/2for an anonymous child,spawnAs/3/spawnAsGlobal/3for a named one; all three sharestart_link_and_await/3). It answers{ok, Pid}or{error, Reason}(neverignore), lifting the child's#beamtalk_error{}out of its stop reason so the parent's#supervisor_start_failed/#child_start_failedhint is the child's own error. Consequences: (1) aninitializethat raises fails the parent's start instead of the child crash-looping after a reported success; on an OTP restart it fails that restart, which counts against restart intensity; (2) a synchronous call from any actor child'sinitializeto its supervisor or an ancestor (which:,childWithId:,children, a send to a sibling not yet started) stalls until the 5 s init timeout and fails the start, with a hint naming this rule; (3) a slowinitializedelays the tree's start (children start in order), and one over 5 s fails it; (4) the process that started the supervisor or calledstartChildis blocked too, soinitializemust not call it either (an owner actor passing#owner => selftostartChild:, or a class method that runsXSup spawnand whose class the child messages); (5) each failed or hung restart blocks the supervisor for up to 5 s, so a hanging child under intensity N makes it unresponsive for about 5·N s, and a$gen_callthe killed child had already sent to the supervisor is still served afterwards. There is no opt-out: slow or parent-dependent setup goes in acontinueWith:step, which runs after the start has returned. Catalina'sListenerwithClassMethod: #startFor:workaround (BT-4027) is no longer needed. -
Per-instance
childClass,maxChildren,childShutdown.dynamic_init/3reads the three settings from the instance and stores the child class ({ChildClass, ChildModule}, key'$beamtalk_child_class') next to?MAX_CHILDREN_KEY.startChild/1,2,3read it through one helper (pool_child_class/1, also used by BT-3966'sDynamicSupervisor children). Where the process dictionary is unavailable (a remote supervisor, or one started before the upgrade), the helper reads the child module from the pool'ssimple_one_for_onetemplate (supervisor:get_childspec/2, which works remotely) and maps it to its class, or returns a structured#beamtalk_error{}. A pool still has exactly onesimple_one_for_onechild spec;childShutdownfeedsapply_child_shutdown/2as today. This replaces BT-3972 (per-startChild:shutdown, cancelled): OTP'ssimple_one_for_oneholds one spec, and Catalina's need is per server, not per child. -
Validation happens once, in
init/1.validate_max_children/2andvalidate_child_shutdown/2run indynamic_init/3on the values the instance returned. A bad value failsinit/1, which the start helper already reports to the caller as#supervisor_start_failedwith the validator's hint (BT-3965'sstart_link_trapping_exits), and fails the parent's start for a nested instance.precheck_dynamic_configis deleted: it existed only because class-side values could be read before start, and with args-dependent values it would have to run the methods twice. -
Purity is unchanged: configuration runs inside the new supervisor process during
init/1underbeamtalk_class_vars:with_snapshot/2, aschildrendoes today. Class-variable writes raiseclass_state_read_only(ADR 0130), and a raise fails the start. Arg lifetime: args are stored in the parent's child spec and replayed on every restart, so any pid or handle in them must outlive the child. An ancestor's handle does. A sibling's pid, a socket or a caller's pid does not; aDynamicSupervisor startChild: awhoseacarries such a resource must use#temporary(the default), so OTP never replays it. -
Only
class supervisionPolicystays class-side. It describes how the class behaves as a child of another supervisor, which is a property of the class.initializemoves to the instance side (§1), so a supervisor's configuration and lifecycle are all instance methods. -
Removed class-side configuration is a compile error, not a silent no-op. A supervisor subclass that defines
class children,class childClass,class strategy,class maxRestarts,class restartWindow,class maxChildren,class childShutdownorclass initialize:gets an error with a fix-it: "class childrenis no longer read; define instance-sidechildSpecs", "class initialize: supis now instance-sideinitialize; useselfforsup", and "dropclass" for the others. The check lives insupervision_validators.rs(check_class_side_supervisor_config). The existing restart-policy warning (check_children_supervision_policy) scanschildSpecsbodies instead ofclass children.
3. Supervisor classes answer supervisionSpec, and child ids may be integers
Today supervisionSpec lives on Actor and a nested supervisor child is built by hand with start_link/0 and id => Class. Now:
MySup supervisionSpecreturns aSupervisionSpecwithactorClass= the supervisor class,type => supervisor,shutdown => infinity, restart fromclass supervisionPolicy(default#permanent, OTP's default for supervisor children).withId:,withArgs:,withRestart:,withShutdown:(BT-3965) apply as for actors;withName:registers the child under that name (a bounded name, ADR 0079).scope: #globalandwithClassMethod:fail the parent's start with a structuredtype_errornaming the supported fields: a class-method factory would run the start in the class process and link the child to it instead of the parent.SupervisionSpec withId:acceptsSymbol | Integer. OTP child ids are any term; integers are what a generated pool wants and they do not touch the atom table. Lookup and control by id are BT-3966.- Codegen emits
start_link/1(anonymous,supervisor:start_link(M, Args)) andstart_link/2(supervisor:start_link({local, Name}, M, Args)) beside the existingstart_link/0, which now passesnilas the init arg.init/1forwardsArgstostatic_init/3/dynamic_init/3;static_init/2/dynamic_init/2stay asnil-args wrappers so previously compiled modules still start (ADR 0125). - In
spec_to_otp/2's supervisor branch, a static child starts through a runtime trampoline,{beamtalk_supervisor, start_supervisor_child, [M, Args]}or[M, Args, Name](withName:), not{M, start_link, …}directly. The trampoline callsM:start_link/1,2whenMexports them and falls back toM:start_link/0for a child module compiled before this ADR (ADR 0125: a parent recompiled first must not fail withundefon an old child; the old child then ignores args and registers under its module, as today). It is the same entry the DynamicSupervisor template below uses, so static and dynamic supervisor children have one start path. - DynamicSupervisor of supervisors needs an indirection template.
simple_one_for_oneappends thestartChild:arguments to the template MFA, so a plain{M, start_link, []}template would make a no-argstartChildcall the registeredstart_link/0(the second child failsalready_started), andstartChild:name:would land onstart_link/2with its arguments in the wrong order. The template is{beamtalk_supervisor, start_dynamic_supervisor_child, [M, DefaultArgs]}with arities 2/3/4 forstartChild/startChild:/startChild:name:, mirroring the existingstart_dynamic_child/2,3,4for actor children. EachstartChildstarts a new anonymous supervisor child, andstartChild:name:registers it.
Behaviour change: a bare supervisor class in childSpecs becomes an anonymous child. build_child_spec/2's hand-built supervisor branch is deleted; a bare class goes through Class supervisionSpec → childSpec → spec_to_otp/2 like any other child (see "Single source of truth"). So a nested InnerSup is no longer registered under its module name: InnerSup current no longer finds it, and InnerSup supervise no longer returns the nested instance (it starts a separate singleton). Use parent which: InnerSup or BT-3966's by-id lookup instead. Nothing in this repo or in the sibling beamtalk-* repos relies on the old behaviour (grepped), and the change removes a footgun: two parents that each nest the same bare supervisor class used to fail with already_started.
REPL session
pool := AcceptorPoolSupervisor spawnWith: #{#config => cfg3, #server => nil} // cfg3 numAcceptors = 3
pool count // => 3
pool whichChildren collect: [:c | c id] // => #(1, 2, 3) (BT-3966)
pool2 := AcceptorPoolSupervisor spawnWith: #{#config => cfg1, #server => nil}
pool == pool2 // => false
AcceptorPoolSupervisor current // => nil (spawned instances are not "current")
pool args at: #config // => cfg3
pool stop. pool2 stop
Error examples
ServerSupervisor spawnWith: cfg as: #http_server
ServerSupervisor spawnWith: cfg as: #http_server
// => Result error: #name_registered (the kind actors return from spawnAs:)
ServerSupervisor named: #no_such_server
// => Result error: #name_not_registered
ServerSupervisor named: #counter // #counter is an actor
// => Result error: #wrong_class
DynamicSupervisor subclass: Pool
class childClass => Worker
// ⛔ Error: `class childClass` is no longer read by DynamicSupervisor; define it on the
// instance side (drop `class`): `childClass => Worker`.
Supervisor subclass: Broken
childSpecs => self count > 0 ifTrue: [#()] ifFalse: [#(Worker)]
Broken spawn
// => raises #supervisor_start_failed: configuration methods run inside the supervisor's
// init; use `self args` and return specs, do not send messages to `self` (calling_self).
pool := AcceptorPoolSupervisor spawnWith: #{} // childSpecs: self args at: #config is missing
// => raises with kind #supervisor_start_failed, wrapping the error from inside init —
// same as a failing `class children` today.
ConnectionSupervisor spawnWith: (cfg withNumConnections: -1)
// => raises #supervisor_start_failed with the maxChildren validator's hint (from init/1)
Single source of truth
- Child-spec construction stays in
SupervisionSpec childSpec(Beamtalk) →spec_to_otp/2(Erlang). The supervisor branch ofbuild_child_spec/2is replaced byClass supervisionSpec, so there is one builder, not two. - The spawn family and
superviseare implemented by one runtime start helper (generalisingstart_link_trapping_exits/1to take the start fun, and unlinking after start), usingsupervisor:start_linkwith or without{local, Name};superviseis that helper with{local, Module}plus "already started → return the running instance";named:iswhereisplus a class check;{already_started, _}maps through the actorspawnAs:error builder. No second registry. - Configuration defaults live in the
Supervisor/DynamicSupervisorstdlib instance methods, not in codegen or the runtime; the runtime reads every setting by sending it to the instance, once, ininit/1. There is no second resolver and no pre-start evaluation.
Prior Art
| Platform | Instances | Args |
|---|---|---|
| Erlang | supervisor:start_link(Mod, Args) anonymous; start_link(Name, Mod, Args) named | Args → Mod:init(Args) returns {ok, {Flags, ChildSpecs}}; one module serves any number of trees; self() in init/1 is the supervisor |
| Elixir | use Supervisor; start_link(arg) with optional name:; placed in a parent as {MySup, arg} | init(arg) builds children from arg; DynamicSupervisor has max_children and heterogeneous start_child/2 |
Gleam gleam_otp | `static_supervisor.new(strategy) | > add(...) |
| Akka | supervision is a property of every actor; no supervisor objects | n/a |
| Pharo / Squeak | no supervision; instances come from class-side creation messages (new, on:, with:) | arguments are keyword parts of the creation message |
Adopted: Smalltalk's class-side creation messages (the spawn family, with keyword arguments), Erlang's named/anonymous split and init(Args), Elixir's "a supervisor is placed in its parent as {Module, arg}" (our supervisionSpec withArgs:), and Thousand Island's use of self() in init/1 (our self in childSpecs). Adapted: Beamtalk keeps per-setting methods (ADR 0059) rather than one init returning a spec, and moves them to the instance, where Erlang's init/1 already lives. Rejected: Gleam's builder value — Beamtalk supervisors are classes, and a builder would be a second way to say what childSpecs already says.
User Impact
-
Newcomer.
spawnon a supervisor does whatspawnon an actor does, including not linking to the caller. Configuration is ordinary instance methods,self argsis the input, andselfis this supervisor. Leftover class-side configuration is a compile error that names the fix. -
Smalltalk developer. Class-side factory messages, same protocol family as
Actor; nothing declarative added to the class body. -
Erlang/BEAM developer. Every OTP concept has a direct counterpart:
OTP / Elixir Beamtalk (this ADR, BT-3966) supervisor:start_link(Mod, Args)MySup spawnWith: args(spawnpassesnil)supervisor:start_link({local, N}, Mod, Args)MySup spawnWith: args as: #nwhereis(N)MySup named: #nMod:init(Args)the configuration methods, reading self args{ok, {#{strategy, intensity, period}, Children}}strategy,maxRestarts,restartWindow,childSpecsself()insideinit/1selfinside those methodschild spec map; Elixir {Mod, Arg}Mod supervisionSpec withId: … withArgs: …simple_one_for_one+ templateDynamicSupervisor+childClassElixir max_children; childshutdownmaxChildren;childShutdown,withShutdown:which_children,terminate_child,restart_child,delete_childwhichChildren,terminateChild:,restartChild:,deleteChild:(BT-3966)"never call yourself from init"the same rule; OTP's calling_selfbecomes#supervisor_start_failedwith a hintThree deliberate differences.
init/1is split into one method per setting, so a subclass overridesstrategyalone and inherits the rest; each method is a separate send, so expensive work (reading files, say) belongs inchildSpecsonly, not repeated in several settings.supervise(idempotent "ensure it is running") has no OTP counterpart; it serves REPL re-evaluation and the[application]boot path.initializeruns after start in the caller, where an Erlang programmer would put code afterstart_linkreturns. -
Operator. Anonymous instances show up in
Node current supervisorsby pid and class through thebeamtalk_supervisor_instancespggroup. Nothing about[application]roots or top-levelcurrentchanges; a nested bare supervisor is no longercurrent. Hot reload: as ADR 0059 noted, a reloaded supervisor class does not change live child sets; with N instances there are N to restart. Documented, not solved here. -
Tooling developer.
default_root_pids/0gains thepggroup.supervisionSpecon supervisor classes, instance-side configuration methods andwithId: Integerare the surface changes visible to the LSP; the type checker no longer flagsspawnWith:keys on supervisor classes.
Steelman Analysis
B: supervise always starts a fresh instance; superviseAs: registers
- 🧑💻 Newcomer: "One verb. I never have to ask whether
supervisegave me an old process." - ⚙️ BEAM veteran: "
start_linknever hands back an existing pid; keeping that behaviour insupervisekeeps a surprise alive." - 🎨 Language designer: "You are already breaking supervisor code in this ADR. Break this too and end up with one start verb instead of two."
C: class-side class registration => #singleton | #none
- 🧑💻 Newcomer: "No new messages to learn."
- 🎩 Smalltalk purist: "A declarative class property, like
strategy."
D: single init: args returning the whole spec (Elixir style)
- ⚙️ BEAM veteran: "Exactly
init/1, and honest about it: you can see you are insideinit, so nobody expects to message the supervisor from there. Instance-side configuration methods makeselflook like an ordinary supervisor that you cannot actually talk to." - 🎨 Language designer: "One override point instead of seven methods, the whole topology readable in one place, and no special rule about which instance methods run inside
init/1."
F: keep class-side configuration and add …For: args hooks (this ADR's first draft)
- 🏭 Operator / existing user: "Zero migration. Some 150 class-side definitions across stdlib, docs and four packages keep compiling, and every existing tutorial stays right."
- 🎩 Smalltalk purist: "Settings that describe a kind of supervisor (its strategy, its restart limits) are class knowledge; the instance side is for the behaviour of a running thing."
E: a new verb (start / startWith:) instead of spawn
- 🎨 Language designer: "No compiler carve-out:
spawnstays an actor intrinsic and supervisors get their own word." - ⚙️ BEAM veteran: "A supervisor is started, not spawned."
G: an ancestor accessor (self supervisor, from '$ancestors') instead of passing self down
- ⚙️ BEAM veteran: "
proc_libalready records the parent. It is correct after every restart with nothing replayed, and every child gets it, including ones whose specs never mention it."
H: defer the named forms (spawnAs:, named:, withName:)
- 🎨 Language designer: "No current user needs them; ship the smallest surface and add them on the same helper later, without breaking anything."
Arguments for shipping them now (adopted)
- ⚙️ BEAM veteran: "Registered names are how you find things from observer, a remote shell or
sys:get_state. An anonymous Catalina server is invisible to all of them." - 🧑💻 Newcomer: "Actors have
spawnAs:; finding it missing on supervisors is a surprise."
Tension points
- D's context argument is the strongest case against the decision. Instance-side configuration runs in an unusual place (inside the supervisor's own
init/1), andselfthere is a handle you can pass but not message. The decision accepts that because the failure is immediate and explained (calling_self→#supervisor_start_failedwith a hint), only the configuration methods run there, and D would make every subclass rebuild the full flags-and-children value to change one setting, which is the per-setting design ADR 0059 chose deliberately. The cost is a rule users must learn; it is documented, not removed. - F's zero migration is the honest price of the decision. The decision trades a one-time, mechanical, compiler-guided migration (while every supervisor user is first-party) for one form per setting forever. F would keep two forms of every setting, a both-forms compile check and a pre-start evaluation for the life of the language. The purist's "class knowledge" point is real for
strategyand restart limits, which rarely vary per instance; it does not hold forchildSpecsorchildClass, which Catalina computes per instance, and splitting the settings between the two sides would be worse than either. - B is rejected on merit, not compatibility. This ADR breaks configuration anyway, so "it would break exdura" is not the argument. The argument is that an idempotent "ensure it is running" start is useful in its own right, for re-evaluated REPL and workspace code and for the
[application]boot path, and definingsuperviseas sugar over the same helper means it costs no second mechanism. The surprise B wants to remove shrinks to "a second call returns the running instance", which is the point of the message. - G is deferred, not rejected. Passing
selfcovers Catalina, and an accessor can be added later without breaking anything. H's deferral was rejected: without names, a running Catalina server is a bare pid to observer, a remote shell andsys:get_state, which matters as soon as it runs in production, and the named forms cost little on the shared start helper. - E trades a compiler special case for a new word users must learn and that collides with their own
start:facades; the decision pays the carve-out once. - Who sides with whom: existing users and operators side with F (no migration). Newcomers and Smalltalk developers side with the decision (one form,
selfandself args, the sameinitializehook as actors). BEAM veterans split between the decision and D.
Alternatives Considered
B: supervise starts fresh; superviseAs: registers
Rejected on merit (see Tension points): an idempotent "ensure it is running" start is needed for re-evaluated REPL/workspace code and the [application] boot path, and as sugar over the spawn helper it adds no mechanism. Everything B offers is available as spawn. (It would also break ExduraSupervisor supervise valueOrDo:, current after supervise, the repl-protocol supervisor.btscript / supervisor_initialize.btscript cases and ADR 0080's idempotent-startup convention, but that is secondary: this ADR breaks configuration anyway.)
C: class-side registration switch
Rejected: a class could not be both an app root (named) and a per-test instance (anonymous), which Catalina's test suite needs; and the meaning of supervise would depend on a declaration elsewhere.
D: class init: args returning a spec
Rejected: ADR 0059 chose per-setting methods and documented why. Moving those methods to the instance gives D's main benefit (configuration computed from init's argument, with access to the supervisor) without collapsing every setting into one return value that each subclass must rebuild.
E: start / startWith: instead of spawn
Rejected: it would avoid the intrinsic carve-out, but start: is a common user facade name (symphony, watcher, exdura, http, Catalina), and the spawn family already carries the named / unnamed / named: semantics users know from Actor.
F: keep class-side configuration and add …For: args hooks
The earlier draft of this ADR: every class-side setting gains a keyword variant (childSpecsFor:, strategyFor:, … seven in all), plus childSpecsFor:supervisor: for the parent handle, with delegating defaults. Rejected: two forms of every setting, a compile error for classes that define both, a pre-start check that evaluated the methods twice, and a special variant just to pass self. Instance-side methods give the same power with one form per setting, at the cost of a mechanical migration.
G: an ancestor accessor (self supervisor, from '$ancestors') for the parent handle
Deferred: with instance-side configuration the parent passes self explicitly, which is visible in the code and needs no pid-to-handle mapping. An accessor can be added later, without breaking anything, for children that were not given their parent.
H: defer named supervisor instances
Rejected: operability. A server started with spawnWith: alone is only a pid to observer and remote shells; spawnWith:as: gives it a name, and the named forms mirror Actor exactly on the same start helper.
children: as the configuration name
Rejected: with BT-3966's live-children sup children, the same name would mean "running children" and "child specs" on the same object.
superviseWith: args
Rejected: the instance's identity (singleton or not) would depend on whether args were passed.
Keep singletons; have Catalina generate classes
Rejected: numAcceptors is a runtime option and the handler class belongs to the user; code generation at start time is not a thing Beamtalk does.
Consequences
Positive
- Libraries can build OTP-shaped trees from runtime configuration, including per-server limits and parent handles; Catalina Phase 2 is unblocked, exdura's per-pool supervisor becomes expressible, supervisor tests no longer need to be serial.
- No change to how top-level code starts supervisors; the spawn vocabulary and its unlinked semantics are already known from
Actor. - Delivers ADR 0080 Future Work #4 with the
Result(Self, Error)shape it asked for. - A nested bare supervisor class no longer fails
already_startedin a multi-instance parent, and a DynamicSupervisor of supervisors can start more than one child.
Negative
- Two entry points to learn (
supervisevsspawn), differing only in idempotence and the implicit name;superviseis sugar over the same start helper, not a separate path. The docs must state the rule in one sentence:superviseensures,spawncreates. - Behaviour change:
superviseno longer links the tree to the class process. A supervisor that exhausts its restart intensity now dies alone instead of taking its class process down (the exdura failure); code that relied on the class process dying with it would notice, and none is known. spawn/spawnWith:are no longer uniformly actor intrinsics: codegen and the type checker each need a supervisor carve-out, and must keep it as the intrinsics evolve.- Breaking: class-side configuration (
class children,class strategy,class childClass, …) moves to the instance side, andclass childrenbecomeschildSpecs. About 75 definitions in stdlib, tests and examples, ~60 in docs, and 17 across exdura, symphony, watcher and catalina. The change is mechanical and the compiler names the fix for each one. - Configuration methods run in an unusual context: inside the supervisor's own
init/1, where messages toselffail (calling_self). Other supervisor instance methods run in the caller. One sentence in the docs, and the failure is immediate and explained. - The parent handle is a hang hazard: calling a supervisor from code it is waiting on (its configuration methods, nested supervisors' configuration methods,
withName:/withClassMethod:children'sinitialize) hangs during start, restart andstartChild:. It is a documented rule, not something the compiler can check, and unnamed children that call early still wait up to the 5 s call timeout. - Behaviour change: a supervisor nested as a bare class is anonymous, so
InnerSup currentreturns nil for it andInnerSup supervisestarts a separate instance. - Anonymous instances are only reachable through the object you hold or
Node current supervisors, same as anonymous actors; name the ones operators need to find (spawnWith:as:). - Class-based
which:andterminate:lose their meaning in multi-instance parents:which: AcceptorSupervisoranswers the first of 100 matching children, andterminate: aClasstreats the class name as the child id, so on integer-id orwithId:children it silently does nothing. BT-3966 fixesterminate:(resolve by module,#ambiguous_childon several matches);which:should get the same#ambiguous_childrule there. Until then, use by-id control. - Integer ids widen types that tooling assumes are atoms:
beamtalk_process_navigation:classify/3(Id :: atom() | undefined) andwhichChildren/1({ok, [atom()]}) need their specs widened, and REPL rendering of supervision trees must print integer ids. - Runtime class-method overrides (ADR 0084) can still install a class-side
children/strategy/… that the compile-time check never saw; the runtime ignores it. The override path warns when it installs a removed class-side configuration selector on a supervisor class. - Hot upgrade: a parent's child specs built before the upgrade still name
{M, start_link, []}, so an OTP restart of a nested supervisor after the upgrade recreates a registered child until the parent itself restarts and rebuilds its specs. Mixed trees are possible in that window; documented, not solved. - Tests stop being
serialonly if they usespawn/spawnWith:and avoid global side effects ininitialize; tests usingsupervisestay serial.
Neutral
currentkeeps its narrow meaning (the class-named singleton).named:is the lookup for explicitly named instances.SupervisionSpec withId:widens toSymbol | Integer; existing symbol ids are unaffected.whichChildren/1's id type widens with it until BT-3966 replaces it.- A DynamicSupervisor's child class,
maxChildrenand child shutdown become per instance, read from the instance's process dictionary; the generatedchildClass/0stays as the fallback for old or remote supervisors.
Implementation
BT-3963 (instance-side configuration, initialize, args into init/1; size L, ~3 days; first):
- Stdlib: move every configuration method to the instance side (
childSpecs,strategy,maxRestarts,restartWindow;childClass,maxChildren,childShutdown), with docs (including the no-messages-to-selfand hang rules). Migrate every supervisor in stdlib, tests, examples and docs. - Codegen and runtime:
supervisor_codegen.rsemitsstart_link/1,start_link/2andinit(Args)→static_init/3/dynamic_init/3, which build the handle and read each setting by instance dispatch; mapcalling_selfto#supervisor_start_failedwith the hint; deleteprecheck_dynamic_configand the class-side config readers (class_config_value,call_class_method_directfor configuration);'$beamtalk_child_class'andpool_child_class/1forstartChild/1,2,3. - Validators (
supervision_validators.rs):check_class_side_supervisor_config(compile error with fix-it for each removed class-side selector) andcheck_children_supervision_policyreadingchildSpecsbodies. - Tests:
stdlib/test/supervisor_start_args_test.btandbt3963_*fixtures; validator unit tests; eunit for the args-aware resolver.
BT-3962 (spawn family, nesting, discovery; size L, ~3–4 days; after BT-3963):
5. Stdlib (supervisor.bt, dynamic_supervisor.bt, supervision_spec.bt): spawn, spawnWith:, spawnAs:, spawnWith:as:, named:, supervisionPolicy, supervisionSpec (class side); args and initialize (instance side; class initialize: removed); withId: accepts Symbol | Integer.
6. Codegen: (start_link/1,2 and init(Args) come from BT-3963.) dispatch_codegen.rs try_handle_spawn_await and the class_self_spawn arm lower supervisor receivers to the runtime start helper in the caller; type_checker/validation.rs skips the spawnWith: state-key check for them.
7. Runtime (beamtalk_supervisor.erl): one start helper for anonymous (unlink, init gate, pg:join) and named (#name_registered) starts; named/2; with supervise (start_link_supervisor/2) rewritten onto it (registered under the module, already-started → existing instance, unlinked); the beamtalk_supervisor_new post-dispatch hook sends instance-side initialize; build_child_spec/2 supervisor branch deleted; spec_to_otp/2 starts supervisor children through the start_supervisor_child trampoline (with the start_link/0 fallback for old modules); start_dynamic_supervisor_child/2,3,4 on the same trampoline; pg join in init/1 for top-level starts; widened id specs in whichChildren/1 and beamtalk_process_navigation:classify/3; args stored for sup args. beamtalk_process_navigation:default_root_pids/0 adds the pg group.
8. Tests: stdlib/test/supervisor_instances_test.bt (not serial) and bt3962_* fixtures; eunit for spec_to_otp/2 supervisor mapping, no-link, pg membership, named/2; codegen tests for the carve-out and start_link/1,2; a type-checker test for spawnWith: on a supervisor class.
Docs (both issues): language-features § Supervision Trees gets an "Instances and arguments" subsection (supervise ensures, spawn creates; unlinked; nesting via supervisionSpec; integer ids; instance-side configuration table; args/restart rule; parent-handle rule) and replaces "define two classes"; ADR 0059 status note; ADR 0080 Future Work #4 marked delivered.
Affected components: stdlib, runtime, codegen, type checker, semantic analysis, tests, docs. No parser change.
Migration Path
None for top-level code: supervise's result and idempotence, current, [application] supervisor = and Workspace startSupervisor: are unchanged, as is the withArgs: meaning for actor children. supervise no longer links the started tree to the class process; no code change is needed, and a crashing tree now leaves its class process alive. Configuration moves to the instance side (breaking, mechanical): drop class from strategy, maxRestarts, restartWindow, childClass, maxChildren, childShutdown, rename class children to childSpecs, and turn class initialize: sup into instance-side initialize (with self for sup). The compiler rejects the old forms with that fix-it, so nothing silently changes behaviour. One further behaviour change: a supervisor nested as a bare class in childSpecs is now an anonymous child, so InnerSup current returns nil for it; use parent which: InnerSup or BT-3966's by-id lookup. A DynamicSupervisor with a supervisor child class now starts anonymous children (before, the second startChild always failed). Packages that want per-instance supervisors (exdura's ActivityWorkerSupervisor) opt in by calling spawnWith: where they called supervise.
References
- Related issues: BT-3962 (multi-instance supervisors), BT-3963 (start-time configuration), BT-3964 (
maxChildren), BT-3965 (withShutdown:/childShutdown), BT-3966 (child control by id; livechildren), BT-3972 (per-child shutdown, cancelled in favour of per-instancechildShutdown); epic BT-3957 - Related ADRs: ADR 0059 (supervision tree syntax; amended: configuration moves to the instance side), ADR 0079 (atom namespaces,
spawnAs:), ADR 0080 (lifecycleResult, Future Work #4), ADR 0084 (runtime class-method overrides), ADR 0092 (process navigation), ADR 0125 (compiled-module compatibility), ADR 0130 (class-variable purity in configuration hooks) - Documentation:
docs/beamtalk-language-features.md§ Supervision Trees;docs/beamtalk-principles.md§10;beamtalk-catalina/PLAN.md - Code:
stdlib/src/supervisor.bt,stdlib/src/dynamic_supervisor.bt,stdlib/src/supervision_spec.bt,stdlib/src/actor.bt(spawn…named:,initialize),runtime/apps/beamtalk_runtime/src/beamtalk_supervisor.erl,runtime/apps/beamtalk_runtime/src/beamtalk_process_navigation.erl(default_root_pids/0),crates/beamtalk-codegen/src/core_erlang/supervisor_codegen.rs,crates/beamtalk-codegen/src/core_erlang/dispatch_codegen.rs(try_handle_spawn_await),crates/beamtalk-core/src/semantic_analysis/type_checker/validation.rs,crates/beamtalk-core/src/semantic_analysis/validators/supervision_validators.rs