Skip to content

Prototype crash-resilient TRX writes#10106

Closed
nohwnd wants to merge 6 commits into
mainfrom
nohwnd-trx-crash-prototype
Closed

Prototype crash-resilient TRX writes#10106
nohwnd wants to merge 6 commits into
mainfrom
nohwnd-trx-crash-prototype

Conversation

@nohwnd

@nohwnd nohwnd commented Jul 21, 2026

Copy link
Copy Markdown
Member

Related #10016

Wanted to implement both options and see what actually survives interrupted writes. Neither implementation is wired into production.

The padded file cannot provide the guarantee from the issue. Across 5,656 injected operation failures and byte cuts:

  • 4,545 were malformed
  • 719 were parseable but inconsistent
  • 22 were repairable
  • 370 were truthful

The append-only journal recovered a complete prefix in all 246 interruption cases, including restart and append after a torn final record. Publishing complete streamed snapshots through sibling-file replacement kept the destination old or new and truthful in all 3,519 observations.

For 10k synthetic results, journal plus snapshots did 10,004 flushes and wrote 18.3 MB. The padded writer did 89,959 flushes and wrote 24.6 MB. Replay keeps one record, no result collection, and no XDocument.

Changes

  • Add an isolated padded incremental writer with fixed pads, counters, running slots, reflow, and compaction.
  • Add an append-only journal with torn-tail recovery and streamed snapshot publication.
  • Add deterministic operation and partial-write injection, semantic TRX classification, concurrent-reader barriers, and real-file-system tests.
  • Cover CRLF preservation, UTF-8-safe truncation, long metadata, large output, summary data, startup overwrite, replacement sharing modes, and 10k-result diagnostics.

Verification

  • 148 focused tests passed across net462, net472, net8.0, and net9.0.
  • 3,432 extension unit tests passed, with 20 existing skips.
  • 20 Release diagnostics passed.
  • TRX acceptance passed: 40 MTP, 6 MSTest TRX, and 6 MSTest output tests.
  • Debug and Release builds, full repository build, and package production passed.

This does not claim XSD, Visual Studio, Azure DevOps, third-party reader, network filesystem, antivirus, physical power-loss, or actual attachment-copying compatibility. Atomic overwrite intentionally fails closed on .NET Framework where the same replacement guarantee is not available.

LMK if this should stay as evidence only, or if I should follow with the production journal and snapshot path.

🤖

nohwnd and others added 6 commits July 20, 2026 22:01
Add isolated padded in-place and journal plus snapshot writers without wiring the production lifecycle.

Run deterministic operation and byte-cut interruption matrices, concurrent readers, compatibility probes, and 10k diagnostics. The evidence disproves arbitrary-termination validity for padded mutation and supports append-only journal recovery plus atomic sibling snapshots.

Fix torn journal tails before resumed appends and keep prototype summary children in schema order.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🤖
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🤖
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🤖
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🤖
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🤖
Copilot AI review requested due to automatic review settings July 21, 2026 07:59

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

Prototypes and evaluates crash-resilient TRX persistence without integrating either approach into production.

Changes:

  • Adds padded incremental and journal/snapshot TRX prototypes.
  • Adds atomic file publication and fault-injection infrastructure.
  • Adds semantic, interruption, compatibility, and performance evidence tests.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Platform/Microsoft.Testing.Extensions.TrxReport/InternalAPI/InternalAPI.Unshipped.txt Tracks new internal APIs.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Streaming/Prototype/ITrxPrototypeFileOperations.cs Defines prototype file abstractions.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Streaming/Prototype/TrxIncrementalWriterPrototype.cs Implements padded incremental writes.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Streaming/Prototype/TrxJournalSnapshotPrototype.cs Implements journal replay and snapshots.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Streaming/Prototype/TrxPrototypeFileOperations.cs Provides real filesystem operations.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Streaming/Prototype/TrxPrototypeXmlRenderer.cs Renders prototype TRX XML.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Streaming/Prototype/TrxSnapshotPublisherPrototype.cs Publishes snapshots by sibling replacement.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Helpers/TrxDocumentClassifier.cs Classifies TRX consistency.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Helpers/TrxFaultInjectingFileOperations.cs Simulates filesystem faults.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Helpers/TrxPrototypeDiagnostics.cs Collects prototype metrics.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Helpers/TrxPrototypeScenarioFactory.cs Builds deterministic scenarios.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxCompatibilityEvidenceTests.cs Records compatibility boundaries.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxConcurrentReaderTests.cs Exercises concurrent readers.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxCrashConsistencyContractTests.cs Captures canonical TRX semantics.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxDocumentClassifierTests.cs Tests semantic classification.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxFaultInjectingFileOperationsTests.cs Tests fault simulation behavior.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxIncrementalWriterInterruptionTests.cs Sweeps padded-writer interruptions.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxIncrementalWriterPrototypeTests.cs Tests incremental rendering.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxJournalSnapshotPrototypeTests.cs Tests journal recovery and publication.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxPrototypeDiagnosticsTests.cs Verifies large-run diagnostics.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxPrototypeFileOperationsTests.cs Tests real file operations.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxPrototypeRealFileSystemTests.cs Exercises real replacement behavior.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxPrototypeWarningSuppressions.cs Suppresses prototype-test style warnings.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/TrxSnapshotPublisherPrototypeTests.cs Tests reflow and atomic publication.

