You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Preserve plus-prefixed content in file creation patches - #1758
apply_patch's create_file parser strips every line starting with +++ as a unified-diff header. An added source line such as ++counter is encoded as +++counter, so it is silently dropped. The tool still reports success and writes a file missing those statements. This also affects content such as ++ counter, whose encoded line includes the space used by a real +++ file header.
Changes
Strip a leading paired --- / +++ file header rather than filtering those prefixes throughout the added content. Keep the existing hunk and Codex wrapper handling.
Add one regression through applyPatchTool with real temporary files. It checks exact file contents and successful results for the same plus-prefixed source in bare and unified-header create payloads.
Verification
Windows x64, Bun 1.3.14, base c2ce3b69fdbb4a691dfd7d39edc2cb8943d85cc1. Commands use --no-env-file and the repository's placeholder-only sdk/test/setup-env.ts preload in an isolated test home.
bun test sdk/src/__tests__/apply-patch.test.ts -t 'preserves added lines that resemble diff headers': before 0 pass, 1 fail; after 1 pass, 0 fail. Before the fix, the written file contains only console.log(counter) instead of all four source lines.
bun test sdk/src/__tests__/apply-patch.test.ts sdk/src/__tests__/change-file.test.ts: before 1 pass, 21 fail with the new regression; after 2 pass, 20 fail. The remaining 20 failure names are identical before and after. Existing fixtures use POSIX /repo paths and expectations on Windows; this is not a passing whole-suite claim.
bun node_modules/typescript/bin/tsc --noEmit -p sdk: passed.
ESLint on both changed files: 0 errors, 5 pre-existing warnings. Prettier comparison against main has the same 7 existing formatting hunks; the added code introduces none. git diff --check: passed.
bun install --frozen-lockfile: passed, no dependency changes.
SDK build (cd sdk && bun scripts/build.ts), bun freebuff/cli/build.ts 0.0.0-ci, binary --version, and bun cli/scripts/smoke-binary.ts cli/bin/freebuff.exe: passed.
Notes / Scope
This is a source-audit finding with no existing issue being claimed. Only create-payload parsing changes; update/delete operations, path checks and runtime permissions retain their existing behavior. Linux/macOS and the full monorepo suite were not run. The regression exercises the parser and actual filesystem directly without an account, model request or module mock.
Good catch. The old parseCreateDiff filtered every line starting with ---, +++, @@, or *** anywhere in the payload, so a legitimately added source line like ++counter (encoded as +++counter once the diff's own leading + marker is applied) was silently dropped — the tool still reported success while writing a truncated file. That's a real, user-visible correctness bug.
The fix in sdk/src/tools/apply-patch.ts is appropriately narrow: it only treats the first two lines as a unified header pair when they match the real header shape (--- and +++ with trailing spaces, as actual diff tools emit), and otherwise keeps all lines as content. That's a more precise heuristic than prefix-matching every line, and it still preserves support for wrapped unified create payloads.
The added test in apply-patch.test.ts is solid — it exercises both the bare and unified-header create paths through the real tool with a temp directory, asserts exact file contents, and would have failed under the old implementation per your repro notes. Good that you verified tsc/eslint/prettier and ran the existing suite to confirm no regressions beyond pre-existing failures.
One thing to double check before porting: the detection only looks at the very first two lines for the header pair. If a create diff ever has leading blank lines or a different wrapper ordering before the ---/+++ pair (e.g., from the Codex wrapper mentioned in your notes), the header might not be recognized and would then be treated as content. Worth a quick look at how isWrappedAtHeader/Codex handling composes with this function to make sure there's no case where headers land past index 0/1.
Overall this is a well-scoped, well-tested fix in-scope for the SDK. Recommending it for porting.
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
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.
Problem / Why
apply_patch'screate_fileparser strips every line starting with+++as a unified-diff header. An added source line such as++counteris encoded as+++counter, so it is silently dropped. The tool still reports success and writes a file missing those statements. This also affects content such as++ counter, whose encoded line includes the space used by a real+++file header.Changes
---/+++file header rather than filtering those prefixes throughout the added content. Keep the existing hunk and Codex wrapper handling.applyPatchToolwith real temporary files. It checks exact file contents and successful results for the same plus-prefixed source in bare and unified-header create payloads.Verification
Windows x64, Bun 1.3.14, base
c2ce3b69fdbb4a691dfd7d39edc2cb8943d85cc1. Commands use--no-env-fileand the repository's placeholder-onlysdk/test/setup-env.tspreload in an isolated test home.bun test sdk/src/__tests__/apply-patch.test.ts -t 'preserves added lines that resemble diff headers': before 0 pass, 1 fail; after 1 pass, 0 fail. Before the fix, the written file contains onlyconsole.log(counter)instead of all four source lines.bun test sdk/src/__tests__/apply-patch.test.ts sdk/src/__tests__/change-file.test.ts: before 1 pass, 21 fail with the new regression; after 2 pass, 20 fail. The remaining 20 failure names are identical before and after. Existing fixtures use POSIX/repopaths and expectations on Windows; this is not a passing whole-suite claim.bun node_modules/typescript/bin/tsc --noEmit -p sdk: passed.git diff --check: passed.bun install --frozen-lockfile: passed, no dependency changes.cd sdk && bun scripts/build.ts),bun freebuff/cli/build.ts 0.0.0-ci, binary--version, andbun cli/scripts/smoke-binary.ts cli/bin/freebuff.exe: passed.Notes / Scope
This is a source-audit finding with no existing issue being claimed. Only create-payload parsing changes; update/delete operations, path checks and runtime permissions retain their existing behavior. Linux/macOS and the full monorepo suite were not run. The regression exercises the parser and actual filesystem directly without an account, model request or module mock.