Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

SandboxApplyPatchTool splits patch lines with str.splitlines(), so a form feed or 
 in a line breaks Add/Update File

クローズ 初心者向け
#5,349 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@abhishekacharya200 がすでに取り組んでいます。

2026年10月11日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
tooling

調査の方向性

src/agents/sandbox/capabilities/tools/apply_patch_tool.py にある _parse_apply_patch_input から始め、行の分割方法を、LF で行を終端する Lark grammar と比較してください。次に、同じく "\n" で分割する agents/apply_diff.py を調べてください。Add File の内容が列挙された文字を保持することと、Update File の再現例で const n = 1 が const n = 2 に変わることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

Please read this first
  • Have you read the docs? Agents SDK docs
  • Have you searched for related issues? Others may have faced similar issues.
Describe the bug

SandboxApplyPatchTool parses the freeform patch with raw_input.splitlines() (_parse_apply_patch_input in src/agents/sandbox/capabilities/tools/apply_patch_tool.py). str.splitlines() also breaks at \v, \f, \x1c-\x1e, \x85, \u2028, \u2029 and a bare \r. The tool's own Lark grammar only ends a line at LF: add_line: "+" /(.*)/ LF and change_line: ("+" | "-" | " ") /(.*)/ LF. agents/apply_diff.py also splits on "\n".

So a patch the grammar accepts is rejected when any line contains one of those characters. For example, a form feed between sections of a Python or C file, or a \u2028 inside a JS string or pasted text:

  • *** Add File: fails with Invalid Add File line: <rest of the line>, and the file is not created.
  • *** Update File: turns the rest of the line into an unprefixed diff line, and apply_diff fails with Invalid Line: <rest of the line>. This happens even when the character is only in a context line.

Splitting the envelope on "\n", as the grammar and apply_diff do, makes both cases work. In the repro below, the same hunk applies cleanly once it is split that way.

Debug information
  • Agents SDK version: main at 125efa0 (0.23.1)
  • Python version: 3.12.3
  • Operating system: Linux
  • Model and model provider: n/a (the parser is called directly)
  • Does the issue reproduce with the latest Agents SDK release? Yes. v0.23.1 has the same splitlines() call and grammar; I ran the repro on main (125efa0).
  • Does the issue occur consistently or intermittently? Consistently
'+page one\x0cpage two' -> Invalid Add File line: page two
'+const s = "a\u2028b";' -> Invalid Add File line: b";
'+x\x85y' -> Invalid Add File line: y
parsed diff: '@@\n const s = "a\nb";\n-const n = 1;\n+const n = 2;\n'
apply_diff -> Invalid Line: b";
'const s = "a\u2028b";\nconst n = 2;\n'
Repro steps
from agents.apply_diff import apply_diff
from agents.sandbox.capabilities.tools import SandboxApplyPatchTool
from agents.testing import scripted_sandbox_session

tool = SandboxApplyPatchTool(session=scripted_sandbox_session())

# 1. Add File: the grammar's add_line is "+" /(.*)/ LF, so these lines are valid input.
for line in ["+page one\fpage two", '+const s = "a\u2028b";', "+x\x85y"]:
    patch = f"*** Begin Patch\n*** Add File: notes.txt\n{line}\n*** End Patch\n"
    try:
        tool.parse_custom_input(patch)
        print(ascii(line), "-> parsed")
    except ValueError as e:
        print(ascii(line), "->", e)

# 2. Update File whose context line contains U+2028.
original = 'const s = "a\u2028b";\nconst n = 1;\n'
patch = (
    "*** Begin Patch\n*** Update File: app.js\n@@\n"
    ' const s = "a\u2028b";\n-const n = 1;\n+const n = 2;\n*** End Patch\n'
)
(op,) = tool.parse_custom_input(patch)
print("parsed diff:", ascii(op.diff))
try:
    apply_diff(original, op.diff)
except ValueError as e:
    print("apply_diff ->", e)

# The same hunk, split on "\n" only, applies cleanly.
print(ascii(apply_diff(original, '@@\n const s = "a\u2028b";\n-const n = 1;\n+const n = 2;\n')))
Expected behavior

The three Add File patches create files whose content keeps the form feed, \u2028 and \x85. The Update File patch changes const n = 1; to const n = 2;, which is what apply_diff produces when the hunk is split on "\n" only.

主要言語
Python
スター
30k
フォーク
4.9k
平均マージ
16時間 25分
マージ済み PR(30日)
220

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-agents-python のほかの issue

openai/openai-agents-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。