fix(ui): dispose VM subscriptions/timers, guard offline Stop, align review delta-path
- DetailsIslandViewModel/TasksIslandViewModel/ListsIslandViewModel: implement IDisposable, unsubscribe Loc.LanguageChanged and worker events (memory leaks). - IslandsShellViewModel: dispose the three System.Timers.Timer instances. - StopAsync: guard on Task/IsRunning/IsConnected and wrap CancelTask in try/catch. - TaskMatchesList virtual:review now matches WaitingForReview (aligns with ReviewFilter). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -46,13 +46,21 @@ public sealed class LogLineViewModel
|
||||
};
|
||||
}
|
||||
|
||||
public sealed partial class DetailsIslandViewModel : ViewModelBase
|
||||
public sealed partial class DetailsIslandViewModel : ViewModelBase, IDisposable
|
||||
{
|
||||
private readonly IDbContextFactory<ClaudeDoDbContext> _dbFactory;
|
||||
private readonly IWorkerClient _worker;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly INotesApi _notesApi;
|
||||
|
||||
// Captured handler delegates for disposal
|
||||
private readonly EventHandler _langChangedHandler;
|
||||
private readonly System.ComponentModel.PropertyChangedEventHandler _workerPropertyChangedHandler;
|
||||
private readonly Action<string, string, DateTime> _workerTaskStartedHandler;
|
||||
private readonly Action<string, string, string, DateTime> _workerTaskFinishedHandler;
|
||||
private readonly Action<string> _workerWorktreeUpdatedHandler;
|
||||
private readonly Action<string> _workerTaskUpdatedHandler;
|
||||
|
||||
[ObservableProperty] private bool _isNotesMode;
|
||||
[ObservableProperty] private bool _isPrepMode;
|
||||
[ObservableProperty] private bool _isPrepRunning;
|
||||
@@ -501,13 +509,14 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
||||
_notesApi = notesApi;
|
||||
Notes = new NotesEditorViewModel(_notesApi);
|
||||
Subtasks.CollectionChanged += (_, _) => NotifyStepsChanged();
|
||||
Loc.LanguageChanged += (_, _) =>
|
||||
_langChangedHandler = (_, _) =>
|
||||
{
|
||||
OnPropertyChanged(nameof(AgentStatusLabel));
|
||||
RecomputeModelBadge();
|
||||
RecomputeTurnsBadge();
|
||||
RecomputeAgentBadge();
|
||||
};
|
||||
Loc.LanguageChanged += _langChangedHandler;
|
||||
|
||||
// Subscribe once; filter by current task id inside the handler
|
||||
_worker.TaskMessageEvent += OnTaskMessage;
|
||||
@@ -516,7 +525,7 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
||||
_worker.PrepFinishedEvent += OnPrepFinished;
|
||||
|
||||
// Re-evaluate CanExecute when worker connection flips.
|
||||
_worker.PropertyChanged += (_, e) =>
|
||||
_workerPropertyChangedHandler = (_, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(WorkerClient.IsConnected))
|
||||
{
|
||||
@@ -526,14 +535,17 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
||||
ContinueCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
};
|
||||
_worker.PropertyChanged += _workerPropertyChangedHandler;
|
||||
|
||||
// If the task row's live status changes (e.g. TaskStarted/Finished), mirror it.
|
||||
_worker.TaskStartedEvent += (slot, taskId, startedAt) =>
|
||||
_workerTaskStartedHandler = (slot, taskId, startedAt) =>
|
||||
{
|
||||
if (Task?.Id == taskId) AgentState = "running";
|
||||
_ = RefreshChildOutcomeAsync(taskId);
|
||||
};
|
||||
_worker.TaskFinishedEvent += (slot, taskId, status, finishedAt) =>
|
||||
_worker.TaskStartedEvent += _workerTaskStartedHandler;
|
||||
|
||||
_workerTaskFinishedHandler = (slot, taskId, status, finishedAt) =>
|
||||
{
|
||||
if (Task?.Id != taskId) return;
|
||||
FlushClaudeBuffer();
|
||||
@@ -548,20 +560,23 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
||||
_ = RefreshChildOutcomeAsync(taskId);
|
||||
_ = RefreshOutcomeAsync(taskId);
|
||||
};
|
||||
_worker.TaskFinishedEvent += _workerTaskFinishedHandler;
|
||||
|
||||
_worker.WorktreeUpdatedEvent += taskId =>
|
||||
_workerWorktreeUpdatedHandler = taskId =>
|
||||
{
|
||||
if (Task?.Id == taskId) _ = RefreshWorktreeAsync(taskId);
|
||||
if (Task?.IsPlanningParent == true) _ = RefreshPlanningChildAsync(taskId);
|
||||
_ = RefreshChildOutcomeAsync(taskId);
|
||||
};
|
||||
_worker.WorktreeUpdatedEvent += _workerWorktreeUpdatedHandler;
|
||||
|
||||
_worker.TaskUpdatedEvent += taskId =>
|
||||
_workerTaskUpdatedHandler = taskId =>
|
||||
{
|
||||
if (Task?.Id == taskId) _ = RefreshStatusAsync(taskId);
|
||||
if (Task?.IsPlanningParent == true) _ = RefreshPlanningChildAsync(taskId);
|
||||
_ = RefreshChildOutcomeAsync(taskId);
|
||||
};
|
||||
_worker.TaskUpdatedEvent += _workerTaskUpdatedHandler;
|
||||
|
||||
Subtasks.CollectionChanged += (_, _) =>
|
||||
{
|
||||
@@ -579,6 +594,20 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
||||
PrepLog.CollectionChanged += (_, _) => OnPropertyChanged(nameof(ShowPrepEmptyState));
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Loc.LanguageChanged -= _langChangedHandler;
|
||||
_worker.PropertyChanged -= _workerPropertyChangedHandler;
|
||||
_worker.TaskStartedEvent -= _workerTaskStartedHandler;
|
||||
_worker.TaskFinishedEvent -= _workerTaskFinishedHandler;
|
||||
_worker.WorktreeUpdatedEvent -= _workerWorktreeUpdatedHandler;
|
||||
_worker.TaskUpdatedEvent -= _workerTaskUpdatedHandler;
|
||||
_worker.TaskMessageEvent -= OnTaskMessage;
|
||||
_worker.PrepStartedEvent -= OnPrepStarted;
|
||||
_worker.PrepLineEvent -= OnPrepLine;
|
||||
_worker.PrepFinishedEvent -= OnPrepFinished;
|
||||
}
|
||||
|
||||
private void OnTaskMessage(string taskId, string line)
|
||||
{
|
||||
if (taskId != _subscribedTaskId) return;
|
||||
@@ -1412,8 +1441,10 @@ public sealed partial class DetailsIslandViewModel : ViewModelBase
|
||||
[RelayCommand]
|
||||
private async System.Threading.Tasks.Task StopAsync()
|
||||
{
|
||||
if (Task == null) return;
|
||||
await _worker.CancelTaskAsync(Task.Id);
|
||||
if (Task == null || !IsRunning) return;
|
||||
if (!_worker.IsConnected) return;
|
||||
try { await _worker.CancelTaskAsync(Task.Id); }
|
||||
catch { /* offline */ }
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanEnqueue))]
|
||||
|
||||
Reference in New Issue
Block a user