Repository navigation
Retry the settings file replace when it is briefly locked - #47
Merged
Merged
Conversation
Saving settings replaces settings.json via a temp file; on Windows the replace fails if another process (antivirus, indexer, OneDrive, or a test poll) holds the file open, which showed a spurious save-failure error. Retry the replace up to 8 times (<= 900 ms) on sharing/lock violations only; other failures surface as before. UI tests now read settings.json without blocking the app's save. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by an active traceability issue: the new SettingsStoreLockTests.cs file is missing from the unit’s SysML2 SoftwareInfo.testFiles metadata.
1 open issue
What changed in this PR
This PR makes SettingsStore resilient to brief Windows file-sharing and lock violations during atomic settings replacement, preventing transient save failures in the application and UI tests.
Changes:
- Adds bounded retry and backoff handling for transient replace failures, including load-time repository-order write-back.
- Adds deterministic unit coverage for retry behavior, non-transient failures, cleanup, and real locked-file scenarios.
- Updates UI-test file reads, requirements, design and verification documentation, and review tracking.
| File | Description |
|---|---|
| test/DemaConsulting.AgentControl.UiTests/ShellSettingTests.cs | Uses shared-delete settings-file reads during UI-test polling. |
| test/DemaConsulting.AgentControl.UiTests/SharedFile.cs | Adds shared file-reading helpers that permit concurrent writes, replacement, and deletion. |
| test/DemaConsulting.AgentControl.UiTests/RepoOrderTests.cs | Uses shared file reads for persisted repository-order assertions. |
| test/DemaConsulting.AgentControl.UiTests/RepoGroupsAndColorsTests.cs | Uses shared file reads for settings assertions. |
| test/DemaConsulting.AgentControl.UiTests/RepoCardFeatureTests.cs | Uses shared file reads during settings polling. |
| test/DemaConsulting.AgentControl.UiTests/RememberedSignInTests.cs | Allows deletion sharing while reading persisted text files. |
| test/DemaConsulting.AgentControl.UiTests/PackageSourcesTests.cs | Uses shared file reads for persisted package-source assertions. |
| test/DemaConsulting.AgentControl.UiTests/NuGetServerSourceTests.cs | Allows deletion sharing while reading persisted text files. |
| test/DemaConsulting.AgentControl.UiTests/GitSourceTests.cs | Uses shared file reads for persisted Git-source assertions. |
| test/DemaConsulting.AgentControl.UiTests/AppearanceTests.cs | Uses shared file reads for settings polling. |
| test/DemaConsulting.AgentControl.Tests/Settings/SettingsStoreLockTests.cs | Adds unit coverage for transient locks, retry bounds, cleanup, non-transient failures, real file locks, and load-time write-back. |
| src/DemaConsulting.AgentControl/Settings/SettingsStore.cs | Implements bounded replacement retries and injectable replacement and delay operations. |
| docs/verification/agent-control/settings/settings-store.md | Documents verification scenarios for locked-file tolerance and retry behavior. |
| docs/verification/agent-control/settings.md | Links the locked-file tolerance requirement to subsystem verification. |
| docs/reqstream/agent-control/settings/settings-store.yaml | Defines the locked-file tolerance requirement and associated tests. |
| docs/reqstream/agent-control/settings.yaml | Links the new locked-file tolerance requirement to the settings subsystem. |
| docs/design/agent-control/settings/settings-store.md | Documents the replacement retry policy, behavior, dependencies, and error handling. |
| docs/design/agent-control/settings.md | Adds locked-file tolerance to the settings subsystem contract. |
| .reviewmark.yaml | Registers the new settings lock test file for review tracking. |
Review effort: Lite
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Approval should be deferred because the fix relies on Windows-specific file-sharing and atomic-replace semantics, while the FlaUI UI tests were not run locally and CI or human validation is still needed to confirm replace behavior and polling races.
No open issues 🎉
1 resolved since last review
Review effort: Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Pull Request
Description
Fixes spurious "settings could not be saved" errors when another process briefly has
settings.jsonopen.SettingsStoresaves by writing a temporary file and then replacingsettings.jsonwith it. On Windows that replace fails with a sharing violation whenever any process has the file open without delete sharing. That process could be antivirus, the Windows Search indexer, OneDrive, or in CI the UI test's own polling read. When the replace failed, the user saw an error box and the change was not saved. This caused the UI-test failure in the first release attempt (RepoGroupsAndColorsTests.CardMenu_CardColor_PaletteOffersEveryColorAndAutomaticClearsTheChoice).SettingsStore.Saveand the load-time card-order write-back now retry the replace.UnauthorizedAccessExceptionandIOExceptionwith a sharing or lock violation (Win32 error 32 or 33) are retried.SettingsStoreLockTests, which inject the replace and delay operations, plus a test that holds the real file open and releases the lock deterministically.settings.jsonwithFileShare.ReadWrite | FileShare.Delete, so they no longer block the app's save.AgentControl-SettingsStore-LockedFileTolerance, plus design and verification updates, and a.reviewmark.yamlentry for the new test file.Type of Change
Related Issues
None. The failure was found in release run 43712100941, attempt 1.
Pre-Submission Checklist
Build and Test
pwsh ./build.ps1. Not run as a single command, because it drives the desktop. Its parts were run separately:dotnet build(Debug): passed.dotnet test test/DemaConsulting.AgentControl.Tests: passed, 2487 passed, 0 failed, 42 skipped (environment-gated).Code Quality
Quality Checks
pwsh ./lint.ps1passed.Testing
Documentation
docs/reqstream/are updated, andreqstream --lint --enforceis clean.Additional Notes
The retry is bounded and on the UI thread, so a file held locked for more than about 1 s still produces the existing save-failure message.