Skip to content

Conversation

@wtfsayo
Copy link
Member

@wtfsayo wtfsayo commented Dec 6, 2025

Summary

This PR implements parallel action execution within the processActions() method to improve performance for multi-action responses.

Changes

Core Runtime (packages/core/src/runtime.ts)

  • Execute actions within a single response batch in parallel using Promise.allSettled()
  • All actions in a batch receive the same initial state snapshot
  • State accumulates sequentially between response batches
  • Merge all ActionResult.values after parallel batch completes
  • Preserve fault tolerance: if one action fails, others still complete

Prompts (packages/core/src/prompts.ts)

  • Updated messageHandlerTemplate to reflect parallel execution model
  • Changed "IMPORTANT ACTION ORDERING RULES" to "IMPORTANT ACTION EXECUTION RULES"
  • Clarified that actions listed in a single response execute in parallel
  • Added guidance to use multi-step workflow for sequential dependencies

Action State Provider (packages/plugin-bootstrap/src/providers/actionState.ts)

  • Updated JSDoc and description to clarify "previous results" refers to prior response batches, not sibling parallel actions

Tests

  • Updated runtime.test.ts to match new state initialization behavior
  • Updated prompts.test.ts to match new prompt text

Key Data Flow

Response 1: [action1, action2, action3]
  ├─> Execute ALL in parallel with initialState
  ├─> Wait for all to complete
  └─> Merge results → accumulatedState

Response 2: [action4, action5]
  ├─> Execute ALL in parallel with accumulatedState from Response 1
  ├─> Wait for all to complete
  └─> Merge results → new accumulatedState

Testing

  • All existing runtime tests pass
  • All prompt tests pass
  • All multi-step workflow tests pass
  • Action chaining tests pass

Breaking Changes

None - backward compatible. Actions that previously assumed sequential execution within a batch will now run in parallel, but since they all receive the same state snapshot, behavior should be equivalent for independent actions.


Note

Execute actions in a response batch in parallel with a shared state snapshot, accumulate results across batches, and introduce AsyncLocalStorage-based prompt tracking with prompt/provider/test updates.

  • Core (runtime.ts):
    • Parallelize processActions per response using Promise.allSettled(); each batch shares a composed state snapshot; accumulate ActionResult.values and plan state between batches.
    • Add robust action resolution (exact/fuzzy/similes), error paths for missing action/handler, and consistent action memory/logging.
    • Preserve legacy returns (void/boolean) as completed; treat { success:false } (including minimal/error-only) as failed.
    • Merge working memory with size cap; cache action_results; update action plan immutably per step.
    • Introduce AsyncLocalStorage context: ActionContextStore, getCurrentActionContext, and browser fallback createBrowserFallback for prompt collection; include action context in useModel logs; skip collecting TEXT_EMBEDDING prompts.
  • Prompts (prompts.ts):
    • Update messageHandlerTemplate for parallel execution model and guidance on multi-step dependencies.
  • Provider (plugin-bootstrap/actionState.ts):
    • Clarify description/docs: "previous results" are from prior response batches; parallel actions share the same snapshot.
  • Tests:
    • Expand runtime.test.ts: parallel execution behavior, action result status semantics, prompt collection/isolation via AsyncLocalStorage, browser fallback behavior, exact vs fuzzy action matching.
    • Update prompts.test.ts for new execution rules and wording.

Written by Cursor Bugbot for commit 55765fc. This will update automatically on new commits. Configure here.

- Execute actions within a single response batch in parallel using Promise.allSettled()
- All actions in a batch receive the same initial state snapshot
- State accumulates sequentially between response batches
- Merge all ActionResult.values after parallel batch completes
- Preserve fault tolerance: if one action fails, others still complete
- Update prompts to reflect parallel execution model
- Update actionStateProvider to clarify 'previous results' refers to prior batches
- Update tests to match new behavior

This improves performance for multi-action responses while maintaining
proper state accumulation for multi-step reasoning workflows.
@wtfsayo wtfsayo marked this pull request as ready for review December 6, 2025 19:03
wtfsayo and others added 7 commits December 6, 2025 23:21
Introduces AsyncLocalStorage to track action context and prompts during parallel action execution in AgentRuntime. Updates prompt collection and logging to use the new context, ensuring prompts are isolated per action and supporting parallel-safe tracing. Adds comprehensive tests for prompt tracking, isolation, and context logging.
Enhances the browser fallback's context management to properly restore the store for both sync and async callbacks, ensuring correct context in async action handlers. Also refines action plan step updates to better distinguish between failed and successful (including legacy) action results.
Enhances the browser fallback's context management to properly restore the store for both sync and async callbacks, ensuring correct context in async action handlers. Also refines action plan step updates to better distinguish between failed and successful (including legacy) action results.

Add parallel-safe prompt tracking with AsyncLocalStorage

Introduces AsyncLocalStorage to track action context and prompts during parallel action execution in AgentRuntime. Updates prompt collection and logging to use the new context, ensuring prompts are isolated per action and supporting parallel-safe tracing. Adds comprehensive tests for prompt tracking, isolation, and context logging.

