The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Identify a file event by its path, not by how the operation was named
Claudef8dff6609d66
diff --git a/pkg/asymptoteobserve/dedupe.go b/pkg/asymptoteobserve/dedupe.goindex b0734be7..3761ee4d 100644--- a/pkg/asymptoteobserve/dedupe.go+++ b/pkg/asymptoteobserve/dedupe.go@@ -179,7 +179,19 @@ func dedupeTarget(action string, event map[string]interface{}) string {case "command.executed":return canonicalTarget("command", nestedString(event, "command", "command"), nestedString(event, "tool", "command"))case "file.read", "file.modified":- return canonicalTarget("file", nestedString(event, "file", "path"), nestedString(event, "file", "operation"))+ // The path alone, deliberately. file.operation is the one part of a file+ // event the two capture paths describe differently for the same action:+ // a Claude Code Write reaches the hook through diffFields, which records+ // "modify", and reaches the collector as "create". Including it in the+ // target let one action fail to match itself, so every Write stayed in+ // the log twice however well the two events were identified otherwise.+ //+ // Nothing is lost by dropping it. The action already separates a read+ // from a write, and within file.modified the operation only ever varies+ // between two words for the same event -- so it discriminated nothing+ // and disagreed often. The sandbox checker's mirror of this key has+ // always used the path alone.+ return canonicalTarget("file", nestedString(event, "file", "path"))case "tool.completed":return canonicalTarget("tool.completed", stringValue(event["model"]), stringValue(event["message"]))case "tool.invoked", "tool.failed":diff --git a/pkg/asymptoteobserve/dedupe_test.go b/pkg/asymptoteobserve/dedupe_test.goindex 251f14b0..ee77d4fd 100644--- a/pkg/asymptoteobserve/dedupe_test.go+++ b/pkg/asymptoteobserve/dedupe_test.go@@ -135,3 +135,37 @@ func TestIsDuplicateEndpointEventCollapsesNormalizedHarnessOnCallID(t *testing.Tt.Fatal("the hook and OTLP reports of one Bash call should collapse on their shared call ID")}}++// A Claude Code Write reaches the hook through diffFields, which records+// file.operation "modify", and reaches the collector as "create" -- two words+// for one action. While the target included the operation, the pair could not+// match itself however well the call ID identified it, so every Write stayed in+// the log twice. Reported by Cursor Bugbot.+func TestIsDuplicateEndpointEventCollapsesAWriteDescribedTwoWays(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ hook := `{"timestamp":"2026-08-21T18:00:01Z","event":{"action":"file.modified"},"harness":{"name":"claude_code"},"session":{"id":"s1","working_directory":"/repo"},"file":{"path":"/repo/notes.md","operation":"modify"},"tool":{"name":"Write","path":"/repo/notes.md"},"gen_ai":{"tool":{"call":{"id":"toolu_w"}}}}`+ collector := []byte(`{"timestamp":"2026-08-21T18:00:07Z","event":{"action":"file.modified"},"harness":{"name":"claude_code"},"session":{"id":"s1","working_directory":"/repo"},"file":{"path":"/repo/notes.md","operation":"create"},"tool":{"name":"Write","path":"/repo/notes.md"},"gen_ai":{"tool":{"call":{"id":"toolu_w"}}}}`)+ if err := os.WriteFile(path, []byte(hook+"\n"), 0644); err != nil {+ t.Fatalf("write existing event: %v", err)+ }++ if !IsDuplicateEndpointEvent(path, collector, EndpointDuplicateWindow) {+ t.Fatal("one Write reported by both paths should collapse despite create/modify disagreeing")+ }+}++// Two edits to different files in one MultiEdit share a call ID, and must not+// collapse into one: the path is what separates them, so dropping the operation+// from the target must not have taken the path with it.+func TestIsDuplicateEndpointEventKeepsEditsToDifferentFiles(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ first := `{"timestamp":"2026-08-21T18:00:01Z","event":{"action":"file.modified"},"harness":{"name":"claude_code"},"session":{"id":"s1","working_directory":"/repo"},"file":{"path":"/repo/a.go","operation":"modify"},"gen_ai":{"tool":{"call":{"id":"toolu_m"}}}}`+ second := []byte(`{"timestamp":"2026-08-21T18:00:01Z","event":{"action":"file.modified"},"harness":{"name":"claude_code"},"session":{"id":"s1","working_directory":"/repo"},"file":{"path":"/repo/b.go","operation":"modify"},"gen_ai":{"tool":{"call":{"id":"toolu_m"}}}}`)+ if err := os.WriteFile(path, []byte(first+"\n"), 0644); err != nil {+ t.Fatalf("write existing event: %v", err)+ }++ if IsDuplicateEndpointEvent(path, second, EndpointDuplicateWindow) {+ t.Fatal("two files edited by one MultiEdit are two edits and must both survive")+ }+}diff --git a/pkg/asymptoteobserve/identity_test.go b/pkg/asymptoteobserve/identity_test.goindex d0d5376a..3ae30070 100644--- a/pkg/asymptoteobserve/identity_test.go+++ b/pkg/asymptoteobserve/identity_test.go@@ -84,3 +84,14 @@ func TestEventIDForLineIsStableAcrossReleases(t *testing.T) {"ever written just changed meaning", got, want)}}++// The same disagreement, at the identity layer: the hook's and the collector's+// reports of one Write must derive one event ID even though they name the+// operation differently.+func TestEventIDForLineIgnoresHowTheOperationIsNamed(t *testing.T) {+ hook := EventIDForLine([]byte(`{"timestamp":"2026-08-21T18:00:01Z","event":{"action":"file.modified"},"harness":{"name":"claude_code"},"session":{"id":"s1","working_directory":"/repo"},"file":{"path":"/repo/notes.md","operation":"modify"},"gen_ai":{"tool":{"call":{"id":"toolu_w"}}}}`))+ collector := EventIDForLine([]byte(`{"timestamp":"2026-08-21T18:00:07Z","event":{"action":"file.modified"},"harness":{"name":"claude_code"},"session":{"id":"s1","working_directory":"/repo"},"file":{"path":"/repo/notes.md","operation":"create"},"gen_ai":{"tool":{"call":{"id":"toolu_w"}}}}`))+ if hook != collector {+ t.Fatalf("one Write derived two IDs: %s and %s", hook, collector)+ }+}