Skip to content

Conversation

@prastoin
Copy link
Contributor

@prastoin prastoin commented Feb 10, 2026

Introduction

Followup #17622

Refactoring the actions handler to be returning a metadata event
It has to be done incrementally, as if not update metadata event would be stale as depends on the incremental action execution order and optimistic application

What's next

@prastoin prastoin force-pushed the runner-metadata-events branch from 606a882 to cd127e6 Compare February 10, 2026 17:12
@prastoin prastoin self-assigned this Feb 10, 2026
@prastoin prastoin marked this pull request as ready for review February 10, 2026 17:17
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 10 files

@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2026

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:30605

This environment will automatically shut down when the PR is closed or after 5 hours.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 10, 2026

Greptile Overview

Greptile Summary

This PR refactors the workspace migration runner/action-handler flow to emit MetadataEvent[] alongside the existing optimistic cache updates, and adds utilities to derive create/update/delete metadata events from flat migration actions.

The new flow is wired through BaseWorkspaceMigrationRunnerActionHandlerService.execute (now returning { partialOptimisticCache, metadataEvents }) and WorkspaceMigrationRunnerService.run (now aggregating and returning { allFlatEntityMaps, metadataEvents }). This fits into the migration system by letting downstream consumers react to metadata mutations without re-deriving diffs from the cache.

Key merge blockers are: (1) run() return type changed but existing call sites still treat it as returning AllFlatEntityMaps, and (2) event derivation currently uses pre-optimistic state, which can make after/diff inconsistent with what the runner actually applied.

Confidence Score: 2/5

  • This PR is not safe to merge until return-type integration and event correctness are fixed.
  • Runner/action-handler signatures changed and at least two existing call sites still use the old return type. Additionally, metadata events are derived from pre-optimistic state, which can produce incorrect event payloads relative to the applied action order/state. These are correctness/integration issues likely to break compilation or downstream consumers.
  • packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/services/workspace-migration-runner.service.ts; packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/interfaces/workspace-migration-runner-action-handler-service.interface.ts; packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/types/metadata-event.ts

Important Files Changed

Filename Overview
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-builder/types/workspace-migration-action-common.ts Generalized AllFlatWorkspaceMigrationAction with action-type generic; no functional issues spotted.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/interfaces/workspace-migration-runner-action-handler-service.interface.ts Action handler execute now returns {partialOptimisticCache, metadataEvents}; events currently derived from pre-optimistic state.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/services/workspace-migration-runner.service.ts Runner service aggregates metadataEvents and changes run() return type; callers need updates to handle new return shape.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/types/metadata-event.ts Introduces MetadataEvent union types; UpdateMetadataEvent includes full before/after which may violate event-payload guidance.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/utils/derive-metadata-events-from-create-action.util.ts Adds create-event derivation; function signature includes unused allFlatEntityMaps argument.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/utils/derive-metadata-events-from-delete-action.util.ts Adds delete-event derivation; uses as MetadataEvent assertion which can hide payload/type mismatches.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/utils/derive-metadata-events-from-update-action.util.ts Adds update-event derivation with diff/updatedFields; includes full before/after in event payload (heavy) and uses type assertions.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/utils/optimistically-apply-create-action-on-all-flat-entity-maps.util.ts Refactors optimistic create apply to accept AllFlatWorkspaceMigrationAction<'create'>; no behavior change observed.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/utils/optimistically-apply-delete-action-on-all-flat-entity-maps.util.ts Refactors optimistic delete apply to accept AllFlatWorkspaceMigrationAction<'delete'>; no behavior change observed.
packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/utils/optimistically-apply-update-action-on-all-flat-entity-maps.util.ts Refactors optimistic update apply to accept AllFlatWorkspaceMigrationAction<'update'>; no behavior change observed.

Sequence Diagram

sequenceDiagram
  participant Builder as MigrationBuilder
  participant Runner as WorkspaceMigrationRunnerService
  participant Handler as RunnerActionHandlerService
  participant Derive as deriveMetadataEventsFrom*Action
  participant Apply as optimisticallyApply*Action
  participant State as FlatEntityMaps

  Builder->>Runner: execute(actions)
  loop for each action
    Runner->>Handler: handle(action, context)
    Handler-->>Runner: { metadataEvents[], result }
    Runner->>State: apply optimistic change
    Runner->>Apply: optimisticallyApply*(action, State)
    Apply-->>Runner: updated State
    Runner->>Derive: deriveMetadataEventsFrom*(action, before/after)
    Derive-->>Runner: metadataEvents
    Runner-->>Runner: accumulate metadataEvents
  end
  Runner-->>Builder: { appliedActions, metadataEvents }
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

10 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 10, 2026

Additional Comments (1)

packages/twenty-server/src/engine/workspace-manager/workspace-migration/workspace-migration-runner/services/workspace-migration-runner.service.ts
Breaking return type change

WorkspaceMigrationRunnerService.run now returns { allFlatEntityMaps, metadataEvents } instead of AllFlatEntityMaps, but existing callers still ignore/destructure the old return type (e.g. workspace:-migration-validate-build-and-run-service.ts:251 and application.resolver.ts:154). This will be a TS error (or silently drop metadataEvents if callers were expecting the maps directly). Update all call sites and any interface typings that expect Promise<AllFlatEntityMaps> to match the new shape.

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

LGTM :)

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.

2 participants