snapshotItems returns a copy of s.Messages safe to use without holding s.mu. Each Message value is deep-copied so concurrent UpdateMessage calls cannot mutate the snapshot; non-Message fields (Summary, SubSession, Cost, FirstKeptEntry) are shallow-copied since they are not mutated in place.
()
| 436 | // cannot mutate the snapshot; non-Message fields (Summary, SubSession, Cost, |
| 437 | // FirstKeptEntry) are shallow-copied since they are not mutated in place. |
| 438 | func (s *Session) snapshotItems() []Item { |
| 439 | s.mu.RLock() |
| 440 | defer s.mu.RUnlock() |
| 441 | items := make([]Item, len(s.Messages)) |
| 442 | for i, item := range s.Messages { |
| 443 | items[i] = item |
| 444 | if item.Message != nil { |
| 445 | items[i].Message = cloneMessage(item.Message) |
| 446 | } |
| 447 | } |
| 448 | return items |
| 449 | } |
| 450 | |
| 451 | // cloneChatMessage returns a deep copy of a chat.Message, duplicating |
| 452 | // all slice and pointer fields that would otherwise alias the original. |
no test coverage detected