Skip to content

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

Merge Bugbot's interrupt fix; collapse the two failure checks into one predicate

Justinf18154e0015a
diff --git a/cli/beacon-hooks/cmd/post_tool.go b/cli/beacon-hooks/cmd/post_tool.go
index b34a6789..8f2531f6 100644
--- a/cli/beacon-hooks/cmd/post_tool.go
+++ b/cli/beacon-hooks/cmd/post_tool.go
@@ -339,11 +339,19 @@ func emitPostToolObserved(logger *logging.Logger, input map[string]interface{})
emitHookEvent(logger, "tool.failed", "tool", "high", "Tool execution failed", input, fields)
return
}
- if platformFlag == "qwen" {
- if interrupted, _ := input["is_interrupt"].(bool); interrupted {
- emitHookEvent(logger, "tool.failed", "tool", "high", "Tool execution failed", input, fields)
- return
- }
+ // One predicate decides "did this tool fail", for both the diff-path guard in
+ // parseClaudeCopilotInput and the classification here.
+ //
+ // It was two, and they disagreed: `qwenToolFailed` reads three signals -- the failure event
+ // name, a non-empty `error`, and `is_interrupt` -- while the check above reads only the first
+ // two. An interrupt carrying an empty error therefore skipped the diff path as a failure and
+ // then arrived here to be classified a successful `file.modified`: the exact false positive
+ // this runtime's mapping exists to prevent, reintroduced by the gap between two spellings of
+ // the same question. Calling the predicate rather than restating its logic is what stops that
+ // pair drifting a second time.
+ if platformFlag == "qwen" && qwenToolFailed(input) {
+ emitHookEvent(logger, "tool.failed", "tool", "high", "Tool execution failed", input, fields)
+ return
}
action := actionForTool(hookEvent, toolName)
category := "tool"
diff --git a/cli/beacon-hooks/cmd/qwen_event_test.go b/cli/beacon-hooks/cmd/qwen_event_test.go
index efe13001..b835f85a 100644
--- a/cli/beacon-hooks/cmd/qwen_event_test.go
+++ b/cli/beacon-hooks/cmd/qwen_event_test.go
@@ -474,3 +474,56 @@ func TestQwenRawPayloadSurvivesTheFileEditPath(t *testing.T) {
})
}
}
+
+// The two paths that ask "did this tool fail" must never disagree.
+//
+// They did once: `qwenToolFailed` guards the diff path and reads three signals, while the
+// classification in emitPostToolObserved read only two. An interrupt with an empty error skipped
+// the diff path as a failure and was then classified a successful `file.modified` -- the exact
+// false positive this runtime's mapping exists to prevent, reintroduced by the gap between two
+// spellings of one question.
+//
+// Every signal is exercised against the same edit tool, because an edit tool is where the
+// disagreement is expensive: a misclassified `web_fetch` is noise, a misclassified `write_file`
+// asserts a file changed when it did not.
+func TestQwenEveryFailureSignalIsClassifiedAsAFailure(t *testing.T) {
+ for name, overrides := range map[string]map[string]interface{}{
+ "failure event name": {"hook_event_name": "PostToolUseFailure"},
+ "error message": {"hook_event_name": "PostToolUse", "error": "EACCES: permission denied"},
+ "interrupt flag": {"hook_event_name": "PostToolUse", "error": "", "is_interrupt": true},
+ } {
+ t.Run(name, func(t *testing.T) {
+ logPath := setupQwenHook(t)
+ payload := readQwenFixture(t, "post_tool_write_file.json")
+ for key, value := range overrides {
+ payload[key] = value
+ }
+
+ runHookWithInput(t, runPostTool, payload)
+
+ event := lastEndpointEvent(t, logPath)
+ if got := qwenAction(t, event); got != "tool.failed" {
+ t.Fatalf("event.action = %q, want tool.failed", got)
+ }
+ if got := event["severity"]; got != "high" {
+ t.Errorf("severity = %q, want high", got)
+ }
+ // A failure never carries a diff. The content in the payload describes a write that
+ // did not land, so recording it would assert a change that never happened.
+ if file, ok := event["file"].(map[string]interface{}); ok {
+ if diff, ok := file["diff"]; ok {
+ t.Errorf("failed edit carried a diff: %v", diff)
+ }
+ }
+ })
+ }
+
+ // The control: the same payload with no failure signal is still a successful edit, so the
+ // guard above cannot be satisfied by classifying everything as a failure.
+ logPath := setupQwenHook(t)
+ runHookWithInput(t, runPostTool, readQwenFixture(t, "post_tool_write_file.json"))
+ event := lastEndpointEvent(t, logPath)
+ if got := qwenAction(t, event); got != "file.modified" {
+ t.Fatalf("a clean write was classified %q, want file.modified", got)
+ }
+}