Skip to content

fix(observability): mark utility LLM spans (title generation, ask_agent) - #4359

Merged
simonrosenberg merged 3 commits into
mainfrom
fix-utility-llm-span-tagging
Aug 4, 2026
Merged

simonrosenberg merged 3 commits into
mainfrom
fix-utility-llm-span-tagging

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Add metadata to ask_agent and title generation so they are distinguishable from regular agent outputs in Laminar.


AGENT:

Why

generate_title and ask_agent run LLM completions alongside a conversation, and
their LLM spans are indistinguishable from real agent turns. A consumer that fetches
"all LLM spans for this session" (dataset-utils rebuilding a training trajectory from
Laminar) splices their output in as a genuine assistant turn.

Confirmed in production data: a trace whose "assistant" step content is the whole
string "💄 Generate Title with Emoji\x00" — generate_title's degenerate output,
spliced into the middle of a real conversation and flagged downstream as text
corruption.

Nothing marked these calls as side utilities, so there was nothing to filter on:

  • Title generation defaults to agent.llm — the same LLM and usage_id as the
    main loop — so not even the usage id distinguishes it.
  • LocalConversation.ask_agent had no @observe at all on main, so its LLM
    span had no distinguishing ancestor span either.
  • The path a deployed agent-server actually takes was worse than unmarked.
    Titles do not come from LocalConversation.generate_title in production — they
    come from AutoTitleSubscriber in conversation_service.py, which calls the
    module-level generate_title_from_message helper directly from a
    run_in_executor worker thread. That thread inherits no OTel context, so the
    litellm.completion span was a root span in its own trace — while still
    carrying the conversation's session_id. A session-keyed consumer therefore
    picked it up with no ancestor to filter it out. This is the exact shape that
    produced the corruption above.

Summary

  • Introduce OPERATION_METADATA_KEY = "openhands.operation" in
    openhands/sdk/observability/laminar.py, exported from
    openhands.sdk.observability, so the marker downstream consumers filter on has a
    single source of truth.
  • agent-server auto-title path (conversation_service.py): route
    AutoTitleSubscriber's executor call through a new _generate_title_traced
    helper carrying @observe(name="conversation.generate_title", metadata={...}).
    The conversation is passed as the helper's first positional argument — that
    is where observe's _maybe_use_root_span looks for _observability_root_span,
    and re-attaching it there is what turns the orphan into a real child of the
    conversation trace across both the asyncio.create_task and the
    run_in_executor hop.
  • LocalConversation.generate_title / RemoteConversation.generate_title: add
    metadata={OPERATION_METADATA_KEY: "title_generation"} to the existing
    @observe.
  • LocalConversation.ask_agent: add
    @observe(name="conversation.ask_agent", metadata={...: "ask_agent"}) — it
    previously had no span at all. This one is on the deployed path:
    POST /{id}/ask_agent → ConversationService.ask_agent →
    EventService.ask_agent → run_in_executor(..., self._conversation.ask_agent, ...).
  • RemoteConversation.ask_agent: not decorated (see Notes for why).
  • Two regression tests, both driving a real Laminar tracer through an
    InMemorySpanExporter in a subprocess:
    tests/sdk/conversation/test_utility_llm_span_metadata.py (SDK conversation
    methods) and tests/agent_server/test_auto_title_span_metadata.py (the
    agent-server auto-title path, asserting both the marker and same-trace parenting).

LLM spans are not created by @observe — they come from lmnr's LiteLLM
auto-instrumentation as children of the enclosing @observe span. metadata= is
the only lmnr channel that reaches them: _setup_span stamps
lmnr.association.properties.metadata.<key>, set_association_props_in_context
lifts it into the OTel context, and LaminarSpanProcessor.on_start re-stamps it
onto every descendant. tags= does not propagate (it keeps the
lmnr.association.properties. prefix, which set_association_props_in_context
filters out), and plain span attributes never propagate in OTel.

Issue Number

Partially addresses #4358 (Bug 2 of 2). Bug 1 — the TOOL-span parent loss under
ParallelToolExecutor — is PR #4360, so this one does not close the issue.

