Skip to content

fix(sync): write trust.json before adopting the change in memory - #331

Merged
DeepDiver1975 merged 1 commit into
mainfrom
fix/trust-store-write-order
Sep 15, 2026
Merged

DeepDiver1975 merged 1 commit into
mainfrom
fix/trust-store-write-order

Conversation

@DeepDiver1975

Copy link
Copy Markdown
Contributor

Summary

Two more items off the #302 checklist, both in LageBuch.Sync.

JsonTrustStore.Persist() mutated memory before the disk write. SaveThumbprint and
RemoveThumbprint updated _cache and then wrote, so a write that threw (full disk,
permissions, an AV lock on Windows) left the running app trusting a certificate trust.json does
not record. That divergence lasts for the rest of the process, and it is user-visible: the next
start reads the file back and re-prompts for a host this session had silently accepted.

The candidate dictionary is now built off to the side, written, and only adopted once the write
lands — a failed write changes nothing at all.

While confirming that, a second bug fell out: RemoveThumbprint consumed Dictionary.Remove's
return value before persisting, so after a failed write the entry was already gone from memory
and a retry saw false and skipped the write entirely — leaving the thumbprint on disk forever.
Removing from the candidate instead fixes that, and the second test covers it.

The duplicated comment block above OnSnapshot in RemoteIncidentSession.cs is gone.

Both new tests were confirmed to fail against main and pass with the fix.

Changes

  • JsonTrustStore: build → persist → adopt, all still under _gate; Persist takes the
    dictionary to write rather than reading the field
  • RemoteIncidentSession: drop the verbatim-duplicated three-line comment
  • Two tests in JsonTrustStoreTests: a failed SaveThumbprint leaves memory agreeing with disk;
    a failed RemoveThumbprint leaves the thumbprint trusted and a retry still does the work
  • Changelog entry under Fixed

Checklist

  • Commits follow Conventional Commits and are DCO signed off (git commit -s)
  • dotnet build and dotnet test pass locally (make ci, all eight projects)
  • UI changes include before/after screenshots — n/a, no UI change
  • No real master data / personnel data committed

Part of #302.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YavFrkz1GFaMNXbHQKsMyf

SaveThumbprint and RemoveThumbprint mutated _cache and then called
Persist(), so a write that threw (full disk, permissions, an AV lock on
Windows) left this instance trusting a certificate trust.json does not
record. The divergence survives for the rest of the process and it
matters: the next start reads the file back and re-prompts for a host the
session had silently accepted.

Build the candidate dictionary off to the side, write it, and only then
adopt it -- a failed write now changes nothing at all.

RemoveThumbprint additionally consumed Dictionary.Remove's return value
before persisting, so after a failed write the entry was already gone from
memory and a retry saw false and skipped the write entirely, leaving the
thumbprint on disk forever. Removing from the candidate fixes that too.

Also drop a three-line comment block above OnSnapshot in
RemoteIncidentSession that was duplicated verbatim.

Part of #302.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YavFrkz1GFaMNXbHQKsMyf
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
@DeepDiver1975
DeepDiver1975 force-pushed the fix/trust-store-write-order branch from e36aac8 to 37b03f5 Compare September 15, 2026 20:15
@DeepDiver1975
DeepDiver1975 merged commit 99ee2e9 into main Sep 15, 2026
3 checks passed
@DeepDiver1975
DeepDiver1975 deleted the fix/trust-store-write-order branch September 15, 2026 20:50
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.

1 participant