Skip to content

Commit 34b914b

Browse files
plarroy-nvclaude
andcommitted
fix(setup): don't roll back completed work on capability-verification failure
SetupPipeline previously rolled back every completed step whenever any step failed with RollbackOnFailure enabled. A failed Local AI GPU/inference verification downstream of expensive artifact acquisition would delete the just-downloaded multi-gigabyte model and llama-server runtime, per PR #1237's third finding. Adds SetupStep.RollsBackPrecedingStepsOnFailure (default true, preserving existing behavior everywhere else) and opts VerifyLocalAiGpuLoadStep and VerifyLocalAiInferenceStep out of it — both are read-only verification steps whose failure shouldn't force re-acquisition of artifacts that are otherwise reused via each acquisition step's own CreatedThisRun-gated skip logic. The failed step itself is still rolled back regardless. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent ba48794 commit 34b914b

5 files changed

Lines changed: 109 additions & 2 deletions

File tree

‎src/OpenClaw.SetupEngine/LocalAiGpuVerification.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ internal VerifyLocalAiGpuLoadStep(
254254
public override string DisplayName => "Verifying Local AI GPU placement";
255255
public override bool CanRetry => false;
256256
public override RetryPolicy Retry => RetryPolicy.None;
257+
258+
// Read-only verification downstream of expensive model/runtime acquisition.
259+
// A failure here shouldn't force those artifacts to be re-downloaded.
260+
public override bool RollsBackPrecedingStepsOnFailure => false;
261+
257262
public override bool CanSkip(SetupContext ctx) => !ctx.Config.LocalAi.Enabled;
258263

259264
public override async Task<StepResult> ExecuteAsync(SetupContext ctx, CancellationToken ct)

‎src/OpenClaw.SetupEngine/LocalAiSetupSteps.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,10 @@ internal VerifyLocalAiInferenceStep(Func<ILlamaServerInferenceClient> clientFact
758758
public override bool CanRetry => false;
759759
public override RetryPolicy Retry => RetryPolicy.None;
760760

761+
// Read-only verification downstream of expensive model/runtime acquisition.
762+
// A failure here shouldn't force those artifacts to be re-downloaded.
763+
public override bool RollsBackPrecedingStepsOnFailure => false;
764+
761765
public override bool CanSkip(SetupContext ctx) => !ctx.Config.LocalAi.Enabled;
762766

763767
public override async Task<StepResult> ExecuteAsync(SetupContext ctx, CancellationToken ct)

‎src/OpenClaw.SetupEngine/SetupPipeline.cs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ public abstract class SetupStep
1515
public virtual bool CanSkip(SetupContext ctx) => false;
1616
public virtual bool CanRetry => true;
1717
public virtual RetryPolicy Retry => RetryPolicy.Default;
18+
19+
/// <summary>
20+
/// Whether this step's failure should roll back previously-completed steps.
21+
/// Read-only verification steps that fail after expensive prior acquisition
22+
/// (model/runtime download, manifest persistence) should return false so a
23+
/// failed verification doesn't force those artifacts to be re-downloaded —
24+
/// they remain in place, reusable by a retry via each step's own
25+
/// CreatedThisRun-gated skip/reuse logic. The failed step itself is still
26+
/// rolled back regardless of this flag.
27+
/// </summary>
28+
public virtual bool RollsBackPrecedingStepsOnFailure => true;
1829
}
1930

2031
// ─── Pipeline Result ───
@@ -212,7 +223,16 @@ public async Task<PipelineResult> RunAsync(SetupContext ctx)
212223
if (_rollbackOnFailureOverride ?? ctx.Config.RollbackOnFailure)
213224
{
214225
await RollbackFailedStep(step, ctx);
215-
await RollbackCompletedSteps(ctx);
226+
if (step.RollsBackPrecedingStepsOnFailure)
227+
{
228+
await RollbackCompletedSteps(ctx);
229+
}
230+
else
231+
{
232+
ctx.Logger.Warn(
233+
$"Preserving {_completedSteps.Count} completed step(s); " +
234+
$"'{step.Id}' does not roll back preceding work.");
235+
}
216236
}
217237

218238
ctx.Journal.RecordPipelineEvent("pipeline_failed", $"step={step.Id}, message={result.Message}");

‎tests/OpenClaw.SetupEngine.Tests/LocalAiGpuVerificationTests.cs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,24 @@ public void HasRequiredGpuLoadEvidence_RejectsWhenNeitherMemoryProofMeetsThresho
9191

9292
Assert.False(accepted);
9393
}
94+
95+
[Fact]
96+
public void RollsBackPrecedingStepsOnFailure_IsFalse()
97+
{
98+
// A failed GPU-load verification must not force the pipeline to roll
99+
// back (delete) the already-downloaded model/runtime it just verified.
100+
SetupStep step = new VerifyLocalAiGpuLoadStep();
101+
102+
Assert.False(step.RollsBackPrecedingStepsOnFailure);
103+
}
104+
105+
[Fact]
106+
public void VerifyLocalAiInferenceStep_RollsBackPrecedingStepsOnFailure_IsFalse()
107+
{
108+
// Same reasoning as VerifyLocalAiGpuLoadStep: a failed on-demand-load
109+
// verification must not force re-acquisition of the model/runtime.
110+
SetupStep step = new VerifyLocalAiInferenceStep();
111+
112+
Assert.False(step.RollsBackPrecedingStepsOnFailure);
113+
}
94114
}

