Skip to content

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

Tidy after the autofix: drop the dead reader, correct its comment, fold its test

Claudedd1b9fe36d38
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.go
index bc05f122..1592fa6b 100644
--- a/cli/beacon-hooks/cmd/endpoint_events.go
+++ b/cli/beacon-hooks/cmd/endpoint_events.go
@@ -310,10 +310,12 @@ func toolCallIDFromEnvelope(input map[string]interface{}) string {
// which is where Claude Code puts tool_use_id -- outside tool_input, so no
// amount of reading the tool arguments would ever have found it.
//
-// The top-level payload ID is authoritative: it always overwrites any value that
-// toolFieldsWithResponse may have set from inside tool arguments, because tool
-// parameters are user-controlled and may coincidentally carry key names like
-// call_id without being the runtime's invocation identifier.
+// The envelope is the only source of a call ID anywhere in the hook path, so
+// this is a plain promotion rather than a contest between sources. Tool
+// arguments were once read too, which let a tool parameter that happened to be
+// called call_id become the join key and shut out the runtime's real
+// tool_use_id; that read is gone rather than merely outranked, because a tool
+// parameter is not weaker evidence of identity, it is not evidence at all.
//
// Only an event that already describes a tool action takes one. A session
// lifecycle payload that happens to echo an ID is not a tool call, and giving it
@@ -336,15 +338,6 @@ func describesToolAction(fields map[string]interface{}) bool {
return false
}
-// toolCallIDOf reads back what setToolCallID wrote.
-func toolCallIDOf(fields map[string]interface{}) string {
- genAI, _ := fields["gen_ai"].(map[string]interface{})
- tool, _ := genAI["tool"].(map[string]interface{})
- call, _ := tool["call"].(map[string]interface{})
- id, _ := call["id"].(string)
- return strings.TrimSpace(id)
-}
-
// setToolCallID writes gen_ai.tool.call.id, creating the objects on the way down
// and leaving whatever is already in them alone. mergeNested cannot do this: it
// is a one-level merge, so writing the call through it would replace the whole
diff --git a/cli/beacon-hooks/cmd/tool_call_id_test.go b/cli/beacon-hooks/cmd/tool_call_id_test.go
index 44ac02f8..b0d2bbb6 100644
--- a/cli/beacon-hooks/cmd/tool_call_id_test.go
+++ b/cli/beacon-hooks/cmd/tool_call_id_test.go
@@ -106,39 +106,6 @@ func TestSessionEventsDoNotTakeAToolCallID(t *testing.T) {
}
}
-// A tool argument named call_id (common in telephony and similar APIs) must not
-// block the real runtime invocation ID that sits at the top level of the payload.
-func TestTopLevelIDOverridesToolArgumentCallID(t *testing.T) {
- setupHookConfigDirs(t)
- platformFlag = "claude"
- logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
- t.Setenv("BEACON_ENDPOINT_LOG", logPath)
-
- runHookWithInput(t, runPostTool, map[string]interface{}{
- "session_id": "claude-session",
- "cwd": "/repo",
- "hook_event_name": "PostToolUse",
- "tool_name": "mcp__telephony__dial",
- "tool_use_id": "toolu_real_id",
- "tool_input": map[string]interface{}{
- "mcp_server": "telephony",
- "call_id": "tel_wrong_id",
- "number": "+1555000000",
- },
- "tool_response": map[string]interface{}{"ok": true},
- })
-
- events := endpointEvents(t, logPath)
- if len(events) == 0 {
- t.Fatal("no events written")
- }
- for _, event := range events {
- if got := callIDOfEvent(event); got != "toolu_real_id" {
- t.Fatalf("gen_ai.tool.call.id = %q, want toolu_real_id (the runtime ID, not the tool argument)", got)
- }
- }
-}
-
// An MCP event already builds a gen_ai object for its arguments, so the call ID
// has to be written into it rather than over it.
func TestToolCallIDDoesNotDisplaceMCPToolFields(t *testing.T) {
@@ -177,6 +144,9 @@ func TestArgumentNamedCallIDNeverBecomesTheJoinKey(t *testing.T) {
"tool_name": "mcp__stripe__get_charge",
"tool_use_id": "toolu_REAL",
"tool_input": map[string]interface{}{"mcp_server": "stripe", "call_id": "ch_ARGUMENT"},
+ // The response is checked too: it is the tool's own output, so it is no
+ // more a statement of identity than the arguments are.
+ "tool_response": map[string]interface{}{"ok": true, "call_id": "ch_RESPONSE"},
})
events := endpointEvents(t, logPath)