Skip to content

Add request_id field to Activity - #591

Merged
Rodrigo Brandão (rodrigobr-msft) merged 6 commits into
mainfrom
users/robrandao/request-id
Sep 18, 2026
Merged

Rodrigo Brandão (rodrigobr-msft) merged 6 commits into
mainfrom
users/robrandao/request-id

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request introduces support for propagating a request_id field throughout the activity and conversation reference lifecycle, ensuring that requests can be traced end-to-end. The request_id is now generated for each incoming HTTP request, attached to Activity objects, and properly propagated through ConversationReference and related methods. Comprehensive tests have been added to verify the correct handling and propagation of request_id.

Key changes include:

Request ID Propagation:

  • Added a request_id field to both the Activity and ConversationReference models, allowing the request ID to be stored and transferred between these objects. [1] [2]
  • Updated the apply_conversation_reference and get_conversation_reference methods in Activity to propagate the request_id field when converting between Activity and ConversationReference. [1] [2]
  • Ensured that get_continuation_activity in ConversationReference also propagates the request_id to the new Activity instance.

Request ID Generation:

  • Modified the HTTP adapter base so that a new request_id is generated using uuid4() for each incoming request and assigned to the corresponding Activity. [1] [2]

Testing Enhancements:

  • Added and updated tests to verify that request_id is correctly propagated through Activity and ConversationReference methods, and that it defaults to None when not provided. [1] [2] [3] [4] [5]
  • Updated test imports and utility functions to support request_id handling.

Copilot AI lite review requested due to automatic review settings September 17, 2026 20:49
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) marked this pull request as ready for review September 17, 2026 20:50

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

Normal TurnContext sends and agent-to-agent posts still drop request_id, leaving propagation incomplete.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds internal request_id correlation across activities, conversation references, and HTTP ingress.

Changes:

  • Adds and propagates request_id fields.
  • Generates UUIDs for incoming HTTP activities.
  • Adds propagation tests.
File summaries
File Description
activity.py Adds Activity request ID support.
conversation_reference.py Adds continuation propagation.
_http_adapter_base.py Generates request IDs.
test_activity.py Tests Activity propagation.
test_conversation_reference.py Tests continuation propagation.
test_http_adapter_telemetry.py Updates telemetry test imports.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 3
  • Review effort level: Lite

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

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.

🔵 Needs a closer look

Normal TurnContext reply paths still drop request_id, and generation lacks a focused test.

Review details

Suppressed comments (3)

Previously missed (1) — in code that hasn't changed since the last review.

tests/hosting_core/telemetry/test_http_adapter_telemetry.py:17

  • Neither uuid nor Activity is referenced anywhere in this test module, so these new imports trigger unused-import lint failures and should be removed unless the missing request-ID assertion is added.

libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py:310

  • This updates only Activity.apply_conversation_reference, but normal replies and updates go through the separate TurnContext.apply_conversation_reference implementation (turn_context.py:346-374), which does not copy reference.request_id. As a result, context.send_activity() produces an outgoing activity with a missing request ID, so this propagation is bypassed on the primary send path. Update the TurnContext helper as well (or delegate to the Activity implementation) and cover that path with a test.
        self.request_id = reference.request_id

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/_http_adapter_base.py:120

  • The new UUID assignment is not covered by the added telemetry tests: none asserts that the activity passed to process_activity receives a valid per-request ID. The newly added uuid and Activity imports in test_http_adapter_telemetry.py are also unused, which suggests the intended assertion is missing; add a focused test that captures the processed activity and validates its request_id.
            activity.request_id = str(uuid4())
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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.

🔵 Needs a closer look

Derived activity helpers drop request_id, and HTTP request-ID generation lacks regression coverage.

Review details

Suppressed comments (2)

Previously missed (1) — in code that hasn't changed since the last review.

libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py:202

  • Adding the field here does not propagate it through Activity.create_reply() and Activity.create_trace(): both helpers construct a new Activity from self but never pass self.request_id. A caller that uses either helper directly (or before TurnContext.apply_conversation_reference) loses the correlation ID, so the new field is not preserved across these Activity transformations. Pass the ID into both derived activities and cover it.

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/_http_adapter_base.py:120

  • The new UUID assignment has no regression test. The updated HTTP adapter telemetry module only adds unused uuid and Activity imports, so the suite would still pass if request_id were never assigned or were reused. Capture the activity passed to process_activity and assert a valid, distinct UUID for separate requests.
            activity.request_id = str(uuid4())
  • Files reviewed: 9/9 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

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

Unresolved moderate findings remain around request-ID generation, serialization, and HTTP-channel propagation coverage.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (5)

libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py:202

  • Activity's public fields are documented in the class docstring, but the new request_id field has no corresponding :param:/:type: entry. Document that it is an internal request identifier and explain its wire-serialization behavior so the generated API documentation does not omit the new field's contract.
    request_id: str | None = Field(None, exclude=True)

libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py:202

  • The exclude=True choice is an important wire-format contract, but no updated serialization test sets request_id and verifies that top-level requestId is omitted from Activity.model_dump(...). Add that assertion so a future model/serializer change cannot accidentally expose every generated request ID in channel payloads.
    request_id: str | None = Field(None, exclude=True)

libraries/microsoft-agents-activity/microsoft_agents/activity/conversation_reference.py:56

  • ConversationReference's class docstring documents the existing fields through service_url, but it does not document the new request_id field. Add its parameter and type documentation so consumers of this public model understand how the propagated identifier is intended to be used.
    request_id: str | None = None

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/_http_adapter_base.py:120

  • The new UUID generation is not covered by the updated telemetry tests: they only assert spans/metrics, and the Activity received by process_activity is never inspected. Add a test that captures that activity and verifies request_id is a UUID (and that separate requests get distinct IDs), otherwise this tracing contract can regress unnoticed.
            activity.request_id = str(uuid4())

tests/hosting_core/telemetry/test_http_adapter_telemetry.py:10

  • The newly added uuid and Activity imports are unused anywhere in this test module. Please either use them in the request-ID test or remove them; as written they add lint noise and indicate the new HTTP-path behavior is not covered.
import uuid
  • Files reviewed: 9/9 changed files
  • Comments generated: 1
  • Review effort level: Lite

@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) merged commit f62a47c into main Sep 18, 2026
11 checks passed
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) deleted the users/robrandao/request-id branch September 18, 2026 20:02
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.

3 participants