Skip to content

fix: Use custom state manager for cronjob controller#3539

Merged
Mrtenz merged 2 commits intomainfrom
mrtenz/cronjob-state-manager
Jul 18, 2025
Merged

fix: Use custom state manager for cronjob controller#3539
Mrtenz merged 2 commits intomainfrom
mrtenz/cronjob-state-manager

Conversation

@Mrtenz
Copy link
Copy Markdown
Member

@Mrtenz Mrtenz commented Jul 18, 2025

This updates the cronjob controller to add a custom stateManager property for persisting state. This is a temporary workaround for the controller persisting state too often, causing the entire client state to be written.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.26%. Comparing base (ca23eda) to head (0672fed).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3539   +/-   ##
=======================================
  Coverage   98.26%   98.26%           
=======================================
  Files         411      411           
  Lines       11619    11624    +5     
  Branches     1810     1810           
=======================================
+ Hits        11417    11422    +5     
  Misses        202      202           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Mrtenz Mrtenz force-pushed the mrtenz/cronjob-state-manager branch from c846098 to 0672fed Compare July 18, 2025 16:31
Comment on lines 186 to +187
...state,
...stateManager.getInitialState(),
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.

I guess this means we will always overwrite an obsolete state after the first init but that looks fine for now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

getInitialState may be undefined

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.

Yeah and we still need to recover the state the first time

@Mrtenz Mrtenz marked this pull request as ready for review July 18, 2025 16:40
@Mrtenz Mrtenz requested a review from a team as a code owner July 18, 2025 16:40
@Mrtenz Mrtenz added this pull request to the merge queue Jul 18, 2025
Copy link
Copy Markdown

@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.

Bug: State Initialization Fails When Undefined is Spread

The CronjobController constructor's state initialization attempts to spread stateManager.getInitialState(), which can return undefined. Spreading undefined in an object literal causes a TypeError at runtime. Additionally, the state merge order (...state, ...stateManager.getInitialState()) means that properties from the state constructor parameter are silently overridden by those from stateManager.getInitialState() if keys conflict.

packages/snaps-controllers/src/cronjob/CronjobController.ts#L183-L188

name: controllerName,
state: {
events: {},
...state,
...stateManager.getInitialState(),
},

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

Merged via the queue into main with commit 8c54f0c Jul 18, 2025
120 checks passed
@Mrtenz Mrtenz deleted the mrtenz/cronjob-state-manager branch July 18, 2025 16:46
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.

3 participants