Browse documentation

Every abort leaves the module evaluations it cut short to load again

Date: 2026-12-02 Area: runtime, embedding, modules Related: ADR 0198 (supersedes its module-record consequence), ADR 0139, #2254

Context

An embedder may run many entries on one engine, each with its own budget: a daemon that gives every request a timeout, an instruction limit or a memory limit, and cancels a request whose client went away. A run can then end at a budget in the middle of a module's evaluation, a module that would finish under a later run's budget.

ADR 0198 let a cancellation leave the module evaluations it cut short to load again, but a limit's abort left its error in them, so every later import of such a module rejected with an error from an earlier request. The recovery also covered only the records the cancelled run made: a record an earlier run linked, such as an import.defer namespace's, and the aborted run evaluated, kept the cancellation. Each superseded record stayed rooted until the engine ended, so repeated aborts of a module that allocates kept one copy of what it made each.

ECMA-262 does not settle this. ES2026 §16.2.1.6.1.3 Evaluate (sec-moduleevaluation, snapshot 0248456c), step 9, stores an abrupt completion of InnerModuleEvaluation as the [[EvaluationError]] of every module on the stack, so a module that throws rejects every later import. The specification has no notion of a host stopping a run: a timeout, a budget or a cancellation is not a completion of the module's code, so it can be read as a throw (ADR 0198's limits) or as the host taking the run away (ADR 0198's cancellation).

Decision

An abort of any kind leaves the module evaluations it cut short to load again. After a timeout, the instruction limit, the memory limit or a host abort (the abort handle's cancellation, an audit that failed), whether Run, RunArtifact, RunTests, RunBenchmarks, InjectModuleGlobals or the host environment's setup met it, and whether a cancellation was observed during the run or only reported after it, the engine supersedes (SupersedeAbortedModules):

  • every record the aborted work made that did not finish, as ADR 0198 did for a cancellation;
  • every older record whose evaluation the aborted work started (TModRec.EvalStart past the run's mark) and did not finish, or whose linking it left halfway;
  • what follows from those as before: a cycle member whose cycle root went, and a record only loaded or linked that links one that went.

A superseded record is no longer found by an import, so the next request loads and evaluates the module afresh. A superseded record that evaluated (one the abort ended, or a cycle member that finished before its root went) releases its environment, its generator, its namespace and deferred namespace, its evaluation promise, its evaluation error unless a deferred namespace of it (or of a cycle member deferring to it) was made and may still read it, and its import.meta object unless a function of the module may still read it (compiled code that reads it, or a function not compiled yet whose source mentions meta).

A run that fails on its own uncaught exception keeps ECMA-262's behaviour: the modules it started record the error, and a later import rejects with it.

Considered options

  • Keep ADR 0198: only a cancellation recovers, and widen it to the earlier runs' records. Rejected: a request that meets its budget once would leave its modules failing every later request on the engine, which a host that reuses engines under per-request budgets cannot undo short of a new engine.

Consequences

  • A module an abort cut off halfway runs its top-level code again on the next import, side effects included (a global it set, a file it wrote, a request it sent), as a cancelled module already did. A host that cannot repeat such effects makes the module idempotent or uses a new engine.
  • A module that threw on its own during a run that was later aborted loads again too: its evaluation belonged to the run the abort discarded.
  • A namespace, a function or a deferred namespace taken from a superseded record before the abort keeps working as that record: a function still reads the cells it closed over and the same import.meta object, and reading a deferred namespace of a record the abort ended throws the abort's error. A binding read in its temporal dead zone through such a function reports the generic message, since its record no longer holds the table that names the binding.
  • Repeated aborts of the same module no longer grow the heap by what each aborted evaluation made.
  • ADR 0198's other decisions stand.