Skip to content

Add thread-safety locks for Organization state access#127

Closed
Copilot wants to merge 4 commits intofix/grouping-seems-broken-i-can-create-a-gro-20260216-2018from
copilot/sub-pr-125-again
Closed

Add thread-safety locks for Organization state access#127
Copilot wants to merge 4 commits intofix/grouping-seems-broken-i-can-create-a-gro-20260216-2018from
copilot/sub-pr-125-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 16, 2026

Organization.Sessions and Organization.Groups are List<T> collections accessed from both the UI thread (Blazor event handlers) and background threads (WebSocket receive loop in WsBridgeServer.HandleOrganizationCommand), creating a race condition.

Changes:

  • Added _organizationLock to synchronize all accesses to Organization.Sessions and Organization.Groups
  • Protected all 17 methods in CopilotService.Organization.cs that read/write organization state
  • Protected 4 direct access points in CopilotService.cs (ResumeSessionAsync, CreateSessionAsync, CreateSession, RenameSession)

Lock patterns:

  • Snapshot saves: Serialize under lock, write file outside lock to avoid holding lock during I/O
  • GetOrganizedSessions: Copy state under lock, sort outside lock for better performance
  • C# locks are reentrant, so nested calls (LoadOrganization → ReconcileOrganization → SaveOrganization) work correctly
public void MoveSession(string sessionName, string groupId)
{
    lock (_organizationLock)
    {
        if (!Organization.Groups.Any(g => g.Id == groupId))
            return;

        var meta = Organization.Sessions.FirstOrDefault(m => m.SessionName == sessionName);
        // ... update meta, save, notify
    }
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 16, 2026 21:09
…oups access

Co-authored-by: davidortinau <41873+davidortinau@users.noreply.github.com>
…clarity

Co-authored-by: davidortinau <41873+davidortinau@users.noreply.github.com>
…ecisions

Co-authored-by: davidortinau <41873+davidortinau@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix session grouping menu item issue based on feedback Add thread-safety locks for Organization state access Feb 16, 2026
Copilot AI requested a review from davidortinau February 16, 2026 21:15
@PureWeen PureWeen deleted the branch fix/grouping-seems-broken-i-can-create-a-gro-20260216-2018 February 22, 2026 00:18
@PureWeen PureWeen closed this Feb 22, 2026
@PureWeen PureWeen deleted the copilot/sub-pr-125-again branch February 22, 2026 00:18
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.

3 participants