Skip to content

Add epoch deadline callback binding to Store - #373

Merged
martindevans merged 1 commit into
bytecodealliance:mainfrom
rlauuzo:feat/epoch-deadline-callback
Aug 16, 2026
Merged

Add epoch deadline callback binding to Store#373
martindevans merged 1 commit into
bytecodealliance:mainfrom
rlauuzo:feat/epoch-deadline-callback

Conversation

@rlauuzo

@rlauuzo rlauuzo commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Wasmtime's wasmtime_store_epoch_deadline_callback was unbound, so the only way to bound wasm execution was a single SetEpochDeadline fixed at call start. Stopping a running guest early meant incrementing the engine-wide epoch, which traps every other in-flight store sharing the engine.

Store.SetEpochDeadlineCallback binds it: the callback runs on the executing thread when the deadline is reached, and either returns a new relative deadline to resume with, or throws to terminate the execution. A throwing callback surfaces to the caller as the inner exception of a WasmtimeException, using the same CallbackErrorCause mechanism as host function callbacks, so a host can renew a short deadline per tick and stop the guest on cancellation.

Yielding (WASMTIME_UPDATE_DEADLINE_YIELD) is not exposed, as it requires async support this binding does not enable.

Covered by tests for deadline renewal, callback replacement and null arguments.

Wasmtime's `wasmtime_store_epoch_deadline_callback` was unbound, so the only way
to bound wasm execution was a single `SetEpochDeadline` fixed at call start.
Stopping a running guest early meant incrementing the engine-wide epoch, which
traps every other in-flight store sharing the engine.

`Store.SetEpochDeadlineCallback` binds it: the callback runs on the executing
thread when the deadline is reached, and either returns a new relative deadline
to resume with, or throws to terminate the execution. A throwing callback
surfaces to the caller as the inner exception of a `WasmtimeException`, using the
same `CallbackErrorCause` mechanism as host function callbacks, so a host can
renew a short deadline per tick and stop the guest on cancellation.

Yielding (`WASMTIME_UPDATE_DEADLINE_YIELD`) is not exposed, as it requires async
support this binding does not enable.

Covered by tests for deadline renewal, callback replacement and null arguments.

@martindevans martindevans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks for working on this

@martindevans
martindevans merged commit 91c8ce6 into bytecodealliance:main Aug 16, 2026
6 checks passed
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.

2 participants