Repository navigation
Add a client-activity workflow event provider - #53082
Open
antoniocasagrande-airia wants to merge 3 commits into
Open
antoniocasagrande-airia wants to merge 3 commits into
antoniocasagrande-airia wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The public event is undocumented, and two supported activity event paths lack integration coverage.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Adds client activity tracking for workflows and aligns workflow scheduling with Keycloak’s offset-aware clock.
Changes:
- Adds
client-activityfor successful login, code exchange, and token refresh events. - Adds activation/reset and failed-login integration coverage.
- Fixes cumulative scheduling under time offsets.
| File | Description |
|---|---|
BrokeredUserLifecycleWorkflowTest.java |
Updates cumulative time offsets. |
ClientActivityWorkflowTest.java |
Tests client activity workflow behavior. |
WorkflowEventProviderFactory |
Registers the new provider. |
JpaWorkflowStateProvider.java |
Uses the offset-aware clock. |
ClientActivityWorkflowEventProvider.java |
Defines qualifying activity events. |
ClientActivityWorkflowEventFactory.java |
Exposes the client-activity event. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
antoniocasagrande-airia
force-pushed
the
workflow-client-activity-event
branch
from
October 14, 2026 18:15
f176028 to
acb31b5
Compare
… the same clock JpaWorkflowStateProvider.scheduleStep stamped scheduledStepTimestamp with Instant.now() while getDueScheduledSteps compares it against Time.currentTimeMillis(). Production behavior is unchanged (Time delegates to the system clock), but a step scheduled while a time offset is set, such as a workflow restarted by an event, was scheduled against the real clock and fell due early. Signed-off-by: Antonio Casagrande <antoniocasagrande@airia.com>
Workflows can already react to a client authenticating, but that event is EventType.CLIENT_LOGIN, which only the client_credentials grant emits. A public authorization-code client - what dynamic client registration produces - never raises it, so a workflow that means "disable this client if it has been idle for N days" silently degrades to "N days after it was created" for exactly the population most likely to accumulate. Add client-activity over LOGIN, CODE_TO_TOKEN and REFRESH_TOKEN, so any use of the client resets the timer. The *_ERROR variants are deliberately excluded: they carry the client id too, so counting them would let failed authentication against a dormant client keep it alive indefinitely. Signed-off-by: Antonio Casagrande <antoniocasagrande@airia.com>
Add the event to the event-functions table. Pin the counted and ignored event types in a unit test, since an authorization code is only issued at the end of a login and an integration test cannot exercise CODE_TO_TOKEN apart from LOGIN. Add an integration case where a token refresh is the only activity and still resets the workflow. Signed-off-by: Antonio Casagrande <antoniocasagrande@airia.com>
antoniocasagrande-airia
force-pushed
the
workflow-client-activity-event
branch
from
October 14, 2026 18:52
acb31b5 to
1b121dd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Part of #51595.
Workflows can already react to a client authenticating, but that event is
EventType.CLIENT_LOGIN, which only theclient_credentialsgrant emits. A public authorization-code client — what dynamic client registration produces — never raises it. So a CLIENTS workflow meaning "disable this client if it has been idle for N days" silently degrades to "N days after it was created" for exactly the population most likely to accumulate.This adds
client-activityoverLOGIN,CODE_TO_TOKENandREFRESH_TOKEN, so any use of the client resets the timer.The
*_ERRORvariants are deliberately excluded. They carry the client id too, so counting them would let failed authentication against a dormant client keep it alive indefinitely — a property worth stating explicitly, since it is the kind of thing that looks like an oversight later.The first commit is a separate defect
JpaWorkflowStateProviderschedules steps withInstant.now()while the due-check queries againstTime.currentTimeMillis():Under any time offset the due-check moves and the schedule does not, so steps fire at the wrong time. This is independent of the event provider, and production is unaffected because
Timedelegates to the system clock; it is first here because the activity test cannot express "the timer resets on use" without both sides agreeing on a clock. Happy to split it into its own PR if you would rather review it separately.It only matters where a step is scheduled while an offset is set, as when a later login restarts the workflow. Steps scheduled from
runScheduledStepsare unaffected: the step task runs after the transaction completes, by which point the test help 8000 er has already reset the offset. Without this commit, the two reset cases inClientActivityWorkflowTestfail; existing tests pass either way.Testing
Integration tests cover activation on use and the reset after a login, a reset where a token refresh is the only activity, and a case pinning that failed logins do not activate. A unit test pins each counted and ignored event type, since an authorization code is only issued at the end of a login and an integration test cannot exercise
CODE_TO_TOKENon its own.Verified locally against a server built from this branch:
ClientActivityWorkflowTest(3) and the unchangedBrokeredUserLifecycleWorkflowTest(4) pass, as does the unit test (3), andmvn spotless:check -pl model/jpa,tests/baseis clean. The unit test fails if an*_ERRORtype is added to the counted set.In practice
We have run this event as a custom extension since August, as the reset trigger for disable and delete workflows on dynamically registered clients. One thing we added alongside it: a condition that checks the client has no live sessions before each due step, because an event-driven clock is only as reliable as the events that reach it. The engine already re-evaluates a workflow's conditions before running a scheduled step, so that check fits without engine changes. Happy to propose it separately if it is useful.
Context: this was originally part of #51629, which I have closed since the client-attribute condition it also carried is superseded by #52189. #52189 does not include an activity event, so this half is still open and is here on its own.