Problem
_activeSessionName is a plain string? field on CopilotService accessed from multiple threads:
| Thread |
Operation |
Location |
| UI thread |
Write (SetActiveSession, CloseSession, RenameSession, CreateSession) |
CopilotService.cs |
| WsBridge background |
Read + conditional write |
CopilotService.Bridge.cs:532 |
| Restore background |
Conditional write (??=) |
CopilotService.Persistence.cs:380 |
| SDK event handler |
Read comparison |
CopilotService.Events.cs:876 |
| SaveActiveSessionsToDisk |
Read |
CopilotService.Persistence.cs:457 |
On ARM (iOS/Android), without volatile, a write from the UI thread may sit in a CPU store buffer and never become visible to reads on other cores. This can cause:
- WsBridge syncing a stale active session name
- SaveActiveSessionsToDisk persisting the wrong active session
- Events handler comparing against a stale value
Proposed Fix
Mark the field volatile — ensures memory barriers on every read/write. All compound patterns (??=, compare-then-swap) are either on the UI thread or benign (idempotent/first-write-wins).
Problem
_activeSessionNameis a plainstring?field onCopilotServiceaccessed from multiple threads:??=)On ARM (iOS/Android), without
volatile, a write from the UI thread may sit in a CPU store buffer and never become visible to reads on other cores. This can cause:Proposed Fix
Mark the field
volatile— ensures memory barriers on every read/write. All compound patterns (??=, compare-then-swap) are either on the UI thread or benign (idempotent/first-write-wins).