How to Test

Everything below was run on this branch at aacc6b136.

1. The production auto-title path now joins the conversation trace

The new agent-server probe is directly runnable. It initializes a real Laminar
tracer, swaps LaminarSpanProcessor.instance for a
SimpleSpanProcessor(InMemorySpanExporter()), enables the real
Instruments.LITELLM auto-instrumentation, builds a real Conversation plus a
StoredConversation, and fires AutoTitleSubscriber with a user MessageEvent
— i.e. the full create_task → run_in_executor → litellm.completion chain,
with litellm's own mock_response standing in for network I/O:

uv run --no-sync python tests/agent_server/test_auto_title_span_metadata.py

Before (sources at the pre-PR base 8c2297b19) — the orphan:

conversation_trace_id: 88068842322890103784699585827543645958

litellm.completion   parent=None   trace_id=149314837929701029874291855801380402573
    association properties: {}
    lmnr.span.path: ['litellm.completion']

After — a real child of the conversation root, same trace, marked:

conversation_trace_id: 241786796964671280679697988124795999424

litellm.completion   parent=conversation.generate_title
                     trace_id=241786796964671280679697988124795999424
    lmnr.span.path: ['conversation', 'conversation.generate_title', 'litellm.completion']
    lmnr.association.properties.session_id:                          f135219d-7249-...
    lmnr.association.properties.metadata.repo:                       OpenHands/software-agent-sdk
    lmnr.association.properties.metadata.openhands.operation:        title_generation

conversation.generate_title   parent=None (the still-open conversation root)
    lmnr.span.input:  {"message":"fix the auth bug","max_length":50}
    lmnr.span.output: "Fix Auth Bug"

Note lmnr.span.input — ignore_inputs=["conversation", "llm"] keeps the
conversation object and the LLM out of the recorded span input.

2. End-to-end: the marker reaches the real exported LLM span (SDK methods)

uv run --no-sync python tests/sdk/conversation/test_utility_llm_span_metadata.py

Exported spans (name / parent / propagated metadata):

conversation.send_message     parent=None                          metadata={'repo': 'OpenHands/software-agent-sdk'}
litellm.completion            parent=agent.step                    metadata={'repo': 'OpenHands/software-agent-sdk'}
agent.step                    parent=conversation.run              metadata={'repo': 'OpenHands/software-agent-sdk'}
conversation.run              parent=None                          metadata={'repo': 'OpenHands/software-agent-sdk'}
litellm.completion            parent=conversation.generate_title   metadata={'repo': 'OpenHands/software-agent-sdk', 'openhands.operation': 'title_generation'}
conversation.generate_title   parent=None                          metadata={'repo': 'OpenHands/software-agent-sdk', 'openhands.operation': 'title_generation'}
litellm.completion            parent=conversation.ask_agent        metadata={'repo': 'OpenHands/software-agent-sdk', 'openhands.operation': 'ask_agent'}
conversation.ask_agent        parent=None                          metadata={'repo': 'OpenHands/software-agent-sdk', 'openhands.operation': 'ask_agent'}

Three things this shows:

  1. The marker lands on the auto-instrumented litellm.completion LLM span, not
    just on the @observe span — that is the property a session-level consumer
    needs.
  2. It is subtree-scoped: the main-loop litellm.completion under agent.step
    does not carry it.
  3. Conversation-level trace metadata (repo, supplied via
    observability_metadata) still reaches every span, so nothing regressed there.

parent=None on the four top-level spans is the conversation root span, which is
still open (never ended) and therefore not in the exporter — normal, not a
regression.

3. Regression tests

uv run --no-sync pytest tests/sdk/conversation/test_utility_llm_span_metadata.py \
  tests/agent_server/test_auto_title_span_metadata.py -q
# 5 passed in 9.41s

Confirmed both tests actually catch the bug — with the three changed source files
reverted to the pre-PR base (git checkout 8c2297b19 -- <3 source files>) and only
the tests kept:

