Skip to content

fix(traceview): push the id ReferenceId resolves to onto the hierarchy - #1115

Merged
jepadil23 merged 3 commits into
mainfrom
fix/hierarchy-leaf-matches-reference-id
Sep 25, 2026
Merged

jepadil23 merged 3 commits into
mainfrom
fix/hierarchy-leaf-matches-reference-id

Conversation

@jepadil23

@jepadil23 jepadil23 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
  • Bug: the langgraph entry pushed onto the reference hierarchy named a different entity than the span's own ReferenceId.
  • Root cause: _push_reference_context() read os.environ["UIPATH_AGENT_ID"] directly, while _SpanUtils.otel_span_to_uipath_span derives ReferenceId as agentId or referenceId with agentId set from resolve_project_id() — which prefers uipath.json#id and only then falls back to the env var. Whenever uipath.json#id existed, the leaf and ReferenceId diverged.
  • Fix: push resolve_project_id() or UIPATH_AGENT_ID. resolve_project_id joins the same guarded uipath.tracing import, so older uipath packages still degrade to the existing no-op shim. The resolution order inside resolve_project_id() is left completely untouched.
  • Second fix: wrapped the push in a ValueError guard. ReferenceContext.add() validates UUIDs and env-var sources are unvalidated, so a non-UUID UIPATH_AGENT_ID raised straight out of execute() / stream() and failed the run. It now skips the entry, matching what uipath-agents-python already does.
  • Scope: only the hierarchy entry and that guard.

Behaviour

With uipath.json#id = 1111… and UIPATH_AGENT_ID = 2222…:

before after
ReferenceId 1111… 1111… unchanged
hierarchy leaf 2222… 1111…
match? ✗ ✓

With no uipath.json#id, both are 2222… before and after — which is why the existing wiring tests pass unchanged.

Tests

TestHierarchyLeafMatchesReferenceId in tests/runtime/test_reference_context_wiring.py:

  • uipath.json#id wins over UIPATH_AGENT_ID;
  • falls back to UIPATH_AGENT_ID when no uipath.json exists;
  • a non-UUID id is skipped rather than raised.

The first and third fail against main and pass with this change. Full tests/runtime suite green; ruff + mypy clean.

Companion

uipath-agents-python has the same divergence for its agent entry — fixed the same way in UiPath/uipath-agents-python#768.

🤖 Generated with Claude Code

The langgraph entry carried UIPATH_AGENT_ID, but a span's ReferenceId is
derived as `agentId or referenceId`, with `agentId` set from
resolve_project_id() — which prefers uipath.json#id. Whenever the two
disagreed the hierarchy leaf and ReferenceId named different entities.

Also guard the push against a non-UUID id: env-var sources are unvalidated,
so ReferenceContext.add() could raise straight out of execute()/stream().

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Separate the optional imports so missing resolve_project_id does not disable ReferenceContext on older uipath versions.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes hierarchy IDs to match ReferenceId and safely skips invalid UUIDs.

Changes:

  • Resolves project IDs with environment fallback.
  • Adds invalid-ID handling.
  • Adds regression coverage for precedence, fallback, and invalid IDs.
File Description
tests/​runtime/​test_reference_context_wiring.py Tests hierarchy/reference ID alignment and invalid-ID behavior.
src/​uipath_langchain/​runtime/​runtime.py Updates hierarchy ID resolution and validation handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/uipath_langchain/runtime/runtime.py
jepadil23 and others added 2 commits September 25, 2026 07:35
@sonarqubecloud

Copy link
Copy Markdown

@jepadil23
jepadil23 merged commit 29c04b5 into main Sep 25, 2026
48 checks passed
@jepadil23
jepadil23 deleted the fix/hierarchy-leaf-matches-reference-id branch September 25, 2026 14:38
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.

3 participants