Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(exporter): preserve MCP description reversions within batches (#942)

Rudy Mizrahi Celekli2ddd5ad4d9e5
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings.go
index 6623097d..cbdcb700 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings.go
@@ -59,7 +59,11 @@ func (l *MCPListings) Filter(events []Event) []Event {
inBatch := map[string][sha256.Size]byte{}
for _, event := range events {
if key, digest, ok := eventListingKey(event); ok {
- if previous, repeat := inBatch[key]; (repeat && previous == digest) || l.listedLocked(key, digest) {
+ previous, listed := inBatch[key]
+ if !listed {
+ previous, listed = l.seen[key]
+ }
+ if listed && previous == digest {
continue
}
inBatch[key] = digest
diff --git a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings_test.go b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings_test.go
index 4d228e0a..3b191dd2 100644
--- a/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings_test.go
+++ b/collector-builder/exporter/beaconjsonexporter/internal/beaconevent/mcp_listings_test.go
@@ -96,3 +96,31 @@ func TestNilMCPListingsKeepsEverything(t *testing.T) {
}
listings.Remember(batch...)
}
+
+// Description changes must reach the destination in order, even when the final
+// request in a batch returns to the description remembered before that batch.
+func TestMCPListingsKeepsDescriptionReversionWithinBatch(t *testing.T) {
+ var listings MCPListings
+ original := listing("s1", "mcp__notes__save", "Original description")
+ changed := listing("s1", "mcp__notes__save", "Changed description")
+ listings.Remember(original)
+ batch := []Event{changed, original, original}
+ for attempt := 0; attempt < 2; attempt++ {
+ kept := listings.Filter(batch)
+ if len(kept) != 2 {
+ t.Fatalf("attempt %d: kept %d listings, want both description changes", attempt, len(kept))
+ }
+ if kept[0].GenAI.Tool.Description != "Changed description" || kept[1].GenAI.Tool.Description != "Original description" {
+ t.Fatalf("description changes lost their order: %v", kept)
+ }
+ }
+ // Filtering alone does not remember a failed delivery: both attempts above
+ // must retain both changes. Remember only after the successful delivery.
+ listings.Remember(listings.Filter(batch)...)
+ if kept := listings.Filter([]Event{original}); len(kept) != 0 {
+ t.Fatalf("successfully delivered final description should be deduplicated, kept %d", len(kept))
+ }
+ if kept := listings.Filter([]Event{changed}); len(kept) != 1 {
+ t.Fatalf("a subsequent changed description should be kept, got %d", len(kept))
+ }
+}