Skip to content

Retry the settings file replace when it is briefly locked - #47

Merged
Malcolmnixon merged 2 commits into
mainfrom
settings-save-retry
Nov 15, 2026
Merged

Malcolmnixon merged 2 commits into
mainfrom
settings-save-retry

Conversation

@Malcolmnixon

Copy link
Copy Markdown
Member

Pull Request

Description

Fixes spurious "settings could not be saved" errors when another process briefly has settings.json open.

SettingsStore saves by writing a temporary file and then replacing settings.json with 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).

  • Product: SettingsStore.Save and the load-time card-order write-back now retry the replace.
    • Up to 8 attempts, backing off 20/40/80/160/200/200/200 ms. That is at most 900 ms, because saves run on the UI thread.
    • Only UnauthorizedAccessException and IOException with a sharing or lock violation (Win32 error 32 or 33) are retried.
    • Other failures, and a lock that outlasts the retries, surface exactly as before.
  • Tests:
    • New SettingsStoreLockTests, which inject the replace and delay operations, plus a test that holds the real file open and releases the lock deterministically.
    • UI tests now read settings.json with FileShare.ReadWrite | FileShare.Delete, so they no longer block the app's save.
  • Docs: new requirement AgentControl-SettingsStore-LockedFileTolerance, plus design and verification updates, and a .reviewmark.yaml entry for the new test file.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Related Issues

None. The failure was found in release run 43712100941, attempt 1.

Pre-Submission Checklist

Build and Test

  • Code builds successfully and all tests pass: pwsh ./build.ps1. Not run as a single command, because it drives the desktop. Its parts were run separately:
    • Solution dotnet build (Debug): passed.
    • dotnet test test/DemaConsulting.AgentControl.Tests: passed, 2487 passed, 0 failed, 42 skipped (environment-gated).
    • FlaUI UI tests: not run locally. CI runs them on this PR.
  • Code produces zero warnings

Code Quality

  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

  • All linters pass: pwsh ./lint.ps1 passed.

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable). Not applicable.
  • Updated docs/ documentation (if applicable)
  • Added code examples for new features (if applicable). Not applicable.
  • Updated requirements.yaml (if applicable). The requirements under docs/reqstream/ are updated, and reqstream --lint --enforce is 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.

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>
Copilot AI lite review requested due to automatic review settings November 15, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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>
Copilot AI lite review requested due to automatic review settings November 15, 2026 13:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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

@Malcolmnixon
Malcolmnixon merged commit 618ea13 into main Nov 15, 2026
8 checks passed
@Malcolmnixon
Malcolmnixon deleted the settings-save-retry branch November 15, 2026 13:52
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.

2 participants