Skip to content

fix: hierarchy drag crash, persistence loss, stale layout tabs - #123

Merged
aterrylu merged 3 commits into
mainfrom
terry/hierarchy-bugs
Apr 11, 2026
Merged

fix: hierarchy drag crash, persistence loss, stale layout tabs#123
aterrylu merged 3 commits into
mainfrom
terry/hierarchy-bugs

Conversation

@aterrylu

Copy link
Copy Markdown
Owner

Summary

Fixes three related bugs in the sidebar hierarchy and layout persistence:

  • Drag crash in hierarchy mode — dragging agents in hierarchy view could crash the page by accidentally activating the layout DropZoneOverlay. Hierarchy drag now stays sidebar-only.
  • Manager/hierarchy persistence losspersistSession() did full-entry replacement, silently losing manager/template/project fields on resume. Now merges with ?? fallback.
  • Stale layout tabs — killed sessions left ghost tabs in the persisted layout. New pruneStaleSessionTabs() cleans them up on every poll, including on fresh page load from localStorage.

Changes

File What
Sidebar.tsx Remove startDrag()/endDrag() from hierarchy drag handlers; add minimal setData for browser compat
layoutTree.ts Add pruneStaleSessionTabs() — recursive tree walker that removes dead session tabs
store.ts Call pruneStaleSessionTabs after fetchSessions; reset groups on full prune; run prune even when session list unchanged
persisted.ts Merge fields in persistSession() instead of full replace; guard status/manager/template/project with ??

Test plan

  • make check — lint, typecheck, 70 tests pass
  • Drag-to-reorder in hierarchy mode — should not crash
  • Set up multi-level hierarchy, restart server, verify managers persist
  • Kill a session, verify its tab is cleaned up from the layout
  • Reload dashboard with stale localStorage, verify ghost tabs are pruned

🤖 Generated with Claude Code

@nox-0x nox-0x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Solid fixes. Hierarchy drag isolation is clean, the merge logic in persistSession correctly handles undefined fields, and pruneStaleSessionTabs correctly handles all edge cases (empty prune, single-side prune, activeTabIndex clamping). Good defensive work.

@aterrylu
aterrylu marked this pull request as ready for review April 11, 2026 06:17
aterrylu and others added 3 commits April 10, 2026 23:18
Three related fixes for the sidebar hierarchy and layout persistence:

1. **Drag crash in hierarchy mode** — hierarchy drag handlers were calling
   startDrag() which activated the layout DropZoneOverlay. When dropping
   across tree levels, the overlay tried to split/move panes and crashed.
   Fix: hierarchy drag is sidebar-only reordering, no longer triggers
   layout DragContext.

2. **Manager/hierarchy persistence loss** — persistSession() did full-entry
   replacement, losing manager/template/project when called without those
   fields (e.g. during resume). Fix: merge fields with ?? fallback to
   preserve existing values for optional metadata.

3. **Stale layout tabs** — killed/exited sessions left ghost tabs in the
   persisted layout tree. The X button on the last ghost tab was a no-op
   (removeLeaf returns null for root). Fix: pruneStaleSessionTabs() runs
   after every fetchSessions poll, removing tabs for dead sessions and
   collapsing empty leaves. Also runs on unchanged session lists to clean
   up stale localStorage on page load.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests cover: single leaf (valid/stale/mixed tabs, activeTabIndex
clamping), non-session tabs (orgchart/templates/preview never pruned),
branch trees (collapse when children stale, deep nesting), referential
equality preservation, and edge cases (empty leaf, extra valid IDs).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aterrylu
aterrylu force-pushed the terry/hierarchy-bugs branch from f54b24a to d4aac84 Compare April 11, 2026 06:18
@aterrylu
aterrylu merged commit 17f7ec8 into main Apr 11, 2026
1 check passed
@aterrylu
aterrylu deleted the terry/hierarchy-bugs branch April 11, 2026 06:19

@nox-0x nox-0x left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clean, well-scoped fix for three distinct bugs. pruneStaleSessionTabs is correct (referential equality shortcut is sound, activeTabIndex clamping is right, null-collapse propagates correctly up the tree), persistSession merge with ?? is the right fix for undefined clobbering, and Sidebar drag isolation is the correct fix for the DropZoneOverlay crash. Comprehensive test coverage. LGTM.

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.

2 participants