Execution Patterns
Saga Compensation
dir_core.saga
Saga Compensation (DIR §7, Topologies §6.4).
Parent-Child flows: mark_dirty on partial failure, deterministic compensation.
CompensationResult
dataclass
Result of execute_compensation.
Source code in src/dir_core/saga.py
19 20 21 22 23 24 | |
SagaCompensation
Manages dirty state and deterministic compensation (DIR §7).
Storage backend is pluggable. Pass storage= for a custom backend, or
db_path= to use the built-in SQLite backend (default behaviour).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Optional[str]
|
Path to SQLite database. Used when |
None
|
revert_callback
|
Optional[Callable[[str, Dict[str, Any]], bool]]
|
Called with (dfid, partial_state) on REVERT. |
None
|
close_all_callback
|
Optional[Callable[[str], bool]]
|
Called with (dfid,) on CLOSE_ALL. |
None
|
alert_human_callback
|
Optional[Callable[[str, Dict[str, Any]], None]]
|
Called with (dfid, partial_state) on ALERT_HUMAN. |
None
|
storage
|
Optional[SagaStorage]
|
Custom :class: |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When neither |
Source code in src/dir_core/saga.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
execute_compensation(dfid, action)
Execute deterministic compensation. Callbacks are domain-specific. ALERT_HUMAN triggers escalation callback.
Source code in src/dir_core/saga.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
get_dirty_flows()
Return list of dfids in dirty state.
Source code in src/dir_core/saga.py
82 83 84 | |
get_dirty_state(dfid)
Return partial state for dirty flow.
Source code in src/dir_core/saga.py
86 87 88 | |
mark_dirty(dfid, failed_step, partial_state)
Record flow as PARTIAL_SUCCESS_DIRTY after step failure.
Source code in src/dir_core/saga.py
70 71 72 73 74 75 76 77 78 79 80 | |
Intent Retry Governor
dir_core.intent_retry
Intent Retry Governor (DIR §6.2).
Limits correction attempts per DFID. After max_retries rejections, flow must be aborted with REASONING_EXHAUSTION to prevent feedback poisoning.
IntentRetryGovernor
Tracks rejection count per DFID; enforces max retries before abort.
Storage backend is pluggable. The default is in-memory when neither
db_path nor storage is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_retries
|
int
|
Maximum number of allowed rejections before abort. |
3
|
db_path
|
Optional[str]
|
Path to SQLite database for persistent counting. |
None
|
storage
|
Optional[IntentRetryStorage]
|
Custom :class: |
None
|
Source code in src/dir_core/intent_retry.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
record_rejection(dfid)
Increment rejection count for dfid; return new count.
Source code in src/dir_core/intent_retry.py
51 52 53 54 55 56 | |
reset(dfid)
Clear rejection count when flow ends (CLOSED/ABORTED).
Source code in src/dir_core/intent_retry.py
62 63 64 | |
should_abort(dfid)
True if count >= max_retries (flow must be aborted).
Source code in src/dir_core/intent_retry.py
58 59 60 | |