MCPcopy Index your code
hub / github.com/docker/docker-agent / AddMessage

Method AddMessage

pkg/session/store.go:269–285  ·  view source on GitHub ↗

AddMessage adds a message to a session at the next position. Returns the ID of the created message (for in-memory, this is a simple counter).

(_ context.Context, sessionID string, msg *Message)

Source from the content-addressed store, hash-verified

267// AddMessage adds a message to a session at the next position.
268// Returns the ID of the created message (for in-memory, this is a simple counter).
269func (s *InMemorySessionStore) AddMessage(_ context.Context, sessionID string, msg *Message) (int64, error) {
270 if sessionID == "" {
271 return 0, ErrEmptyID
272 }
273 session, exists := s.sessions.Load(sessionID)
274 if !exists {
275 return 0, ErrNotFound
276 }
277 // Deep-copy before mutating ID. The caller's pointer may be held
278 // concurrently by another goroutine (snapshotItems → cloneMessage),
279 // and writing msg.ID directly races with those reads.
280 stored := cloneMessage(msg)
281 s.messageID++
282 stored.ID = s.messageID
283 session.AddMessage(stored)
284 return s.messageID, nil
285}
286
287// UpdateMessage updates an existing message by its ID.
288func (s *InMemorySessionStore) UpdateMessage(_ context.Context, messageID int64, msg *Message) error {

Calls 3

cloneMessageFunction · 0.85
LoadMethod · 0.80
AddMessageMethod · 0.65

Tested by 1