Skip to content

Publish Azure DevOps retry attempts as sub-results - #10431

Merged
Amaury Levé (Evangelink) merged 25 commits into
mainfrom
dev/amauryleve/azdo-rerun-subresults
Aug 4, 2026
Merged

Amaury Levé (Evangelink) merged 25 commits into
mainfrom
dev/amauryleve/azdo-rerun-subresults

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

  • publish the first execution of a test as a normal Azure DevOps result and persist its assigned result id
  • publish later retry attempts by PATCHing that result with resultGroupType: "rerun" and accumulated subResults
  • use the latest attempt as the parent outcome while retaining earlier failures as sub-results
  • coordinate result ids across retry-host processes with a run-scoped, atomically written map
  • fall back to separate result creation whenever ids or safe persisted state are unavailable, so results are never dropped
  • keep retry attachments on the parent result with attempt-qualified names

Coordination and compatibility

The retry orchestrator gives each attempt a separate results directory, so it publishes a shared map path through a new build-scoped environment-variable handoff. This is intentionally separate from the existing run-id handoff so older processes continue to parse and honor the one-run-per-build contract from #10375.

The map is scoped by a random orchestration id and validates both build id and run id. Before PATCHing an existing result, the persisted map is invalidated; if that cannot be done safely, publishing degrades to a separate POST rather than risking stale history replacing an accepted attempt.

Validation

  • full Debug solution build
  • Microsoft.Testing.Extensions.UnitTests: 928 passed, 0 failed, 6 skipped
  • Microsoft.Testing.Platform.UnitTests: 2024 passed, 0 failed
  • four independent code-review rounds; all actionable findings addressed

Closes #10400

Copilot AI balanced review requested due to automatic review settings August 4, 2026 09:41

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 Azure DevOps rerun publishing so retry attempts become sub-results of one test result.

Changes:

  • Persists result IDs across retry processes and PATCHes subsequent attempts.
  • Preserves latest outcomes, attempt history, and qualified attachments.
  • Adds diagnostics, API tracking, localization metadata, and tests.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/AzureDevOpsLivePublishingTests.cs Tests reruns, persistence, fallbacks, and payloads.
