-
Notifications
You must be signed in to change notification settings - Fork 269
[Fix] Subtasks process queued feedback before returning #1318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
928b020
3772cd3
a2dc754
a83534e
98d3846
d461e2c
e50e993
da6b088
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import path from "path" | |
| import { isBinaryFile } from "isbinaryfile" | ||
|
|
||
| import { readFileTool, ReadFileTool } from "../ReadFileTool" | ||
| import { Task } from "../../task/Task" | ||
| import { formatResponse } from "../../prompts/responses" | ||
| import { | ||
| validateImageForProcessing, | ||
|
|
@@ -649,6 +650,89 @@ describe("ReadFileTool", () => { | |
| expect(mockTask.say).toHaveBeenCalledWith("user_feedback", "This file contains secrets", undefined) | ||
| expect(formatResponse.toolDeniedWithFeedback).toHaveBeenCalledWith("This file contains secrets") | ||
| }) | ||
|
|
||
| it("denies batch reads and reports queued message feedback without parsing it as permissions", async () => { | ||
| const task = Object.create(Task.prototype) as Task | ||
| Object.defineProperty(task, "cwd", { value: "/test/workspace", writable: true }) | ||
| Object.assign(task, createMockTask()) | ||
| const queuedImages = ["data:image/png;base64,queued"] | ||
| task.ask = vi.fn().mockResolvedValue({ | ||
| response: "messageResponse", | ||
| text: "Read a different file instead", | ||
| images: queuedImages, | ||
| }) | ||
| const fileResults = [ | ||
| { path: "one.ts", status: "pending" as const, entry: { path: "one.ts", mode: "slice" as const } }, | ||
| { path: "two.ts", status: "pending" as const, entry: { path: "two.ts", mode: "slice" as const } }, | ||
| ] | ||
| const updates = new Map<string, Record<string, unknown>>() | ||
| const parseSpy = vi.spyOn(JSON, "parse") | ||
|
|
||
| await readFileTool["requestApproval"](task, fileResults, (filePath, update) => { | ||
| updates.set(filePath, update) | ||
| }) | ||
|
|
||
| expect(parseSpy).not.toHaveBeenCalled() | ||
| expect(task.say).toHaveBeenCalledWith("user_feedback", "Read a different file instead", queuedImages) | ||
| expect(task.didRejectTool).toBe(true) | ||
| expect(updates.get("one.ts")).toMatchObject({ | ||
| status: "denied", | ||
| feedbackText: "Read a different file instead", | ||
| feedbackImages: queuedImages, | ||
| }) | ||
| expect(updates.get("two.ts")).toMatchObject({ | ||
| status: "denied", | ||
| feedbackText: "Read a different file instead", | ||
| feedbackImages: queuedImages, | ||
| }) | ||
| parseSpy.mockRestore() | ||
| }) | ||
|
|
||
| it("denies batch reads without feedback text", async () => { | ||
| const task = Object.create(Task.prototype) as Task | ||
| Object.defineProperty(task, "cwd", { value: "/test/workspace", writable: true }) | ||
| Object.assign(task, createMockTask()) | ||
| task.ask = vi.fn().mockResolvedValue({ response: "noButtonClicked", text: undefined, images: undefined }) | ||
| const parseSpy = vi.spyOn(JSON, "parse") | ||
| const fileResults = [ | ||
| { path: "one.ts", status: "pending" as const, entry: { path: "one.ts", mode: "slice" as const } }, | ||
| { path: "two.ts", status: "pending" as const, entry: { path: "two.ts", mode: "slice" as const } }, | ||
| ] | ||
|
|
||
| await readFileTool["requestApproval"](task, fileResults, () => {}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Assert per-file denial in the no-feedback batch test.
🤖 Prompt for AI Agents |
||
|
|
||
| expect(parseSpy).not.toHaveBeenCalled() | ||
| expect(task.say).not.toHaveBeenCalledWith("user_feedback", expect.anything(), expect.anything()) | ||
| expect(task.didRejectTool).toBe(true) | ||
| parseSpy.mockRestore() | ||
| }) | ||
|
|
||
| it("applies individual decisions for a batch read", async () => { | ||
| const task = Object.create(Task.prototype) as Task | ||
| Object.defineProperty(task, "cwd", { value: "/test/workspace", writable: true }) | ||
| Object.assign(task, createMockTask()) | ||
| task.ask = vi.fn().mockImplementation(async (_type, text) => { | ||
| const { batchFiles } = JSON.parse(text ?? "{}") as { batchFiles: Array<{ key: string }> } | ||
| return { | ||
| response: "objectResponse", | ||
| text: JSON.stringify({ [batchFiles[0].key]: true, [batchFiles[1].key]: false }), | ||
| images: undefined, | ||
| } | ||
| }) | ||
| const fileResults = [ | ||
| { path: "one.ts", status: "pending" as const, entry: { path: "one.ts", mode: "slice" as const } }, | ||
| { path: "two.ts", status: "pending" as const, entry: { path: "two.ts", mode: "slice" as const } }, | ||
| ] | ||
| const updates = new Map<string, Record<string, unknown>>() | ||
|
|
||
| await readFileTool["requestApproval"](task, fileResults, (filePath, update) => { | ||
| updates.set(filePath, update) | ||
| }) | ||
|
|
||
| expect(updates.get("one.ts")).toMatchObject({ status: "approved" }) | ||
| expect(updates.get("two.ts")).toMatchObject({ status: "denied" }) | ||
| expect(task.didRejectTool).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe("output structure", () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve image-only queued feedback.
When
messageResponsecontains images but no text,requestApprovalstoresfeedbackImagesand denies the read.buildAndPushResultselects feedback only whenfeedbackTextis nonempty, so it omits the queued images from the model result. Treat nonempty text or images as feedback in both paths, and add batch regression tests for image-only and no-image responses.🤖 Prompt for AI Agents