Skip to content

Conversation

@Yhmidi
Copy link
Contributor

@Yhmidi Yhmidi commented Jan 25, 2026

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I added multiple integration tests (Spring) related to the features (with a high test coverage).
  • I added pre-authorization annotations according to the guidelines and checked the course groups for all new REST Calls (security).
  • I documented the Java code using JavaDoc style.

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding guidelines.
  • I strictly followed the AET UI-UX guidelines.
  • Following the theming guidelines, I specified colors only in the theming variable files and checked that the changes look consistent in both the light and the dark theme.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.
  • I added authorities to all new routes and checked the course groups for displaying navigation elements (links, buttons).
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Motivation and Context

As it is common while interacting with Agents that it sometimes is stuck in a context and unable to help you with your requests. It is the same for our Atlas Companion which introduces the need for a contexting clearing feature.

Description

Server Side:

  • I have added a new endpoint --> @PostMapping("courses/{courseId}/chat/clear-session")
  • Implemented clearSession method in service file
  • Migrated to pass the sessionId dynamically per request using advisors param

Client Side:

  • added button "New Chat" top corner right on the companion's component
  • added clearSession method that calls the endpoint to clear the session
  • implemented onNewChat in the component file

Steps for Testing

Prerequisites:

  • 1 Instructor
  • Test server with admin rights or test locally
  1. Log in to Artemis
  2. Navigate to Course Administration
  3. enable the feature toggle : AtlasAgent
  4. navigate to your own course -> Competencies -> click on Manage
  5. open Companion's pop up , tell it any context/information, click on new chat --> messages should disappear
  6. ask it about that context --> should not know about it

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

Test on TS3 for admin rights or locally

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Test Coverage

Client

Class/File Line Coverage Lines Expects Ratio
agent-chat-modal.component.ts 95.85% 281 162 57.7
agent-chat.service.ts 100.00% 60 64 106.7

Server

Class/File Line Coverage Lines
AtlasChatMemoryRepository.java 100.00% 23
AtlasAgentService.java 86.00% 278
AtlasAgentResource.java 100.00% 56

Last updated: 2026-01-25 22:24:28 UTC

Screenshots

image

Summary by CodeRabbit

  • New Features

    • "New Chat" button to start a fresh conversation; disabled while agent is typing or a session reset is in progress.
    • Client now calls a server-side clear-session API to fully reset conversation memory and pending operations.
  • Localization

    • Added translations for the new button label and title (en/de).
  • Tests

    • Added unit and integration tests covering the chat-reset flow and endpoint access control.

✏️ Tip: You can customize this high-level summary in your review settings.

@Yhmidi Yhmidi requested a review from a team as a code owner January 25, 2026 08:18
@github-project-automation github-project-automation bot moved this to Work In Progress in Artemis Development Jan 25, 2026
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) client Pull requests that update TypeScript code. (Added Automatically!) atlas Pull requests that affect the corresponding module labels Jan 25, 2026
@github-actions
Copy link

@Yhmidi Test coverage could not be fully measured because some tests failed. Please check the workflow logs for details.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 25, 2026

Walkthrough

Adds a backend clear-session API and service integration to delete chat memory and evict pending operations, a frontend "New Chat" UI action that calls it and resets the chat, plus repository, tests, and i18n keys.

Changes

