on main help sign in
fix(ui): clean up nested tool IDs in RemoveMessage

RemoveMessage only deleted the top-level item ID from idInxMap but left nested tool IDs pointing to the removed item's index. After rebuilding, those stale IDs would point to whatever item shifted into that position, causing animation ticks to be routed to the wrong item. Now cleans up nested IDs before removal and updates them during the rebuild.

commit19eb38a5e086836d4ba2781c05c0210d22f5f54e authoriko <mail@iko.soy> dateThu 9 Jul 2026, 03:44 (3 months ago) parent68c5026
1 file changed+18
internal/ui/model/chat.go+18
internal/ui/model/chat.go+18
@@ -673,6 +673,18 @@ func (m *Chat) RemoveMessage(id string) {
673673 return
674674 }
675675
676+ // Clean up nested tool IDs that point to this item's index before
677+ // removing it, so they don't end up pointing to a wrong item after
678+ // the rebuild.
679+ if item, ok := m.list.ItemAt(idx).(chat.MessageItem); ok {
680+ if container, ok := item.(chat.NestedToolContainer); ok {
681+ for _, nested := range container.NestedTools() {
682+ delete(m.idInxMap, nested.ID())
683+ delete(m.pausedAnimations, nested.ID())
684+ }
685+ }
686+ }
687+
676688 // Remove from list
677689 m.list.RemoveItem(idx)
678690
@@ -683,6 +695,12 @@ func (m *Chat) RemoveMessage(id string) {
683695 for i := idx; i < m.list.Len(); i++ {
684696 if item, ok := m.list.ItemAt(i).(chat.MessageItem); ok {
685697 m.idInxMap[item.ID()] = i
698+ // Also update nested tool IDs for containers.
699+ if container, ok := item.(chat.NestedToolContainer); ok {
700+ for _, nested := range container.NestedTools() {
701+ m.idInxMap[nested.ID()] = i
702+ }
703+ }
686704 }
687705 }
688706