Skip to content

Fix memory ordering race condition in MotelyPaths initialization#16

Merged
joirunner merged 2 commits intofeat/stabilize-local-dev-pathsfrom
copilot/sub-pr-1-again
Jan 19, 2026
Merged

Fix memory ordering race condition in MotelyPaths initialization#16
joirunner merged 2 commits intofeat/stabilize-local-dev-pathsfrom
copilot/sub-pr-1-again

Conversation

Copy link

Copilot AI commented Jan 19, 2026

The MotelyPaths static class had a memory ordering race condition: only _contentRoot and _isInitialized were volatile, but the override path fields were not. Threads could observe _isInitialized = true while still seeing uninitialized values for _jamlFiltersOverride, _seedSourcesOverride, and _searchResultsOverride due to CPU cache coherency delays.

Changes

  • Made all static fields in MotelyPaths volatile to ensure proper memory ordering
private static volatile string _contentRoot = Directory.GetCurrentDirectory();
private static volatile string? _jamlFiltersOverride;      // now volatile
private static volatile string? _seedSourcesOverride;      // now volatile  
private static volatile string? _searchResultsOverride;    // now volatile
private static volatile bool _isInitialized = false;

This guarantees that when a thread observes _isInitialized = true, it will also observe the correct initialized values for all override paths written during Initialize().


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ce condition

Co-authored-by: joirunner <6373131+joirunner@users.noreply.github.com>
@joirunner joirunner marked this pull request as ready for review January 19, 2026 23:34
Copilot AI review requested due to automatic review settings January 19, 2026 23:34
Copilot AI changed the title [WIP] Fix local dev paths stabilization with ContentRoot resolution Fix memory ordering race condition in MotelyPaths initialization Jan 19, 2026
@joirunner joirunner merged commit b10f984 into feat/stabilize-local-dev-paths Jan 19, 2026
Copilot AI requested a review from joirunner January 19, 2026 23:34
Copilot stopped work on behalf of joirunner due to an error January 19, 2026 23:34
@joirunner joirunner deleted the copilot/sub-pr-1-again branch January 19, 2026 23:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a memory ordering race condition in the MotelyPaths static class by adding the volatile keyword to three static fields that store path override configurations. The fix ensures proper memory visibility when these fields are written during initialization and subsequently read by concurrent threads accessing path properties.

Changes:

  • Added volatile modifier to _jamlFiltersOverride, _seedSourcesOverride, and _searchResultsOverride static fields to ensure memory ordering consistency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +17
private static volatile string? _jamlFiltersOverride;
private static volatile string? _seedSourcesOverride;
private static volatile string? _searchResultsOverride;
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MotelyPaths class lacks test coverage for its initialization and thread-safety behavior. Consider adding tests to verify that the volatile fields are properly initialized and that concurrent access to path properties after initialization works correctly. This is especially important given that this PR addresses a memory ordering race condition.

Copilot uses AI. Check for mistakes.
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