Skip to content

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

fix(qwen): complete the notebook_path resolvers, and pin what a notebook edit records

Justin32a045838844
diff --git a/cli/beacon-hooks/cmd/post_tool.go b/cli/beacon-hooks/cmd/post_tool.go
index 8f2531f6..0d00485a 100644
--- a/cli/beacon-hooks/cmd/post_tool.go
+++ b/cli/beacon-hooks/cmd/post_tool.go
@@ -183,6 +183,18 @@ func parseClaudeCopilotInput(input map[string]interface{}, logger *logging.Logge
if filePath == "" {
filePath = diff.GetStringFromMaps("absolute_path", toolInput, toolResponse)
}
+ // `notebook_path` completes the set: it is read by toolFieldsWithResponse, so leaving it out
+ // here made one key resolve in one reader and not its two siblings -- the exact asymmetry that
+ // produced the earlier defects on this branch.
+ //
+ // Stated plainly: adding it changes no behavior today. `notebook_edit` targets a `.ipynb`, which
+ // is not in scannableExtensions, so this path returns before the diff is built whether or not
+ // the path resolved. The event is still recorded as `file.modified` with the right path, from
+ // toolFieldsWithResponse, and still carries no diff. This exists so the three readers agree, and
+ // so the path is already resolvable if `.ipynb` ever becomes scannable.
+ if filePath == "" {
+ filePath = diff.GetStringFromMaps("notebook_path", toolInput, toolResponse)
+ }
filePath = diff.NormalizePath(filePath)
if (sessionID == "" && !isDevinLikePlatform(platformFlag)) || toolName == "" || filePath == "" {
diff --git a/cli/beacon-hooks/cmd/qwen_event_test.go b/cli/beacon-hooks/cmd/qwen_event_test.go
index b835f85a..2521a03f 100644
--- a/cli/beacon-hooks/cmd/qwen_event_test.go
+++ b/cli/beacon-hooks/cmd/qwen_event_test.go
@@ -527,3 +527,52 @@ func TestQwenEveryFailureSignalIsClassifiedAsAFailure(t *testing.T) {
t.Fatalf("a clean write was classified %q, want file.modified", got)
}
}
+
+// What a Qwen `notebook_edit` actually records, pinned so the answer is written down rather than
+// rediscovered.
+//
+// It is classified `file.modified` with the notebook's path and a `modify` operation, and it carries
+// no diff. The missing diff is not the path resolver: all three readers now accept `notebook_path`.
+// It is `IsScannableFile`, which does not list `.ipynb`, so the diff path returns before a diff is
+// attempted -- and `notebook_edit`'s payload carries `cell_id` / `new_source` rather than the
+// `old_string` / `new_string` pair the diff builder knows, so there would be nothing to build from
+// without a `structuredPatch`.
+//
+// Recording the path and the action while honestly carrying no diff is the right outcome: the event
+// says a notebook changed, and does not pretend to say how.
+func TestQwenNotebookEditRecordsThePathWithoutClaimingADiff(t *testing.T) {
+ logPath := setupQwenHook(t)
+
+ runHookWithInput(t, runPostTool, map[string]interface{}{
+ "session_id": "qwen-8f21c4a0",
+ "cwd": "/Users/example/projects/beacon-demo",
+ "hook_event_name": "PostToolUse",
+ "tool_name": "notebook_edit",
+ "tool_input": map[string]interface{}{
+ "notebook_path": "/Users/example/projects/beacon-demo/analysis.ipynb",
+ "cell_id": "cell-1",
+ "new_source": "print('hello')",
+ "edit_mode": "replace",
+ },
+ "tool_response": map[string]interface{}{"success": true},
+ })
+
+ event := lastEndpointEvent(t, logPath)
+ if got := qwenAction(t, event); got != "file.modified" {
+ t.Fatalf("event.action = %q, want file.modified", got)
+ }
+ file, ok := event["file"].(map[string]interface{})
+ if !ok {
+ t.Fatalf("event has no file object: %#v", event)
+ }
+ if file["path"] != "/Users/example/projects/beacon-demo/analysis.ipynb" {
+ t.Fatalf("file.path = %q, want the notebook_path value", file["path"])
+ }
+ if file["operation"] != "modify" {
+ t.Fatalf("file.operation = %q, want modify", file["operation"])
+ }
+ if diff, ok := file["diff"]; ok {
+ t.Fatalf("file.diff = %v; a notebook edit has no diff to build, so claiming one would be "+
+ "asserting content Beacon never saw", diff)
+ }
+}
diff --git a/cli/beacon-hooks/internal/diff/diff.go b/cli/beacon-hooks/internal/diff/diff.go
index 8a513bd8..1053d7c7 100644
--- a/cli/beacon-hooks/internal/diff/diff.go
+++ b/cli/beacon-hooks/internal/diff/diff.go
@@ -24,6 +24,11 @@ func FromToolResponse(toolName string, toolInput, toolResponse map[string]interf
if filePath == "" {
filePath = GetStringFromMaps("absolute_path", toolInput, toolResponse)
}
+ // Kept in step with the resolver in parseClaudeCopilotInput; see the note there for why this
+ // changes no behavior today and is here so the readers do not drift.
+ if filePath == "" {
+ filePath = GetStringFromMaps("notebook_path", toolInput, toolResponse)
+ }
filePath = NormalizePath(filePath)
if filePath == "" {
return ""