Skip to content

Conversation

@rarepolz
Copy link
Contributor

@rarepolz rarepolz commented Oct 16, 2025

Issue #, if available:
closes #31
closes #32
Description of changes:

  • Added thread-safe synchronization to Execution and InMemoryExecutionStore classes using OrderedLock from the SDK.
    • Execution.py: Added _state_lock (threading.Lock) to synchronize all state modifications including token sequence increments, operations list updates, and used tokens modifications in methods like start(), get_new_checkpoint_token(), complete_wait(), and complete_retry()
    • stores/memory.py: Added _lock (threading.Lock) to ensure atomic operations for save(), load(), update(), and list_all() methods
  • Added unit tests for execution operations:
    • tests/execution_concurrent_test.py: Added concurrent access tests verifying thread-safe operations under multi-threaded scenarios
    • tests/execution_wait_retry_test.py: Added tests for wait and retry operations
    • tests/stores/concurrent_test.py: Added concurrent access tests for InMemoryExecutionStore verifying thread-safe operations
    • Updated tests/invoker_test.py: Enhanced existing tests with thread safety considerations

Dependencies

If this PR requires testing against a specific branch of the Python Language SDK (e.g., for unreleased changes), uncomment and specify the branch below. Otherwise, leave commented to use the main branch.

PYTHON_LANGUAGE_SDK_BRANCH: lambda-ctx

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rarepolz rarepolz requested review from a user, vip-amzn and yaythomas October 16, 2025 11:30
@rarepolz rarepolz force-pushed the thread-safe-execution branch 5 times, most recently from e853482 to 238c7a9 Compare October 16, 2025 12:05
@rarepolz rarepolz marked this pull request as ready for review October 16, 2025 12:08
@yaythomas
Copy link
Member

please remember to clean-up commit history before final merge...

@rarepolz rarepolz force-pushed the thread-safe-execution branch 5 times, most recently from d539e2b to dc73230 Compare October 16, 2025 18:04
@rarepolz rarepolz requested a review from yaythomas October 16, 2025 18:07
@rarepolz rarepolz force-pushed the thread-safe-execution branch 2 times, most recently from 440f3f2 to db8551b Compare October 16, 2025 18:28
- Added thread-safe synchronization to Execution and InMemoryExecutionStore classes using standard threading.Lock
- Execution.py: Added _state_lock (Lock) to synchronize all state modifications including token sequence increments, operations list updates, and used tokens modifications in methods like start(), get_new_checkpoint_token(), complete_wait(), and complete_retry()
- stores/memory.py: Added _lock (Lock) to ensure atomic operations for save(), load(), update(), and list_all() methods
- Added unit tests for execution operations:
  - tests/execution_concurrent_test.py: Added concurrent access tests verifying thread-safe operations under multi-threaded scenarios
  - tests/execution_wait_retry_test.py: Added tests for wait and retry operations
  - tests/stores/concurrent_test.py: Added concurrent access tests for InMemoryExecutionStore verifying thread-safe operations
- Made token_sequence a read-only property without setter to encapsulate mutations within the class
@rarepolz rarepolz force-pushed the thread-safe-execution branch from db8551b to 9a68680 Compare October 16, 2025 18:32
Copy link
Member

@yaythomas yaythomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good :-) :shipit:

Please remember to conform commit message to https://www.conventionalcommits.org/en/v1.0.0/

@rarepolz rarepolz merged commit 7dc7dfe into main Oct 16, 2025
14 checks passed
@rarepolz rarepolz deleted the thread-safe-execution branch October 16, 2025 19:01
@rarepolz rarepolz linked an issue Oct 18, 2025 that may be closed by this pull request
2 tasks
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.

Implement thread-safe execution store Add thread safety to execution operations Implement thread-safe token sequence generation

2 participants