# 5 failed in 9.44s
#  2x AssertionError: assert None == {'openhands.operation': 'title_generation'}
#        (generate_title local + remote — @observe exists on main, metadata is None)
#  1x KeyError: 'name'
#        (LocalConversation.ask_agent — no decorator at all on main)
#  1x AssertionError: assert {'agent.step', None, 'conversation.generate_title'}
#        == {'agent.step', 'conversation.ask_agent', 'conversation.generate_title'}
#        (ask_agent's LLM span had no distinguishing parent at all)
#  1x AssertionError: assert None == 'conversation.generate_title'
#        (the auto-title LLM span was an orphan, not a child of the conversation)

4. Existing suites, lint, types

uv run --no-sync pytest tests/sdk/conversation/ tests/sdk/observability/ -q
# 806 passed, 3 warnings in 141.11s

uv run --no-sync pytest tests/agent_server/ -q
# 1864 passed, 13 deselected, 50 warnings in 192.96s

uv run --no-sync pytest tests/sdk/agent/test_acp_agent.py \
  tests/sdk/conversation/test_ask_agent.py tests/sdk/conversation/test_generate_title.py -q
# 452 passed in 10.41s

uv run --no-sync ruff check <changed files>          # All checks passed!
uv run --no-sync ruff format --check <changed files> # 7 files already formatted
uv run --no-sync pyright <changed files>             # 0 errors, 0 warnings, 0 informations

Video/Screenshots

N/A — observability-only change; the span dumps in "How to Test" are the observable
output.

Type

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

Notes

Why the auto-title fix is shaped this way

Two options were on the table for covering AutoTitleSubscriber:

(a) Route it through LocalConversation.generate_title so it inherits the
existing decorator. Rejected: it changes behaviour. AutoTitleSubscriber
deliberately extracts the message text before spawning its background task, to
avoid a race where the event is not yet in the events list; generate_title goes
back to self._state.active_branch() and re-extracts, reopening that race. It also
raises ValueError when no user message is found, which would degrade the current
truncation fallback into "no title at all" (the except Exception: logger.warning
swallows it).

