Skip to content

fix(tests): walk through the llm.<model> span in the auto-title trace assertion - #4911

Closed
simonrosenberg wants to merge 1 commit into
mainfrom
fix-auto-title-span-parent
Closed

simonrosenberg wants to merge 1 commit into
mainfrom
fix-auto-title-span-parent

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Verified the span tree myself and confirmed the tracing is correct — it's the assertion that went stale, not the instrumentation.


AGENT:

Why

main is red. agent-server-tests fails on every PR that touches an agent-server path:

tests/agent_server/test_auto_title_span_metadata.py::test_auto_title_llm_span_joins_the_conversation_trace
E   AssertionError: assert 'llm.gpt-4o' == 'conversation.generate_title'

#4836 gave Telemetry.on_request its own llm.<model> span, which stays current while the call runs so the authoritative cost can be attached before lmnr ends its litellm.completion span. That span now sits between the operation span and the LLM span:

conversation.generate_title
  └── llm.gpt-4o            ← added by #4836
        └── litellm.completion

The tracing is correct. The title LLM span is still in the conversation trace and still under conversation.generate_title; only the direct-parent assertion was stale.

tests/sdk/conversation/test_utility_llm_span_metadata.py was updated for exactly this in the same PR — it grew an operation_parent() helper that skips the llm. wrapper, plus a separate immediate_parent. The agent-server counterpart was missed.

How it reached main past a required check

Worth recording, because it is not obvious and it is why #4836's author never saw this test fail.

agent-server-tests is path-gated — every step is if: steps.changed.outputs.any_changed == 'true' over openhands-agent-server/**, tests/agent_server/**, pyproject.toml, uv.lock, .github/workflows/tests.yml. When nothing matches, the job executes nothing and still reports success.

step fc9646ad8 (#4836) 56b016e7f (#4839)
Install deps skipped success
Run Agent Server tests skipped failure
job conclusion success failure

#4836's diff is openhands-sdk/** + tests/sdk/** only, so the job was green having run nothing. #4839 touched agent-server paths, opening the gate, and so became the first commit to actually run this test since #4836 landed. #4836 is the cause; #4839 is only the detector.

The filter gap itself is broader than this PR fixes and is tracked separately in #4912.

Summary

  • parent now walks through the synthetic llm.<model> wrapper to the operation the call belongs to, matching the operation_parent() helper the sibling SDK test already uses rather than inventing a second convention.
  • immediate_parent is added and asserted, so the test still fails if the LLM span detaches or the wrapper disappears silently.
  • The trace_id and title_generation operation-attribute assertions are unchanged. No production code changes.

Issue Number

Related to #4912 — this PR fixes the test breakage reported there; the CI path-filter gap in that issue is a separate change.

How to Test

uv run pytest tests/agent_server/test_auto_title_span_metadata.py

Fails on main, passes on this branch. Verified it is not a local artifact by reproducing on a clean detached worktree at fc9646ad8 with none of this branch's changes present — deterministic, 3/3 runs.

Full agent-server suite on this branch:

$ uv run pytest tests/agent_server/ -q
2101 passed, 13 deselected in 216.60s (0:03:36)

The span tree the probe actually emits, which is what the new assertions encode:

litellm.completion            parent=llm.gpt-4o                    same_trace=True
llm.gpt-4o                    parent=conversation.generate_title   same_trace=True
conversation.generate_title   parent=None                          same_trace=True

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

Test-only change; no production code touched. Unblocks every PR whose diff opens the agent-server-tests gate, including #4864.

🤖 Generated with Claude Code

… assertion

#4836 gave Telemetry.on_request its own `llm.<model>` span, which stays
current while the call runs so the authoritative cost can be attached before
lmnr ends `litellm.completion`. That span now sits between the operation span
and the LLM span, so `litellm.completion`'s immediate parent is `llm.gpt-4o`
rather than `conversation.generate_title`.

tests/sdk/conversation/test_utility_llm_span_metadata.py was updated for that
in the same PR; this agent-server counterpart was missed and has had main red
since. Same treatment: `parent` walks through the wrapper to the operation the
call belongs to, `immediate_parent` keeps the wrapper itself under assertion.

The tracing was correct throughout — the title span is still in the
conversation trace, under `conversation.generate_title`. Only the assertion
was stale.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL423371764958% 
report-only-changed-files is enabled. No files were changed during this commit :)

@all-hands-bot

Copy link
Copy Markdown
Collaborator

🤖 OpenHands is reviewing this PR.

Head commit: 62990aca6248ec46096031f02fc71627fda91a5f
View the conversation: https://oss-agent-canvas.ngrok.dev/conversations/58b07cb4-4783-4b89-84be-d98a9264f1e3

This comment was posted by an AI agent (OpenHands).

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This review was created by an AI agent (OpenHands) on behalf of the repository maintainers.

🟢 Good taste

No material code findings. This test-only change matches the established sibling-test pattern, preserves the immediate-parent assertion for the synthetic llm.<model> span, and correctly walks to conversation.generate_title for operation attribution. The focused test passes locally, and the exact-head agent-server-tests check is green.

The required Validate PR description check is currently failing with these validator errors:

  • The first visible line of the PR description must be HUMAN:.
  • Add a short human-written note between HUMAN: and AGENT:.
  • Keep the AGENT: marker from the PR template.
  • Link an issue in the ## Issue Number section (e.g. Fixes #123). Newly opened issues must carry the ready-for-dev label.

Because the HUMAN: field is human-only, a human contributor needs to update the PR description before merge.

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW

The change is isolated to a tracing assertion in one test, introduces no production behavior, API, dependency, persistence, or security changes, and has passing targeted and CI validation.

VERDICT:
✅ Worth merging once the required PR-description metadata check is fixed by a human.

KEY INSIGHT:
The updated test now verifies both levels of the intended span hierarchy instead of treating the synthetic cost span as a tracing regression.

@simonrosenberg

Copy link
Copy Markdown
Member Author

Closing as redundant — this was fixed independently in #4908 (Release v1.46.0), which landed on main as 6a1e4d0f0 while this was waiting for review.

Their fix asserts the two-level chain explicitly:

sdk_llm_spans = [span for span in probe["spans"] if span["name"] == "llm.gpt-4o"]
assert sdk_llm["parent"] == "conversation.generate_title"
assert title_llm["parent"] == "llm.gpt-4o"

Verified main is green: uv run pytest tests/agent_server/test_auto_title_span_metadata.py passes at 6a1e4d0f0. Same conclusion this PR reached — the tracing was correct and only the assertion was stale — so there is nothing left to fix and no reason to churn the file again.

One difference worth noting for whoever touches this next, not worth a PR on its own: their version hard-codes the span name llm.gpt-4o, so it will need editing if the probe's model fixture ever changes, and it diverges from the operation_parent() helper that tests/sdk/conversation/test_utility_llm_span_metadata.py already uses for the same wrapper. Fine as-is; just two conventions for one thing now.

#4912 stays open and is unaffected — the path-filter gap that let this reach main with every required check green is still there. That is the part with lasting value here.

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.

2 participants