You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default AGFS client mode was changed from 'http-client' to 'binding-client'. This may cause issues if the native library (libagfsbinding) is not available. Verify if this change is intentional and properly documented.
The code imports and uses the private function '_find_library' from openviking.pyagfs.binding_client. While the code is copied into the project, using private functions reduces maintainability. Consider if there's a public API alternative or if this is acceptable.
Latest suggestions up to 1f47239
Explore these optional code suggestions:
Category
Suggestion
Impact
Possible issue
Free native memory in cat/read method
Free the native memory allocated for result_ptr using AGFS_FreeString after copying the data. This prevents a memory leak each time cat/read is called.
if result_ptr:
data = ctypes.string_at(result_ptr, size_ptr.value)
+ self._lib.lib.AGFS_FreeString(result_ptr)
return data
return b""
Suggestion importance[1-10]: 8
__
Why: Fixes a critical memory leak by freeing native memory allocated for result_ptr using AGFS_FreeString after copying the data, which is important for long-running processes using the binding client.
Medium
General
Update outdated import error message
Update the ImportError message to reflect that pyagfs is now included as openviking.pyagfs and no longer needs separate installation.
except ImportError:
raise ImportError(
- "pyagfs not found. Please install: pip install -e third_party/agfs/agfs-sdk/python"+ "Failed to import AGFS client. This should be included with openviking."
)
Suggestion importance[1-10]: 4
__
Why: Updates the outdated ImportError message to reflect that pyagfs is now included as openviking.pyagfs, improving user experience but not affecting core functionality.
Fix memory leak in the cat method by freeing the library-allocated result_ptr using AGFS_FreeString. This prevents memory leaks when reading files with the binding client.
if result_ptr:
data = ctypes.string_at(result_ptr, size_ptr.value)
+ self._lib.lib.AGFS_FreeString(result_ptr)
return data
return b""
Suggestion importance[1-10]: 8
__
Why: This correctly identifies and fixes a memory leak in the cat method by freeing the library-allocated result_ptr with AGFS_FreeString, which is important for preventing memory leaks when using the binding client.
Medium
Fix memory leaks in _parse_response
Fix memory leaks in all methods using _parse_response by modifying it to accept and free library-allocated strings. Since ctypes converts c_char_p to bytes immediately, we need to adjust how we call library functions to retain the pointer for freeing.
-def _parse_response(self, result: bytes) -> Dict[str, Any]:- """Parse JSON response from the library."""- if isinstance(result, bytes):- result = result.decode("utf-8")- data = json.loads(result)+def _parse_response(self, result_ptr: ctypes.c_char_p) -> Dict[str, Any]:+ """Parse JSON response from the library and free the allocated string."""+ try:+ if not result_ptr:+ return {}+ result_bytes = ctypes.string_at(result_ptr)+ result = result_bytes.decode("utf-8")+ data = json.loads(result)- if "error_id" in data and data["error_id"] != 0:- error_msg = self._lib.lib.AGFS_GetLastError(data["error_id"])- if isinstance(error_msg, bytes):- error_msg = error_msg.decode("utf-8")- raise AGFSClientError(error_msg if error_msg else "Unknown error")+ if "error_id" in data and data["error_id"] != 0:+ error_msg = self._lib.lib.AGFS_GetLastError(data["error_id"])+ if isinstance(error_msg, bytes):+ error_msg = error_msg.decode("utf-8")+ raise AGFSClientError(error_msg if error_msg else "Unknown error")- return data+ return data+ finally:+ if result_ptr:+ self._lib.lib.AGFS_FreeString(result_ptr)
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly identifies a memory leak issue with library-allocated strings, but the proposed change would break all existing callers of _parse_response since they currently pass bytes objects. Additionally, ctypes would need to be configured differently to retain raw pointers instead of auto-converting to bytes.
Low
Update methods to use new _parse_response
Update all methods calling library functions that return strings to work with the new _parse_response signature. Since we need the raw pointer to free it, we must adjust our ctypes calls to retain the pointer.
Why: The suggestion is directionally correct for addressing memory leaks, but the implementation is incomplete (only updates two methods) and the restype is already set in _setup_functions. Also, it doesn't fully resolve how to retain raw pointers from ctypes calls.
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
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.
Summary
修复agfs binding-client无法import问题。
binding-client目前未合入到agfs主干,pyagfs 1.4.0不能找到该class。
修复方案:复制pyagfs到openviking,改用openviking.pyagfs
Type of Change
Testing
描述如何测试这些更改:
Related Issues
Checklist