GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(arty): add runtime hook API by martintmk · Pull Request #966 · microsoft/oxidizer

Conversation

@martintmk

@martintmk martintmk commented Nov 10, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

This change adds a typed runtime hook API to Arty.

  • Add HookFn<H, D>, which keeps worker-local data and a plain function pointer together.
  • Make HookFn cloneable and ThreadAware. Arty clones and relocates its data for each worker.
  • Let RuntimeBuilder::on and RuntimeControl::on accept any value that converts into HookFn.
  • Let third-party types implement standard From conversions without an Arty-specific adapter trait.
  • Add OnStart and OnPanic hook events.
  • Add OnPanic::IGNORE for the common policy that keeps the runtime running.
  • Replace async panic-policy configuration with OnPanic callbacks. Shutdown remains the default action.
  • Let arty_tokio::init retain private OnStart state for workers that future dynamic scaling creates.

API

use arty::runtime::Runtime;
use arty::runtime::hook::{HookFn, OnPanic, OnStart};

let runtime = Runtime::builder()
    .on(Foo::new(data))
    .on(OnPanic::IGNORE)
    .on(HookFn::<OnStart, _>::new((), |event, ()| {
        let _worker = event.thread();
    }))
    .build()?;

A third-party hook can carry its data and callback through a standard conversion:

impl From<Foo> for HookFn<OnPanic, Foo> {
    fn from(foo: Foo) -> Self {
        HookFn::new(foo, Foo::on_panic)
    }
}

Behavior

Hooks run in registration order. OnStart runs before RuntimeBuilder::build returns. Late registrations use the prioritized system-command queue for each worker. The runtime ignores registrations after shutdown starts.

Each async worker keeps one hook registry in worker-local storage. Hook invocation does not clone or move the registry or callback data.

OnPanic covers async task creation and task polling. A callback can call ignore() to keep the runtime available. It can call shutdown() to stop the runtime.

Blocking panics do not invoke OnPanic and do not stop the runtime. Their join handles still return the original panic payload.

The entry-point macros, runtime documentation, example, public contract tests, and Tokio compatibility layer use the new API.

Validation

  • cargo check -p arty -p arty_executor -p arty_macros_impl -p anyspawn --all-targets
  • cargo clippy -p arty --all-targets --all-features -- -D warnings
  • cargo test -p arty --test runtime_hooks --test panic --test construction --test public_paths
  • cargo test -p arty_executor --test lifecycle
  • cargo test -p arty_macros_impl
  • cargo check -p arty_tokio --all-targets
  • cargo test -p arty_tokio --test compatibility
  • cargo clippy -p arty_tokio --all-targets --all-features -- -D warnings
  • just anvil-fmt
  • just anvil-readme --fix
  • cargo check -p arty --all-targets after the final HookFn cleanup

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@martintmk
martintmk changed the base branch from martintmk-runtime-hook-api to main November 10, 2026 14:02
@martintmk martintmk changed the title refactor(arty): simplify runtime hook callbacks feat(arty): add runtime hook API Nov 10, 2026
martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/builder.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/worker/blocking/mod.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/dispatch/core.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/worker/asynchronous/protocol.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/examples/arty_hooks.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/hook/mod.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/hook/registry.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/hook/registry.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/hook/registry.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/worker/asynchronous/worker.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/testing.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty_executor/src/panic_policy.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 10, 2026
View reviewed changes
Comment thread crates/arty_executor/src/panic_policy.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Nov 10, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (ff31146) to head (f828785).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #966      +/-   ##
==========================================
  Coverage   100.0%   100.0%              
==========================================
  Files         798      136     -662     
  Lines       68902     8858   -60044     
