Skip to content

fix: Preserve tokens and TTL in working memory update methods#181

Merged
raphaeldelio merged 1 commit intoredis:mainfrom
raphaeldelio:fix/java-sdk-preserve-tokens-ttl
Mar 17, 2026
Merged

fix: Preserve tokens and TTL in working memory update methods#181
raphaeldelio merged 1 commit intoredis:mainfrom
raphaeldelio:fix/java-sdk-preserve-tokens-ttl

Conversation

@raphaeldelio
Copy link
Collaborator

@raphaeldelio raphaeldelio commented Mar 4, 2026

Summary

Working memory update methods were losing tokens and ttlSeconds values.
This PR preserves these fields and adds parameters to set them when appending messages.

Changes

  • appendMessagesToWorkingMemory: Added optional tokens and ttlSeconds parameters
  • setWorkingMemoryData, addMemoriesToWorkingMemory, updateWorkingMemoryData: Now preserve existing tokens and ttlSeconds
  • Added unit and integration tests

Usage

// Restart TTL to 1 hour and update token count when appending messages
client.workingMemory().appendMessagesToWorkingMemory(
    sessionId, messages, namespace, modelName, 
    contextWindowMax, userId, 250, 3600);

Breaking Change

None - new parameters are optional and existing method signatures are preserved.


Note

Medium Risk
Moderate risk because it changes how enhanced working-memory methods call putWorkingMemory (swapping namespace/userId argument positions) and adjusts appendMessagesToWorkingMemory signatures/overloads, which could alter request query parameters or client behavior if relied upon.

Overview
Fixes working-memory update flows to retain tokens and ttlSeconds when rebuilding WorkingMemory in setWorkingMemoryData, addMemoriesToWorkingMemory, and updateWorkingMemoryData.

Extends appendMessagesToWorkingMemory to accept optional tokens and ttlSeconds (defaulting to existing values when omitted) and adds overloads to keep existing call sites working.

Adds unit + integration tests to verify token/TTL preservation and persistence when appending messages.

Written by Cursor Bugbot for commit 345fdd1. This will update automatically on new commits. Configure here.

@raphaeldelio raphaeldelio requested review from bsbodden and jruaux March 4, 2026 17:00
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

.build();

return putWorkingMemory(sessionId, updated, userId, namespace, null, null);
return putWorkingMemory(sessionId, updated, namespace, userId, null, null);
Copy link

Choose a reason for hiding this comment

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

Swapped userId and namespace parameters in putWorkingMemory calls

High Severity

All four internal putWorkingMemory calls now pass namespace as the userId parameter and userId as the namespace parameter. The putWorkingMemory signature is (sessionId, memory, userId, namespace, modelName, contextWindowMax), but every changed call site swaps the third and fourth arguments. Since both are @Nullable String, the compiler won't catch this, and API requests will send namespace as user_id and vice versa.

Additional Locations (2)

Fix in Cursor Fix in Web

Copy link
Collaborator

@bsbodden bsbodden left a comment

Choose a reason for hiding this comment

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

LGTM, but check the automated reviews and why the CI is breaking

@raphaeldelio raphaeldelio merged commit 44a92ea into redis:main Mar 17, 2026
21 of 24 checks passed
@raphaeldelio raphaeldelio deleted the fix/java-sdk-preserve-tokens-ttl branch March 17, 2026 01:55
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.

2 participants