Fix chat scope to use BibDatabaseContext ID#15459
Fix chat scope to use BibDatabaseContext ID#15459Ranjeet2702 wants to merge 52 commits intoJabRef:mainfrom
Conversation
Fixes JabRef#14641 - Removed final from bibDatabaseContext and aiChatLogic - Added updateDatabase() method to re-instantiate AiChatLogic on library switch - Store name and chatHistory for re-use on database change
|
You have removed the section "Checklist" from your pull request description. Please adhere to our pull request template. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| private final AiChatLogic aiChatLogic; | ||
| private StringProperty name; | ||
| private ObservableList<ChatMessage> chatHistory; | ||
| private AiChatLogic aiChatLogic; |
There was a problem hiding this comment.
chatHistory needs to be a class variable because updateDatabase() method needs to update it when the database context changes. Since the method is called from outside the component, the list needs to persist at the class level.
|
|
||
| public void updateDatabase(BibDatabaseContext newBibDatabaseContext, | ||
| ObservableList<ChatMessage> newChatHistory) { | ||
| this.bibDatabaseContext = newBibDatabaseContext; |
There was a problem hiding this comment.
Sorry for the inconsistent formatting, I'll fix it to match the existing code style.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ All tests passed ✅🏷️ Commit: 790caee Learn more about TestLens at testlens.app. |
Review Summary by QodoFix AI chat scope to use BibDatabaseContext ID
WalkthroughsDescription• Fixes chat scope to use BibDatabaseContext ID instead of global group names • Removes final modifiers from bibDatabaseContext and aiChatLogic fields • Adds instance fields for name and chatHistory to preserve state • Introduces updateDatabase() method to re-instantiate AiChatLogic on library switch Diagramflowchart LR
A["Chat Component"] -->|stores| B["name & chatHistory"]
A -->|updates on switch| C["updateDatabase method"]
C -->|creates new| D["AiChatLogic instance"]
D -->|scoped to| E["BibDatabaseContext ID"]
File Changes1. jabgui/src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java
|
Code Review by Qodo
1. updateDatabase() lacks test coverage
|
| public void updateDatabase(BibDatabaseContext newBibDatabaseContext, | ||
| ObservableList<ChatMessage> newChatHistory) { | ||
| this.bibDatabaseContext = newBibDatabaseContext; | ||
| this.chatHistory = newChatHistory; | ||
| this.aiChatLogic = aiService.getAiChatService().makeChat(name, newChatHistory, entries, newBibDatabaseContext); | ||
| uiChatHistory.setItems(aiChatLogic.getChatHistory()); | ||
| } |
There was a problem hiding this comment.
1. updatedatabase() lacks test coverage 📘 Rule violation ☼ Reliability
A new public method changes chat scoping behavior by re-instantiating AiChatLogic and swapping chat history, but no corresponding test was added/updated to prevent regressions. This risks incorrect chat history when switching libraries going unnoticed.
Agent Prompt
## Issue description
`AiChatComponent.updateDatabase(...)` introduces new behavior (recreate chat + switch displayed chat history) but there are no tests asserting the expected behavior.
## Issue Context
There is already a `AiChatComponentTest`, but it only verifies `computeNoticeText()` behavior when provider/model changes.
## Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java[129-135]
- jabgui/src/test/java/org/jabref/gui/ai/components/aichat/AiChatComponentTest.java[94-152]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| public void updateDatabase(BibDatabaseContext newBibDatabaseContext, | ||
| ObservableList<ChatMessage> newChatHistory) { | ||
| this.bibDatabaseContext = newBibDatabaseContext; | ||
| this.chatHistory = newChatHistory; | ||
| this.aiChatLogic = aiService.getAiChatService().makeChat(name, newChatHistory, entries, newBibDatabaseContext); | ||
| uiChatHistory.setItems(aiChatLogic.getChatHistory()); | ||
| } |
There was a problem hiding this comment.
3. Stale bindings after logic swap 🐞 Bug ≡ Correctness
updateDatabase() replaces aiChatLogic but does not update the existing exportButton binding and follow-up-questions listener, leaving UI state wired to the previous AiChatLogic instance. After a database switch, export enablement and follow-up question updates can stop reflecting the new chat session.
Agent Prompt
### Issue description
After `updateDatabase()` re-instantiates `aiChatLogic`, UI bindings/listeners created during `initialize()` still point to the old `AiChatLogic` instance.
### Issue Context
- `exportButton.disableProperty()` is bound once to `Bindings.isEmpty(aiChatLogic.getChatHistory())`.
- A follow-up-questions listener is added once to `aiChatLogic.getFollowUpQuestions()`.
- `updateDatabase()` swaps `aiChatLogic` but does not rewire those.
### Fix Focus Areas
- jabgui/src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java[129-147]
- jabgui/src/main/java/org/jabref/gui/ai/components/aichat/AiChatComponent.java[247-285]
### Suggested fix
In `updateDatabase()` (or a shared method used by both initialization and update):
- `exportButton.disableProperty().unbind();` then bind to the **new** `aiChatLogic.getChatHistory()`.
- Remove the old follow-up listener (store it in a field) and attach it to `aiChatLogic.getFollowUpQuestions()` of the new logic.
- Consider centralizing the (re)wiring so `initialize()` and `updateDatabase()` cannot drift.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Hi @koppor, I have fixed the indentation in the updateDatabase() method to match the existing code style. All checks are passing now. Could you please re-review? Thank you! |
|
I can still replicate the issue. You should look into |
I don't know about the architecture. Maybe @InAnYan can help. Otherwise, the self guided approach would be to draw an UML sequence diagram covering that case. |
|
Hi ranjeet and faneeshh! Thanks for looking into AI features and its code. I admit, that during the development several design mistakes were made, which need a fix. But fixing this is not easy at first glance (this is why I'm preparing a big AI refactoring PR). And yes the real culprit is in the TreeMap and how it handles chats with groups with the same name. So, if you have ideas or fixes - you are welcome! |
|
Hi @InAnYan, thank you for the clarification! I will look into fixing the TreeMap comparator in ChatHistoryService.java to include library context. Looking forward to your refactoring PR as well! |
|
Hi @InAnYan, thank you for the clarification! Could you guide me on the correct approach to fix the TreeMap issue? I want to make sure my fix aligns with your upcoming refactoring PR. |
|
I actually don’t know what to advise you 😅 . You can do anything which solves the problem and not too tricky. and don’t worry about my refactoring PR, so no need to align anything |
|
Your pull request conflicts with the target branch. Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line. |
* Update gradle to nightly of 2026-03-19 * Add FAQ on gradle (and remove outdated FAQ) * Fix casing * Add --stop * Fix header formatting in FAQ section * Fix capitalization of 'Gradle' in FAQ * Update search * Update wrapper * Restore valid .jar
* Fix Docker building (and also build for forks) * Fix meta data
…bRef#15431) Bumps [org.gradlex:java-module-testing](https://github.com/gradlex-org/java-module-testing) from 1.8 to 1.8.1. - [Release notes](https://github.com/gradlex-org/java-module-testing/releases) - [Changelog](https://github.com/gradlex-org/java-module-testing/blob/main/CHANGELOG.md) - [Commits](gradlex-org/java-module-testing@v1.8...v1.8.1) --- updated-dependencies: - dependency-name: org.gradlex:java-module-testing dependency-version: 1.8.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Christoph <siedlerkiller@gmail.com>
* Allow suffix letters in page range Relax the page checker regex so that suffix letters are accepted such as "436S-439S". Add unit tests for valid and invalid suffix cases, and update the changelog. * Refine test case * Align the comment --------- Co-authored-by: Subhramit Basu <subhramit.bb@live.in>
Bumps org.libreoffice:unoloader from 24.8.4 to 25.2.7. --- updated-dependencies: - dependency-name: org.libreoffice:unoloader dependency-version: 25.2.7 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
JabRef#15447) Bumps org.apache.logging.log4j:log4j-to-slf4j from 2.25.3 to 2.25.4. --- updated-dependencies: - dependency-name: org.apache.logging.log4j:log4j-to-slf4j dependency-version: 2.25.4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…5451) Bumps com.konghq:unirest-java-core from 4.8.0 to 4.8.1. --- updated-dependencies: - dependency-name: com.konghq:unirest-java-core dependency-version: 4.8.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
) Bumps org.libreoffice:libreoffice from 24.8.4 to 25.2.7. --- updated-dependencies: - dependency-name: org.libreoffice:libreoffice dependency-version: 25.2.7 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [tools.jackson:jackson-bom](https://github.com/FasterXML/jackson-bom) from 3.1.0 to 3.1.1. - [Commits](FasterXML/jackson-bom@jackson-bom-3.1.0...jackson-bom-3.1.1) --- updated-dependencies: - dependency-name: tools.jackson:jackson-bom dependency-version: 3.1.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Improve refresh button behavior in Citation Relations tab - Ask user before refetching if data was fetched recently - Retry immediately if last fetch resulted in an error - Refetch normally if data is old enough (TTL expired) Fixes JabRef#12247 * Update CHANGELOG for JabRef#12247 * Add missing localization keys and shorten CHANGELOG entry
* Persist in-text/empty nature in the CSL reference mark * Backward compatibility with legacy citations * Remove superfluous comments * Add comments in `getUpdatedReferenceMarkNameWithNewNumbers` * Extract citation style and citation type into one method * Reformat code * Update CHANGELOG.md * Transform if-else to switch * Refactor updateMarkAndTextWithNewStyle * use else-if for backward compatibility * update CHANGELOG.md --------- Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
30e0742 to
d16bcf4
Compare
|
Hi @koppor, my branch has too many commits due to rebase. Could you please squash the commits or should I create a new PR with only the relevant changes. |
|
@Ranjeet2702 no need, it’s okay, your PR will be squash merged |
|
Hi @koppor, all conflicts have been resolved and all checks are passing. Could you please re-review the PR? Thank you |
| @@ -1,16 +1,16 @@ | |||
| name: PR gate (maintainer/CI/label) | |||
| description: Checks whether actor is maintainer and whether CI is running or "status: changes-required" label is set. | |||
There was a problem hiding this comment.
No changes not related to the PR please
|
|
||
| // Note about `Optional<BibDatabaseContext>`: it was necessary in previous version, but currently we never save an `Optional.empty()`. | ||
| // However, we decided to left it here: to reduce migrations and to make possible to chat with a {@link BibEntry} without {@link BibDatabaseContext} | ||
| // ({@link BibDatabaseContext} is required only for load/store of the chat). |
|
Closing due to excessive AI use in code and description, and in communication. |
|
This pull requests was closed without merging. You have been unassigned from the respective issue #14641. In case you closed the PR for yourself, you can re-open it. Please also check After submission of a pull request in CONTRIBUTING.md. |
|
I apologize for using AI- generated code and comment in my PR. I am a 2nd second year student and had no idea at initial time but i wanted to contribute that's why i did . Please give me another chance this time you will not hear any complain from my side. Thanks for understanding. |
Please go through our contributing guidelines. You are free to try again. |

Summary
Fixes #14641
The AI Chat feature was using global group names causing
incorrect chat history when multiple libraries shared the
same group name.
Changes Made
finalfrombibDatabaseContextandaiChatLogicnameandchatHistoryas instance fieldsupdateDatabase()method to re-instantiateAiChatLogic when library is switched
Note
I am a GSoC 2026 applicant. This is a draft PR for feedback.
Checklist