8000 Clean up scheduled workflow state when a client is removed by sguilhen · Pull Request #55641 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Clean up scheduled workflow state when a client is removed - #55641

Open
sguilhen wants to merge 2 commits into
keycloak:mainfrom
sguilhen:55603-client-removal-workflow-state-cleanup
Open

sguilhen wants to merge 2 commits into
keycloak:mainfrom
sguilhen:55603-client-removal-workflow-state-cleanup

Conversation

@sguilhen
Copy link
Copy Markdown
Contributor

Closes #55603

JpaWorkflowStateProviderFactory only listened for UserRemovedEvent and RealmRemovedEvent, so scheduled workflow steps for a removed client were never deleted from WORKFLOW_STATE.

@sguilhen
sguilhen requested a review from a team as a code owner November 27, 2026 19:06
Copilot AI balanced review requested due to automatic review settings November 27, 2026 19:06
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.

🟡 Changes recommended

Client cleanup can incorrectly delete a surviving user’s scheduled workflows when their IDs collide in the same realm, and the persisted-state regression is excluded from cross-database testing.

2 open issues
What changed in this PR

Addresses #55603 by extending workflow-state cleanup to client removal, alongside the existing user and realm cleanup handlers.

Changes:

  • Handles ClientRemovedEvent to remove the client's scheduled workflow state within its realm.
  • Adds a regression test that schedules a delayed client step, deletes the client, and verifies the state is removed.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​workflow/​step/​DeleteClientStepTest.java Adds a client-removal cleanup regression test.
model/​jpa/​src/​main/​java/​org/​keycloak/​models/​workflow/​JpaWorkflowStateProviderFactory.java Registers client-removal handling and invokes workflow-state cleanup.

Review effort: Balanced

Closes keycloak#55603

JpaWorkflowStateProviderFactory only listened for UserRemovedEvent and
RealmRemovedEvent, so scheduled workflow steps for a removed client
were never deleted from WORKFLOW_STATE.

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
@sguilhen
sguilhen force-pushed the 55603-client-removal-workflow-state-cleanup branch from 56a9138 to 2408456 Compare November 28, 2026 22:35
Copilot AI balanced review requested due to automatic review settings November 28, 2026 22:35
Copilot AI left a comment 8000
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.

🟡 Changes recommended

The resource-type equality check excludes legacy states with null RESOURCE_TYPE, leaving existing client and user executions orphaned unless those rows are backfilled or handled by a collision-safe fallback.

1 open issue
2 resolved since last review

Review effort: Balanced

…s populated

Resource-type-scoped cleanup on user/client removal only matches rows whose
RESOURCE_TYPE is set, so rows scheduled before that column started being
populated would never match and stay orphaned after upgrade. Backfill derives
the type from each row's owning workflow's configured supported type; rows
whose workflow no longer exists are left as-is, since they were already
unreachable through the workflow's realm.

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
Copilot AI balanced review requested due to automatic review settings November 29, 2026 00:26
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.

🔵 Needs a closer look

A delete-client step with a delayed successor can recreate workflow state after the client is deleted, leaving orphaned scheduled state; advancement must stop when the resource is removed, with regression coverage for this case.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Prevent scheduling successors after client deletion

model/​jpa/​src/​main/​java/​org/​keycloak/​models/​workflow/​JpaWorkflowStateProviderFactory.java:77

When a delete-client step has a delayed successor, this listener removes the current state during step execution, but RunWorkflowTask then schedules the successor in a separate transaction; scheduleStep recreates the row because it no longer exists. The deleted client therefore still ends up with orphaned scheduled state. Stop advancement when the resource has been removed (and add a delete-client-with-successor regression).

1 resolved since last review

Review effort: Balanced

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.

Deleting a client does not remove its scheduled workflow state

2 participants

0