(b) Decorate the auto-title call itself — chosen. The one trap is that a naive
decorator does not fix the orphan: _maybe_use_root_span / _root_span_from_args
only re-attach the root span when args[0] carries _observability_root_span,
and _generate_and_save is a zero-arg closure. So the helper takes the
conversation as its first positional argument. That parameter is unused in the body
(# noqa: ARG001) and carries a comment saying why it must stay — deleting it
would silently reintroduce the orphan with green CI. The "before/after" dump in
"How to Test" is the proof the reparenting works across both the create_task and
run_in_executor hops.

Behaviour is otherwise untouched: still non-blocking/background, still swallows
exceptions with logger.warning, still guards on "title already set", still
title_llm_profile → agent.llm → truncation, and the LLM is still resolved
before the task is spawned.

RemoteConversation.ask_agent is deliberately not decorated

An earlier revision of this PR decorated it for symmetry. Removed, because the
decoration buys nothing and costs something:

  • It is pure HTTP delegation — the LLM runs server-side. There is no local LLM span
    for the marker to reach.
  • No W3C trace context crosses the boundary: the SDK never injects a traceparent
    (it does not import opentelemetry at all), lmnr's Instruments enum has no
    httpx/requests instrumentor, and agent-server installs no OTel extract middleware.
    So the server-side span is not in the client's trace either.
  • The server side is already covered by LocalConversation.ask_agent, which is
    on the deployed path via POST /{id}/ask_agent.
  • Its only net effect was writing openhands.operation into the client trace's
    metadata — which, given the trace-level rollup below, makes a client trace
    advertise a marker for which it holds no marked LLM span, and can
    non-deterministically clobber the trace-level value when a client-side
    generate_title happens in the same trace.

RemoteConversation.generate_title is genuinely different and keeps its marker: it
runs generate_conversation_title client-side, so there is a real local LLM
span to mark.

Metadata is trace-level in Laminar's data model — known trade-off

At the OTel level the marker is strictly subtree-scoped, proven by the tests above,
and that span-level view is what the downstream consumer actually reads. But
Laminar's ingestion also rolls per-span metadata up into the trace record: its
backend aggregates spans into a trace (TraceAggregation::from_spans), merging the
lmnr.association.properties.metadata.* of every span in the trace and upserting
with metadata = COALESCE(traces.metadata || EXCLUDED.metadata, ...). Laminar's own
docs say the same thing from the user side:

"Trace metadata applies to the entire trace." … "Metadata set during the trace is
merged as spans arrive." … "Set each metadata key in one place per trace (ideally
the root span) and avoid duplicate keys in nested observe(...) calls." … "the
last span processed wins (order is not guaranteed)"
— https://laminar.sh/docs/tracing/structure/metadata

Consequences, stated plainly:

  • Every conversation trace that contains a utility call now advertises
    openhands.operation at trace level, in the Laminar UI and API.
  • If one trace contains both a title generation and an ask_agent, the trace-level
    value is last-writer-wins and therefore non-deterministic.
  • The OTel span-level scoping is correct and unaffected. Removing
    RemoteConversation.ask_agent's decoration (above) removes one of the two ways
    this could happen client-side.

(The backend specifics — TraceAggregation::from_spans, the COALESCE upsert —
come from review of Laminar's server source, not from anything I ran here. The
docs quote and the span-level behaviour are both verified.)

I still went with metadata, because:

  • The bug is span-level. A consumer reading LLM span attributes gets a correct,
    stable, subtree-scoped answer, which is the only thing needed to stop splicing
    utility output into trajectories.
  • There is no alternative channel. lmnr's context propagation extracts exactly four
    things (user_id, session_id, trace_type, metadata); metadata is the only
    non-reserved one, so no span-subtree-scoped attribute channel exists in lmnr.
  • It cannot break existing trace-level filters — the key is new, nothing filters on
    it yet.

If a reviewer would rather keep trace-level metadata pristine, the conflict-free
variant is one key per operation (openhands.utility.title_generation = true,
openhands.utility.ask_agent = true): each key then has exactly one possible value,
so the merge is deterministic. It costs consumers a prefix match instead of an
equality check. Happy to switch.

Marker key: why openhands.operation and not bare operation

observability_metadata is a fully caller-controlled dict of arbitrary keys
(repo, repo_name, …) landing in the same
lmnr.association.properties.metadata.* namespace, and
_validate_observability_metadata accepts any non-empty string key — including
"openhands.operation" itself. So namespacing does not make collision impossible;
it makes it implausible. operation is a generic enough word that a caller could
already be using it; openhands.operation is unambiguously SDK-owned. The dotted
key round-trips cleanly through lmnr (on_start strips only the fixed
lmnr.association.properties.metadata. prefix), as the span dumps show.

Both tests assert the raw exported attribute name
lmnr.association.properties.metadata.openhands.operation as a literal, not via
OPERATION_METADATA_KEY. Renaming the constant's value would otherwise leave the
suite green while silently breaking every downstream filter.

ask_agent behavior review

  • The agent-specific early return (self.agent.ask_agent, used by ACPAgent's
    fork_session) is untouched: @observe wraps the call, the early return is
    inside the body, so return value and control flow are identical.
    tests/sdk/agent/test_acp_agent.py is green.
  • Adding a span to LocalConversation.ask_agent is a real trace-shape change,
    and a beneficial one beyond the marker: EventService.ask_agent dispatches via
    loop.run_in_executor(None, self._conversation.ask_agent, question), i.e. a
    pooled worker thread where contextvars propagation is unreliable. With the
    decorator, _maybe_use_root_span fires — args[0] is the conversation — and
    re-attaches the conversation root span, exactly as the auto-title fix does.
    Server-side ask_agent LLM spans should now be correctly parented rather than
    orphaned. Verified in-process by the span dump above; not verified against a live
    agent-server.
  • Span input/output capture: @observe(name="conversation.send_message") already
    records the user's full message text and generate_title already records the
    generated title, so recording ask_agent's question and answer is consistent
    with what the SDK already emits. Note this is not because the codebase never
    redacts — hooks/executor.py:204 uses ignore_inputs=["self", "hook", "event"]
    and ignore_output=True on perfectly serializable pydantic models, so
    suppression for reasons other than serializability does have precedent. The
    argument here is consistency with the sibling conversation methods, not a house
    rule. Easy to add ignore_input/ignore_output if the team disagrees.

Test isolation

Both end-to-end probes run in a subprocess. Laminar.initialize() flips
process-global state that cannot be undone — global TracerProvider, permanent
should_enable_observability() == True, global litellm instrumentation, and a
BatchLogRecordProcessor background thread — which would silently change every
later test in the same pytest worker. The three in-process cases use the existing
patch("lmnr.observe", ...) pattern from tests/sdk/observability/test_laminar.py
and exploit the lazy build in observe's wrapper; the recorder returns the function
unchanged so the wrapper cache it leaves behind is behaviourally identical to no
decorator.

Deliberately out of scope (follow-ups)

A consumer trusting openhands.operation alone is not yet fully protected —
these LLM calls still emit unmarked spans inside a conversation trace:

  • The condenser (context/condenser/llm_summarizing_condenser.py:293 and
    :338). Same class of defect: a trajectory rebuilder will splice condensation
    summaries in as assistant turns. A two-line follow-up using the same
    OPERATION_METADATA_KEY.
  • Agent hooks (hooks/executor.py:204). _execute_agent_hook spawns a nested
    LocalConversation, so its LLM spans are literally named agent.step inside the
    parent trace — indistinguishable by name from the real loop, and the worst case
    for a name-based filter.
  • The \x00 NUL byte in title output. Real corruption seen in production
    ("…Emoji\x00"), but it is a sanitization concern at the title/consumer boundary,
    not a span-tagging one.
  • A dedicated usage_id/LLM profile for title generation. Would make the
    utility call distinguishable by usage id too, but it changes cost attribution and
    other work is in flight there.

Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:7785537-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-7785537-python \
  ghcr.io/openhands/agent-server:7785537-python

All tags pushed for this build

ghcr.io/openhands/agent-server:7785537-golang-amd64
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-golang-amd64
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-golang-amd64
ghcr.io/openhands/agent-server:7785537-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:7785537-golang-arm64
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-golang-arm64
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-golang-arm64
ghcr.io/openhands/agent-server:7785537-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:7785537-java-amd64
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-java-amd64
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-java-amd64
ghcr.io/openhands/agent-server:7785537-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:7785537-java-arm64
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-java-arm64
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-java-arm64
ghcr.io/openhands/agent-server:7785537-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:7785537-python-amd64
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-python-amd64
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-python-amd64
ghcr.io/openhands/agent-server:7785537-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:7785537-python-arm64
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-python-arm64
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-python-arm64
ghcr.io/openhands/agent-server:7785537-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:7785537-golang
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-golang
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-golang
ghcr.io/openhands/agent-server:7785537-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:7785537-java
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-java
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-java
ghcr.io/openhands/agent-server:7785537-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:7785537-python
ghcr.io/openhands/agent-server:77855373aae2da27487f9719ab3d1bc17bd4def5-python
ghcr.io/openhands/agent-server:fix-utility-llm-span-tagging-python
ghcr.io/openhands/agent-server:7785537-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 7785537-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 7785537-python-amd64) are also available if needed

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

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   conversation_service.py109912389%180–181, 190, 216–217, 221–222, 227, 327–328, 331–332, 344–345, 359, 524–525, 543, 560, 611, 633, 640–641, 663, 713, 780, 800, 827–828, 844, 874, 878, 892, 904–907, 913–914, 923, 925, 979, 985–986, 990–991, 999, 1026, 1032, 1126, 1132, 1137, 1143, 1151–1152, 1161–1164, 1173, 1185, 1193, 1216, 1222–1223, 1226–1228, 1255, 1301, 1392–1393, 1453, 1497–1499, 1501–1502, 1505–1506, 1526, 1640–1642, 1645–1646, 1650–1652, 1655–1656, 1660–1662, 1665–1666, 1695, 1704, 1744, 1754–1756, 1816, 1819, 1846, 1856, 1861–1864, 1878, 1889, 1900–1901, 1933, 2022, 2073, 2131, 2142–2143, 2503, 2556, 2559
openhands-sdk/openhands/sdk/conversation/impl
   local_conversation.py10568692%150, 603–604, 637, 679, 1007, 1031–1032, 1037, 1052, 1054, 1158, 1174, 1222, 1248, 1312, 1316–1322, 1381, 1401–1403, 1452, 1471–1473, 1797–1798, 1813, 2031, 2034–2035, 2060, 2091, 2097, 2178, 2185, 2188, 2191, 2195–2196, 2200–2201, 2204, 2211, 2236, 2240, 2243, 2262, 2314, 2317, 2356, 2363–2364, 2372, 2376–2378, 2385, 2422–2428, 2431, 2434, 2441, 2504, 2509, 2618–2619, 2637–2638, 2671, 2875, 2879, 2949, 2956–2957
   remote_conversation.py7518888%91, 166, 193, 206, 208–211, 237, 255–256, 267–270, 277–278, 283–286, 370, 380–382, 388, 466, 613–616, 618, 644–648, 653–656, 659, 675, 813, 871–872, 876–877, 891, 905–908, 949, 962–963, 987–988, 1028–1029, 1065, 1075, 1079, 1088–1089, 1128, 1278–1279, 1373–1374, 1378, 1383–1387, 1393–1399, 1412, 1417, 1467, 1715–1716
