Repository navigation
fix(tui): quit when the closing session fails to retire - #699
Merged
Merged
Conversation
`/quit` closed the selected session first and only exited when that close reported success. Retirement is best-effort and time-boxed (5s for the driver to stop, 5s for the session lock, 5-6s for resource retirement), so a workspace that takes longer than that to release makes `CloseSession` fail. The `Quit` follow-up had no failure branch, so the reply was dropped on the floor and `run_loop` kept spinning: the session could not be quit at all. Exit once the last session's close has resolved either way, and take the same fallback when the close cannot even be queued. Leaving cleanup unfinished is safe because the supervisor reconciles leftover actors and worktrees on the next launch. With a sibling still active, a failed close keeps the app running as before.
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.
Root cause
/quitclosed the selected session first and only exited when that closereported success (
CommandFollowUp::Quitincrates/forge-tui/src/app/input.rs,documented as "Quit once the selected session's
CloseSessionsucceeds").There was no failure branch, so a failed close was dropped and
run_loop'swhile !app.exit.is_requested()kept spinning — an unquittablesession.
The close fails deterministically past ~5s because retirement is time-boxed:
crates/forge-session/src/supervisor.rs:2418— 5s for the driver to clearcrates/forge-session/src/supervisor.rs:2432— 5s for the session lockcrates/forge-session/src/supervisor.rs:2445— 6s forretire_resourcescrates/forge-core/src/background.rs:704— 5s deadline for background tasksA background shell, subagent, or in-flight provider call that outlives that
window makes
CloseSessionfail, which then vetoed the quit.Supporting evidence that the coupling is incidental, not required:
Ctrl+D(
crates/forge-tui/src/app/workspace.rs:152) exits directly without closing asession, so it never hangs.
Fix
Treat the close as cleanup, not a precondition for quitting:
CommandFollowUp::Quitnow exits on failure too, throughTuiApp::request_quit_after_deferred_cleanup./quittakes the same fallback when the close cannot even be enqueued(
SupervisorHandle::submitreturnsFull/Closed).Unfinished cleanup is safe: the supervisor's
reconcile_worktreesalready runson the next launch.
Tests
quit_exits_even_when_the_last_session_close_fails— fails on the old logic("a failed close on the last session must still quit"), passes now.
quit_with_a_sibling_stays_running_when_the_close_failsBoth inject a failed close reply into the tracked completion, which is exactly
what the retirement deadline produces.
cargo test --package forge-tui --locked app::tests::multi_task— 38 passedcargo test --package forge-tui --locked app::tests::commands— 69 passedcargo fmt --all -- --checkcleancargo clippy --package forge-tui --all-targets --locked— no errorsNot in this PR
block
RemoveManagedWorktree.Shutdownuses the same deadlines and propagates the failure, so a slow draincan still surface as a
TuiErroron exit rather than a clean quit.