ApplyCompaction atomically resets the session's cumulative token counts and appends a summary item under s.mu so concurrent readers (e.g. the persistence observer's UpdateSession snapshot) cannot observe the new tokens without the matching summary item.
(inputTokens, outputTokens int64, item Item)
| 571 | // (e.g. the persistence observer's UpdateSession snapshot) cannot |
| 572 | // observe the new tokens without the matching summary item. |
| 573 | func (s *Session) ApplyCompaction(inputTokens, outputTokens int64, item Item) { |
| 574 | s.mu.Lock() |
| 575 | defer s.mu.Unlock() |
| 576 | s.InputTokens = inputTokens |
| 577 | s.OutputTokens = outputTokens |
| 578 | s.Messages = append(s.Messages, item) |
| 579 | } |
| 580 | |
| 581 | // AddSubSession adds a sub-session to the session |
| 582 | func (s *Session) AddSubSession(subSession *Session) { |