Declarative Scheduler Theory
Preamble
This document defines a formal, mathematical theory for declarative schedulers. It is part of the Declarative Scheduler Specification.
Purpose
We tell implementers exactly what must be observable for a scheduler to be correct. We write axioms about starts, ends, initialization, stopping, due/retry pulses, and crashes; we bound progress by the environment's granted compute; and we keep internals out of scope. The result is a portable yardstick for conformance, fairness assumptions, and failure attribution.
The goals are to
- specify conformance precisely,
- enable proofs and model checking of behaviors,
- support portable tests/oracles that attribute responsibility to the scheduler vs. the environment.
Scope
This theory focuses on externally observable behavior of the scheduler, defining:
- The observable event alphabet and timing semantics
- Safety and liveness properties that schedulers MUST satisfy
- The interface contract between scheduler and execution environment
Non-Goals
This specification does not cover:
- Error-handling implementation details
- Internal scheduler data structures or algorithms
- Performance optimization strategies
- Specific embedding mechanisms in JavaScript runtimes
Mathematical Preliminaries & Notation
We work over timestamped linear traces () and reason in first-order linear-time temporal logic with past. Variables range over the scheduler’s observable objects and time domain. By convention, formulas without explicit quantifiers are universally quantified. We write etc. for instantiated predicates and distinguish environment-owned predicates/functions (clock pulses, crashes, compute/duration) from scheduler-owned actions (starts/ends/init/stop). Quantitative liveness uses compute-bounded modalities, with budgets linear in bit-lengths ( ) and a fixed lag ( ). These modalities are definition schemata over the signature.
The universe of scheduler's objects includes all possible objects, not just those present in a particular trace. This means that, for instance, a task with cron expression * * * * * exists.
Time & Traces
- Time domain: a set used to timestamp observable instants. The timestamps have abstract resolution (i.e., they are not tied to any specific real-world clock). But they do correspond to real time, in the sense that for every real-world instance, there is a corresponding timestamp in .
- Trace: a sequence of positions with a timestamp function that is non-strictly increasing. At each position , one or more observable events may occur. Events that are simultaneous appear at the same integer time points. Time bounds are background semantics only (not encoded in LTL). Reference to simultaneity rules is provided in axiom EA3.
LTL with Past
Our formulas are written in linear-time temporal logic with past. We use the following operators:
- Future operators: (□), (◊), (next), (until), (weak until).
- Past operators: (historically), (once), (since), (previous).
Encodings & Bit-Length Conventions
Encodings and bit-length. Fix a canonical, prefix-free, computable encoding from objects to bitstrings with linear-time decoding. For any object , write for the bit length of its encoding.
Background time value and its size. Each position is associated with a background timestamp value . Define using a standard signed binary encoding (so this equals , where is the absolute value of ). Important: measures the value of the clock, not the density of events; events may be sparse in even when grows.
Helper Modalities
Strict compute-bounded eventually
For a given scheduler and , the modality
holds at time iff there exists , , and such that:
- holds at ,
- ,
- .
Intuitively, this asserts that will occur after receiving at most units of environment-provided compute from the current position, plus a small lag to account for a constant delay.
This is the strict progress condition that attributes all delay to the scheduler except for the fixed lag in its witnesses.
In typical usage, is a finite value derived from the scheduler's complexity bounds, though the definition permits .
Compute-bounded eventually
At time and for ,
Intuitively, once holds, the environment will cumulatively offer at least units of compute starting at the current instant.
The regular modality only promises progress when the environment has the potential to provide at least units of compute from the current instant onward.
Linear-in-input compute bound
For a given scheduler , define:
A natural extension is to multiple inputs:
Domains & Data Types
- — the time domain.
- — the domain of durations.
- — the domain of compute.
- — a set of public task identifiers.
- — a set of uninterpreted atoms where only equality is meaningful.
- — the set of externally observable callback behaviours (abstracted here to equality).
- — an abstract object interpreted by the predicate indicating minute-boundary instants when a task is eligible to start.
- — non-negative time durations.
- with projections , , , , .
- — a finite ordered list of tasks. Indexing uses for and strong list membership .
- — a set of valid registration lists.
- — an abstract domain of supernatural phenomenon types.
Interpretation
names externally visible tasks. A is the raw 4-tuple provided at registration time, plus the value, where is an equality-only argument attached to that tuple so the specification can refer to that exact instance without implying pointer semantics or constraining key generation or reuse. The key is not explicitly passed into registration, and it is not directly observable by scheduler implementations.
and are parameters determined by the environment (host clock); they are not hidden internal state. Time units for and coincide.
A is the public input provided at initialization; its order and multiplicities are significant, and duplicate identifiers may appear both within a single list and across successive initializations. Duplicate tasks are also possible in a list.
The list is an environment truth. The scheduler must handle any . Even though duplicates are possible in a registration list, the has those lists excluded. Therefore, the scheduler must reject any list with duplicates. This is to model the situation where users may supply lists with duplicates, but they are invalid and must be rejected.
Durations in correspond to some real-world durations. For example, it could be that is one hour.
Elements of represent different kinds of unmodelled events. The internal structure of is uninterpreted. This set may include ordinary events like sunsets, user interactions, or rare ones, like cosmic rays that flip RAM bits - anything that exists in reality but isn't part of our formal scheduler/environment vocabulary. To recognize which things constitute supernatural phenomena, see the Classification of Supernatural Phenomena.
Helper Equalities on Tasks
Define id-only equality for raw tasks by .
Lift this pointwise to registration lists with .
Observable Alphabet
Each event predicate is evaluated at a trace position (we omit when clear from context):
- — the JavaScript interpreter calls
initialize(...). The effective registration set is .
- — the
initialize(...)call returns normally. The effective registration set is .
- — the
initialize(...)call throws an error. The effective registration set is .
- — the JavaScript interpreter calls
stop().
- — the
stop()call returns.
- — the public callback of task is called.
- — an invocation completes and returns normally.
This event is an environment-supplied truth that occurs when the callback returns without throwing. It cannot be caused or prevented by the scheduler. The scheduler may not know whether the callback will succeed or fail or loop forever.
- — an invocation ends by throwing an error.
This event is an environment-supplied truth that occurs when the callback returns by throwing an error. It cannot be caused or prevented by the scheduler. The scheduler may not know whether the callback will succeed or fail or loop forever.
- — an unexpected, in-flight system shutdown occurs (e.g., process or host crash). This interrupts running callbacks and preempts further starts until a subsequent .
This predicate is supplied by the environment's crash generator. It is not controlled by the scheduler. The scheduler may not know when a crash will occur.
- — a function mapping each time instant to the set of supernatural phenomenon types occurring at that instant.
Interpretation: This function classifies supernatural events by their types. At each time , returns the set of supernatural phenomenon types present at that instant. When , no supernatural events occur at time .
- — is start of a minute that the cron schedule for task matches.
Interpretation: the cron schedule for matches the start of a civil minute according to the host system's local clock.
For example, for a cron expression * * * * *, a due fires at 2024-01-01T12:34:00 local time, at the exact start of that minute.
Important: task does not have to be registered for to occur.
Note: because of DST and other irregularities of a civil clock, minute starts are not uniformly spaced in .
-
— is the instant when the backoff for a failure of expires.
It is formally defined as:
Interpretation: is a primitive point event (like ), supplied by the environment/clock. If the latest occurs at time , then holds at time . These pulses are truths about the environment.
Each predicate marks the instant the named public action occurs from the perspective of the embedding JavaScript runtime: function entry (, ), function return (, ), callback invocation begin/end (, ), and exogenous crash (). No logging or internal bookkeeping is modeled.
Macros
Abbreviations
Stateful
There was a in the past (or now), and no since.
This is a strict version - if clear and set occur simultaneously, the result is false.
An inclusive version of - if set and clear occur simultaneously, the result is true.
At most one between consecutive 's. One single is allowed if there is no next .
Starts of civil minutes.
To see why this definition works, note that every minute boundary in the civil clock induces a pulse for the cron expression * * * * *.
Because that expression is contained within every other expression, whenever any task becomes due, the wildcard expression is also due.
Conversely, the wildcard expression is defined precisely for minute starts.
Therefore the existential over all tasks captures exactly the instants that are the start of a minute.
This macro holds continuously from the instant of until, but not including, the next .
Effectively this keeps the duty cycle "high" for the entire minute. The past-time operator requires that the most recent occurred before the current position and that no has happened since, which means is true exactly while the civil minute that began with is still in progress.
Reference to the most recent successful initialization of a specific registration list .
Membership of in the most recent observed registration list.
Note that this does not imply .
A weaker version of that considers only task identifier, not the full task tuple.
Stop started for a specific registration list .
Stop ended for a specific registration list .
The moment of appearance of task named such that it was not present in the previous registration list.
Note that the comparison is by identifiers, not by full task tuple.
This property allows completely "forgetting" a task after it has been removed instead of tracking its retry/due states forever.
True for an active registration list . Determines boundary of when tasks in can start. The last disjunct ensures that becomes false if a new initialization occurs (which can only succeed after the current one has stopped or crashed, per the concurrent initialization restriction).
An invocation of has begun and has not finished before the current position.
The scheduler is currently initializing with registration list .
No callbacks are currently running.
The first instant at or after when the system becomes quiescent.
An interruption of task by a crash.
A start of run that eventually completes successfully (not preempted by failure or crash).
A start of initialization that eventually throws an error.
An outstanding request to perform a start after a due tick, cleared by a start and by . But the task is not pending if it is currently running.
The reason that clears is that the scheduler should not start all tasks at once after the first initialization - not to overwhelm the system.
A retry request exists after a failure and persists until it is retried.
Similarly to , the task is not retry-pending if it is currently running.
Similarly to , clears .
A task that was interrupted by a crash and has not yet been restarted.
Task has just appeared and the current civil minute is one when is due - so it is pending unless already running.
A task is ready to run.
Note that when task failed but is not retry-due yet, it can still be pending because of due or boot-due.
The scheduler should actually start task now.
An abbreviation.
Environment
The scheduler operates against an abstract Environment .
The environment is an orthogonal concern to the scheduler design; it is a source of non-determinism that influences observable behaviour.
This section is informative. The formulas enumerated here are axioms about the environments we target:
- All formal statements in this section are truths about environments in scope.
- All possible real-world environments in scope satisfy these statements.
- Implementors need not prove these axioms; the task is to map environments to this theory.
Some environments make it impossible to implement a useful scheduler (for example, permanently freezing environments), but for all environments there exist conformant schedulers. The value of this section is to clarify the blame assignment between scheduler and environment.
Among others, environments contribute these ingredients:
-
Crash generator — a predicate over trace positions. When true, the environment marks an exogenous interruption that preempts in-flight callbacks and halts the scheduler itself; axiom EA1 enforces the resulting quiescence in the trace.
-
Compute event predicate — a predicate over trace positions indicating instants when the environment could execute one microinstruction of the scheduler implementation. This is an environment-owned primitive that marks opportunities for scheduler progress.
From this predicate, we derive the compute function:
which counts how many compute events occur within a set of time points. The result is in (the count may be infinite for unbounded sets).
Compute events are only spent on scheduler's actions. So, in particular, these do not require or "consume" compute events:
- IO operations,
- scheduler's sleeping or waiting,
- garbage collection,
- progress of callbacks (except for starting and ending them),
- other activity of the embedding JavaScript runtime.
More specifically, marks the potential for executing the scheduler's own code (and of its JavaScript dependencies), not anything else.
It is expected that the scheduler will have access to fewer compute events when more callbacks are running, but this is a very vague assumption, so not formalising it here.
Core Environment Axioms
The statements in this section constitute the theory .
EA1 — Busy crashing
No work progresses around a crash instant.
EA2 - Actions require work
Observable events, including end of a callback, require that some work has been spent on them.
Importantly, and are not included here, as they are primitive truths about the environment, not actions.
EA3 - No simultaneous actions
Two actions cannot happen simultaneously.
EA4 - Unlimited freeze
There are infinitely many intervals of time during which no work progresses. This asserts "density" of time within compute.
EA5 - Unlimited dues
For every task , the cron schedule matches infinitely often or never at all.
This comes from the fact that cron schedules are periodic and unbounded in time. It is impossible to have a valid cron expression that matches only finitely many times.
EA6 — Crash/RE consistency
After a , no new ends until a new start.
EA7 — Ends follow starts
Every completion must correspond to a prior start.
Environment Taxonomy
The following labels identify illustrative environment classes:
-
Freezing environments: admit arbitrarily long intervals with (i.e., no events).
-
Eventually thawing environments: there exists such that every interval of length contains at least one event.
-
Lower-bounded-density environments: there exist parameters and such that for all and , (average density of events after never drops below ).
-
Burst environments: concentrate events in sporadic spikes; for every there are intervals of length with arbitrarily few events alternating with brief, high-density bursts.
Scheduler Axioms
The formulas in this section constitute the theory . Each axiom is parameterised by the witnesses that appear in the compute-bounded modalities.
Safety Axioms
These axioms state scheduler invariants and prevent invalid sequences of events.
S1 — Start safety
A run can occur only after an obligation to run.
S2 — Conservation of starts
Should prevent multiple successful executions per single due period.
S3 — StopEnd consistency
This means that call to stop() waits for in-flight callbacks to complete.
S4 — Registration soundness
The scheduler must reject any registrations not from the set of valid registrations.
S5 - Registration completeness
The scheduler must accept any registrations from the set of valid registrations, unless a concurrent initialization was in progress.
S6 — No concurrent initialization
After a successful initialization, no other initialization can succeed until after a stop or crash.
This ensures that initialize() calls made while the scheduler is in the "running" state result in IEf (thrown error), not IEs.
Liveness Axioms
These normative axioms state progress guarantees. They prevent deadlocks, starvation, livelocks, and unbounded postponement of obligations.
Progress is always read relative to the environment's willingness to provide compute. In fully freezing environments (see Environment taxonomy), obligations may accumulate without violating safety; in eventually thawing or lower-bounded-density environments, the fairness assumptions below become reasonable or derivable premises for liveness. In other words, in some environments, a conformant scheduler may be useless.
L1 — Obligation fulfillment
When a task is supposed to be executed, we must eventually see that execution in the form of (or a , or ).
Furthermore, that execution occurs within a bounded compute (as a linear function of the sizes of the current registration list and timestamp) after the obligation arises, provided the environment actually grants that much compute from the current point onward.
L2 — Initialization completes
Similar to L1, this property ensures that once an initialization starts, it must eventually complete within a bounded amount of compute (unless preempted by a crash) whenever the environment supplies that budget.
L3 — Stop completes after quiescence
Interpretation. After , as soon as the system first becomes quiescent (no callbacks running), the scheduler must complete stop() within a compute budget linear in the sizes of the registration list and current timestamp (modulo environment grants), or else be pre-empted by .
Structures & Satisfaction
Signature & Structures
We work over a multi-sorted first-order signature with the following sorts:
- (timestamps), (durations), (compute budgets), and (supernatural phenomenon types).
- , , , , , , and .
- Auxiliary finite sets such as and Boolean values .
Function symbols include:
- (timestamp map over trace positions).
- and (where is defined via the predicate as described in Environment Axioms).
- (mapping time instants to sets of supernatural phenomenon types).
- Task projections , , , , , list operations (length, indexing), and the environment parameters , .
Predicate symbols cover the observable alphabet. They include scheduler-owned atoms , , , , , , , as well as environment-owned atoms such as , , , and , and the standalone supernatural predicate . Indexed predicates range over the appropriate sorts (e.g., ranges over , over ); and are 0-ary.
The free constants are theory parameters that instantiate compute-bounded modalities within .
An environment is packaged as the tuple
providing the interpretations for environment-owned predicates listed above. The function is then derived from by counting.
A scheduler behavior is similarly packaged as
providing the interpretations for scheduler-owned predicates.
The supernatural function is packaged as
providing the interpretation for the function mapping time instants to sets of supernatural phenomenon types that exist outside the theory's formal scope.
ownership note. We classify predicate symbols by ownership: environment-owned predicates are interpreted directly from the environment tuple , while scheduler-owned predicates are produced by the scheduler behavior . The supernatural function stands separately as it represents phenomena that are neither controlled by the environment nor the scheduler but exist outside the formal model. This classification is informative; it explains which component determines the symbol's interpretation inside any structure.
Satisfaction & Models
The satisfaction judgment uses linear-time temporal logic with past over trace positions equipped with . Definition schemata , , and are macros over this signature.
Let denote the set of Scheduler Axioms: S1–S4 and L1–L3 with every modality instantiated using the same witnesses . Let denote the Environment Axioms EA1–EA7.
We write
to mean that the structure interpreting environment-owned symbols via , scheduler-owned symbols via , the supernatural function via , and the timestamp map via satisfies the temporal formula in the standard LTL-with-past semantics. Here, is an individual environment, is an individual scheduler behavior, and is the supernatural function mapping time to phenomenon types.
Models of the Theory
A trace over with timestamps yields a structure . The structure is a model of the theory, written as , iff:
- Environment-owned predicates are interpreted exactly as the lifts provided by the environment tuple (which includes , , , , , , , and ).
- Scheduler-owned predicates are produced by the scheduler behavior (at most one observable action per position, cf. EA3).
- The supernatural function is interpreted via , mapping each time instant to the set of supernatural phenomenon types occurring at that instant.
- The structure satisfies every axiom in .
This perspective separates scheduler obligations from environmental truths (see Environment Axioms) and supernatural phenomena, anchoring liveness reasoning in the satisfaction relation defined above.
Conformance
This section is much less formal than the previous ones. Requirements in this section can be trivially gamed by filling in values adversarially for any of the parameters. Therefore, its main purpose is to give just a little bit more than a fully hand-wavy explanation of what conformance means. It culminates in something that can be summarized as "a scheduler implementation may do anything it wants in presence of things outside of our idealistic scheduler theory".
Implementations
A scheduler implementation is a function
that maps each triple of environment , supernatural function , and timestamp function to a scheduler behavior . Here, denotes the space of all possible environments (each providing , , , , , , , and ), denotes the space of all possible supernatural functions (each mapping ), and denotes the space of all possible scheduler behaviors (producing , , and events).
The implementation is the abstract representation of the scheduler's code: given any environment, supernatural function, and timestamp function, it determines how the scheduler will respond. The timestamp function provides the temporal context for the scheduler's decisions. However, note that causality works both ways: the environment influences the scheduler's behavior, and the scheduler's actions affect the environment (e.g., by initiating callbacks).
World Theory
The world theory is a theory that can reason about supernatural phenomena. Unlike and , which are formulated purely in terms of the observable scheduler/environment interface and cannot reference the supernatural function , the world theory has in its signature and can make assertions about it.
This theory captures the reader's background understanding that certain combinations of observables and supernaturals are coherent or incoherent. For example, might assert that if a cosmic ray is reported at time (a supernatural phenomenon), then certain memory corruption patterns become plausible—connections that our formal scheduler theory cannot express because it doesn't "see" supernaturals.
We assume because consists of axioms that hold for all real-world environments (as stated in Environment), so these are also basic truths about the world.
The theory itself is not explicitly axiomatized in this specification; it remains a parameter representing the reader's background knowledge about what constitutes a coherent world.
Important: is not a theory of the actual physical world—it is an idealistic world theory. For instance, the world represented by the theory must be infinite. An infinite theory ensures that conformance cannot be achieved by enumerating and special-casing a finite set of world axioms, forcing implementations to be genuinely correct across all coherent traces.
Happy Set
A happy set is a set of supernatural functions chosen by the user to represent the scenarios under which the scheduler is expected to operate correctly. The happy set captures the user's judgment about which combinations of supernatural phenomena are "reasonable" or "within scope" for the scheduler to handle.
The choice of happy set is not part of this specification—it is a parameter determined by the user's requirements, risk tolerance, and deployment context.
A structure is a happy trace (with respect to ) iff .
Conformance
Let .
An implementation is conformant with respect to a happy set iff:
In other words, a conformant implementation must produce correct behavior for all happy traces. Specifically:
- For every happy trace,
- If the trace satisfies the world theory (is coherent with respect to ),
- Then there must exist complexity witnesses such that the trace satisfies the combined scheduler and environment theory .
Traces that are not happy (supernatural function outside ) are considered out-of-scope, the scheduler is allowed to behave arbitrarily on them.
Interpretation: A conformant scheduler implementation behaves correctly on all traces that are both happy and coherent (satisfy the world theory). On traces that are either unhappy or incoherent, the scheduler may behave arbitrarily.