Skip to content

state_exec: a run's step budget counts what each pick charged (G1, fifth part) - #1117

Merged
transfix merged 1 commit into
masterfrom
feat/wasm-guests-5
Nov 10, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/wasm-guests-5

Conversation

@transfix

Copy link
Copy Markdown
Owner

G1, fifth part: the drain's pump budget now counts the steps guest slices charge, not one step per pick. Before, a guest could stretch a drain to its 0.1 s backstop (roadmap §8.5, "Slices").

The bug

async_scheduler's run loop counted each pick as one step against max_steps, however much that pick's evaluator step charged on top of itself through evaluation_stats::add_steps. Script engines charge their work that way: Ariadne's ScriptSlice::charge, and a wasm guest's fuel at 64 steps a slice. So:

  • a slice cost the drain's 200,000-step budget one step;
  • with no caps and no frame budget, an activation charging 10,000 steps a slice got 4,545 slices in one drain, where the budget allows about twenty;
  • only the pump's 0.1 s time backstop stopped it.

The fix

  • execute_process_step records how far its step moved the process's step count (get_step_count()): the step itself, plus anything it added.
    • It reads the count before a finished process lets go of its state, whichever way the step ends.
  • The run loop counts that amount (at least one) against max_steps, and sync_run_steps() returns the same count.
  • An iteration that picks nothing still counts one.

A plain program charges one step a pick, so its count is unchanged. Two kinds of work done inside a step now count:

  • script engines' slices;
  • an inline async call's run time (STATE_EXEC_EXCEPTIONS.md 3.8).

Every pump of an async scheduler counts this way: the Ariadne drain, exec_group's pump and pycvc's Exec. The sync scheduler is unchanged.

Docs

  • async_scheduler.h's run/sync_run_steps.
  • The developer guide's notes on pumping.
  • The scripting hosts roadmap:
    • a §8.3 "G1's fifth part, built" bullet, with the item off "Left for G1";
    • §8.5's Slices bullet;
    • the G1 row.

Tests

Local, Windows static Release tree:

  • New tests:
    • AsyncSchedulerTest.ARunsStepBudgetCountsWhatAStepCharged: a native charging 1,000 steps a call uses up a 5,000-step run in about five calls.
    • ScriptEngineTest.ADrainCountsWhatTheSlicesCharge: about twenty 10,000-step slices a drain, and as many in the next.
  • Both fail with the old count put back: 1,000 calls in a 5,000-step run, and 4,545 slices in a drain.
  • Suites:
    • ariadne_script_engine_test 23/23 and ariadne_wasm_test 18/18, three runs each;
    • state_exec_async_test 107/107 and state_exec_groups_test 28/28;
    • ariadne_runtime_test 262/262 and state_exec_exceptions_test 25/25;
    • the arix_wasm_block and ari_wasm_needs_arix ctests.

Left for G1

  • The lock manager for the instance, in place of a frame at a time, and RecursionError for indirect re-entry.
  • The key, pointer, signal and message hooks.
  • The state imports and §8.4.1's writes.
  • A host option for state_exec.policy.
  • wasmtime in the recipes.

…fth part)

async_scheduler's run loop counted a pick as one step against max_steps,
whatever the pick's evaluator step charged on top of itself through
evaluation_stats::add_steps. A script engine's slice charges its work that
way: Ariadne's ScriptSlice::charge, a wasm guest's fuel at 64 steps a slice.
So a slice cost the drain's 200,000-step pump budget one step, and a guest
could stretch a drain to its 0.1 s backstop: 4,545 slices of 10,000 steps
in one drain, where the budget allows about twenty.

Now execute_process_step records how much the step moved the process's step
count (its own step, plus what it added), read before a finished process
lets go of its state. The run loop counts that, at least one, against
max_steps, and sync_run_steps() returns the same count. An iteration that
picks nothing still counts one. A plain program charges one step a pick,
so nothing else changes; an inline async call's run time (3.8) now counts
too.

Tests: AsyncSchedulerTest.ARunsStepBudgetCountsWhatAStepCharged and
ScriptEngineTest.ADrainCountsWhatTheSlicesCharge; both fail on the old
count (1,000 calls in a 5,000-step run; 4,545 slices in a drain).

Docs: async_scheduler.h, the developer guide's pump notes, and the
scripting hosts roadmap (8.3, 8.5, the G1 row).
@transfix
transfix enabled auto-merge (squash) November 10, 2026 02:23
@transfix
transfix merged commit 6986679 into master Nov 10, 2026
16 of 30 checks passed
@transfix
transfix deleted the feat/wasm-guests-5 branch November 10, 2026 03:53
transfix added a commit that referenced this pull request Nov 10, 2026
Conflicts in script_engine.h and script_engine.cpp, both kept: the sliced
form is bound where the program's host parks (this branch) and takes its
activation's lock around the job (master's #1126). The lock is a with-lock
key on the app's one lock manager, which every group shares (4.19), so it
excludes across group 0 and isolated groups alike; STATE_EXEC_THREADED.md
says so. #1117's run loop counts what each pick charged, so a group's pump
budget counts a slice's steps as group 0's does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant