feat(worker): surface startup recovery via OperationProgress channel

The six Lifecycle/*Recovery hosted services now broadcast one
OperationProgress("startup-recovery", <phase>, current, total) message each
after they finish, instead of leaving the UI on a bare "connecting" text
during worker startup. IslandsShellViewModel subscribes and swaps in
"Recovering... (i/n)" (existing ops.worker.startupRecovery key, no locale
changes) while Worker.IsReconnecting is true, and clears it once actually
connected so a later transient reconnect doesn't replay stale text.

OperationProgress broadcasts to Clients.All with no replay-on-connect, so a
UI that hasn't finished its SignalR handshake yet can miss some or all of
these messages and simply keep showing "connecting" as before -- accepted
rather than adding a cached-state + reconnect-replay path (mirroring
RefreshExternalMergeConflictsAsync) for what is a fast, best-effort,
local-only startup sweep with no UI-visible failure mode beyond that.
This commit is contained in:
mika kuns
2026-08-21 13:36:25 +02:00
parent dcda067b48
commit 6ec81f653b
16 changed files with 254 additions and 11 deletions
@@ -1,5 +1,6 @@
using ClaudeDo.Data;
using ClaudeDo.Data.Models;
using ClaudeDo.Worker.Hub;
using ClaudeDo.Worker.Lifecycle;
using ClaudeDo.Worker.Tests.Infrastructure;
using Microsoft.Extensions.Logging.Abstractions;
@@ -49,14 +50,18 @@ public sealed class AttachmentOrphanRecoveryTests : IDisposable
Directory.CreateDirectory(liveDir);
Directory.CreateDirectory(orphanDir);
var hubContext = new CapturingHubContext();
var sut = new AttachmentOrphanRecovery(
_db.CreateFactory(), store,
new HubBroadcaster(hubContext),
NullLogger<AttachmentOrphanRecovery>.Instance);
await sut.StartAsync(CancellationToken.None);
Assert.True(Directory.Exists(liveDir), "Live task dir should be kept");
Assert.False(Directory.Exists(orphanDir), "Orphan dir should be deleted");
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
}
[Fact]
@@ -66,10 +71,15 @@ public sealed class AttachmentOrphanRecoveryTests : IDisposable
var missingRoot = Path.Combine(Path.GetTempPath(), $"claudedo_missing_{Guid.NewGuid():N}");
var store = new AttachmentStore(missingRoot);
var hubContext = new CapturingHubContext();
var sut = new AttachmentOrphanRecovery(
_db.CreateFactory(), store,
new HubBroadcaster(hubContext),
NullLogger<AttachmentOrphanRecovery>.Instance);
await sut.StartAsync(CancellationToken.None); // must not throw
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
}
}
@@ -1,4 +1,5 @@
using ClaudeDo.Data.Models;
using ClaudeDo.Worker.Hub;
using ClaudeDo.Worker.Lifecycle;
using ClaudeDo.Worker.Tests.Infrastructure;
using Microsoft.Extensions.Logging.Abstractions;
@@ -63,9 +64,14 @@ public sealed class LegacyWorktreeFolderRecoveryTests : IDisposable
[Fact]
public async Task StartAsync_NoLists_DoesNotThrow()
{
var sut = new LegacyWorktreeFolderRecovery(_db.CreateFactory(), NullLogger<LegacyWorktreeFolderRecovery>.Instance);
var hubContext = new CapturingHubContext();
var sut = new LegacyWorktreeFolderRecovery(
_db.CreateFactory(), new HubBroadcaster(hubContext), NullLogger<LegacyWorktreeFolderRecovery>.Instance);
await sut.StartAsync(CancellationToken.None);
await sut.StopAsync(CancellationToken.None);
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
}
}
@@ -0,0 +1,27 @@
using ClaudeDo.Worker.Hub;
using ClaudeDo.Worker.Lifecycle;
using ClaudeDo.Worker.Tests.Infrastructure;
using Microsoft.Extensions.Logging.Abstractions;
namespace ClaudeDo.Worker.Tests.Lifecycle;
public sealed class OrphanRecoveryTests : IDisposable
{
private readonly DbFixture _db = new();
public void Dispose() => _db.Dispose();
[Fact]
public async Task StartAsync_NoOrphans_BroadcastsStartupRecoveryProgress()
{
var hubContext = new CapturingHubContext();
var sut = new OrphanRecovery(
_db.CreateFactory(), new HubBroadcaster(hubContext), NullLogger<OrphanRecovery>.Instance);
await sut.StartAsync(CancellationToken.None);
await sut.StopAsync(CancellationToken.None);
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
}
}
@@ -0,0 +1,52 @@
using ClaudeDo.Worker.Hub;
using ClaudeDo.Worker.Lifecycle;
using ClaudeDo.Worker.Tests.Infrastructure;
using Microsoft.Extensions.Logging.Abstractions;
namespace ClaudeDo.Worker.Tests.Lifecycle;
public sealed class PlanningLineageRecoveryTests : IDisposable
{
private readonly DbFixture _db = new();
public void Dispose() => _db.Dispose();
[Fact]
public async Task StartAsync_SessionsDirMissing_BroadcastsStartupRecoveryProgress()
{
var missingRoot = Path.Combine(Path.GetTempPath(), $"claudedo_planning_sessions_{Guid.NewGuid():N}");
var hubContext = new CapturingHubContext();
var sut = new PlanningLineageRecovery(
_db.CreateFactory(), missingRoot, new HubBroadcaster(hubContext),
NullLogger<PlanningLineageRecovery>.Instance);
await sut.StartAsync(CancellationToken.None);
await sut.StopAsync(CancellationToken.None);
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
}
[Fact]
public async Task StartAsync_NoSessionFolders_BroadcastsStartupRecoveryProgress()
{
var root = Path.Combine(Path.GetTempPath(), $"claudedo_planning_sessions_{Guid.NewGuid():N}");
Directory.CreateDirectory(root);
try
{
var hubContext = new CapturingHubContext();
var sut = new PlanningLineageRecovery(
_db.CreateFactory(), root, new HubBroadcaster(hubContext),
NullLogger<PlanningLineageRecovery>.Instance);
await sut.StartAsync(CancellationToken.None);
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
}
finally
{
if (Directory.Exists(root)) Directory.Delete(root, recursive: true);
}
}
}
@@ -1,6 +1,8 @@
using System.Text.Json;
using ClaudeDo.Data;
using ClaudeDo.Worker.Hub;
using ClaudeDo.Worker.Lifecycle;
using ClaudeDo.Worker.Tests.Infrastructure;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
@@ -49,7 +51,8 @@ public sealed class PromptFileRecoveryTests
var orphanPath = Path.Combine(root, "agent.md");
File.WriteAllText(orphanPath, "leftover");
var sut = new PromptFileRecovery(NullLogger<PromptFileRecovery>.Instance, root);
var hubContext = new CapturingHubContext();
var sut = new PromptFileRecovery(NullLogger<PromptFileRecovery>.Instance, new HubBroadcaster(hubContext), root);
await sut.StartAsync(CancellationToken.None);
@@ -57,6 +60,8 @@ public sealed class PromptFileRecoveryTests
Assert.True(File.Exists(PromptFiles.PathFor(PromptKind.System, root)), "Real edit must survive");
Assert.False(File.Exists(orphanPath), "Orphan must be moved out of the prompts root");
Assert.True(File.Exists(Path.Combine(root, "_orphans", "agent.md")), "Orphan must be quarantined, not deleted");
Assert.Contains(hubContext.Proxy.Calls, c =>
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
await sut.StopAsync(CancellationToken.None); // must not throw
}
@@ -77,7 +82,7 @@ public sealed class PromptFileRecoveryTests
File.WriteAllText(orphanPath, "my old customized triage+wait+merge prompt");
var logger = new CapturingLogger<PromptFileRecovery>();
var sut = new PromptFileRecovery(logger, root);
var sut = new PromptFileRecovery(logger, new HubBroadcaster(new CapturingHubContext()), root);
await sut.StartAsync(CancellationToken.None);