Skip to content

fix(concurrent): capture context for each thread pool submission - #1474

Open
LJK-ikun wants to merge 1 commit into
AgentOps-AI:mainfrom
LJK-ikun:fix/threadpool-submission-context
Open

LJK-ikun wants to merge 1 commit into
AgentOps-AI:mainfrom
LJK-ikun:fix/threadpool-submission-context

Conversation

@LJK-ikun

Copy link
Copy Markdown

📥 Pull Request

📘 Description

Closes #1473.

An instrumented executor reused across requests keeps the context captured when the pool was created. Worker spans can therefore attach to an old trace instead of the request active at submission. A task's ContextVar writes also remain visible to the next task on the same worker.

Capture a fresh context on each submit and execute the callable through that context's run. This fixes request parentage and isolates task-local writes, including after an exception. Existing executor initialization, argument forwarding and Future behavior are preserved. No dependency or public API changes.

🧪 Testing

  • Real-thread regression/control tests: request trace ID and parent span, queued submission snapshots, isolation after both success and failure, and initializer/task argument compatibility. No mocks, backend or LLM are used in the new cases.
  • Unchanged main: 4 regression failures and 1 control pass, reproduced with both OpenTelemetry 1.45.1 and the lockfile's 1.31.1 SDK.
  • Fixed branch: python -m pytest tests/unit/sdk -q — 155 passed, including the new five cases (Python 3.12.14, OpenTelemetry 1.31.1, pytest 8.4.1).
  • pre-commit run --all-files — Ruff lint and formatting pass (repository-pinned Ruff 0.12.9).
  • git diff --cached --check — pass.

An initial broader run with pytest 9 / OpenTelemetry 1.45.1 hit exporter failures and a pytest-depends internal error. After aligning the SDK to the repository's locked OpenTelemetry version and using compatible pytest 8, the SDK suite above passed. This is not a claim that the full repository or live-provider integration tests passed.

Prepared with AI assistance; the reproductions and checks reported here were executed locally.

This branch has not been deployed

No deployments
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.

bug: reused thread pools propagate creation context instead of each request

1 participant