Python: Fix Hyperlight CodeAct span parenting#6712
Open
eavanvalkenburg wants to merge 3 commits into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes OpenTelemetry span parenting for CodeAct host-tool calls executed inside execute_code when Hyperlight crosses thread boundaries, so traces reflect the true nested execution flow.
Changes:
- Propagate the active
contextvarscontext into Hyperlight’s worker thread executor path. - Propagate the active
contextvarscontext into the dedicated thread used to run the async sandbox callback (asyncio.run(...)). - Add a regression test asserting the host tool span is a child of the
execute_codetool span.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/hyperlight/agent_framework_hyperlight/_execute_code_tool.py | Copies and replays contextvars context across the Hyperlight worker-thread boundary and the sandbox-callback thread boundary to preserve OTEL parent span context. |
| python/packages/hyperlight/tests/hyperlight/test_hyperlight_codeact.py | Adds an in-memory OTEL exporter fixture and a regression test asserting correct parent/child span relationship for host tool calls inside execute_code. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TaoChenOSU
approved these changes
Jun 24, 2026
giles17
approved these changes
Jun 24, 2026
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
CodeAct host-tool calls made from inside
execute_codewere losing their parent span when Hyperlight hopped onto its worker thread. That made the execution flow look flattened in OTEL backends and hid the nested relationship betweenexecute_codeand the host tool call.Description & Review Guide
execute_code.Related Issue
Fixes #6704
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.