Skip to content

Fix DirectoryWidget freeze when cancelling workers#110

Merged
presstab merged 4 commits intomasterfrom
dirtree_fix
Jul 14, 2025
Merged

Fix DirectoryWidget freeze when cancelling workers#110
presstab merged 4 commits intomasterfrom
dirtree_fix

Conversation

@presstab
Copy link
Owner

Overview

This pull request resolves a critical bug in the Textual UI where the DirectoryWidget would become unresponsive after cancelling running tasks. The issue stemmed from the global workers.cancel_all() call inadvertently affecting UI components. The fix introduces targeted worker management, ensuring only application-level workers are cancelled while preserving UI responsiveness.

What This Means for Users

Users can now safely cancel long-running operations without the file browser locking up. Previously, hitting the stop button could leave the directory tree in an unusable state; the interface now remains fully interactive after cancellation.

A Closer Look at the Changes

  • Worker lifecycle management

    • Added launched_workers: List[Worker] to track only the workers created by the application.
    • Replaced the blanket workers.cancel_all() with a targeted loop that cancels only workers in launched_workers.
    • Workers are automatically removed from the list once they reach a terminal state (SUCCESS, ERROR, or CANCELLED), preventing memory leaks.
  • Minor refinements

    • Improved error logging in the router agent by including the raw JSON substring when parsing fails.
    • Clarified the router prompt to emphasize that /code should be used for any code generation or editing.
    • Fixed curses import placement for broader platform compatibility.
    • Disabled auto-scroll in the Git diff viewer for easier reading of large diffs.
      Generated by JrDev AI using moonshotai/kimi-k2

presstab added 4 commits July 14, 2025 08:53
- Add raw JSON content to error logs when parsing fails
- Initialize json_content variable to prevent unbound variable errors
- Clarify router prompt to emphasize /code command usage
…targeted cancellation

- Introduce `launched_workers` list to keep references of active workers
- Replace `workers.cancel_all()` with selective cancellation of tracked workers
- Clean up finished workers from the list on state change
- DirectoryTree widget was being frozen from `workers.cancel_all()` as the tree has a worker watching the tree
@presstab presstab merged commit f6744ad into master Jul 14, 2025
@presstab presstab deleted the dirtree_fix branch July 14, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant