|
| 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 |
0 commit comments