Skip to content

fix(hr): a re-observed up-to-date file must be a silent no-op (spec 055) - #23865

Merged
dr1rrb merged 4 commits into
masterfrom
dev/dr/hr-noop-pass-dedup
Jul 30, 2026
Merged

dr1rrb merged 4 commits into
masterfrom
dev/dr/hr-noop-pass-dedup

Conversation

@dr1rrb

@dr1rrb dr1rrb commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

GitHub Issue: closes #23862

PR Type:

🐞 Bugfix

What changed? 🚀

A trailing file-system event for a file the hot-reload pipeline wrote itself — the
per-request HotReloadInfo.g.cs, whose late IN_CLOSE_WRITE (Linux/inotify) arrives after
the 250 ms watcher buffer already closed — re-opened a watcher batch for content that was
already in the solution. That parasite pass forked the solution (a byte-identical
WithDocumentText still produces a new snapshot), emitted 0 updates, landed in the
blocked-compilation audit, and — when it merged into the originating request's still-open
operation — overwrote the real outcome (observed live: the request reported Failed
after its edits had applied successfully).

Fix — content-level no-op detection in SolutionUpdater. Before replacing a document's
text, the new on-disk content is compared with the current text (SourceText.ContentEquals,
documents and additional documents) and identical writes are skipped. Only realized
texts are compared, so a document that was never read is always applied (a first edit is
never swallowed). A fully-reduced batch returns the original Solution instance, so the
manager's reference-equality NoChanges short-circuit fires before the emit — no
metadata roundtrip, no audit, no spurious Failed. Skipped entries are surfaced on
SolutionUpdateResult.UpToDateChanges (consumed, not ignored) and reported by the manager.

The info file stays a first-class change: on the request's own batch its content genuinely
differs from the solution, so it is applied and emitted normally and the app's
HotReloadInfo.VersionId keeps bumping (spec 050 R6). The operation lifecycle, TryMerge,
and the merge-under-gate decision (8076b444aa) are untouched. No watcher-level trigger
exclusion — making a specific file "unable to open the update gate" is conceptually wrong
and cannot be made reliable (the file system is not transactional). Full reasoning and the
rejected alternatives are recorded in specs/055-hotreload-noop-pass-dedup/spec.md.

PR Checklist ✅

Copilot AI review requested due to automatic review settings July 23, 2026 16:53
@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 5m 58s —— View job


PR Review — specs/055-hotreload-noop-pass-dedup/spec.md

  • Gather context — read spec, HotReloadManager.cs, HotReloadOperation.cs, FileUpdater.cs, HotReloadTracker.cs, ISolutionUpdater.cs
  • Post inline findings (4 comments)
  • Post summary

Verdict: fix-first on 2 points, nit on 2

The core R1 rationale is correct and well-grounded: WithDocumentText with byte-identical content still produces a new snapshot (reference inequality), so the result.Solution == originalSolution shortcut is never reached for parasite passes. R1 closes this cleanly. The non-goals are well-scoped and R3 (info file exemption) is a natural consequence of the content-based approach.

4 inline findings posted:

