perf(tui): offload task archive to background worker#194
Merged
Conversation
Archiving a task synchronously kills tmux sessions, removes worktrees, archives attached agents and rewrites meta — enough work to stall the TUI event loop and freeze rendering for hundreds of ms. Reuse the respawn async pattern: `archive_in_progress` tracks task ids currently being archived; `archive_task` removes the row from `self.tasks` synchronously, marks the id in-progress, clamps selection, and spawns `use_cases::archive_task` via `tokio::spawn_blocking`. The result channel is drained by `apply_archive_results` from the main loop, which clears the in-progress entry and surfaces success/failure to the status line. `refresh_tasks_for_project` filters out in-progress task ids so the periodic disk-backed refresh cannot flicker the row back between the optimistic remove and the worker writing `archived_at`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
App::archive_tasknow does only sync UI work (remove row, mark in-progress, clamp selection, status) and offloadsuse_cases::archive_taskviatokio::task::spawn_blocking. Results are drained from a new mpsc channel byapply_archive_resultsin the main loop.refresh_tasks_for_projectfilters out task ids inarchive_in_progressso the 1Hz refresh can't resurrect the row before the worker writesarchived_at.use_caseschanges; scope deliberately narrow per researcher recommendationtui-blocking-archive-ops.Test plan
cargo fmt -- --checkcargo clippy --all-targets -- -D warningscargo test(all suites pass; 17 + 38 + 3 + 3 + 16 + 8 + 7 + 32 + 5 + 3 + 6 + 19 + 2 + 20)archive_task_marks_in_progress_and_refresh_does_not_re_add_taskproves the in-progress filter gates the refresharchive_task_inserts_task_id_into_archive_in_progresscovers the synchronous side-effects🤖 Generated with Claude Code