Skip to content

refactor(agent-hypervisor)!: make session methods synchronous - #3645

Open
Tionne Smith (electricwolfemarshmallowhypertext) wants to merge 3 commits into
microsoft:mainfrom
electricwolfemarshmallowhypertext:marshmallow/hypervisor-sync-surface-current
Open

refactor(agent-hypervisor)!: make session methods synchronous#3645
Tionne Smith (electricwolfemarshmallowhypertext) wants to merge 3 commits into
microsoft:mainfrom
electricwolfemarshmallowhypertext:marshmallow/hypervisor-sync-surface-current

Conversation

@electricwolfemarshmallowhypertext

@electricwolfemarshmallowhypertext Tionne Smith (electricwolfemarshmallowhypertext) commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Related Issue

Fixes #3178.

Problem & Solution

The Hypervisor session surface mixed sync and async methods even though six methods had no internal await points.

This PR implements the maintainer-approved sync direction for:

  • create_session
  • join_session
  • activate_session
  • terminate_session
  • verify_behavior
  • monitor_sessions

Direct call sites were updated across the current repository. Unrelated same-name async APIs were left unchanged.

SagaOrchestrator.execute_step and compensate remain async, with a narrow runtime guard requiring executor/compensator results to be awaitable.

Impact on Your Work

Removes the mixed sync/async Hypervisor API footgun and makes the session surface consistent with the existing synchronous helpers and callers.

Timeline

None.

Alternatives Considered

Keeping the six methods async was rejected because they contain no internal await points and the maintainer explicitly selected the synchronous direction in #3178.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Maintenance (dependency updates, CI/CD, refactoring)
  • Security fix

Package(s) Affected

Core & runtime:

  • agent-governance-toolkit-core
  • agent-primitives
  • agent-os
  • agent-mesh
  • agent-runtime
  • agent-sre
  • agent-compliance

Governance & security:

  • agent-mcp-governance
  • agent-rag-governance
  • agent-sandbox
  • agent-discovery
  • agt-policies
  • policy-engine

Platform & tooling:

  • agent-hypervisor
  • agent-lightning
  • agent-marketplace
  • agent-governance-toolkit-cli
  • agent-governance-toolkit-integrations
  • agent-governance-toolkit-protocols
  • agentmesh-integrations (framework integrations)

CLI plugins:

  • agent-governance CLI plugins (copilot-cli / claude-code / opencode / antigravity-cli)

Shared / other:

  • schemas
  • action (GitHub Action)
  • examples
  • docs / root

Testing

Unit Testing

Focused Hypervisor test suite:

102 passed, 5 skipped

Manual Testing

  • py_compile passed for edited Python files
  • git diff --check passed
  • repo-wide search found zero stale awaited direct Hypervisor calls
  • unrelated mesh.create_session(...) await remains intentionally unchanged

Checklist

  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"
  • My code follows the project style guidelines (ruff check)
  • I have added tests that prove my fix/feature works
  • All new and existing focused tests pass (pytest)
  • I have updated documentation as needed
  • I have signed the Microsoft CLA

Attribution & Prior Art

  • This contribution does not contain code copied or derived from other projects without attribution
  • Any external projects that inspired this design are credited in code comments or documentation
  • If this PR implements functionality similar to an existing open-source project, I have listed it below

Prior art / related projects (if any):

None.

AI Assistance

  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered
  • I have run tests and verification appropriate for this change
  • No part of this PR was autonomously submitted by an AI agent without my review
  • I have not used AI to generate review comments on others' PRs

If AI tools materially shaped this change, briefly note what was used:

AI-assisted code review and repository search were used during implementation; all changes were reviewed and validated manually before submission.

IP, Patents, and Licensing

  • This contribution does not implement patent-pending or patent-encumbered techniques
  • This contribution does not require an NDA or licensing agreement to understand or use
  • Any AI tools used have terms compatible with the MIT License

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

