Skip to content

Conversation

@JMLX42
Copy link

@JMLX42 JMLX42 commented Dec 29, 2025

Summary

Implements opt-in stateful mode where Store/Instance persist per-component for the lifetime of the process, enabling in-memory state and WASI resource continuity across tool calls.

Closes #615

Implementation Tasks

  • Create LoadOptions struct with stateful: bool field
  • Create StatefulInstance struct for caching Store/Instance
  • Add stateful_instances cache to LifecycleManager
  • Update load_component to accept LoadOptions parameter
  • Update execute_component_call for stateful mode
  • Update unload_component to clean up stateful instances
  • Write unit tests for stateful mode
  • Update documentation

Design

See implementation plan for full design details.

Key characteristics:

  • Opt-in: Enabled via stateful: true parameter at load time
  • Per-component: Each stateful component gets one persistent Store/Instance pair
  • Serialized execution: Concurrent calls to the same stateful component are queued
  • Process-scoped: State lives until component unload or process exit

Test Plan

  • Unit test: stateful component retains memory across calls
  • Unit test: concurrent calls are serialized (not interleaved)
  • Unit test: unload drops state, reload starts fresh

Note: Tests require fixing pre-existing compilation errors in mcp-server crate on upstream/main.

Add LoadOptions struct and StatefulInstance cache to support persistent
Store/Instance pairs for components that need in-memory state and WASI
resource continuity across tool calls.

Part of microsoft#615
- Add load_component_with_options for explicit LoadOptions
- Implement execute_stateful_component_call with persistent Store/Instance
- Serialize concurrent calls to stateful components via mutex
- Clean up stateful instances on unload and reload
Tests verify:
- LoadOptions default and explicit values
- Loading components with stateful: true
- Multiple calls to stateful components
- Unload clears stateful state
- Reload clears previous stateful state
- Stateless components still work
Add documentation for stateful vs stateless components in concepts.md,
explaining when and how to use stateful mode for components that need
to maintain in-memory state across tool calls.
@JMLX42
Copy link
Author

JMLX42 commented Dec 29, 2025

CI Failures - Pre-existing Issue on main

The CI failures are not caused by this PR. They are pre-existing on upstream/main due to a recent rmcp dependency update that added new required fields (meta, icons, title) to Tool and CallToolResult structs.

Verification:

$ git checkout upstream/main
$ cargo check --all
error[E0063]: missing field `meta` in initializer of `rmcp::model::CallToolResult`
# ... same errors

The wassette crate (which this PR modifies) compiles and tests pass:

$ cargo test -p wassette
test result: ok. 92 passed; 0 failed; 0 ignored

This PR should be mergeable once the mcp-server crate is updated to handle the new rmcp API.

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.

Support per-session/per-agent instances with persistent Store lifetime

1 participant