feat(guardrails): send execution source and job key headers#1739
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds correlation metadata to guardrail validation requests by propagating the CLI execution “source” and orchestrator job key into HTTP headers, aligning guardrails with existing licensing/metering flows.
Changes:
- Set
UIPATH_EXECUTION_SOURCEat the start of CLI agent-executing commands (run,debug,dev,eval) via a new execution-source resolver. - Send
x-uipath-agenthub-config(execution source) andx-uipath-jobkey(job key) headers on guardrail validation requests, omitting each when unset. - Add unit tests to verify presence/absence of the new headers on outgoing guardrails requests.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/uipath/src/uipath/_cli/cli_run.py | Sets execution source for run before runtime construction. |
| packages/uipath/src/uipath/_cli/cli_eval.py | Sets execution source for eval before evaluation execution starts. |
| packages/uipath/src/uipath/_cli/cli_dev.py | Sets execution source for dev before launching the developer console/runtime. |
| packages/uipath/src/uipath/_cli/cli_debug.py | Sets execution source for debug before runtime/debug setup. |
| packages/uipath/src/uipath/_cli/_utils/_execution_source.py | New mapping logic from CLI command → execution source env var. |
| packages/uipath-platform/src/uipath/platform/guardrails/_guardrails_service.py | Adds execution source + job key headers to guardrails validate requests. |
| packages/uipath-platform/src/uipath/platform/common/constants.py | Introduces UIPATH_EXECUTION_SOURCE env var constant. |
| packages/uipath-platform/src/uipath/platform/common/_job_context.py | Adds header_execution_source() helper alongside existing job key header helper. |
| packages/uipath-platform/src/uipath/platform/common/_config.py | Exposes UiPathConfig.execution_source via the new env var. |
| packages/uipath-platform/tests/services/test_guardrails_service.py | Adds tests ensuring headers are present when set and omitted when unset. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
radu-mocanu
left a comment
There was a problem hiding this comment.
env vars are acceptable for process bootstrap/config coming from the outside world, but this PR uses an env var as an internal (same-process) message bus from the CLI layer to the platform client. this is not a clean design as it:
- makes the state global
- can t be scoped in async/concurrent eval runs
etc.
we should make this execution metadata part of runtimecontext and pass it through the existing context boundary, as currently done for for command/job/trace-related execution state.
A cleaner shape would be:
- map `command -> execution_source` when building `UiPathRuntimeContext`
- carry it as `runtime_context.execution_source`
- propagate it into `UiPathExecutionContext` / the platform client context
- have `GuardrailsService` read `self._execution_context.execution_source` when adding `x-uipath-guardrails-source`
| Carries the source (e.g. ``runtime``/``playground``/``eval``) via a context | ||
| variable instead of a process-global env var, and releases it on exit so it |
There was a problem hiding this comment.
please remove the references to the old impl instead of a process-global env var
|
|
||
| def __init__(self, execution_source: Optional[str]) -> None: | ||
| self._execution_source = execution_source | ||
| self._token: Optional[Token[Optional[str]]] = None |
There was a problem hiding this comment.
nit: let s use the new typing hints please
| self._token: Optional[Token[Optional[str]]] = None | |
| self._token: Token[str | None] | None = None |
c5c093c to
7475d93
Compare
Guardrail validation calls now send the execution source (x-uipath-guardrails-source) and job key (x-uipath-jobkey) headers for licensing/metering correlation. The source is derived from the executing CLI command (run -> runtime, debug/dev -> playground, eval -> eval) on UiPathRuntimeContext.execution_source (uipath-runtime 0.11.4) and flows through the execution-context boundary: the CLI enters ExecutionSourceContext(ctx.execution_source) — a scoped ContextVar that releases its token on exit — UiPathExecutionContext.execution_source reads it, and GuardrailsService builds the header from self._execution_context.execution_source. This keeps the source correctly scoped for concurrent/eval runs and works for both coded and low-code agents. Job key comes from UiPathConfig.job_key; both headers are omitted when unset. Bumps uipath-platform to 0.1.78 and pins uipath-runtime>=0.11.4. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7475d93 to
ec20883
Compare
|
🚨 Heads up:
|
Co-authored-by: Valentina Bojan <valentina.bojan@uipath.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>



Guardrail validation calls now send the execution source (
x-uipath-guardrails-source) and job key (x-uipath-jobkey) headers for licensing/metering correlation.The source is derived from the executing CLI command (
run→runtime,debug/dev→playground,eval→eval) onUiPathRuntimeContext.execution_source(added in uipath-runtime 0.11.4), and flows through the execution-context boundary rather than an env var: the CLI callsset_execution_source(ctx.execution_source), which sets aContextVarthatUiPathExecutionContext.execution_sourcereads, andGuardrailsServicebuilds the header fromself._execution_context.execution_source. This keeps the source correctly scoped for concurrent/eval runs and works for both coded and low-code agents, since both run through theuipathCLI. Job key continues to come fromUiPathConfig.job_key; both headers are omitted when unset.Requires
uipath-runtime>=0.11.4(companion PR: UiPath/uipath-runtime-python#132).🤖 Generated with Claude Code