Summary
KernelDispatch (skainet-backend-api) keeps its kernel table in a plain MutableList and guards auto-install with an unsynchronized var autoInstallAttempted; KernelRegistry does the same with its provider list. KernelDispatch.matmul calls ensureInstalled() and find(key) on every dispatch, so two threads dispatching at once (e.g. per-head attention tasks, or two forwards on two contexts) can race: ConcurrentModificationException from ArrayList, a double auto-install, or a lost registration.
Where
skainet-backends/skainet-backend-api/src/commonMain/kotlin/sk/ainet/backend/api/kernel/KernelDispatch.kt — kernels: MutableList, ensureInstalled(), register(), var defaultSink
.../KernelRegistry.kt — providers: MutableList, register() (its KDoc already says "not thread-safe")
Fix (in feature/skeep-005-schedules)
Immutable snapshots replaced wholesale under a lock (@Volatile list + a @OptionalExpectation JvmSynchronized that actualizes to kotlin.jvm.Synchronized on JVM/Android and is a no-op elsewhere). Reads stay lock-free. Covered by KernelDispatchConcurrencyTest (16 threads registering/finding; contended ensureInstalled() runs once).
Context
Prerequisite for SKEEP-005 (schedules / structured concurrency): schedule workers dispatch concurrently.
Summary
KernelDispatch(skainet-backend-api) keeps its kernel table in a plainMutableListand guards auto-install with an unsynchronizedvar autoInstallAttempted;KernelRegistrydoes the same with its provider list.KernelDispatch.matmulcallsensureInstalled()andfind(key)on every dispatch, so two threads dispatching at once (e.g. per-head attention tasks, or two forwards on two contexts) can race:ConcurrentModificationExceptionfromArrayList, a double auto-install, or a lost registration.Where
skainet-backends/skainet-backend-api/src/commonMain/kotlin/sk/ainet/backend/api/kernel/KernelDispatch.kt—kernels: MutableList,ensureInstalled(),register(),var defaultSink.../KernelRegistry.kt—providers: MutableList,register()(its KDoc already says "not thread-safe")Fix (in
feature/skeep-005-schedules)Immutable snapshots replaced wholesale under a lock (
@Volatilelist + a@OptionalExpectationJvmSynchronizedthat actualizes tokotlin.jvm.Synchronizedon JVM/Android and is a no-op elsewhere). Reads stay lock-free. Covered byKernelDispatchConcurrencyTest(16 threads registering/finding; contendedensureInstalled()runs once).Context
Prerequisite for SKEEP-005 (schedules / structured concurrency): schedule workers dispatch concurrently.