Skip to content

Commit 25a3db6

Browse files
committed
Report installation deadlines with confirmed process cleanup
1 parent 5071480 commit 25a3db6

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎GrokSharpSDK.Tests/ManagementTests.cs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ public async Task ManagedInstallation_EarlyDisposeJoinsAndRemovesUnverifiedGener
7474
await Assert.That(Directory.EnumerateFiles(options.InstallationDirectory!, "*", SearchOption.AllDirectories)).IsEmpty();
7575
}
7676

77+
[Test]
78+
public async Task ManagedInstallation_DeadlineReportsConfirmedFailureAndRemovesGeneration()
79+
{
80+
await using var fixture = await NativeFixture.CreateAsync();
81+
using var client = new GrokClient(fixture.ClientOptions);
82+
// Force the real package manager to exceed the installation budget; no fake process is substituted.
83+
var options = CreateInstallationOptions(fixture, CliPackageManager.Npm) with { InstallTimeout = TimeSpan.FromMilliseconds(1) };
84+
CliExecutionFailureException? failure = null;
85+
try
86+
{
87+
await foreach (var _ in client.InstallOrUpdateCliAsync(options)) { }
88+
}
89+
catch (CliExecutionFailureException exception) { failure = exception; }
90+
await Assert.That(failure).IsNotNull();
91+
await Assert.That(failure!.RootProcessExitConfirmed).IsTrue();
92+
await Assert.That(failure.InnerException is TimeoutException).IsTrue();
93+
await Assert.That(Directory.EnumerateFiles(options.InstallationDirectory!, "*", SearchOption.AllDirectories)).IsEmpty();
94+
}
95+
7796
private static CliInstallationOptions CreateInstallationOptions(NativeFixture fixture, CliPackageManager manager)
7897
{
7998
var executable = FindExecutable(manager == CliPackageManager.Npm ? "node" : "bun");

‎GrokSharpSDK/Client/GrokClient.Management.cs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ public async IAsyncEnumerable<CliInstallationUpdate> InstallOrUpdateCliAsync(Cli
6464
catch (Exception exception)
6565
{
6666
await updates.DisposeAsync().ConfigureAwait(false);
67-
if (exception is OperationCanceledException or CliExecutionFailureException)
67+
if (exception is CliExecutionFailureException ||
68+
exception is OperationCanceledException && lifetime.IsCancellationRequested)
6869
{
6970
throw;
7071
}
72+
if (exception is OperationCanceledException)
73+
{
74+
throw new CliExecutionFailureException("Grok CLI installation exceeded its deadline.", true,
75+
new TimeoutException("The package-manager installation deadline expired.", exception));
76+
}
7177
throw new CliExecutionFailureException("Grok CLI installation failed.", true, exception);
7278
}
7379
if (!available)

‎docs/Features/Execution.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ Native references at the pinned upstream revision:
2727
Launch descriptors use standard System.Text.Json constructor binding and source generation. A persisted launch can be reloaded without a custom converter. The consumer owns descriptor storage and retirement of previously successful generations.
2828

2929
Execution and installation failures expose `CliExecutionFailureException.RootProcessExitConfirmed`. A confirmed failure is reported only after the operation joins its process and readers. An unconfirmed cleanup exception overrides cancellation or the provider error; consumers must retain their execution fence. Native tool events expose only the standard `native_tool` activity tag and thoughts expose `reasoning`; raw native records remain caller-owned data.
30+
31+
An expired internal installation deadline is a confirmed process failure after joining cleanup, with TimeoutException as its cause. Caller cancellation remains cancellation. This distinction lets a Worker retry a failed installation without treating an ordinary deadline as an unknown live process.

0 commit comments

Comments
 (0)