fix(core): Make AsyncLocalStorage browser-compatible with fallback
Updated tests to track action result status by intercepting createMemory calls instead of log calls. This change ensures verification of action status is based on memory creation, aligning with current runtime behavior.
@elizaOS elizaOS deleted a comment from coderabbitai bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 6, 2025
Increase fetch-depth to 50 for better commit history visibility. Update Claude review prompt to require checking previous comments, reviews, and commits, and to avoid repeating already addressed issues. Add instructions to acknowledge resolved issues and list only new actionable items.
Introduces a browser fallback implementation for AsyncLocalStorage with parallel usage detection and warnings. Enhances AgentRuntime to create error memories when an action is missing a handler or not found. Adds comprehensive tests for these behaviors and the browser fallback context handling.
@elizaOS elizaOS deleted a comment from coderabbitai bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@elizaOS elizaOS deleted a comment from cursor bot Dec 6, 2025
@claude
Copy link
Contributor

claude bot commented Dec 6, 2025

Claude finished @wtfsayo's task —— View job


Code Review Analysis

Todo List:

  • Read and analyze core runtime changes
  • Review test coverage and implementation
  • Check TypeScript types and error handling
  • Verify no breaking changes or security issues
  • Check adherence to repo patterns and tools
  • Provide actionable feedback

Review Results

CRITICAL: Excessive any type usage → Fix: Replace all any types with specific TypeScript types

  • packages/core/src/runtime.ts: Found 45+ instances of any type usage
  • Lines 233, 257, 441, 661, 741, 755, 762, 969, 1217, 1569-1744, and many others
  • This violates the "no any" rule and reduces type safety

⚠️ IMPORTANT: Missing error handling validation → Fix: Add comprehensive error handling tests

  • The parallel execution lacks specific tests for error scenarios during parallel action execution
  • Need tests for when one action fails while others succeed in the same batch
  • Should test Promise.allSettled error isolation behavior

⚠️ IMPORTANT: Browser fallback has known limitations → Fix: Add clear warnings in documentation

  • Lines 35-41: Browser fallback cannot provide true async context isolation
  • The current implementation warns at runtime but should be documented clearly
  • Consider more robust browser detection/handling

💡 SUGGESTION: Add timeout protection for parallel actions → Consider: Implementing per-action timeouts

  • Parallel actions could potentially hang indefinitely without timeout protection
  • Current implementation relies on individual action timeout handling only

💡 SUGGESTION: Improve AsyncLocalStorage type safety → Consider: Stricter typing for ActionContextStore

  • The browser fallback and real AsyncLocalStorage should share stricter type constraints
  • Current IAsyncLocalStorage<T> interface could be more type-safe

Positive Findings

Good test coverage - Comprehensive tests for parallel execution and prompt isolation
Proper use of bun test - All tests use bun test framework correctly
No security issues - No hardcoded credentials or injection vulnerabilities
Error isolation - Uses Promise.allSettled correctly for fault tolerance
State management - Proper state snapshot sharing and accumulation between batches

Main Issue

The excessive use of any types throughout the codebase is the primary blocker. This needs to be addressed before merge as it violates TypeScript best practices and the repository's coding standards.

Updates the runtime to correctly mark minimal ActionResult objects (e.g., { success: false }) and those with only an error field as 'failed' instead of 'completed'. Adds tests to verify that actions returning minimal failure results are properly handled.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 6, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/parallel-action-execution

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link
Contributor

claude bot commented Dec 6, 2025

Claude finished @wtfsayo's task —— View job


Code Review Analysis

Todo List:

  • Read and analyze core runtime changes
  • Review test coverage and implementation
  • Check TypeScript types and error handling
  • Verify no breaking changes or security issues
  • Check adherence to repo patterns and tools
  • Provide actionable feedback

Review Results

CRITICAL: Excessive any type usage → Fix: Replace all any types with specific TypeScript types

  • packages/core/src/runtime.ts: Found 45+ instances of any type usage
  • Lines 233, 257, 441, 661, 741, 755, 762, 969, 1217, 1569-1744, and many others
  • This violates the "no any" rule and reduces type safety

⚠️ IMPORTANT: Missing error handling validation → Fix: Add comprehensive error handling tests

  • The parallel execution lacks specific tests for error scenarios during parallel action execution
  • Need tests for when one action fails while others succeed in the same batch
  • Should test Promise.allSettled error isolation behavior

⚠️ IMPORTANT: Browser fallback has known limitations → Fix: Add clear warnings in documentation

  • Lines 35-41: Browser fallback cannot provide true async context isolation
  • The current implementation warns at runtime but should be documented clearly
  • Consider more robust browser detection/handling

💡 SUGGESTION: Add timeout protection for parallel actions → Consider: Implementing per-action timeouts

  • Parallel actions could potentially hang indefinitely without timeout protection
  • Current implementation relies on individual action timeout handling only

💡 SUGGESTION: Improve AsyncLocalStorage type safety → Consider: Stricter typing for ActionContextStore

  • The browser fallback and real AsyncLocalStorage should share stricter type constraints
  • Current IAsyncLocalStorage<T> interface could be more type-safe

Positive Findings

Good test coverage - Comprehensive tests for parallel execution and prompt isolation
Proper use of bun test - All tests use bun test framework correctly
No security issues - No hardcoded credentials or injection vulnerabilities
Error isolation - Uses Promise.allSettled correctly for fault tolerance
State management - Proper state snapshot sharing and accumulation between batches

Main Issue

The excessive use of any types throughout the codebase is the primary blocker. This needs to be addressed before merge as it violates TypeScript best practices and the repository's coding standards.


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.

2 participants