Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Python: [Bug]: Local shell results are sent to OpenAI as exit 0, even when the command failed or timed out

Cerrado
#8,929 1 comentario 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@eavanvalkenburg ya está trabajando en esto.

Desde el 1/10/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

python reproduced skills
Description

When a local shell tool runs through the OpenAI Responses client, its result goes back as a shell_call_output whose structured outcome is always {"type": "exit", "exit_code": 0}. That holds when the command exited non-zero and when it timed out. stderr is also sent inside stdout, and the stderr field is empty.

The cause is a mismatch between two packages:

  • LocalShellTool.as_function() returns ShellResult.format_for_model(), a single string such as "stderr: oops\n\nexit_code: 1" (agent_framework_tools/shell/_tool.py:314; DockerShellTool does the same at _docker.py:805).
  • RawOpenAIChatClient._to_shell_call_output_payload (agent_framework_openai/_chat_client.py:2391) can build stdout, stderr, exit_code and timed_out from a mapping. Given a string, it puts the whole text in stdout and falls back to exit_code = 0, because there is no exception.

So the model receives a structured outcome that contradicts the text next to it: a failed command reported as success, and a timeout reported as a clean exit rather than the payload's dedicated {"type": "timeout"}.

Expected: outcome matches the command's real result (exit_code: 3, exit_code: 1, {"type": "timeout"}), and stderr goes in stderr.

Actual: outcome is {"type": "exit", "exit_code": 0} in all three cases below.

Code Sample
import asyncio
import tempfile

from agent_framework import Content
from agent_framework.openai import OpenAIChatClient
from agent_framework_tools.shell import LocalShellTool


async def main() -> None:
    shell = LocalShellTool(mode="stateless", workdir=tempfile.mkdtemp(), approval_mode="never_require",
                           acknowledge_unsafe=True, timeout=2)
    shell_tool = OpenAIChatClient.get_shell_tool(func=shell.as_function())
    # PowerShell syntax (Windows); on Linux/macOS use e.g. "echo oops >&2; exit 1" and "sleep 5".
    for command in ("exit 3", "[Console]::Error.WriteLine('oops'); exit 1", "Start-Sleep 5"):
        result = await shell_tool.invoke(arguments={"command": command})  # what the function loop receives
        payload = OpenAIChatClient._to_shell_call_output_payload(Content.from_function_result(call_id="c", result=result))
        print(f"$ {command}\n  tool text : {result[0].text!r}\n  sent      : {payload}")


asyncio.run(main())
Error Messages / Stack Traces
$ exit 3
  tool text : 'exit_code: 3'
  sent      : [{'stdout': 'exit_code: 3', 'stderr': '', 'outcome': {'type': 'exit', 'exit_code': 0}}]

$ [Console]::Error.WriteLine('oops'); exit 1
  tool text : 'stderr: oops\r\n\nexit_code: 1'
  sent      : [{'stdout': 'stderr: oops\r\n\nexit_code: 1', 'stderr': '', 'outcome': {'type': 'exit', 'exit_code': 0}}]

$ Start-Sleep 5
  tool text : '[command timed out]\nexit_code: 15'
  sent      : [{'stdout': '[command timed out]\nexit_code: 15', 'stderr': '', 'outcome': {'type': 'exit', 'exit_code': 0}}]
Package Versions

agent-framework-core: 1.19.0, agent-framework-openai: 1.14.4, agent-framework-tools: 1.0.0b260918

Python Version

Python 3.13.13 (Windows 11, PowerShell)

Additional Context
  • Reproduced on the released packages above, in a fresh environment, and on main at 7634356a1.
  • Only the OpenAI shell path is affected. With Anthropic's bash_* tool the result goes back as a tool_result carrying the text (with is_error set only on an exception), and a plain function tool sends the text as its output, so neither has a structured exit code to contradict it.
  • Proposed fix: have the shell tools return their structured result alongside the text, and have the OpenAI payload builder use it. Core already defines Content.from_shell_command_output(stdout=, stderr=, exit_code=, timed_out=), which the OpenAI and Anthropic clients use today for inbound hosted shell output. The local tools could emit the same content, and _to_shell_call_output_payload could build stdout, stderr and the exit/timeout outcome from it. Providers that take text keep receiving format_for_model()'s output, so nothing changes for them. Reading the exit code back out of the text would be a smaller change, but it would tie the payload to a display format.
  • This crosses agent-framework-tools and agent-framework-openai, and changes how shell results are serialized, which docs/specs/004-python-function-calling-loop.md covers, so I'd like a maintainer's OK on this direction first. I'm happy to take it.
Lenguaje dominante
Python
Estrellas
14k
Forks
2.5k
Merge medio
2 d 4 h
PR fusionados (30 d)
403

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/agent-framework

Todos los issues de microsoft/agent-framework

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.