Python: isolate hosted session snapshots#7141
Open
eavanvalkenburg wants to merge 3 commits into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75d26ffd-7dc7-46b3-9966-9aaebb7b6bc3
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75d26ffd-7dc7-46b3-9966-9aaebb7b6bc3
eavanvalkenburg
marked this pull request as ready for review
July 16, 2026 10:39
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Python hosting state model so hosted Responses continuations restore isolated session snapshots rather than returning a shared, mutable AgentSession instance, enabling safe branching from the same previous_response_id.
Changes:
- Make
SessionStore.get()return a deep-copiedAgentSession, and adjustAgentState.get_or_create_session()to return independent working copies. - Update hosting samples/docs to distinguish immutable
previous_response_idsnapshots from mutableconversation_idheads (which require app-owned single-writer coordination). - Add regression tests covering independent concurrent branches and
WorkflowState(cache_target=False)returning fresh workflow instances.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/samples/04-hosting/af-hosting/local_responses/README.md | Clarifies snapshot vs mutable-head semantics for previous_response_id vs conversation_id. |
| python/samples/04-hosting/af-hosting/local_responses/app.py | Persists session either under stable conversation_id (mutable head) or under new response_id (snapshot continuation). |
| python/samples/04-hosting/af-hosting/local_responses_workflow/README.md | Documents using cache_target=False to allow simultaneous workflow runs (fresh instances). |
| python/packages/hosting/tests/hosting/test_state.py | Updates/extends tests to validate copy-on-read session behavior and fresh targets when cache is disabled. |
| python/packages/hosting/README.md | Documents snapshot isolation semantics and workflow concurrency guidance. |
| python/packages/hosting/agent_framework_hosting/_state.py | Implements deep-copy snapshot reads and returns independent working sessions from get_or_create_session(). |
| python/packages/hosting-responses/tests/hosting_responses/test_http_round_trip.py | Adds regression coverage for independent branching from the same previous_response_id. |
| python/packages/hosting-responses/README.md | Documents snapshot (previous_response_id) vs mutable head (conversation_id) continuation patterns. |
| docs/specs/002-python-hosting-channels.md | Updates hosting spec to note workflow instance single-active-run constraint and fresh-instance pattern. |
| docs/decisions/0027-hosting-channels.md | Updates ADR text to reflect snapshot isolation on session reads and branching semantics. |
rogerbarreto
approved these changes
Jul 16, 2026
eavanvalkenburg
enabled auto-merge
July 16, 2026 14:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
Hosted Responses continuations currently retrieve the same mutable
AgentSessionobject from the in-memory store. Concurrent branches from oneprevious_response_idcan therefore mutate each other, and older response IDs do not remain independent continuation points.Description & Review Guide
SessionStore.get()now returns a deep copy,AgentStateseparates newly created working sessions from stored baselines, and regression coverage exercises independent concurrent branches. Hosting guidance now distinguishes immutable response snapshots from mutable conversation heads and explains fresh workflow targets for concurrent runs.conversation_idruns perform one explicit write back to the conversation key and remain subject to app-owned single-writer coordination.Related Issue
Fixes #7140
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.