Repository navigation
apps/ios: complete strict-concurrency checking for FlashTeXPadKit, warning-clean (follow-up to #359/#372) - #375
Merged
Conversation
…s without a lock CaptureQueueTests.testConcurrentRefreshSendAndRecordsRead hammers refreshOutcome/send/draft plus tight records reads from Task.detached on two received captures (FakeMac + temp CaptureStore). Ran against unfixed CaptureQueue (HEAD 304120c, iPad Pro 11-inch M5 947A8CC1-07E2-4AA2-9363-FA389B569E8D): control unit suite first: Executed 25 tests, with 1 test skipped and 0 failures (0 unexpected) / ** TEST SUCCEEDED ** race test: Crash: FlashTeXPad at closure #1 in closure #1 in closure #2 in CaptureQueueTests.testConcurrentRefreshSendAndRecordsRead(); ** TEST FAILED ** (Restarting after unexpected exit, crash, or test timeout) Next: lock CaptureQueue._records and lastStoreError; isolate hosted XCTest PadModel; re-run this test then the suite. Implementation-Agent: cursor-agent cursor-grok-4.6 Commit-Executor: cursor-agent (this session, git commit) Lane-Owner: daniel-parent (mac-m5pro-dq222) Co-authored-by: Cursor <[email protected]>
…ychain/disk/polling CaptureQueue.records/lastStoreError/redeliveries are NSLock snapshots; update/draft/persistLocked run under the lock (store.save included). pollOutcome is @mainactor [weak self]. Hosted XCTestConfigurationFilePath PadModel() does not attach Keychain or CaptureStore and does not poll leftovers; FlashTeXPadApp skips auto-reconnect in that environment. Ran (iPad Pro 11-inch M5 947A8CC1-07E2-4AA2-9363-FA389B569E8D, iOS 26.5, Xcode 26.6): - unfixed race test: Crash: FlashTeXPad ... testConcurrentRefreshSendAndRecordsRead; TEST FAILED - after lock: race + hosted Executed 2 tests, with 0 failures; TEST SUCCEEDED - FlashTeXPadTests: Executed 27 tests, with 1 test skipped and 0 failures (control was 25 / 1 skip) - TSan -enableThreadSanitizer YES on race test and full suite: Executed 27 tests, 1 skipped, 0 failures; no ThreadSanitizer data-race reports - swift test in FlashTeXPadKit: Build complete! then error: no tests found (package has no test target by design) Next: lane-owner review / PR. Not switching CaptureQueue to actor/@mainactor (would hop off-main callers; current tests are @mainactor so it is feasible). Implementation-Agent: cursor-agent cursor-grok-4.6 Commit-Executor: cursor-agent (this session, git commit) Lane-Owner: daniel-parent (mac-m5pro-dq222) Co-authored-by: Cursor <[email protected]>
Package.swift: .enableExperimentalFeature("StrictConcurrency") on FlashTeXPadKit
only (no .unsafeFlags; NearbyClient / FlashTeXProtocol flags not committed).
What was run (iPad Pro 11-inch M5 947A8CC1-07E2-4AA2-9363-FA389B569E8D, iOS 26.5, Xcode 26.6 / Swift 6.3.3):
- control on unmodified d401d2e: Executed 27 tests, with 1 test skipped and 0 failures / ** TEST SUCCEEDED **
- FlashTeXPad build with PadKit flag: ** BUILD SUCCEEDED **; -enable-experimental-feature StrictConcurrency on FlashTeXPadKit.swiftc; 0 warnings in Sources/FlashTeXPadKit/*.swift
- inventory build with temporary sibling flags + SWIFT_STRICT_CONCURRENCY=complete (not in this commit): ** BUILD SUCCEEDED **; 0 PadKit-owned, 21 NearbyClient, 3 FlashTeXProtocol, 13 app-target (report-only)
PadKit sources are already warning-clean under complete checking (Swift 6.3 region isolation no longer diagnoses class mutation after await). Flag stays ON.
Next: classify (a)/(b); annotate CaptureQueue (@unchecked Sendable, lock) and TranscriptLine (Sendable) as (b); no (a) remaining in PadKit after #359 lock. Then unit + TSan gates.
Open questions: none on the flag spelling; experimental still maps to complete on this frontend.
Implementation-Agent: cursor-agent cursor-grok-4.6
Commit-Executor: cursor-agent (this session, git commit)
Lane-Owner: daniel-parent (mac-m5pro-dq222)
Co-authored-by: Cursor <[email protected]>
…ringStore (b) checker-only; no runtime behaviour change. - CaptureQueue: @unchecked Sendable — lock serializes _records/_lastStoreError/_redeliveries - MacLink.TranscriptLine (and Direction): Sendable (immutable value type) - PairingStore: Sendable (PairFile and KeychainPairStore already are) Rebuild with PadKit StrictConcurrency + SWIFT_STRICT_CONCURRENCY=complete: ** BUILD SUCCEEDED **; still 0 warnings in Sources/FlashTeXPadKit. App PadModel sending-queue/line warnings gone; remaining app warnings are NearbyClient PairedMac/DiscoveredMac (report-only). Next: FlashTeXPadTests control-vs-after and -enableThreadSanitizer YES. Implementation-Agent: cursor-agent cursor-grok-4.6 Commit-Executor: cursor-agent (this session, git commit) Lane-Owner: daniel-parent (mac-m5pro-dq222) Co-authored-by: Cursor <[email protected]>
This was referenced Sep 14, 2026
…h-merged CaptureQueue.swift conflict: main has #372's lock without the Sendable annotation; kept this branch's `@unchecked Sendable` + lock comment. Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
GoKubar
marked this pull request as ready for review
September 14, 2026 16:28
d-q222
added a commit
that referenced
this pull request
Sep 14, 2026
Fixes GH-NEARBY-PAIRFILE (found by #375's strict-concurrency audit): PairFile declares @unchecked Sendable but mutated its `pairs` array with no synchronisation, and read it unlocked from pair(fingerprint:)/ pair(matching:). A real data race, not just a compiler technicality -- confirmed below. Follows the exact CaptureQueue.records shape from #372: private `_pairs` backing storage, `private let lock = NSLock()`, a public computed `pairs` property that reads under the lock, and every mutating method (upsert, remove) taking the lock once around its whole read-modify-write-and-persist sequence via a new saveLocked() (caller must hold lock). pair(fingerprint:) and pair(matching:) now read under the lock too. Public API surface (method signatures, pairs' type and read-only-ness from outside) is unchanged -- behavior-neutral for every existing caller. Also adds Sendable to PairedMac, PairFile.Contents, DiscoveredMac (NearbyBrowser.swift), and NearbyWire.CaptureReceived -- all plain immutable value types with already-Sendable fields. NearbyWire.Destination (referenced by PairedMac.lastDestination) is NOT yet Sendable, which is why PairedMac: Sendable currently compiles with a Swift-6-mode warning rather than an error; fixing Destination is out of this slice's scope (NearbyWire.swift changes were limited to CaptureReceived) and is a natural, one-word follow-up before any Swift 6 migration. New testConcurrentUpsertRemoveKeepsStoreConsistent (125 concurrent tasks: 50 upserts, 50 reads, 25 removes on one PairFile instance) asserts no duplicate fingerprints and disk/memory agreement afterward. Verification, measured (not inferred), by the reviewer outside the Muse sandbox: - BEFORE (unpatched source, same new test applied on top): `swift test --sanitize=thread` reports multiple real "ThreadSanitizer: Swift access race" warnings in PairFile.remove(fingerprint:), and the process crashes with "Fatal error: Index out of range" in ContiguousArrayBuffer -- a real, severe race, not a false positive. - AFTER (this fix): `swift test --filter PairFileTests --sanitize=thread`: 2 tests, 0 failures, zero TSan reports. Re-run again after rebasing onto current main: still clean. - `swift build` in nearby-client: exit 0 (only the anticipated Destination warning, expected and explained above). Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane nearby-pairfile-lock, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Muse-Lane-Head: 2aa90d0e Co-authored-by: d-q222 <[email protected]>
d-q222
added a commit
that referenced
this pull request
Sep 14, 2026
Fixes GH-NEARBY-PAIRFILE (found by #375's strict-concurrency audit): PairFile declares @unchecked Sendable but mutated its `pairs` array with no synchronisation, and read it unlocked from pair(fingerprint:)/ pair(matching:). A real data race, not just a compiler technicality -- confirmed below. Follows the exact CaptureQueue.records shape from #372: private `_pairs` backing storage, `private let lock = NSLock()`, a public computed `pairs` property that reads under the lock, and every mutating method (upsert, remove) taking the lock once around its whole read-modify-write-and-persist sequence via a new saveLocked() (caller must hold lock). pair(fingerprint:) and pair(matching:) now read under the lock too. Public API surface (method signatures, pairs' type and read-only-ness from outside) is unchanged -- behavior-neutral for every existing caller. Also adds Sendable to PairedMac, PairFile.Contents, DiscoveredMac (NearbyBrowser.swift), and NearbyWire.CaptureReceived -- all plain immutable value types with already-Sendable fields. NearbyWire.Destination (referenced by PairedMac.lastDestination) is NOT yet Sendable, which is why PairedMac: Sendable currently compiles with a Swift-6-mode warning rather than an error; fixing Destination is out of this slice's scope (NearbyWire.swift changes were limited to CaptureReceived) and is a natural, one-word follow-up before any Swift 6 migration. New testConcurrentUpsertRemoveKeepsStoreConsistent (125 concurrent tasks: 50 upserts, 50 reads, 25 removes on one PairFile instance) asserts no duplicate fingerprints and disk/memory agreement afterward. Verification, measured (not inferred), by the reviewer outside the Muse sandbox: - BEFORE (unpatched source, same new test applied on top): `swift test --sanitize=thread` reports multiple real "ThreadSanitizer: Swift access race" warnings in PairFile.remove(fingerprint:), and the process crashes with "Fatal error: Index out of range" in ContiguousArrayBuffer -- a real, severe race, not a false positive. - AFTER (this fix): `swift test --filter PairFileTests --sanitize=thread`: 2 tests, 0 failures, zero TSan reports. Re-run again after rebasing onto current main: still clean. - `swift build` in nearby-client: exit 0 (only the anticipated Destination warning, expected and explained above). Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane nearby-pairfile-lock, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Muse-Lane-Head: 2aa90d0e Co-authored-by: d-q222 <[email protected]>
GoKubar
pushed a commit
that referenced
this pull request
Sep 15, 2026
…#410) Fixes GH-NEARBY-PAIRFILE (found by #375's strict-concurrency audit): PairFile declares @unchecked Sendable but mutated its `pairs` array with no synchronisation, and read it unlocked from pair(fingerprint:)/ pair(matching:). A real data race, not just a compiler technicality -- confirmed below. Follows the exact CaptureQueue.records shape from #372: private `_pairs` backing storage, `private let lock = NSLock()`, a public computed `pairs` property that reads under the lock, and every mutating method (upsert, remove) taking the lock once around its whole read-modify-write-and-persist sequence via a new saveLocked() (caller must hold lock). pair(fingerprint:) and pair(matching:) now read under the lock too. Public API surface (method signatures, pairs' type and read-only-ness from outside) is unchanged -- behavior-neutral for every existing caller. Also adds Sendable to PairedMac, PairFile.Contents, DiscoveredMac (NearbyBrowser.swift), and NearbyWire.CaptureReceived -- all plain immutable value types with already-Sendable fields. NearbyWire.Destination (referenced by PairedMac.lastDestination) is NOT yet Sendable, which is why PairedMac: Sendable currently compiles with a Swift-6-mode warning rather than an error; fixing Destination is out of this slice's scope (NearbyWire.swift changes were limited to CaptureReceived) and is a natural, one-word follow-up before any Swift 6 migration. New testConcurrentUpsertRemoveKeepsStoreConsistent (125 concurrent tasks: 50 upserts, 50 reads, 25 removes on one PairFile instance) asserts no duplicate fingerprints and disk/memory agreement afterward. Verification, measured (not inferred), by the reviewer outside the Muse sandbox: - BEFORE (unpatched source, same new test applied on top): `swift test --sanitize=thread` reports multiple real "ThreadSanitizer: Swift access race" warnings in PairFile.remove(fingerprint:), and the process crashes with "Fatal error: Index out of range" in ContiguousArrayBuffer -- a real, severe race, not a false positive. - AFTER (this fix): `swift test --filter PairFileTests --sanitize=thread`: 2 tests, 0 failures, zero TSan reports. Re-run again after rebasing onto current main: still clean. - `swift build` in nearby-client: exit 0 (only the anticipated Destination warning, expected and explained above). Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane nearby-pairfile-lock, slice 1) Commit-Executor: daniel-muse-lead (Claude Sonnet) Reviewed-by: daniel-muse-lead (Claude Sonnet) Muse-Lane-Head: 2aa90d0e Co-authored-by: muse-spark-1.3-contributor <[email protected]>
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.
Claim
GH-PADKIT-CONCURRENCY, announced on #2 before launch. Implemented by a Cursor worker (Grok 4.6 high), reviewed by daniel-parent. Draft, stacked on #372 (the FlashTeXPad crash fix); this lane's commits are5796c275..dcfcfbf1.Why
#359's crash was a data race that
SWIFT_STRICT_CONCURRENCY = minimallet through. This turns on complete checking for theFlashTeXPadKittarget so the compiler catches the next one.Change (4 files, +19/−5, no behaviour change)
Package.swift:.enableExperimentalFeature("StrictConcurrency")on the FlashTeXPadKit target only..unsafeFlagsisn't used because Xcode refuses unsafe flags in dependency packages. The Mac-ownedNearbyClient/FlashTeXProtocolsymlink targets are untouched.CaptureQueue:@unchecked Sendable. The comment names thelockthat serializes_records,_lastStoreErrorand_redeliveries(all verified to be accessed only under the lock).MacLink.TranscriptLineand.Direction:Sendable(immutable value types).PairingStore: now requiresSendable; both conformers already were.Result
FlashTeXPadKit(Swift 6.3 region-based isolation hadn't flagged the FlashTeXPad crashes (EXC_BAD_ACCESS/SIGSEGV) in PadModel.pollOutcome → @Published captures setter — data race on CaptureQueue.records #359 pattern either). The useful signal was cross-module Sendable holes, now annotated.** BUILD SUCCEEDED **with-enable-experimental-feature StrictConcurrencyon the compile line, and 0 warnings inSources/FlashTeXPadKit.Report only (not edited, owned elsewhere)
Inventory from a temporary complete-checking build of all targets, not committed:
NearbyClient(21 unique warnings, Mac-owned):PairedMac,DiscoveredMacandNearbyWire.CaptureReceivedneedSendable. More importantly,PairFileis@unchecked Sendablebut itspairsarray is mutated without a lock (NearbyClient.swift:142). That's a latent race if the file store is used from more than one task.FlashTeXProtocol: 3 warnings.ContentView/CaptureVieware being edited by ios: the capture canvas fills the screen again (revert the 200pt cap) #348, ios: continuous autofocus for the QR scanner and the capture camera #349 and ios: show where a capture will land and how it will be wrapped #352):CaptureView.cameraAvailable, an unusedtry?inPadModel,ContentViewpreconcurrency conformances.MacLink.onTranscript: an unsynchronised public stored property. It's written once inPadModel.initbefore connect, so it isn't reachable as a race today.🤖 Generated with Claude Code
https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz