SandboxApplyPatchTool splits patch lines with str.splitlines(), so a form feed or in a line breaks Add/Update File
Los mantenedores suelen responder en 1 día
@abhishekacharya200 ya está trabajando en esto.
Desde el 11/10/2026.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Empieza por _parse_apply_patch_input en src/agents/sandbox/capabilities/tools/apply_patch_tool.py y compara cómo divide las líneas con la gramática de Lark, que termina las líneas en LF. Después, inspecciona agents/apply_diff.py, que también divide por "\n". Verifica que el contenido de Add File conserve los caracteres indicados y que la reproducción de Update File cambie const n = 1 por const n = 2.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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 withInvalid 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, andapply_difffails withInvalid 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:
mainat 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 onmain(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.
- Lenguaje dominante
- Python
- Estrellas
- 29.9k
- Forks
- 4.8k
- Merge medio
- 22 h 17 min
- PR fusionados (30 d)
- 208
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de openai/openai-agents-python
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 87/100
openai/openai-agents-python#5350 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
openai/openai-agents-python#5348 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Support the OpenAI Decisions APIAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
openai/openai-agents-python#5353 ·
Los mantenedores suelen responder en 1 día
-
RunState round trip drops alias-only fields: `"async": null` on a function call is serialized as `async_` and breaks `get_interruptions()` on restorePosiblemente ocupada @iveteamorim la tomó hace 1 día. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
openai/openai-agents-python#5352 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
openai/openai-agents-python#5351 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de openai/openai-agents-python
Issues similares
-
area: agents area: docs good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
openapi/gknowledge#23 ·
-
get() for StrEnumPosiblemente ocupada @FeJo5952 la tomó hoy. Abiertogood first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
collective/icalendar#1921 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Improvement Python Spans
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
getsentry/sentry-python#7994 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
alphagov/notifications-api#5004 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
equinor/radix-flux#3922 ·
Los mantenedores suelen responder en 1 día