phronomy 0.37.0 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -0
  3. data/README.md +24 -2
  4. data/SECURITY.md +1 -1
  5. data/docs/architecture/agent-approval-recovery.md +320 -0
  6. data/docs/architecture/agent-child-approval-recovery.md +387 -0
  7. data/docs/architecture/agent-child-execution-recovery.md +425 -0
  8. data/docs/architecture/agent-dispatch-recovery.md +308 -0
  9. data/docs/architecture/agent-terminal-persistence-evidence.md +360 -0
  10. data/docs/architecture/agent-terminal-recovery.md +298 -0
  11. data/docs/architecture/agent-terminal-submission-recovery.md +275 -0
  12. data/docs/architecture/agent-tool-child-lifetime.md +29 -0
  13. data/docs/architecture/agent-transition-ownership.md +24 -0
  14. data/docs/architecture/backend-groups.md +6 -0
  15. data/docs/architecture/detached-outcome-proof-projection.md +576 -0
  16. data/docs/architecture/execution-abstraction-review.md +5 -0
  17. data/docs/architecture/handoff-dispatch-recovery.md +205 -0
  18. data/docs/architecture/handoff-initial-terminal-application.md +321 -0
  19. data/docs/architecture/initial-preparation-recovery.md +308 -0
  20. data/docs/architecture/multi-agent-handoff.md +17 -0
  21. data/docs/architecture/native-outcome-preparation.md +715 -0
  22. data/docs/architecture/native-parent-dispatch-recovery.md +460 -0
  23. data/docs/architecture/native-parent-outcome-recovery.md +644 -0
  24. data/docs/architecture/parent-child-terminal-acknowledgement.md +297 -0
  25. data/docs/architecture/r8-unit12.md +6 -3
  26. data/docs/architecture/r8-unit4.md +11 -2
  27. data/docs/architecture/recovery-physical-attempt.md +88 -0
  28. data/docs/architecture/recovery-submission-custody.md +247 -0
  29. data/docs/architecture/retained-attempts.md +229 -0
  30. data/docs/architecture/retained-outcome-materialization.md +636 -0
  31. data/docs/architecture/retained-outcome-publication.md +506 -0
  32. data/docs/architecture/storage-execution-boundaries.md +1 -1
  33. data/docs/architecture/structured-output-and-scope.md +15 -0
  34. data/docs/architecture/synchronous-participant-application.md +397 -0
  35. data/docs/architecture/synchronous-participant-contract.md +195 -0
  36. data/docs/architecture/team-admission-rejection.md +91 -0
  37. data/docs/architecture/team-cancellation-delivery.md +245 -0
  38. data/docs/architecture/team-child-retirement.md +104 -0
  39. data/docs/architecture/tracing.md +26 -0
  40. data/docs/architecture/workflow-terminal-ownership-design.md +25 -9
  41. data/docs/architecture/workflow-terminal-reconciliation.md +221 -0
  42. data/docs/architecture.md +16 -9
  43. data/docs/decisions/025-process-local-agent-ownership-and-runtime-admission.md +8 -0
  44. data/docs/features.md +3 -3
  45. data/docs/mcp-client.md +138 -5
  46. data/docs/migrations/orchestrator-subagent-dispatch.md +89 -0
  47. data/docs/migrations/vector-async-clients.md +18 -3
  48. data/docs/persistence-backends.md +30 -4
  49. data/docs/runtime-and-concurrency.md +235 -11
  50. data/lib/phronomy/agent/admission.rb +37 -17
  51. data/lib/phronomy/agent/api/agent.rb +25 -0
  52. data/lib/phronomy/agent/approval_recovery.rb +30 -0
  53. data/lib/phronomy/agent/approval_recovery_api.rb +61 -0
  54. data/lib/phronomy/agent/approval_recovery_error.rb +39 -0
  55. data/lib/phronomy/agent/approval_recovery_result.rb +94 -0
  56. data/lib/phronomy/agent/async_event_api.rb +22 -5
  57. data/lib/phronomy/agent/base.rb +76 -48
  58. data/lib/phronomy/agent/context_preparation.rb +10 -8
  59. data/lib/phronomy/agent/dispatch_recovery.rb +29 -0
  60. data/lib/phronomy/agent/dispatch_recovery_api.rb +84 -0
  61. data/lib/phronomy/agent/dispatch_recovery_error.rb +36 -0
  62. data/lib/phronomy/agent/dispatch_recovery_result.rb +93 -0
  63. data/lib/phronomy/agent/execution/agent_invocation.rb +11 -3
  64. data/lib/phronomy/agent/execution/approval_continuation_plan.rb +131 -0
  65. data/lib/phronomy/agent/execution/approval_parent_evidence.rb +116 -0
  66. data/lib/phronomy/agent/execution/approval_persistence_evidence.rb +111 -0
  67. data/lib/phronomy/agent/execution/approval_recovery_operation.rb +496 -0
  68. data/lib/phronomy/agent/execution/approval_resume_commit.rb +174 -10
  69. data/lib/phronomy/agent/execution/dispatch_continuation_delivery.rb +96 -0
  70. data/lib/phronomy/agent/execution/dispatch_persistence_evidence.rb +147 -0
  71. data/lib/phronomy/agent/execution/dispatch_preparation.rb +63 -7
  72. data/lib/phronomy/agent/execution/dispatch_recovery_operation.rb +495 -0
  73. data/lib/phronomy/agent/execution/execution_coordinator.rb +724 -158
  74. data/lib/phronomy/agent/execution/execution_outcome_committer.rb +312 -39
  75. data/lib/phronomy/agent/execution/execution_registry.rb +508 -13
  76. data/lib/phronomy/agent/execution/initial_persistence_evidence.rb +269 -0
  77. data/lib/phronomy/agent/execution/initial_preparation.rb +132 -40
  78. data/lib/phronomy/agent/execution/initial_preparation_recovery_operation.rb +513 -0
  79. data/lib/phronomy/agent/execution/invocation_transitions.rb +3 -0
  80. data/lib/phronomy/agent/execution/outcome_planning.rb +108 -0
  81. data/lib/phronomy/agent/execution/outcome_preparation.rb +81 -0
  82. data/lib/phronomy/agent/execution/outcome_recovery_operation.rb +609 -0
  83. data/lib/phronomy/agent/execution/outcome_text_projection.rb +73 -0
  84. data/lib/phronomy/agent/execution/outcome_write_plan.rb +48 -0
  85. data/lib/phronomy/agent/execution/runtime_record_encoder.rb +7 -4
  86. data/lib/phronomy/agent/execution/terminal_persistence_evidence.rb +280 -0
  87. data/lib/phronomy/agent/execution/terminal_recovery_operation.rb +38 -0
  88. data/lib/phronomy/agent/execution_change.rb +138 -26
  89. data/lib/phronomy/agent/execution_environment.rb +29 -0
  90. data/lib/phronomy/agent/execution_rejected_error.rb +34 -0
  91. data/lib/phronomy/agent/initial_preparation_recovery.rb +32 -0
  92. data/lib/phronomy/agent/initial_preparation_recovery_api.rb +85 -0
  93. data/lib/phronomy/agent/initial_preparation_recovery_error.rb +41 -0
  94. data/lib/phronomy/agent/initial_preparation_recovery_result.rb +115 -0
  95. data/lib/phronomy/agent/lifecycle/hosted_approval_context.rb +86 -0
  96. data/lib/phronomy/agent/lifecycle/hosted_invocation.rb +42 -10
  97. data/lib/phronomy/agent/lifecycle/identity_write.rb +101 -0
  98. data/lib/phronomy/agent/lifecycle/lifetime_api.rb +28 -0
  99. data/lib/phronomy/agent/lifecycle/ownership_registry.rb +136 -70
  100. data/lib/phronomy/agent/lifecycle/scope.rb +3 -3
  101. data/lib/phronomy/agent/outcome_recovery.rb +47 -0
  102. data/lib/phronomy/agent/outcome_recovery_api.rb +114 -0
  103. data/lib/phronomy/agent/outcome_recovery_error.rb +36 -0
  104. data/lib/phronomy/agent/outcome_recovery_result.rb +92 -0
  105. data/lib/phronomy/agent/output_contract.rb +16 -6
  106. data/lib/phronomy/agent/persistence/identity_receipt_repository.rb +61 -0
  107. data/lib/phronomy/agent/persistence/records.rb +2 -0
  108. data/lib/phronomy/agent/persistence/storage_schema.rb +2 -0
  109. data/lib/phronomy/agent/recovery/invocation_restorer.rb +8 -5
  110. data/lib/phronomy/agent/recovery/recovery_coordinator/continuation.rb +6 -4
  111. data/lib/phronomy/agent/recovery/recovery_coordinator/installation.rb +21 -43
  112. data/lib/phronomy/agent/recovery/recovery_coordinator.rb +19 -6
  113. data/lib/phronomy/agent/runtime_binding/engine_environment.rb +12 -0
  114. data/lib/phronomy/agent/state_writer.rb +4 -3
  115. data/lib/phronomy/agent/store.rb +7 -1
  116. data/lib/phronomy/agent/terminal_recovery.rb +41 -0
  117. data/lib/phronomy/agent/terminal_recovery_api.rb +101 -0
  118. data/lib/phronomy/agent/terminal_recovery_error.rb +36 -0
  119. data/lib/phronomy/agent/terminal_recovery_result.rb +67 -0
  120. data/lib/phronomy/agent/tool_execution/tool_approval_request.rb +25 -1
  121. data/lib/phronomy/common/values/serializable.rb +37 -4
  122. data/lib/phronomy/engine/concurrency/offload_pool.rb +32 -4
  123. data/lib/phronomy/engine/concurrency/pool_registry.rb +6 -0
  124. data/lib/phronomy/engine/event_loop.rb +161 -11
  125. data/lib/phronomy/engine/execution_binding.rb +4 -2
  126. data/lib/phronomy/engine/execution_receiver_binding.rb +5 -0
  127. data/lib/phronomy/engine/runtime/shutdown_result.rb +21 -0
  128. data/lib/phronomy/engine/runtime/timer_queue.rb +7 -2
  129. data/lib/phronomy/engine/runtime.rb +119 -15
  130. data/lib/phronomy/execution/attempt_completion.rb +91 -0
  131. data/lib/phronomy/execution/concurrency/cancellation_token.rb +7 -2
  132. data/lib/phronomy/execution/concurrency/physical_completion_task.rb +7 -2
  133. data/lib/phronomy/execution/execution.rb +17 -2
  134. data/lib/phronomy/execution/execution_receiver.rb +27 -0
  135. data/lib/phronomy/execution/execution_retirement.rb +30 -0
  136. data/lib/phronomy/execution/invocation_controls.rb +2 -2
  137. data/lib/phronomy/execution/retained_attempts.rb +179 -0
  138. data/lib/phronomy/execution/stopped_terminal_custody.rb +99 -0
  139. data/lib/phronomy/llm_adapter/response.rb +7 -1
  140. data/lib/phronomy/multi_agent/admission_registry.rb +6 -0
  141. data/lib/phronomy/multi_agent/durable_subagent_coordinator.rb +175 -39
  142. data/lib/phronomy/multi_agent/handoff_dispatch_evidence.rb +176 -0
  143. data/lib/phronomy/multi_agent/handoff_finalization_error.rb +33 -0
  144. data/lib/phronomy/multi_agent/handoff_history_release.rb +80 -0
  145. data/lib/phronomy/multi_agent/handoff_participant.rb +31 -6
  146. data/lib/phronomy/multi_agent/handoff_runner.rb +195 -21
  147. data/lib/phronomy/multi_agent/handoff_terminal_finalization.rb +176 -0
  148. data/lib/phronomy/multi_agent/native_approval_evidence.rb +26 -0
  149. data/lib/phronomy/multi_agent/native_child_authority.rb +135 -0
  150. data/lib/phronomy/multi_agent/native_dispatch_evidence.rb +43 -0
  151. data/lib/phronomy/multi_agent/native_outcome_evidence.rb +46 -0
  152. data/lib/phronomy/multi_agent/native_persistence_plan.rb +93 -0
  153. data/lib/phronomy/multi_agent/orchestrator.rb +28 -52
  154. data/lib/phronomy/multi_agent/reserved_child_admission.rb +90 -1
  155. data/lib/phronomy/multi_agent/store.rb +5 -34
  156. data/lib/phronomy/multi_agent/subagent_history_release.rb +88 -0
  157. data/lib/phronomy/multi_agent/team_cancellation_delivery_error.rb +21 -0
  158. data/lib/phronomy/multi_agent/team_cancellation_request.rb +134 -0
  159. data/lib/phronomy/multi_agent/team_coordinator.rb +174 -27
  160. data/lib/phronomy/persistence_composition/stores.rb +10 -3
  161. data/lib/phronomy/runtime_composition/execution_defaults.rb +18 -0
  162. data/lib/phronomy/storage/backends/in_memory.rb +3 -1
  163. data/lib/phronomy/storage/resource.rb +10 -1
  164. data/lib/phronomy/tools/agent.rb +7 -1
  165. data/lib/phronomy/tools/mcp.rb +210 -91
  166. data/lib/phronomy/tools/mcp_http_close_response.rb +23 -0
  167. data/lib/phronomy/tools/mcp_transport_registry.rb +210 -0
  168. data/lib/phronomy/tools/vector_search.rb +28 -5
  169. data/lib/phronomy/tracing/automatic.rb +8 -1
  170. data/lib/phronomy/version.rb +1 -1
  171. data/lib/phronomy/workflow/execution/workflow.rb +34 -0
  172. data/lib/phronomy/workflow/execution/workflow_execution_environment.rb +1 -0
  173. data/lib/phronomy/workflow/execution/workflow_execution_registry.rb +106 -7
  174. data/lib/phronomy/workflow/execution/workflow_runner.rb +53 -108
  175. data/lib/phronomy/workflow/execution/workflow_terminal_operation.rb +489 -0
  176. data/lib/phronomy/workflow/execution/workflow_terminal_persistence.rb +81 -0
  177. data/lib/phronomy/workflow/execution/workflow_terminal_recovery.rb +38 -0
  178. data/lib/phronomy/workflow/execution/workflow_terminal_recovery_error.rb +34 -0
  179. data/lib/phronomy/workflow/execution/workflow_terminal_recovery_result.rb +56 -0
  180. data/lib/phronomy/workflow/runtime_binding/workflow_engine_environment.rb +10 -1
  181. data/lib/phronomy/workflow/runtime_binding/workflow_task_session.rb +3 -1
  182. data/lib/phronomy/workflow/runtime_binding/workflow_terminal_policy.rb +2 -1
  183. data/scripts/api_snapshot.rb +46 -1
  184. data/sig/_private/phronomy/multi_agent/team_cancellation_request.rbs +19 -0
  185. data/sig/phronomy/agent/approval_recovery.rbs +54 -0
  186. data/sig/phronomy/agent/dispatch_recovery.rbs +49 -0
  187. data/sig/phronomy/agent/execution_contract.rbs +4 -1
  188. data/sig/phronomy/agent/execution_environment.rbs +2 -0
  189. data/sig/phronomy/agent/initial_preparation_recovery.rbs +48 -0
  190. data/sig/phronomy/agent/outcome_recovery.rbs +51 -0
  191. data/sig/phronomy/agent/store.rbs +1 -0
  192. data/sig/phronomy/agent/terminal_persistence_evidence.rbs +111 -0
  193. data/sig/phronomy/agent/terminal_recovery.rbs +46 -0
  194. data/sig/phronomy/agent.rbs +36 -0
  195. data/sig/phronomy/engine/concurrency/timer_bindings.rbs +2 -0
  196. data/sig/phronomy/engine/execution_binding.rbs +2 -1
  197. data/sig/phronomy/engine/execution_receiver.rbs +4 -0
  198. data/sig/phronomy/engine/observability.rbs +22 -1
  199. data/sig/phronomy/execution/execution.rbs +16 -1
  200. data/sig/phronomy/execution/execution_receiver.rbs +12 -0
  201. data/sig/phronomy/execution/execution_retirement.rbs +18 -0
  202. data/sig/phronomy/execution/stopped_terminal_custody.rbs +19 -0
  203. data/sig/phronomy/handoff.rbs +1 -0
  204. data/sig/phronomy/multi_agent/handoff_finalization_error.rbs +18 -0
  205. data/sig/phronomy/multi_agent/store.rbs +1 -1
  206. data/sig/phronomy/multi_agent/team_cancellation_delivery_error.rbs +9 -0
  207. data/sig/phronomy/persistence_composition.rbs +2 -1
  208. data/sig/phronomy/storage/contracts.rbs +2 -1
  209. data/sig/phronomy/tools/mcp.rbs +27 -0
  210. data/sig/phronomy/workflow.rbs +42 -0
  211. metadata +104 -2
