Skip to content

Add WorkflowEvent model and backend serialization#3486

Open
vegaro wants to merge 1 commit into
mainfrom
cesar/workflow-events-definition
Open

Add WorkflowEvent model and backend serialization#3486
vegaro wants to merge 1 commit into
mainfrom
cesar/workflow-events-definition

Conversation

@vegaro
Copy link
Copy Markdown
Member

@vegaro vegaro commented May 14, 2026

Adds the domain model and serialization layer for workflow step lifecycle events. Wiring in PaywallViewModel is in #3487.

  • WorkflowEvent sealed class (StepStarted, StepCompleted), sibling to PaywallEvent
  • BackendEvent.Workflows wire format matching khepri's WorkflowsEvent schema
  • BackendStoredEvent.Workflows + WorkflowEvent.toBackendStoredEvent() mapper
  • BackendStoredEvent.Workflows registered in EventsManager's JSON polymorphic config

Note

Medium Risk
Extends the event ingestion/serialization pipeline with a new polymorphic event type, which could affect event persistence and backend payload compatibility if mis-serialized or mis-registered.

Overview
Adds first-class support for tracking workflow step lifecycle events end-to-end.

Introduces WorkflowEvent (StepStarted, StepCompleted) plus a new backend wire model BackendEvent.Workflows, registers it for polymorphic JSON encoding/decoding, and adds BackendStoredEvent.Workflows + mapping so EventsManager.track can persist and flush workflow events like other feature events.

Updates workflow models to include WorkflowStep.screenType, and adds tests covering event storage and Khepri-compatible request serialization/round-tripping.

Reviewed by Cursor Bugbot for commit 3f91e95. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown
Member Author

vegaro commented May 14, 2026

@vegaro vegaro changed the title Rebuild workflow step states on color scheme change (#3419) feat: add WorkflowEvent model and backend serialization May 14, 2026
@vegaro vegaro changed the title feat: add WorkflowEvent model and backend serialization Add WorkflowEvent model and backend serialization May 14, 2026
### Motivation

In a multi-step workflow paywall, toggling dark/light mode while on a
non-first step would silently navigate the user back to step 1. The
configuration change calls `updateState()`, which re-runs the full
workflow setup — including resetting `WorkflowNavigator` to the initial
step — instead of just rebuilding the cached step states for the new
color scheme.

### Description

Introduces `rebuildWorkflowStepStates()`, called from the
configuration-change path instead of `updateState()` when the active
paywall is a workflow. It:

- Clears the existing `workflowStepStateCache`.
- Rebuilds the current step's `PaywallState.Loaded.Components` against
the new color scheme.
- Leaves `WorkflowNavigator`'s `currentStepId` and `backStack`
untouched, so the user stays on the step they were on.
- Re-kicks the off-thread pre-warm so visited and unvisited steps
repopulate with the new colors.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes workflow paywall refresh behavior to rebuild step UI state
in-place instead of reloading the workflow, which could impact
navigation/state caching if edge cases exist. Covered by new unit tests
that assert navigation position and network call count are preserved.
>
> **Overview**
> Fixes a workflow-paywall bug where changing the Compose `ColorScheme`
(e.g., dark/light toggle) could reset multi-step workflow navigation
back to the initial step.
>
> When a workflow is active, `refreshStateIfColorsChanged` now rebuilds
workflow step states via
`rebuildWorkflowStepStates`/`buildWorkflowStates` (clearing and
repopulating the step cache using the *current* step) instead of calling
`updateState()` and re-fetching/resetting the `WorkflowNavigator`. Adds
tests ensuring the current workflow step is preserved and that
`awaitGetWorkflow` is not called again on color refresh.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
8472463. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Facundo Menzella <facumenzella@gmail.com>

feat: track workflow step lifecycle events (step_started / step_completed)

Implements the workflows_step_started and workflows_step_completed event
pipeline, routing WorkflowEvent through EventsManager → BackendStoredEvent
→ BackendEvent.Workflows → /v1/events.

- Add WorkflowEvent sealed class (StepStarted / StepCompleted) implementing
  FeatureEvent; @SerialName discriminators ensure stable serialisation
- Add BackendEvent.Workflows wire model with nested Context and Properties
- Register BackendStoredEvent.Workflows in both JsonProvider and
  EventsManager polymorphic modules
- Add WorkflowEvent.toBackendStoredEvent() converter
- Track step_started on successful initial workflow load (guarded so a
  failed load does not fire spurious events)
- Track step_completed + step_started on forward and back navigation
- Track step_completed (toStepId = null) on paywall close
- Track step_completed and clear traceId when workflow state is cleared
  on error

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

feat: align workflow event properties with monetization event naming spec

Remove trace_id (not in spec) and add workflow_type ("paywall"),
step_type (from WorkflowStep.type), and screen_type (from
WorkflowStep.screenType, defaults to emptyList) to both
StepStarted and StepCompleted events and their BackendEvent wire shape.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

test: add non-empty screen_type coverage for workflow events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

fix: remove workflow_type/step_type/screen_type from BackendEvent wire model

Khepri derives these from its own DB at event time — no need for the SDK to send them.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vegaro vegaro force-pushed the cesar/workflow-events-definition branch from be17d14 to 3f91e95 Compare May 14, 2026 16:30
@vegaro vegaro marked this pull request as ready for review May 14, 2026 16:30
@vegaro vegaro requested a review from a team as a code owner May 14, 2026 16:30
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.

1 participant