Resources/xlf/AzureDevOpsResources.zh-Hant.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.zh-Hans.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.tr.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.ru.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.pt-BR.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.pl.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.ko.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.ja.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.it.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.fr.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.es.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.de.xlf Adds localization unit.
Resources/xlf/AzureDevOpsResources.cs.xlf Adds localization unit.
Resources/AzureDevOpsResources.resx Adds map-read failure diagnostic.
InternalAPI/InternalAPI.Unshipped.txt Tracks new internal API surface.
IAzureDevOpsTestResultsClient.cs Adds result-update contract.
AzureDevOpsTestRunOrchestratorLifetime.cs Publishes and cleans up the shared map path.
AzureDevOpsTestResultsPublisher.Flush.cs Splits result creation and rerun updates.
AzureDevOpsTestResultsPublisher.cs Loads and saves result mappings.
AzureDevOpsTestResultsClient.cs Sends PATCH requests for results.
AzureDevOpsResultIdStore.cs Implements persisted attempt history.
AzureDevOpsLivePublishingModels.cs Adds rerun and sub-result models.
AzureDevOpsConstants.cs Adds map-path environment handoff.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:271

  • Only the key fields are validated even though the map is treated as untrusted. A missing/empty attempts array makes the next PATCH replace the earlier failure with only the current attempt; malformed entries (for example null sub-results or invalid outcomes/sequence IDs) instead make Azure DevOps reject every retry until the current result is dropped. Validate the complete attempt history and treat any invalid entry as unseen so the safe POST fallback is used.
                // Entries come from disk, so nothing about them is guaranteed however the record is
                // annotated: a truncated or hand-edited file can yield nulls and non-positive ids.
                if (entry is { Id: > 0, Storage: { Length: > 0 } storage, Name: { Length: > 0 } name })
                {
                    _results[CreateKey(storage, name)] = new AzureDevOpsPublishedResult(storage, name, entry.Id, entry.Attempts ?? []);
  • Files reviewed: 24/24 changed files
  • Comments generated: 3
  • Review effort level: Balanced

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Evangelink Amaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Aug 4, 2026
@Evangelink
Amaury Levé (Evangelink) enabled auto-merge (squash) August 4, 2026 10:07
Copilot AI review requested due to automatic review settings August 4, 2026 10:12

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.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:212

  • This does not provide the PR's claimed atomic map replacement on all supported targets. For the extension's netstandard2.0/.NET Framework path, SystemFileSystem.MoveFile(..., overwrite: true) is implemented as File.Copy followed by File.Delete (SystemFileSystem.cs:17-21), so interruption can tear the destination map. Add an atomic replace primitive (for example, replace when the destination exists and rename when it does not) rather than relying on this abstraction's non-atomic overwrite implementation.
            _fileSystem.MoveFile(temporaryFilePath, _filePath, overwrite: true);
  • Files reviewed: 24/24 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings August 4, 2026 10:16

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.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:212

  • This replacement is not atomic on supported netstandard2.0 and .NET Framework builds: SystemFileSystem.MoveFile(..., overwrite: true) uses File.Copy followed by File.Delete (SystemFileSystem.cs:15-20). An interruption can therefore destroy the previous valid map during a create-only save, contrary to the PR's atomic-write guarantee, and the next retry degrades to duplicate results. Add an atomic replace operation to IFileSystem and use it here.
            _fileSystem.MoveFile(temporaryFilePath, _filePath, overwrite: true);
  • Files reviewed: 24/24 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings August 4, 2026 10:25

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.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:168

  • A failed/ambiguous PATCH can still cause the deleted map to be recreated with stale history. If this session already accepted a creation or an earlier update, the store is dirty; finalization then saves every loaded entry, including this failed batch's old attempts. When Azure DevOps accepted the PATCH before the transport failure, the next attempt can PATCH from that stale history and erase the accepted attempt. Mark the store non-persistable (or remove the affected entries) when an update ultimately fails, so SaveAsync cannot restore the invalidated state; this needs a mixed- or multi-batch regression test.
                else if (updates.Count > 0 && !await TryUpdateResultsAsync(updates, deferredAttachments, cancellationToken).ConfigureAwait(false))
                {
                    RequeueUnsafe([.. updates.Select(update => update.Attempt)]);
                    await UploadDeferredAttachmentsAsync(deferredAttachments, cancellationToken).ConfigureAwait(false);
                    return;
  • Files reviewed: 28/28 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings August 4, 2026 10:31

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.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:356

  • The new attempt-qualified attachment naming is externally visible, but the added retry tests never assert the uploaded filename (there are no attempt- assertions in the suite). Please add coverage that publishes a retry with an attachment and verifies the parent upload uses the expected name, including preservation of the original extension, so this PR requirement cannot regress unnoticed.
            renamed[i] = attachments[i].WithFileName(
                $"{Path.GetFileNameWithoutExtension(fileName)}.attempt-{attemptNumber.ToString(CultureInfo.InvariantCulture)}{extension}");
  • Files reviewed: 28/28 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings August 4, 2026 10:39

@github-actions github-actions Bot 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.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · auto · 108.8 AIC · ⌖ 3.9 AIC · ⊞ 16.2K · ◷

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.

Review details

Suppressed comments (2)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:166

  • ExistFile is backed by File.Exists, which returns false for access/path errors as well as for a missing file. In this safety gate that makes invalidation fail open: a transient access failure can leave the old map in place, allow the PATCH, and then let a later attempt replay stale history if saving fails or the process exits. Delete unconditionally (File.Delete is a no-op when the file is absent) and use the existing exception handler to force the safe POST fallback when deletion cannot be confirmed.
        if (!_fileSystem.ExistFile(_filePath))
        {
            return true;
        }

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:237

  • This retains every created result—including passed and skipped tests—in _resultIdStore until session end and serializes all of them to disk. The retry orchestrator builds later attempt filters only from failed/error/timeout/cancelled UIDs (RetryDataConsumer.cs:73-81, RetryArgumentsBuilder.cs:109-147), so passed/skipped entries can never be looked up. For large mostly-green suites this changes the live publisher from bounded batch memory to O(total test count) memory and writes a potentially large map even when no retry runs; record only outcomes eligible for retry.
        for (int i = 0; i < batch.Count; i++)
        {
            _resultIdStore?.RecordCreated(batch[i].Result, resultIds[i]);
  • Files reviewed: 28/28 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@github-actions

This comment has been minimized.

Copilot AI review requested due to automatic review settings August 4, 2026 10:52

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.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:283

  • The with expression also copies DurationInMs from only the latest attempt. Once the result becomes a rerun, that top-level duration represents the grouped test and is what Azure DevOps uses for result/run duration reporting; rerun publishers populate it with the total of the sub-result durations (the Microsoft UpdateUnreliableTests.ps1 publisher does this explicitly). A fail taking 30 s followed by a 1 s pass is therefore reported here as 1 s even though both executions are retained below it. Keep the latest outcome/error as intended, but derive the parent duration from the accumulated attempt history (and add a timing assertion).
            attemptHistories[i] = AzureDevOpsResultIdStore.BuildNextAttempts(updates[i].Published, updates[i].Attempt.Result);
            parents[i] = updates[i].Attempt.Result with
            {
                Id = updates[i].Published.Id,
                ResultGroupType = AzureDevOpsLivePublishingConstants.RerunResultGroupType,
                SubResults = attemptHistories[i],
            };
  • Files reviewed: 28/28 changed files
  • Comments generated: 1
  • Review effort level: Balanced

@github-actions

This comment has been minimized.

@github-actions github-actions Bot 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.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · auto · 156.5 AIC · ⌖ 4.77 AIC · ⊞ 16.2K · ◷

Copilot AI review requested due to automatic review settings August 4, 2026 11:08

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.

Review details

  • Files reviewed: 28/28 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Count identity collisions before payload validation and handle SecurityException across map invalidation, loading, cleanup, and orchestrator teardown.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
Copilot AI review requested due to automatic review settings August 4, 2026 12:26
@github-actions

This comment has been minimized.

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.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:276

  • A result created in this host attempt is added to the store but its ID is not marked as claimed. If another row with the same (storage, UID, title) arrives in a later batch (for example, duplicate folded rows split by a batch-size or interval flush), it resolves to this newly created result and is PATCHed as though it were a retry, collapsing two rows from the same attempt. Claim every newly assigned ID when recording it so later same-attempt matches take the safe-create path and mark the key ambiguous.
            _resultIdStore?.RecordCreated(batch[i].Result, resultIds[i]);
  • Files reviewed: 28/28 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Prevent later duplicate rows in the same test-host attempt from PATCHing a parent created by an earlier batch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
Copilot AI review requested due to automatic review settings August 4, 2026 12:33
Treat every positive server result id as an ownership claim even when the surrounding persisted key is malformed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152

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.

Review details

Suppressed comments (2)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:330

  • When the latest retry passes (or has no stack trace), these nullable detail fields remain null, but the client serializes PATCH bodies with JsonIgnoreCondition.WhenWritingNull. Azure DevOps treats omitted PATCH fields as unchanged, so the parent can become Passed while retaining the earlier failure's errorMessage/stackTrace, contrary to the latest-attempt parent semantics. Serialize explicit nulls for these fields on updates (while continuing to omit rerun-only nulls on POST).
            parents[i] = updates[i].Attempt.Result with
            {
                Id = updates[i].Published.Id,
                ResultGroupType = AzureDevOpsLivePublishingConstants.RerunResultGroupType,
                SubResults = attemptHistories[i],
                DurationInMs = totalDurations[i],
                StartedDate = startedDates[i],
                CompletedDate = completedDates[i],
            };

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsResultIdStore.cs:342

  • A positive result ID is counted only when the same entry also has a complete key. Thus a malformed entry such as { "id": 433 } is ignored, and a later valid entry claiming ID 433 is accepted and PATCHed even though the untrusted map assigns that ID twice. Count every positive ID independently of key validation so all collisions take the safe-create path.
                if (entry is null)
                {
                    continue;
                }

  • Files reviewed: 27/28 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings August 4, 2026 12:39
@github-actions

This comment has been minimized.

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.

Review details

Suppressed comments (1)

src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsTestResultsPublisher.Flush.cs:190

  • When map invalidation fails during the session-end forced flush, a transient failure of the safe-create POST requeues the retry result and returns. No later flush drains that queue, so the attempt is reported as dropped instead of receiving the same immediate create retry used after a failed PATCH. On forced flushes, continue once so the retained claim reclassifies this item as a plain creation; background flushes should still return for backoff.
                    if (!await TryCreateResultsAsync(updateFallbacks, deferredAttachments, cancellationToken).ConfigureAwait(false))
                    {
                        RequeueUnsafe(updateFallbacks);
                        await UploadDeferredAttachmentsAsync(deferredAttachments, cancellationToken).ConfigureAwait(false);
                        return;
  • Files reviewed: 27/28 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Use update-specific JSON serialization so passing retries send explicit null error and stack-trace fields while create payloads retain null omission.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
Copilot AI review requested due to automatic review settings August 4, 2026 12:44

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.

Review details

  • Files reviewed: 27/28 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@github-actions

This comment has been minimized.

Give the invalidation-failure fallback one immediate session-end retry while preserving background-flush backoff.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 522344b1-f0e0-47a5-a8d0-cf897db28152
Copilot AI review requested due to automatic review settings August 4, 2026 12:52
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🧪 Test quality grade — PR #10431

No new or modified test methods were identified in the changed regions of this PR. Nothing to grade.

Re-run with /grade-tests.

🤖 Automated content by GitHub Copilot. Generated by the Grade Tests on PR (on open / sync) workflow. · auto · 18 AIC · ⌖ 3.51 AIC · ⊞ 16.2K · [◷]( · ◷)

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.

Review details

  • Files reviewed: 27/28 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🧵 Parallel-safety audit — PR #10431

Parallelization — assembly audited:

Test assembly Scope Workers Analyzer coverage
Microsoft.Testing.Extensions.UnitTests MethodLevel CPU count (Workers = 0) coverable once the parallel-safety analyzers ship (attribute-based opt-in in Program.cs, unchanged by this PR)

Findings: A (global-state) 0 · B (paths) 0 · C (declaration) 0 · D (over-serialization) 0 — nothing flagged.

This PR only touches AzureDevOpsLivePublishingTests.cs (new retry/sub-result tests plus refactored helper methods, behavior-preserving) and TrxResultStreamingStoreTests.cs (one added no-op ReplaceFile override on a fake IFileSystem). Reviewed every added test method, the new RetryTestStartTime static readonly field, and the reused helpers (CreateOrchestratorLifetime, CreatePublisher, PublishSingleResultAsync, StartPublisherAsync, CreateEnvironmentMockWithSettableRunId):

  • Every new test gets its own TestDirectory (a GUID-named temp subdirectory created via Path.Combine(Path.GetTempPath(), nameof(AzureDevOpsLivePublishingTests), Guid.NewGuid().ToString("N"))), so no two tests can collide on a filesystem path (category B clean).
  • Environment.SetEnvironmentVariable calls only happen on a per-test Mock<IEnvironment> instance (an in-memory closure-backed fake), never on the real process environment, so there is no process-global mutation (category A clean).
  • RetryTestStartTime is a static readonly field, but it's an immutable DateTimeOffset used only for input construction — never mutated after initialization, so it introduces no cross-test channel.
  • No [ResourceLock], [DoNotParallelize], or assembly-level [Parallelize]/[DoNotParallelize] declarations were added, removed, or changed by this PR (Program.cs's existing [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] is untouched).
  • No lifecycle members ([TestInitialize]/[TestCleanup]/[ClassInitialize]/constructor) were modified; the existing [TestCleanup] cleanup of _directoriesToDelete is unchanged.

Nothing here needs to be serialized, locked, or isolated further. Clean audit.

Advisory only — heuristic, non-blocking. Re-run with /parallel-audit. This audit answers "is it parallel-safe?"; for testability, smells, or flakiness see the detect-static-dependencies / test-smell-detection / test-anti-patterns analyses.

🤖 Automated content by GitHub Copilot. Generated by the Parallel-safety audit on PR (on open / sync) workflow. · auto · 89.1 AIC · ⌖ 2.96 AIC · ⊞ 24.7K · [◷]( · ◷)

@Evangelink
Amaury Levé (Evangelink) merged commit fd78d82 into main Aug 4, 2026
32 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/azdo-rerun-subresults branch August 4, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-review Awaiting review from the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publish retry attempts as sub-results of one Azure DevOps test result instead of duplicate results

3 participants