Skip to content

fix(storage): defer binding updates until ensemble.storage.clear() completes#2231

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-identification-4017
Draft

fix(storage): defer binding updates until ensemble.storage.clear() completes#2231
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-identification-4017

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor Bot commented May 22, 2026

Description

Fixes a race in EnsembleStorage.clear(): StorageManager.clearPublicStorage() is asynchronous (each GetStorage.remove is awaited in a loop), but storage binding listeners handle ModelChangeEvent by re-evaluating the full binding expression via dataContext.eval(), which reads the current value from GetStorage. Firing those dispatches immediately after starting the async clear meant listeners could still read non-null persisted values and repopulate bound widgets, so the UI could appear uncleared until an unrelated rebuild.

Related Issue

None filed; same root cause as the investigation in #2227 (that PR was closed with no code landed).

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

What Has Changed

  • EnsembleStorage.clear() now uses unawaited(StorageManager().clearPublicStorage().whenComplete(...)) so ScreenController.dispatchStorageChanges runs only after the async clear finishes (or fails), preserving the synchronous invokable surface for scripts while fixing ordering for bindings.

How to Test

  1. From modules/ensemble, run flutter test (including test/ensemble_storage_clear_test.dart and test/storage_manager_test.dart).
  2. Manually: bind a widget property to \${ensemble.storage.someKey}, call ensemble.storage.clear() from an action, and confirm the bound UI reflects cleared storage without needing a second interaction or navigation.

Screenshots / Videos

N/A

Checklist

  • I have run flutter analyze and addressed any new warnings
  • I have run flutter test and all tests pass
  • I have tested my changes on the relevant platform(s)
  • I have updated documentation if needed
  • My changes do not introduce new warnings or errors

Note: The CI/automation image used here did not have the Flutter SDK on PATH, so flutter analyze / flutter test were not executed in this environment. Please run them locally per AGENTS.md.

Open in Web View Automation 

…pletes

EnsembleStorage.clear() called clearPublicStorage() without awaiting; binding
listeners re-evaluate expressions by reading GetStorage, so notifications could
run while keys still existed and refresh the UI from stale values.

Co-authored-by: Sharjeel Yunus <sharjeelyunus@users.noreply.github.com>
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