Skip to content

fix(core): preserve initial messages when loading buffered contexts - #8207

Open
zoedsy wants to merge 1 commit into
microsoft:mainfrom
zoedsy:fix/buffered-context-initial-messages
Open

fix(core): preserve initial messages when loading buffered contexts#8207
zoedsy wants to merge 1 commit into
microsoft:mainfrom
zoedsy:fix/buffered-context-initial-messages

Conversation

@zoedsy

@zoedsy zoedsy commented Sep 8, 2026

Copy link
Copy Markdown

Why are these changes needed?

Reloading a BufferedChatCompletionContext component with initial_messages turns its messages into dictionaries because _from_config() unpacks config.model_dump(). This breaks the LLMMessage return contract and prevents get_messages() from removing a leading function result after truncation.

Pass the validated message objects directly to the constructor, as the other context implementations do. Add JSON component round-trip regressions for ordinary messages and a truncated tool-call exchange.

Related issue number

No existing issue; reproduced through a JSON component round trip.

Validation

  • Both new regression tests fail against the unchanged implementation.
  • pytest tests/test_model_context.py -q: 11 passed.
  • Ruff formatting and lint checks passed for both changed files.
  • Mypy passed for both changed files.

Checks

  • I've included any doc changes needed (no public API or documentation changes).
  • I've added tests corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed (upstream CI pending).

This change and its regression tests were prepared with Codex.

@zoedsy

zoedsy commented Sep 8, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

1 participant