Skip to content

Fix cross-window tab drag removing the wrong tab after a mid-drag list shift - #14347

Closed
2solarmax wants to merge 8 commits into
warpdotdev:masterfrom
2solarmax:2solarmax/cross-window-drag-removes-wrong-tab
Closed

2solarmax wants to merge 8 commits into
warpdotdev:masterfrom
2solarmax:2solarmax/cross-window-drag-removes-wrong-tab

Conversation

@2solarmax

Copy link
Copy Markdown

Description

A cross-window tab drag recorded the source tab's index when the drag started, and the drop removed whatever sat at that index. That index only moves in one situation, when you drag back over the source window's own tab bar and set_source_placeholder_index walks it along with the placeholder. Nothing moves it when the source tab list shifts for a reason the drag did not cause, and a shell exiting is enough to do that with no input from the user at all.

So the drop removed a bystander, closed its shell, and left the dragged tab in place, with both windows then holding a TabData pointing at the same pane group. The existing guard only bounds-checked the index, which does not help: after a tab is removed the stale index is usually still in bounds and just points at the neighbour.

ActiveDrag now captures the dragged pane group's EntityId at drag start, and the three source-cleanup DropResult variants carry that id instead of an index. Dropping the index from those variants is the point of the shape: the stale-index path stops being representable rather than staying guarded.

Three more places on the same gesture needed the same treatment, all found while reviewing the first commit:

  • The put-back branch of perform_handoff. Dropping a tab back onto its own window's tab bar still resolved by the frozen index, and its failure is worse: it unsubscribed and removed a bystander, left the dragged tab's placeholder in place, then re-inserted the real tab, leaving two TabData rows on one pane group in one window.
  • Placeholder rendering and the window snapshot. Both read the same frozen index, so after a mid-drag tab close an innocent tab rendered at zero width, and a save_app during the drag persisted a snapshot that omitted a bystander while keeping the placeholder. The drag model still decides whether to collapse or skip; only the which is now resolved by identity.
  • Removing the last remaining tab. remove_tab treats the last tab as "close the window" via a bare ctx.close_window(), which leaves suppress_detach_panes_on_window_close false, and on_window_closed would then detach the panes of a pane group that now lives in the target window. That path was previously unreachable because the stale index was usually out of bounds and the removal was skipped entirely; resolving by identity reaches it, so it now closes the way the other content-transfer paths do.

Not covered here: reverse_handoff and on_drag_while_inserted are still index-based, but they operate on indices the drag itself owns inside the preview/target, not on the source list, so they are not affected by this class of shift.

Linked Issue

Fixes #14346.

  • The linked issue is labeled ready-to-spec or ready-to-implement

Just filed, so it has not been triaged yet. Flagging for a readiness label. Happy to hold until it is labeled.

Related: #14152 (dragging whole tab groups between windows) builds on this same source-cleanup path. A group transfer removes several source tabs at once, which is where index-based cleanup gets worse, so this is probably worth landing underneath it. The open draft PR #14164 for that issue removes source tabs positionally by {index, count}, so it carries this same defect at higher arity.

Testing

Automated, all ungated so they run in default CI:

  • test_cross_window_drop_removes_the_dragged_tab_not_whatever_took_its_index — seeds a four-tab window, closes tab 0 mid-drag, and asserts the dragged tab is removed and the bystander survives. This is the regression test for the reported bug; on master, with the pre-change API, it removes the bystander and leaves the dragged tab.
  • test_cross_window_drop_of_the_last_source_tab_closes_without_detaching_panes — covers the last-tab path above, asserting the window closes with pane detach suppressed.
  • test_cross_window_drop_ignores_a_source_tab_that_is_already_gone — a drop whose tab vanished mid-drag removes nothing rather than falling back to an index.
  • drag_captures_the_dragged_pane_group_identity — both begin_*_drag entry points capture the id, so cleanup has something to resolve through.

Gates on this branch:

  • cargo clippy -p warp --all-targets --tests -- -D warnings — clean

  • ./script/format --check — clean

  • cargo test -p warp --lib — 13 pre-existing environmental failures (OpenAI key, notebooks fs, telemetry, terminal, path resolution), identical set to master, which shows 15 on the same machine. No drag or tab-group test fails.

  • I have manually tested my changes locally with ./script/run

Not yet — flagging honestly rather than checking the box. The repro needs two windows and a 30-second timer mid-drag, and drag_tabs_to_windows is not in the default feature set, so it needs ./script/run --features drag_tabs_to_windows. I can record it if you would like it before review; the deterministic unit test above covers the same state transition.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-BUG-FIX: Fixed dragging a tab between windows closing the wrong tab when another tab in the source window closed mid-drag.

A cross-window tab drag recorded the source tab's INDEX when the drag
started, and the drop removed whatever sat at that index. Nothing kept the
index in step with the source window's tab list, so anything that closed a
tab mid-drag shifted the list and the drop removed a bystander, while the
dragged tab stayed behind and was then live in two windows at once.

A shell exiting is enough to trigger it: PaneGroup::Event::Exited reaches
handle_file_tree_event and closes that tab. cmd-W and another window handing
a tab off do the same.

