Skip to content

✨ split RumEvent into RendererRumEvent and MainRumEvent - #207

Open
bcaudan wants to merge 2 commits into
mainfrom
bcaudan/schema-update
Open

✨ split RumEvent into RendererRumEvent and MainRumEvent#207
bcaudan wants to merge 2 commits into
mainfrom
bcaudan/schema-update

Conversation

@bcaudan

@bcaudan bcaudan commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Motivation

This allows the Electron SDK to properly type events coming from the main process versus the renderer process, and to support future execution-context events that will be handled by the main process. Main-process code could previously construct RUM events of any type in the full RumEvent union, including action/long_task, even though those never actually originate from the main process.

This builds on rum-events-format#437 (merged), which introduces schemas/rum-events-electron-schema.json: a RumEvent union schema mirroring the browser schema but limited to the event types the main process actually emit.

Changes

  • Generate two separate RUM event unions: RendererRumEvent (browser schema, unchanged) and MainRumEvent (new electron schema), and make ServerRumEvent a discriminated union on source.
  • Move RUM event/type definitions under src/domain/rum/types/.
  • Remove the now-impossible action branch from ViewCollection's main-only counter path.

Test instructions

  1. Run the app in Electron, trigger a click action in the renderer, and confirm the view document's action.count still increments (renderer-origin action events are unaffected by the split).
  2. Trigger a main-process error (e.g. a crash) and confirm it still reaches RUM intake with error.source_type: nodejs.
  3. Try making main-process code construct an action-typed ServerRumEvent and confirm yarn typecheck now rejects it.

Checklist

  • Tested locally (playground)
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated related documentation.
  • Agentic code review findings addressed or explicitly dismissed.

@bcaudan
bcaudan force-pushed the bcaudan/schema-update branch from bf7c83b to 2409b57 Compare August 26, 2026 07:15
@bcaudan

bcaudan commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale comment

PR Review — Score: 4.7 / 5

This is a well-motivated type-boundary refactor that correctly splits browser vs electron RUM schemas, threads the distinction through ServerRumEvent via source, and removes the now-dead main-process action counter path. Tests and assembly call sites are updated consistently, and the change is compile-time safe without altering runtime intake behavior. I would approve.

Why 4.7: Clear motivation tied to rum-events-format#437, disciplined file moves under src/domain/rum/types/, discriminated ServerRumEvent in event.types.ts, targeted ViewCollection cleanup, and unit tests that now assert the main-process subset (error/resource only).

Why not 5: Shared FormatHooks still types RUM assembly with the broad RumEvent union, which forces a cast in MainAssembly and leaves hook callbacks process-agnostic. docs/DEVELOPMENT.md still documents the old src/rumEvent.types.ts path.


Findings

  • [Minor] Stale schema docsdocs/DEVELOPMENT.md still references the removed src/rumEvent.types.ts path instead of the new src/domain/rum/types/ layout.
  • [Minor] Hook pipeline still process-agnosticFormatHooks continues to use RecursivePartial<RumEvent>, so main-process assembly needs an explicit cast rather than getting compile-time guarantees end-to-end.
  • [Nit] Renderer pipeline typingRendererPipeline still casts bridge payloads to the broad RumEvent union; RendererRumEvent would complete the split on the renderer side.

Architectural flow

sequenceDiagram
    participant Raw as RawRumData
    participant MainAsm as MainAssembly
    participant Hooks as FormatHooks
    participant EM as EventManager
    participant Pipe as RendererPipeline
    participant VC as ViewCollection

    Raw->>MainAsm: main-process raw RUM
    MainAsm->>Hooks: triggerRum MAIN
    Hooks-->>MainAsm: hook overrides
    MainAsm->>EM: ServerMainRumEvent

    Pipe->>Hooks: triggerRum RENDERER
    Pipe->>EM: ServerRendererRumEvent

    EM->>VC: ServerRumEvent by source
    Note over VC: main only counts error and resource
Loading

