Skip to content

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

Fix Grok tool failures being logged as successes with info severity

Cursor Agent696c9226d5ff
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.go
index c9514724..17276dbf 100644
--- a/cli/beacon-hooks/cmd/endpoint_events.go
+++ b/cli/beacon-hooks/cmd/endpoint_events.go
@@ -136,6 +136,9 @@ func fileOperation(toolName string) string {
func actionForTool(hookEvent, toolName string) string {
lower := strings.ToLower(toolName)
if platformFlag == "grok" {
+ if hookEvent == "post_tool_use_failure" {
+ return "tool.failed"
+ }
switch lower {
case "run_terminal_cmd":
return "command.executed"
@@ -144,9 +147,6 @@ func actionForTool(hookEvent, toolName string) string {
case "search_replace", "write_file":
return "file.modified"
}
- if hookEvent == "post_tool_use_failure" {
- return "tool.failed"
- }
}
if platformFlag == "devin" {
switch {
diff --git a/cli/beacon-hooks/cmd/grok_hooks_test.go b/cli/beacon-hooks/cmd/grok_hooks_test.go
index 6578fcf1..e57e990c 100644
--- a/cli/beacon-hooks/cmd/grok_hooks_test.go
+++ b/cli/beacon-hooks/cmd/grok_hooks_test.go
@@ -124,6 +124,26 @@ func TestGrokPostToolMapsCommandAndFailure(t *testing.T) {
if action := event["event"].(map[string]interface{})["action"]; action != "tool.failed" {
t.Fatalf("failure event.action = %q, want tool.failed", action)
}
+ if sev := event["severity"]; sev != "high" {
+ t.Fatalf("failure severity = %q, want high", sev)
+ }
+
+ // Known tool failures must also be recorded as tool.failed with high severity.
+ runHookWithInput(t, runPostTool, map[string]interface{}{
+ "hookEventName": "post_tool_use_failure",
+ "sessionId": "grok-session-1",
+ "toolName": "run_terminal_cmd",
+ "toolInput": map[string]interface{}{
+ "command": "exit 1",
+ },
+ })
+ event = lastEndpointEvent(t, logPath)
+ if action := event["event"].(map[string]interface{})["action"]; action != "tool.failed" {
+ t.Fatalf("known tool failure event.action = %q, want tool.failed", action)
+ }
+ if sev := event["severity"]; sev != "high" {
+ t.Fatalf("known tool failure severity = %q, want high", sev)
+ }
}
func TestGrokCwdFallsBackToEnvironment(t *testing.T) {
diff --git a/cli/beacon-hooks/cmd/post_tool.go b/cli/beacon-hooks/cmd/post_tool.go
index fd26c9f8..61bb7d9e 100644
--- a/cli/beacon-hooks/cmd/post_tool.go
+++ b/cli/beacon-hooks/cmd/post_tool.go
@@ -233,7 +233,7 @@ func emitPostToolObserved(logger *logging.Logger, input map[string]interface{})
for key, value := range toolFields(toolName, toolInput) {
fields[key] = value
}
- if hookEvent == "postToolUseFailure" {
+ if hookEvent == "postToolUseFailure" || hookEvent == "post_tool_use_failure" {
emitHookEvent(logger, "tool.failed", "tool", "high", "Tool execution failed", input, fields)
return
}