MCPcopy
hub / github.com/docker/docker-agent / snapshotItems

Method snapshotItems

pkg/session/session.go:438–449  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

436// cannot mutate the snapshot; non-Message fields (Summary, SubSession, Cost,
437// FirstKeptEntry) are shallow-copied since they are not mutated in place.
438func (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.

Callers 4

GetAllMessagesMethod · 0.95
OwnMessagesMethod · 0.95
CompactionInputMethod · 0.95
GetMessagesMethod · 0.95

Implementers 7

fakeSessionpkg/tools/lifecycle/supervisor_test.go
sessionClientpkg/tools/mcp/session_client.go
mockMCPClientpkg/tools/mcp/mcp_test.go
reconnectableMockClientpkg/tools/mcp/mcp_test.go
failingInitClientpkg/tools/mcp/reconnect_test.go
clientSessionpkg/tools/mcp/mcp.go
lspSessionpkg/tools/builtin/lsp/lsp_lifecycle.go

Calls 1

cloneMessageFunction · 0.85

Tested by

no test coverage detected