Skip to content

Merge callback instance imports#1998

Draft
cursor[bot] wants to merge 1 commit intofeat/sync-wasm-merge-callbackfrom
cursor/merge-callback-instance-imports-0083
Draft

Merge callback instance imports#1998
cursor[bot] wants to merge 1 commit intofeat/sync-wasm-merge-callbackfrom
cursor/merge-callback-instance-imports-0083

Conversation

@cursor
Copy link
Contributor

@cursor cursor bot commented Feb 14, 2026

Fix: Merge callback instance instantiation fails due to missing imports

Description

This PR addresses a bug in the create_merge_callback() function where WASM modules for custom CRDT merge logic failed to instantiate. The issue stemmed from using wasmer::Imports::default() (empty imports), which caused instantiation to fail for modules that declare host function imports (common in real applications), even if the merge export itself doesn't call them. This resulted in the merge callback being None and NoWasmCallback errors during conflict resolution for CrdtType::Custom.

The fix ensures that the merge callback instance is created with a complete set of stub imports, satisfying all module import requirements. These stubs will trap if called, but pure merge functions are not expected to call host functions.

Fixes bug b4b3194a-aa72-4c72-a538-e473373df5b1.

Test plan

  • Verified that the code compiles successfully using cargo check.
  • Executed the full test suite with cargo test, and all 107 tests passed.
  • Ran cargo fmt --check and cargo clippy to ensure code quality and style.

Documentation update

None.


The create_merge_callback() function was using wasmer::Imports::default()
which is empty. However, real WASM modules import host functions from the
'env' namespace. Even though merge functions don't actually call those
host functions at runtime, Wasmer requires all imports to be satisfied
at instantiation time.

This fix creates stub imports that satisfy the module's import requirements.
These stubs trap if called (which shouldn't happen since merge functions
are pure data merge operations).
@cursor
Copy link
Contributor Author

cursor bot commented Feb 14, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions
Copy link

Your PR title does not adhere to the Conventional Commits convention:

<type>(<scope>): <subject>

Common errors to avoid:

  1. The title must be in lower case.
  2. Allowed type values are: build, ci, docs, feat, fix, perf, refactor, test.

Copy link

@meroreviewer meroreviewer bot left a comment

Choose a reason for hiding this comment

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

🤖 AI Code Reviewer

Reviewed by 3 agents | Quality score: 100% | Review time: 102.6s

🟡 1 warnings. See inline comments.


🤖 Generated by AI Code Reviewer | Review ID: review-1e5e7c0a

let instance = Instance::new(&mut store, &self.module, &imports).ok()?;
merge_callback::RuntimeMergeCallback::from_instance(store, instance)
}

Copy link

Choose a reason for hiding this comment

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

🟡 Bug fix lacks regression test

This fixes a bug where modules with host imports couldn't instantiate merge callbacks, but no test was added to prevent regression.

Suggested fix:

Add a test with a WASM module that declares host function imports and verify `create_merge_callback()` returns `Some(_)` instead of `None`.

@github-actions
Copy link

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions bot added the Stale label Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant