fix: prevent invalid component instance reuse across chained invocations #224
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.
Feature or Problem
This PR fixes a correctness issue where component instances were incorrectly reused across chained invocations.
In multi-component execution flows (e.g. A → B → C → B), wasmCloud previously captured a
ComponentExportIndexat link time and attempted to reuse the same component instance on subsequent invocations. This causedget_functo fail withfunction not found, even though the export existed and was successfully invoked earlier.This change introduces a scoped instance cache keyed by exporter component ID and store ID, ensuring component instances are only reused when it is safe to do so. When the store changes or no cached instance exists for a given exporter, a fresh instance is created.
This avoids stale instance reuse and eliminates silent runtime failures when the same component is invoked more than once in a chained, multi-component execution flow.
Example failure (logs)
Fully general instance reuse across stores would likely require upstream changes in Wasmtime. This PR instead scopes instance reuse conservatively to preserve correctness.
Related Issues
Release Information
Consumer Impact
Testing
Unit Test(s)
Acceptance or Integration
Manual Verification