Skip to content

Do not pass completion hook to retrieval and embedding invocations - #980

Open
DylanRussell wants to merge 16 commits into
mainfrom
DylanRussell/disallow-completion-hook-non-inference
Open

DylanRussell wants to merge 16 commits into
mainfrom
DylanRussell/disallow-completion-hook-non-inference

Conversation

@DylanRussell

@DylanRussell DylanRussell commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Retrieval / Embedding do not currently use the hook, so no need to pass it.

Tests

updated unit tests.

Type of change

  • Bug fix

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

Ensures that local agent, workflow, retrieval, and embedding invocations
do not trigger the completion/upload hook, avoiding duplicate uploads of
messages handled by child inference spans. Remote agent invocations still
call the completion hook because there are no client-side inference spans
in that scenario.
@DylanRussell
DylanRussell requested a review from a team as a code owner October 23, 2026 20:36
Copilot AI balanced review requested due to automatic review settings October 23, 2026 20:36
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-11-09 18:37 UTC

Merge when ready.

Also blocked by: 1 required status check is failing.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

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.

🟢 Approval recommended

The scoped hook changes match the stated behavior, with regression coverage and no identified blocking issues.

No open issues 🎉

What changed in this PR

Updates shared GenAI utilities to prevent duplicate completion uploads from local agent and workflow invocations. Retrieval and embedding invocations also bypass the hook, while inference and remote-agent hooks remain enabled.

Changes:

  • Routes excluded invocation types through no-op completion hooks.
  • Moves agent completion-hook execution into remote-agent finalization.
  • Updates regression tests for hook suppression and preserved remote-agent behavior.
File Description
util/​opentelemetry-util-genai/​tests/​test_handler_completion_hook.py Verifies hook suppression and remote-agent hook behavior.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​handler.py Supplies no-op hooks for excluded invocation types.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_workflow_invocation.py Disables workflow completion hooks.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_retrieval_invocation.py Disables retrieval hooks, including suppressed invocations.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_embedding_invocation.py Uses a no-op hook for embeddings.
util/​opentelemetry-util-genai/​src/​opentelemetry/​util/​genai/​_agent_invocation.py Restricts agent completion hooks to remote invocations.

Review effort: Balanced

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent and workflow input/output aren't duplicates of the inference messages. From the inference spans alone, we can't tell which inference output became the final answer, or what the agent got as input before it built the prompts. Frameworks post-process, merge, retry, and pick between candidates. The agent span is the only place that has the real request and answer, which is why we record them there too. Some turns also skip the LLM entirely (like the qwenpaw /stop test), so nothing would reach the hook.

I think the hook should run wherever we capture messages and be skipped only where there are none. Could we scope this PR to retrieval and embedding and keep the hook on local agent and workflow? I opened open-telemetry/semantic-conventions-genai#649 to get this documented per operation in semconv.

@DylanRussell

Copy link
Copy Markdown
Contributor Author

OK that makes sense. Reverted the changes to agent/workflow. Added a comment to the bug

@DylanRussell
DylanRussell force-pushed the DylanRussell/disallow-completion-hook-non-inference branch from c141481 to df2c829 Compare October 30, 2026 13:57

@lmolkova lmolkova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title/description also still mention local agent and workflow

@DylanRussell DylanRussell changed the title Do not invoke completion hook for local agent and workflow invocations Do not pass completion hook to retrieval and embedding invocations Nov 4, 2026
@DylanRussell DylanRussell added Skip Changelog PR does not require a changelog entry Approve Public API check Skip public API check when breaking changes are approved labels Nov 4, 2026
@DylanRussell
DylanRussell force-pushed the DylanRussell/disallow-completion-hook-non-inference branch from 3f2cd12 to 52137ab Compare November 4, 2026 14:56
@opentelemetry-pr-dashboard

This comment has been minimized.

@DylanRussell

Copy link
Copy Markdown
Contributor Author

/dashboard route:reviewers

@opentelemetry-pr-dashboard

Copy link
Copy Markdown

@DylanRussell, your reviewer-routing request was recorded; this pull request has the approvals it needs and is now waiting on maintainers. The handoff remains active across pushes until newer actionable human feedback arrives. Top-level feedback through this request will not return; unresolved review threads remain open.

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

Approve Public API check Skip public API check when breaking changes are approved Skip Changelog PR does not require a changelog entry

Development

Successfully merging this pull request may close these issues.

5 participants