@@ -0,0 +1,221 @@
1
+ # Workflow terminal reconciliation
2
+
3
+ The later [stopped terminal custody contract](../runtime-and-concurrency.md#transfer-a-stopped-terminal-disposition) adds an explicit same-process recipient after the original Runtime stops. The live-owner procedures below retain their original admission rules.
4
+
5
+ Workflow owns each accepted execution segment until its terminal persistence and
6
+ required owner-side application are resolved. A failed observation must not erase
7
+ that responsibility. This process-local recovery path uses the captured Workflow
8
+ and its original running or draining Runtime; it does not transfer work to a new
9
+ Runtime or provide recovery after process loss.
10
+
11
+ For example, a Workflow can save value `7`, lose the save response, and then fail
12
+ its first authoritative read. A later explicit reconciliation can establish that
13
+ same saved result without saving again or executing the graph again.
14
+
15
+ ## Retained responsibility and original observation
16
+
17
+ The Workflow owner retains an immutable description of the attempted save before
18
+ submission. Retirement explicitly transfers the original completion obligation
19
+ from Engine to Workflow. Persistence classification and owner release remain
20
+ Workflow decisions; Engine does not interpret snapshots or business results.
21
+
22
+ For example, when the first read cannot establish the save outcome, the original
23
+ observation fails with `WorkflowTerminalRecoveryError` after custody is retained.
24
+ Failing the old source task through normal finalization would release the owner,
25
+ so retirement follows its own acknowledged path.
26
+
27
+ Receiver acceptance and completion delivery are checked separately. The
28
+ Workflow operation first accepts the exact retirement envelope. Engine then
29
+ detaches the original completion slot and delivers that same envelope through
30
+ its source completion. Runner confirms that exact delivery before recovery may
31
+ apply and release the owner. Merely returning acceptance or having a different
32
+ source task finish is not confirmation. A withheld completion prevents recovery
33
+ from applying or releasing responsibility, even if persistence is already known.
34
+
35
+ The error has code `workflow.terminal_recovery` and exposes
36
+ `workflow_instance_id`, `recovery_id`, and `recovery`. `original_error` preserves
37
+ the original persistence failure when available; `cause` reports the immediate
38
+ operation failure. It is not `CancellationError` or a declaration that the
39
+ business result failed. Ordinary and task-bearing Workflows follow this same
40
+ observation contract. The original failed TaskResult remains failed permanently.
41
+ After a `stream` call returns an error, its old block is not called by recovery.
42
+
43
+ The capability is read-only, cannot be publicly constructed, and belongs to the
44
+ exact compiled Workflow and captured owner. IDs are diagnostic identities rather
45
+ than serializable recovery tickets. While unresolved, the registry retains the
46
+ obligation even if every caller drops its reference. After resolution, a held
47
+ capability preserves its resolved receipt without an indefinite global history
48
+ map. It must not be sent as JSON or treated as a cross-process authorization token.
49
+
50
+ As of 2026-11-28, Workflow uses the same C13 `RetainedAttempts` manager and
51
+ `AttemptCompletion` evidence record as Agent outcome, approval and dispatch
52
+ recovery. Slot/observer management and completion observations are shared;
53
+ Workflow retains custody confirmation, persistence classification, context
54
+ reconstruction and segment release. See [shared retained-attempt management](retained-attempts.md).
55
+
56
+ ## Explicit observation and lookup
57
+
58
+ Recovery reads the original repository only while the persistence fact is
59
+ unknown. Confirmed persistence, application and release are separate facts.
60
+ Concurrent recovery observers share one physical attempt, while cancelling or
61
+ timing out an observation does not cancel the retained responsibility.
62
+
63
+ Each observer receives its own context view even when its physical read is
64
+ shared. Mutating one returned view cannot change retained proof or another
65
+ observer's context. The application class's construction behavior still applies
66
+ to each view, as described below.
67
+
68
+ For example, after the repository becomes readable, an application can call
69
+ `workflow.reconcile_terminal_async(recovery: error.recovery)`. Repeating that
70
+ operation after resolution observes the retained receipt rather than loading
71
+ storage or acquiring another segment owner.
72
+
73
+ | Public operation | Contract |
74
+ | --- | --- |
75
+ | `reconcile_terminal_async(recovery:)` | Returns a fresh `TaskResult<WorkflowTerminalRecoveryResult>`. Invalid or foreign capabilities are rejected before storage I/O. |
76
+ | `reconcile_terminal(recovery:)` | Waits for the same operation on a host thread. Blocking on EventLoop is rejected. |
77
+ | `pending_terminal_recovery(workflow_instance_id:)` | Reads the captured Workflow's local unresolved index. No storage I/O, Runtime startup or state change. Requires a nonempty String. Returns `nil` when no matching uncertain obligation is indexed. |
78
+
79
+ The lookup supplies a recovery reference when an initial TaskResult was
80
+ cancelled or its error was discarded. It does not report a save still in normal
81
+ progress as uncertain. After release, lookup returns `nil`; a capability already
82
+ held by the caller still supports repeat observation. This is not a general
83
+ lookup across different compiled Workflow instances or process generations.
84
+
85
+ No retry loop, new save, `resume`, `send_saved_event`, or graph event is part of
86
+ reconciliation. Entry, exit, transition, stable-state, task-start, Provider and
87
+ Tool callbacks are not replayed. Returned context views are reconstructed with
88
+ the declared context class and metadata. A custom constructor or a context field
89
+ default can run during construction, so arbitrary context-construction code is
90
+ not covered by the graph-callback no-replay guarantee. Construction can fail
91
+ independently; another explicit observation can retry that construction using
92
+ retained proof, without another read or save.
93
+
94
+ ## Reading the result
95
+
96
+ Each result captures persistence, application and ownership as an immutable
97
+ observation. A subsequent observation may show progress without changing an
98
+ earlier result. An application should check the separate states before treating
99
+ recovery as finished.
100
+
101
+ For example, `confirmed_post`, `pending`, and `retained` establish the saved
102
+ snapshot but leave owner application unfinished. `confirmed_post` alone does not
103
+ permit a new segment or prove that a context view was delivered successfully.
104
+
105
+ | Reader | Values and meaning |
106
+ | --- | --- |
107
+ | `outcome` | `confirmed_post`: exact intended snapshot/revision; `confirmed_pre`: original save is proven absent; `unresolved`: readable conflicting evidence; `unavailable`: no classified fact and the read/owner/delivery is unavailable. |
108
+ | `application_state` | `pending` or `applied`; whether the exact owner applied the classified disposition. |
109
+ | `ownership_state` | `retained` or `released`; release also requires the relevant physical completion boundaries. `pending`/`released` is invalid. |
110
+ | `revision`, `context` | Saved revision and an independent context view only for `confirmed_post`. Context may be `nil` when construction fails or the observation cannot materialize a view. |
111
+ | `error` | Persistence, read, application or context-construction diagnostic. It does not reverse an already confirmed persistence fact. |
112
+ | `recovery`, `workflow_instance_id`, `recovery_id` | The original capability and immutable diagnostic identities. |
113
+
114
+ Unclassified outcomes are always pending and retained. Confirmed outcomes can
115
+ remain pending/retained, become applied/retained, or become applied/released.
116
+ Once persistence is known, a later observation retries only missing application
117
+ or context construction. Already applied owner steps are not repeated. A result
118
+ can be applied/released and still carry a context-construction error; its stored
119
+ fact and release are preserved.
120
+
121
+ Confirmed pre-state follows Workflow's existing known-save-failure policy and
122
+ does not replay the save. This differs from an Agent execution whose accepted
123
+ durable job may still be active. It is not a shared business-failure rule.
124
+
125
+ ## Application integration
126
+
127
+ The caller retains observations and local recovery references, decides when an
128
+ explicit reconciliation is appropriate, and translates the separate facts into
129
+ its own service response. Authorization and any later business retry remain
130
+ application decisions.
131
+
132
+ For example, a service keeps the original TaskResult after a waiter-local
133
+ timeout. When its error is available it uses that exact recovery reference; if
134
+ the observation was cancelled, it can query the same Workflow's pending index.
135
+ Neither path automatically restarts the investigation.
136
+
137
+ These complete function units require `phronomy` and a configured Workflow passed
138
+ as an argument. The shared normal-path behavior is observing its context. The
139
+ failure-path change is intentional: a recoverable unknown result now provides a
140
+ typed reference instead of leaving an ordinary observation pending indefinitely.
141
+
142
+ ```ruby
143
+ require "phronomy"
144
+
145
+ def observe_workflow(workflow:, input:, workflow_instance_id:, timeout:)
146
+ report = {task: nil, context: nil, error: nil, recovery: nil}
147
+ begin
148
+ report[:task] = workflow.invoke_async(input,
149
+ config: {workflow_instance_id: workflow_instance_id})
150
+ report[:context] = report[:task].wait_result(timeout: timeout)
151
+ rescue Phronomy::WorkflowTerminalRecoveryError => error
152
+ report[:error] = error
153
+ report[:recovery] = error.recovery
154
+ rescue StandardError => error
155
+ report[:error] = error
156
+ end
157
+ report.freeze
158
+ end
159
+
160
+ def inspect_pending_recovery(workflow:, workflow_instance_id:)
161
+ workflow.pending_terminal_recovery(workflow_instance_id: workflow_instance_id)
162
+ end
163
+
164
+ def reconcile_once(workflow:, recovery:, timeout:)
165
+ report = {task: nil, recovery: recovery, observation: nil, error: nil}
166
+ begin
167
+ report[:task] = workflow.reconcile_terminal_async(recovery: recovery)
168
+ report[:observation] = report[:task].wait_result(timeout: timeout)
169
+ rescue StandardError => error
170
+ report[:error] = error
171
+ end
172
+ report.freeze
173
+ end
174
+ ```
175
+
176
+ The returned report retains its TaskResult on timeout so the caller can observe
177
+ it later. A normal return from `reconcile_once` can contain an unresolved or
178
+ unavailable observation; application code must not equate it with successful
179
+ business completion. An outer operation error and the observation's own `error`
180
+ also remain distinct.
181
+
182
+ ## Shutdown and the supported recovery profile
183
+
184
+ Unresolved terminal responsibility prevents complete cleanup and survives the
185
+ original observer's lifetime. The captured Runtime is never silently replaced.
186
+ This implementation profile allows recovery while its existing owner can still
187
+ receive and apply results; it does not implement a stopped-owner custody transfer.
188
+
189
+ For example, after the original dispatcher has stopped, lookup still exposes its
190
+ retained reference. Reconciliation with no confirmed persistence reports
191
+ unavailable; any already confirmed fact remains confirmed while ownership stays
192
+ retained. A new default Runtime cannot adopt that old operation merely by using
193
+ the same ID.
194
+ An already finalized capability can still report its resolved receipt without I/O.
195
+
196
+ Physical completion is distinct from logical TaskResult settlement. A save that
197
+ may still commit cannot be classified as absent merely because one observer
198
+ timed out. Neither shutdown nor an unavailable result makes that inference.
199
+ Later recovery does not rewrite a previously recorded incomplete shutdown result.
200
+ Exclusive host ownership, the repository's monotonic revision/CAS contract and
201
+ in-process reference retention remain prerequisites. Pre-state confirmation also
202
+ requires authoritative readback ordered after the original save has settled:
203
+ that save must not be able to commit later. Local worker or TaskResult physical
204
+ completion alone does not establish this remote-storage guarantee, and an
205
+ eventually consistent replica is not authoritative readback. The existing
206
+ repository capability flags do not certify either condition. A backend that can
207
+ commit after returning an ambiguous failure requires separate settlement
208
+ evidence or fencing before this profile's `confirmed_pre` result can be relied
209
+ on. The in-memory fault tests exercise settled writes; remote adapters require
210
+ their own acceptance tests. This implementation does not add that backend
211
+ settlement protocol.
212
+
213
+ Crash durability, remote
214
+ request receipts, arbitrary competing writers, stopped-owner takeover and the
215
+ remaining Agent recovery paths require separate work.
216
+
217
+ ## Preserve custody when submission is uncertain
218
+
219
+ Terminal recovery retains the original owner whenever a submitted worker may still execute. Positive executor rejection, returned handles and physical completion remain separate from whether the caller received a response.
220
+
221
+ For example, an adapter that queues a reconciliation read and then loses its handle must not permit a second read or release the owner. See [recovery submission custody](recovery-submission-custody.md) for the shared evidence rules, deliberate fault-behavior change, compatibility limits and validation scope.
data/docs/architecture.md CHANGED
@@ -189,7 +189,11 @@ participant joins its own domain changes to the same scope. MultiAgent owns
189
189
  subagent reservations and Handoff routing; it passes extension state and transfer
190
190
  receipts, never Agent records or arbitrary update blocks. The EventLoop owner
191
191
  continues to apply confirmed results and deliver callbacks. See
192
- [r8 unit 4](architecture/r8-unit4.md).
192
+ [r8 unit 4](architecture/r8-unit4.md) and the current
193
+ [synchronous participant contract](architecture/synchronous-participant-contract.md).
194
+ That contract limits each change to its active synchronous call and detaches
195
+ comparison evidence. Existing dispatch/outcome owners retain uncertain public
196
+ participant operations independently of their private persistence replay capability.
193
197
 
194
198
  The remaining execution owner expresses result handling as validation, committed
195
199
  state installation, and continuation or delivery. Private methods keep these
@@ -204,14 +208,17 @@ the same methods as their cleanup decisions.
204
208
  | Approval resume result | Validate suspended revision; install committed state and waiter; observe the task; resume the FSM |
205
209
  | Terminal result | Validate revision/session; handle commit uncertainty; apply state and acknowledge the snapshot; deliver the selected outcome |
206
210
 
207
- Terminal delivery releases ownership before notifying completed/failed/Handoff
208
- observers, then settles Tasks. Suspension keeps ordinary Tasks pending. Ordinary
209
- commit uncertainty keeps recovery admission and pending waiters; coordination
210
- errors retain their separate release-and-fail behavior. Session registration
211
- failure during preparation recovery still terminalizes without a live session;
212
- trace/resume failure still uses the newly installed execution revision.
213
- This is an internal readability refinement of ADR-024/047/051, not a change to
214
- persistence, recovery guarantees or public interfaces.
211
+ Confirmed terminal delivery releases the local operation's ownership before
212
+ notifying completed/failed/Handoff observers, then settles Tasks. Suspension keeps
213
+ the logical job active. Supported retained owners close an uncertain caller with
214
+ a typed recovery error while preserving admission and unresolved responsibility;
215
+ later recovery is a separate observation. Public synchronous participants without
216
+ supported replay proof remain explicitly unavailable rather than replaying their
217
+ callback. Session registration failure can terminalize without a live session,
218
+ using the original admission token; trace/resume failure uses the newly installed
219
+ execution revision. The result-entry decomposition originated as the internal
220
+ readability refinement of ADR-024/047/051; the linked recovery contracts define
221
+ the subsequent behavioral guarantees and their limits.
215
222
 
216
223
  Selected nested Zeitwerk roots retain existing top-level Phronomy constants
217
224
  without changing the enclosing feature's existing nested constants. For
@@ -144,6 +144,14 @@ load/shutdown waiters are not left blocked on a transition that can no longer
144
144
  settle by itself. ACS-15 recovery/reconciliation work is responsible for
145
145
  resolving that uncertainty.
146
146
 
147
+ Only an outer Store transaction supplies confirmation for a lost identity
148
+ change reply. If
149
+ Persistence confirms the original transaction before its caller loses the
150
+ reply, create can publish its original result and purge can invalidate its old
151
+ owner using that confirmation. Both operations use the result of the original
152
+ write. A create interrupted after confirmation releases its unpublished
153
+ reservation so the confirmed root can be loaded normally.
154
+
147
155
  ### EventLoop owns same-process top-level execution admission
148
156
 
149
157
  A live Agent may be idle while still owned. Top-level Execution admission is a
data/docs/features.md CHANGED
@@ -55,7 +55,7 @@ rather than implicitly inheriting the parent revision. The Stable
55
55
  | **Knowledge** — Journal-backed persistent Agent context registered with `knowledge:` / `add_knowledge`, selected per LLM call by Context Policy | Beta |
56
56
  | **`VectorStore#size`** — Document count for InMemory, RedisSearch, and Pgvector backends | Beta |
57
57
  | **Storage::AsyncClient** — `transaction_async` runs a raw backend transaction on one worker and returns TaskResult; [usage and lifetime rules](migrations/storage-async-client.md) | Beta |
58
- | **PersistenceComposition resource catalogs** — Unreleased `resources` / `agent_resources` expose canonical frozen declarations for full or Agent-only backend construction; [ownership and example](persistence-backends.md#supplying-a-backend-catalog) | Beta |
58
+ | **PersistenceComposition resource catalogs** — Since v0.35.0, `resources` / `agent_resources` expose canonical frozen declarations for full or Agent-only backend construction; [ownership and example](persistence-backends.md#supplying-a-backend-catalog) | Beta |
59
59
  | **VectorStore::AsyncClient** — `add_async` / `search_async` / `remove_async` / `clear_async` offload the synchronous Backend SPI through Phronomy and return `TaskResult`; native async override is not part of the current Backend SPI | Beta |
60
60
  | **Embeddings::AsyncClient** — `embed_async` offloads synchronous `embed` through Phronomy and returns `TaskResult` | Beta |
61
61
  | **Model Context Protocol (MCP) Tool** — `Phronomy::Tools::Mcp` integration through the official `mcp` gem | Beta |
@@ -112,8 +112,8 @@ See the [migration guide](migrations/parallel-tool-chat-removal.md).
112
112
  | **Completed native child release** — A host can unload the local Orchestrator and its finished direct child while preserving their saved results, conversation and coordination history. [Contract](runtime-and-concurrency.md#releasing-a-completed-orchestrator-and-child) | Beta |
113
113
  | **`Phronomy::MultiAgent::TeamCoordinator`** — LLM coordinator with stateful worker Agents | Beta |
114
114
  | **`Phronomy::MultiAgent::SharedState`** — Sequential peer-agent coordination through an invocation-local findings store; default member derivation preserves Phronomy authoring settings through `Agent::Base.with_tools`; see the [sharing contract](shared-state-sharing.md#deriving-an-agent-with-a-complete-tool-set) and [namespace migration](migrations/shared-state-multi-agent.md) | Experimental |
115
- | **Agent Tool composition** — `Agent::Base.with_tools(definitions, id:, version:)` derives a class with a complete replacement Tool map while preserving Phronomy authoring settings and filters; [contract](shared-state-sharing.md#deriving-an-agent-with-a-complete-tool-set) | Experimental (Unreleased) |
116
- | **Custom shared data and Tools** — `SharedState.sharing(provider, id:, version:)` and `SharedState::Binding` connect application-owned stores and Tool definitions without private overrides; [contract and executable example](shared-state-sharing.md) | Experimental (Unreleased) |
115
+ | **Agent Tool composition** — `Agent::Base.with_tools(definitions, id:, version:)` derives a class with a complete replacement Tool map while preserving Phronomy authoring settings and filters; [contract](shared-state-sharing.md#deriving-an-agent-with-a-complete-tool-set) | Experimental (since v0.33.0) |
116
+ | **Custom shared data and Tools** — `SharedState.sharing(provider, id:, version:)` and `SharedState::Binding` connect application-owned stores and Tool definitions without private overrides; [contract and executable example](shared-state-sharing.md) | Experimental (since v0.33.0) |
117
117
  | **Human-in-the-loop approval** — durable suspension publishes `:approval_required` through the Agent listener; `approve` / `approve_async` resumes the same logical `execution_id` with a fresh FSMSession incarnation | Beta |
118
118
  | **`tool_approval_policy`** — Application-defined allow/approve/reject policy using a value-only `ApprovalEvaluationRequest` without live Agent/Tool references | Beta |
119
119
 
data/docs/mcp-client.md CHANGED
@@ -70,8 +70,141 @@ this phase.
70
70
  a new connection, preventing an abandoned SDK worker from sharing the old stdio
71
71
  stream with a new request.
72
72
 
73
- Calls, reconnects, and explicit `close` operations on a Tool instance are
74
- serialized. `close` synchronously closes the current client and permits a later
75
- call to reconnect. A transport detached by cancellation is owned by the bounded
76
- MCP cleanup pool and is drained during Runtime shutdown; `close` does not wait
77
- for an older detached transport.
73
+ ## Transport ownership
74
+
75
+ Tool construction acquires transport capacity from the current Runtime before
76
+ calling the SDK. Discovery, each live connection and each replacement use a
77
+ distinct generation. A Runtime admits up to 100 reserved, open, queued,
78
+ closing or failed transports in aggregate. Exhaustion raises
79
+ `Phronomy::BackpressureError` before SDK construction. SDK constructors own
80
+ any internal allocations until they return a transport to Phronomy. Reading
81
+ the Tool class or inspecting existing cleanup handles starts no Runtime.
82
+
83
+ Calls and explicit close operations on one Tool are serialized. `tool.close`
84
+ closes the current connection on the calling thread, subject to the SDK's I/O
85
+ behavior. A cancelled call queues cleanup on the originating Runtime. If
86
+ submission raises, the caller attempts the same close inline. Both paths use
87
+ one claim on the generation. A later call by the application may open a fresh
88
+ connection while the previous generation remains in custody, subject to the
89
+ same capacity limit. After Runtime draining begins, new calls and acquisitions
90
+ raise `Phronomy::RuntimeShutdownError`.
91
+
92
+ An explicit close checks older detached generations without waiting for them.
93
+ If any remain, it raises `Phronomy::Tools::Mcp::CleanupError`. Its `pending`
94
+ array snapshots the affected generations and their primary and close errors.
95
+ A discovery, connect or reconnect failure accompanied by a close failure
96
+ raises the same error with the primary cause. An SDK cancellation still raises
97
+ `Phronomy::CancellationError`; its cleanup outcome remains accessible through
98
+ the Tool's handle. For a session-bearing HTTP transport, the adapter also checks
99
+ the response to the SDK's DELETE. For stdio, the SDK owns process and pipe
100
+ shutdown. Verifying an external process or server beyond these observations
101
+ requires separate evidence.
102
+
103
+ ### Handling a Tool result and cleanup separately
104
+
105
+ A host can preserve a successful business value or its error while recording
106
+ a cleanup obligation. For example, this helper performs exactly one search
107
+ against a configured server and returns the three outcomes to its caller.
108
+
109
+ ```ruby
110
+ require "phronomy"
111
+
112
+ def search_docs(server_uri, query)
113
+ value = operation_error = cleanup_error = tool = nil
114
+ begin
115
+ tool = Phronomy::Tools::Mcp.from_server(server_uri, tool_name: "search_docs")
116
+ value = tool.call({query: query})
117
+ rescue Phronomy::Tools::Mcp::CleanupError => error
118
+ operation_error = error.primary_error
119
+ cleanup_error = error
120
+ rescue StandardError => error
121
+ operation_error = error
122
+ ensure
123
+ if tool && cleanup_error.nil?
124
+ begin
125
+ tool.close
126
+ rescue Phronomy::Tools::Mcp::CleanupError => error
127
+ cleanup_error = error
128
+ end
129
+ end
130
+ end
131
+ {value: value, operation_error: operation_error, cleanup_error: cleanup_error}
132
+ end
133
+ ```
134
+
135
+ Earlier versions suppressed SDK close errors and returned from `close` after
136
+ checking only the current connection. Applications that use a single `ensure`
137
+ should capture cleanup errors separately to preserve the business outcome.
138
+ A factory can fail before returning a Tool. Its `error.cleanup_handle` and the
139
+ originating Runtime both retain the resource.
140
+
141
+ ### Management after a failed close
142
+
143
+ The host can inspect
144
+ `Phronomy::Tools::Mcp.cleanup_handles(runtime: original_runtime)` after
145
+ shutdown, even when another Runtime has become the default. Each handle's
146
+ `pending` snapshot identifies its transport generation, origin, state and errors.
147
+ An open transport can be closed through `handle.close`, which uses the original
148
+ Tool's call mutex. This may wait for a call already in progress.
149
+ `handle.finish_queued(generation)` can perform an unstarted first close on
150
+ the management thread. Its Boolean result reports whether that thread claimed
151
+ the attempt. Re-read `pending` for the result. A running attempt retains its
152
+ claim until the SDK call returns.
153
+
154
+ For a finished, failed close, pass a process-local offer to an identified
155
+ recipient. The recipient keeps the offer, calls `accept!` itself and assumes
156
+ responsibility for the exact transport. For example, a host may already have a
157
+ session administrator for one configured endpoint. The administrator's
158
+ `receipts` collection retains incoming offers before acceptance.
159
+
160
+ ```ruby
161
+ class SessionAdministrator
162
+ attr_reader :receipts
163
+
164
+ def initialize
165
+ @receipts = []
166
+ end
167
+
168
+ def accept_failed_transport(handle, generation)
169
+ offer = handle.offer_failed(generation, receiver: self)
170
+ receipts << offer
171
+ offer.accept!(receiver: self)
172
+ end
173
+ end
174
+ ```
175
+
176
+ Only a completed, failed close is eligible. Preparing an offer leaves the
177
+ Runtime's obligation intact. A matching acceptance removes that generation
178
+ from the Runtime and returns the original SDK transport, generation, errors,
179
+ origin and the HTTP session ID when observable immediately before close.
180
+ Repeated acceptance by the same recipient returns the same receipt. Keep these
181
+ process-local capabilities and session identifiers out of logs and persistent
182
+ error reports. Routine snapshots omit the session identifier, headers and URL
183
+ credentials. Use trusted endpoint configuration for any external reconciliation.
184
+
185
+ The adapter never issues a second SDK close against a failed generation. For
186
+ session-bearing HTTP, a Faraday response observer installed through the SDK's
187
+ HTTP constructor records the numeric result of the original DELETE when its
188
+ session ID matches. HTTP 200 and 204 acknowledge termination. HTTP 404 reports
189
+ the session already absent. These are server protocol statements. HTTP 202
190
+ accepts work for later completion, and 405 refuses client-initiated termination.
191
+ Either response, or a known session without a matching response, raises
192
+ `CleanupError` with the retained cause code `mcp.session_termination_unconfirmed`.
193
+ An SDK error such as HTTP 503 preserves its original exception. No additional
194
+ probe or DELETE is sent by the adapter. Routine snapshots record `http_status`,
195
+ with `nil` for missing observations, and the accepted recipient receives the
196
+ original session identifier even when the SDK already cleared its local copy.
197
+
198
+ For HTTP without an assigned session, the adapter relies on local SDK closure.
199
+ For stdio, a failed close can occur after partial pipe or process cleanup.
200
+ Resolving either kind of failure requires transport-specific evidence. An
201
+ accepted transfer records custody and leaves the actual cleanup to the
202
+ recipient. Neither cleanup nor transfer replays a Tool invocation.
203
+
204
+ An interrupt during an SDK handshake or close still reaches the calling thread.
205
+ The registry keeps the exact transport and the close error if the physical close
206
+ unwinds without confirming release. Management can then offer that finished
207
+ attempt to a receiver. The SDK constructors used here allocate a handle before
208
+ connecting. The allocation and local ownership update finish together before an
209
+ asynchronous interrupt is delivered, so the corresponding handshaking or
210
+ cleanup path can find the handle.
@@ -0,0 +1,89 @@
1
+ # Calling a declared Orchestrator subagent
2
+
3
+ A Tool generated by `Orchestrator.subagent` delegates through a reserved child
4
+ slot. The parent execution, slot and child identities let the Orchestrator
5
+ record the outcome, route an approval or recovery, and decide when the pair
6
+ can be unloaded. Call the Orchestrator normally to use this durable behavior,
7
+ including when you retain a native Tool under an alias with `with_tools`.
8
+
9
+ Standalone calls to the generated Tool previously created a registered child
10
+ and returned its output alone. A valid standalone `call`, `call_async` or
11
+ `execute` now raises `Phronomy::ToolError` (through the completion handle for
12
+ `call_async`) with code `multi_agent.subagent_dispatch_unowned` before
13
+ constructing a child. The child error policy `:skip` applies to the outcome of
14
+ an admitted child. Supplying an execution ID or Tool invocation ID to a bare
15
+ Tool cannot establish ownership.
16
+
17
+ ## Migrate a standalone call
18
+
19
+ Save the following common offline setup as `worker.rb` alongside either
20
+ program below. Run each program with `bundle exec ruby` in a project that
21
+ depends on Phronomy.
22
+
23
+ ```ruby
24
+ require "phronomy"
25
+
26
+ class ReviewAdapter < Phronomy::LLMAdapter::Base
27
+ def perform_complete(_request, cancellation_token:)
28
+ Phronomy::LLMAdapter::Response.new(content: "Reviewed")
29
+ end
30
+ end
31
+
32
+ class Reviewer < Phronomy::Agent::Base
33
+ agent_definition id: "review-worker", version: 1
34
+ model "offline"
35
+ end
36
+
37
+ class ReviewDesk < Phronomy::MultiAgent::Orchestrator
38
+ agent_definition id: "review-desk", version: 1
39
+ subagent :reviewer, Reviewer
40
+ end
41
+
42
+ Phronomy.configure { |config| config.llm_adapter = ReviewAdapter.new }
43
+ ```
44
+
45
+ The previous standalone program extracted the generated Tool. It printed
46
+ `Reviewed` and left the created Agent registered without giving the caller
47
+ its identity.
48
+
49
+ ```ruby
50
+ require_relative "worker"
51
+
52
+ dispatch = ReviewDesk.tools.fetch(0).new
53
+ puts dispatch.call({input: "Review the report"})
54
+ ```
55
+
56
+ For a standalone Tool that returns the worker's output, use
57
+ `Tools::Agent.from_agent`. It owns a fresh child, waits for eligible release,
58
+ and reports a release failure through `Tools::Agent::CleanupError`. The error
59
+ retains the child and its outcome for handling without repeating the work.
60
+
61
+ ```ruby
62
+ require_relative "worker"
63
+
64
+ standalone = Phronomy::Tools::Agent.from_agent(Reviewer, tool_name: "review_report")
65
+ puts standalone.new.call({input: "Review the report"})
66
+ ```
67
+
68
+ For a full execution result or inherited parent Knowledge, use the direct
69
+ Orchestrator helper. On success the result includes the child Agent ID and
70
+ execution ID. The caller owns the returned child and can reuse it or release
71
+ it explicitly. A failed cleanup raises an error that identifies the exact owners in
72
+ `Orchestrator::ChildCleanupError#failures`. Handle a pending approval or
73
+ recovery on its original execution before retrying an ineligible release.
74
+
75
+ ```ruby
76
+ require_relative "worker"
77
+
78
+ desk = ReviewDesk.create
79
+ result = desk.subagent(Reviewer, "Review the report")
80
+ reviewer = Reviewer.get(result.fetch(:agent_id))
81
+ puts result.fetch(:output)
82
+ reviewer.unload!
83
+ desk.unload!
84
+ ```
85
+
86
+ For parent-routed approval and restart, keep the registered declaration and
87
+ run the parent with its coordination Store. The host can resume the exact
88
+ stored execution and release the eligible pair. The complete hosted example
89
+ covers approval, import and release. [Hosted Orchestrator](../runtime-and-concurrency.md#hosting-an-orchestrator-through-a-child-approval)
@@ -74,9 +74,24 @@ end
74
74
 
75
75
  The result contains the `ruby` document. The application waits only outside
76
76
  worker callbacks; `flat_map` returns the next TaskResult without blocking a
77
- worker on another operation. `Tools::VectorSearch` continues to call synchronous
78
- `embed` and `search` inside its existing execution boundary, so this migration
79
- does not add nested offload work to that Tool.
77
+ worker on another operation.
78
+
79
+ `Tools::VectorSearch` runs both synchronous operations in one Tool execution.
80
+ When a caller supplies a cancellation token, the Tool checks it before
81
+ embedding and again before starting the search. It passes the same object to
82
+ `embeddings.embed(query, token)` and
83
+ `store.search(query_embedding: vector, k: limit, cancellation_token: token)`.
84
+ For example, if cancellation arrives while an embedding provider computes a
85
+ vector, the Tool raises `CancellationError` at the next checkpoint and skips
86
+ the store. A call already inside a provider or store depends on that adapter's
87
+ cooperation. The Tool never retries a stage.
88
+
89
+ Older adapters can implement `embed(query)` or `search(query_embedding:, k:)`.
90
+ Each stage receives the token only if its method accepts the corresponding
91
+ argument: a second positional argument (including `*args`) for embedding, or a
92
+ `cancellation_token:` keyword (including `**kwargs`) for search. The Tool still
93
+ checks cancellation before entering a legacy method. When the caller omits
94
+ the token, the Tool omits both token arguments.
80
95
 
81
96
  ## Execution and cancellation
82
97
 
@@ -374,9 +374,10 @@ Caller mutation of a loaded snapshot must not mutate durable storage.
374
374
 
375
375
  ### Workflow Runtime admission and terminal-save outcome
376
376
 
377
- Same-process Workflow admission is owned by Runtime/EventLoop, not by this
378
- repository. EventLoop acquires an opaque owner token for `workflow_instance_id`
379
- before mutable durable load/hydration, then binds a separately generated
377
+ Same-process Workflow admission is held by Workflow's registry on Runtime's
378
+ serial EventLoop, not by this repository. The registry acquires an opaque owner
379
+ token for `workflow_instance_id` before mutable durable load/hydration, then binds
380
+ a separately generated
380
381
  `fsm_session_id` only after the concrete FSMSession is constructed.
381
382
 
382
383
  A durable Workflow terminal/halt snapshot is saved through OffloadPool while the
@@ -394,7 +395,7 @@ portable known failure / known not committed
394
395
  -> barrier remains closed; Workflow error path
395
396
 
396
397
  arbitrary storage/transport failure whose commit outcome is not established
397
- -> outcome unknown; barrier remains closed and Runtime fails closed
398
+ -> outcome unknown; retire the session and retain Workflow responsibility
398
399
  ```
399
400
 
400
401
  This distinction is independent of physical topology. A local backend can have
@@ -403,6 +404,31 @@ conflict. Backends must therefore preserve meaningful portable errors when the
403
404
  contract establishes them, and must surface other storage/transport failures
404
405
  honestly rather than converting them into `ConflictError`.
405
406
 
407
+ An unresolved terminal save now produces `WorkflowTerminalRecoveryError` after
408
+ the Workflow owner retains its evidence and completion custody. The original
409
+ observation fails; it is not a failed business result or permission to release
410
+ the unresolved owner. `pending_terminal_recovery` can recover the local reference
411
+ if the initial observer was cancelled or its error was dropped.
412
+
413
+ Explicit `reconcile_terminal_async` / `reconcile_terminal` operations inspect
414
+ that exact retained operation through the original running or draining Runtime.
415
+ Unknown persistence is compared with the exact expected pre-revision and intended
416
+ post-revision/snapshot after the original save's physical boundary. Reconciliation
417
+ does not repeat `save`, resume graph actions or alter this repository SPI. Its
418
+ result separates persistence confirmation, owner application and ownership
419
+ release. Confirmed facts are retained if later application or context construction
420
+ fails.
421
+
422
+ Unresolved obligations prevent complete shutdown cleanup and remain retained
423
+ after the dispatcher stops. This profile does not transfer custody to a stopped
424
+ owner's replacement or provide process-crash recovery. See the implemented
425
+ [Workflow terminal reconciliation contract](architecture/workflow-terminal-reconciliation.md)
426
+ for local capability lifetime, independent observations and supported recovery
427
+ conditions. The earlier
428
+ [terminal ownership design](architecture/workflow-terminal-ownership-design.md)
429
+ is a historical refactoring record, including its superseded uncertainty and
430
+ shutdown behavior.
431
+
406
432
  ### Workflow value serialization
407
433
 
408
434
  The Workflow domain codec accepts canonical JSON-compatible snapshot values in