Close chat history service in AiService#15535
Conversation
Review Summary by QodoClose chat history service in AiService
WalkthroughsDescription• Close chat history service in AiService.close() method • Ensures proper resource cleanup and prevents resource leaks • Aligns with existing service shutdown pattern Diagramflowchart LR
AiService["AiService.close()"] -- "calls" --> chatHistoryService["chatHistoryService.close()"]
AiService -- "calls" --> cachedThreadPool["cachedThreadPool.shutdownNow()"]
AiService -- "calls" --> jabRefChatLanguageModel["jabRefChatLanguageModel.close()"]
AiService -- "calls" --> jabRefEmbeddingModel["jabRefEmbeddingModel.close()"]
File Changes1. jablib/src/main/java/org/jabref/logic/ai/AiService.java
|
Code Review by Qodo
|
| public void close() { | ||
| shutdownSignal.set(true); | ||
|
|
||
| chatHistoryService.close(); |
There was a problem hiding this comment.
1. Shutdown stops on exception 🐞 Bug ☼ Reliability
AiService.close() now calls chatHistoryService.close() before shutting down the executor/models; if chatHistoryService.close() throws while persisting MVStore data, the remaining shutdown steps are skipped. This can leave thread pools/models/storages unclosed and can also make try-with-resources call sites fail during cleanup.
Agent Prompt
### Issue description
`AiService.close()` now calls `chatHistoryService.close()` early, but the method has no exception-safety. If `chatHistoryService.close()` throws (e.g., during MVStore commit/close), the rest of `AiService.close()` is skipped, leaving executor/models/stores unclosed.
### Issue Context
`ChatHistoryService.close()` performs persistence and then commits/closes its MVStore-backed storage. The MVStore wrapper (`MVStoreBase`) does not catch exceptions.
### Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/ai/AiService.java[136-149]
- jablib/src/main/java/org/jabref/logic/ai/chatting/ChatHistoryService.java[194-204]
- jablib/src/main/java/org/jabref/logic/ai/util/MVStoreBase.java[55-65]
### Suggested fix
Refactor `AiService.close()` to always execute the remaining shutdown steps even if chat history persistence fails. For example:
- Wrap `chatHistoryService.close()` in a `try { ... } catch (Exception e) { ... }` (log) and continue, **or**
- Use a `try/finally` where `chatHistoryService.close()` is in the `try` and the remaining shutdown steps are in `finally`, optionally collecting and rethrowing a final exception with suppressed exceptions.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
I think the qodo comment is valid |
|
Well, yeah, but the same thing can be applied to every line in the close method, isn't it? |
Remove awkward empty line, trigger ci
Related issues and pull requests
Closes _____
PR Description
Steps to test
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)