Cohort / File(s) Summary
Backend: Service
src/main/java/de/tum/cit/aet/artemis/atlas/service/AtlasAgentService.java
Added AtlasChatMemoryRepository field and constructor parameter; refactored memory handling to supply sessionId via advisors per request; added public void clearSession(String sessionId) to delete conversation memory and evict pending-operations cache.
Backend: Repository
src/main/java/de/tum/cit/aet/artemis/atlas/repository/AtlasChatMemoryRepository.java
New conditional, lazy repository wrapper around Spring AI ChatMemoryRepository with deleteByConversationId(String) (transactional, no-op if underlying repo absent).
Backend: REST
src/main/java/de/tum/cit/aet/artemis/atlas/web/AtlasAgentResource.java
New POST endpoint api/atlas/agent/courses/{courseId}/chat/clear-session resolving sessionId from course/user and invoking atlasAgentService.clearSession(sessionId).
Frontend: Component Template
src/main/webapp/app/atlas/manage/agent-chat-modal/agent-chat-modal.component.html
Header updated to include a "New Chat" button (calls onNewChat()); button disabled while agent is typing or session is clearing.
Frontend: Component Logic & Tests
src/main/webapp/app/atlas/manage/agent-chat-modal/agent-chat-modal.component.ts, src/main/webapp/app/atlas/manage/agent-chat-modal/agent-chat-modal.component.spec.ts
Added plusIcon, isClearingSession, and onNewChat() which calls service.clearSession(), resets messages to a translated welcome, focuses input; unit test added for onNewChat flow.
Frontend: Service & Tests
src/main/webapp/app/atlas/manage/services/agent-chat.service.ts, src/main/webapp/app/atlas/manage/services/agent-chat.service.spec.ts
Added clearSession(courseId: number): Observable<void> that POSTs to the new endpoint; tests verify the POST and completion.
i18n
src/main/webapp/i18n/en/agent.json, src/main/webapp/i18n/de/agent.json
Added translation keys newChat and newChatTitle.
Backend Tests: Integration & Unit
src/test/java/de/tum/cit/aet/artemis/atlas/agent/AtlasAgentIntegrationTest.java, src/test/java/de/tum/cit/aet/artemis/atlas/service/AtlasAgentServiceTest.java
Added integration tests for clear-session authorization and unit tests verifying chat memory deletion and cache eviction; note duplicated test blocks present in diff.
Architecture Test
src/test/java/de/tum/cit/aet/artemis/shared/architecture/module/AbstractModuleRepositoryArchitectureTest.java
Excluded AtlasChatMemoryRepository.deleteByConversationId(java.lang.String) from transactional-enforcement test exclusions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI as "Agent Chat Modal"
    participant Client as "AgentChatService"
    participant API as "AtlasAgentResource"
    participant Service as "AtlasAgentService"
    participant Repo as "AtlasChatMemoryRepository"
    participant Cache as "PendingOperationsCache"

    User->>UI: Click "New Chat"
    UI->>UI: check isAgentTyping / isClearingSession
    UI->>Client: clearSession(courseId)
    Client->>API: POST /api/atlas/agent/courses/{courseId}/chat/clear-session
    API->>Service: clearSession(sessionId)
    Service->>Repo: deleteByConversationId(sessionId)
    Service->>Cache: evict(sessionId)
    Repo-->>Service: deleted
    Cache-->>Service: evicted
    Service-->>API: 200 OK
    API-->>Client: 200 OK
    Client-->>UI: observable resolved
    UI->>UI: reset messages, inject welcome, focus input
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.81% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main feature: enabling instructors to clear the Atlas Companion's chat and context, which is the primary objective of this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/adaptive-learning/clear-chat-of-companion

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In
`@src/main/webapp/app/atlas/manage/agent-chat-modal/agent-chat-modal.component.html`:
- Around line 3-14: Replace the hard-coded "New Chat" button label and the title
tooltip with translatable keys: update the template for the button in
agent-chat-modal.component.html that uses plusIcon and calls
onNewChat()/isAgentTyping()/closeModal() to use jhiTranslate (or the project's
i18n translation directive/pipe) for both the visible text and the title
attribute (e.g. add a key like artemisApp.agent.chat.new and
artemisApp.agent.chat.newTooltip), and ensure the component's translation keys
are added to the i18n resource files; keep the existing (click)="onNewChat()"
and [disabled]="isAgentTyping()" behavior intact.

In `@src/main/webapp/app/atlas/manage/services/agent-chat.service.ts`:
- Around line 69-79: The clearSession method wraps the HTTP POST in a catchError
that swallows failures; remove the catchError block so the Observable returned
by clearSession(courseId: number) is the raw this.http.post<void>(...) and
errors propagate to callers (e.g., onNewChat in agent-chat-modal.component) so
the UI error handler can run; update clearSession by returning the HTTP
observable directly and ensure callers handle errors as needed.
🧹 Nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/atlas/service/AtlasAgentService.java (1)

26-26: Avoid @Transactional for cache-only clearSession.

clearSession only clears chat memory and cache state; wrapping it in a transaction adds overhead without clear benefit. Consider removing it unless there is a concrete transactional requirement.

♻️ Suggested change
-import org.springframework.transaction.annotation.Transactional;
-    `@Transactional`
     public void clearSession(String sessionId) {
         if (chatMemory != null)
             chatMemory.clear(sessionId);

         clearCachedPendingCompetencyOperations(sessionId);
     }

As per coding guidelines, avoid @Transactional scope.

Also applies to: 502-508

@github-project-automation github-project-automation bot moved this from Work In Progress to Ready For Review in Artemis Development Jan 25, 2026
@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report223 ran221 passed1 skipped1 failed1h 47m 53s 946ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/exam/test-exam/TestExamParticipation.spec.ts
ts.Test exam participation › Early Hand-in › Using exercise overview to navigate within exam❌ failure4m 40s 121ms

added tests
@Yhmidi Yhmidi requested a review from krusche as a code owner January 25, 2026 09:52
@github-actions github-actions bot added the tests label Jan 25, 2026
@github-actions
Copy link

