🐛 Bug Report: OpenAI Agents: with two concurrent runs of the same agent, a handoff span is recorded in the other run's trace
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- observability, testing-qa
Hướng nghiên cứu
Start in the OpenAI Agents SDK instrumentation, especially _start_handoff_span() and _find_agent_span(from_agent), then reproduce the issue with the supplied concurrent run script. Check how each run's trace context is tracked and how the handoff target is named; done when the handoff span appears under run B's assistant.agent span in trace 2. PR #4639 is already open against this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Which component is this bug for?
OpenAI Instrumentation
📜 Description
Package: opentelemetry-instrumentation-openai-agents (OpenAI Agents SDK instrumentation; it is not in the component list).
When an app runs the same agent twice at the same time (for example a server handling two requests), the handoff span of one run is recorded in the trace of the other run, and the run that handed off has no handoff span in its own trace.
_start_handoff_span() takes the parent from _find_agent_span(from_agent), which searches the open agent spans of all runs by agent name and returns the first match, not the agent span of the handoff's own trace. The handoff span is also named assistant → unknown.handoff, since to_agent is not known yet when the span starts.
👟 Reproduction steps
# OpenAI Agents SDK: two concurrent runs of the same agent (two requests to one app). The handoff span of run B is
# recorded in run A's trace, and run B's trace has no handoff span.
import asyncio, json, sys
from importlib.metadata import version
import openai
try:
import httpx2 as httpx # openai >= 3
except ImportError:
import httpx
from opentelemetry.sdk.trace import SpanProcessor, TracerProvider
from agents import Agent, Runner, function_tool, set_default_openai_client, set_trace_processors
from opentelemetry.instrumentation.openai_agents import OpenAIAgentsInstrumentor
class Spans(SpanProcessor):
def __init__(self): self.ended = []
def on_end(self, span): self.ended.append(span)
spans = Spans(); provider = TracerProvider(); provider.add_span_processor(spans)
SCRIPTS = {"A": ["tool", "text"], "B": ["tool", "handoff", "text"]} # only run B hands off
TURN = {}
def respond(request): # a local stand-in for the Responses API, one script per run
body = json.loads(request.content)
first_user = next(i for i in body["input"] if i.get("role") == "user")
run = first_user["content"].split()[-1] # the user asks "question A" or "question B"
n = TURN[run] = TURN.get(run, 0) + 1
step = SCRIPTS[run][n - 1] if n <= len(SCRIPTS[run]) else "text"
item = {"tool": {"type": "function_call", "id": f"fc_{run}{n}", "call_id": f"call_{run}{n}", "name": "lookup",
"arguments": json.dumps({"q": "weather"}), "status": "completed"},
"handoff": {"type": "function_call", "id": f"fc_{run}{n}", "call_id": f"call_{run}{n}",
"name": "transfer_to_specialist", "arguments": "{}", "status": "completed"},
"text": {"type": "message", "id": f"msg_{run}{n}", "status": "completed", "role": "assistant",
"content": [{"type": "output_text", "annotations": [], "text": f"answer for {run}"}]}}[step]
resp = {"id": f"resp_{run}{n}", "object": "response", "created_at": 0, "status": "completed", "model": "m",
"parallel_tool_calls": True, "tool_choice": "auto", "tools": [], "output": [item],
"usage": {"input_tokens": 3, "output_tokens": 2, "total_tokens": 5,
"input_tokens_details": {"cached_tokens": 0}, "output_tokens_details": {"reasoning_tokens": 0}}}
events = [{"type": "response.created", "response": dict(resp, status="in_progress", output=[])},
{"type": "response.output_item.added", "output_index": 0,
"item": dict(item, status="in_progress", **({"content": []} if item["type"] == "message" else {"arguments": ""}))},
{"type": "response.output_item.done", "output_index": 0, "item": item},
{"type": "response.completed", "response": resp}]
text = "".join(f"event: {e['type']}\ndata: {json.dumps(dict(e, sequence_number=i))}\n\n" for i, e in enumerate(events))
return httpx.Response(200, headers={"content-type": "text/event-stream"}, content=text.encode())
set_trace_processors([]) # no export to OpenAI
set_default_openai_client(openai.AsyncOpenAI(api_key="x", base_url="http://mock/v1", max_retries=0,
http_client=httpx.AsyncClient(transport=httpx.MockTransport(respond))), use_for_tracing=False)
@function_tool
def lookup(q: str) -> str:
"""Look something up."""
return "sunny"
specialist = Agent(name="specialist", instructions="Answer in detail.", model="m")
assistant = Agent(name="assistant", instructions="Answer briefly.", model="m", tools=[lookup], handoffs=[specialist])
async def main():
print(f"opentelemetry-instrumentation-openai-agents {version('opentelemetry-instrumentation-openai-agents')} | "
f"openai-agents {version('openai-agents')} | python {sys.version.split()[0]}")
OpenAIAgentsInstrumentor().instrument(tracer_provider=provider)
run_a = Runner.run_streamed(assistant, "question A") # run A: a tool call, then an answer
run_b = Runner.run_streamed(assistant, "question B") # run B: a tool call, a handoff to the specialist, an answer
async for _ in run_a.stream_events(): # both runs are in flight; the app reads A, then B
pass
async for _ in run_b.stream_events():
pass
traces = {}
for s in sorted(spans.ended, key=lambda s: s.start_time):
traces.setdefault(s.context.trace_id, []).append(s.name)
for i, names in enumerate(traces.values(), 1):
print(f"trace {i}: {names}")
asyncio.run(main())
👍 Expected behavior
Each run's spans are in its own trace: the handoff span is in trace 2, under run B's assistant.agent span.
👎 Actual Behavior with Screenshots
opentelemetry-instrumentation-openai-agents 0.62.4 | openai-agents 0.24.0 | python 3.13.7
trace 1: ['Agent Workflow', 'assistant.agent', 'openai.response', 'lookup.tool', 'openai.response', 'assistant → unknown.handoff']
trace 2: ['Agent Workflow', 'assistant.agent', 'openai.response', 'lookup.tool', 'openai.response', 'specialist.agent', 'openai.response']
🤖 Python Version
3.13 (also seen with 3.12)
📃 Provide any additional context for the Bug.
Trace 1 is run A, which calls the tool and answers; it never hands off. Trace 2 is run B, which calls the tool, hands
off to specialist and answers. opentelemetry-instrumentation-openai-agents 0.62.4 (the latest release; main has no changes to this package since), openai-agents 0.24.0 (also 0.23.1). Related: PR #4097.
👀 Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
None
- Ngôn ngữ chính
- Python
- Star
- 7.5k
- Fork
- 1.2k
- Merge trung bình
- 2 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của traceloop/openllmetry
-
bug python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4717 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentationCó thể đã có người làm @Quantum-Enigma-dot đã nhận 21 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
traceloop/openllmetry#4665 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completionsCó thể đã có người làm @jayfeng7 đã nhận 23 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
traceloop/openllmetry#4660 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Report: Failed dataset deletes still remove local rows and columnsCó thể đã có người làm @inchang-ing đã nhận 32 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
traceloop/openllmetry#4630 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penaltyCó thể đã có người làm @shantam77 đã nhận 38 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
traceloop/openllmetry#4598 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của traceloop/openllmetry
Issue tương tự
-
opensubtitlescom: provider rejects pt-PT even though its own converter maps itCó thể đã có người làm @paulo-0308 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Diaoul/subliminal#1405 ·
-
Internal ErrorĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
frappe/frappe_docker#2071 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Đang mởcomp/desktop P2 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NousResearch/hermes-agent#157702 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
zai-org/zcode-plugins#202 ·
Maintainer thường phản hồi trong vòng 1 ngày