The existing guard only bounds-checked the index, which does not help: after
a shift the stale index is usually still in bounds and simply points at the
wrong tab. The log::warn! for a stale index shows the staleness was
anticipated, but only the out-of-bounds half was handled.

ActiveDrag now captures the dragged pane group's EntityId at drag start, and
the three source-cleanup DropResult variants carry that id instead of an
index. Workspace resolves the tab at drop time via
tab_index_for_pane_group_id and skips cleanly if it is already gone. Dropping
the index from those variants makes the stale-index path unrepresentable
rather than merely guarded.

Regression test seeds a four-tab window, closes tab 0 mid-drag, and asserts
the dragged tab is removed and the bystander survives. It fails on master.
Follow-up on the same invariant, from reviewing the first commit.

The put-back branch of perform_handoff still resolved the source tab by the
drag-start index, so dropping a tab back onto its own window's tab bar kept
the original bug: it unsubscribed and removed a bystander, left the dragged
tab's placeholder in place, and then re-inserted the real tab, leaving two
TabData rows pointing at one pane group in one window.

Placeholder rendering and the window snapshot read the same frozen index, so
after a mid-drag tab close an innocent tab rendered at zero width and a
save_app during the drag persisted a snapshot that omitted a bystander. Both
now resolve through the pane group id; the drag model still decides WHETHER
to collapse or skip, only the WHICH is resolved by identity.

Removing the last remaining tab needed its own path. remove_tab treats the
last tab as 'close the window' with a bare ctx.close_window(), which leaves
suppress_detach_panes_on_window_close false, and on_window_closed would then
detach the panes of a pane group that now lives in the target window. That
was previously unreachable because the stale index was usually out of bounds
and the removal was skipped; resolving by identity reaches it, so this path
closes the same way the other content-transfer paths do.

Also drops a duplicated allow(clippy::too_many_arguments) that would have
failed CI under -D warnings.

Tests: identity is captured by both begin_*_drag entry points; the last-tab
drop suppresses pane detach; a drop whose tab already vanished removes
nothing.
The identity helper was inserted between handle_drop_result's doc comment
and the function, so the comment described the wrong thing and
handle_drop_result was left undocumented. Also drops the helper to private,
since both callers are in this file, and renames an index binding that read
like a TabData.
@cla-bot cla-bot Bot added the cla-signed label Jul 27, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Jul 27, 2026
@warp-for-oss

warp-for-oss Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@2solarmax

Every PR must be linked to a same-repo issue before Oz can review it.

This PR is linked to #14346, but no linked issue is marked ready-to-implement yet. Only repository maintainers apply that label, so please wait for a maintainer to mark the issue. Once it is marked, push a new commit or comment /oz-review to re-trigger review.

See the contribution guidelines for the full readiness model.

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@2solarmax

Every PR must be linked to a same-repo issue before Oz can review it.

This PR is linked to #14346, but no linked issue is marked ready-to-implement yet. Only repository maintainers apply that label, so please wait for a maintainer to mark the issue. Once it is marked, push a new commit or comment /oz-review to re-trigger review.

See the contribution guidelines for the full readiness model.

Powered by Oz

@2solarmax

Copy link
Copy Markdown
Author

Rebased onto current master (was 121 behind). Clean merge, mergeable again at fcd33e44, tests and lint green.

This one is only waiting on a readiness label for #14346, which is triaged as bug, repro:high, area:window-tabs-panes but hasn't been marked ready-to-implement yet, so Oz won't review it.

@oss-maintainers — two small asks:

  1. Could someone take a look at Cross-window tab drag removes the wrong tab if the source tab list changes mid-drag #14346 for a readiness label? It's a live data-loss bug on stable (macOS/Windows, DragTabsToWindows is in RELEASE_FLAGS): a cross-window tab drag removes the source tab by an index captured at drag start, so if anything closes a tab mid-drag — a shell exiting is enough — the drop closes a bystander and leaves the dragged tab behind.
  2. Since the PR is blocked on that rather than on me, could you add no-autoclose? Per CONTRIBUTING the staleness clock only resets on my activity, so as it stands I'd have to keep poking the thread just to keep it open.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @2solarmax — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @2solarmax — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

@2solarmax

Copy link
Copy Markdown
Author

Still here and ready — the fix is complete with a regression test, and this PR is waiting on issue #14346 getting a readiness label (only maintainers can apply it), so the blocker is on the review side rather than on me. Per the contribution guidelines, could a maintainer apply no-autoclose? Happy to make any change a reviewer wants.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Hi @2solarmax — a reviewer requested changes on this PR and it hasn't had activity from you in 7 days. When you get a chance, please push updates or reply to the review so a reviewer can take another look. Without activity, this PR will be automatically closed after 14 days of inactivity.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @2solarmax — final reminder: a reviewer requested changes on this PR and it has been inactive for 10 days. It will be automatically closed in about 4 day(s) unless you push updates or reply. Maintainers can apply the no-autoclose label to keep it open.

@github-actions

Copy link
Copy Markdown
Contributor

Closing this pull request because the requested changes have gone unaddressed for over 14 days. If you'd like to continue, push your updates and reopen the PR (or comment to ask a maintainer to reopen) — we'd be glad to pick it back up.

@github-actions github-actions Bot closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-window tab drag removes the wrong tab if the source tab list changes mid-drag

1 participant