A Run can end badly in three ways, and they don’t mix. An Error is an ordinary value that a Script raises, catches and rethrows. A Limit Fault is the end of a Run that exceeded a resource limit, and no Script code sees it. Cancellation and Stop Script come from outside the Run. This chapter states the rules for each, the error-code catalogue and the limits. Host misuse of the embedding interface is a Host Error, in chapter 9, and never reaches a Script.
An Error is a plain map with a text code (ADR 0017). It follows Value Semantics, like any map, and needs no value kind of its own.
Codes are lowercase words separated by spaces, such as "capability revoked", and a word may be hyphenated, as in "not read-only". Every code the Core raises is in the catalogue. The codes a Script throws are free-form.
A Core-raised error carries code, message, at and the fields its catalogue entry lists. Parity covers the code and every field exactly, but not the wording of message.
at is the source position of the raise, added by the Core only when the map has no at key, so a rethrow keeps the original position. It is the map {unit, handler, line, column}:
unit is the name of the code unit that raised it: a Script’s or a Library’s name, or <script>+<n> for a Script’s nth extension (chapter 11).
handler is the name of the Handler or function the code is in, the enclosing one for a Lambda.
line and column are the position, counted as in chapter 1, that the source map gives the raising instruction (chapter 8).
Inside the stdlib, whether a stdlib Library throws the error or an operator or Built-in in its code raises it, at names the call that entered the stdlib, in the nearest frame that isn’t stdlib code, and its unit, handler, line and column are that frame’s. So pad("x", -1) points at the Script’s own line. A Function Value the stdlib calls, such as a Lambda passed to map, is the Script’s code, so an error inside it points into it (ADR 0037).
Key order: maps are ordered, so a Core-raised error map’s keys come in a fixed order: code, message, then the fields its catalogue entry lists, the required ones and then the optional ones, each in the catalogue’s order, then at last. A Fail’s map is code, message, its Data entries in their order, then capability, operation and at. A key the Core adds to a map that already exists, such as at on a throw, index or during, goes at its end.
Input positions are other fields. offset is a 1-based Character position in text, and path is a Path, the keys and 1-based positions into a value, so it prints as /lines/2/sku (ADR 0033, ADR 0184). err's path as list gives its Value Path. The one exception is can't patch, whose path is the failed operation’s JSON Pointer text, as written.
Kind names in fields such as expected and got are the kind names of chapter 3.
Not Errors: a Limit Fault, a cancellation and Stop Script are not Errors. No catch sees them.
Optional key reads use wrong kind with expected"text" for an
invalid computed key, or "map" for a receiver that is not a map, Nothing
or Host Object, and
value the offending value. Their own errors point at the; evaluated
operand errors retain their positions. They add no cumulative path.
The stdlib attribution rule above applies to both read and operand errors.
throw e raises the map e as it is, adding at if it is missing. The map needs a text code, and message is optional.
throw t, for a text t, raises {code: t}, decided at run time by the value’s kind.
Anything else given to throw raises bad throw.
Built-ins, operators and statements raise catalogue codes, such as can't convert for "lots" as number.
Catch search walks retained frames, including local and Library calls, before cleanup runs. It charges per frame the search leaves; later popping is free. A Run unable to pay faults at the instruction driving that search step (chapter 8).
The Trace records every raise, caught or not, as its code and instruction (chapter 11).
Every catch is tested before failed frames unwind. An ordinary accepting catch then runs exited cleanup scopes and continues its real owner. A catch … before unwind runs policy while the failure chain remains retained; choose offer name(args) selects the nearest active named action, and fallthrough declines to the next catch. See the machine contract.
try … end try runs its block. An error raised in it, or in anything it calls, is matched against its catch clauses.
Clauses are Destructuring heads with optional Guards, tried top to bottom, like Handler Clauses. The first that matches runs, with its names bound. A bare catch e matches every error.
Shorthand:catch "out of stock" is short for catch {code: "out of stock"}, and a where Guard may follow it. Only a text literal is shorthand, so a name in a head still binds.
No match: continue searching outward without cleanup. Rejecting catches are transparent to caller recovery; an accepting ordinary catch discards deeper offers. If none accepts, unwind all frames and finally scopes.
Guards on catch clauses follow the rules for Handler Guards. An error in one skips the clause and is invisible, except in the Trace.
An error in an ordinary catch body unwinds from there, through the try’s finally.
An error in recovery policy starts a nested two-phase search bounded by that selection control. It sees its own failure chain’s offers, never those of the original failure. Local handling resumes policy. Escape aborts that recovery, adds its original Error as during only when absent, runs exited policy and retained cleanup, and searches outward from the catching try, bypassing its sibling catches.
An error in transfer cleanup leaves a chosen action pending when caught locally. Escape cancels the choice and searches anew from the cleanup site, attaching the original Error as during only when absent. Offers remain eligible until action entry. Action failures search outside their sibling offers and catches; an action may suspend wherever its surrounding body permits.
Nothing rolls back: a caught error undoes no write to a Script Variable. Rollback is only for Limit Faults and cancellation, where the Script can’t react (ADR 0006).
What catch never sees: a Limit Fault, a cancellation or Stop Script. So a catch e in a loop can’t soak up any of them.
A clause of try:finally comes after the catch clauses. It runs when the try completes, and when an error leaves it, whether caught or not. It also runs when return, exit repeat or next repeat leaves the try.
On a Handler: a Handler whose body ends in finally is short for a try around its whole body.
No Suspension Points: a finally block may contain no possible Suspension Point. The loader checks this.
No leaving it: a return, veto or pass inside a finally block, or an exit repeat or next repeat whose loop is outside it, is a load error, since it would drop the error or cancellation in flight.
veto and pass run the open finally blocks before they end the Run, as return does.
On the Run’s budgets: on completion and on errors, finally runs on the Run’s own Fuel and limits.
An error in finally replaces the error in flight, if there is one. The old error goes in the new map’s during field, added only when it is missing.
On cancellation,finally blocks run on the Cleanup Budget (below).
The Run ends errored. Its run end report carries the error map as a Host value.
The error message: the Core then puts an ordinary error message, with the error map as its one argument, at the back of the Script’s own mailbox. It goes in before a parked Run of the same clause becomes ready (chapter 5), so it is dispatched first. An on error Handler picks it up as a new Run, so it never runs inside the failed Run and can’t resume it.
Clauses:on error can have Handler Clauses, as any Handler can, such as on error {code: "timeout"}. on error "timeout" is short for that, as in catch.
, during name binds name to the message the failed Run was handling, as the map {name, args}, or {fn, args} for a Run started by a Function Value call. The suffix is allowed only on on error.
Only for errored: there is no error message for a Limit Fault, cancelled, unhandled or dropped.
No chain: a Run started by an error message that errors itself sends no further error message.
Nowhere to go: an error message that no clause matches, including when the Script has no on error, is dropped, and never reaches a Fallback Handler. It never climbs the Message Path and isn’t reported as unhandled. If the mailbox is full, the message is dropped, and the Trace records a note.
Fail: a Host function that fails with a ScriptError raises its code as is. Its message becomes message, and the entries of its Data become top-level fields, converted and charged to the calling Run. The Core adds capability, operation and at.
Becomes host error, with only capability and operation:
a Fail whose Data is neither a map nor Nothing
a Fail with a catalogue code, unless it is a Standard Capability code its Operation declares (below)
a Fail whose Data uses a reserved key, listed in the catalogue
a Fail with a code outside its Operation’s declared list, when the Operation lists its codes
a Host function that fails with anything else, such as a Go panic or a TS exception
a result that breaks its Operation’s result Shape (ADR 0030)
No Host detail: a host error carries nothing from the Host, since a panic’s text could leak Host internals. The detail goes only in the call failed report. Uncaught, a host error ends the Run as errored, like any other error.
Interrupted crossings: if Stop or cancellation interrupts the Run at an Operation crossing, a Host failure neither raises host error nor emits call failed; the call record is still written (chapter 9). Failures in Operations called during cancellation’s finally cleanup still raise and report normally.
Standard Capability codes: the fixed calendar Operation Declarations list unknown zone and ambiguous time, the store ones can't store, store full, store busy and watch limit, with increment also listing wrong kind, incompatible units and overflow, and the sqlite ones sql, constraint, sqlite busy, not read-only, too many rows and unrepresentable, and the user ones user busy. A Host may Fail with the codes its Operation lists. The Core checks their fields against the catalogue, and a mismatch becomes host error. The Core checks a locale tag itself before the Host function runs, and raises bad locale, and it raises invalid key itself for an empty store key and invalid watch for an empty watch name or invalid effective message (the staged validation). It raises out of range for a bad sqlitemax, sql for a result that names a column twice, and unrepresentable for a double it can’t hold, and out of domain for an empty userchoose list (ADR 0033, ADR 0050, ADR 0070, ADR 0077).
Arguments are checked first: an argument that breaks its Shape raises wrong kind before the Host function runs, and nothing is charged. The fields describe the first node that doesn’t match, searched depth-first in argument order: argument is its 1-based position and path locates it inside the argument, when it isn’t the argument itself. A OneOf expects its kind names joined with " or ", and an Optional expects its Shape’s followed by " or nothing". A Quantity Shape expects its Unit, or its Unit Kind, and a Quantity that breaks it got its own Unit. For a missing key, got is "nothing", and for an extra key in a closed map, expected is "nothing". capability is the Grant’s name, as the Script writes it. A Function Value where a Shape takes only data — under any, or in an open map’s undeclared field — raises not encodable, with path from the argument’s 1-based position; value and function Shapes take Function Values, value at any depth. The Script Shape checks of chapter 7 raise these same two errors for a mismatch, with paths relative to the checked value and no Capability fields, and invalid shape for data that isn’t a Shape.
Revoked Grants: a call through a revoked Grant raises capability revoked until the next Reload, after which it is a load error.
Charging: a Charge the Run can’t cover is a Limit Fault at the call, not an Error.
send failed: when the receiver of a send … and wait doesn’t reply, the sender raises {code: "send failed", reason} at the send. reason is errored, limit fault, cancelled, unhandled, dropped or stopped, and for errored, error is the receiver’s error map. Uncaught, it ends the sender’s Run as errored too.
The receiver still reports its own outcome, and for errored its own on error still fires.
From the Host: a Request rejects with the same map, as a rejected Promise in TS and an error value in Go. A Host Call of a stale Function Value rejects with reason function gone, and nothing runs.
Function Values: a call to a Function Value in another Script fails as send … and wait does. A stale Function Value called from inside a Script raises function gone itself.
Plain calls: a Command Call to a Handler of the Script, or an imported one, is a plain call, so its errors unwind straight into the caller.
timeout: a send … and wait or a Function Value call that runs past MaxWait raises timeout, with after, and the receiver keeps running.
A Timeout Block’s deadline: a wait that runs past the deadline of a Timeout Block it is written in raises timeout, with after the block’s duration in ms (or s when its ms coefficient would exceed the number range) and deadline: true. A Capability call adds capability and operation, as for its own timeout (chapter 5).
Fail fast: of the Join Member failures that arrived before the Join’s closing end, the earliest-started member’s is raised there. After the Join suspends, the first member failure to arrive resumes the Run and is raised at its closing end. Either is raised as the member’s own error map plus index, its 1-based start position. A failed send member raises send failed, plus index.
index is added only when it is missing, so a rethrow keeps it. It is a reserved key.
A Timeout Block around the Join: when its deadline runs out first, every pending member is abandoned and the Join raises timeout with deadline: true and no index, since no member failed.
The rest of the pending members are abandoned (chapter 5).
errors.toml lists every code the Core raises inside a Script. Each code has one set of fields that every raise carries, and a raise that knows more adds the optional fields beside them (ADR 0033). Every field has one meaning wherever it appears.
Reserved keys:code, message, at, capability, operation, index, during, deadline. The Core sets them, and a Host Fail’s Data may not use them.
Code
Fields
Raised when
Sources
restricted operation
instruction
A restricted callback attempts an instruction or Built-in that observes live state, performs an effect or accesses recovery offers
The receiver of a send … and wait, a Function Value call or a Host Request doesn’t answer; reason is errored, limit fault, effect failed, cancelled, unhandled, dropped, stopped or function gone, or for a Remote Send, which the Host fails, also unreachable, mailbox full or not exposed, and error is present only for errored
A send with a computed message name is given text that isn’t a Name or a Selector, that is all or a Reserved Word, or that is a Selector whose part count isn’t arguments, the argument count
An operand or argument has the wrong kind, e.g. "007" + 1, if 0 or a Text Pattern search on a value that isn’t text; for a Capability argument that breaks its Shape, the fields describe the first node that doesn’t match, argument is its 1-based position and path is the Path that locates the node inside it
A conversion fails, e.g. "lots" as number or a bad as target, a parse such as parseDate doesn’t match, or a spliced Text Pattern clashes with the one it is spliced into; a parse adds offset, and parseDate adds its template as format
< or a sort orders two values of kinds that can’t be compared, e.g. a text and a number, or a date-only value and a date-time; the fields are the two operands
An operation combines Quantities of different dimensions or Unit Kinds, e.g. 1 month + 1 day or a range from 1 m to 2 kg, adds a calendar duration to an Instant, or adds to a date-only value an exact duration that isn’t a whole number of days, or to a Civil Date a calendar duration that isn’t a whole number of months; the fields are the two Units’ display forms, singular, and 1 for a plain number
A Host function fails with something other than a Script error, a Fail misuses a reserved code or key or uses a code its Operation doesn’t declare, or a result breaks its Shape; it carries no Host detail
A suspending Operation call runs past its maxPending or the Script’s MaxWait, or a send … and wait or a call to a Function Value in another Script runs past MaxWait, and is abandoned; or a Suspension Point runs past, or is reached after, the deadline of a Timeout Block it is written in; after is the limit that ran out, in ms (or s when its ms coefficient would exceed the number range), a Capability call adds capability and operation, and a Timeout Block’s deadline adds deadline, which is true
JSON encoding, a data-Shaped Capability argument or a Shape check meets a value plain data can’t hold, such as a Quantity or Bytes, or a Remote Send’s arguments hold a Host Object that isn’t a Peer, with kind"object"; path is the Path that locates it inside the value being encoded or checked, the empty Path at its root
An argument is outside a function’s domain, e.g. sqrt(-1), a format key that’s missing, a bad sort direction, a Standard Capability option word that isn’t listed, an empty list of userchoose items, an empty peer name or address, a Peer given to wait for … from or sent to by a Script with no peer Grant, or an Object Element Reference or Element Count on a Host Object whose kind has no collection; value is the argument, the missing key, the word or the receiver, and function is the function’s or Operation’s name, element, number of elements or elements
A value is outside the range its position allows: a date outside 0001–9999, a date field that isn’t an in-range integer, a character, word or byte write past the end, any chunk write at index 0, before the start or over a reversed range, a negative repeat count, an empty delimited by, a Binary Pattern build value too large for its segment, or a sqlite call’s max that isn’t a whole number up to its Grant’s row cap
toInstant with "reject" meets a DST gap or overlap; the Host fails with it from calendar, and the Core raises it from the toInstant Built-in given Zone Rules
A send … to reaches a disposed Host Object, or names a Script the Group doesn’t hold, or a property or the collection of a disposed object is read or set; object is the object, or the Script’s name as text
A Shape check Built-in is given data that isn’t a Shape; reason is the chapter 7 reason for the first definition error, path is the Path that locates it inside the Shape data, the empty Path at its root, and value is the offending part
map.transform receives an invalid Mapping definition; reason and precedence are fixed in chapter 7, path is a definition-relative Path, an embedded Shape failure is preserved in error, and an overlap names the earliest otherRule
A Mapping source selection is absent under the error policy; this plain diagnostic is nested in a source-stage report, with the resolved prefix and failed step on its wrapper
A storewatch or unwatch is given empty text as its name, or watch an effective message that isn’t a plain Name; field is name or message, and the Core raises it before the Host function runs
A watch would take its Store’s watches past a limit, after removing the watch it replaces; limit is watches, size or pending, and the Host raises it before anything changes
A store write would take the Store past one of its quotas, counting every live Segment’s pending growth; limit is size, keys or value, and the Host raises it
A store write names a key that another live Segment has reserved with an uncommitted write, or, for a Store that shares a Segment Coordinator with sqlite, another Segment holds the database’s write lock; the Host raises it before anything changes
A sqlite statement can’t run as given: SQLite rejects it, it is more than one statement, its placeholders don’t match params, the Host’s authorizer denies it, or its result names a column twice; reason is SQLite’s or the Host’s own text, which isn’t portable between SQLite versions
A sqlite statement gives more rows than the call’s max; the Host raises it, leaving the database as it was before the call, and never truncates the result
A sqlite result holds a value Talk can’t hold exactly: a NaN, an infinity, a REAL of magnitude 10^34 or more, or TEXT that isn’t valid UTF-8; column is its column’s name, and the Core raises it, except that a TS Host raises it for TEXT
An httpserve or unserve is given empty text as its name, or serve a prefix that doesn’t begin with / or an effective message that isn’t a plain Name; field is name, prefix or message, and the Core raises it before the Host function runs
An httpserve asks for a host or port its Grant binding doesn’t allow, or one that can’t be listened on, or a fetch names an origin its Grant binding doesn’t allow, or a peerexpose or reach names a name its Grant binding doesn’t allow; the Host raises it
An httprespond is given a status outside 100 to 599, a headers value that isn’t text or a list of texts, two header names that differ only in case, or both body and json; field names the key, and the Core raises it before the Host function runs
An httpfetch is given a URL outside chapter 7’s profile, a header the profile refuses, a body on GET or HEAD, both body and json, a json value the json Library can’t write, or both a query in the URL and query; field is url, headers, query, body or json, and the Core raises it before the Host function runs
An httpfetch receives more header or body bytes than its Grant binding allows; field is headers or body and limit the bound in bytes, and the Host raises it without giving a partial response
Every Core-raised error carries a message, written from its template below. {field} stands for that field’s value in the display form (chapter 11). The wording is outside parity, and the Trace leaves message out of Core-raised errors. A Script’s own message is data, so the Trace keeps it. An error that stdlib code throws with a catalogue code and no message is Core-raised, so the Core adds its message too (ADR 0037).
Code
Message
restricted operation
The instruction {instruction} is not allowed in a restricted callback
bad throw
Only a map with a text code, or a text, can be thrown
no match
The value doesn’t match the pattern
send failed
No answer came: the receiver’s Run ended {reason}
mailbox full
The mailbox of {to} is full
bad message name
{name} can’t name a message with {arguments} arguments
capability revoked
The Grant for {capability} is revoked, so {operation} can’t be called
wrong kind
Expected {expected}, but got {got}: {value}
can't convert
Can’t convert {value} to {to}
can't compare
Can’t compare {left} with {right}
division by zero
Division by zero
overflow
The result of {operator} is too large
incompatible units
Can’t combine {left} with {right}
host error
{capability} failed while doing {operation}
timeout
No answer came within {after}
would suspend
This function may wait, so call it with and wait
function gone
The function no longer exists
wrong arity
The function or offer was called with the wrong number of arguments
not encodable
A {kind} can’t be encoded as plain data
out of domain
{value} is outside the domain of {function}
out of range
{value} is out of range for {field}
can't decode
Invalid {format} at Character {offset}
can't patch
JSON Patch operation {index} ({op} at {path}) failed: {reason}
unknown zone
Unknown time zone {zone}
ambiguous time
{civil} is ambiguous, or doesn’t exist, in {zone}
bad locale
{locale} isn’t a well-formed locale tag
object gone
{object} has been disposed
read only
That property is read-only
call lost
The call was lost in a restore
scope already open
The scope {scope} on {capability} is already open
scope not open
The scope {scope} on {capability} is not open
scope open
The scope {scope} on {capability} must close before waiting
scope in join
The scope {scope} cannot open inside a Join
segment participant conflict
The Segment already participates through {participant}, so {capability} cannot join
capability disabled
The Grant for {capability} is disabled, so {operation} cannot be called
offer unavailable
The recovery offer {name} is unavailable
invalid shape
The Shape is invalid: {reason}
invalid mapping
The Mapping is invalid: {reason}
missing selection
The selection step {step} is missing
invalid key
A Store key can’t be empty text
invalid watch
A watch’s {field} isn’t valid
watch limit
The Store’s {limit} limit for watches would be exceeded
can't store
A {kind} object can’t be kept in a Store
store full
The Store’s {limit} limit would be exceeded
store busy
Another Segment is writing {key}
sql
The SQL failed: {reason}
constraint
The change breaks a {kind} constraint
sqlite busy
Another Segment is writing to the database
not read-only
A query must not change the database
too many rows
The statement gave more than {max} rows
unrepresentable
The value in {column} can’t be represented
no musical time
This Host keeps no musical time
user busy
Another prompt is waiting for an answer
invalid serve
A Serve Registration’s {field} isn’t valid
address in use
That address is already in use
bad address
That address isn’t allowed
name in use
That name is already exposed
not exposed
No Script is exposed under that name
invalid response
The response’s {field} isn’t valid
already responded
That HTTP request has already been answered
exchange closed
The client has gone
not owner
Only the Run that received this HTTP request can answer it
invalid request
The request’s {field} isn’t valid
network error
The request didn’t get a response
response too large
The response’s {field} is larger than {limit} bytes
Set at load: a Host sets a Script’s limits when it loads the Script. A field left at zero takes its default, from the default limit profile below.
Tightened per Delivery:Deliver, Request, Broadcast, Decide and Call take an optional override of the limits marked “yes” below. It can only tighten them, and an override that loosens one is the Host error invalid value. The Trace records the override. The Persistent State cap is Script-wide, and can’t be overridden.
Runs started by a Script’s send get the receiving Script’s limits, with no override.
No Script-side syntax: a Script can’t read or change its limits.
Conformance minimums: every Core honours any value from 1 to a limit’s minimum exactly. A Core may honour larger values too. A Core that can’t honour a value refuses it at load, or in the override, as invalid value, and never quietly lowers it. Conformance cases stay within the minimums.
Fuel per Run covers the Run’s whole life, suspensions included. Each instruction’s whole charge applies at it, so a Run that can’t cover a charge faults at that instruction (ADR 0010). A Capability call charges its declared cost at the call, Charge during its Host callback, and an additional late cost when the Run resumes. Metered Operations can authorize successive chunks; asynchronous requests charge when their Pump admits them, even while the Run waits. Waiting alone costs no Fuel.
The Allocation Budget counts the logical size of every value the Run constructs over its life, as if nothing were shared, with frees ignored.
Persistent State counts, by logical size, everything the Script keeps between Segments: its Script Variables, the frames of its suspended, parked and preempted Runs, the answers a Join has received early, and the messages in its mailbox. It is measured at each Segment end, at a suspension or at the Run’s end, and a breach faults the Run at that instruction. Growth within a Segment is the Allocation Budget’s job.
A Run that is ending isn’t suspended, parked or preempted, so its own frames don’t count at its end. A suspending Run’s frames do.
At a Run-ending return, pass or veto, this check precedes that instruction’s own charge (chapter 8); at a suspension it follows the charged instruction and any Host effect.
After a fault or a cancellation, the Persistent State the Trace reports is measured after the rollback, with the Run gone.
Call depth counts the frames on a Run’s stack: its Handler and every Handler, function, Library and Lambda call inside it. The retained real frames count too, even while a cleanup copy runs (chapter 8). A call that would pass it is a Limit Fault at the call.
Text Pattern size counts the instructions of a Text Pattern’s compiled program (chapter 8). A literal pattern over it is a load error, and a pattern made at run time over it is a Limit Fault at its make-pattern. Counted repetitions such as 1000 digits count every copy, and a count has no limit of its own, so this limit is what bounds it.
Mailbox depth counts the messages waiting in a Script’s mailbox. Parked and suspended Runs don’t count. A Script’s send to a full mailbox raises mailbox full, and a Host call that would overfill one, counting the Deliveries already queued to it, returns MailboxFull. A Delivery the Host’s call accepted joins the mailbox when it is drained, even past the depth (chapter 9).
MaxWait is the longest a call waits for an answer, in whole milliseconds on the Group’s Clock: a suspending Operation call with no maxPending of its own, a send … and wait, and a call to a Function Value in another Script. Its deadline is the Clock reading of the Pump in which the call started, plus the limit. When it fires, the call is abandoned and the Run raises timeout. wait and wait for aren’t bounded by it.
MaxJoin is how many members one Join may start. Starting one more is a Limit Fault at that statement, and the members already started are abandoned.
The Cleanup Budget is the Fuel a cancelled Run’s finally blocks may spend (below).
An instruction’s own limit comes first: call depth, Text Pattern size and MaxJoin are each checked at one instruction, before its Fuel and allocation. So an instruction that passes one faults on that limit, and is never charged (chapter 8).
Uncatchable: a Limit Fault ends the Run at once, as limit fault. No catch or finally runs, and no error message is sent. The report names the limit.
Rollback: the failing Segment is rolled back, so the Script’s Script Variables return to their bindings at the Segment’s start. An enlisted Segment participant rolls back too, after scope abandonment. Other effects already made in the Segment, such as ordinary immediate and fire-and-forget Capability calls and messages sent, are final (ADR 0006).
Asynchronous metering refusal: draining the request ends the Run at the originating call’s saved source position. A suspended Run has no executing Segment to roll back: already committed state remains, with no synthetic Segment or Stretch. If its pending Join Member belongs to a preempted Run with an open Segment, roll back that existing Segment instead (metering).
Pending calls, including Join Members, are abandoned.
Other Runs of the Script carry on.
Senders of the message get send failed, reason limit fault, and a deciding Run that faults before its seal leaves its Decision undecided.
Rationale. A catchable limit would turn a hard sandbox into a soft one, since try inside a loop could run past any budget. Rolling back keeps an exhausted Run from leaving a healthy Script’s Script Variables half-written (ADR 0006).
A definite failure to commit a Segment participant rolls back Script Variables and ends the Run as effect failed, without Script catch, finally or an error message. It is neither an ordinary Error nor a Limit Fault and does not increment Faults. Senders receive send failed, reason effect failed, and an unsealed Decision is undecided. The report identifies the lifecycle failure. Ambiguous commit or failed rollback stops the Group with reason effect state unknown. The lifecycle contract defines ordering, including failure during cancellation cleanup.
Cancelling a Run:, replacing, CancelRun, and cancel-delivery from a cancelled Request, Decide or Call, cancel a Run.
Scopes on the participating Grants are abandoned, then the Run’s current Segment and its participant are rolled back, as for a Limit Fault. A suspended Run is between Segments, so nothing is rolled back.
Its pending calls, including Join Members, are abandoned.
Its dispatch-local and retained finally scopes run once, innermost first, all under one Cleanup Budget. Scope identity is the control activation plus cleanup entry; an activation inherits its owner’s enclosing scopes. An already entered cleanup copy is not restarted. Shared owner locals remain retained for any remaining scope. The Fuel they spend is charged to the Cleanup Budget, not to the Run’s Fuel. No catch clause runs.
Remaining scopes are abandoned and the cleanup Segment’s participant is finalized. The Run ends as cancelled, unless finalization itself ends it effect failed or stops the Group.
Where each step happens: steps 1 and 2 happen where the cancel lands. A Run cancelled while it runs then goes straight on to step 3, in the same turn. Any other Run becomes ready, and steps 3 and 4 happen in its Script’s turn (chapter 5), so its cleanup never runs inside another Run’s Segment. A Run already in its Script’s queue, such as a preempted one at its head, keeps its place.
Nothing is unwound: cancelling charges no unwind. The frames are dropped, not popped by an error, and only the finally blocks cost anything.
Cleanup’s Fuel is the Cleanup Budget’s, not the Run’s, but it is still Fuel the Script spends: it counts toward the Fuel Slice and the Group’s Fuel cap, which can preempt the cleanup, and the Trace counts it in the Stretch’s seg or preempt figures as well as the Run’s run figures (chapter 11).
Cleanup that fails: an ordinary error in a finally block, an exhausted Cleanup Budget, or any other limit exceeded during cleanup ends the remaining cleanup, outer blocks included. Subject to participant finalization succeeding, the Run still ends as cancelled, and the report and the Trace add cleanup failed with the error’s code or the limit.
The run end report carries cleanupFailed: {code} for an error, or {limit} with cleanup, alloc, persistent, depth, pattern or join. It has no ordinary error or limit field, since cancellation remains its outcome.
A failed cleanup’s writes: an error keeps the Script Variables the cleanup wrote, since an error never rolls back. A limit rolls the Segment back, as a Limit Fault does. Step 1 has already rolled back the rest of the Segment, or a suspended Run’s cleanup is a Segment of its own, so this undoes only the cleanup’s writes.
A Delivery still in the mailbox that is cancelled is removed. It is reported as a run end with outcome cancelled and no Run or Handler.
A sender’s cancellation never cancels its receiver (chapter 5).
Rewinding a Run isn’t a cancellation: its Segment rolls back as for a Limit Fault, no finally runs, and its message goes back to the mailbox to be dispatched again (chapter 9, ADR 0068).
Stop Script is sticky. It discards the Script’s running, parked and suspended Runs with no finally, and drops the messages in its mailbox. The senders waiting on any of them get send failed, reason stopped, and an open Decision settles as undecided, cancelled. The stop report lists what was discarded and dropped. Disposing a Script’s owner stops it the same way, within the same Host Input, with reason owner disposed.
A repeated Stop does nothing and keeps the original reason. A later Delivery to the Script is still accepted subject to mailbox depth, then dropped when drained, with another stop report listing it under that reason; its Request fails as stopped, and its Decision is undecided, cancelled. A Script’s send to it is dropped too. Broadcasts leave stopped Scripts out of their recipients. A Group with at least one Script, all stopped, pumps as stopped.
Scope abandonment and participant rollback also run on Stop, disposal, Reload and replacement, before reports or another Run. They execute Host code, consume no Script Fuel, and do not run Script finally (lifecycle contract).
Rationale. A finally that ran on a Limit Fault or Stop would be recovery code after running out of budget, and Stop means no more Script code. A cancelled Run has done nothing wrong, so its cleanup runs, but on a budget of its own (ADR 0017).