Skip to content

Paginate deleteByConversationId to delete all events#55

Open
vaquarkhan wants to merge 1 commit intospring-ai-community:mainfrom
vaquarkhan:fix/delete-conversation-pagination
Open

Paginate deleteByConversationId to delete all events#55
vaquarkhan wants to merge 1 commit intospring-ai-community:mainfrom
vaquarkhan:fix/delete-conversation-pagination

Conversation

@vaquarkhan
Copy link
Copy Markdown

Summary

AgentCoreShortTermMemoryRepository.deleteByConversationId() calls listEvents once with maxResults(pageSize) but never paginates using nextToken. If a conversation has more events than pageSize, the remaining events are silently orphaned — never deleted, never visible, wasting storage indefinitely.

Root Cause

The fetchAllEvents() method in the same class correctly implements pagination with a do/while loop checking nextToken. The deleteByConversationId() method was simply missing the same pattern.

Changes

  • AgentCoreShortTermMemoryRepository.java — Added do/while pagination loop with nextToken handling in deleteByConversationId(), matching the existing fetchAllEvents() pattern

Before vs After

// BEFORE — single page, orphans remaining events
var events = client.listEvents(request).events();
events.forEach(event -> client.deleteEvent(...));

// AFTER — paginates through ALL events
String nextToken = null;
do {
    var response = client.listEvents(requestBuilder.build());
    response.events().forEach(event -> client.deleteEvent(...));
    nextToken = response.nextToken();
} while (nextToken != null);


**Testing**
mvn test -pl spring-ai-agentcore-memory94 tests, 0 failures
mvn spring-javaformat:applyclean

Fixes #[52](https://github.com/spring-ai-community/spring-ai-agentcore/issues/52)

deleteByConversationId() called listEvents once with maxResults(pageSize) but
never followed nextToken for subsequent pages. Conversations with more events
than pageSize had remaining events silently orphaned — never deleted, never
visible, wasting storage indefinitely.

Added a do/while pagination loop matching the existing fetchAllEvents() pattern
to ensure all events across all pages are deleted.

Fixes: deleteByConversationId only deletes first page of events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant