Browse documentation

A run's limits live in the engine, and code below it reaches them through one hook

Date: 2026-11-29 Area: engine, runtime, embedding Related: ADR 0174, ADR 0198, ADR 0148, ADR 0107, #2187, #2296, #1331, #2051

Context

Since #2187 every GocciaScript application runs on the engine in source/engine. A run's limits are the engine's: TGocciaEngine arms its TimeoutMs and MaxInstructions with LimitsArm (Goccia.VM), a timer thread sets the engine thread's Interrupt at the deadline, back edges and calls check it, and a built-in whose loop the script sizes polls it with PollInterrupt. Code that waits rather than loops reads the deadline itself: LimitRemainingMs, LimitDeadline and LimitDeadlinePassed (a fetch socket, and a provider-package download since #2296). A host's abort handle (ADR 0198) interrupts the same way.

The interpreter's limit layer stayed behind in source/units and was compiled into the engine and every application that runs scripts: Goccia.Timeout (StartExecutionTimeout, PushTimeoutScope, CheckExecutionTimeout, CheckExecutionTimeoutNow, RemainingExecutionTimeoutMilliseconds and the abort plumbing of ADR 0174), Goccia.InstructionLimit (StartInstructionLimit and its scopes) and Goccia.ThreadPolls, which mirrored both for the old VM's hot paths. No application armed them, so every one of their polls saw no deadline and no budget whatever --timeout and --max-instructions said. Two places still fell back to them: CheckNativeWork (Goccia.NativeLimits) and the regex matcher's poll (Goccia.RegExp.VM), whenever no NativeWorkHook was installed, which the sandbox did only while a sandbox ran. ADRs 0107, 0148 and 0174 and older issues still named these procedures as the way a deadline reaches a loop or a wait, and #1331 asked for a download to read RemainingExecutionTimeoutMilliseconds, which would never have ended it.

Decision

  • One model. A run's deadline, instruction budget, memory refusal and abort are the engine's (source/engine: Goccia.VM, with the heap ceiling of Goccia.Core and the shared budget of Goccia.InstructionBudget). No unit outside the engine keeps limit state of its own or offers a procedure that arms one. Goccia.Timeout, Goccia.InstructionLimit and Goccia.ThreadPolls are deleted, with their tests; the embedding guide already listed StartExecutionTimeout and StartInstructionLimit as removed in favour of TimeoutMs and MaxInstructions.
  • Code in the engine polls PollInterrupt in a loop the script sizes (PollInstructionUnits for a batch), and code that waits reads LimitRemainingMs, LimitDeadline or LimitDeadlinePassed.
  • Code below the engine (source/units, which cannot use Goccia.VM), such as a sandbox's glob, grep and fuzzy search and the regex matcher a grep runs, polls CheckNativeWork. It reaches the run's limits through NativeWorkHook, which the engine installs for the life of its VM (VMInit to VMDone), whether or not a sandbox runs. What the poll observes and how a refusal returns are in the engine guide's Execution limits.

Consequences

  • A loop or a wait that follows the docs reaches the limits that are in force; there is no second API to call by mistake that compiles, runs and never fires.
  • CheckNativeWork behaves the same in and out of a sandbox. The sandbox no longer installs the hook; it sets only its native byte ledger (NativeBytesHook).
  • #2051 (limits per engine rather than per thread) starts from Goccia.VM's limit state: the thread-level free functions it planned to keep as wrappers are gone.
  • Unit tests of code below the engine run without a VM, so they cannot exercise its limits; a limit on that code is tested through the engine. scripts/engine/native-work-hook-test.pas polls CheckNativeWork from an embedder native outside any sandbox under an instruction cap and a deadline, and checks that the hook lives exactly as long as the engine; scripts/test-cli-sandbox-search.ts charges a search's native work to --max-instructions.