From e73f3c2288cc958812e36a201dca0efbe9d2dcce Mon Sep 17 00:00:00 2001 From: npub1ft62tztwwm2x9xamk25smmuaj4sfckdkldksruf2x2jwqalffkrq0g7arr <4af4a5896e76d4629bbbb2a90def9d95609c59b6fb6d01f12a32a4e077e94d86@sprout-oss.stage.blox.sqprod.co> Date: Sun, 19 Jul 2026 17:11:52 -0700 Subject: [PATCH] fix(mobile): retry diagnostics teardown Co-authored-by: npub1ft62tztwwm2x9xamk25smmuaj4sfckdkldksruf2x2jwqalffkrq0g7arr <4af4a5896e76d4629bbbb2a90def9d95609c59b6fb6d01f12a32a4e077e94d86@sprout-oss.stage.blox.sqprod.co> Signed-off-by: npub1ft62tztwwm2x9xamk25smmuaj4sfckdkldksruf2x2jwqalffkrq0g7arr <4af4a5896e76d4629bbbb2a90def9d95609c59b6fb6d01f12a32a4e077e94d86@sprout-oss.stage.blox.sqprod.co> --- .../shared/diagnostics/diagnostics_controller.dart | 6 ++++++ .../diagnostics/diagnostics_controller_test.dart | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mobile/lib/shared/diagnostics/diagnostics_controller.dart b/mobile/lib/shared/diagnostics/diagnostics_controller.dart index c7cddefde..5ac17e256 100644 --- a/mobile/lib/shared/diagnostics/diagnostics_controller.dart +++ b/mobile/lib/shared/diagnostics/diagnostics_controller.dart @@ -61,6 +61,12 @@ class DiagnosticsController extends ChangeNotifier { Future setConsent(bool granted) { return _serialize(() async { if (_consentGranted == granted) { + // A failed close keeps the runtime initialized even though the + // persisted preference and visible control are already off. Allow the + // same revocation to retry teardown until it succeeds. + if (!granted && _initialized) { + await _applyCurrentConsent(); + } return; } diff --git a/mobile/test/shared/diagnostics/diagnostics_controller_test.dart b/mobile/test/shared/diagnostics/diagnostics_controller_test.dart index ce8db62a0..a3f3540fa 100644 --- a/mobile/test/shared/diagnostics/diagnostics_controller_test.dart +++ b/mobile/test/shared/diagnostics/diagnostics_controller_test.dart @@ -207,7 +207,7 @@ void main() { expect(reporter.initializeCalls, 1); }); - test('close failure preserves persisted revocation', () async { + test('close failure preserves revocation and retries teardown', () async { final controller = await createController( storedValues: {diagnosticsConsentPreferenceKey: true}, ); @@ -219,6 +219,17 @@ void main() { expect(controller.consentGranted, isFalse); expect(preferences.getBool(diagnosticsConsentPreferenceKey), isFalse); expect(reporter.closeCalls, 1); + + reporter.closeError = null; + await controller.setConsent(false); + + expect(controller.consentGranted, isFalse); + expect(preferences.getBool(diagnosticsConsentPreferenceKey), isFalse); + expect(reporter.closeCalls, 2); + expect( + logs, + contains('Diagnostics disabled: user consent is off; Sentry closed.'), + ); }); test('continues accepting changes after a failed operation', () async {