Skip to content

refactor(protocol/sandbox): remove store clear counter#5466

Open
ark0f wants to merge 47 commits into
masterfrom
al/verify-wasmtime-store-clear
Open

refactor(protocol/sandbox): remove store clear counter#5466
ark0f wants to merge 47 commits into
masterfrom
al/verify-wasmtime-store-clear

Conversation

@ark0f
Copy link
Copy Markdown
Member

@ark0f ark0f commented May 17, 2026

Closes #5465

Summary

Removes the sandbox store clear counter plumbing now that the runtime uses the Wasmtime backend. The sandbox host context no longer tracks a per-thread clear counter, the runtime/node/replay entry points initialize the sandbox backend without a clear limit, and the CLI option was removed.

Keeps the Criterion benchmark that compares a long-lived Wasmtime-backed sandbox store with periodic store clearing, so the old Wasmer-era workaround stays covered by measurable evidence.

How to test

cargo test -p gear-sandbox-host init_selects_backend_without_store_clear_limit
cargo clippy -p gear-sandbox-host -p gear-sandbox-interface -p gear-cli -p gear-replay-cli --all-targets -- -D warnings
cargo bench -p gear-sandbox-host --bench wasmtime_store_growth

Notes

Current local benchmark result did not show a Wasmtime slowdown comparable to the old Wasmer behavior:

wasmtime_store_growth/long_lived_store
                        time:   [67.335 us 67.885 us 68.493 us]
wasmtime_store_growth/clear_periodically
                        time:   [69.142 us 70.486 us 72.269 us]

Checklist

  • PR title follows Conventional Commits (type(scope): description)
  • Single logical change
  • Tests added or updated (if logic changed)
  • Docs updated (if needed)

ark0f and others added 30 commits September 21, 2025 18:19
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	ethexe/processor/src/host/api/mod.rs
#	ethexe/rpc/src/lib.rs
#	ethexe/signer/src/storage.rs
#	examples/ctor/build.rs
#	gcli/src/template.rs
#	pallets/gear/src/tests.rs
#	sandbox/host/Cargo.toml
#	sandbox/host/src/sandbox/wasmer_backend.rs
#	sandbox/sandbox/Cargo.toml
#	sandbox/sandbox/src/embedded_executor.rs
#	utils/calc-stack-height/src/main.rs
#	utils/gear-wasmer-cache/Cargo.toml
#	utils/gear-wasmer-cache/src/lib.rs
#	utils/gring/tests/command.rs
#	utils/lazy-pages-fuzzer/src/wasmtime_backend.rs
@ark0f ark0f added type: refactor Internal improvements without changing behavior scope: vara Vara Network (Layer 1) ai-friendly Suitable for AI-assisted implementation or review labels May 17, 2026
Comment thread protocol/sandbox/host/benches/wasmtime_store_growth.rs Outdated
Base automatically changed from al/wasmtime-migration to master May 26, 2026 19:03
…store-clear

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	ethexe/processor/src/host/api/mod.rs
#	protocol/lazy-pages/fuzzer/src/wasmtime_backend.rs
#	protocol/lazy-pages/src/sys/windows.rs
#	protocol/sandbox/host/src/sandbox/wasmtime_backend.rs
#	protocol/sandbox/src/embedded_executor.rs
#	utils/gear-workspace-hack/Cargo.toml
#	vara/pallets/gear/src/schedule.rs
#	vara/runtime/interface/sandbox/src/detail.rs
@ark0f ark0f changed the title refactor(vara): remove sandbox store clear counter refactor(protocol/sandbox): remove store clear counter May 30, 2026
@ark0f ark0f added scope: gear Gear protocol and removed scope: vara Vara Network (Layer 1) labels May 30, 2026
@ark0f ark0f marked this pull request as ready for review May 30, 2026 18:47
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the sandbox protocol by eliminating the store clear counter, a mechanism that became redundant with the full adoption of the Wasmtime backend. The change simplifies the host context, removes related configuration options from the CLI, and ensures that sandbox initialization no longer involves a clear limit. A new benchmark has been added to validate that this removal does not negatively impact performance, particularly concerning Wasmtime store growth.

Highlights

  • Sandbox Store Clear Counter Removal: The mechanism for periodically clearing the sandbox store, previously used as a workaround for Wasmer, has been entirely removed. This includes the per-thread clear counter in the sandbox host context.
  • Wasmtime Backend Integration: With the runtime now exclusively using the Wasmtime backend, the store clear counter is no longer necessary, simplifying the sandbox initialization process across runtime, node, and replay entry points.
  • CLI Option Deprecation: The command-line interface option sandbox_store_clear_counter_limit has been removed, streamlining configuration and reflecting the removal of the underlying functionality.
  • New Benchmark for Wasmtime Store Growth: A new Criterion benchmark has been introduced to compare the performance of a long-lived Wasmtime-backed sandbox store against one with periodic clearing, ensuring performance is maintained without the old workaround.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes the sandbox store clear counter limit logic and its associated CLI argument, simplifying sandbox initialization. It also introduces a new benchmark, wasmtime_store_growth, to evaluate Wasmtime store growth. However, the benchmark code contains several compilation issues, including references to private wasmtime constants and the use of unstable Rust features like is_multiple_of and let chains, which will fail to compile on stable Rust.

Comment thread protocol/sandbox/host/benches/wasmtime_store_growth.rs
Comment thread protocol/sandbox/host/benches/wasmtime_store_growth.rs
Comment thread protocol/sandbox/host/benches/wasmtime_store_growth.rs
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b3829b5d7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

state.sandboxes.clear(&mut state.clear_counter);
state
.sandboxes
.get(supervisor_context.data_ptr())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve periodic Wasmtime store resets

When a worker thread keeps using the same StoreData pointer, this now creates each sandbox memory/instance in the same long-lived Wasmtime Store indefinitely. Wasmtime increments the store's lifetime instance/resource counters on each module instantiation and enforces the default 10,000-instance limit, so after enough program executions on the same runtime store, new_memory/instantiation starts failing even though Gear tears down its handles. The removed clear counter was the only path that refreshed this backend store before store_data_ptr changed, so long-running nodes can hit this limit under normal block processing.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@codex verify the usage of memory_teardown and instance_teardown functions. I guess the limit should be unattainable

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b3829b5d7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

state.sandboxes.clear(&mut state.clear_counter);
state
.sandboxes
.get(supervisor_context.data_ptr())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore a reset before exhausting Wasmtime store limits

For long-lived runtime stores, relying on memory_teardown/instance_teardown is not enough: those functions only replace Gear's handle slots with None, while the underlying Wasmtime Store keeps monotonically bumped resource counters (DEFAULT_INSTANCE_LIMIT/DEFAULT_MEMORY_LIMIT are 10,000 and are not decremented on teardown). After roughly 10k sandbox instantiations on the same StoreData pointer, instantiate starts returning ERR_MODULE from Wasmtime's resource limit even though every Instance/Memory was dropped; the new benchmark also has to recreate BenchState before that limit, which confirms the limit is reachable unless the store is periodically cleared/recreated here.

Useful? React with 👍 / 👎.

@ark0f ark0f added the pr: do-not-merge Must not be merged label May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-friendly Suitable for AI-assisted implementation or review pr: do-not-merge Must not be merged scope: gear Gear protocol type: refactor Internal improvements without changing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Verify whether sandbox store clear workaround is still needed with Wasmtime

2 participants