Skip to content

fix(tui): keep the TUI responsive while supervised turns and actions run - #655

Merged
mohitranka merged 1 commit into
mainfrom
fix/tui-responsiveness-plan
Sep 12, 2026
Merged

mohitranka merged 1 commit into
mainfrom
fix/tui-responsiveness-plan

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Problem

Supervised UI actions awaited supervisor command completion while an actor held its session lock for a whole turn. Choosing a model, stopping a turn, or cancelling a background task could freeze input and rendering until the turn ended — Stop itself became unreachable from that UI.

Changes

  • Non-blocking command dispatch — SupervisorHandle::submit queues a command and returns its completion receiver. The TUI submits via submit_session_command / submit_session_command_tracked and applies CommandFollowUp results on the application tick. All former send_session_command callers migrated; success, rollback, and quit semantics stay truthful.
  • Lock-free background controls — forge_core::BackgroundControl mirrors each live task's cancellation token and subagent approval sender into an Arc-shared map kept in sync by BackgroundTaskRegistry (spawn, token replace, terminal, remove). SessionActor holds a clone, so CancelBackgroundTask / ResolveBackgroundApproval reach a busy actor and publish immediately only when the session lock is free.
  • Cancellable stream completion — the final drain in run_model_step_with_stream observes cancellation instead of waiting on a channel a sender-retaining provider never closes.
  • Off-thread explorer refresh — FileExplorer walks loaded directories on a spawn_blocking worker with generation and coalescing tracking, installing only while still current. Expand/collapse invalidate an in-flight snapshot so a stale result cannot overwrite it.
  • AGENTS.md — targeted tests only, never the full workspace suite.

Tests

  • tracked_command_applies_after_a_busy_turn_without_blocking_input — gated supervised turn keeps input live and applies the queued model change later (forge-tui).
  • control_signals_cancel_and_hitl_without_a_session (forge-core) and extended unrelated_session_commands_progress_while_another_turn_holds_its_actor, which now asserts both controls answer while a gated turn still holds its actor (forge-session).
  • final_drain_observes_turn_cancel_when_provider_retains_sender (forge-core).
  • Async explorer refresh, stale-drop, and expand-during-refresh guards (forge-tui).

Validation

  • forge-core 272 passed, forge-session 71 passed
  • forge-tui targeted: app::tests::tasks 6, app::tests::multi_task 28, app::tests::commands 66, file_explorer:: 37, watch:: 12, responsiveness_tests 5
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --locked -- -D warnings clean
  • cargo build --release --locked --package forge-cli + forge --version OK

Supervised UI actions awaited command completion while an actor held its
session lock for an entire turn, so choosing a model, stopping a turn,
or cancelling a background task could freeze input and rendering; Stop
itself became unreachable.

- Queue supervisor commands without awaiting execution:
  SupervisorHandle::submit returns the completion receiver, the TUI
  applies CommandFollowUp results on the application tick, and every
  former send_session_command caller is migrated with success,
  rollback, and quit semantics preserved.
- Mirror each live background task's cancellation token and subagent
  approval sender into an Arc-shared BackgroundControl kept in sync by
  BackgroundTaskRegistry. SessionActor holds a clone, so
  CancelBackgroundTask and ResolveBackgroundApproval reach a busy actor
  and publish immediately only when the session lock is free.
- Make the final stream drain observe cancellation instead of waiting
  on a channel a sender-retaining provider never closes.
- Walk the explorer's loaded directories on a blocking worker with
  generation and coalescing tracking; expand/collapse invalidate an
  in-flight snapshot so a stale result cannot overwrite it.
- AGENTS.md: targeted tests only, never the full workspace suite.

Regression tests cover the gated supervised turn, lock-free background
signalling, the leaky stream sender, and async explorer refresh.

Validated: forge-core 272, forge-session 71, forge-tui targeted
modules, fmt, clippy -D warnings, and release build.
@mohitranka
mohitranka merged commit 06fccf3 into main Sep 12, 2026
3 checks passed
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