@Yhmidi Test coverage could not be fully measured because some tests failed. Please check the workflow logs for details.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/main/webapp/i18n/de/agent.json`:
- Line 5: Replace the incorrect German label for the JSON key "newChatTitle":
update its value from "Neu Chat" to a grammatically correct alternative such as
"Neuer Chat" (or "Neues Gespräch") so the UI shows proper German; locate the
"newChatTitle" entry in src/main/webapp/i18n/de/agent.json and change the string
value accordingly.
🧹 Nitpick comments (1)
src/test/java/de/tum/cit/aet/artemis/atlas/agent/AtlasAgentIntegrationTest.java (1)

344-358: Consider adding a tutor authorization test for consistency.

The existing test groups in this file (ConversationHistory and Authorization) test forbidden access for both students and tutors. For consistency and complete access control coverage, consider adding a test for tutor access:

♻️ Suggested addition
         `@Test`
         `@WithMockUser`(username = TEST_PREFIX + "student1", roles = "USER")
         void shouldReturnForbiddenForNonInstructor() throws Exception {
             request.performMvcRequest(post("/api/atlas/agent/courses/{courseId}/chat/clear-session", course.getId())).andExpect(status().isForbidden());
         }
+
+        `@Test`
+        `@WithMockUser`(username = TEST_PREFIX + "tutor1", roles = "TA")
+        void shouldReturnForbiddenForTutor() throws Exception {
+            request.performMvcRequest(post("/api/atlas/agent/courses/{courseId}/chat/clear-session", course.getId())).andExpect(status().isForbidden());
+        }
     }

@github-actions
Copy link

@Yhmidi Test coverage could not be fully measured because some tests failed. Please check the workflow logs for details.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 25, 2026
@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed2s 127ms
TestResultTime ⏱
No test annotations available

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 25, 2026
@github-actions
Copy link

@Yhmidi Test coverage has been automatically updated in the PR description.

@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed2s 192ms
TestResultTime ⏱
No test annotations available

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 25, 2026
@github-actions
Copy link

@Yhmidi Test coverage has been automatically updated in the PR description.

@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed2s 171ms
TestResultTime ⏱
No test annotations available

@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅Skipped ⚠️FailedTime ⏱
End-to-End (E2E) Test Report223 ran222 passed1 skipped0 failed1h 28m 49s 781ms
TestResultTime ⏱
No test annotations available

@helios-aet helios-aet bot temporarily deployed to artemis-test5.artemis.cit.tum.de January 25, 2026 14:32 Inactive
Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change Request

  • Please add the translation for the button
  • Please get rid of the magic number, ideally extract a more readable method

Other Comments

Optional

- added string key
- added integration test
- preventing race conditions by adding a flag to when the new chat is clicked
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 25, 2026
@github-actions
Copy link

@Yhmidi Test coverage has been automatically updated in the PR description.

1 similar comment
@github-actions
Copy link

@Yhmidi Test coverage has been automatically updated in the PR description.

@helios-aet helios-aet bot temporarily deployed to artemis-test3.artemis.cit.tum.de January 25, 2026 16:55 Inactive
Copy link
Contributor

@MarcosOlivaKaczmarek MarcosOlivaKaczmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS3, it does not forget about the context in the new chat.

Grabacion.de.pantalla.2026-01-25.a.las.18.06.58.mov

@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅Skipped ⚠️FailedTime ⏱
End-to-End (E2E) Test Report223 ran222 passed1 skipped0 failed1h 27m 51s 64ms
TestResultTime ⏱
No test annotations available

…able to use @transactional as it is necessary for our clearSession method as         ChatMemoryRepository.deleteByConversationId(sessionId); doest it handle it on its own
…able to use @transactional as it is necessary for our clearSession method as         ChatMemoryRepository.deleteByConversationId(sessionId); doest it handle it on its own
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In
`@src/main/java/de/tum/cit/aet/artemis/atlas/repository/AtlasChatMemoryRepository.java`:
- Around line 23-36: In AtlasChatMemoryRepository.deleteByConversationId, add
input validation for the conversationId parameter before calling
chatMemoryRepository: check for null or blank (e.g., null or
conversationId.trim().isEmpty()) and short-circuit (return immediately) to avoid
forwarding invalid IDs to chatMemoryRepository; if desired, log a warning or
throw an IllegalArgumentException for clearly invalid callers, but do not call
chatMemoryRepository.deleteByConversationId when the ID is invalid.

In `@src/main/java/de/tum/cit/aet/artemis/atlas/service/AtlasAgentService.java`:
- Around line 505-508: In clearSession, guard against a null
atlasChatMemoryRepository and invalid sessionId by validating/sanitizing
sessionId (non-null, non-empty) before using it, and only call
atlasChatMemoryRepository.deleteByConversationId(sessionId) when
atlasChatMemoryRepository != null and sessionId is valid; likewise call
clearCachedPendingCompetencyOperations(sessionId) only after the same sessionId
validation to avoid NPEs and invalid-cache operations.

Comment on lines 23 to 36
public AtlasChatMemoryRepository(@Autowired(required = false) ChatMemoryRepository chatMemoryRepository) {
this.chatMemoryRepository = chatMemoryRepository;
}

/**
* Deletes all messages for a given conversation/session.
*
* @param conversationId the conversation/session ID
*/
@Transactional
public void deleteByConversationId(String conversationId) {
if (chatMemoryRepository != null) {
chatMemoryRepository.deleteByConversationId(conversationId);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Validate conversationId before deleting.

If conversationId is null/blank, the underlying repository may error or delete unintended data. Add a guard to short-circuit invalid input (Line 33).

✅ Proposed fix
     `@Transactional`
     public void deleteByConversationId(String conversationId) {
-        if (chatMemoryRepository != null) {
+        if (chatMemoryRepository != null && conversationId != null && !conversationId.isBlank()) {
             chatMemoryRepository.deleteByConversationId(conversationId);
         }
     }

Based on learnings, validate and sanitize inputs in server-side code.

🤖 Prompt for AI Agents
In
`@src/main/java/de/tum/cit/aet/artemis/atlas/repository/AtlasChatMemoryRepository.java`
around lines 23 - 36, In AtlasChatMemoryRepository.deleteByConversationId, add
input validation for the conversationId parameter before calling
chatMemoryRepository: check for null or blank (e.g., null or
conversationId.trim().isEmpty()) and short-circuit (return immediately) to avoid
forwarding invalid IDs to chatMemoryRepository; if desired, log a warning or
throw an IllegalArgumentException for clearly invalid callers, but do not call
chatMemoryRepository.deleteByConversationId when the ID is invalid.

Comment on lines +505 to +508
public void clearSession(String sessionId) {
atlasChatMemoryRepository.deleteByConversationId(sessionId);
clearCachedPendingCompetencyOperations(sessionId);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard against null repository and invalid session IDs.

atlasChatMemoryRepository is optional; calling deleteByConversationId without a null check can NPE. Also validate sessionId before cache or repository operations (Line 505).

✅ Proposed fix
     public void clearSession(String sessionId) {
-        atlasChatMemoryRepository.deleteByConversationId(sessionId);
-        clearCachedPendingCompetencyOperations(sessionId);
+        if (sessionId == null || sessionId.isBlank()) {
+            return;
+        }
+        if (atlasChatMemoryRepository != null) {
+            atlasChatMemoryRepository.deleteByConversationId(sessionId);
+        }
+        clearCachedPendingCompetencyOperations(sessionId);
     }

Based on learnings, validate and sanitize inputs in server-side code.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public void clearSession(String sessionId) {
atlasChatMemoryRepository.deleteByConversationId(sessionId);
clearCachedPendingCompetencyOperations(sessionId);
}
public void clearSession(String sessionId) {
if (sessionId == null || sessionId.isBlank()) {
return;
}
if (atlasChatMemoryRepository != null) {
atlasChatMemoryRepository.deleteByConversationId(sessionId);
}
clearCachedPendingCompetencyOperations(sessionId);
}
🤖 Prompt for AI Agents
In `@src/main/java/de/tum/cit/aet/artemis/atlas/service/AtlasAgentService.java`
around lines 505 - 508, In clearSession, guard against a null
atlasChatMemoryRepository and invalid sessionId by validating/sanitizing
sessionId (non-null, non-empty) before using it, and only call
atlasChatMemoryRepository.deleteByConversationId(sessionId) when
atlasChatMemoryRepository != null and sessionId is valid; likewise call
clearCachedPendingCompetencyOperations(sessionId) only after the same sessionId
validation to avoid NPEs and invalid-cache operations.

@github-actions
Copy link

@Yhmidi Test coverage could not be fully measured because some tests failed. Please check the workflow logs for details.

…onversationbyID() need @transactional in order to function correctly . so had to exclude the added wrapper repository from the architecture test.
@github-actions
Copy link

@Yhmidi Test coverage has been automatically updated in the PR description.

@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed2s 234ms
TestResultTime ⏱
No test annotations available

@github-actions
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report223 ran219 passed2 skipped2 failed1h 44m 43s 557ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/atlas/LearningPathManagement.spec.ts
ts.Learning Path Management › Create simple learning path❌ failure20s 762ms
e2e/exam/ExamAssessment.spec.ts
ts.Exam assessment › Text exercise assessment › Complaints about text exercises assessment❌ failure1m 26s 129ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

atlas Pull requests that affect the corresponding module client Pull requests that update TypeScript code. (Added Automatically!) server Pull requests that update Java code. (Added Automatically!) tests

Projects

Status: Ready For Review

Development

Successfully merging this pull request may close these issues.

4 participants