.NET: Improve Hosted Agent LRA Resilient Recovery Sample - #8082
Open
Roger Barreto (rogerbarreto) wants to merge 4 commits into
Open
.NET: Improve Hosted Agent LRA Resilient Recovery Sample#8082Roger Barreto (rogerbarreto) wants to merge 4 commits into
Roger Barreto (rogerbarreto) wants to merge 4 commits into
Conversation
Roger Barreto (rogerbarreto)
requested review from
SergeyMenshykh,
Vincent Biret (baywet),
chetantoshniwal,
Peter Ibekwe (peibekwe) and
westey (westey-m)
as code owners
September 5, 2026 00:30
Roger Barreto (rogerbarreto)
deployed
to
github-app-auth
September 5, 2026 00:30 — with
GitHub Actions
Active
Roger Barreto (rogerbarreto)
deployed
to
github-app-auth
September 5, 2026 00:30 — with
GitHub Actions
Active
Roger Barreto (rogerbarreto)
deployed
to
github-app-auth
September 5, 2026 00:31 — with
GitHub Actions
Active
Roger Barreto (rogerbarreto)
deployed
to
integration
September 5, 2026 00:31 — with
GitHub Actions
Active
Roger Barreto (rogerbarreto)
deployed
to
integration
September 5, 2026 00:31 — with
GitHub Actions
Active
Copilot started reviewing on behalf of
Roger Barreto (rogerbarreto)
September 5, 2026 00:32
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The hosted deployment has an unavailable sibling project dependency, and the E2E can mask failures while reporting success.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Simplifies resilient workflow recovery while demonstrating idempotent downstream operations through a SQLite-backed service.
Changes:
- Introduces explicit workflow-checkpoint items and handler persistence.
- Adds crash/shutdown recovery scenarios with an idempotent service.
- Updates deployment configuration, documentation, and tests.
File summaries
| File | Description |
|---|---|
OutputConverterWorkflowTests.cs |
Tests checkpoint item emission. |
OutputConverter.cs |
Adds explicit checkpoint boundaries. |
AgentFrameworkResponseHandler.cs |
Persists checkpoint items in order. |
Using-Samples/README.md |
Updates resilience sample reference. |
Using-E2E-Resilience.csproj |
Adds SQLite and ASP.NET dependencies. |
ServerProcess.cs |
Manages child-process output and lifetime. |
ServerManager.cs |
Coordinates builds, services, and recovery. |
Using-E2E-Resilience/README.md |
Documents recovery and idempotency flow. |
Using-E2E-Resilience/Program.cs |
Runs crash and shutdown scenarios. |
IdempotentService.cs |
Implements the SQLite-backed service. |
Hosted-Workflow-Resilient-Long-Running/README.md |
Documents revised workflow behavior. |
Hosted-Workflow-Resilient-Long-Running/Program.cs |
Integrates idempotent operations and shutdown handling. |
HostedWorkflowResilientLongRunning.csproj |
References the shared client project. |
azure.yaml |
Configures service endpoint and scope. |
.env.example |
Adds local idempotency settings. |
IdempotentServiceClient.cs |
Adds the shared HTTP client. |
ClawAgent.Hosted/.gitignore |
Ignores local launch settings. |
Directory.Packages.props |
Pins Microsoft.Data.Sqlite. |
Review details
- Files reviewed: 18/18 changed files
- Comments generated: 5
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Hosted_Shared_Contributor_Setup\Hosted_Shared_Contributor_Setup.csproj" /> |
Comment on lines
+134
to
+136
| int operationCount = await idempotentService.GetOperationCountAsync(serverManager.OperationScope, cancellationToken); | ||
| Console.WriteLine($" Idempotent service contains {operationCount} completed operations."); | ||
| serverManager.MarkSucceeded(); |
Comment on lines
+109
to
112
| catch | ||
| { | ||
| if (this._preCrashTexts is not { Count: > 0 } preCrashTexts) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| this._recoveryIncludesSnapshot ??= | ||
| string.Equals(text, preCrashTexts[0], StringComparison.Ordinal); | ||
| if (this._recoveryIncludesSnapshot is not true) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (this._recoverySnapshotIndex >= preCrashTexts.Count) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (!string.Equals( | ||
| text, | ||
| preCrashTexts[this._recoverySnapshotIndex], | ||
| StringComparison.Ordinal)) | ||
| { | ||
| throw new InvalidOperationException( | ||
| "The response snapshot returned during reconnection did not match the pre-crash output."); | ||
| } | ||
|
|
||
| this._recoverySnapshotIndex++; | ||
| WriteOutput("restored", text); | ||
| return true; | ||
| } | ||
|
|
||
| private static void WriteOutput(string phase, string text) | ||
| { | ||
| Console.ForegroundColor = phase == "recovered" | ||
| ? ConsoleColor.Green | ||
| : ConsoleColor.DarkGray; | ||
| Console.WriteLine($" {phase,-9} > {text}"); | ||
| Console.ResetColor(); | ||
| } | ||
| } | ||
|
|
||
| internal sealed class ServerProcess | ||
| { | ||
| private readonly Process _process; | ||
| private readonly Task _outputPump; | ||
| private readonly Task _errorPump; | ||
|
|
||
| private ServerProcess(Process process, TextWriter logWriter) | ||
| { | ||
| this._process = process; | ||
| this._outputPump = PumpAsync(process.StandardOutput, logWriter, "stdout"); | ||
| this._errorPump = PumpAsync(process.StandardError, logWriter, "stderr"); | ||
| Console.WriteLine(" The connection was interrupted."); | ||
| } |
| cancellationToken); | ||
| return; | ||
| } | ||
| // The first turn of the workflow is a single message that contains the countdown start value with added of 10 units. |
| if (!string.IsNullOrEmpty(update.Text)) | ||
| { | ||
| await writer.WriteLineAsync($"[{source}] {line}"); | ||
| Console.WriteLine($" {update.Text}{(textUpdates.Contains(update.Text) ? " > Repeated due to abrupt crash and recovery replay (idempotency matters here)" : "")}"); |
Roger Barreto (rogerbarreto)
deployed
to
github-app-auth
September 5, 2026 00:39 — with
GitHub Actions
Active
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.
Motivation & Context
Make the .NET Foundry hosted workflow resilience sample easier to follow and show why downstream services must tolerate repeated calls during recovery. Recovering workflow progress and replaying response events do not prevent an unfinished step from being executed again.
Description & Review Guide
--idempotent-servicemode. ShareIdempotentServiceClientbetween the hosted workflow and E2E. Replace the output converter's checkpoint callback with explicit checkpoint items handled byAgentFrameworkResponseHandler, add coverage for the marker, and update sample documentation and XML remarks. Ignore local launch settings for the Claw hosted sample.Related Issue
N/A
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix). A workflow keeps the label and title prefix in sync automatically.