refactor(core): add timeouts to block() and use Objects utilities#836
refactor(core): add timeouts to block() and use Objects utilities#836no-0-name wants to merge 1 commit intoagentscope-ai:mainfrom
Conversation
|
|
Summary of ChangesHello @no-0-name, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the stability and consistency of the core module by introducing explicit timeouts for asynchronous blocking operations and standardizing null-checking practices. These changes mitigate potential deadlocks or indefinite waits in critical sections and align the codebase with modern Java utility usage, leading to a more predictable and maintainable system. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a good step towards making the application more robust by adding timeouts to blocking calls and improving code style with Objects utilities. The changes in MsgHub and KnowledgeRetrievalTools are well-implemented, including the use of constants for timeout values. However, in Toolkit and McpAsyncClientWrapper, new timeouts have been introduced with magic numbers. I've left a couple of suggestions to extract these into named constants for better maintainability and consistency across the project.
| groupName, | ||
| presetParameters) | ||
| .block(); | ||
| .block(Duration.ofSeconds(30)); |
There was a problem hiding this comment.
To improve maintainability and for consistency with other changes in this PR, please extract the magic number 30 into a named constant within the ToolRegistration class. For example: private static final Duration MCP_REGISTRATION_TIMEOUT = Duration.ofSeconds(30);
| .block(Duration.ofSeconds(30)); | |
| .block(MCP_REGISTRATION_TIMEOUT); |
| .doOnSuccess(v -> logger.debug("MCP client '{}' closed", name)) | ||
| .doOnError(e -> logger.error("Error closing MCP client '{}'", name, e)) | ||
| .block(); | ||
| .block(Duration.ofSeconds(10)); |
There was a problem hiding this comment.
To improve maintainability and for consistency with other changes in this PR, please extract the magic number 10 into a named constant at the top of the McpAsyncClientWrapper class. For example: private static final Duration CLOSE_GRACEFULLY_TIMEOUT = Duration.ofSeconds(10);
| .block(Duration.ofSeconds(10)); | |
| .block(CLOSE_GRACEFULLY_TIMEOUT); |
Description
Adds explicit timeouts to all
block()calls in core to avoid indefinite blocking, and usesObjects.requireNonNull/Objects.requireNonNullElsewhere appropriate for consistency with project style.Changes:
DEFAULT_RETRIEVE_LIMIT(5) andRETRIEVE_TIMEOUT(60s);Objects.requireNonNull(knowledge)in constructor;Objects.requireNonNullElse(limit, DEFAULT_RETRIEVE_LIMIT);block(RETRIEVE_TIMEOUT)for retrieval.CLOSE_TIMEOUT(10s) forexit().block()inclose();Objects.requireNonNullElse(builder.name, ...)in constructor.close().Testing:
mvn spotless:applyandmvn test(ormvn verify) pass.