# Severity Location Issue
1 Medium line 8 (Related links) Specs 053 and 054 don't exist in the repo; spec 054 is load-bearing (it is what turns the 0-update branch into Failed). Dependency order should be confirmed before implementation.
2 Medium lines 28-35 (Overview) The "overwrites the real outcome" claim is only accurate for the exception path in ProcessFileChanges (where the catch block completes O1 outside the gate). The normal path is already protected by the under-gate merge decision; a parasite pass there gets a fresh O2. The "Observed live" scenario should pin which path was observed.
3 Medium line 111 (Test plan #5) Test case 5 as written targets "same operation" but the gate-protected flow puts pass B on O2, not O1. The test should either drive the HotReloadOperation.Complete CAS directly (idempotency), or construct the exception-path scenario that actually reuses O1.
4 Minor line 53 (R1) SourceText.ContentEquals is O(n) on every call; SourceText.GetChecksum() caches the hash after first computation. The spec already mentions checksums as an alternative — suggest presenting checksum comparison as the primary path (with ContentEquals as the fallback) rather than the reverse.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Hot Reload design spec (spec 055) describing how to deduplicate trailing file-system watcher batches that produce no effective solution changes, and how to prevent such no-op passes from overwriting real operation outcomes.

Changes:

  • Introduces requirements for content-level no-op detection during solution updates (document + additional document text comparisons).
  • Specifies operation-lifecycle protections so vacuous continuation passes cannot degrade an already-determined outcome.
  • Defines a unit-test plan for the updater, manager short-circuiting, and merged-operation outcome preservation.

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

@dr1rrb dr1rrb changed the title fix(hr): ignore no-op watcher passes and protect operation outcomes (spec 055) fix(hr): a re-observed up-to-date file must be a silent no-op (spec 055) Jul 24, 2026
@dr1rrb
dr1rrb marked this pull request as ready for review July 24, 2026 01:49
Copilot AI review requested due to automatic review settings July 24, 2026 01:49
@dr1rrb
dr1rrb enabled auto-merge July 24, 2026 01:49
@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 5m 8s —— View job


PR Review — fix(hr): a re-observed up-to-date file must be a silent no-op

  • Gather context — read changed files
  • Review implementation code (SolutionUpdater.cs, SolutionUpdateResult.cs, ChangeSet.cs, HotReloadManager.cs)
  • Review test code (Given_SolutionUpdater.cs, Given_HotReloadManager.cs, test utilities)
  • Post inline findings (3 comments)
  • Post summary

Verdict: nit on 3 points

The core logic is correct and well-reasoned. The TryGetText + ContentEquals guard properly handles the unrealized-text boundary, the with-expression on IgnoredChanges correctly passes through unconsumed fields, and the UpToDateChanges property default (ChangeSet.Empty) keeps the manager safe against custom updaters that don't set it. The test coverage is thorough: it covers the no-op, the real-change path, the additional-document case, the mixed batch, the unrealized-text boundary, and the manager short-circuit.

3 inline findings:

# Severity Location Issue
1 Minor Given_SolutionUpdater.cs:16 (and all other [Description] attributes in that file + Given_HotReloadManager.cs:317) All descriptions reference "Spec 055 R2" for behaviour that is R1 in the spec (content-level no-op detection). R2 is "the info file stays a first-class change", which is not directly unit-tested. Systematic off-by-one impairs traceability as the spec evolves.
2 Minor SolutionUpdater.cs:37 <see cref="..."/> inside a plain // comment is not processed by the doc generator — it renders as literal XML markup to source readers.
3 Style HotReloadManager.cs:174 GetAllPaths().ToImmutableArray() is { IsEmpty: false } upToDate — the IsEmpty: false double-negation is uncommon. Two-liner (var upToDate = ...; if (!upToDate.IsEmpty)) is clearer and equivalent.

No functional or correctness issues found in the implementation.

@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 5m 12s —— View job


PR Review — fix(hr): a re-observed up-to-date file must be a silent no-op

  • Gather context — read changed files
  • Review implementation (SolutionUpdater.cs, SolutionUpdateResult.cs, ChangeSet.cs, HotReloadManager.cs)
  • Review tests (Given_SolutionUpdater.cs, Given_HotReloadManager.cs, TempDirectory.cs, RecordingReporter.cs)
  • Post inline findings
  • Post summary

Verdict: fix-first on 1 nit, comment on 2

The root fix is correct and well-contained. SolutionUpdater.UpdateAsync reads disk content first, then compares with the document's realized text via TryGetText + ContentEquals; unrealized documents fall through unconditionally (no false skips). A fully-reduced batch returns the original Solution instance, letting the manager's existing result.Solution == originalSolution → NoChanges short-circuit fire before the emitter and audit. The ChangeSet.Empty sentinel, UpToDateChanges property, and verbose-log reporting are all well-scoped.

3 inline findings posted — all nits/minor:

# Severity Location Issue
1 Nit SolutionUpdater.cs:158 ChangeSet.Empty with { ... } always creates a new record even when both builders are empty (common non-parasite path); a count guard preserves the existing default and skips the allocation.
2 Minor HotReloadManager.cs:174 GetAllPaths().ToImmutableArray() instantiates an enumerator + ImmutableArray on every hot-reload pass; a cheap IsEmpty pre-check on the struct fields avoids both in the fast path.
3 Nit Given_HotReloadManager.cs:333 UpToDateChanges = ChangeSet.IgnoreAll(["/work/Model.cs"]) uses the IgnoredFiles slot, which works but diverges from how production code populates UpToDateChanges (EditedDocuments/EditedAdditionalDocuments).

Cross-cutting observations:

  • specs/053 and specs/054 are still absent from the repo (flagged in the previous review cycle). If they're on other in-flight branches, fine; if they're expected to exist before implementation, they should land first.
  • ContentEquals (O(n) character scan) vs GetChecksum() (cached after first call) was previously noted on the spec. The implementation follows the spec's stated choice — the performance trade-off is a spec-level call, not a code-level defect.
  • Test coverage in Given_SolutionUpdater is thorough: realized-identical, realized-different, additional-document, mixed batch, and unrealized-text boundary cases are all covered. The manager test for the fully-reduced-batch short-circuit is well-structured.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread src/Uno.HotReload/HotReloadManager.cs Resolved
Comment thread src/Uno.HotReload/HotReloadManager.cs Resolved
Comment thread src/Uno.HotReload/HotReloadManager.cs Resolved
dr1rrb added a commit that referenced this pull request Jul 24, 2026
Spec (first review round):
- Replace dead links to specs 053/054 (absent from the repo) with the
  blocked-compilation audit issue #23861; drop the tangential 053 reference.
- Scope the "overwrites the real outcome" claim to the still-open window (the
  normal path is already guarded by the under-gate merge decision 8076b44,
  which routes a completed operation's parasite to a fresh operation).
- Document why ContentEquals is preferred over GetChecksum for this access
  pattern (fresh disk text carries no cached checksum; one comparison per pass).

Code (second review round):
- SolutionUpdater: keep UpToDateChanges as ChangeSet.Empty unless at least one
  entry was skipped, so the common path allocates no ChangeSet; plain-text doc
  reference in the // comment (a <see cref> there is not processed).
- HotReloadManager: guard the up-to-date verbose report on the cheap
  EditedDocuments/EditedAdditionalDocuments emptiness check, so the common path
  builds neither the GetAllPaths enumerator nor the ImmutableArray.
- TempDirectory: broaden the best-effort cleanup catch to UnauthorizedAccessException.
- Tests: correct the Spec 055 R2 -> R1 requirement labels; build UpToDateChanges
  via EditedDocuments (as the real updater does) rather than IgnoreAll.
Copilot AI review requested due to automatic review settings July 24, 2026 02:08
@github-actions

github-actions Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 2m 26s —— View job


PR Review — fix(hr): a re-observed up-to-date file must be a silent no-op

  • Read changed files (spec + implementation + tests)
  • Verify previous findings are addressed
  • Check for new issues
  • Post summary

Verdict: ship

All findings from the three prior review rounds are confirmed addressed in the current branch state (0ee1d938). No new issues found.

Prior findings — all resolved:

Round Finding Status
1 Dead links to specs 053/054 Removed; #23861 and spec 050 remain
1 "overwrites real outcome" claim too broad Overview now precisely scopes to the exception-path / still-open-operation window
1 Test plan inconsistent with gate-flow Test plan rewritten around content-level no-op; spec status updated to Resolved
1 ContentEquals vs GetChecksum trade-off undocumented Rationale added to spec (lines 54–61)
2 [Description] attributes cited R2 for R1 behaviour Fixed across all 5 Given_SolutionUpdater methods and the manager test
2 <see cref> in plain // comment Replaced with plain-text reference
2 IsEmpty: false double-negation Replaced with clean struct-field emptiness guard
3 UpToDateChanges allocated on every pass Guarded: ChangeSet.Empty returned when no entries skipped
3 Unconditional GetAllPaths().ToImmutableArray() Guarded on EditedDocuments/EditedAdditionalDocuments emptiness check
3 TempDirectory.Dispose caught only IOException Now catches IOException or UnauthorizedAccessException
3 Manager test used IgnoredFiles slot Fixed: test populates EditedDocuments to match how the real updater reports up-to-date entries

Implementation quality notes (no action needed):

  • TryGetText + ContentEquals guard is correctly ordered: the file is always read (needed for the WithDocumentText call on change/unrealized paths), and only the identical-content case bears the unnecessary I/O cost — the accepted trade-off for simpler code (the spec explains the ContentEquals reasoning at lines 54–61).
  • UpToDateChanges documents in SolutionUpdater are from the original solution snapshot; the manager only consumes their FilePath via GetAllPaths(), so snapshot provenance doesn't matter downstream.
  • Test harness in When_FullyReducedBatch_Then_NoChangesWithoutEmitNorAudit builds the upToDate Document from a forked snapshot (not what's returned), but the comment explains this and the assertion only checks the file path — correct for the test's purpose.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@unodevops

Copy link
Copy Markdown
Contributor

@autocarl autocarl 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.

Static review of the current head. The content comparison and snapshot preservation are sound, and the hosted CI failure is an unrelated iOS worker timeout. However, the new up-to-date signal does not yet prevent the outcome race that motivates the PR, so I cannot approve this head.

Comment thread src/Uno.HotReload/HotReloadManager.cs Resolved
Copilot AI review requested due to automatic review settings July 27, 2026 15:59
@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 4m 50s —— View job


PR Review — fix(hr): complete the hot-reload operation under the update gate (spec 055)

  • Gather context — read changed files (latest commit 2c9d392d)
  • Review gate-completion fix in HotReloadManager.cs
  • Review spec and test changes
  • Post inline findings (2 comments)
  • Post summary

Verdict: ship (2 nits)

Gate fix (2c9d392d) — correct. Moving _solutionUpdateGate.LockAsync from inside the try to before it ensures that Complete(InternalError) in the catch runs under the gate. The invariant "an operation is completed by the pass that processes it, under the gate" now holds for both the success path (no change from before) and the exception path (the fix). A queued pass B that acquires the gate after the exception sees _result != -1 on TryMerge and starts a fresh operation — the race autocarl described is closed.

Content-level no-op (R1) — correct and unchanged since the ship verdict in the previous round. TryGetText + ContentEquals guard is sound; the unrealized-text bypass is correct; the ChangeSet.Empty allocation guard is in place; test coverage is thorough.

2 nits posted inline:

# Severity Location Issue
1 Nit HotReloadManager.cs:138 No targeted test for the exception-path gate race. When_BatchMergedIntoCompletedOperation_Then_ItsResultIsTracked covers the normal-path only; a throw-while-queued scenario would directly verify the new invariant.
2 Nit spec.md:95 Non-goal bullet "operation lifecycle untouched" is now stale — the gate scope was widened in 2c9d392d.

No functional or correctness issues found in any changed file.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/Uno.HotReload/Diffing/SolutionUpdater.cs:52

  • Pre-size the additional-document builder to avoid internal growth allocations when many additional files are edited in a batch.
		var upToDateAdditionalDocuments = ImmutableArray.CreateBuilder<TextDocument>();

Comment thread src/Uno.HotReload/HotReloadManager.cs Resolved
@unodevops

Copy link
Copy Markdown
Contributor

@carldebilly carldebilly left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@mergify

mergify Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

dr1rrb added 4 commits July 28, 2026 13:40
…il operations

Trailing file-system events can re-open a watcher batch for files whose content
is already in the solution: the pass forks the solution anyway (identical text
still produces a new snapshot), emits 0 updates, lands in the blocked-
compilation audit, and - when it merged into the originating request's still-
open operation - overwrites the real outcome (observed: request reported Failed
after its edits applied successfully). Spec: content-level no-op detection in
the solution updater (SourceText.ContentEquals, docs + additional docs,
reference-equal solution when fully reduced), and lifecycle protection so a
vacuous continuation never degrades a substantive outcome. The info file stays
a first-class change (content-based dedup only).
FileUpdater writes a request's edits AND its per-request hot-reload info file
(HotReloadInfo.g.cs) under the BufferGate, so they flush as one batch. But the
file system is not transactional: a single write emits several inotify events
(IN_MODIFY, IN_CLOSE_WRITE) and WaitForFileUpdated only syncs on the first. A
trailing event - typically the close-write for a file the pipeline just wrote
itself, delivered after the 250 ms buffer closed (observed on Linux/inotify
during a long first pass) - opened a NEW watcher batch for a file whose on-disk
content was already in the solution. That parasite pass forked the solution
(byte-identical WithDocumentText still creates a snapshot), emitted 0 updates,
landed in the blocked-compilation audit, and - when merged into a still-open
operation - overwrote the real outcome (observed: request reported Failed after
its edits applied successfully).

Fix (spec 055): content-level no-op detection in SolutionUpdater. Before
replacing a document's text, compare the new on-disk content with the current
text (SourceText.ContentEquals, documents + additional documents) and skip
identical writes. Only realized texts are compared, so a never-read document is
always applied (never swallow a first edit). A fully-reduced batch returns the
original solution instance, so the manager's reference-equality NoChanges
short-circuit fires BEFORE the emit: no metadata roundtrip, no audit, no Failed.
Skipped entries are surfaced on SolutionUpdateResult.UpToDateChanges (consumed,
not ignored) and reported by the manager with a verbose line.

The info file stays a first-class change: its content genuinely changes per
request, so on the request's own batch it differs from the solution and is
applied/emitted normally (VersionId keeps bumping - spec 050 R6). The dedup is
strictly content-based; only byte-identical re-observations are suppressed.

No watcher-level trigger exclusion: making a specific file unable to open the
update gate is conceptually wrong and cannot be made reliable (the file system
is not transactional). The operation lifecycle, TryMerge and the merge-under-gate
decision (8076b44) are untouched.
Spec (first review round):
- Replace dead links to specs 053/054 (absent from the repo) with the
  blocked-compilation audit issue #23861; drop the tangential 053 reference.
- Scope the "overwrites the real outcome" claim to the still-open window (the
  normal path is already guarded by the under-gate merge decision 8076b44,
  which routes a completed operation's parasite to a fresh operation).
- Document why ContentEquals is preferred over GetChecksum for this access
  pattern (fresh disk text carries no cached checksum; one comparison per pass).

Code (second review round):
- SolutionUpdater: keep UpToDateChanges as ChangeSet.Empty unless at least one
  entry was skipped, so the common path allocates no ChangeSet; plain-text doc
  reference in the // comment (a <see cref> there is not processed).
- HotReloadManager: guard the up-to-date verbose report on the cheap
  EditedDocuments/EditedAdditionalDocuments emptiness check, so the common path
  builds neither the GetAllPaths enumerator nor the ImmutableArray.
- TempDirectory: broaden the best-effort cleanup catch to UnauthorizedAccessException.
- Tests: correct the Spec 055 R2 -> R1 requirement labels; build UpToDateChanges
  via EditedDocuments (as the real updater does) rather than IgnoreAll.
…c 055)

ProcessFileChanges acquired the solution-update gate inside the try, so on the
failure path the `using` released it as the exception unwound — before the catch
completed the operation as InternalError. In that window a queued batch could
acquire the gate, merge into the still-open operation (TryMerge sees _result ==
-1) and complete it first (e.g. as a content-no-op NoChanges), dropping this
pass's real outcome and reporting a failed pass as a clean reload.

Hold the gate across the whole pass, including the catch, so the completion —
terminal outcome on success, or InternalError on failure — always happens under
the gate. A queued batch then only runs after this operation is completed, so its
TryMerge starts a fresh operation instead of overwriting this one. Ownership is
enforced by the gate; no separate completion-ownership guard is needed.

Also: TempDirectory.WriteFileAsync (test helper) rejects a rooted relativePath
before Path.Combine, so a rooted value cannot silently drop the temp root.
Copilot AI review requested due to automatic review settings July 28, 2026 20:50
@dr1rrb
dr1rrb force-pushed the dev/dr/hr-noop-pass-dedup branch from 2c9d392 to 2d8bfc2 Compare July 28, 2026 20:50
@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 1s —— View job


I'll analyze this and get back to you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/Uno.HotReload.Tests/Given_HotReloadManager.cs:483

  • The test builds upToDateDoc by calling solution.AddDocument(...) but then returns the original solution instance. That means UpToDateChanges contains a Document that does not belong to result.Solution (and holds onto an extra solution snapshot), which is confusing and could break if production code later assumes those documents are from the returned solution. Since the manager only needs paths for diagnostic logging here, consider populating UpToDateChanges.IgnoredFiles with the up-to-date path instead of manufacturing a Document from a different snapshot.
				// Mirror the real updater: up-to-date entries are surfaced via EditedDocuments (with
				// their file path), never IgnoredFiles. Build a document to reference but return the
				// original solution unchanged, so the reference-equality NoChanges short-circuit fires.
				var docId = DocumentId.CreateNewId(solution.ProjectIds[0]);
				var upToDateDoc = solution
					.AddDocument(docId, "Model.cs", "class Model { }", filePath: "/work/Model.cs")
					.GetDocument(docId)!;
				return new SolutionUpdateResult(solution, ChangeSet.IgnoreAll([]))
				{
					UpToDateChanges = ChangeSet.Empty with { EditedDocuments = [upToDateDoc] },
				};

@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 224607 has failed on Uno.UI - CI.

@dr1rrb
dr1rrb merged commit 4d1a183 into master Jul 30, 2026
53 of 54 checks passed
@dr1rrb
dr1rrb deleted the dev/dr/hr-noop-pass-dedup branch July 30, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HR] Trailing watcher events create no-op passes that can overwrite a request outcome

6 participants