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 ListsIslandViewModel? Lists { get; }
|
||||||
public TasksIslandViewModel? Tasks { get; }
|
public TasksIslandViewModel? Tasks { get; }
|
||||||
public DetailsIslandViewModel? Details { get; }
|
public DetailsIslandViewModel? Details { get; }
|
||||||
public IWorkerClient? Worker { get; }
|
public IWorkerClient? Worker { get; internal set; }
|
||||||
public MissionControlViewModel? MissionControl { get; }
|
public MissionControlViewModel? MissionControl { get; }
|
||||||
public UsagePillViewModel? UsagePill { get; }
|
public UsagePillViewModel? UsagePill { get; }
|
||||||
public UpdateCheckService UpdateCheck => _updateCheck;
|
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 =>
|
public string ConnectionText =>
|
||||||
Worker?.IsConnected == true ? Loc.T("vm.connection.online")
|
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");
|
: Loc.T("vm.connection.offline");
|
||||||
|
|
||||||
public bool IsOffline => Worker?.IsConnected != true && Worker?.IsReconnecting != true;
|
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);
|
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)
|
private void ClearExternalMergeConflict(string planningTaskId)
|
||||||
{
|
{
|
||||||
_externalMergeConflicts.Remove(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 (e.PropertyName is nameof(IWorkerClient.IsConnected) or nameof(IWorkerClient.IsReconnecting))
|
||||||
{
|
{
|
||||||
|
if (Worker.IsConnected) _startupRecoveryText = null;
|
||||||
OnPropertyChanged(nameof(ConnectionText));
|
OnPropertyChanged(nameof(ConnectionText));
|
||||||
OnPropertyChanged(nameof(IsOffline));
|
OnPropertyChanged(nameof(IsOffline));
|
||||||
OnPropertyChanged(nameof(CanOpenWorkerConnectionHelp));
|
OnPropertyChanged(nameof(CanOpenWorkerConnectionHelp));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Worker.OperationProgressEvent += OnOperationProgress;
|
||||||
Worker.WorkerLogReceivedEvent += OnWorkerLogReceived;
|
Worker.WorkerLogReceivedEvent += OnWorkerLogReceived;
|
||||||
Worker.ConnectionRestoredEvent += () => _ = RefreshStaleWorkerCheckAsync();
|
Worker.ConnectionRestoredEvent += () => _ = RefreshStaleWorkerCheckAsync();
|
||||||
Worker.PlanningMergeConflictEvent += OnPlanningMergeConflict;
|
Worker.PlanningMergeConflictEvent += OnPlanningMergeConflict;
|
||||||
@@ -410,6 +434,7 @@ public sealed partial class IslandsShellViewModel : ViewModelBase, IDisposable
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (Worker is not null) Worker.OperationProgressEvent -= OnOperationProgress;
|
||||||
_clearTimer.Stop();
|
_clearTimer.Stop();
|
||||||
_clearTimer.Dispose();
|
_clearTimer.Dispose();
|
||||||
_connectTimer.Stop();
|
_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.Data;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace ClaudeDo.Worker.Lifecycle;
|
namespace ClaudeDo.Worker.Lifecycle;
|
||||||
@@ -8,17 +9,22 @@ namespace ClaudeDo.Worker.Lifecycle;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class AttachmentOrphanRecovery : IHostedService
|
public sealed class AttachmentOrphanRecovery : IHostedService
|
||||||
{
|
{
|
||||||
|
public const string Phase = "attachments";
|
||||||
|
|
||||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||||
private readonly AttachmentStore _store;
|
private readonly AttachmentStore _store;
|
||||||
|
private readonly HubBroadcaster _broadcaster;
|
||||||
private readonly ILogger<AttachmentOrphanRecovery> _logger;
|
private readonly ILogger<AttachmentOrphanRecovery> _logger;
|
||||||
|
|
||||||
public AttachmentOrphanRecovery(
|
public AttachmentOrphanRecovery(
|
||||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||||
AttachmentStore store,
|
AttachmentStore store,
|
||||||
|
HubBroadcaster broadcaster,
|
||||||
ILogger<AttachmentOrphanRecovery> logger)
|
ILogger<AttachmentOrphanRecovery> logger)
|
||||||
{
|
{
|
||||||
_dbFactory = dbFactory;
|
_dbFactory = dbFactory;
|
||||||
_store = store;
|
_store = store;
|
||||||
|
_broadcaster = broadcaster;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,6 +34,7 @@ public sealed class AttachmentOrphanRecovery : IHostedService
|
|||||||
if (taskIds.Count == 0)
|
if (taskIds.Count == 0)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Attachment orphan recovery: no attachment directories found");
|
_logger.LogInformation("Attachment orphan recovery: no attachment directories found");
|
||||||
|
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +52,8 @@ public sealed class AttachmentOrphanRecovery : IHostedService
|
|||||||
_logger.LogWarning("Attachment orphan recovery: removed {Count} orphaned attachment director(ies)", orphans.Count);
|
_logger.LogWarning("Attachment orphan recovery: removed {Count} orphaned attachment director(ies)", orphans.Count);
|
||||||
else
|
else
|
||||||
_logger.LogInformation("Attachment orphan recovery: no orphaned attachment directories found");
|
_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;
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Models;
|
using ClaudeDo.Data.Models;
|
||||||
using ClaudeDo.Data.Repositories;
|
using ClaudeDo.Data.Repositories;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace ClaudeDo.Worker.Lifecycle;
|
namespace ClaudeDo.Worker.Lifecycle;
|
||||||
@@ -13,16 +14,21 @@ namespace ClaudeDo.Worker.Lifecycle;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class LegacyWorktreeFolderRecovery : IHostedService
|
public sealed class LegacyWorktreeFolderRecovery : IHostedService
|
||||||
{
|
{
|
||||||
|
public const string Phase = "legacy-worktrees";
|
||||||
|
|
||||||
private const string LegacyFolderName = ".claudedo-worktrees";
|
private const string LegacyFolderName = ".claudedo-worktrees";
|
||||||
|
|
||||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||||
|
private readonly HubBroadcaster _broadcaster;
|
||||||
private readonly ILogger<LegacyWorktreeFolderRecovery> _logger;
|
private readonly ILogger<LegacyWorktreeFolderRecovery> _logger;
|
||||||
|
|
||||||
public LegacyWorktreeFolderRecovery(
|
public LegacyWorktreeFolderRecovery(
|
||||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||||
|
HubBroadcaster broadcaster,
|
||||||
ILogger<LegacyWorktreeFolderRecovery> logger)
|
ILogger<LegacyWorktreeFolderRecovery> logger)
|
||||||
{
|
{
|
||||||
_dbFactory = dbFactory;
|
_dbFactory = dbFactory;
|
||||||
|
_broadcaster = broadcaster;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +46,8 @@ public sealed class LegacyWorktreeFolderRecovery : IHostedService
|
|||||||
LegacyFolderName, affected.Count, string.Join(", ", affected));
|
LegacyFolderName, affected.Count, string.Join(", ", affected));
|
||||||
else
|
else
|
||||||
_logger.LogInformation("Legacy worktree folder recovery: no lists affected");
|
_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;
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Repositories;
|
using ClaudeDo.Data.Repositories;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace ClaudeDo.Worker.Lifecycle;
|
namespace ClaudeDo.Worker.Lifecycle;
|
||||||
@@ -12,14 +13,19 @@ namespace ClaudeDo.Worker.Lifecycle;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class OrphanRecovery : IHostedService
|
public sealed class OrphanRecovery : IHostedService
|
||||||
{
|
{
|
||||||
|
public const string Phase = "orphaned-children";
|
||||||
|
|
||||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||||
|
private readonly HubBroadcaster _broadcaster;
|
||||||
private readonly ILogger<OrphanRecovery> _logger;
|
private readonly ILogger<OrphanRecovery> _logger;
|
||||||
|
|
||||||
public OrphanRecovery(
|
public OrphanRecovery(
|
||||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||||
|
HubBroadcaster broadcaster,
|
||||||
ILogger<OrphanRecovery> logger)
|
ILogger<OrphanRecovery> logger)
|
||||||
{
|
{
|
||||||
_dbFactory = dbFactory;
|
_dbFactory = dbFactory;
|
||||||
|
_broadcaster = broadcaster;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +38,8 @@ public sealed class OrphanRecovery : IHostedService
|
|||||||
_logger.LogWarning("Orphan recovery: dequeued {Count} stuck child task(s)", dequeued);
|
_logger.LogWarning("Orphan recovery: dequeued {Count} stuck child task(s)", dequeued);
|
||||||
else
|
else
|
||||||
_logger.LogInformation("Orphan recovery: no stuck child tasks found");
|
_logger.LogInformation("Orphan recovery: no stuck child tasks found");
|
||||||
|
|
||||||
|
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Repositories;
|
using ClaudeDo.Data.Repositories;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace ClaudeDo.Worker.Lifecycle;
|
namespace ClaudeDo.Worker.Lifecycle;
|
||||||
@@ -13,17 +14,22 @@ namespace ClaudeDo.Worker.Lifecycle;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class PlanningLineageRecovery : IHostedService
|
public sealed class PlanningLineageRecovery : IHostedService
|
||||||
{
|
{
|
||||||
|
public const string Phase = "planning-lineage";
|
||||||
|
|
||||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||||
private readonly string _sessionsRoot;
|
private readonly string _sessionsRoot;
|
||||||
|
private readonly HubBroadcaster _broadcaster;
|
||||||
private readonly ILogger<PlanningLineageRecovery> _logger;
|
private readonly ILogger<PlanningLineageRecovery> _logger;
|
||||||
|
|
||||||
public PlanningLineageRecovery(
|
public PlanningLineageRecovery(
|
||||||
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
IDbContextFactory<ClaudeDoDbContext> dbFactory,
|
||||||
string sessionsRoot,
|
string sessionsRoot,
|
||||||
|
HubBroadcaster broadcaster,
|
||||||
ILogger<PlanningLineageRecovery> logger)
|
ILogger<PlanningLineageRecovery> logger)
|
||||||
{
|
{
|
||||||
_dbFactory = dbFactory;
|
_dbFactory = dbFactory;
|
||||||
_sessionsRoot = sessionsRoot;
|
_sessionsRoot = sessionsRoot;
|
||||||
|
_broadcaster = broadcaster;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +38,7 @@ public sealed class PlanningLineageRecovery : IHostedService
|
|||||||
if (!Directory.Exists(_sessionsRoot))
|
if (!Directory.Exists(_sessionsRoot))
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Planning lineage recovery: sessions directory missing, nothing to scan");
|
_logger.LogInformation("Planning lineage recovery: sessions directory missing, nothing to scan");
|
||||||
|
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +46,7 @@ public sealed class PlanningLineageRecovery : IHostedService
|
|||||||
if (folders.Length == 0)
|
if (folders.Length == 0)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Planning lineage recovery: no session folders");
|
_logger.LogInformation("Planning lineage recovery: no session folders");
|
||||||
|
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,6 +71,8 @@ public sealed class PlanningLineageRecovery : IHostedService
|
|||||||
|
|
||||||
if (restored == 0)
|
if (restored == 0)
|
||||||
_logger.LogInformation("Planning lineage recovery: no candidates");
|
_logger.LogInformation("Planning lineage recovery: no candidates");
|
||||||
|
|
||||||
|
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, folders.Length, folders.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
|
|
||||||
namespace ClaudeDo.Worker.Lifecycle;
|
namespace ClaudeDo.Worker.Lifecycle;
|
||||||
|
|
||||||
@@ -10,16 +11,20 @@ namespace ClaudeDo.Worker.Lifecycle;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class PromptFileRecovery : IHostedService
|
public sealed class PromptFileRecovery : IHostedService
|
||||||
{
|
{
|
||||||
|
public const string Phase = "prompt-files";
|
||||||
|
|
||||||
private readonly ILogger<PromptFileRecovery> _logger;
|
private readonly ILogger<PromptFileRecovery> _logger;
|
||||||
|
private readonly HubBroadcaster _broadcaster;
|
||||||
private readonly string? _root;
|
private readonly string? _root;
|
||||||
|
|
||||||
public PromptFileRecovery(ILogger<PromptFileRecovery> logger, string? root = null)
|
public PromptFileRecovery(ILogger<PromptFileRecovery> logger, HubBroadcaster broadcaster, string? root = null)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_broadcaster = broadcaster;
|
||||||
_root = root;
|
_root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken)
|
public async Task StartAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
PromptFiles.ReconcileStaleDefaults(_root);
|
PromptFiles.ReconcileStaleDefaults(_root);
|
||||||
|
|
||||||
@@ -27,7 +32,8 @@ public sealed class PromptFileRecovery : IHostedService
|
|||||||
if (orphans.Count == 0)
|
if (orphans.Count == 0)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Prompt file recovery: no orphaned prompt files found");
|
_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)
|
foreach (var orphan_path in orphans)
|
||||||
@@ -40,7 +46,7 @@ public sealed class PromptFileRecovery : IHostedService
|
|||||||
orphan_path);
|
orphan_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, orphans.Count, orphans.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using ClaudeDo.Worker.State;
|
using ClaudeDo.Worker.State;
|
||||||
|
|
||||||
namespace ClaudeDo.Worker.Lifecycle;
|
namespace ClaudeDo.Worker.Lifecycle;
|
||||||
|
|
||||||
public sealed class StaleTaskRecovery : IHostedService
|
public sealed class StaleTaskRecovery : IHostedService
|
||||||
{
|
{
|
||||||
|
public const string Phase = "stale-tasks";
|
||||||
|
|
||||||
private readonly ITaskStateService _state;
|
private readonly ITaskStateService _state;
|
||||||
|
private readonly HubBroadcaster _broadcaster;
|
||||||
private readonly ILogger<StaleTaskRecovery> _logger;
|
private readonly ILogger<StaleTaskRecovery> _logger;
|
||||||
|
|
||||||
public StaleTaskRecovery(ITaskStateService state, ILogger<StaleTaskRecovery> logger)
|
public StaleTaskRecovery(ITaskStateService state, HubBroadcaster broadcaster, ILogger<StaleTaskRecovery> logger)
|
||||||
{
|
{
|
||||||
_state = state;
|
_state = state;
|
||||||
|
_broadcaster = broadcaster;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,6 +25,8 @@ public sealed class StaleTaskRecovery : IHostedService
|
|||||||
_logger.LogWarning("Stale task recovery: flipped {Count} running task(s) to failed", flipped);
|
_logger.LogWarning("Stale task recovery: flipped {Count} running task(s) to failed", flipped);
|
||||||
else
|
else
|
||||||
_logger.LogInformation("Stale task recovery: no stale tasks found");
|
_logger.LogInformation("Stale task recovery: no stale tasks found");
|
||||||
|
|
||||||
|
await _broadcaster.OperationProgress(OperationProgressOpKeys.StartupRecovery, Phase, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ builder.Services.AddSingleton(sp =>
|
|||||||
builder.Services.AddHostedService(sp => new PlanningLineageRecovery(
|
builder.Services.AddHostedService(sp => new PlanningLineageRecovery(
|
||||||
sp.GetRequiredService<IDbContextFactory<ClaudeDoDbContext>>(),
|
sp.GetRequiredService<IDbContextFactory<ClaudeDoDbContext>>(),
|
||||||
planningSessionsDir,
|
planningSessionsDir,
|
||||||
|
sp.GetRequiredService<HubBroadcaster>(),
|
||||||
sp.GetRequiredService<ILogger<PlanningLineageRecovery>>()));
|
sp.GetRequiredService<ILogger<PlanningLineageRecovery>>()));
|
||||||
builder.Services.AddSingleton<ITerminalLauncher>(sp =>
|
builder.Services.AddSingleton<ITerminalLauncher>(sp =>
|
||||||
new WindowsTerminalLauncher("wt.exe", cfg.ClaudeBin));
|
new WindowsTerminalLauncher("wt.exe", cfg.ClaudeBin));
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using ClaudeDo.Ui.ViewModels;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.Tests;
|
||||||
|
|
||||||
|
// Covers C2: the six Lifecycle/*Recovery startup sweeps broadcast OperationProgress under the
|
||||||
|
// stable "startup-recovery" opKey; the shell replaces the generic "connecting" text with it
|
||||||
|
// while the worker is reconnecting.
|
||||||
|
public class IslandsShellViewModelStartupRecoveryTests
|
||||||
|
{
|
||||||
|
private sealed class ReconnectingWorkerClient : StubWorkerClient
|
||||||
|
{
|
||||||
|
public override bool IsReconnecting => true;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void StartupRecoveryProgress_ReplacesConnectingText()
|
||||||
|
{
|
||||||
|
var vm = new IslandsShellViewModel();
|
||||||
|
var worker = new ReconnectingWorkerClient();
|
||||||
|
vm.Worker = worker;
|
||||||
|
worker.OperationProgressEvent += vm.OnOperationProgress;
|
||||||
|
|
||||||
|
worker.RaiseOperationProgress("startup-recovery", "attachments", 3, 6);
|
||||||
|
|
||||||
|
Assert.Contains("3/6", vm.ConnectionText);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void StartupRecoveryProgress_WithoutTotal_ShowsLabelOnly()
|
||||||
|
{
|
||||||
|
var vm = new IslandsShellViewModel();
|
||||||
|
var worker = new ReconnectingWorkerClient();
|
||||||
|
vm.Worker = worker;
|
||||||
|
worker.OperationProgressEvent += vm.OnOperationProgress;
|
||||||
|
|
||||||
|
worker.RaiseOperationProgress("startup-recovery", "stale-tasks", 0, 0);
|
||||||
|
|
||||||
|
Assert.DoesNotContain("/", vm.ConnectionText);
|
||||||
|
Assert.NotEqual(string.Empty, vm.ConnectionText);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ForeignOpKey_DoesNotChangeConnectionText()
|
||||||
|
{
|
||||||
|
var vm = new IslandsShellViewModel();
|
||||||
|
var worker = new ReconnectingWorkerClient();
|
||||||
|
vm.Worker = worker;
|
||||||
|
worker.OperationProgressEvent += vm.OnOperationProgress;
|
||||||
|
var before = vm.ConnectionText;
|
||||||
|
|
||||||
|
worker.RaiseOperationProgress("merge:task-123", "merging", 0, 0);
|
||||||
|
|
||||||
|
Assert.Equal(before, vm.ConnectionText);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Models;
|
using ClaudeDo.Data.Models;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using ClaudeDo.Worker.Lifecycle;
|
using ClaudeDo.Worker.Lifecycle;
|
||||||
using ClaudeDo.Worker.Tests.Infrastructure;
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
@@ -49,14 +50,18 @@ public sealed class AttachmentOrphanRecoveryTests : IDisposable
|
|||||||
Directory.CreateDirectory(liveDir);
|
Directory.CreateDirectory(liveDir);
|
||||||
Directory.CreateDirectory(orphanDir);
|
Directory.CreateDirectory(orphanDir);
|
||||||
|
|
||||||
|
var hubContext = new CapturingHubContext();
|
||||||
var sut = new AttachmentOrphanRecovery(
|
var sut = new AttachmentOrphanRecovery(
|
||||||
_db.CreateFactory(), store,
|
_db.CreateFactory(), store,
|
||||||
|
new HubBroadcaster(hubContext),
|
||||||
NullLogger<AttachmentOrphanRecovery>.Instance);
|
NullLogger<AttachmentOrphanRecovery>.Instance);
|
||||||
|
|
||||||
await sut.StartAsync(CancellationToken.None);
|
await sut.StartAsync(CancellationToken.None);
|
||||||
|
|
||||||
Assert.True(Directory.Exists(liveDir), "Live task dir should be kept");
|
Assert.True(Directory.Exists(liveDir), "Live task dir should be kept");
|
||||||
Assert.False(Directory.Exists(orphanDir), "Orphan dir should be deleted");
|
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]
|
[Fact]
|
||||||
@@ -66,10 +71,15 @@ public sealed class AttachmentOrphanRecoveryTests : IDisposable
|
|||||||
var missingRoot = Path.Combine(Path.GetTempPath(), $"claudedo_missing_{Guid.NewGuid():N}");
|
var missingRoot = Path.Combine(Path.GetTempPath(), $"claudedo_missing_{Guid.NewGuid():N}");
|
||||||
var store = new AttachmentStore(missingRoot);
|
var store = new AttachmentStore(missingRoot);
|
||||||
|
|
||||||
|
var hubContext = new CapturingHubContext();
|
||||||
var sut = new AttachmentOrphanRecovery(
|
var sut = new AttachmentOrphanRecovery(
|
||||||
_db.CreateFactory(), store,
|
_db.CreateFactory(), store,
|
||||||
|
new HubBroadcaster(hubContext),
|
||||||
NullLogger<AttachmentOrphanRecovery>.Instance);
|
NullLogger<AttachmentOrphanRecovery>.Instance);
|
||||||
|
|
||||||
await sut.StartAsync(CancellationToken.None); // must not throw
|
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.Data.Models;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using ClaudeDo.Worker.Lifecycle;
|
using ClaudeDo.Worker.Lifecycle;
|
||||||
using ClaudeDo.Worker.Tests.Infrastructure;
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
@@ -63,9 +64,14 @@ public sealed class LegacyWorktreeFolderRecoveryTests : IDisposable
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task StartAsync_NoLists_DoesNotThrow()
|
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.StartAsync(CancellationToken.None);
|
||||||
await sut.StopAsync(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 System.Text.Json;
|
||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using ClaudeDo.Worker.Lifecycle;
|
using ClaudeDo.Worker.Lifecycle;
|
||||||
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
@@ -49,7 +51,8 @@ public sealed class PromptFileRecoveryTests
|
|||||||
var orphanPath = Path.Combine(root, "agent.md");
|
var orphanPath = Path.Combine(root, "agent.md");
|
||||||
File.WriteAllText(orphanPath, "leftover");
|
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);
|
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.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.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.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
|
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");
|
File.WriteAllText(orphanPath, "my old customized triage+wait+merge prompt");
|
||||||
|
|
||||||
var logger = new CapturingLogger<PromptFileRecovery>();
|
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);
|
await sut.StartAsync(CancellationToken.None);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using ClaudeDo.Data;
|
using ClaudeDo.Data;
|
||||||
using ClaudeDo.Data.Models;
|
using ClaudeDo.Data.Models;
|
||||||
using ClaudeDo.Data.Repositories;
|
using ClaudeDo.Data.Repositories;
|
||||||
|
using ClaudeDo.Worker.Hub;
|
||||||
using ClaudeDo.Worker.Lifecycle;
|
using ClaudeDo.Worker.Lifecycle;
|
||||||
using ClaudeDo.Worker.Tests.Infrastructure;
|
using ClaudeDo.Worker.Tests.Infrastructure;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
@@ -55,7 +56,8 @@ public sealed class StaleTaskRecoveryTests : IDisposable
|
|||||||
await _tasks.AddAsync(queued);
|
await _tasks.AddAsync(queued);
|
||||||
|
|
||||||
var built = TaskStateServiceBuilder.Build(_db.CreateFactory());
|
var built = TaskStateServiceBuilder.Build(_db.CreateFactory());
|
||||||
var recovery = new StaleTaskRecovery(built.State, NullLogger<StaleTaskRecovery>.Instance);
|
var hubContext = new CapturingHubContext();
|
||||||
|
var recovery = new StaleTaskRecovery(built.State, new HubBroadcaster(hubContext), NullLogger<StaleTaskRecovery>.Instance);
|
||||||
await recovery.StartAsync(CancellationToken.None);
|
await recovery.StartAsync(CancellationToken.None);
|
||||||
|
|
||||||
var r = await _tasks.GetByIdAsync(running.Id);
|
var r = await _tasks.GetByIdAsync(running.Id);
|
||||||
@@ -64,5 +66,8 @@ public sealed class StaleTaskRecoveryTests : IDisposable
|
|||||||
|
|
||||||
var q = await _tasks.GetByIdAsync(queued.Id);
|
var q = await _tasks.GetByIdAsync(queued.Id);
|
||||||
Assert.Equal(TaskStatus.Queued, q!.Status);
|
Assert.Equal(TaskStatus.Queued, q!.Status);
|
||||||
|
|
||||||
|
Assert.Contains(hubContext.Proxy.Calls, c =>
|
||||||
|
c.Method == "OperationProgress" && (string)c.Args[0]! == "startup-recovery");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user