-
Notifications
You must be signed in to change notification settings - Fork 50
feat: concurrency-safe tool coverage #699
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
Draft
codeacme17
wants to merge
7
commits into
xorbitsai:main
Choose a base branch
from
codeacme17:feat/extend-concurrency-safe-coverage-to-write-and-stateful-tools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f01103
feat: Extend concurrency-safe coverage for workspace file tools and e…
codeacme17 8922f49
feat: Implement concurrency-safe file mutation tools and enhance work…
codeacme17 4d59a50
Add concurrency safety tests for browser tools and enhance session ma…
codeacme17 060c211
feat: Enhance PythonExecutorTool for concurrency safety and isolation…
codeacme17 5f763b2
feat: Enhance concurrency safety for document and image tools, add pa…
codeacme17 32fdd88
feat: Enhance concurrency safety in path locks and improve workspace …
codeacme17 87c063e
feat: Implement RAG ingestion locks for concurrency safety in documen…
codeacme17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """Shared normalized-path mutation locks.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import threading | ||
| from contextlib import ExitStack, contextmanager | ||
| from pathlib import Path | ||
| from typing import Iterator | ||
|
|
||
|
|
||
| class PathMutationLockRegistry: | ||
| """Provide re-entrant locks keyed by normalized absolute filesystem path.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| self._guard = threading.Lock() | ||
| self._locks: dict[str, tuple[threading.RLock, int]] = {} | ||
|
|
||
| @staticmethod | ||
| def normalize_path(path: str | Path) -> Path: | ||
| return Path(path).expanduser().resolve() | ||
|
|
||
| def _acquire_lock_for_key(self, key: str) -> threading.RLock: | ||
| with self._guard: | ||
| lock_entry = self._locks.get(key) | ||
| if lock_entry is None: | ||
| lock = threading.RLock() | ||
| self._locks[key] = (lock, 1) | ||
| return lock | ||
|
|
||
| lock, ref_count = lock_entry | ||
| self._locks[key] = (lock, ref_count + 1) | ||
| return lock | ||
|
|
||
| def _release_lock_for_key(self, key: str) -> None: | ||
| with self._guard: | ||
| lock_entry = self._locks.get(key) | ||
| if lock_entry is None: | ||
| return | ||
|
|
||
| lock, ref_count = lock_entry | ||
| if ref_count <= 1: | ||
| self._locks.pop(key, None) | ||
| else: | ||
| self._locks[key] = (lock, ref_count - 1) | ||
|
|
||
| @contextmanager | ||
| def guard_path(self, path: str | Path) -> Iterator[Path]: | ||
| normalized_path = self.normalize_path(path) | ||
| key = str(normalized_path) | ||
| lock = self._acquire_lock_for_key(key) | ||
| try: | ||
| with lock: | ||
| yield normalized_path | ||
| finally: | ||
| self._release_lock_for_key(key) | ||
|
|
||
| @contextmanager | ||
| def guard_paths(self, paths: list[str | Path]) -> Iterator[tuple[Path, ...]]: | ||
| normalized_paths = tuple(self.normalize_path(path) for path in paths) | ||
| unique_paths = {str(path): path for path in normalized_paths} | ||
| ordered_paths = [unique_paths[key] for key in sorted(unique_paths)] | ||
|
|
||
| with ExitStack() as stack: | ||
| for normalized_path in ordered_paths: | ||
| stack.enter_context(self.guard_path(normalized_path)) | ||
| yield normalized_paths | ||
|
|
||
|
|
||
| GLOBAL_PATH_MUTATION_LOCKS = PathMutationLockRegistry() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.