Repository navigation
fix(plc): pause writes until the comparison decides - #247
Merged
Merged
Conversation
Sync wrote the screen recipe to the PLC before the reconnect comparison read the PLC recipe (#181). An edit after a link drop started the 1 s debounce, and a reconnect inside it wrote that edit over a recipe the comparison had not seen yet. The same happened to an edit made while sync on was still connecting. A failed comparison read also wrote the screen recipe, a conflict dialog closed without a choice left sync on for the next edit to overwrite the PLC, an answer from before a link drop still acted, and a version mismatch on reconnect disconnected from inside the comparison, waiting on the reconnect loop, and turned sync off without a message. PlcSyncCoordinator now holds a write pause. Sync on and a link loss start it and drop a debounced write; a write already in flight ends as before. Edits during the pause stay on screen and are kept, and no debounce, run end or finished write starts a new write while it holds. PlcLifecycleManager gives each comparison an ID, which a link drop, a newer comparison or sync off makes stale. Each current outcome ends the pause in one step with the ID check: identical, PLC empty or not committed end it with a write of the newest screen recipe, a conflict keeps it, a take ends it without a write. Stale results and answers change nothing. A failed, deadline-passed or throwing comparison read closes the client and declares link loss through IS7Connection.DeclareLinkLost, so the reconnect loop compares again. A comparison cut by a link drop counts as failed too, so the count does not depend on whether the drop or the failed read arrives first. Three in a row turn sync off. A version mismatch on reconnect turns sync off with the version message. The first-connect comparison runs after EnableSync's version read and skips its own, so a mismatched PLC is never compared or written. The conflict answers carry the comparison ID. Closing the dialog without a choice (X, Esc, Alt+F4; Esc gets a handler) or a dialog that cannot be shown turns sync off, and so does a PLC recipe that fails the take check, in the dialog or on the reconnect take. Sync on and off run one at a time behind one gate, and a comparison starts only while the sync-on flag, kept under the comparison lock, is set. The app posts its turn-offs so the comparison and the reconnect loop never wait on them; each is checked again when it runs and does nothing after sync off, in a newer sync-on period, or for the failure cap once a later comparison decided. The switch acts in the direction it showed at the press, so a press during an app turn-off cannot turn sync back on. A conflict handler that throws, or a take that throws, also ends the conflict with sync off instead of holding the pause with no dialog. The reconnect take checks again on the UI thread that the screen recipe is empty and saved; an Open that landed during the read gets the conflict instead. Each turn-off reason reaches the notification panel as a typed error on PlcLifecycleManager.SyncTurnOffs and stays there through edits until sync is turned on again. PlcLifecycleManager is now a facade over PlcSyncSwitch, PlcComparisonState, PlcReconnectComparison, PlcConflictNotifier, PlcReconnectTake and PlcComparisonAnswers. S7Service.DeclareLinkLost marks the link lost before it closes the client, so the close cannot hit a link the reconnect loop opened. Closes #181 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
With sync on, the app could write the local recipe to the PLC before the reconnect comparison read the PLC recipe (#181):
EnableSyncturned sync on before it connected, so an edit during the connect, or a link that came back inside the 1 s debounce, wrote first and the conflict was never seen. A failed read during the comparison also wrote the local recipe. Closing the conflict dialog without a choice left sync on, so the next edit overwrote the PLC recipe. A write could slip out between the app finding a conflict and the operator answering it. A version check that failed on reconnect only logged. The sync switch read its direction when the command ran, not at the press.What changed
PlcSyncCoordinatorowns the pause.PlcConflictDialoghandles Esc.PlcLifecycleManageris split intoPlcSyncSwitch,PlcComparisonState,PlcReconnectComparison,PlcComparisonAnswers,PlcConflictNotifierandPlcReconnectTake.docs/readme.md(sync, conflict, notifications),dialogs-and-interactions.md,error-reporting.md,exit-flow.md, and the plan's Behavior line on the notification.This is Task 3b of
docs/plans/20261130-recipe-replace-save-exit-safety.md.Verification
dotnet format --verify-no-changesclean.Closes #181
🤖 Generated with Claude Code