Skip to content

Ariadne: a resident that stops is restarted; a setting for its step cap - #917

Merged
transfix merged 17 commits into
masterfrom
feat/ari-resident-restart
Oct 31, 2026
Merged

transfix merged 17 commits into
masterfrom
feat/ari-resident-restart

Conversation

@transfix

@transfix transfix commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

A tick, input or signal resident that is killed or fails is now started again, instead of staying dead for the rest of the document. A load:ed module's on_tick: (#904) is a resident too, so a module's request loop can no longer get stuck.

Stacked on #904 (feat/ari-module-on-tick). Rebase onto master once #904 merges.

Why

cypkg's browser test sees one load:ed module's on_tick: request never resolve, in about 1 run of 3 on a heavily loaded machine. The module stays on "loading..." while the rest of the page runs. What was checked in the code:

  • Never restarted. Once a resident was killed or failed, nothing started it again:

    • ensure_resident returned early because the pid slot was still set;
    • ensure_mount_tick returned early once the channel was set;
    • post_tick kept posting to the dead channel.

    The same held for the document's own residents. A dead on_signal: also swallowed every Ctrl-C, because post_signal saw a pid and reported the signal handled.

  • The step cap. The 50 ms per-step cap is a se::time_budget. Its first half is charged on the steady clock. Its second half is charged on thread CPU time, with each gap between checks counted up to 1/16 of that half. So on native builds a descheduled step must still run 25 ms itself before it is killed. Single-threaded wasm has no thread CPU clock (thread_cpu_seconds is the steady clock there), so a step that checks often on a loaded box is charged for its waits too.

What changes

  • Restart policy (retire_if_stopped, in the per-drain sweep). A killed or failed resident is reported once per message, as before, then reaped and scheduled to start again on a later drain:
    • the first time, at once;
    • while it keeps stopping within 100 drains of starting, after 1, 2, 4 … up to 64 drains;
    • after 8 such stops in a row, it is given up with a warning, until its program is set again (a reload does that).
  • Every lane. The policy covers on_tick, on_key, on_pointer, on_signal and each module's on_tick. A module's tick restarts from the drain, whether or not the mount is drawn.
    • A signal that arrives during the restart delay starts its handler at once.
    • A key or pointer event that arrives during the delay is dropped, as it is when a document has no handler.
  • One record per resident. The document's four lanes and each MountTick share one Resident record (context, pid, restart state), instead of parallel context and pid fields.
  • Step-cap setting. The cap is now the tree setting ariadne.limits.resident_max_step_time, in seconds, with 0 meaning no cap. It is read as each resident starts. The default is 0.05 s natively and 1 s in wasm. Scheduler time semantics are unchanged.
  • A start that throws (not a syntax error, which is read inside the process) is given up at once. Before, it was retried every drain behind a deduplicated warning.

Not done

Tests

  • ariadne_host_test AriadneResidents.*:
    • a tick that raises once is restarted and runs again;
    • a module tick killed by a tiny resident_max_step_time is restarted, and runs once the cap is lifted;
    • a tick that always raises is given up after the first run and 8 restarts, stays given up, and starts afresh on a reload.
  • Locally, all pass: host 41, runtime 211, ari_test_command_test 8, ftxui 66, loader 207, ari_net 8.
  • Docs: ARIADNE.md §2.3 (the cap, the setting and the restart policy for every lane) and §2.4 ("Keeping a resident running").

transfix and others added 15 commits October 30, 2026 01:00
- (quit [code]): AppRuntime::register_quit() binds `on: quit` and the verb; the
  first close request's code is exit_code(). ari run/snapshot/check and arigl (window
  and --terminal) exit with it; snapshot stops on the frame the document quit.
- (assert cond [message [data]]): a builtin raising AssertionError (a new class under
  Exception), "assertion failed[: message]"; its traceback ends at the form.
- tests: block (name -> program) captured by the loader; Runtime::run_program runs a
  program on the action lane and reports how it ended to a callback.
- ari test [--tap] [--timeout S] [--frames N] doc.ari...: each document headless until
  it quits, its tests have run, N frames, or the timeout. Fails on a non-zero quit, an
  uncaught error, a failed or warning load, a failed test, or a timeout. One line per
  document with what failed and in which program; TAP with --tap; exit 1 on failure.
  Network flags and settling as snapshot's.
