Skip to content

[CTX-1457] fix(ui): prune the emptied workspace when its last shell exits (#2525) - #2535

Merged
Xuepoo merged 2 commits into
mainfrom
ctx-1457/fix-last-panel-exit
Oct 23, 2026
Merged

Xuepoo merged 2 commits into
mainfrom
ctx-1457/fix-last-panel-exit

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Priority: P0 | Area: area:stability | Labels: fix,P0,area:stability | Milestone: v0.0.27 | RFC: - | Task: CTX-1457

Problem

Reported in #2525: after layout churn (many panels/workspaces, deletes, resizes,
fullscreen), the last panel of a workspace hangs on exit/Ctrl+D and sometimes
stays behind as a ghost. The shell is gone but the tile stays focused and
silently drops input.

Deterministic repro on an isolated Xvfb instance (own PIDs, no desktop
interaction):

  1. open three workspaces (each gets a shell),
  2. send exit to the active workspace's only panel.

Before this change: the workspace stayed with a session-less tile, has_session=false,
and the focused view no longer had an input path. The primary path had the same
defect: it logged closing primary pane, but close_focused_leaf refuses a
singleton layout, leaving the dead primary tile in place.

Root cause

TerminalApp::reap_exited_shells did not mirror the close-view workspace
prune (CTX-1297). Exiting the last panel of a workspace is a panel close, and
the close gesture prunes the emptied workspace and follows focus to a surviving
one. The reap path instead kept a session-less tile by design ("CTX-1044"),
which wedges input; the primary branch additionally relied on
close_focused_leaf, which cannot remove a workspace's only leaf.

Fix

  • Add Runtime::workspace_index_of_view / workspace_panel_counts (the latter
    returns (tiled, floats); active slot from the live layout, inactive slots
    from their stash).
  • In the pane-shell exit path, when the dead view was the sole panel of its
    workspace and another workspace survives (no floats/pins), prune that
    workspace exactly like the close-view gesture instead of keeping a ghost.
  • Apply the same rule to the primary-shell exit path before the singleton
    layout surgery.
  • Keep the existing pinned/float/scratchpad handling untouched.

Review fix: zoom backup on inactive workspaces

An inactive workspace stores its zoom proxy (one leaf) as its stashed
layout while the real tree lives in the app-side zoom backup keyed by workspace
sequence. The prune decision must read the backup:

  • New TerminalApp::workspace_real_panel_count substitutes
    chrome.zoom.backup_leaf_ids_for_seq(workspace_seq_at(index)) for the stashed
    tiled count, keeping the slot's float count.
  • Both prune paths use it, so a zoomed pane exiting in a background workspace
    with a hidden live pane no longer reads as a singleton and no longer prunes
    the workspace. It falls through to the leaf path instead.

Regression coverage

  • reap_exited_zoomed_pane_in_inactive_workspace_keeps_workspace (new):
    ws1 has two panes, pane A zoomed, switch to ws2, A exits — workspace count
    stays 2, the hidden pane's session and real-tree leaf survive.
  • reap_exited_pane_in_inactive_workspace_prunes_emptied_workspace (new):
    inactive sole-pane exit still prunes.
  • reap_exited_last_leaf_of_workspace_prunes_the_workspace (updated),
    reap_exited_primary_last_leaf_of_workspace_prunes_workspace (new).
  • workspace_panel_counts_and_view_owner_cover_active_and_stashed_slots
    (new runtime helper unit test).
  • All 19 reap_exited_*, 14 close_view_*, and 20 workspace_* tests pass;
    fmt and clippy -D warnings clean.

Verified on the real event loop with the release binary: exiting the active
workspace's only panel (and Ctrl+D on the primary) prunes the workspace, keeps
the surviving workspace's live shell focused, and the app stays responsive.
A single-workspace last shell still exits in ~125 ms with the session save.

Residuals (this PR does not close #2525)

  • The Wayland/Hyprland "Application Not Responding" after long layout churn was
    not reproduced here: 25+ minutes of real-key churn (7 panes, btop, zoom,
    fullscreen, resizes, 7-shell workspace close) on isolated Xvfb stayed
    responsive (12-57 threads, 58-118 fds, no watchdog stall). The remaining
    freeze is likely compositor/GPU-present specific; the owner's process was
    once observed in drm_syncobj_array_wait_timeout, and the stall watchdog is
    still opt-in.
  • Follow-up: capture the opt-in watchdog report (BITTY_STALL_WATCHDOG=1) on
    the next Wayland occurrence, and audit the synchronous wgpu
    get_current_texture wait (1 s acquire timeout) plus serial PTY teardown
    joins during pane/workspace close.
  • Zoom-backup leaf surgery for a non-singleton inactive zoomed workspace (the
    dead zoomed leaf in the backup) remains the pre-existing leaf-path behavior;
    this fix only prevents the unsafe prune.
  • [0.0.27] Workspace ids keep increasing after deletion instead of reusing free ids #2532 workspace-id churn is the trigger scenario used for the repro, not an
    allocator fix.

Refs #2525, #2454, #2488

@Xuepoo Xuepoo added this to the v0.0.27 milestone Oct 22, 2026
@Xuepoo Xuepoo added fix Bug fix P0 Priority: highest area:stability Stability hardening labels Oct 22, 2026
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d6b5bef3-74d0-4a9b-9857-6ce32adaefae
📥 Commits

Reviewing files that changed from the base of the PR and between 4b740cf and 550f3b8.

📒 Files selected for processing: 3
  • crates/bitty-runtime/src/runtime/workspaces.rs
  • crates/bitty-terminal/src/terminal_app.rs
  • crates/bitty-terminal/src/tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Xuepoo

Xuepoo commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Review NEEDS-FIX addressed in 2f5c53f.

  • New TerminalApp::workspace_real_panel_count substitutes chrome.zoom.backup_leaf_ids_for_seq(workspace_seq_at(index)) for the stashed tiled count (floats preserved), and both prune paths use it. A zoomed inactive workspace with a hidden live pane now reads 2 and skips the prune, falling through to the leaf path.
  • New regressions: reap_exited_zoomed_pane_in_inactive_workspace_keeps_workspace (ws1 has 2 panes, zoom A, switch to ws2, A exits → workspace_count 2, hidden session + backup leaf survive), reap_exited_pane_in_inactive_workspace_prunes_emptied_workspace (inactive prune still works), plus a runtime helper unit test for workspace_panel_counts/workspace_index_of_view.
  • Verified locally: 19 reap_exited tests, 14 close_view tests, 20 workspace tests pass; fmt/clippy -D warnings clean. CI is running on the new head.

@Xuepoo
Xuepoo force-pushed the ctx-1457/fix-last-panel-exit branch from 2f5c53f to 8e34d83 Compare October 22, 2026 21:27
@Xuepoo
Xuepoo force-pushed the ctx-1457/fix-last-panel-exit branch from 8e34d83 to 550f3b8 Compare October 23, 2026 01:50
@Xuepoo
Xuepoo merged commit a311681 into main Oct 23, 2026
20 checks passed
@Xuepoo
Xuepoo deleted the ctx-1457/fix-last-panel-exit branch October 23, 2026 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:stability Stability hardening fix Bug fix P0 Priority: highest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.0.27] Bitty freezes and terminates by itself after <=15 minutes

1 participant