Replace identity-hash Koin scopeId with a monotonic counter in context classes#759
Draft
bedaHovorka with Copilot wants to merge 2 commits into
Draft
Replace identity-hash Koin scopeId with a monotonic counter in context classes#759bedaHovorka with Copilot wants to merge 2 commits into
bedaHovorka with Copilot wants to merge 2 commits into
Conversation
Copilot
AI
changed the title
[WIP] Fix Koin scope id generation in DefaultSimulationContext
Replace identity-hash Koin scopeId with a monotonic counter in context classes
Jul 12, 2026
c3a599f to
08f93d8
Compare
d47ca41 to
a635cf0
Compare
|
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.



DefaultSimulationContextandDefaultEditingContextderived their KoinscopeIdfrom identity hash codes (platformIdentityCode/hashCode()). Identity hash codes live in a 31-bit space and are not unique, so under high context-creation volume (e.g. JMH benchmarks creating tens of thousands of contexts) two live contexts can collide, throwingScopeAlreadyCreatedException.Scope id generation
ContextScopeIds.ktwithnextContextScopeId(), a process-wide,atomicfu-backed monotonic counter that is unique by construction regardless of context creation rate.DefaultSimulationContextandDefaultEditingContextnow usenextContextScopeId()instead of an identity hash code:Documentation
platformIdentityCode's KDoc to explicitly state it must not be used as a unique identifier (debug logging only), since its own collision caveat was previously being ignored at a load-bearing call site.Tests
ContextScopeIdUniquenessTest(commonTest) asserting scope ids stay unique across thousands of contexts and thatnextContextScopeId()never repeats.