🟡 Contributor Check: MEDIUM

Check Result
Profile MEDIUM
Credential LOW
Overall MEDIUM

Automated check by AGT Contributor Check.

@github-actions github-actions Bot added the needs-review:MEDIUM Contributor check flagged MEDIUM risk label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

PR Review Summary

Check Status Details
🔍 Code Review ⚠️ Missing No current-run comment
🛡️ Security Scan ⚠️ Missing No current-run comment
🔄 Breaking Changes ⚠️ Missing No current-run comment
📝 Docs Sync ⚠️ Missing No current-run comment
🧪 Test Coverage ⚠️ Missing No current-run comment

Verdict: ⚠️ AI review incomplete; ready for human review

AI review comments are untrusted advisory output. The summary reports workflow-generated completion status only, not model-authored pass/fail claims.

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.

Pull request overview

Syncs the Hypervisor session lifecycle API (6 methods) to remove async-without-await footguns, updates repo call sites (docs/tests/examples/API), and adds a runtime guard in SagaOrchestrator to ensure step executors/compensators return awaitables.

TL;DR: 1 blocker, 2 warnings. Fix #1 and this ships.

# Sev Issue Where
1 Block Awaitable guard rejects valid non-coroutine awaitables SagaOrchestrator._ensure_awaitable
2 Warn Quick start missing required creator_did (example will raise TypeError) docs/packages/agent-runtime.md
3 Warn Quick start missing required creator_did (example will raise TypeError) agent-governance-python/agent-runtime/README.md

#1: Validate generic awaitables (e.g., __await__) instead of only asyncio.isfuture/iscoroutine.

Changes:

  • Convert Hypervisor session lifecycle methods from async defdef.
  • Update Python call sites (API server, tests, examples, benchmarks) to remove await.
  • Add an executor/compensator awaitable return-type guard in SagaOrchestrator.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/packages/agent-runtime.md Update runtime quick start to sync session creation
docs/packages/agent-os.md Update runtime session lifecycle example to sync calls
docs/packages/agent-hypervisor.md Update hypervisor lifecycle examples to sync calls
agent-governance-python/agent-runtime/README.md Update runtime README example to sync session creation
agent-governance-python/agent-os/README.md Update Agent OS README lifecycle example to sync calls
agent-governance-python/agent-hypervisor/tests/unit/test_cli.py Remove awaits in fixture session setup
agent-governance-python/agent-hypervisor/tests/test_agent_manager.py Remove awaits across hypervisor unit tests
agent-governance-python/agent-hypervisor/tests/integration/test_scenarios.py Remove awaits in integration scenarios
agent-governance-python/agent-hypervisor/tests/integration/test_hypervisor_e2e.py Remove awaits in E2E hypervisor tests
agent-governance-python/agent-hypervisor/src/hypervisor/saga/orchestrator.py Add runtime awaitable guard for step execution/compensation
agent-governance-python/agent-hypervisor/src/hypervisor/core.py Make session lifecycle methods synchronous
agent-governance-python/agent-hypervisor/src/hypervisor/api/server.py Update FastAPI handlers to call sync hypervisor methods
agent-governance-python/agent-hypervisor/README.md Update README lifecycle examples to sync calls
agent-governance-python/agent-hypervisor/examples/docker-compose/app/server.py Update example server to call sync hypervisor methods
agent-governance-python/agent-hypervisor/examples/demo.py Update demo flows to call sync hypervisor methods
agent-governance-python/agent-hypervisor/docs/api-reference.md Update API reference examples to sync calls
agent-governance-python/agent-hypervisor/benchmarks/bench_hypervisor.py Update benchmarks to call sync lifecycle methods
agent-governance-python/agent-compliance/examples/governed_agent.py Update compliance example to call sync runtime session creation

