Skip to content

Commit 287d5cc

Browse files
authored
Feat: Add governed execution runtime (#27)
## Summary This PR closes the first governed execution loop in ModularityKit.Mutator.Governance and aligns the package docs with the current runtime shape. ## Added - governed execution contracts and runtime orchestration through IGovernanceExecutionManager and GovernanceExecutionManager - request execution outcome handling, guarded execution persistence, and governance-aware mutation wrapping - end-to-end governance execution coverage in ModularityKit.Mutator.Governance.Tests - runnable Examples/Governance/GovernedExecution sample - ADR-027 for the governed execution manager ## Changed - MutationRequest construction moved into MutationRequestFactory so the request model stays focused on state - governance examples and tests now use the request factory entry points - governance package README now describes the runtime by flow and responsibility instead of only folder layout - governance example READMEs now point to the updated request factory usage ## Result Governance now owns the path from approved request to version resolution, core mutation execution, and terminal request state. The package documentation also reflects the current execution model instead of describing major runtime pieces as future work. ## Testing - dotnet build src/ModularityKit.Mutator.Governance.csproj -c Release - dotnet build Examples/Governance/GovernedExecution/GovernedExecution.csproj -c Release - dotnet test Tests/ModularityKit.Mutator.Governance.Tests/ModularityKit.Mutator.Governance.Tests.csproj -c Release ## Linked Issues - Closes #16 ## Checklist - [x] Governed execution resolves requests before execution - [x] Terminal execution outcomes are persisted through governance runtime - [x] Governance execution has runnable example coverage - [x] Governance execution has test coverage - [x] ADR and package docs reflect the new runtime shape
2 parents f4853cc + 82549e9 commit 287d5cc

30 files changed

Lines changed: 1260 additions & 279 deletions
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# ADR-027: Governed Execution Manager
2+
3+
## Tag
4+
#adr_027
5+
6+
## Status
7+
Accepted
8+
9+
## Date
10+
2026-06-24
11+
12+
## Scope
13+
ModularityKit.Mutator.Governance
14+
15+
## Context
16+
17+
The governance package already models:
18+
19+
- durable mutation requests
20+
- pending request lifecycle
21+
- approval workflow
22+
- version-aware request resolution
23+
24+
What remained open was the final governed execution loop:
25+
26+
- load an approved request
27+
- resolve it against the current state version
28+
- execute the underlying core mutation only when resolution permits it
29+
- persist the terminal governance outcome
30+
- record the resulting state version for future audit and replay
31+
32+
Without an explicit runtime service for that flow, callers would have to manually compose:
33+
34+
- request loading
35+
- resolution
36+
- mutation engine invocation
37+
- request status persistence
38+
- execution decision history
39+
40+
That would make governed execution easy to implement inconsistently across applications.
41+
42+
## Decision
43+
44+
The governance package introduces a dedicated governed execution runtime centered on `IGovernanceExecutionManager`.
45+
46+
The governed execution flow is:
47+
48+
1. load and resolve an approved request through governance version resolution
49+
2. stop early when resolution yields a non-executable outcome such as:
50+
- `RejectedAsStale`
51+
- `RequiresRenewedApproval`
52+
3. execute the wrapped core mutation through `IMutationEngine` only when resolution allows execution
53+
4. persist the terminal governance request outcome:
54+
- `Executed` on successful mutation execution
55+
- `Rejected` on failed execution or execution exception
56+
5. record governance metadata such as:
57+
- resulting state version
58+
- executed timestamp
59+
- request correlation metadata flowing into core audit/history
60+
61+
The runtime is intentionally split by responsibility:
62+
63+
- `GovernanceExecutionManager` orchestrates the end-to-end flow
64+
- `GovernedMutation` carries governance request identifiers into core execution metadata
65+
- `GovernedExecutionOutcomeHandler` maps execution outcomes into terminal request state
66+
- `GovernedExecutionDecisionFactory` creates execution-related governance decisions
67+
- `GovernedExecutionRequestPersistence` performs guarded request persistence with optimistic concurrency
68+
69+
## Design Rationale
70+
71+
- Governed execution is governance concern, not responsibility of the base mutation engine.
72+
- Version resolution must always happen before governed execution proceeds.
73+
- Terminal request persistence must be handled consistently and with optimistic concurrency checks.
74+
- The execution runtime should remain decomposed so orchestration, persistence, and decision mapping can evolve independently.
75+
76+
## Consequences
77+
78+
### Positive
79+
80+
- Governance now closes the loop from approved request to terminal execution outcome.
81+
- Version drift handling is enforced before core execution starts.
82+
- Core audit/history can be correlated with governance request identifiers.
83+
- Execution state is recorded explicitly through `ExecutedAt` and `ResultingStateVersion`.
84+
85+
### Negative
86+
87+
- Governance runtime now owns a larger orchestration surface.
88+
- Execution failures currently collapse into terminal rejection and may require richer taxonomy later.
89+
- Future work is still needed for:
90+
- governed execution retries
91+
- compensation semantics
92+
- persistent queryable execution history across providers
93+
94+
## Related ADRs
95+
96+
- ADR-020: Governance MutationRequest Model
97+
- ADR-023: Governance Versioned Request Resolution
98+
- ADR-024: Governance Runtime Pending Request Handling
99+
- ADR-025: Governance Approval Workflow

Docs/Decision/listadr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ These ADRs describe the `ModularityKit.Mutator.Governance` extension layer and i
4242
| ADR-024 | Governance Runtime Pending Request Handling | [ADR-024](Adr/ADR_024_Governance_Runtime_Pending_Request_Handling.md) |
4343
| ADR-025 | Governance Approval Workflow | [ADR-025](Adr/ADR_025_Governance_Approval_Workflow.md) |
4444
| ADR-026 | Governance Request Query API | [ADR-026](Adr/ADR_026_Governance_Request_Query_API.md) |
45+
| ADR-027 | Governed Execution Manager | [ADR-027](Adr/ADR_027_Governed_Execution_Manager.md) |
4546

4647
> See individual ADRs for detailed context, decision rationale, and consequences.

Docs/ExecutionModel.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This document describes the execution model that `ModularityKit.Mutator` is moving toward as governance features become first-class runtime capabilities.
44

5-
It complements the roadmap by explaining the lifecycle of a mutation once the engine supports pending execution, approvals, versioning, and compensation.
5+
It complements the roadmap by explaining the lifecycle of a mutation now that governance already has request lifecycle, approval workflow, and version-resolution primitives, but still needs a fully closed governed execution loop.
66

77
## Current Model
88

@@ -18,7 +18,7 @@ Today, the engine is centered around direct mutation execution:
1818
This model is strong for immediate execution flows, but it is intentionally narrow:
1919

2020
- blocked mutations are terminal outcomes
21-
- approval requirements are modeled but not yet lifecycle-driven
21+
- direct mutation execution is still the dominant runtime path
2222
- concurrency is not yet part of a first-class execution contract
2323
- compensation and re-execution are not yet modeled as governed transitions
2424

@@ -32,11 +32,12 @@ The target shape is:
3232
2. Evaluate policies and requirements
3333
3. Enter pending state when execution is deferred
3434
4. Resolve requirements through approvals or external checks
35-
5. Re-validate against the current state version
36-
6. Execute or reject
35+
5. Resolve against the current state version
36+
6. Execute through a governed execution manager
3737
7. Emit side effects
3838
8. Audit and persist history
39-
9. Optionally compensate or reverse
39+
9. Record executed or terminal governance decision
40+
10. Optionally compensate or reverse
4041

4142
This is the key conceptual shift in the project:
4243

@@ -69,7 +70,7 @@ Possible pending reasons:
6970
- `PendingDependency`
7071
- `PendingQuota`
7172

72-
Pending state should be treated as a first-class runtime state, not just a flag in `MutationResult`.
73+
Pending state is already a first-class governance state. The remaining work is to ensure every pending path has a clear re-entry route into governed execution.
7374

7475
### Resolution
7576

@@ -83,6 +84,8 @@ Possible outcomes:
8384
- expired
8485
- superseded by a newer request or state version
8586

87+
Resolution is already modeled in the governance runtime. The remaining gap is making it part of one mandatory execution path rather than a helper that callers compose manually.
88+
8689
### Versioned Execution
8790

8891
Approval and deferred execution require explicit version handling.
@@ -95,6 +98,23 @@ When a request is approved against a later state than the one originally evaluat
9598

9699
This behavior must be explicit and consistent across all pending mutation types.
97100

101+
The main hardening point is no longer whether version resolution exists, but whether approved requests always pass through it before execution and whether revalidation has its own explicit runtime semantics.
102+
103+
### Governed Execution Manager
104+
105+
Once approvals and version resolution exist, the runtime needs one orchestrator that closes the loop.
106+
107+
Expected responsibilities:
108+
109+
- load an approved request
110+
- perform mandatory version resolution
111+
- choose execute / reject / re-approve / revalidate paths
112+
- invoke the core mutation engine when execution is still valid
113+
- record resulting state version and execution outcome
114+
- persist terminal governance decisions such as `Executed`
115+
116+
Without this step, governance remains a set of useful runtime pieces rather than one coherent execution contract.
117+
98118
### Compensation
99119

100120
Once the engine supports governed execution over time, compensation becomes part of the execution model rather than a simple utility.
@@ -123,18 +143,20 @@ Without an explicit execution model, these features risk being implemented as is
123143

124144
## Design Pressure Points
125145

126-
These are the architectural questions that should stay visible as implementation starts:
146+
These are the architectural questions that should stay visible as implementation continues:
127147

128148
- Is the primary unit of governance a mutation or a mutation request?
129149
- What state version contract is required for deferred execution?
130150
- When does a pending mutation become stale?
131151
- Can approvals survive state drift, or must they be renewed?
152+
- What is the exact contract of revalidation before execution?
132153
- Are side effects emitted on request creation, on execution, or both?
133154
- How are compensation flows represented in audit and history?
155+
- Where does core mutation execution concurrency end and governance request concurrency begin?
134156

135157
## Relationship to the Roadmap
136158

137-
- `v1.1 Governance Runtime` introduces pending mutation lifecycle, approval workflow, versioned execution, and concurrency control.
159+
- `v1.1 Governance Runtime Hardening` closes the governed execution loop and hardens approval, version-resolution, and core concurrency semantics.
138160
- `v1.2 Governance Data` adds persistence, queryability, metadata handling, and typed side effects around that runtime model.
139161
- `v1.3 Integration` expands the model to async policy evaluation and external governance dependencies.
140162
- `v2.0 Governance Platform` extends the lifecycle with compensation and richer policy composition.

0 commit comments

Comments
 (0)