Commit e73b0bc
refactor(governance): instance-scope PolicyLoader; explicit is_conversational
Addresses radu's review on PR #121 — collapses three architectural
boundary concerns into the loader/runtime layers.
1. PolicyLoader is now instance-scoped, not module-globals.
Each GovernanceRuntime constructs its own loader carrying its
own provider, cache, prefetch state, and conversational selector.
uipath eval can spin up multiple runtimes in parallel without
them clobbering each other's policy state.
2. is_governance_enabled() reads removed from the runtime layer.
The decision "should governance attach?" belongs to the wiring
layer (uipath CLI) — it chooses whether to construct
GovernanceRuntime at all. Inside the loader the contract is
purely "provider present → load policies; provider missing →
empty PolicyIndex". The feature flag itself stays in uipath-core.
3. _extract_is_conversational and its delegate-walking deleted.
GovernanceRuntime now takes is_conversational explicitly as a
keyword arg; the wiring layer (which knows the agent type) passes
it in. Runtime no longer reaches into _delegate._agent_definition
private attrs.
Plus two correctness fixes called out in the readiness re-check:
- clear_cache() vs in-flight prefetch worker race: worker now
checks _prefetch_event is event before publishing self._policy_index
so an orphaned worker can't clobber the just-cleared cache.
- _load_from_provider takes the narrowed provider as a parameter
instead of asserting self._provider is not None — the bandit
B101 "assert stripped under -O" finding is now gone.
Tests rewritten around PolicyLoader instances; cross-instance
isolation pinned; orphan-worker race regression test added; conftest
autouse reset fixture removed (no module state to clean). 187 pass,
ruff/mypy/bandit clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 413e967 commit e73b0bc
5 files changed
Lines changed: 550 additions & 788 deletions
File tree
- src/uipath/runtime/governance
- native
- tests
0 commit comments