Skip to content

fix(maf): preserve legacy streaming context#241

Merged
sipercai merged 1 commit into
mainfrom
fix/maf-streaming-context
Jul 9, 2026
Merged

fix(maf): preserve legacy streaming context#241
sipercai merged 1 commit into
mainfrom
fix/maf-streaming-context

Conversation

@sipercai

@sipercai sipercai commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR fixes legacy Microsoft Agent Framework streaming agent telemetry for MAF versions whose ResponseStream does not provide with_pull_context_manager.

The bridge now backports the per-pull context manager surface for legacy streams and wraps legacy streaming agent invocation so the AGENT span is created before execute(), activated while the stream resolves and yields updates, and finalized with response/content capture during stream cleanup. This preserves AGENT -> STEP -> LLM/TOOL parent-child relationships and AGENT input/output capture for legacy streaming paths while leaving modern MAF behavior unchanged through feature detection.

Fixes # (N/A)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • uvx ruff check instrumentation-loongsuite/loongsuite-instrumentation-microsoft-agent-framework/src/opentelemetry/instrumentation/microsoft_agent_framework/util_genai_bridge.py instrumentation-loongsuite/loongsuite-instrumentation-microsoft-agent-framework/tests/test_util_genai_bridge.py
  • uvx tox -r -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-microsoft-agent-framework
  • uvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-microsoft-agent-framework
  • PRE_COMMIT_HOME="$(mktemp -d)" uvx tox -e precommit

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Validation Evidence

Spec and Scope

  • Linked issue/spec: N/A; direct bug report for broken legacy MAF streaming span links and missing content capture.
  • Approved spec/comment: user requested a branch fix plus CMS2 validation before PR submission.
  • Changed surface: loongsuite-instrumentation-microsoft-agent-framework legacy streaming bridge and focused tests.

Local Checks

Check Command Result Notes
Static readiness python "$PIPELINE_SKILL_DIR/scripts/check_loongsuite_pr_readiness.py" --repo . pass LoongSuite static readiness checker exited 0.
Precommit PRE_COMMIT_HOME="$(mktemp -d)" uvx tox -e precommit pass Fresh hook cache.
Focused tests uvx tox -r -c tox-loongsuite.ini -e py311-test-loongsuite-instrumentation-microsoft-agent-framework pass 70 passed.
Focused lint uvx tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-microsoft-agent-framework pass Ruff passed.
External review qoder_team_review.py review . --backend deep pass Two review rounds; no blocking findings.
Privacy scan Branch diff secret/local-path scan pass No matches in the public diff.
Source package naming Source metadata/dependency check pass Source still uses opentelemetry-util-genai; no release artifact rename.

Real E2E Matrix

Scenario Status Command or Demo Evidence
non-streaming N/A Existing path delegates to the original MAF implementation. The changed compatibility branch only runs for stream=True legacy streams.
streaming pass Legacy agent-framework-core==1.0.0 streaming smoke exported through OTLP. Internal CMS2 readback confirmed one connected AGENT -> STEP -> LLM + TOOL trace; private trace details omitted.
concurrency blocked Not run in this targeted smoke. Follow-up would run two simultaneous legacy streaming invocations and compare trace isolation.
agent/tool/ReAct pass Legacy streaming smoke with one synthetic ReAct step, one LLM span, and one tool span. Parent-child tree and span kinds matched the expected hierarchy.
tool-heavy blocked Not run in this targeted smoke. Follow-up would add multiple tool invocations; the reported bug was reproduced with one tool call.
error path blocked Not run in this targeted smoke. Follow-up would raise from the async stream and assert the AGENT span records error status.

Telemetry and Weaver

Check Status Command or Artifact Notes
Span tree / span kinds pass CMS2 trace tree readback AGENT, STEP, LLM, and TOOL were connected in one trace.
Content capture modes pass CMS2 attribute readback and focused unit test AGENT/LLM input/output and TOOL arguments/result were captured when content capture was enabled.
Concurrency isolation blocked Not run in this targeted smoke. See E2E matrix concurrency row.
Weaver live-check pass weaver registry live-check -r <loongsuite-semantic-conventions>/model --advice-profile loongsuite-genai ... Exit code 0; no blocking violations.

CI

  • GitHub checks: pending; PR not opened yet.
  • Known unrelated failures: none known.
  • Follow-up needed: inspect GitHub CI after PR creation.

@sipercai sipercai marked this pull request as ready for review July 9, 2026 04:36

@ralf0131 ralf0131 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.

Summary

Fixes legacy MAF streaming agent telemetry by backporting with_pull_context_manager to older ResponseStream versions and wrapping the agent trace invocation so the AGENT span is created before execute(), activated during stream resolution, and finalized with response/content capture during cleanup. This preserves AGENT → STEP → LLM/TOOL parent-child relationships for legacy streaming paths while leaving modern MAF behavior unchanged via feature detection.

Findings

No issues found. The implementation is clean:

  • Feature detection (hasattr) correctly gates the legacy path, leaving modern MAF untouched
  • weakref.finalize provides a robust safety net for span cleanup if the stream is GC'd without proper teardown
  • Context var tracking (INNER_RESPONSE_TELEMETRY_CAPTURED_FIELDS / INNER_ACCUMULATED_USAGE) prevents double-capture
  • _finalize_stream properly captures exceptions without re-raising (telemetry shouldn't break the stream)
  • Comprehensive test verifies parent-child span relationships, input/output capture, and proper revert

CI: all checks passing. Changelog updated.


Automated review by github-manager-bot

@sipercai sipercai merged commit c86e01f into main Jul 9, 2026
19 of 23 checks passed
@sipercai sipercai deleted the fix/maf-streaming-context branch July 9, 2026 05:57
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