==========================================
- Hits        68902     8858   -60044     
Flag Coverage Δ
linux 100.0% <100.0%> (ø)
linux-arm 100.0% <100.0%> (ø)
scheduled ?
windows 100.0% <100.0%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@martintmk
martintmk force-pushed the martintmk-reshape-runtime-hook-api branch from 234c703 to 084d7ee Compare November 11, 2026 07:36
martintmk
martintmk commented Nov 11, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/dispatch/client.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 11, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/worker/asynchronous/local_worker.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

martintmk
martintmk commented Nov 11, 2026
View reviewed changes
Comment thread crates/arty/src/runtime/worker/asynchronous/local_worker.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@martintmk
feat(arty): add runtime hook API
2dc6b7d
Introduce typed worker lifecycle hooks for startup and async panic handling. Keep hook data worker-local, route live registration through system commands, and leave blocking panics as join errors.

Co-authored-by: Copilot App <[email protected]>
@martintmk
martintmk force-pushed the martintmk-reshape-runtime-hook-api branch from 3d2db3e to 2dc6b7d Compare November 11, 2026 14:21
martintmk and others added 7 commits November 11, 2026 15:41
@martintmk
feat(arty_tokio): prepare future Arty workers
0392136
After init succeeds, retain a private OnStart hook with a relocated scheduler so future dynamically scaled workers enter the same Tokio context.

Co-authored-by: Copilot App <[email protected]>
@martintmk
feat(arty_tokio): retain future worker initialization
ba45292
Keep private OnStart state for future dynamic workers and cover the Arty panic fallback that runs without an installed scheduler.

Co-authored-by: Copilot App <[email protected]>
@martintmk
fix(arty): apply local hook registration immediately
cccc567
Co-authored-by: Copilot App <[email protected]>
@martintmk
test(arty): detect duplicate local hooks
84eead7
Co-authored-by: Copilot App <[email protected]>
@martintmk
feat(arty): reshape runtime hook API
65c0599
Co-authored-by: Copilot App <[email protected]>
@martintmk
refactor(arty): simplify runtime hook erasure
77f4a25
Co-authored-by: Copilot App <[email protected]>
@martintmk
refactor(arty): colocate hook registration
0d07278
Co-authored-by: Copilot App <[email protected]>
@martintmk
martintmk marked this pull request as ready for review November 12, 2026 09:02
Copilot AI balanced review requested due to automatic review settings November 12, 2026 09:02
Copilot started reviewing on behalf of martintmk November 12, 2026 09:02
View session
martintmk and others added 3 commits November 12, 2026 10:04
@martintmk
test(arty): keep hook events non-cloneable
cc0e68b
Co-authored-by: Copilot App <[email protected]>
@martintmk
refactor(arty): align erased hook visibility
20ae977
Co-authored-by: Copilot App <[email protected]>
@martintmk
refactor(arty): keep erased hooks crate-private
f828785
Co-authored-by: Copilot App <[email protected]>
Copilot AI reviewed Nov 12, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical hook-registration bugs can reorder panic handlers or trigger a reentrant mutable-borrow panic, selecting the wrong panic action or interrupting delivery of the original panic result.

4 open issues
  • High severity Queued hook registrations can be overtaken by local registrations · New
  • High severity Registering a hook inside OnPanic can panic on a reentrant borrow · New
  • Medium severity Example uses the macros feature without requiring it · New
  • Low severity Blocking task panic behavior is documented incorrectly · New
What changed in this PR

This PR adds typed runtime hooks to Arty, replacing async panic-policy configuration with callbacks and integrating hook registration into worker startup and runtime control.

Changes:

  • Add HookFn, OnStart, and OnPanic, with worker-local data and registration through builder and control APIs.
  • Route async panic decisions through hooks while keeping blocking panics isolated to their join handles.
  • Update entry-point macros, Tokio integration, documentation, examples, and contract tests.
