Skip to content

Python: fix empty local shell calls leaving orphaned history - #9803

Open
M-Hietala wants to merge 1 commit into
microsoft:mainfrom
M-Hietala:m-hietala/python_fix_empty_local_shell_calls_leaving_orphaned_history
Open

M-Hietala wants to merge 1 commit into
microsoft:mainfrom
M-Hietala:m-hietala/python_fix_empty_local_shell_calls_leaving_orphaned_history

Conversation

@M-Hietala

@M-Hietala M-Hietala commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Motivation & Context

Empty local shell calls (commands=[]) currently leave a shell call without a matching output in conversation history. Stateless continuation can then fail with HTTP 400: “No tool output found for shell call.”

This change treats an empty command list as a no-op and returns a matching empty output without executing a shell command.

A live Azure OpenAI check using a gpt-6.1-sol deployment confirmed that replaying the empty shell call without an output returns HTTP 400 (“No tool output found for shell call”). The same request with the matching shell_call_output containing output=[] completed successfully. No shell commands were executed.

Description & Review Guide

  • What are the major changes?
    Pair empty shell calls for a configured local executor with shell_call_output containing output=[]. Support replay of the synthetic result, preserve max_output_length, and document the behavior in the function-loop specification. Add 17 regression cases covering both parsers, streaming finalization, replay, and unaffected cases.

  • What is the impact of these changes?
    Empty local shell calls no longer leave orphaned calls in stateless history. Hosted, unconfigured, and malformed calls retain their existing handling. The separate shell checkpoint-persistence issue (Python: [Bug]: LocalShellTool result text cannot be persisted by FileSessionStore #9696) is outside this change.

    The core and OpenAI unit-test suites passed. A live Azure OpenAI check using a gpt-6.1-sol deployment reproduced the missing-output error without the result and completed successfully with the paired empty output.

  • What do you want reviewers to focus on?
    The no-op interpretation, call/result pairing, and preservation of the local-versus-hosted shell boundary. No local execution or approval is entered for the empty command list.

Related Issue

Fixes #9697

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Copilot assisted with implementation, tests, documentation, focused validation, the live-test diagnostic, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after a language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 16:35
@M-Hietala
M-Hietala deployed to github-app-auth October 28, 2026 16:36 — with GitHub Actions Active
@M-Hietala
M-Hietala deployed to github-app-auth October 28, 2026 16:36 — with GitHub Actions Active
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Oct 28, 2026
@M-Hietala
M-Hietala deployed to github-app-auth October 28, 2026 16:37 — with GitHub Actions Active
@M-Hietala
M-Hietala marked this pull request as ready for review October 28, 2026 16:39
@M-Hietala
M-Hietala deployed to github-app-auth October 28, 2026 16:39 — with GitHub Actions Active

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Service-side continuation and mixed-tool batches still discard synthetic shell-tool output, which can cause requests to fail with unresolved shell calls.

1 open issue
What changed in this PR

This PR addresses #9697 by pairing empty local shell calls with synthetic empty outputs, preventing orphaned calls in stateless conversation history without executing commands or requesting approval.

Changes:

  • Generate empty results for valid empty calls targeting a configured local executor.
  • Support replay of synthetic results while preserving max_output_length.
  • Add 17 regression cases and document the no-op behavior; shell checkpoint persistence remains out of scope.
File Description
python/​packages/​openai/​tests/​openai/​test_openai_chat_client.py Adds parser, streaming, replay, and unaffected-case regression coverage.
python/​packages/​openai/​agent_framework_openai/​_chat_client.py Creates synthetic empty shell results and supports their replay.
docs/​specs/​004-python-function-calling-loop.md Defines empty local shell semantics and maps regression tests.

Review effort: Balanced

Comment on lines +2608 to +2612
Content.from_shell_tool_result(
call_id=shell_call_id,
outputs=[],
max_output_length=shell_max_output,
)

This branch was successfully deployed

1 active deployment
github-app-auth — 6fbe168c Deployed Oct 28, 2026 by M-Hietala via team_check #7918
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Empty local shell commands produce an orphan shell call on replay

3 participants