fix(core): Clear contexts on Scope.clear() - #5902
Merged
Merged
Conversation
Scope.clear() reset every field except contexts, so anything set via setContexts survived a clear. Contexts had no clear() method, unlike the tags, extra, and fingerprint collections, which is why it was skipped. Add Contexts.clear(), override it in CombinedContextsView to delegate to the default context, and clear contexts in Scope.clear() while notifying scope observers so persisted scopes stay in sync. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📲 Install BuildsAndroid
|
runningcode
marked this pull request as ready for review
August 6, 2026 13:44
runningcode
requested review from
0xadam-brown,
adinauer,
markushi and
romtsn
as code owners
August 6, 2026 13:44
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 303.49 ms | 439.08 ms | 135.59 ms |
| b750b96 | 408.98 ms | 480.32 ms | 71.34 ms |
| 17a0955 | 372.53 ms | 446.70 ms | 74.17 ms |
| d217708 | 355.34 ms | 381.39 ms | 26.05 ms |
| 5b1a06b | 310.56 ms | 362.79 ms | 52.22 ms |
| fcec2f2 | 311.35 ms | 384.94 ms | 73.59 ms |
| 62b579c | 349.26 ms | 426.26 ms | 77.00 ms |
| 5f14e5d | 325.76 ms | 368.32 ms | 42.56 ms |
| 48277cd | 320.38 ms | 379.90 ms | 59.52 ms |
| a416a65 | 295.53 ms | 373.74 ms | 78.21 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| b750b96 | 1.58 MiB | 2.10 MiB | 533.19 KiB |
| 17a0955 | 1.58 MiB | 2.10 MiB | 533.20 KiB |
| d217708 | 1.58 MiB | 2.10 MiB | 532.97 KiB |
| 5b1a06b | 0 B | 0 B | 0 B |
| fcec2f2 | 1.58 MiB | 2.12 MiB | 551.51 KiB |
| 62b579c | 0 B | 0 B | 0 B |
| 5f14e5d | 1.58 MiB | 2.19 MiB | 620.00 KiB |
| 48277cd | 0 B | 0 B | 0 B |
| a416a65 | 1.58 MiB | 2.12 MiB | 555.26 KiB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
Scope.clear()reset every field on the scope exceptcontexts, so anything set viasetContexts(...)survived aclear(). The root cause is thatContextshad noclear()method (unlike thetags,extra, andfingerprintcollections thatclear()already resets), so contexts were simply left untouched.This PR:
Contexts.clear().clear()inCombinedContextsViewto delegate to the default context, consistent with howput/removealready delegate (otherwiseclear()on the view would no-op against its always-empty inherited storage).Scope.clear()and notifies scope observers with the now-empty contexts, so persisted scopes (e.g. Android's scope-on-disk used for native crashes) stay in sync — matching whatsetContexts/clearBreadcrumbsalready do.💡 Motivation and Context
Reported while adding the scopes API to the Godot Engine (hybrid) SDK:
clear()cleared everything except contexts, forcing a manual workaround that removes each context key by hand.Fixes GH-5894
Fixes JAVA-683
💚 How did you test it?
Added unit tests:
ContextsTest—clear()empties the contexts.CombinedContextsViewTest—clear()clears only the default context.ScopeTest— extended the reset test to cover contexts, plus a new test verifyingclear()notifies scope observers with empty contexts.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Hybrid SDKs (e.g. Godot) can drop their manual context-clearing workaround once this ships.