Skip to content

refactor(backend): update event processor#1542

Merged
tyler-dane merged 4 commits intomainfrom
refactor/event-processor
Mar 16, 2026
Merged

refactor(backend): update event processor#1542
tyler-dane merged 4 commits intomainfrom
refactor/event-processor

Conversation

@tyler-dane
Copy link
Copy Markdown
Contributor

@tyler-dane tyler-dane commented Mar 16, 2026

Summary

Refactor Compass recurrence sync from a lifecycle-heavy parser class into explicit planner/executor layers, and document the recurrence model and sync flow more clearly.

Why

The old CompassEventParser was handling too many concerns at once:

  • loading DB state
  • classifying recurrence transitions
  • deciding which persistence path to take
  • performing Compass writes
  • describing Google side effects

That made the code branch-heavy and stateful. Most methods depended on hidden mutable state set by init(), so the actual inputs and invariants were not obvious from the call sites.

This change separates those responsibilities so each layer answers one question:

  • planner: what transition happened and what should happen next?
  • executor: what Compass DB mutations should be applied?
  • processor: should Google be updated/deleted/created after Compass persistence succeeds?

What changed

Compass sync refactor

Explicit plan model

Added internal backend types for the Compass path:

  • CompassTransitionContext
  • CompassOperationPlan
  • CompassApplyResult
  • CompassMutation
  • GoogleEffectPlan

Notable details:

  • new Compass mutation keys use uppercase syntax: CREATE, UPDATE, DELETE, UPDATE_SERIES, RECREATE_SERIES, TRUNCATE_SERIES
  • delete-oriented Google effects prefer persisted dbEvent.gEventId before the incoming payload gEventId
  • recurrence split behavior is explicit:
    • TRUNCATE_SERIES when only UNTIL changed
    • RECREATE_SERIES when other RRULE semantics changed
    • UPDATE_SERIES when no split is needed

Tests

Docs

Rationale

This refactor reduces hidden state and makes the recurrence path easier to reason about:

  • transition analysis is now plain data, not object lifecycle
  • Compass DB mutations are centralized in one executor
  • Google side effects stay at the processor boundary where external coordination belongs
  • recurrence-specific branching is easier to test in isolation
  • the sync processor is easier to read because orchestration is explicit instead of spread across parser methods

The main goal was maintainability, not a product behavior change.

Validation

Ran:

yarn test:backend --runTestsByPath packages/backend/src/event/classes/compass.event.parser.test.ts packages/backend/src/event/classes/compass.event.executor.test.ts packages/backend/src/sync/services/sync/__tests__/compass.sync.processor.test.ts --runInBand

Result:

  • 3 suites passed
  • 16 tests passed

I also observed the existing Compass recurrence-heavy backend integration suites passing during a broader backend run, although a full clean yarn test:backend remains noisy in this environment due to unrelated Jest/Mongo setup issues outside this change.


Note

Medium Risk
Refactors core event/recurrence sync orchestration and Google side-effect execution, which could subtly change persistence or sync behavior across many transition paths. Risk is mitigated by new unit tests and largely equivalent transition mapping, but regressions would affect recurring events and Google sync.

Overview
Refactors Compass event write processing from a stateful CompassEventParser lifecycle into an explicit plan/apply/side-effect pipeline: analyzeCompassTransition(...) now builds a CompassOperationPlan, applyCompassPlan(...) executes only Compass DB mutation steps, and CompassSyncProcessor runs Google create/update/delete after successful DB commit.

Adds a new recurrence transition/planning model (series update vs truncate vs recreate), including safeguards like clearing recurrence before Google updates when a series becomes standalone and preferring persisted gEventId for delete operations. Updates backend tests to target the new planner/executor boundaries and adjusts integration tests to create initial series via CompassSyncProcessor.

Documentation is expanded/updated with a new recurrence-handling.md and refreshed backend/google-sync flow docs to match the new architecture, plus removes some debug logging in the Google notification handler.

Written by Cursor Bugbot for commit b3725f2. This will update automatically on new commits. Configure here.

@tyler-dane tyler-dane marked this pull request as ready for review March 16, 2026 02:40
- Introduced the `applyCompassPlan` function to handle various event operations such as creation, updating, and deletion of Compass events.
- Added comprehensive unit tests for `applyCompassPlan` to ensure correct behavior across different scenarios, including standalone and recurring events.
- Refactored the `CompassEventParser` and `CompassSyncProcessor` to utilize the new plan application logic, enhancing the overall event handling process.
- Updated existing tests to align with the new structure and ensure robust coverage of the event synchronization features.
…andling guide

- Updated the backend request flow documentation to clarify the processing steps in the `CompassSyncProcessor`.
- Revised common change recipes to include new references for recurrence handling and related files.
- Added a new document detailing the recurrence handling lifecycle, including structural models, categories, and update scopes for recurring events.
- Improved the Google sync and websocket flow documentation to reflect changes in event processing and side effects.
- Ensured all relevant files are documented for better understanding of event and task domain models.
- Updated the Compass mutation strings in the codebase to use uppercase naming conventions for consistency.
- Adjusted related tests and documentation to reflect these changes, ensuring uniformity across the application.
- Enhanced clarity and maintainability of the event handling logic by adhering to a unified naming standard.
@tyler-dane tyler-dane force-pushed the refactor/event-processor branch from 7f3d4ca to b3725f2 Compare March 16, 2026 03:07
@tyler-dane tyler-dane merged commit fa2de81 into main Mar 16, 2026
9 checks passed
@tyler-dane tyler-dane deleted the refactor/event-processor branch March 16, 2026 03:13
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.


const nextSyncToken = response.data.nextSyncToken;

console.log("LATEST CHANGES (from gcal):");
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.

Debug console.log left after partial cleanup

Low Severity

This commit removed the label console.log("LATEST CHANGES (from gcal):") but left behind the paired console.log(JSON.stringify(response.data, null, 2)), which dumps the full Google Calendar response payload to stdout. In compass.sync.processor.ts, the analogous pair of console.log statements was fully removed. The inconsistency suggests this line was overlooked during cleanup.

Fix in Cursor Fix in Web

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