Skip to content

feat(context): add execution_source derived from command#132

Merged
valentinabojan merged 2 commits into
mainfrom
valentinabojan/runtime-context-execution-source
Jun 24, 2026
Merged

feat(context): add execution_source derived from command#132
valentinabojan merged 2 commits into
mainfrom
valentinabojan/runtime-context-execution-source

Conversation

@valentinabojan

@valentinabojan valentinabojan commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Adds a first-class execution_source field to UiPathRuntimeContext, derived from the executing command (runruntime, debug/devplayground, evaleval; unset for other commands such as init/pack, and an explicitly-passed value is never overwritten).

The derivation runs in a model_validator(mode="after") so it fires on every construction path — both the plain constructor (e.g. dev/init, which build the context directly) and with_defaults. Unmapped commands are left genuinely unset (never assigned None), so the field is absent under model_dump(exclude_unset=True). Since with_defaults mutates command via setattr after construction (which does not re-run the validator), it re-applies the derivation through the same guarded helper.

This lets execution metadata flow through the existing runtime-context boundary — the same way command/job/trace state already does — rather than via an out-of-band env var, so it stays correctly scoped in concurrent/eval runs. Downstream platform clients (e.g. the guardrails service) will read this to set the x-uipath-guardrails-source header.

Part 1 of a two-repo change; the uipath-python side will consume this field via UiPathExecutionContext.

🤖 Generated with Claude Code

Add UiPathRuntimeContext.execution_source, derived from the executing
command (run -> runtime, debug/dev -> playground, eval -> eval) in
with_defaults. This lets execution metadata flow through the existing
context boundary instead of an out-of-band env var, so downstream
platform calls (e.g. guardrails) can identify the run context and it
stays correctly scoped in concurrent runs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@valentinabojan valentinabojan requested a review from a team as a code owner June 24, 2026 13:37
Copilot AI review requested due to automatic review settings June 24, 2026 13:37

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.

Pull request overview

Adds a first-class execution_source field to UiPathRuntimeContext, deriving it from the executing command in with_defaults() so downstream platform clients can reliably scope execution metadata without relying on environment variables.

Changes:

  • Introduce UiPathRuntimeContext.execution_source and a command→source mapping.
  • Derive execution_source in UiPathRuntimeContext.with_defaults() without overriding an explicitly provided value.
  • Add unit tests for the mapping behavior and bump package version to 0.11.4.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/uipath/runtime/context.py Adds execution_source field and derives it from command in with_defaults().
tests/test_context.py Adds tests validating derived execution_source behavior.
pyproject.toml Bumps package version to 0.11.4.
uv.lock Updates locked package version to 0.11.4.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/uipath/runtime/context.py Outdated
Comment thread tests/test_context.py Outdated
valentinabojan pushed a commit that referenced this pull request Jun 24, 2026
Move derivation out of with_defaults into a model_validator so it fires
on the plain-constructor path too (e.g. dev/init), and never assign None
for unmapped commands so the field stays absent under
model_dump(exclude_unset=True). with_defaults re-applies it since it
mutates command via setattr after construction.

Addresses Copilot review feedback on PR #132.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread src/uipath/runtime/context.py Outdated
Move derivation out of with_defaults into a model_validator so it fires
on the plain-constructor path too (e.g. dev/init), and never assign None
for unmapped commands so the field stays absent under
model_dump(exclude_unset=True). with_defaults re-applies it since it
mutates command via setattr after construction.

Addresses Copilot review feedback on PR #132.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@valentinabojan valentinabojan force-pushed the valentinabojan/runtime-context-execution-source branch from adc667a to 711246a Compare June 24, 2026 14:11
@sonarqubecloud

Copy link
Copy Markdown

@valentinabojan valentinabojan merged commit b5d481d into main Jun 24, 2026
94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants