Skip to content

apps/ios: complete strict-concurrency checking for FlashTeXPadKit, warning-clean (follow-up to #359/#372) - #375

Merged
GoKubar merged 5 commits into
mainfrom
agent/daniel-parent/padkit-strict-concurrency
Sep 14, 2026
Merged

GoKubar merged 5 commits into
mainfrom
agent/daniel-parent/padkit-strict-concurrency

Conversation

@d-q222

@d-q222 d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

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 are 5796c275..dcfcfbf1.

Why

#359's crash was a data race that SWIFT_STRICT_CONCURRENCY = minimal let through. This turns on complete checking for the FlashTeXPadKit target so the compiler catches the next one.

Change (4 files, +19/−5, no behaviour change)

  • Package.swift: .enableExperimentalFeature("StrictConcurrency") on the FlashTeXPadKit target only. .unsafeFlags isn't used because Xcode refuses unsafe flags in dependency packages. The Mac-owned NearbyClient/FlashTeXProtocol symlink targets are untouched.
  • CaptureQueue: @unchecked Sendable. The comment names the lock that serializes _records, _lastStoreError and _redeliveries (all verified to be accessed only under the lock).
  • MacLink.TranscriptLine and .Direction: Sendable (immutable value types).
  • PairingStore: now requires Sendable; both conformers already were.

Result

Report only (not edited, owned elsewhere)

Inventory from a temporary complete-checking build of all targets, not committed:

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

d-q222 and others added 4 commits September 14, 2026 01:46
…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]>
…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
GoKubar marked this pull request as ready for review September 14, 2026 16:28
@GoKubar
GoKubar merged commit 4bff7eb into main Sep 14, 2026
20 checks passed
@GoKubar
GoKubar deleted the agent/daniel-parent/padkit-strict-concurrency branch 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]>
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