Skip to content

Conversation

@Aditya1404Sal
Copy link
Contributor

@Aditya1404Sal Aditya1404Sal commented Jan 6, 2026

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 ComponentExportIndex at link time and attempted to reuse the same component instance on subsequent invocations. This caused get_func to fail with function not found, even though the export existed and was successfully invoked earlier.

let func = instance
    .get_func(&mut store, func_idx)
    .context("function not found")?;

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)

hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044143Z  INFO lifting results name=betty-blocks:data-api/data-api fn_name=request results_buf=[Result(Ok(Some(String("{\"data\":{\"onePokemon\":{\"id\":33,\"name\":\"test\"}}}"))))]
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044166Z  INFO invoked dynamic export name=betty-blocks:data-api/data-api fn_name=request results=[Result(Ok(Some(String("{\"data\":{\"onePokemon\":{\"id\":33,\"name\":\"test\"}}}"))))]
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044208Z  INFO lifting results name=betty-blocks:crud/crud fn_name=create results_buf=[Result(Ok(Some(String("{\"id\":33,\"name\":\"test\"}"))))]
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044213Z  INFO invoked dynamic export name=betty-blocks:crud/crud fn_name=create results=[Result(Ok(Some(String("{\"id\":33,\"name\":\"test\"}"))))]
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044233Z  INFO lifting results name=betty-blocks:create/[email protected] fn_name=create results_buf=[Result(Ok(Some(String("{\"id\":33,\"name\":\"test\"}"))))]
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044237Z  INFO invoked dynamic export name=betty-blocks:create/[email protected] fn_name=create results=[Result(Ok(Some(String("{\"id\":33,\"name\":\"test\"}"))))]
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044686Z  INFO Calling this export name: update
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044692Z  INFO Into the new box: update
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044695Z  INFO Before creating the instance: update
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044697Z  INFO Dropping existing instance: update
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044700Z  INFO Starting by getting the function from the instance: update
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044703Z  INFO Exported components: [("betty-blocks:update/[email protected]", ComponentInstance(ComponentInstance(Handle { index: TypeComponentInstanceIndex(12) })))]
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044712Z  INFO Imported components: [("betty-blocks:data-api/data-api", ComponentInstance(ComponentInstance(Handle { index: TypeComponentInstanceIndex(0) }))), ("betty-blocks:crud/crud",
... omitted for clarity
hostgroup-default-667c74c7f4-l8dwj host 2025-12-18T16:38:21.044732Z ERROR Error in gettin func: function not found

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

@Aditya1404Sal Aditya1404Sal force-pushed the fix/remove_existing_instance_reuse branch from 83fb275 to 51cb878 Compare January 6, 2026 19:22
@Aditya1404Sal Aditya1404Sal changed the title fix: Remove component reuse and enforce fresh instance usage on each invocation fix: prevent invalid component instance reuse across chained invocations Jan 7, 2026
@Aditya1404Sal Aditya1404Sal marked this pull request as ready for review January 7, 2026 07:23
@Aditya1404Sal Aditya1404Sal requested a review from a team as a code owner January 7, 2026 07:23
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.

1 participant