Repository navigation
fix(prompts): warn that apply_diff SEARCH requires whole lines, not substrings #1712
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
Merged
edelauna
merged 8 commits into
Zoo-Code-Org:main
from
myk1yt:fix/868-apply-diff-whole-lines-warning
Oct 16, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d7afbc5
fix(prompts): warn that apply_diff SEARCH requires whole lines, not s…
5a1525e
Merge remote-tracking branch 'upstream/main' into fix/868-apply-diff-…
myk1yt ebd3978
Merge remote-tracking branch 'origin/main' into fix/868-apply-diff-wh…
myk1yt b43ef9b
test(prompts,diff): assert whole-lines guidance in apply_diff descrip…
myk1yt 77161c0
chore: restore unrelated spec formatting altered by merge hook
myk1yt 0deb3d6
chore: retrigger review-state reconciliation
myk1yt 64682c0
chore: re-run checks cancelled by infra
myk1yt 3bf102b
chore: retrigger review-state reconciliation
myk1yt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/core/prompts/tools/native-tools/__tests__/apply_diff.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import type OpenAI from "openai" | ||
| import { apply_diff } from "../apply_diff" | ||
|
|
||
| // Helper type to access function tools | ||
| type FunctionTool = OpenAI.Chat.ChatCompletionTool & { type: "function" } | ||
|
|
||
| // Helper to get function definition from tool | ||
| const getFunctionDef = (tool: OpenAI.Chat.ChatCompletionTool) => (tool as FunctionTool).function | ||
|
|
||
| // OpenAI types the parameter schema as FunctionParameters (Record<string, unknown>). | ||
| // Narrow it with runtime checks instead of assertions so the spec tracks schema changes. | ||
| function asRecord(value: unknown): Record<string, unknown> { | ||
| if (typeof value !== "object" || value === null) { | ||
| throw new Error("expected an object value in the apply_diff parameter schema") | ||
| } | ||
| return value as Record<string, unknown> | ||
| } | ||
|
|
||
| const getDiffParameterDescription = (): string => { | ||
| const parameters = asRecord(getFunctionDef(apply_diff).parameters) | ||
| const properties = asRecord(parameters["properties"]) | ||
| const diff = asRecord(properties["diff"]) | ||
| const description = diff["description"] | ||
| if (typeof description !== "string") { | ||
| throw new Error("diff parameter must declare a string description") | ||
| } | ||
| return description | ||
| } | ||
|
|
||
| describe("apply_diff diff parameter description", () => { | ||
| const diffDescription = getDiffParameterDescription() | ||
|
|
||
| it("should require complete, whole lines in the SEARCH block", () => { | ||
| expect(diffDescription).toContain("The SEARCH block must contain complete, whole lines") | ||
| }) | ||
|
|
||
| it("should warn that partial-line (substring) matching is not supported", () => { | ||
| expect(diffDescription).toContain("partial-line (substring) matching is not supported") | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Benchmark result on qwen3.8-27b (Solheim API). The test gave the model one long Markdown line and asked it to change one phrase with apply_diff. A run passes when the SEARCH lines equal whole file lines.
Limits: one scenario, one model, 12 runs for each description. The test did not cover the error-message tip.