Before: A single RumEvent union backed by the browser schema was used for both processes, so main-process code could type-check impossible event kinds (action, long_task). ServerRumEvent.data was untyped with respect to origin.

After: Browser and electron schemas generate RendererRumEvent and MainRumEvent; ServerRumEvent is a discriminated union on source, and main-only collection paths (e.g. view counters) narrow to the electron subset.

Open in Web View Automation 

Sent by Cursor Automation: electron-sdk reviews

Comment thread src/assembly/MainAssembly.ts
Comment thread src/domain/rum/types/index.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2409b5708f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread eslint.config.mjs
Comment thread scripts/generate-schema-types.ts
@bcaudan
bcaudan force-pushed the bcaudan/schema-update branch 2 times, most recently from db22459 to f881df5 Compare August 26, 2026 07:38
@bcaudan
bcaudan marked this pull request as ready for review August 26, 2026 07:39
@bcaudan
bcaudan requested a review from a team as a code owner August 26, 2026 07:39

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PR Review — Score: 4.9 / 5

This is a well-executed type-boundary refactor that splits browser vs electron RUM schemas, threads the distinction through ServerRumEvent via source, and removes the dead main-process action counter path. Follow-up commits since the first review addressed the documentation, static-analysis ignore list, renderer pipeline typing, and barrel-export rationale. Runtime intake behavior is unchanged and the compile-time guarantees are materially stronger. I would approve.

Why 4.9: Clear motivation tied to rum-events-format#437, disciplined relocation under src/domain/rum/types/, discriminated ServerRumEvent in event.types.ts, targeted ViewCollection cleanup, renderer pipeline now typed with RendererRumEvent, and prior Codex/automation feedback incorporated in the latest head.

Why not 5: FormatHooks.triggerRum still returns the broad RumEvent union (you noted this can wait for a follow-up), so MainAssembly keeps a narrow cast at the hook boundary. That is an intentional tradeoff, not a functional gap.


Architectural flow

sequenceDiagram
    participant Raw as RawRumData
    participant MainAsm as MainAssembly
    participant Hooks as FormatHooks
    participant EM as EventManager
    participant Pipe as RendererPipeline
    participant VC as ViewCollection

    Raw->>MainAsm: main-process raw RUM
    MainAsm->>Hooks: triggerRum MAIN
    Hooks-->>MainAsm: hook overrides
    MainAsm->>EM: ServerMainRumEvent

    Pipe->>Hooks: triggerRum RENDERER
    Pipe->>EM: ServerRendererRumEvent

    EM->>VC: ServerRumEvent by source
    Note over VC: main counts error and resource only
Loading

Before: A single browser-schema RumEvent union backed both processes, so main-process code could type-check impossible event kinds (action, long_task). ServerRumEvent.data was not tied to source.

After: Browser and electron schemas generate RendererRumEvent and MainRumEvent. ServerRumEvent is a discriminated union on source, and main-only collection paths narrow to the electron subset.

Open in Web View Automation 

Sent by Cursor Automation: electron-sdk reviews

Comment thread src/event/event.types.ts
Comment thread src/domain/rum/view/ViewCollection.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f881df5c25

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/DEVELOPMENT.md Outdated
- Add rum-events-electron-schema.json entrypoint (error, resource, view, view_update, vital) as the source for main-process events, keeping the browser schema for renderer events
- Move generated/raw RUM types under src/domain/rum/types/ as a self-contained package boundary (barrel-only imports enforced by no-internal-modules)
- Make ServerRumEvent a discriminated union on source (RENDERER -> RendererRumEvent, MAIN -> MainRumEvent), closing a gap where main-process code could construct action/long_task events that never actually occur
- Drop the now-impossible 'action' branch in ViewCollection's main-only counter path

Submodule ref points to the not-yet-reviewed bcaudan/electron-schema-entrypoint branch; will be updated to master once that PR merges.
@bcaudan
bcaudan force-pushed the bcaudan/schema-update branch from f881df5 to 44926eb Compare August 26, 2026 07:46
@sbarrio
sbarrio requested a review from cdn34dd September 1, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant