Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions mcp/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,15 @@ func (s *MemoryEventStore) After(_ context.Context, sessionID, streamID string,
if !ok {
return nil, fmt.Errorf("MemoryEventStore.After: unknown stream ID %v in session %q", streamID, sessionID)
}
start := index + 1
if dl.first > start {
start := (index + 1) - dl.first
if start < 0 {
return nil, fmt.Errorf("MemoryEventStore.After: index %d, stream ID %v, session %q: %w",
index, streamID, sessionID, ErrEventsPurged)
}
return slices.Clone(dl.data[start-dl.first:]), nil
if start >= len(dl.data) {
return nil, nil
}
return slices.Clone(dl.data[start:]), nil
}

return func(yield func([]byte, error) bool) {
Expand Down
4 changes: 4 additions & 0 deletions mcp/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ func TestMemoryEventStoreAfter(t *testing.T) {
{"S1", "1", 0, []string{"d2", "d3"}, ""},
{"S1", "1", 1, []string{"d3"}, ""},
{"S1", "1", 2, nil, ""},
{"S1", "1", 3, nil, ""},
{"S1", "1", 100, nil, ""}, // past the end of stream "1" (highest is 2)
{"S1", "2", 0, nil, ""},
{"S1", "2", 1, nil, ""},
{"S1", "2", 100, nil, ""},
{"S1", "3", 0, nil, "unknown stream ID"},
{"S2", "0", 0, nil, "unknown session ID"},
} {
Expand Down
Loading