Skip to content

Python: Preserve message status in chat history XML - #14453

Open
Gali (Jokasa7) wants to merge 2 commits into
microsoft:mainfrom
Jokasa7:JoyCx/fix-chat-history-xml-status
Open

Gali (Jokasa7) wants to merge 2 commits into
microsoft:mainfrom
Jokasa7:JoyCx/fix-chat-history-xml-status

Conversation

@Jokasa7

@Jokasa7 Gali (Jokasa7) commented Sep 17, 2026

Copy link
Copy Markdown

Motivation and Context

Python ChatMessageContent.status records the Responses API message state, but ChatHistory.to_prompt() / str(history) omits that field from the XML message attributes. Loading the rendered prompt therefore silently changes every explicit status (completed, failed, in_progress, or incomplete) to None.

Description

Include the existing optional status field in ChatMessageContent.to_element()'s XML attribute allowlist. The existing enum handling writes its string value, and ChatMessageContent.from_element() already validates that value back into Status. Legacy XML without a status attribute continues to deserialize with status=None.

Regression tests cover all four Status values through both public ChatHistory XML serialization entry points. They also verify that clearing an optional status after construction omits the XML attribute instead of passing None to ElementTree.

Validation

  • New regression cases against the original implementation: 8 failed.
  • The original eight cases plus two cleared-status cases with the final fix: 10 passed. The cleared-status cases failed with TypeError: cannot serialize None before the follow-up guard.
  • pytest tests/unit/contents -q: 404 passed, with existing deprecation warnings.
  • Official Python pre-commit checks passed for the changed files and for the whole repository, including Ruff lint/format, uv-lock, and Bandit.
  • Full-package mypy checked 555 source files and reported 23 errors in 6 unchanged files. The diagnostic set exactly matches the clean-worktree baseline previously captured at this same base commit; this change adds no reported type errors, but this is not a clean full-package type-check claim.

Contribution Checklist

  • The code builds clean without any errors or warnings — the full-package type-check limitation is recorded above.
  • The PR follows the SK Contribution Guidelines and the pre-submission formatting script raises no violations.
  • All relevant unit tests pass, and regression coverage has been added.
  • Legacy XML without status retains its existing behavior.

Prepared with AI assistance, including the implementation, tests, and this description. The behavior was reproduced and validated locally without a live provider request.

Copilot AI lite review requested due to automatic review settings September 17, 2026 09:17
@Jokasa7
Gali (Jokasa7) requested a review from a team as a code owner September 17, 2026 09:17

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

Explicitly setting an optional status to None can cause XML serialization to fail instead of omitting the attribute.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR preserves ChatMessageContent.status values during chat history XML serialization.

Changes:

  • Adds status to XML message attributes.
  • Adds round-trip tests for all status values and serialization entry points.
File summaries
File Summary
python/tests/unit/contents/test_chat_history.py Tests status XML round trips.
python/semantic_kernel/contents/chat_message_content.py Serializes message status attributes.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

root = Element(self.tag)
for field in self.model_fields_set:
if field not in ["role", "name", "encoding", "finish_reason", "ai_model_id"]:
if field not in ["role", "name", "encoding", "finish_reason", "status", "ai_model_id"]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants