Conversation
There was a problem hiding this comment.
Pull request overview
Follow-up to #126 that standardizes the Locked synchronization helper and updates call sites to use it consistently when guarding shared mutable state.
Changes:
- Rename
Locked.access→Locked.withLockand moveLockedintoSources/AnyLanguageModel/Shared/. - Replace ad-hoc
NSLock+ dictionaries in caches withLocked<...>wrappers. - Update
LanguageModelSessionand tests to usewithLockthroughout.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/AnyLanguageModelTests/ObservationTests.swift | Updates observation tests to use withLock when mutating/reading tracked flags. |
| Tests/AnyLanguageModelTests/LockedTests.swift | Updates Locked unit tests for the renamed API and suite name. |
| Sources/AnyLanguageModel/Shared/StructuredGeneration.swift | Replaces manual NSLock protection of token cache with Locked. |
| Sources/AnyLanguageModel/Shared/Locked.swift | Adds Locked implementation with withLock API and documentation. |
| Sources/AnyLanguageModel/Models/MLXLanguageModel.swift | Replaces manual locking of inFlight task dictionary with Locked. |
| Sources/AnyLanguageModel/Locked.swift | Removes the old Locked implementation from the root source folder. |
| Sources/AnyLanguageModel/LanguageModelSession.swift | Updates session state access/mutations to use withLock consistently. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
atdrendel
approved these changes
Feb 17, 2026
Contributor
atdrendel
left a comment
There was a problem hiding this comment.
Good stuff. I'm happy to see Locked being used elsewhere in the app. Sadly, it seems like every open source project needs its own implementation, at least until we call all rely on Mutex when requiring iOS 18.
Contributor
There was a problem hiding this comment.
Nice to see the Locked be used elsewhere in the app.
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.
Follow-up to #126