Comment on lines +238 to +240
def _ensure_awaitable(self, result: Any, name: str) -> None:
if not asyncio.isfuture(result) and not asyncio.iscoroutine(result):
raise TypeError(f"{name} must return an awaitable")
Comment on lines +57 to 59
session = hv.create_session(
config=SessionConfig(consistency_mode=ConsistencyMode.EVENTUAL)
)
Comment on lines +51 to 53
session = hv.create_session(
config=SessionConfig(consistency_mode=ConsistencyMode.EVENTUAL)
)

@MohammadHaroonAbuomar MohammadHaroonAbuomar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • PR title: fails the required Validate PR title check; use the conventional format with the breaking marker, e.g. refactor(agent-hypervisor)!: make session methods synchronous.
  • BREAKING_CHANGES.md: no entry, though the six converted methods ship in the published agent-governance-toolkit-core wheel (the pyproject force-includes hypervisor/src), so external consumers awaiting them break. Add an entry with a how-to-update line (drop the await).

Minor:

  • a small test for _ensure_awaitable would make the checklist claim true; everything else verified clean: zero stale awaited call sites repo-wide, 640/640 hypervisor tests on the sync API, no fail-open - the conversion actually removes the forgot-await silent no-op class. Direction is maintainer-ordered per issue #3178.

Comment on lines +238 to +240
def _ensure_awaitable(self, result: Any, name: str) -> None:
if not asyncio.isfuture(result) and not asyncio.iscoroutine(result):
raise TypeError(f"{name} must return an awaitable")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

_ensure_awaitable accepts only asyncio.isfuture/iscoroutine, rejecting generic await-only awaitables that asyncio.wait_for accepted before this change (verified both sides) - use inspect.isawaitable. Also raise the guard's TypeError outside the retry try: currently a misconfigured sync executor is re-invoked through every retry with backoff (3 calls / 3s probed), repeating side effects before surfacing.

@electricwolfemarshmallowhypertext Tionne Smith (electricwolfemarshmallowhypertext) changed the title Make hypervisor session methods synchronous refactor(agent-hypervisor)!: make session methods synchronous Aug 7, 2026
@electricwolfemarshmallowhypertext

Copy link
Copy Markdown
Contributor Author

MohammadHaroonAbuomar

Addressed the review items:

  • _ensure_awaitable now uses inspect.isawaitable
  • executor contract errors are validated before retry/backoff, so invalid sync executors fail once without repeated side effects
  • added regression coverage for generic await objects and single-call failure behavior
  • updated the PR title to the breaking-change conventional format
  • added the BREAKING_CHANGES.md migration note
  • fixed the two runtime examples to include required creator_did

Validation:

  • 119 passed, 5 skipped
  • Ruff passed
  • py_compile passed
  • git diff --check passed

Ready for re-review.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed current head 1c76630f. The approved sync direction is implemented consistently across the six Hypervisor methods and direct repository call sites.

The subsequent blockers are all addressed:

  • generic __await__ objects are accepted via inspect.isawaitable;
  • sync executor contract violations are rejected before retry/backoff, preventing repeated side effects;
  • both behaviors have focused regression tests;
  • the breaking API change is documented with the correct “drop await” migration;
  • runtime examples now pass the required creator_did;
  • unrelated async Saga APIs remain awaited.

The content is approved. GitHub currently reports the branch as not mergeable, so any current base conflict/check gate still needs to be resolved before merge.

Signed-off-by: Electric Wolfe Marshmallow Hypertext <tionne@gmail.com>
Signed-off-by: Electric Wolfe Marshmallow Hypertext <tionne@gmail.com>
Signed-off-by: Electric Wolfe Marshmallow Hypertext <tionne@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-hypervisor agent-hypervisor package documentation Improvements or additions to documentation needs-review:MEDIUM Contributor check flagged MEDIUM risk size/XL Extra large PR (500+ lines) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hypervisor/SagaOrchestrator: async-without-await methods create a mixed sync/async surface (footgun)

4 participants