File Description
crates/​arty/​tests/​runtime_hooks.rs Add public hook contract tests.
crates/​arty/​tests/​runtime_contracts.rs Use the ignore hook in panic tests.
crates/​arty/​tests/​public_paths.rs Check public hook types and traits.
crates/​arty/​tests/​panic/​self_wake.rs Migrate self-wake tests to hooks.
crates/​arty/​tests/​panic/​policy.rs Update async and blocking panic contracts.
crates/​arty/​tests/​panic_support/​mod.rs Configure shared test runtimes with hooks.
crates/​arty/​tests/​join_failures.rs Replace legacy panic configuration.
crates/​arty/​tests/​construction.rs Exercise hook-based runtime construction.
crates/​arty/​tests/​behavior_contracts.rs Use hooks in runtime behavior tests.
crates/​arty/​src/​task/​scheduler.rs Update the blocking-panic documentation reference.
crates/​arty/​src/​task/​runtime_scheduler.rs Update panic documentation and test configuration.
crates/​arty/​src/​task/​preparation/​tests.rs Revise blocking-panic preparation tests.
crates/​arty/​src/​task/​preparation/​blocking.rs Remove shutdown decisions for blocking panics.
crates/​arty/​src/​task/​handle/​error.rs Reference hooks in panic-error documentation.
crates/​arty/​src/​task/​handle/​channel.rs Remove an unused shutdown accessor.
crates/​arty/​src/​runtime/​worker/​blocking/​worker.rs Remove blocking-worker panic-policy state.
crates/​arty/​src/​runtime/​worker/​blocking/​panic_policy.rs Delete the blocking panic-policy type.
crates/​arty/​src/​runtime/​worker/​blocking/​mod.rs Remove panic-policy module wiring.
crates/​arty/​src/​runtime/​worker/​asynchronous/​worker.rs Resolve panics through hooks and process registrations.
crates/​arty/​src/​runtime/​worker/​asynchronous/​thread.rs Relocate hooks and invoke startup callbacks.
crates/​arty/​src/​runtime/​worker/​asynchronous/​local_worker.rs Store, invoke, and clear worker-local hooks.
crates/​arty/​src/​runtime/​worker/​asynchronous/​command.rs Add a hook-registration command.
crates/​arty/​src/​runtime/​testing.rs Centralize runtime test helpers.
crates/​arty/​src/​runtime/​mod.rs Export hooks and revise runtime defaults.
crates/​arty/​src/​runtime/​hook/​registry.rs Store ordered callback collections.
crates/​arty/​src/​runtime/​hook/​on_start.rs Define the worker-start event.
crates/​arty/​src/​runtime/​hook/​on_panic.rs Define panic events and response selection.
crates/​arty/​src/​runtime/​hook/​mod.rs Expose and document the hook API.
crates/​arty/​src/​runtime/​hook/​hook_fn.rs Pair callbacks with cloneable, relocatable data.
crates/​arty/​src/​runtime/​handle.rs Update runtime-handle tests and helpers.
crates/​arty/​src/​runtime/​dispatch/​core.rs Distribute registrations across live workers.
crates/​arty/​src/​runtime/​dispatch/​client.rs Forward hook registrations to dispatch.
crates/​arty/​src/​runtime/​control.rs Add late hook registration.
crates/​arty/​src/​runtime/​config/​runtime_config.rs Replace panic policy with hook storage.
crates/​arty/​src/​runtime/​config/​panic_policy.rs Delete the legacy public panic policy.
crates/​arty/​src/​runtime/​config/​mod.rs Remove the legacy policy export.
crates/​arty/​src/​runtime/​builder.rs Add hook registration during construction.
crates/​arty/​src/​runtime/​bootstrap/​startup.rs Clone configured hooks for each worker.
crates/​arty/​examples/​arty_hooks.rs Demonstrate panic-hook registration.
crates/​arty/​docs/​PANICS.md Explain hook-based panic handling.
crates/​arty/​Cargo.toml Register the hook example.
crates/​arty/​AGENTS.md Update async panic-handling guidance.
crates/​arty_tokio/​src/​lib.rs Document intended support for future workers.
crates/​arty_tokio/​src/​initialization.rs Register a startup hook for Tokio context installation.
crates/​arty_tokio/​Cargo.toml Add relocation and mutation-test dependencies.
crates/​arty_macros_impl/​src/​lib.rs Generate hook-based panic configuration.
crates/​arty_executor/​tests/​lifecycle/​completion_lifecycle.rs Cover dynamic panic decisions.
crates/​arty_executor/​src/​task.rs Resolve panic actions before publishing completion.
crates/​arty_executor/​src/​panic_policy.rs Add dynamic panic resolution.
crates/​anyspawn/​tests/​arty.rs Migrate Arty integration tests to hooks.
Cargo.lock Record added Tokio integration dependencies.

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/arty/src/runtime/dispatch/core.rs
Comment on lines +215 to +216
if let Some(source) = &source {
LocalWorker::install_hook(hook.clone(), Some(source));
Comment thread crates/arty/src/runtime/worker/asynchronous/local_worker.rs
let current = current.expect("a running worker retains its scheduler while processing hook registration");
current.thread.clone()
});
HOOKS.with_borrow_mut(|hooks| {
Comment thread crates/arty/Cargo.toml

[[example]]
name = "arty_hooks"
required-features = ["rt"]
Comment thread crates/arty/src/task/scheduler.rs
/// processing timers. The function runs on a separate pool thread.
/// A panic in this function returns an error through [`JoinHandle`] and
/// follows the configured [`PanicPolicy`](crate::runtime::PanicPolicy).
/// follows the configured [`OnPanic`](crate::runtime::hook::OnPanic) hook.
Copilot AI balanced review requested due to automatic review settings November 12, 2026 09:11
Copilot started reviewing on behalf of martintmk November 12, 2026 09:12
View session
Copilot AI reviewed Nov 12, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Hook registration can violate callback order or trigger mutable-borrow panics during callback execution, and the new example lacks its required macros feature gate.

4 open issues
  • High severity Registering a hook inside OnPanic can panic on a reentrant borrow
  • High severity Queued hook registrations can be overtaken by local registrations
  • Medium severity Example uses the macros feature without requiring it
  • Low severity Blocking task panic behavior is documented incorrectly
4 previously missed issues

In code that hasn't changed since last review

Medium severity Register test hooks on the worker before submitting the panic task

crates/​arty/​tests/​runtime_hooks.rs:173

These external registrations are not acknowledged before the test submits a panicking task. In worker.rs, a worker can check the system queue before registration arrives, then receive and poll the task in the same cycle with the old panic response. Perform both registrations on the worker, where on applies synchronously, and wait for each registration call to finish before submitting the panic task.

Medium severity Acknowledge registration on both workers before checking the counter

crates/​arty/​tests/​runtime_hooks.rs:252

The counter is read before either worker is known to have processed the late registration, so an incorrect OnStart replay can go unnoticed. Shutdown can also discard the queued registration. Add an acknowledgement of registration processing on both workers before checking the counter; an ordinary task is not a sufficient barrier because prepare_cycle can receive it after checking the system queue.

Low severity Clarify shutdown behavior for async and blocking failures

crates/​arty/​src/​task/​handle/​error.rs:27

The default-shutdown description also needs the new async/blocking distinction. Blocking failures return this same JoinError, but task/preparation/blocking.rs no longer starts shutdown or invokes OnPanic. Limit the default shutdown and ignore-hook statements to async factories and polls, and state the blocking behavior explicitly.

Low severity Update the contract for blocking panic behavior

crates/​arty/​src/​task/​runtime_scheduler.rs:205

This still promises hook handling for blocking panics, but task/preparation/blocking.rs:35–39 now only reports them through their join handles. OnPanic explicitly excludes blocking functions. Update this method's contract so callers do not rely on a hook to observe blocking failures or request shutdown.

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

At least 2 approving reviews are required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@martintmk
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.