Skip to content

Persist client session note removals with persistent user sessions - #52039

Merged
ahus1 merged 3 commits into
keycloak:mainfrom
thomasdarimont:issue/gh-52038-fix-auth-session-note-removal
Aug 26, 2026
Merged

ahus1 merged 3 commits into
keycloak:mainfrom
thomasdarimont:issue/gh-52038-fix-auth-session-note-removal

Conversation

@thomasdarimont

@thomasdarimont thomasdarimont commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

With persistent user sessions, JpaChangesPerformer replayed the recorded update tasks against a synthetic entity whose getNotes() returned a fresh anonymous HashMap forwarding only get/put (client sessions) or get/put/remove/clear (user sessions) to the persisted model. Every other Map operation ran against the throwaway map, so AuthenticatedClientSessionModel#removeNote and restartClientSession() (which clears all notes) never reached the database.

The synthetic entities now expose the persisted model's notes map directly, so all Map operations of the update tasks are applied to the persisted state.
PersistentAuthenticatedClientSessionAdapter#getNotes() lazily initializes the map instead of returning an immutable empty map, so that the tasks can mutate it.
UserSessionAdapter#setNote(name, null) removes the note from the task's entity instead of registering a nested update task from within the task, which would modify the task list while it is being replayed.

Fixes #52038

…eycloak#52038)

JpaChangesPerformer replayed update tasks against a synthetic notes map that only forwarded
get/put (client sessions) or get/put/remove/clear (user sessions) to the persisted model,
so AuthenticatedClientSessionModel#removeNote and restartClientSession() never reached the database.

Both merges now run the tasks against a snapshot of the persisted notes and write the result back once,
which makes every Map operation behave correctly.
UserSessionAdapter#setNote(name, null) removes the note from the task's entity instead of registering a nested update task.

Fixes keycloak#52038

Signed-off-by: Thomas Darimont <thomas.darimont@googlemail.com>
Copilot AI balanced review requested due to automatic review settings August 25, 2026 15:43
@thomasdarimont
thomasdarimont requested review from a team as code owners August 25, 2026 15:43
@ahus1 ahus1 self-assigned this Aug 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds regression coverage and fixes for persisting removal/clearing of session notes (client + user sessions) when persistent sessions are enabled, ensuring update tasks applied by JpaChangesPerformer correctly reach the database.

Changes:

  • Add an integration test suite to verify note removals and restart-driven note clearing are persisted for both client and user sessions.
  • Change JpaChangesPerformer to apply update tasks to a mutable snapshot of persisted notes and write back once, enabling correct behavior for all Map operations (remove/clear/containsKey/iteration/etc.).
  • Update UserSessionAdapter#setNote(name, null) to remove the note directly from the update entity rather than registering nested tasks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/base/src/test/java/org/keycloak/tests/session/SessionNotePersistenceTest.java Adds regression tests validating that note removals/clears are persisted to DB (bypassing cache).
model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/changes/JpaChangesPerformer.java Applies updates to a notes snapshot and writes back once to ensure correct persistence for all Map operations.
model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserSessionAdapter.java Adjusts null note handling to directly remove from the entity notes map during updates.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Signed-off-by: Alexander Schwartz <alexander.schwartz@ibm.com>
@ahus1 ahus1 changed the title Persist client session note removals with persistent user sessions (#52038) Persist client session note removals with persistent user sessions Aug 26, 2026
Copilot AI review requested due to automatic review settings August 26, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Alexander Schwartz <alexander.schwartz@gmx.net>
Copilot AI review requested due to automatic review settings August 26, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@thomasdarimont

Copy link
Copy Markdown
Contributor Author

LGTM

@ahus1
ahus1 merged commit b333c0f into keycloak:main Aug 26, 2026
153 of 155 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client session note removals are not persisted with persistent user sessions

3 participants