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:
@@ -20,14 +20,24 @@ public sealed partial class IslandsShellViewModel : ViewModelBase, IDisposable
|
||||
public ListsIslandViewModel? Lists { get; }
|
||||
public TasksIslandViewModel? Tasks { get; }
|
||||
public DetailsIslandViewModel? Details { get; }
|
||||
public IWorkerClient? Worker { get; }
|
||||
public IWorkerClient? Worker { get; internal set; }
|
||||
public MissionControlViewModel? MissionControl { get; }
|
||||
public UsagePillViewModel? UsagePill { get; }
|
||||
public UpdateCheckService UpdateCheck => _updateCheck;
|
||||
|
||||
// Stable opKey the six Lifecycle/*Recovery startup sweeps broadcast under (see
|
||||
// OperationProgressOpKeys.StartupRecovery on the worker side — not shared across the
|
||||
// SignalR wire, so the literal is duplicated here on purpose).
|
||||
private const string StartupRecoveryOpKey = "startup-recovery";
|
||||
|
||||
// Last startup-recovery text received this connection cycle, shown in place of the generic
|
||||
// "connecting" label. Cleared once actually connected so a later transient reconnect (not a
|
||||
// fresh worker boot) doesn't replay stale recovery text.
|
||||
private string? _startupRecoveryText;
|
||||
|
||||
public string ConnectionText =>
|
||||
Worker?.IsConnected == true ? Loc.T("vm.connection.online")
|
||||
: Worker?.IsReconnecting == true ? Loc.T("vm.connection.connecting")
|
||||
: Worker?.IsReconnecting == true ? (_startupRecoveryText ?? Loc.T("vm.connection.connecting"))
|
||||
: Loc.T("vm.connection.offline");
|
||||
|
||||
public bool IsOffline => Worker?.IsConnected != true && Worker?.IsReconnecting != true;
|
||||
@@ -228,6 +238,18 @@ public sealed partial class IslandsShellViewModel : ViewModelBase, IDisposable
|
||||
}
|
||||
public void OnPlanningMergeCompleted(string planningTaskId) => ClearExternalMergeConflict(planningTaskId);
|
||||
|
||||
// Wired to Worker.OperationProgressEvent; also called directly by tests. A foreign opKey
|
||||
// (merge phases, worktree cleanup, ...) is left untouched — this only tracks the
|
||||
// startup-recovery channel.
|
||||
public void OnOperationProgress(string opKey, string phase, int current, int total)
|
||||
{
|
||||
if (opKey != StartupRecoveryOpKey) return;
|
||||
_startupRecoveryText = total > 0
|
||||
? $"{Loc.T("ops.worker.startupRecovery")} ({current}/{total})"
|
||||
: Loc.T("ops.worker.startupRecovery");
|
||||
OnPropertyChanged(nameof(ConnectionText));
|
||||
}
|
||||
|
||||
private void ClearExternalMergeConflict(string planningTaskId)
|
||||
{
|
||||
_externalMergeConflicts.Remove(planningTaskId);
|
||||
@@ -358,11 +380,13 @@ public sealed partial class IslandsShellViewModel : ViewModelBase, IDisposable
|
||||
{
|
||||
if (e.PropertyName is nameof(IWorkerClient.IsConnected) or nameof(IWorkerClient.IsReconnecting))
|
||||
{
|
||||
if (Worker.IsConnected) _startupRecoveryText = null;
|
||||
OnPropertyChanged(nameof(ConnectionText));
|
||||
OnPropertyChanged(nameof(IsOffline));
|
||||
OnPropertyChanged(nameof(CanOpenWorkerConnectionHelp));
|
||||
}
|
||||
};
|
||||
Worker.OperationProgressEvent += OnOperationProgress;
|
||||
Worker.WorkerLogReceivedEvent += OnWorkerLogReceived;
|
||||
Worker.ConnectionRestoredEvent += () => _ = RefreshStaleWorkerCheckAsync();
|
||||
Worker.PlanningMergeConflictEvent += OnPlanningMergeConflict;
|
||||
@@ -410,6 +434,7 @@ public sealed partial class IslandsShellViewModel : ViewModelBase, IDisposable
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Worker is not null) Worker.OperationProgressEvent -= OnOperationProgress;
|
||||
_clearTimer.Stop();
|
||||
_clearTimer.Dispose();
|
||||
_connectTimer.Stop();
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace ClaudeDo.Worker.Hub;
|
||||
|
||||
/// <summary>Stable, non-task-bound opKeys for <see cref="HubBroadcaster.OperationProgress"/>.</summary>
|
||||
public static class OperationProgressOpKeys
|
||||
{
|
||||
/// <summary>The six startup-only <c>Lifecycle/*Recovery</c> hosted services.</summary>
|
||||
public const string StartupRecovery = "startup-recovery";
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ClaudeDo.Worker.Lifecycle;
|
||||
@@ -8,17 +9,22 @@ namespace ClaudeDo.Worker.Lifecycle;
|
||||
/// </summary>
|
||||
public sealed class AttachmentOrphanRecovery : IHostedService
|
||||
{
|
||||
public const string Phase = "attachments";
|
||||
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private readonly AttachmentStore _store;
|
||||
private readonly HubBroadcaster _broadcaster;
|
||||
private readonly ILogger<AttachmentOrphanRecovery> _logger;
|
||||
|
||||
public AttachmentOrphanRecovery(
|
||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||
AttachmentStore store,
|
||||
HubBroadcaster broadcaster,
|
||||
ILogger<AttachmentOrphanRecovery> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_store = store;
|
||||
_broadcaster = broadcaster;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -28,6 +34,7 @@ public sealed class AttachmentOrphanRecovery : IHostedService
|
||||
if (taskIds.Count == 0)
|
||||
{
|
||||
_logger.LogInformation("Attachment orphan recovery: no attachment directories found");
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,6 +52,8 @@ public sealed class AttachmentOrphanRecovery : IHostedService
|
||||
_logger.LogWarning("Attachment orphan recovery: removed {Count} orphaned attachment director(ies)", orphans.Count);
|
||||
else
|
||||
_logger.LogInformation("Attachment orphan recovery: no orphaned attachment directories found");
|
||||
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, taskIds.Count, taskIds.Count);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ClaudeDo.Worker.Lifecycle;
|
||||
@@ -13,16 +14,21 @@ namespace ClaudeDo.Worker.Lifecycle;
|
||||
/// </summary>
|
||||
public sealed class LegacyWorktreeFolderRecovery : IHostedService
|
||||
{
|
||||
public const string Phase = "legacy-worktrees";
|
||||
|
||||
private const string LegacyFolderName = ".claudedo-worktrees";
|
||||
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private readonly HubBroadcaster _broadcaster;
|
||||
private readonly ILogger<LegacyWorktreeFolderRecovery> _logger;
|
||||
|
||||
public LegacyWorktreeFolderRecovery(
|
||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||
HubBroadcaster broadcaster,
|
||||
ILogger<LegacyWorktreeFolderRecovery> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_broadcaster = broadcaster;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -40,6 +46,8 @@ public sealed class LegacyWorktreeFolderRecovery : IHostedService
|
||||
LegacyFolderName, affected.Count, string.Join(", ", affected));
|
||||
else
|
||||
_logger.LogInformation("Legacy worktree folder recovery: no lists affected");
|
||||
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, lists.Count, lists.Count);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ClaudeDo.Worker.Lifecycle;
|
||||
@@ -12,14 +13,19 @@ namespace ClaudeDo.Worker.Lifecycle;
|
||||
/// </summary>
|
||||
public sealed class OrphanRecovery : IHostedService
|
||||
{
|
||||
public const string Phase = "orphaned-children";
|
||||
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private readonly HubBroadcaster _broadcaster;
|
||||
private readonly ILogger<OrphanRecovery> _logger;
|
||||
|
||||
public OrphanRecovery(
|
||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||
HubBroadcaster broadcaster,
|
||||
ILogger<OrphanRecovery> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_broadcaster = broadcaster;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -32,6 +38,8 @@ public sealed class OrphanRecovery : IHostedService
|
||||
_logger.LogWarning("Orphan recovery: dequeued {Count} stuck child task(s)", dequeued);
|
||||
else
|
||||
_logger.LogInformation("Orphan recovery: no stuck child tasks found");
|
||||
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Repositories;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ClaudeDo.Worker.Lifecycle;
|
||||
@@ -13,17 +14,22 @@ namespace ClaudeDo.Worker.Lifecycle;
|
||||
/// </summary>
|
||||
public sealed class PlanningLineageRecovery : IHostedService
|
||||
{
|
||||
public const string Phase = "planning-lineage";
|
||||
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private readonly string _sessionsRoot;
|
||||
private readonly HubBroadcaster _broadcaster;
|
||||
private readonly ILogger<PlanningLineageRecovery> _logger;
|
||||
|
||||
public PlanningLineageRecovery(
|
||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||
string sessionsRoot,
|
||||
HubBroadcaster broadcaster,
|
||||
ILogger<PlanningLineageRecovery> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_sessionsRoot = sessionsRoot;
|
||||
_broadcaster = broadcaster;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -32,6 +38,7 @@ public sealed class PlanningLineageRecovery : IHostedService
|
||||
if (!Directory.Exists(_sessionsRoot))
|
||||
{
|
||||
_logger.LogInformation("Planning lineage recovery: sessions directory missing, nothing to scan");
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,6 +46,7 @@ public sealed class PlanningLineageRecovery : IHostedService
|
||||
if (folders.Length == 0)
|
||||
{
|
||||
_logger.LogInformation("Planning lineage recovery: no session folders");
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,6 +71,8 @@ public sealed class PlanningLineageRecovery : IHostedService
|
||||
|
||||
if (restored == 0)
|
||||
_logger.LogInformation("Planning lineage recovery: no candidates");
|
||||
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, folders.Length, folders.Length);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Worker.Hub;
|
||||
|
||||
namespace ClaudeDo.Worker.Lifecycle;
|
||||
|
||||
@@ -10,16 +11,20 @@ namespace ClaudeDo.Worker.Lifecycle;
|
||||
/// </summary>
|
||||
public sealed class PromptFileRecovery : IHostedService
|
||||
{
|
||||
public const string Phase = "prompt-files";
|
||||
|
||||
private readonly ILogger<PromptFileRecovery> _logger;
|
||||
private readonly HubBroadcaster _broadcaster;
|
||||
private readonly string? _root;
|
||||
|
||||
public PromptFileRecovery(ILogger<PromptFileRecovery> logger, string? root = null)
|
||||
public PromptFileRecovery(ILogger<PromptFileRecovery> logger, HubBroadcaster broadcaster, string? root = null)
|
||||
{
|
||||
_logger = logger;
|
||||
_broadcaster = broadcaster;
|
||||
_root = root;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
PromptFiles.ReconcileStaleDefaults(_root);
|
||||
|
||||
@@ -27,7 +32,8 @@ public sealed class PromptFileRecovery : IHostedService
|
||||
if (orphans.Count == 0)
|
||||
{
|
||||
_logger.LogInformation("Prompt file recovery: no orphaned prompt files found");
|
||||
return Task.CompletedTask;
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var orphan_path in orphans)
|
||||
@@ -40,7 +46,7 @@ public sealed class PromptFileRecovery : IHostedService
|
||||
orphan_path);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, orphans.Count, orphans.Count);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
using ClaudeDo.Worker.Hub;
|
||||
using ClaudeDo.Worker.State;
|
||||
|
||||
namespace ClaudeDo.Worker.Lifecycle;
|
||||
|
||||
public sealed class StaleTaskRecovery : IHostedService
|
||||
{
|
||||
public const string Phase = "stale-tasks";
|
||||
|
||||
private readonly ITaskStateService _state;
|
||||
private readonly HubBroadcaster _broadcaster;
|
||||
private readonly ILogger<StaleTaskRecovery> _logger;
|
||||
|
||||
public StaleTaskRecovery(ITaskStateService state, ILogger<StaleTaskRecovery> logger)
|
||||
public StaleTaskRecovery(ITaskStateService state, HubBroadcaster broadcaster, ILogger<StaleTaskRecovery> logger)
|
||||
{
|
||||
_state = state;
|
||||
_broadcaster = broadcaster;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -20,6 +25,8 @@ public sealed class StaleTaskRecovery : IHostedService
|
||||
_logger.LogWarning("Stale task recovery: flipped {Count} running task(s) to failed", flipped);
|
||||
else
|
||||
_logger.LogInformation("Stale task recovery: no stale tasks found");
|
||||
|
||||
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
@@ -174,6 +174,7 @@ builder.Services.AddSingleton(sp =>
|
||||
builder.Services.AddHostedService(sp => new PlanningLineageRecovery(
|
||||
sp.GetRequiredService<IDbContextFactory<ClaudeDoDbContext>>(),
|
||||
planningSessionsDir,
|
||||
sp.GetRequiredService<HubBroadcaster>(),
|
||||
sp.GetRequiredService<ILogger<PlanningLineageRecovery>>()));
|
||||
builder.Services.AddSingleton<ITerminalLauncher>(sp =>
|
||||
new WindowsTerminalLauncher("wt.exe", cfg.ClaudeBin));
|
||||
|
||||
Reference in New Issue
Block a user