- Action failure warnings name their program; resident ones their lane.
- Docs: ARIADNE.md §13, the exceptions table, the developer guide.
…s modules (#894)

- functions: (top level): a program of (defun ...) forms that every program in the
  document's scope can call (init:, on:, residents, key bindings, tests:); anything
  else is skipped with a warning. import: merges a library's functions.
- load: functions: [names] | name | "*": grants the parent's functions to the module,
  each with the functions it calls; a module gets none otherwise, and its own
  functions: stay inside it. Code, not authority: a granted function runs chrooted to
  the module.
- Mechanism: Widget::functions (FunctionScope) on the root and every mount wrapper; the
  runtime keeps a function-scope stack beside the mount scopes and runs the scope's
  prelude ahead of each program (actions, residents, run_program, init:, mount init:).
- The free-head preflight is scope-aware and scans function bodies and mount init:.
- Docs: ARIADNE.md §6.6.
- Loader: expand_load captures the fragment's on_tick: onto the mount wrapper
  (Widget::tick_script), as it does init:. A fragment's on_key:, on_pointer: and
  on_signal: now load with a warning instead of being dropped silently: input and
  signals stay the outermost document's (docs/ARIADNE.md §6.3).
- Runtime: one tick resident per mount sub-prefix, owner-tagged, chrooted there with
  the mount's FunctionScope prelude, on <owner>#tick@<sub-prefix>, woken each drain by
  post_tick. Started on the mount's first frame, after its init:. A reconcile keeps it
  when the new tree has the same mount and program, and stops it otherwise. A repeated
  mount's instance stops when its outermost repeat: count drops below it.
- A failing module tick is reported as on_tick: of mount '<sub-prefix>'. The preflight
  and the channel lint scan a mount's on_tick:.
- Tests: AriadneModuleTick.* (ariadne_host_test), AriTest.AModulesOnTickRuns.
- Docs: ARIADNE.md §2.3, §2.4, §6.3, §7.4.
Conflicts with the locks spawn context (#865) and --credential-env (#895): the sweep keeps
run_program's report and the spawned children's reap; ari test settles with AppRuntime::settle,
which replaced settle_async_calls; --timeout joins --credential-env among the value flags.
…-tick

The locks spawn context (#865) makes resident contexts shared and built by
make_action_context: a mount's tick resident is made the same way, chrooted to its
sub-prefix.
…illing

stepped_solve::impl did f.assign(nv, f[0]): the value is a reference into f, and libc++'s
assign frees the old buffer before filling the new one, so on macOS every entry was read
from freed memory (Fem.SteppedPoissonMatchesTheOneShotSolve, rel diff 6.7e268 in the macOS
recipe lanes). libstdc++ and MSVC copy the value first, so Linux and Windows passed.
Takes #903's fix for the stepped Poisson solve in place of the same fix made here.
- A tick, key, pointer or signal resident, or a module's tick, that is killed (its
  per-step cap, a syntax error read inside it) or fails (an exception it didn't catch)
  is reported once per message as before, reaped, and started again on a later drain:
  at once the first time, then 1, 2, 4 ... up to 64 drains later while it keeps
  stopping within 100 drains of starting. After 8 such stops in a row it is given up
  with a warning, until its program is set again. A module's tick restarts whether or
  not the mount is drawn. A signal arriving during the delay starts its handler at once.
  Before, a stopped resident stayed dead: a module's on_tick request loop sat on
  "loading..." for good, and a dead on_signal swallowed every Ctrl-C.
- Residents share one Resident record (context, pid, restart state) instead of
  parallel context and pid fields.
- The per-step cap is the tree setting ariadne.limits.resident_max_step_time (0 = none),
  default 0.05 s, 0.25 s in wasm, which has no thread CPU clock, so a step that checks
  often on a loaded machine is charged for its waits.
- Tests: AriadneResidents.* (a failed tick restarts, a module tick killed by its cap
  restarts, one that always fails is given up and a reload starts it afresh).
- Docs: ARIADNE.md §2.3, §2.4.
cypkg's browser test (single-threaded ari.html, load 10-33): with the 0.05 s cap one run of
nine lost a module's tick; with 2 s none of nine did. A runaway step in a tab then freezes it
for at most a second before the resident is killed and restarted.
Base automatically changed from feat/ari-module-on-tick to master October 31, 2026 07:35
The PRs below this one landed on master squashed, so this branch's own change is applied to master
unchanged.
@transfix
transfix enabled auto-merge (squash) October 31, 2026 07:37
…estart

# Conflicts:
#	src/cvc/tests/ariadne_host_test.cpp
transfix added a commit that referenced this pull request Oct 31, 2026
… file

#917 adds its resident-restart tests where these were, after the module-tick tests; at the end
they no longer conflict with it, whichever lands first.
@transfix
transfix merged commit 27c8fab into master Oct 31, 2026
21 of 27 checks passed
@transfix
transfix deleted the feat/ari-resident-restart branch October 31, 2026 18:24
transfix added a commit that referenced this pull request Oct 31, 2026
#917 landed as 27c8fab, whose tree is 6c3d4cc's, the #917 head this branch already has; so the
tree is unchanged.
transfix added a commit that referenced this pull request Oct 31, 2026
…ning process (#927)

* state_exec: the resource intrinsics and state-watch speak for the running process

A host that runs programs on a shared scheduler gives each intrinsics context a placeholder
process and no pid: Ariadne's action and resident lanes do. time-elapsed, time-limit,
step-count, memory-limit and the message counters read that placeholder, so they reported 0
there, and a loop bounded by (time-elapsed) never ended. state-watch registered its handler
for pid 0, which the scheduler ignored, so a watch set from an action or a resident never
fired.

They now use the process the scheduler is stepping (running_process / running_pid), as
self-pid, budget-usage, msg-send and await already did, and the context's own only with no
step running. Tests (AriadneResourceIntrinsics.*): a resident's clock-bounded loop ends by
the clock with a non-zero step count, an action sees its time limit, and a resident's watch
fires; each fails on master. Docs: the developer guide.

* ariadne_host_test: the resource-intrinsics tests go at the end of the file

#917 adds its resident-restart tests where these were, after the module-tick tests; at the end
they no longer conflict with it, whichever lands first.

---------

Co-authored-by: nicotina-ci <[email protected]>
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