openhands-sdk/openhands/sdk/observability
   laminar.py1775271%43–47, 112, 177–178, 191–192, 218–219, 299–306, 321–324, 332–334, 340, 350–353, 355, 360–364, 377, 380–382, 386, 388–390, 405, 442–444, 446–447
TOTAL39486751181% 

…y runs

Conversation titles in a deployed agent-server come from AutoTitleSubscriber,
which calls generate_title_from_message directly rather than through the
decorated LocalConversation.generate_title. Its LLM span was an orphan in its
own trace, so the marker added for the SDK path never reached production.

Route it through an observed helper that takes the conversation as its first
positional argument, which is where observe finds the root span to re-attach
across the create_task + run_in_executor hops.

Drop the marker from RemoteConversation.ask_agent: it is pure HTTP delegation
with no local LLM span, and no trace context is propagated to the server.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@simonrosenberg simonrosenberg self-assigned this Aug 4, 2026

all-hands-bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@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.

Taste: 🟢 Good taste. The change is targeted, solves a real observability problem (utility spans and main-loop turns are now distinguishable in traces), and ships with end-to-end tests that drive a real Laminar tracer through InMemorySpanExporter and assert on exported attributes — not a pile of mocks.

The new _generate_title_traced wrapper is the awkward bit, but the inline comment correctly captures the non-obvious invariant: it exists purely so that _maybe_use_root_span can find the root span via args[0] on the context-less executor thread. That is real architectural tech debt in _maybe_use_root_span (its args[0] heuristic forces this kind of fake-first-arg at every cross-context call site), not a smell introduced by this PR — worth a follow-up to make the root span explicit at the call site (e.g. with use_root_span(root): await loop.run_in_executor(...)), but not in scope here.

Tests are well-constructed: the subprocess indirection exists for a real reason (Laminar.initialize() mutates process-global tracing), and the unit test asserts on the kwargs handed to lmnr.observe at decoration time, which is the real wire contract.

[RISK ASSESSMENT]

  • [Overall PR] Risk Assessment: 🟢 LOW
    Adds new metadata on existing @observe-decorated spans and adds one thread-safe wrapper for the executor-thread title path. No public API change, no behavior change, no breaking surface. New tests are pure additions.

VERDICT: Worth merging.


This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

🤖 OpenHands is reviewing this PR.

Head commit: 77855373aae2da27487f9719ab3d1bc17bd4def5
View the conversation: https://oss-agent-canvas.ngrok.dev/conversations/2e6d28fb-dbb2-4d5e-bdba-983c841239e7

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

@simonrosenberg
simonrosenberg merged commit c789a9a into main Aug 4, 2026
46 of 48 checks passed
@simonrosenberg
simonrosenberg deleted the fix-utility-llm-span-tagging branch August 4, 2026 13:42
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