‎tests/OpenClaw.SetupEngine.Tests/SetupPipelineTests.cs‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ private sealed class MockStep : SetupStep
1919
private readonly Func<SetupContext, CancellationToken, Task<StepResult>> _execute;
2020
private readonly Func<SetupContext, CancellationToken, Task>? _rollback;
2121
private readonly bool _canSkip;
22+
private readonly bool _rollsBackPrecedingSteps;
2223

2324
public override string Id { get; }
2425
public override string DisplayName { get; }
2526
public override bool CanRetry => false;
27+
public override bool RollsBackPrecedingStepsOnFailure => _rollsBackPrecedingSteps;
2628

2729
public MockStep(string id, Func<SetupContext, CancellationToken, Task<StepResult>> execute,
2830
Func<SetupContext, CancellationToken, Task>? rollback = null,
29-
bool canSkip = false)
31+
bool canSkip = false,
32+
bool rollsBackPrecedingSteps = true)
3033
{
3134
Id = id;
3235
DisplayName = id;
3336
_execute = execute;
3437
_rollback = rollback;
3538
_canSkip = canSkip;
39+
_rollsBackPrecedingSteps = rollsBackPrecedingSteps;
3640
}
3741

3842
public override bool CanSkip(SetupContext ctx) => _canSkip;
@@ -235,6 +239,60 @@ public async Task RunAsync_StepFails_WithRollback_CallsRollbackInReverseOrder()
235239
Assert.Equal(["s2", "s1"], rollbackOrder);
236240
}
237241

242+
[Fact]
243+
public async Task RunAsync_StepFails_WithRollback_DefaultStillRollsBackPrecedingSteps()
244+
{
245+
// Regression guard: a step that does not override RollsBackPrecedingStepsOnFailure
246+
// preserves today's behavior of rolling back everything completed before it.
247+
var rollbackOrder = new List<string>();
248+
var config = new SetupConfig { RollbackOnFailure = true };
249+
var ctx = CreateContext(config);
250+
251+
var pipeline = new SetupPipeline([
252+
new MockStep("s1",
253+
(_, _) => Task.FromResult(StepResult.Ok()),
254+
(_, _) => { rollbackOrder.Add("s1"); return Task.CompletedTask; }),
255+
new MockStep("s2",
256+
(_, _) => Task.FromResult(StepResult.Fail("fail"))),
257+
]);
258+
259+
var result = await pipeline.RunAsync(ctx);
260+
261+
Assert.Equal(PipelineOutcome.Failed, result.Outcome);
262+
Assert.Equal(["s1"], rollbackOrder);
263+
}
264+
265+
[Fact]
266+
public async Task RunAsync_StepFails_WithRollback_PreservesPrecedingStepsWhenStepOptsOut()
267+
{
268+
// A verification-style step (e.g. VerifyLocalAiGpuLoadStep) opting out of
269+
// RollsBackPrecedingStepsOnFailure must not trigger rollback of the
270+
// expensive artifacts acquired by steps before it.
271+
var rollbackOrder = new List<string>();
272+
var failedStepRolledBack = false;
273+
var config = new SetupConfig { RollbackOnFailure = true };
274+
var ctx = CreateContext(config);
275+
276+
var pipeline = new SetupPipeline([
277+
new MockStep("s1",
278+
(_, _) => Task.FromResult(StepResult.Ok()),
279+
(_, _) => { rollbackOrder.Add("s1"); return Task.CompletedTask; }),
280+
new MockStep("s2",
281+
(_, _) => Task.FromResult(StepResult.Ok()),
282+
(_, _) => { rollbackOrder.Add("s2"); return Task.CompletedTask; }),
283+
new MockStep("s3",
284+
(_, _) => Task.FromResult(StepResult.Fail("verification failed")),
285+
(_, _) => { failedStepRolledBack = true; return Task.CompletedTask; },
286+
rollsBackPrecedingSteps: false),
287+
]);
288+
289+
var result = await pipeline.RunAsync(ctx);
290+
291+
Assert.Equal(PipelineOutcome.Failed, result.Outcome);
292+
Assert.Empty(rollbackOrder);
293+
Assert.True(failedStepRolledBack, "the failed step itself is still rolled back");
294+
}
295+
238296
[Fact]
239297
public async Task RunAsync_StepFails_WithRollback_CleansUpFailedStepFirst()
240298
{

0 commit comments

Comments
 (0)