Skip to content

fix(tools): harden apply_patch, fff, and exec tools - #363

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/tool-robustness
Aug 16, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/tool-robustness

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Summary

  • Make apply_patch tolerate the patches models actually emit: wrapped *** Begin/End Patch markers, blank context lines, addition-only hunks (append, not prepend), CRLF preservation, *** Move to:, *** End of File, *** Change File:, and @@ location hints.
  • Route patch paths through resolve_write_path so confinement matches write_file, and cap the patch argument at 8 MB.
  • Clamp fffind/ffgrep max_results (200) and query length (512), reject blank queries, and reuse the shared index on a cache-miss race.
  • Strip provider credentials from exec_command children, refuse login shells, and set kill_on_drop.
  • Refuse unbounded read_file of files over 2 MB, and check view_image size before reading the bytes.

Why

Models wrap patches in markdown, omit the leading space on blank hunk lines, emit addition-only hunks that were prepended, and use official format features (Move to, End of File) that the parser treated as unknown. fffind/ffgrep accepted u32::MAX results. exec_command inherited provider API keys and allowed login shells that re-export them.

Test plan

  • cargo test --package forge-tools --package forge-search --package forge-core --lib --locked
  • cargo clippy --package forge-tools --package forge-search --package forge-core --all-targets --locked -- -D warnings
  • cargo fmt --all -- --check

Make apply_patch tolerate the patches models actually emit (wrapped
markers, blank context lines, addition-only hunks, CRLF, Move to,
End of File, Change File, @@ location hints). Cap fff results and
queries, reuse the shared index, strip credentials from exec_command,
and refuse unbounded huge-file reads.
@github-actions
github-actions Bot enabled auto-merge (squash) August 16, 2026 15:18
@github-actions
github-actions Bot merged commit 8a1262d into main Aug 16, 2026
7 checks passed
mohitranka added a commit that referenced this pull request Aug 21, 2026
Make apply_patch tolerate the patches models actually emit (wrapped
markers, blank context lines, addition-only hunks, CRLF, Move to,
End of File, Change File, @@ location hints). Cap fff results and
queries, reuse the shared index, strip credentials from exec_command,
and refuse unbounded huge-file reads.
mohitranka added a commit that referenced this pull request Sep 11, 2026
Make apply_patch tolerate the patches models actually emit (wrapped
markers, blank context lines, addition-only hunks, CRLF, Move to,
End of File, Change File, @@ location hints). Cap fff results and
queries, reuse the shared index, strip credentials from exec_command,
and refuse unbounded huge-file reads.
mohitranka added a commit that referenced this pull request Sep 11, 2026
Make apply_patch tolerate the patches models actually emit (wrapped
markers, blank context lines, addition-only hunks, CRLF, Move to,
End of File, Change File, @@ location hints). Cap fff results and
queries, reuse the shared index, strip credentials from exec_command,
and refuse unbounded huge-file reads.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant