Skip to content

Fix nesting worktree groups under threads - #4078

Merged
ymichael merged 10 commits into
mainfrom
bb/fix-dragging-threads-into-worktrees-thr_pex33uqdb4
Sep 23, 2026
Merged

ymichael merged 10 commits into
mainfrom
bb/fix-dragging-threads-into-worktrees-thr_pex33uqdb4

Conversation

@ymichael

@ymichael ymichael commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

This makes a worktree/environment group a valid thread-row drag target, supports dragging it back to a section to unparent it, makes thread nesting less finicky, gives group drags an accurate preview, and applies the whole group optimistically on drop.

What was wrong

Environment-group drags were excluded from the nest-target heuristic, so dropping a Worktree group on a thread row could never establish the requested parent relationship. After adding that path, section drops moved the group section but did not clear its root parent relationships. The heuristic also used a narrow row band, a 350 ms delay, and the dragged card edge for horizontal cancellation, making valid targets easy to miss. The group preview inherited the representative root thread's cached display title, so its floating overlay and projected child looked like one root thread. Group persistence also launched one independent optimistic transaction per root, repeatedly cancelling queries and allowing partial intermediate hierarchy states.

What changed

  • Add a nest-group drop decision that reparents only group root threads, preserving descendants and preventing cycles.
  • Add a symmetric detach-group decision that unparents only group roots while moving the represented group into the target section.
  • Widen the target band to the middle 70%, arm the full row after 200 ms, and use pointer position with 12 px left tolerance.
  • Override the representative root's cached display fields so the overlay and projected child show the group name and root count.
  • Apply synchronous group metadata changes through one cache transaction, one snapshot, and one rollback boundary before persisting the individual requests concurrently.
  • Coalesce synchronous plugin SDK thread metadata updates so the plugin-backed and built-in sidebars share the same optimistic behavior.
  • Mirror the behavior in the built-in sidebar and thread-list plugin, with focused unit coverage.
  • Add HANDOFF.md and before/after reviewer evidence for parenting, unparenting, and the corrected child preview.

How you verified

  • pnpm exec turbo run test --filter=bb-plugin-thread-list --force -- --run app/dnd/useSectionThreadDnd.test.ts app/dnd/useSectionThreadDnd.projection.test.tsx (46 passed)
  • pnpm exec turbo run typecheck --filter=bb-plugin-thread-list --force
  • pnpm exec turbo run test --filter=@bb/app --force -- --run src/hooks/mutations/thread-state-mutations.test.tsx src/lib/plugin-bound-sdk.test.ts src/components/sidebar/useSectionThreadDnd.test.ts src/components/sidebar/useSectionThreadDnd.projection.test.tsx (65 passed)
  • pnpm exec turbo run typecheck --filter=@bb/app --force
  • pnpm exec turbo run typecheck --filter=@get-bb/plugin-sdk --force
  • Source-app smoke tests: group parenting and section-drop unparenting persisted for both worktree roots, preserved the group, updated immediately, and survived reload. The overlay and projected child both show Reviewer worktree group (2 threads).
  • Delayed-network smoke: with both PATCH requests held for 30 seconds, the complete group moved immediately while zero requests had been dispatched and direct GETs still showed the old persisted parent.

Related: #3029

AGENT GENERATED

@ymichael
ymichael force-pushed the bb/fix-dragging-threads-into-worktrees-thr_pex33uqdb4 branch 4 times, most recently from 5632fa6 to 81a5e10 Compare September 23, 2026 20:06
@ymichael
ymichael force-pushed the bb/fix-dragging-threads-into-worktrees-thr_pex33uqdb4 branch from b467c90 to c3db162 Compare September 23, 2026 20:34
@ymichael
ymichael force-pushed the bb/fix-dragging-threads-into-worktrees-thr_pex33uqdb4 branch from c3db162 to b6c4c32 Compare September 23, 2026 20:51
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@ymichael
ymichael merged commit 239eb2f into main Sep 23, 2026
40 of 42 checks passed
@ymichael
ymichael deleted the bb/fix-dragging-threads-into-worktrees-thr_pex33uqdb4 branch September 23, 2026 21:37
ymichael added a commit that referenced this pull request Sep 23, 2026
## Human comments

## What was wrong

#4078 made worktree groups draggable onto threads, into sections, and
into and out of Pinned by adding a group copy of every drop decision
(`nest-group`, `detach-group`, `pin-group`, `unpin-group`, next to
`move-group`). Each copy had its own resolver branch, landed check, and
handler, so single-thread and group drops had to be fixed twice and
drifted: group drags did nothing in grouped (project/machine) mode, a
group pin ignored the Pinned insert marker it displayed, and group
section moves rewrote `sectionId` on every nested descendant even though
nested threads follow their parent. A worktree group is only a display
grouping, so it is really a list of top-level threads — the same thing
as a single-thread drag with one entry.

## What changed

`plugins/thread-list/app/dnd/useSectionThreadDnd.ts` (1742 → 1422
lines):
- A dragged item resolves to its top-level threads: `[thread]`, or a
group's `nodes`.
- Decisions shrink to `move` (covers move, detach, and unpin into a
section), `nest`, and `pin`, plus the unchanged
`reorder-pinned`/`rejected`/`unchanged`. Each carries the exact
`unpinThreadIds`, `updates`, and `pinThreadIds` for its threads,
computed per thread from its own pin and nesting state.
- One executor applies unpin → updates → pin, toasts once if an update
fails, and stops before pinning.
- Pinned inserts chain one request per thread so a group lands together
at the marker, and use the pinned thread order rather than sortable item
ids. That fixes #4078's pinned grouping sending an `environment:` item
id as a neighbour thread.

Behaviour changes that follow from applying one rule to both:
- Group drags work in grouped mode, with the same rules as single
threads there.
- Group section moves write only the top-level threads.
- Dropping a group back into its own section, or a pinned group back
into Pinned, shows the "unchanged" state instead of nothing.
- Nesting the child of a pinned thread no longer sends a redundant
unpin.
- Failure toasts read "Failed to move thread(s)." / "Failed to pin
thread(s)."; "Failed to unpin and move thread." and the "worktree group"
wording are gone.
- A thread whose stored section differs from where it is displayed gets
its section rewritten when dropped in its displayed section (previously
treated as unchanged).

Also removes the unused `useUpdateThreads` hook (and its tests) from
`apps/app`; the plugin SDK's update batching stays.

No wire, CLI, SDK, or guide changes.

## How you verified

- Rewrote the decision tests for the new shape, including group
nest/move/pin/unpin, grouped mode, own-descendant rejection, the
unchanged cases, chained pinned inserts, and thread neighbours next to a
pinned environment group.
- New projection test: a group whose un-parenting fails is not pinned.
It fails when the executor keeps going after a failed update.
- `pnpm exec turbo run typecheck lint test
--filter=bb-plugin-thread-list --filter=@bb/app` passes (thread-list 434
tests; app 5059 passed, 5 skipped).
- Rebuilt and ran `pnpm start:worktree` from this change for manual
testing.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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