Make fetched-content filenames collision-proof - #2018
Merged
Conversation
WebFetchTool built each saved-content filename from a second-precision timestamp only. Two fetches of the same URL inside one second built the same filename. File.WriteAllBytes and File.WriteAllText both truncate an existing file, so the second fetch overwrote the first one with no error and no warning. Add a short random suffix to the filename. Keep the timestamp for a human to read. The random suffix gives real uniqueness, matching the pattern in WebhookExecutionService (a guid segment on the actor name). This bug is a sibling of the reminder execution child-name collision fixed in 30ff5d2: a millisecond timestamp collided when two fires landed inside one tick. Add a regression test with a frozen clock. Two fetches of the same URL at the same frozen second now produce two distinct files, and both keep their own content on disk.
Aaronontheweb
enabled auto-merge (squash)
August 19, 2026 19:40
Comment on lines
+804
to
+807
| var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK) | ||
| { | ||
| Content = content | ||
| }; |
The guid suffix owns uniqueness. The timestamp's only job is human readability and name-sort order, and at second precision two fetches in the same second sort by random guid instead of fetch order.
Merged
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.
Bug
WebFetchTool built the saved-content filename from a second-precision
timestamp only (
WebFetchTool.cs:269). Two fetches of the same URLinside one second built the same filename.
File.WriteAllBytesandFile.WriteAllTextboth truncate an existingfile. The second fetch overwrote the first one, silently, with no
error or warning. The first fetch's content was gone, and the tool
result for the first fetch still pointed to a path that now held the
second fetch's content.
This is a sibling of the reminder execution child-name collision fixed
in 30ff5d2 ("Name reminder execution children by sequence, not by
millisecond"): a timestamp collided when two events landed inside one
tick, only there the actor name collision threw, so the bug surfaced
as a crash. Here it fails silently as data loss, which is worse.
Fix
Add a short random suffix (first 8 hex characters of a guid) to the
saved-content filename. Keep the second-precision timestamp for a
human reading the filename. This matches the established pattern in
WebhookExecutionService.cs:42, which appends a full guid segment tothe actor name for the same reason.
Test
Added
ExecuteAsync_same_url_same_frozen_second_saves_two_distinct_filesto
WebFetchToolTests. It freezes the clock at one second withFakeTimeProviderand fetches the same URL twice. Before the fix thisproduces one file on disk with only the second fetch's content; after
the fix it produces two distinct files, each holding its own fetch's
content. No sleeps, no bounded waits — the clock is frozen
deterministically.
Validation
dotnet build --nologo -v q— 0 warnings, 0 errorsdotnet test src/Netclaw.Actors.Tests --no-build --nologo --filter "FullyQualifiedName~WebFetchTool"— 70 passed, 0 faileddotnet slopwatch analyze— 0 issuespwsh -NoProfile -File ./scripts/Add-FileHeaders.ps1 -Verify— all files have headers