Skip to content

Conversation

@KazaiMazai
Copy link
Owner

@KazaiMazai KazaiMazai commented Dec 18, 2025

The PR fixes a possible data race of the underlying BTree since it can contain shared reference-type BtreeNodes


Note

Converts Index.ComparableValue to a locked reference model to prevent BTree data races, adds EntityRefModel macro and wiring, and bumps macOS minimum to 13.

  • Indexing / Concurrency:
    • Convert Index.ComparableValue from @EntityModel struct to @EntityRefModel final class and mark @unchecked Sendable.
    • Add OSAllocatedUnfairLock and wrap reads/writes (sorted, filter, contains, grouped, update, remove) with lock; move mutating internals to private _ helpers.
  • Macros:
    • Introduce EntityRefModel macro and register in Macros.swift and MacrosPlugin.
    • Update EntityModelMacro to handle classes by generating entityRefModelProtocol and nonmutating normalize(); add supporting codegen helpers.
  • Build:
    • Raise macOS deployment target to v13.

Written by Cursor Bugbot for commit 003905b. This will update automatically on new commits. Configure here.

@KazaiMazai KazaiMazai self-assigned this Dec 18, 2025
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.


Bug: Missing lock protection on `sorted` property causes race

The sorted computed property accesses the index dictionary directly without acquiring the lock, creating a data race. All other public methods that read from or write to index (such as filter, contains, grouped, update, and remove) are wrapped with lock.withLock { }, but sorted was missed. This property is actively used in QuerySorted.swift when sorting queries, so concurrent reads via sorted and writes via update/remove can cause undefined behavior.

Sources/SwiftletModel/Index/Index+Comparable.swift#L27-L30

var sorted: [Entity.ID] {
index.flatMap { $0.1.elements }
}

Fix in Cursor Fix in Web


@KazaiMazai KazaiMazai merged commit 02f0dfd into main Dec 18, 2025
2 checks passed
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.

2 participants