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,205 @@
1
+ # Handoff dispatch recovery and exact turn continuation
2
+
3
+ Handoff owns the route between Agent executions. Agent owns the retained save that permits its next Provider or Tool dispatch. This change connects Handoff routing evidence to the existing Agent recovery owner and lets the application continue the same saved Handoff chain after that Agent observation settles.
4
+
5
+ For example, a case Source performs one lookup, then loses the response to the save preceding its next Provider call. Reconciliation confirms the captured save, or the caller explicitly retries a confirmed pre-state. The Source then finishes directly or transfers responsibility to the exact reserved Target. The Runner follows that same case to its saved result without issuing the lookup again.
6
+
7
+ Baseline: `5bfc188ed7516a7464242668fa38abfecb366427`. The candidate uses the same common `RetainedAttempts` and `AttemptCompletion` through the existing Agent dispatch owner. Contract concept version 55 and foundation version 48 keep MultiAgent routing authority separate from Agent execution evidence and common attempt mechanics. No new mutex, executor or generic recovery coordinator is introduced.
8
+
9
+ ## Behavioral scope of the comparison
10
+
11
+ The application supplies the graph, configuration and explicit save-retry policy. The framework supplies exact execution identity, captured persistence proof, retained observation and route continuation. The ordinary success path is equivalent within this application; recovery from the diagnosed uncertain barrier intentionally changes behavior.
12
+
13
+ For example, both ordinary versions below run one lookup and complete the case with two Provider calls, or three when the Source transfers to the Target. On the old uncertain-save path, the original owner can remain held without a public dispatch recovery capability. A second `invoke` after completion creates a new turn, so it is not a general recovery operation.
14
+
15
+ | Boundary | Applied baseline | Candidate |
16
+ | --- | --- | --- |
17
+ | Ordinary Source and Target execution | Existing `invoke` path | Same input, business calls, normal result and error policy |
18
+ | Captured follow-up Provider or Tool save becomes uncertain | Handoff does not supply retained dispatch evidence | Original call raises `Agent::DispatchRecoveryError`; the original Agent retains the capability |
19
+ | Proven pre-state | No Handoff retained dispatch retry route | Application may choose the existing `retry_dispatch`; no implicit write |
20
+ | Proven post-state | No Handoff retained continuation route | Existing Agent owner grants the captured continuation once under current authority |
21
+ | Continue the Handoff chain | `invoke` may start another turn | `resume(execution_id, config: {})` follows only the requested chain |
22
+ | Initial preparation before the ordinary dispatch owner | Separate initial-owner boundary | Remains U-04; this adapter does not repair that path |
23
+
24
+ ## Shared application setup
25
+
26
+ The application keeps the live graph and its Store together while any Agent or route responsibility remains unresolved. A completed application's history-removal policy is separate from its success result.
27
+
28
+ For example, the following case session contains one Source, one Target, their edge and a job cancellation token. The in-memory Store is an executable example configuration, not a persistence recommendation. The close function deliberately forgets completed history before unloading the graph; the caller invokes it only after the saved chain is complete and history is no longer needed.
29
+
30
+ <pre id="handoff-case-shared_setup"><code># frozen_string_literal: true
31
+
32
+ require &quot;phronomy&quot;
33
+
34
+ class HandoffCaseLookup &lt; Phronomy::Tool::Base
35
+ tool_name &quot;handoff_case_lookup&quot;
36
+ description &quot;Read the facts for one case&quot;
37
+ execution_mode :cooperative
38
+ param :case_id, type: :string, desc: &quot;Case identity&quot;
39
+
40
+ def execute(case_id:)
41
+ &quot;Facts for #{case_id}&quot;
42
+ end
43
+ end
44
+
45
+ class HandoffCaseSource &lt; Phronomy::Agent::Base
46
+ agent_definition id: &quot;handoff-case-source&quot;, version: 1
47
+ model &quot;gpt-4o-mini&quot;
48
+ provider :openai
49
+ tools HandoffCaseLookup =&gt; nil
50
+ end
51
+
52
+ class HandoffCaseTarget &lt; Phronomy::Agent::Base
53
+ agent_definition id: &quot;handoff-case-target&quot;, version: 1
54
+ model &quot;gpt-4o-mini&quot;
55
+ provider :openai
56
+ end
57
+
58
+ def open_handoff_case
59
+ stores = Phronomy::PersistenceComposition.in_memory
60
+ source = HandoffCaseSource.create(persistence: stores.agent)
61
+ target = HandoffCaseTarget.create(persistence: stores.agent)
62
+ edge = Phronomy::MultiAgent::Handoff.new(source_agent: source, target_agent: target)
63
+ runner = Phronomy::MultiAgent::HandoffRunner.new(main_agent: source,
64
+ persistence: stores.multi_agent, handoffs: [edge])
65
+ {stores: stores, source: source, target: target, edge: edge, runner: runner,
66
+ agents: [source, target].to_h { |agent| [agent.agent_id, agent] },
67
+ config: {cancellation_token: Phronomy::Concurrency::CancellationToken.new}}
68
+ end
69
+
70
+ # The caller chooses when completed history may be forgotten. Never call this
71
+ # while a save, Agent execution or Handoff target remains unresolved.
72
+ def close_completed_handoff_case(session)
73
+ session.fetch(:runner).forget_history!
74
+ session.fetch(:source).unload!
75
+ session.fetch(:target).unload!
76
+ end
77
+ </code></pre>
78
+
79
+ The example model name and provider are configured application inputs. Acceptance replaces the Provider HTTP response with the existing offline LLM test adapter; no live Provider result is claimed.
80
+
81
+ ## Complete normal application before and after
82
+
83
+ Normal turn entry remains the application's existing Runner invocation. No recovery bookkeeping is required when the save and its observation succeed.
84
+
85
+ For example, the same session and `"case-42"` input below produce `"case-42 completed"` in the offline acceptance fixture. These complete functions are byte-identical and are executed against the exact applied baseline and candidate.
86
+
87
+ <table><thead><tr><th>Applied baseline</th><th>U-03 candidate</th></tr></thead><tbody><tr><td><pre id="handoff-case-normal_before"><code># frozen_string_literal: true
88
+
89
+ def run_handoff_case(session, input)
90
+ session.fetch(:runner).invoke(input, config: session.fetch(:config))
91
+ end
92
+ </code></pre></td><td><pre id="handoff-case-normal_after"><code># frozen_string_literal: true
93
+
94
+ def run_handoff_case(session, input)
95
+ session.fetch(:runner).invoke(input, config: session.fetch(:config))
96
+ end
97
+ </code></pre></td></tr></tbody></table>
98
+
99
+ ## Complete recovery application before and after
100
+
101
+ Recovery adds a separate observation and an explicit policy choice for the same captured save. A resolved Agent receipt permits waiting for that Agent's continuation; completing the Handoff chain still requires the Runner's exact-turn operation.
102
+
103
+ For example, the default policy below keeps a confirmed pre-state pending. Setting `retry_confirmed_pre: true` authorizes one captured-write retry. The helper then waits for the retained Agent execution and resumes its exact chain. It never calls `invoke` to recover an already started turn.
104
+
105
+ The baseline wrapper is an adaptation using only existing public APIs; it has no recovery mechanism. The candidate's recovery behavior is an intentional fix, not an equivalence claim under the injected fault. The complete normal path above remains the equivalence comparison.
106
+
107
+ <table><thead><tr><th>Applied baseline</th><th>U-03 candidate</th></tr></thead><tbody><tr><td><pre id="handoff-case-recovery_before"><code># frozen_string_literal: true
108
+
109
+ # Baseline application: the original call owns the only observation here.
110
+ # No retained Handoff dispatch recovery or exact-chain resume is available.
111
+ def start_handoff_case(session, input)
112
+ {state: :completed, result: run_handoff_case(session, input)}
113
+ end
114
+ </code></pre></td><td><pre id="handoff-case-recovery_after"><code># frozen_string_literal: true
115
+
116
+ def start_handoff_case(session, input, retry_confirmed_pre: false, wait_timeout: nil)
117
+ {state: :completed, result: run_handoff_case(session, input)}
118
+ rescue Phronomy::Agent::DispatchRecoveryError =&gt; failure
119
+ recover_handoff_case(session, failure.recovery,
120
+ retry_confirmed_pre: retry_confirmed_pre, wait_timeout: wait_timeout)
121
+ end
122
+
123
+ # Reconciliation reads. Only this explicit application policy authorizes one
124
+ # captured-write retry after the saved pre-state has been confirmed.
125
+ def recover_handoff_case(session, recovery, retry_confirmed_pre: false, wait_timeout: nil)
126
+ agent = session.fetch(:agents).fetch(recovery.agent_id)
127
+ receipt = agent.reconcile_dispatch(recovery: recovery)
128
+ if receipt.outcome == :confirmed_pre &amp;&amp; retry_confirmed_pre
129
+ receipt = agent.retry_dispatch(recovery: recovery)
130
+ end
131
+ pending = {state: :recovery_pending, recovery: recovery, receipt: receipt}
132
+ return pending unless receipt.resolved?
133
+ finish_handoff_case(session, pending, wait_timeout: wait_timeout)
134
+ end
135
+
136
+ # A waiter timeout leaves the receipt and execution observation available.
137
+ # This timeout bounds only this Task wait, not synchronous Runner operations.
138
+ def finish_handoff_case(session, pending, wait_timeout: nil)
139
+ receipt = pending.fetch(:receipt)
140
+ begin
141
+ receipt.execution_task.wait_result(timeout: wait_timeout)
142
+ rescue Phronomy::TimeoutError =&gt; error
143
+ # A saved Task failure is not a waiter-local timeout.
144
+ raise if receipt.execution_task.done?
145
+ return pending.merge(state: :execution_observation_pending, error: error)
146
+ end
147
+ result = session.fetch(:runner).resume(pending.fetch(:recovery).execution_id,
148
+ config: session.fetch(:config))
149
+ {state: :completed, result: result}
150
+ end
151
+ </code></pre></td></tr></tbody></table>
152
+
153
+ The caller retains `session` and any returned `recovery` and `receipt`. A `recovery_pending` value preserves unavailable, conflicting or confirmed-pre evidence without dispatching. An `execution_observation_pending` value preserves the receipt after a waiter-local timeout; call `finish_handoff_case` again with that value to continue observing it. `wait_timeout` bounds only the execution Task wait, not synchronous reconciliation or Runner calls. A concurrent completion may cause the timeout to propagate instead of returning a pending value; it never converts a saved task failure into success.
154
+
155
+ The helpers handle one retained obligation at a time. If continued business work produces another `DispatchRecoveryError`, the new error and capability propagate to the caller for another explicit policy decision. Other admission, authority, saved execution and observation errors also propagate. The helper does not hide them, change the original failed observation, create a retry loop or unload unresolved work.
156
+
157
+ ## Public continuation and ownership contract
158
+
159
+ The Runner's exact-turn operation observes historical completion independently of current routing, and checks current routing before granting new work. Agent save recovery and Handoff continuation remain separately observable responsibilities.
160
+
161
+ For example, yesterday's case can be resumed to read its saved Target result after today's case begins on the same Agent. An unfinished historical case cannot borrow today's active Agent identity to start or resume today's work.
162
+
163
+ | Operation or condition | Defined behavior |
164
+ | --- | --- |
165
+ | `invoke(input, config: {})` | Existing normal turn entry; no implicit dispatch retry is added |
166
+ | `resume(execution_id, config: {})` | Synchronous continuation of one exact retained chain; positional ID matches Agent/Team resume and Runner cancel/result |
167
+ | Returned value from `resume` | Durable leaf fields `execution_id`, `agent_id`, `status`, `result`, `output`, `raw_output`, `error`, plus the graph's `agent` object |
168
+ | Live `invoke` value | Existing shape is preserved; transient invocation-only fields are not reconstructed by `resume` |
169
+ | Saved failed or cancelled leaf | Existing Runner `value!` error semantics apply; saved failure does not become successful output |
170
+ | Missing or unrelated identity | Existing not-found, configuration or state-conflict errors; no alternate turn is chosen |
171
+ | Pending dispatch capability on `resume` | `ExecutionRehydrationRequiredError` identifies Agent, execution and recovery, with `pending_dispatch_recovery` guidance; it does not wait on the unresolved ordinary Agent path |
172
+ | Original uncertain `invoke` | Existing typed `Agent::DispatchRecoveryError` supplies the retained capability directly |
173
+ | Absent Target | Requires exact pending Source/Target receipt, configured edge, Target definition and context, retained ownership and cancellation authority before the existing reserved admission |
174
+ | Active leaf | Requires its exact execution reservation and the current route; matching Agent ID alone is insufficient |
175
+ | Historical terminal leaf | Saved outcome without new business work. An exact current pending failed/cancelled/blocked Target now performs [separate parent finalization](handoff-initial-terminal-application.md) before delivering its failure; unrelated older terminal history remains read-only. `result` never finalizes routing. |
176
+ | Handoff count | Existing `MAX_HANDOFFS` bounds newly driven handoffs in one continuation segment; historical chain traversal is read-only and cycle checked |
177
+ | Runtime and live graph | Existing Runtime ownership and Agent lifetime restrictions remain; no stopped-owner takeover is supplied |
178
+
179
+ Agent `resume` returns an exact execution observation, including saved failures as values. Handoff Runner already applies `value!` to its business result, so the Runner continuation preserves that domain policy. This is an existing responsibility difference, not a reason to add another generic facade. A keyword-only execution ID, implicit retry-on-`invoke`, a second Handoff recovery capability and a separate asynchronous Runner protocol were considered and not adopted.
180
+
181
+ ## Save proof, authority and cancellation
182
+
183
+ Captured persistence proof establishes what the original save did. Current Handoff authority establishes whether its still-unused continuation is permitted now. Both are required, and a historical post-state never replaces a fresh authority check.
184
+
185
+ For example, a cached post-state can survive a failed continuation notification. If routing changes or a required Source hold disappears before re-observation, the save remains historically confirmed but no new Provider call is authorized.
186
+
187
+ The MultiAgent evidence adapter captures immutable routing and retained-reference facts, requires unchanged participant pre/post footprints for ordinary dispatch, and replays no routing operation. The Agent layer compares the complete Agent footprint and repeats only its captured save from a confirmed pre-state. No participant callback, Policy, transformation, encoding, Provider, Tool or Source transfer is replayed to discover a save result.
188
+
189
+ Handoff routing guards precede ordered Agent guards, consistently with existing admission and cancellation. The supported live-owner protocol requires authority stability between the guarded storage check and later EventLoop continuation admission. The finite model includes a missing-stability-premise counterexample; this implementation does not claim that a released transaction lock fences arbitrary out-of-band changes.
190
+
191
+ Runner selection checks the complete chain and routing facts before choosing a Target. Later, `ReservedChildAdmission` rechecks its actual subset: the active Agent, cancellation and, only when routing is not stable, the exact pending Target identity. It does not repeat the complete selection proof or make that selection a future admission fence. Authority stability is also required across this selection-to-admission interval. The finite model bounds its reserved-Target state to non-stable routing; it does not enumerate routing phase drift across that interval or prove an unconditional pending-identity check in every phase.
192
+
193
+ Cancelling a recovery observation ends that observation only; another observer can still receive the same physical read's result. The Runner's `config[:cancellation_token]` and `cancel(execution_id)` concern the job itself. They are not observer-only cancellation switches. A logical timeout or lost notification is not evidence that a physical worker ended, a save rolled back, or an external call did not happen.
194
+
195
+ ## Acceptance evidence and limits
196
+
197
+ Acceptance joins the existing Agent save protocol to actual Handoff progression and verifies the observable business calls and exact identities. The model checks the selected abstract obligations; executable Runtime cases check the implementation path.
198
+
199
+ For example, the application matrix injects rollback or committed-response loss after a Source Tool effect, makes the immediate readback unavailable, then recovers the save and follows either direct completion or transfer. Both paths keep the lookup effect at one. A separate Target case confirms that a transferred Target's next save recovers without a second Target admission.
200
+
201
+ The new real-Runtime application spec covers Provider/Tool barriers, pre/post recovery, direct/transfer outcomes, unavailable reads, cached routing and hold changes, job cancellation, independent observer cancellation during a slow read, refused continuation delivery, pending exact-resume refusal, and transferred Target authority. Original failures remain closed; post-state confirmation is separate from continuation availability. The exact assembled examples are exercised independently of this spec, including the default hold policy and waiter timeout.
202
+
203
+ The bounded model is documented in [Handoff dispatch recovery](../../spec/models/handoff_dispatch_recovery/README.md). It represents the retained Agent owner, exact-chain Runner and recovery observers separately. Existing generic dispatch/custody models remain separate evidence; this is not a full product or a Ruby refinement proof. The full delivery report records exact counts, source hashes and fresh versus reused evidence.
204
+
205
+ U-04 initial preparation, U-05 incomplete proposal preparation, U-06 arbitrary synchronous participant conformance, stopped Runtime administration, live LLM behavior and production backend matrices remain separately scoped. No capability is inferred from these offline cases for an unsupported participant or lost process-local owner.
@@ -0,0 +1,321 @@
1
+ # Handoff initial terminal finalization in a complete application
2
+
3
+ Handoff owns the routing obligation between Agents; each Agent owns its execution and original local work. An unsuccessful initial Target can therefore have a durable result while its parent still needs a separate routing transition. Existing Runner progress operations now finish that transition after both exact Agents have released local mutation custody and the current durable chain still authorizes it.
4
+
5
+ For case-42, Intake transfers responsibility to Review. Review rejects the input before calling its Provider. The saved failure remains a failure. The Runner makes the current route stable, allowing the application to inspect the outcome, decide whether to keep history, and explicitly release completed history and unload the Agents.
6
+
7
+ ## Behavioral contract
8
+
9
+ The comparison keeps application policy and execution semantics visible. Normal execution has equivalent inputs, output, ordering, session ownership, cancellation token, and explicit cleanup. The failure path intentionally gains parent completion and additional diagnostic handling; this is not an application line-count reduction.
10
+
11
+ For the successful case-42, both complete normal functions return the Review output after two offline Provider responses. For rejected case-42, Before raises the saved error but leaves routing unfinished; After raises the same saved error after routing completion, or exposes a separate unconfirmed-finalization diagnostic.
12
+
13
+ | Situation | Before at ae9fafde | After |
14
+ | --- | --- | --- |
15
+ | Ordinary transfer succeeds | Saved success, stable route | Same success and stable route |
16
+ | Initial Target fails, blocks, or is cancelled | Saved outcome; parent may remain pending | Same outcome; explicit progress finalizes the exact current parent |
17
+ | Reading result | Reads saved outcome | Reads saved outcome, without writes |
18
+ | Initial Agent custody is retained | Explicit U04 reconciliation is required | Same requirement before parent progress |
19
+ | Parent finalization reply is lost | No parent-finalization operation | Confirmed post-state is adopted; otherwise explicit diagnostic and later progress |
20
+ | History removal | Explicit and only after completion | Same policy; no automatic deletion |
21
+ | Unload fails after history removal | Application retains cleanup progress | Same retained flag prevents repeating successful history removal |
22
+
23
+ The Before application is an adaptation of existing APIs, executed against applied commit `ae9fafdebcdaaf954c9a3a80aab5221891ff0e31`. It contains no baseline implementation of the missing finalizer. The After application is exercised through the actual Runtime by `spec/phronomy/multi_agent/handoff_initial_terminal_application_spec.rb`. Both use the complete fixture below; no external model service is contacted.
24
+
25
+ ## Shared session and initial recovery
26
+
27
+ The application owns one serialized session, its cancellation token, original recovery capabilities, and explicit cleanup progress. An observer timeout keeps the same task available; it does not authorize a second write or cancel the underlying work. Initial recovery and parent finalization remain separate decisions.
28
+
29
+ If Review's D2 failure save commits but its response is lost, the application discovers its original capability even when the saved failure is already readable. It reconciles that capability, waits for the fresh exact execution observation, and only then explicitly resumes the same Runner entry. The helper's execution-observation example is scoped to this saved D2 case. Other execution-observation errors propagate with the retained session and receipt.
30
+
31
+ The complete setup appears once and is shared by both columns. Agent definitions use unique IDs so this fixture can run beside the earlier initial-preparation example.
32
+
33
+ ```ruby
34
+ # frozen_string_literal: true
35
+
36
+ require "phronomy"
37
+
38
+ module HandoffTerminalApplication
39
+ class IntakeAgent < Phronomy::Agent::Base
40
+ agent_definition id: "handoff-initial-terminal-intake-example", version: 1
41
+ model "gpt-4o-mini"
42
+ provider :openai
43
+ end
44
+
45
+ class ReviewAgent < Phronomy::Agent::Base
46
+ agent_definition id: "handoff-initial-terminal-review-example", version: 1
47
+ model "gpt-4o-mini"
48
+ provider :openai
49
+ end
50
+
51
+ def self.open_session(handoff: false)
52
+ stores = Phronomy::PersistenceComposition.in_memory
53
+ source = IntakeAgent.create(persistence: stores.agent)
54
+ target = handoff ? ReviewAgent.create(persistence: stores.agent) : nil
55
+ edge = if target
56
+ Phronomy::MultiAgent::Handoff.new(source_agent: source, target_agent: target)
57
+ end
58
+ runner = if edge
59
+ Phronomy::MultiAgent::HandoffRunner.new(main_agent: source,
60
+ persistence: stores.multi_agent, handoffs: [edge])
61
+ end
62
+ {stores: stores, source: source, target: target, edge: edge, runner: runner,
63
+ agents: [source, target].compact.to_h { |agent| [agent.agent_id, agent] },
64
+ config: {cancellation_token: Phronomy::Concurrency::CancellationToken.new},
65
+ history_released: false}
66
+ end
67
+
68
+ # The application decides when terminal history is no longer needed.
69
+ # Never unload a session while its preparation or execution is unresolved.
70
+ def self.close_completed_session(session)
71
+ unless session[:history_released]
72
+ session.fetch(:runner)&.forget_history!
73
+ session[:history_released] = true
74
+ end
75
+ session.fetch(:target)&.unload!
76
+ session.fetch(:source).unload!
77
+ end
78
+ end
79
+
80
+ module HandoffTerminalApplication
81
+ def self.pending_initial(session)
82
+ pending = session.fetch(:agents).values.filter_map(&:pending_initial_preparation_recovery)
83
+ raise Phronomy::Error, "Select one initial obligation explicitly" if pending.size > 1
84
+ pending.first
85
+ end
86
+
87
+ # U04 is already present in Before. These helpers do not retry captured writes.
88
+ def self.begin_initial_recovery(session, pending)
89
+ capability = pending.fetch(:recovery)
90
+ task = session.fetch(:agents).fetch(capability.agent_id)
91
+ .reconcile_initial_preparation_async(recovery: capability)
92
+ pending.merge(state: :initial_waiting, task: task)
93
+ end
94
+
95
+ def self.wait_initial_recovery(pending, timeout: nil)
96
+ task = pending.fetch(:task)
97
+ receipt = task.wait_result(timeout: timeout)
98
+ pending.merge(state: receipt.resolved? ? :initial_applied : :initial_pending, receipt: receipt, wait_error: nil)
99
+ rescue Phronomy::TimeoutError => error
100
+ raise if task.done?
101
+ pending.merge(state: :initial_waiting, wait_error: error)
102
+ end
103
+
104
+ # This example's recovery case is a saved D2 failure. A different execution
105
+ # observation error still propagates; the caller keeps the session and receipt.
106
+ def self.wait_initial_execution(pending, timeout: nil)
107
+ receipt = pending.fetch(:receipt)
108
+ raise ArgumentError, "Initial custody is still pending" unless receipt.resolved?
109
+ task = receipt.execution_task
110
+ result = task.wait_result(timeout: timeout)
111
+ pending.merge(state: :initial_settled, execution_result: result, wait_error: nil)
112
+ rescue Phronomy::TimeoutError => error
113
+ raise if task.done?
114
+ pending.merge(state: :initial_execution_waiting, wait_error: error)
115
+ end
116
+ end
117
+ ```
118
+
119
+ ## Complete normal source comparison
120
+
121
+ The normal call passes the same input and control token to the same session owner. The application marks history as retained for the new turn and receives the existing Runner result.
122
+
123
+ For accepted case-42, the following two functions execute the same Intake-to-Review transfer and return `case-42 reviewed`.
124
+
125
+ <table>
126
+ <tr><th>Before: applied U04</th><th>After: this change</th></tr>
127
+ <tr><td><pre><code>module HandoffTerminalApplication
128
+ module Before
129
+ def self.run(session, input)
130
+ session[:history_released] = false
131
+ session.fetch(:runner).invoke(input, config: session.fetch(:config))
132
+ end
133
+ end
134
+ end
135
+ </code></pre></td><td><pre><code>module HandoffTerminalApplication
136
+ module After
137
+ def self.run(session, input)
138
+ session[:history_released] = false
139
+ session.fetch(:runner).invoke(input, config: session.fetch(:config))
140
+ end
141
+ end
142
+ end
143
+ </code></pre></td></tr>
144
+ </table>
145
+
146
+ ## Complete recovery source comparison
147
+
148
+ The application distinguishes a saved business error from an unconfirmed parent transition, retaining the identities and evidence needed for a later explicit decision. Initial custody takes precedence over parent progress. The added diagnostic branches preserve both errors rather than substituting a successful job result.
149
+
150
+ For rejected case-42 with a rolled-back routing save, After returns `routing_pending` with the exact requested entry, terminal Target ID, immutable saved result, original execution error, finalization error, optional read error, and disposition. A later call to the complete `resume` function is an explicit new routing-only attempt. Before has no equivalent parent-finalization diagnostic because that operation did not exist.
151
+
152
+ <table>
153
+ <tr><th>Before: applied U04</th><th>After: this change</th></tr>
154
+ <tr><td><pre><code>module HandoffTerminalApplication
155
+ module Before
156
+ def self.start(session, input)
157
+ {state: :observed, execution_result: run(session, input)}
158
+ rescue =&gt; error
159
+ capture_error(session, error)
160
+ end
161
+
162
+ def self.resume(session, execution_id)
163
+ result = session.fetch(:runner).resume(execution_id, config: session.fetch(:config))
164
+ {state: :observed, execution_id: execution_id, execution_result: result}
165
+ rescue =&gt; error
166
+ capture_error(session, error, execution_id: execution_id)
167
+ end
168
+
169
+ def self.capture_error(session, error, execution_id: nil)
170
+ capability = HandoffTerminalApplication.pending_initial(session)
171
+ if capability
172
+ {state: :initial_pending, recovery: capability, error: error,
173
+ execution_id: execution_id || capability.execution_id}
174
+ else
175
+ {state: :operation_error, execution_id: execution_id, error: error}
176
+ end
177
+ end
178
+ end
179
+ end
180
+ </code></pre></td><td><pre><code>module HandoffTerminalApplication
181
+ module After
182
+ def self.start(session, input)
183
+ {state: :observed, execution_result: run(session, input)}
184
+ rescue =&gt; error
185
+ capture_error(session, error)
186
+ end
187
+
188
+ def self.resume(session, execution_id)
189
+ result = session.fetch(:runner).resume(execution_id, config: session.fetch(:config))
190
+ {state: :observed, execution_id: execution_id, execution_result: result}
191
+ rescue =&gt; error
192
+ capture_error(session, error, execution_id: execution_id)
193
+ end
194
+
195
+ def self.capture_error(session, error, execution_id: nil)
196
+ capability = HandoffTerminalApplication.pending_initial(session)
197
+ finalization = error.is_a?(Phronomy::MultiAgent::HandoffFinalizationError)
198
+ entry_id = finalization ? error.execution_id : execution_id
199
+ if capability
200
+ return {state: :initial_pending, recovery: capability, error: error,
201
+ execution_id: entry_id || capability.execution_id}
202
+ end
203
+ if finalization
204
+ return {state: :routing_pending, execution_id: error.execution_id,
205
+ target_execution_id: error.target_execution_id,
206
+ main_agent_id: error.main_agent_id, execution_result: error.execution_result,
207
+ execution_error: error.execution_error, finalization_error: error.finalization_error,
208
+ read_error: error.read_error, disposition: error.disposition, error: error}
209
+ end
210
+ # A saved business failure remains an error, never a successful job.
211
+ {state: :operation_error, execution_id: entry_id, error: error}
212
+ end
213
+ end
214
+ end
215
+ </code></pre></td></tr>
216
+ </table>
217
+
218
+ ## Complete driver and offline dependency
219
+
220
+ The driver keeps the session reachable on errors and makes cleanup an explicit application action. Its deterministic Provider fixture supplies exactly the transfer and final output required by the example, so a replay is observable instead of silently obtaining another response.
221
+
222
+ Calling the fixture with `version: :after, reject: true` drives the exact rejected responsibility; `reject: false` drives the ordinary successful transfer. Cleanup returns `cleanup_pending` with the same session when either history removal or unloading fails. Once history removal has succeeded, a later cleanup attempt skips that completed step.
223
+
224
+ The driver is part of `spec/fixtures/handoff_initial_terminal/application.rb`; the following dependency is the entire `offline_fixture.rb` beside it. The fixture requires that complete application file. RSpec supplies only assertions and fault injection in the acceptance suite.
225
+
226
+ ```ruby
227
+ module HandoffTerminalApplication
228
+ # The caller serializes the session and explicitly selects further actions.
229
+ def self.run_example(input, version: :after, session: nil)
230
+ application = case version
231
+ when :before then Before
232
+ when :after then After
233
+ else raise ArgumentError, "version must be before or after"
234
+ end
235
+ session ||= open_session(handoff: true)
236
+ {session: session, application: application, observation: application.start(session, input)}
237
+ rescue => error
238
+ raise unless session
239
+ {session: session, application: application, observation: {state: :operation_error, error: error}}
240
+ end
241
+
242
+ # No ensure block deletes history. A cleanup error keeps the same session.
243
+ def self.close_example(work)
244
+ close_completed_session(work.fetch(:session))
245
+ work.merge(observation: {state: :closed})
246
+ rescue => error
247
+ work.merge(observation: {state: :cleanup_pending, error: error})
248
+ end
249
+ end
250
+ ```
251
+ ```ruby
252
+ # frozen_string_literal: true
253
+
254
+ require_relative "application"
255
+
256
+ module HandoffTerminalApplication
257
+ module OfflineFixture
258
+ class RejectedResponsibility < Phronomy::Filter::Base
259
+ def call(value, **_context)
260
+ raise ArgumentError, "Review rejected case-42" if value == "reject case-42"
261
+ value
262
+ end
263
+ end
264
+ ReviewAgent.input_filter RejectedResponsibility
265
+
266
+ class Adapter < Phronomy::LLMAdapter::Base
267
+ attr_reader :requests
268
+
269
+ def initialize(tool_name: nil, responsibility: nil, responses: nil)
270
+ @requests = []
271
+ @responses = responses || [
272
+ Phronomy::LLMAdapter::Response.new(finish_reason: :tool_calls, tool_calls: [
273
+ Phronomy::Tool::CallRequest.new(id: "delegate-case-42", name: tool_name,
274
+ arguments: {"responsibility" => responsibility})
275
+ ]),
276
+ Phronomy::LLMAdapter::Response.new(content: "case-42 reviewed", finish_reason: :stop)
277
+ ]
278
+ end
279
+
280
+ protected
281
+
282
+ def perform_complete(request, cancellation_token:)
283
+ @requests << request
284
+ @responses.shift || raise("unexpected Provider replay")
285
+ end
286
+ end
287
+
288
+ # This complete fixture supplies deterministic Provider responses. It never
289
+ # constructs an HTTP client or sends the model declaration to a live service.
290
+ def self.run(version:, reject:)
291
+ session = HandoffTerminalApplication.open_session(handoff: true)
292
+ binding = Phronomy::MultiAgent::HandoffCapabilityFactory.build(session.fetch(:edge))
293
+ adapter = Adapter.new(tool_name: binding.tool_name,
294
+ responsibility: reject ? "reject case-42" : "review case-42")
295
+ Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
296
+ work = HandoffTerminalApplication.run_example("case-42", version: version, session: session)
297
+ {work: work, adapter: adapter}
298
+ end
299
+ end
300
+ end
301
+ ```
302
+
303
+ ## Acceptance and scope
304
+
305
+ The application checks exercise live Runtime behavior with deterministic local Provider responses and real in-memory transactions. Domain proof and registry unit checks cover additional invalid-authority and unavailable-query branches; the bounded model is a separate verification layer, not a substitute for Runtime evidence.
306
+
307
+ For example, the acceptance suite blocks Target preparation physically while a concurrent cancellation returns, confirms that cleanup stays blocked, then releases that work and explicitly resolves initial custody when exposed. It also drives a normal two-transfer chain and verifies that the older Sources have released admission before the last Target fails.
308
+
309
+ | Boundary | Application evidence |
310
+ | --- | --- |
311
+ | Normal success and next turn | Complete Before/After functions, same output, explicit cleanup, new active-Target turn |
312
+ | Initial unsuccessful result | Filter, hook, Policy, cancelled, and blocked outcomes preserved; no Target Provider call or callback replay |
313
+ | Routing uncertainty | Pre-save rollback, post-commit response loss, unavailable confirmation read, explicit invoke/resume/cancel |
314
+ | Initial uncertainty and observation | D2 post-save custody, read-only result, explicit reconciliation, same-task observer timeout |
315
+ | Identity and concurrency | Changed authority after custody observation, stale old chain versus new pending chain, concurrent finalizers with one effective revision |
316
+ | Lifetime | Physically blocked preparation and concurrent cancel, retryable cleanup, explicit forget followed by a new main-Agent job |
317
+ | Normal multi-hop history | Older Sources released in the normally driven chain; explicit cleanup succeeds |
318
+
319
+ No helper retries automatically. `result` does not finalize; `forget_history!` does not repair pending routing. A saved failed, cancelled, or blocked Target does not become successful after cleanup. A later genuinely new job uses a new invocation identity. The serial application example does not promise safe concurrent application mutation of its session hash.
320
+
321
+ The multi-hop test proves the normally driven settled chain only. Immediate Source/Target custody observations do not establish that every possible historical owner is quiescent after independent reentry. That broader history-release correspondence remains open under U-01. Unsupported Store/Runtime observations and unknown current authority remain conservative errors; this change does not provide general recovery for them. Pending completed Targets, active/suspended work, arbitrary participant callbacks, and full distributed physical completion are outside this bounded repair.