Comment on lines +176 to +179
if (!_operations.Exists(_journalPath))
{
_journalTailValidated = true;
return;
Replay(
record =>
{
byte[] fragment = _renderer.RenderCompletedResult(record.Result, record.ExecutionId, _startTime);
$"Received two different test definition names ('{existingDefinitionName}' and '{definitionName}') for test id '{testId}'.");
}

byte[] resultBytes = _renderer.RenderCompletedResult(result, executionId, _startTime);
Comment on lines +244 to +247
bool addDefinition = !_definitionNames.TryGetValue(testId, out string? existingDefinitionName);
if (!addDefinition
&& result.TrxTestDefinitionName is not null
&& !string.Equals(existingDefinitionName, definitionName, StringComparison.Ordinal))
Comment on lines +333 to +334
byte[] summaryAdditions = _renderer.RenderSummaryAdditions(completion);
EnsureCapacity("summary", summaryAdditions.Length, _summaryBytesRemaining);
Comment on lines +584 to +585
ValidateOutput(actual, expected, i, errors);
ValidateRelativeOrder(actual, ["Output", "ResultFiles"], $"Result[{i}] child order", errors);
Assert.Contains(
observation => observation.Dimension == TrxPhase3EvidenceDimension.ByteCutFault
&& observation.WriteRole == role
&& observation.Cut == observation.RequestedBytes,
Assert.Contains(
observation => observation.Scenario == "startup-absent"
&& observation.Dimension == TrxPhase3EvidenceDimension.ByteCutFault
&& observation.Cut == observation.RequestedBytes
report.FaultObservations);
Assert.Contains(
observation => observation.WriteRole == TrxPhase3WriteRole.ResultTail
&& observation.Cut == observation.RequestedBytes
EnsureDeleteShareIsCompatible(source, temporaryPath);

long preLength = _files.TryGetValue(destinationPath, out VirtualFileEntry? destination)
? destination.Bytes.LongLength
Comment on lines +491 to +505
foreach (TrxFileOperationKind required in new[]
{
TrxFileOperationKind.Seek,
TrxFileOperationKind.Write,
TrxFileOperationKind.Flush,
})
{
if (baseline.Any(operation => operation.Kind == required))
{
Assert.AreEqual(
baseline.Count(operation => operation.Kind == required),
operationCases.Count(observation => observation.OperationKind == required),
$"{scenario}: {required}");
}
}
Comment on lines +850 to +852
_temporaryDirectory = System.IO.Path.Combine(
System.IO.Path.GetTempPath(),
$"trx-incremental-prototype-{Guid.NewGuid():N}");
$"trx-incremental-prototype-{Guid.NewGuid():N}");
Directory.CreateDirectory(_temporaryDirectory);
operations = new TrxPrototypeFileOperations();
Path = System.IO.Path.Combine(_temporaryDirectory, "results.trx");
{
string uniqueName = Guid.NewGuid().ToString("N");
Path = subdirectoryName is null
? System.IO.Path.Combine(System.IO.Path.GetTempPath(), uniqueName)
string uniqueName = Guid.NewGuid().ToString("N");
Path = subdirectoryName is null
? System.IO.Path.Combine(System.IO.Path.GetTempPath(), uniqueName)
: System.IO.Path.Combine(System.IO.Path.GetTempPath(), subdirectoryName, uniqueName);
Comment on lines +472 to +474
catch
{
}
@nohwnd

nohwnd commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

Closing the investigation after recording the findings and recommendation in #10016. The prototype disproved the padded writer guarantee and supports journal plus atomic snapshots instead. This branch remains available as evidence, but the prototype is intentionally not wired into production and is not intended for merge.

🤖

@nohwnd nohwnd closed this Jul 21, 2026
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