Skip to content

Bug: Failed to detach context #423

@pentium10

Description

@pentium10

Describe the bug
I have created an agent to find PDF files on a given public website, and then to parallel download.
The agent runs successfully.
But DOESN'T stop gracefully as the below error is produced:
Failed to detach context

To Reproduce
Steps to reproduce the behavior:

  1. Use my agent.py
  2. Run in UI
  3. My prompt was:
find all pdf links from this page 
https://www.posta-romana.ro/titluri-de-stat.html 
then download first 5 pdfs to folder tezaur2025
  1. See error
2025-04-27 23:07:15,386 - INFO - fast_api.py:634 - Generated event in agent run streaming: {"content":{"parts":[{"text":"I have downloaded the first 5 PDFs to the 'tezaur2025' folder. All downloads were successful.\n"}],"role":"model"},"invocation_id":"e-ab97422f-2aea-46b8-af78-7815ddf6efe4","author":"pdf_downloader","actions":{"state_delta":{},"artifact_delta":{},"requested_auth_configs":{}},"branch":"parallel_download_agent.pdf_downloader","id":"dwYbbIeM","timestamp":1745784434.52612}
2025-04-27 23:07:15,386 - ERROR - __init__.py:157 - Failed to detach context
Traceback (most recent call last):
  File "D:\wamp\www\vertex_ai - adk\.venv\lib\site-packages\opentelemetry\context\__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "D:\wamp\www\vertex_ai - adk\.venv\lib\site-packages\opentelemetry\context\contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x00000200EE52DC60> at 0x00000200FAD4C280> was created in a different Context
2025-04-27 23:07:15,386 - ERROR - __init__.py:157 - Failed to detach context
Traceback (most recent call last):
  File "D:\wamp\www\vertex_ai - adk\.venv\lib\site-packages\opentelemetry\context\__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "D:\wamp\www\vertex_ai - adk\.venv\lib\site-packages\opentelemetry\context\contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x00000200EE52DC60> at 0x00000200FAF9C640> was created in a different Context

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementationneed attention[Status] This issue is important but the maintainers haven't started working on it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions