Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧵 feat: Implement Request Executor Pattern for Actions #4566

Merged
merged 5 commits into from
Oct 28, 2024

Conversation

danny-avila
Copy link
Owner

@danny-avila danny-avila commented Oct 28, 2024

Summary

This update introduces a new request executor pattern to fix thread-safety issues in concurrent action executions. Previously, shared mutable state could cause race conditions when the same action was called multiple times simultaneously, particularly with authentication headers and parameters.

Closes #4555

Key Changes:

  • Implement RequestExecutor pattern to provide isolated request states
  • Create immutable RequestConfig class to safely share configuration
  • Modify ActionRequest to act as a facade for creating new executors
  • Add comprehensive test suite for concurrent execution scenarios
  • Maintain backward compatibility through delegation and getters
  • improved type safety

Problem Solved:

When assistants made concurrent calls to the same action (e.g., multiple sqrt calculations), the shared mutable state would cause race conditions, resulting in incorrect API calls. The new pattern ensures each request maintains its own isolated state.

Checklist:

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective
  • Local unit tests pass with my changes

…t execution issues

BREAKING CHANGE: ActionRequest now uses a RequestExecutor pattern for isolated request state

- Introduce RequestConfig class to store immutable configuration
- Add RequestExecutor class to handle isolated request state for each execution
- Modify ActionRequest to act as a facade creating new executors for each operation
- Maintain backward compatibility through delegation and getters
- Add TypeScript types for better type safety
- Fix race conditions in concurrent executions with auth and params

This change prevents state mutation issues when the same action is called
multiple times concurrently, particularly when using authentication. Each
request now gets its own isolated state through a new executor instance,
solving race conditions while maintaining the existing API interface.
@danny-avila danny-avila merged commit 1526b42 into main Oct 28, 2024
4 checks passed
@danny-avila danny-avila deleted the refactor/actions branch October 28, 2024 17:42
BertKiv pushed a commit to BertKiv/LibreChat that referenced this pull request Dec 10, 2024
)

* chore: actions typing

* fix(actions): implement request executor pattern to prevent concurrent execution issues

BREAKING CHANGE: ActionRequest now uses a RequestExecutor pattern for isolated request state

- Introduce RequestConfig class to store immutable configuration
- Add RequestExecutor class to handle isolated request state for each execution
- Modify ActionRequest to act as a facade creating new executors for each operation
- Maintain backward compatibility through delegation and getters
- Add TypeScript types for better type safety
- Fix race conditions in concurrent executions with auth and params

This change prevents state mutation issues when the same action is called
multiple times concurrently, particularly when using authentication. Each
request now gets its own isolated state through a new executor instance,
solving race conditions while maintaining the existing API interface.

* ci: test isolation/immutatability

* chore: Update version to 0.7.51 in data-provider package

* refactor(actions): refactor createActionTool to use request executor pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant