Skip to content

Python: Preserve the AG-UI RUN_ERROR code in AGUIChatClient - #8830

Open
Gabriel (gabe-santana) wants to merge 1 commit into
microsoft:mainfrom
gabe-santana:issue-8828
Open

Gabriel (gabe-santana) wants to merge 1 commit into
microsoft:mainfrom
gabe-santana:issue-8828

Conversation

@gabe-santana

Copy link
Copy Markdown
Contributor

Motivation & Context

The AG-UI server in this package sends a specific code with each RUN_ERROR event so clients can tell failures apart. Examples are APPROVAL_INVOCATION_DISABLED (the approved tool stays pending for an explicit retry), APPROVAL_RESUME_NOT_FOUND, WORKFLOW_CHECKPOINT_LOAD_FAILED, and the exception type name for unexpected failures.

AGUIChatClient discarded that code. AGUIEventConverter._handle_run_error created the error content with a hard-coded error_code="RUN_ERROR", so a Python caller got "RUN_ERROR" for every failure and couldn't decide whether to retry, re-submit a resume, or give up. The hard-coded value dates from the first version of the client (#2072), before the server sent specific codes.

Description & Review Guide

  • What are the major changes? _handle_run_error now uses the event's code as the error content's error_code, falling back to "RUN_ERROR" when the event has no code.
  • What is the impact of these changes? AGUIChatClient callers now see the server's error code. Events without a code produce the same result as before. There are no public API changes.
  • What do you want reviewers to focus on? Whether the server's code should be the error_code itself or kept elsewhere, for example in additional_properties. Using error_code matches what the AG-UI event means and keeps the existing fallback.

Validation:

  • Added test_run_error_event_preserves_server_code (converter) and test_get_response_streaming_preserves_run_error_code (AGUIChatClient streaming). Both fail on current main and pass with this change. The existing test_run_error_event, which has no code, still passes.
  • The end-to-end reproduction from Python: [Bug]: AGUIChatClient replaces the server's RUN_ERROR code with a generic "RUN_ERROR" #8828, a real AG-UI FastAPI endpoint called through AGUIChatClient, now reports TimeoutError instead of RUN_ERROR.
  • uv run poe test -P ag-ui: 1395 passed, 14 skipped.
  • uv run poe syntax -P ag-ui and uv run poe test-typing -P ag-ui pass.
  • Source Pyright reports the same three ag_ui_a2ui_toolkit import errors as on unchanged main.

Related Issue

Fixes #8828

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 is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • 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 any language prefix) — a workflow keeps the label and title prefix in sync automatically.

AGUIEventConverter built RUN_ERROR error content with a hard-coded
"RUN_ERROR" code, so AGUIChatClient callers could not tell apart the
specific codes the AG-UI server sends, such as
APPROVAL_INVOCATION_DISABLED or APPROVAL_RESUME_NOT_FOUND. Use the
event's code when present and keep "RUN_ERROR" as the fallback.

Fixes microsoft#8828

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.

Copilot review overview

🟢 Approval recommended

The focused implementation matches the protocol behavior and includes appropriate regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Preserves server-provided AG-UI RUN_ERROR codes while retaining the existing fallback.

Changes:

  • Maps event code to Content.error_code.
  • Adds converter and streaming-client regression coverage.
File Description
python/​packages/​ag-ui/​agent_framework_ag_ui/​_event_converters.py Preserves server error codes.
python/​packages/​ag-ui/​tests/​ag_ui/​test_event_converters.py Tests converter behavior.
python/​packages/​ag-ui/​tests/​ag_ui/​test_ag_ui_client.py Tests streaming propagation.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@moonbox3

Copy link
Copy Markdown
Contributor

Please fix the failing CI/CD checks.

This branch was successfully deployed

1 active deployment
github-app-auth — 32c2e30e Deployed Sep 29, 2026 by gabe-santana via team_check #5489
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: AGUIChatClient replaces the server's RUN_ERROR code with a generic "RUN_ERROR"

3 participants