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,297 @@
1
+ # Acknowledge terminal child custody without inventing result import
2
+
3
+ A coordinating parent must account for each child it owns before releasing its local objects. Ordinary result import and final custody acknowledgement are separate ways of accounting for a terminal child. The parent may finish because a child failed before reaching the ordinary import barrier; a final guarded read can acknowledge that child's saved result without pretending that the result was used to continue the parent's business operation.
4
+
5
+ For example, a report parent delegates one approved review. The review Tool fails, and the parent's existing required-subtask policy fails the report. Both executions are terminal, but the baseline leaves the child slot unimported and rejects local pair unload. G3f records a separate parent-owned acknowledgement during parent finalization so the existing unload operation can release the quiescent pair while retaining both histories.
6
+
7
+ Baseline: applied G3e `2d896e73c607d62440993474c0ad0903523e7a54`, tree `ae87ecce69588e9949713d95601ba72ec601abd4`, PR [#467](https://github.com/Raizo-TCS/phronomy/pull/467). The original 87-file G3e delivery needed one test-support require relocation; its 86 other files and all production code are unchanged. The applied head passed four workflows and 14 jobs. This document describes the G3f candidate; its exact commit and verification results belong to the accompanying delivery evidence. Contract concept v55 and foundation v48 remain the architecture references.
8
+
9
+ ## Separate parent disposition from child execution
10
+
11
+ The child owns its execution and any retained recovery operation. The parent owns its coordination slot and decides how a child's result affects the parent. Local unload additionally requires both owners to be physically quiescent; durable history retention is a separate responsibility.
12
+
13
+ For example, the child may already have a saved failed result while its original terminal-save worker is still retained. The parent can acknowledge that result and fail the report, but unloading the pair remains refused until the child's original recovery owner releases its local admission.
14
+
15
+ | Fact | Owner and evidence | Consequence |
16
+ | --- | --- | --- |
17
+ | Child result is terminal | Exact child observation and opaque reservation | The result can be read; local child work may still be retained |
18
+ | Ordinary import progressed | Existing parent dispatch barrier and `imported` flag | Existing parent continuation semantics apply |
19
+ | Final custody was acknowledged | Parent terminal transaction and separate `terminal_acknowledgement` receipt | Parent has adopted the exact saved terminal outcome for custody disposition; no callback-delivery or successful-business-import claim |
20
+ | Local pair can be unloaded | Existing exact single-child relationship, matching holds, terminal parent and child, valid disposition, and no admitted local work | Existing `unload_with_completed_child!` can release the local pair |
21
+ | History can be discarded | Separate existing history policy and authority | Neither acknowledgement nor local unload grants this permission |
22
+
23
+ The acknowledgement does not change the `imported` flag. A failed required review remains a failed child and failed parent with `imported: false`. An unrelated parent failure may also acknowledge an already-terminal child under the same guarded read: this means the parent has accounted for that child's custody, not that the child's callback determined the parent outcome.
24
+
25
+ ## Record acknowledgement in the parent's final transaction
26
+
27
+ The coordinating domain reads each eligible terminal child under the parent's ordered transaction guards and records its exact outcome identity with the parent's final state. An acknowledgement must describe the same parent execution, slot and child reservation, and it must not appear without the corresponding parent finalization.
28
+
29
+ For example, a child reserved by report execution A cannot satisfy report execution B's acknowledgement even if its Tool name and output match. An active, suspended, absent or differently reserved child remains unacknowledged. A parent coordination wait also does not create a terminal acknowledgement.
30
+
31
+ The native coordinator acts only when `ExecutionChange#finishing?` is true and its existing pending-coordination rule does not keep the parent active. It skips ordinarily imported children. The immutable extension records this receipt for every remaining eligible child:
32
+
33
+ | Receipt field | Meaning |
34
+ | --- | --- |
35
+ | `version` | Receipt schema version, currently `1` |
36
+ | `agent_id`, `execution_id` | Exact observed child identity |
37
+ | `reservation` | Native parent kind, parent Agent ID, parent execution ID and slot |
38
+ | `status` | Exact saved child terminal status |
39
+ | `outcome_digest` | SHA-256 of recursively key-sorted JSON containing materialized `result`, `raw_output`, `error` and `transfer_receipt` |
40
+
41
+ The digest preserves array order and JSON primitive types while sorting object keys recursively. It uses ordinary JSON encoding rather than the stricter `CanonicalJSON` input contract, so valid structured outputs containing large integers or negative zero are not rejected by this custody operation. The digest avoids copying potentially large result bodies into the parent extension. The retained child history remains the result source. The acknowledgement is not an authorization token and its digest is not a digital signature. Its authority comes from the existing guarded parent transaction and exact stored relationship.
42
+
43
+ The digest excludes the cancellation-intent ledger, retention records and unrelated revisions: those can legitimately change without rewriting the historical terminal result. Pair release rereads the child and reconstructs the receipt, so changed identity, reservation, status or terminal content cannot reuse the old acknowledgement. Missing or unreadable result evidence does not establish matching custody.
44
+
45
+ Parent root, execution, journal, opaque extension content and retention evidence remain covered by the existing complete `ExecutionChange` save comparison. A lost response with a matching complete post-state can use that immediate readback. A rolled-back or still-unknown participant save does not gain a new retained parent recovery operation in G3f. If the original observation failed during an unknown readback but a later unload can freshly verify the committed parent, matching acknowledgement and quiescent owners, that unload can succeed while the original observation stays failed. An unreadable current unload proof cannot establish release. No Provider, Tool, preparation hook or participant transaction is replayed merely to infer the outcome.
46
+
47
+ ## Keep application behavior explicit
48
+
49
+ The application continues to choose child policy, approval and later management actions through existing APIs. The library removes the need to invent a successful result import merely to close the local pair after a failed child. It does not remove error reporting or authorize history deletion.
50
+
51
+ For example, the complete report application below gets the child execution ID from its public approval request, approves the review, observes both saved outcomes and attempts the existing pair unload. The same complete source runs on both versions. Successful-review behavior is equivalent; failed-review local release is the intentional behavior change.
52
+
53
+ | Observable behavior | Applied G3e | G3f candidate |
54
+ | --- | --- | --- |
55
+ | Successful review | Child `review ready`, parent `report ready`, four Provider calls, one Tool effect, pair unload succeeds | Same |
56
+ | Required review fails | Child and parent fail with their existing diagnostics; two Provider calls and one Tool effect | Same business outcome and work counts |
57
+ | Local unload after that failure, with both owners quiescent | Refused because ordinary import did not occur | Allowed by matching final acknowledgement |
58
+ | Ordinary `imported` progress on that failure | `false` | Remains `false`; separate acknowledgement is present |
59
+ | Parent and child history holds after local unload | Remain present | Remain present |
60
+ | Failed original caller observation | Stays failed | Stays failed |
61
+ | Child cancellation under `:raise` or `:skip` | Parent follows its existing failure policy; cancellation is not skipped | Same policy; final acknowledgement can enable local unload |
62
+ | Child failure under `:skip` | Existing ordinary import and continuation | Same |
63
+
64
+ ### Shared application setup
65
+
66
+ The setup supplies the same parent, child, protected Tool, deterministic offline Provider and in-memory composition to both versions. The Provider supplies normal Tool requests and final answers; it does not simulate the acknowledgement implementation.
67
+
68
+ For example, the Provider first requests the reviewer and then the protected report read. With failure enabled, the Tool raises after recording its one effect; there are no subsequent successful-review or report-generation calls.
69
+
70
+ <!-- example: shared-setup -->
71
+ ```ruby
72
+ # frozen_string_literal: true
73
+
74
+ require "phronomy"
75
+ require "json"
76
+ require "timeout"
77
+
78
+ class G3fReviewTool < Phronomy::Tool::Base
79
+ tool_name "review_one_report"
80
+ description "Read the approved report once"
81
+ requires_approval true
82
+ on_error :raise
83
+
84
+ class << self
85
+ attr_accessor :effects, :fail_review
86
+ end
87
+
88
+ def execute(query:)
89
+ self.class.effects << query
90
+ raise IOError, "report review failed" if self.class.fail_review
91
+ "reviewed #{query}"
92
+ end
93
+ end
94
+
95
+ class G3fReviewAgent < Phronomy::Agent::Base
96
+ agent_definition id: "child-execution-reviewer", version: 1
97
+ model "offline-model"
98
+ tools G3fReviewTool => nil
99
+ end
100
+
101
+ class G3fReportParent < Phronomy::MultiAgent::Orchestrator
102
+ agent_definition id: "child-execution-parent", version: 1
103
+ model "offline-model"
104
+ subagent :reviewer, G3fReviewAgent
105
+ end
106
+
107
+ class G3fReportAdapter < Phronomy::LLMAdapter::Base
108
+ attr_reader :calls
109
+
110
+ def initialize
111
+ @calls = 0
112
+ end
113
+
114
+ def perform_complete(_request, cancellation_token:)
115
+ cancellation_token&.raise_if_cancelled!
116
+ @calls += 1
117
+ name, arguments = case @calls
118
+ when 1 then ["dispatch_to_reviewer", {input: "Review the report"}]
119
+ when 2 then ["review_one_report", {query: "quarterly report"}]
120
+ when 3
121
+ return Phronomy::LLMAdapter::Response.new(content: "review ready", finish_reason: :stop)
122
+ when 4
123
+ return Phronomy::LLMAdapter::Response.new(content: "report ready", finish_reason: :stop)
124
+ else
125
+ raise "Unexpected repeated Provider work"
126
+ end
127
+ Phronomy::LLMAdapter::Response.new(tool_calls: [
128
+ Phronomy::Tool::CallRequest.new(id: "call-#{@calls}", name: name, arguments: arguments)
129
+ ], finish_reason: :tool_calls)
130
+ end
131
+ end
132
+
133
+ def build_report_service(fail_review: false)
134
+ G3fReviewTool.effects = []
135
+ G3fReviewTool.fail_review = fail_review
136
+ adapter = G3fReportAdapter.new
137
+ Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
138
+ stores = Phronomy::PersistenceComposition.in_memory
139
+ approvals = Queue.new
140
+ parent = G3fReportParent.create(agent_id: "child-execution-parent", persistence: stores.agent,
141
+ coordination_store: stores.multi_agent,
142
+ on_event: ->(event) { approvals << event.payload.fetch(:request) if event.type == :approval_required })
143
+ [adapter, stores, approvals, parent]
144
+ end
145
+ ```
146
+
147
+ ### Complete before and after function
148
+
149
+ The function retains the existing approval, observation and cleanup responsibilities on both sides. Each column is a complete source unit using the shared setup; no branch is omitted to make the changed library appear simpler.
150
+
151
+ For example, the failed original approval observation remains recorded in `child_error`, while later exact observations supply the durable child and parent diagnostics. A cleanup refusal is reported as `released: false`; the application does not reinterpret it as success.
152
+
153
+ <table class="source-comparison">
154
+ <thead><tr><th>Applied G3e baseline</th><th>G3f candidate</th></tr></thead>
155
+ <tbody><tr><td valign="top">
156
+ <!-- example: application-before --><pre><code># The approval request supplies the exact public child identity.
157
+ # The same complete application runs unchanged before and after the library fix.
158
+ def run_report(fail_review: false)
159
+ adapter, stores, approvals, parent = build_report_service(fail_review: fail_review)
160
+ parent_id = &quot;child-report-execution&quot;
161
+ reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
162
+ original = parent.start_hosted(reservation: reservation, input: &quot;Prepare the report&quot;)
163
+ request = Timeout.timeout(5) { approvals.pop }
164
+ begin
165
+ original.wait_result(timeout: 5)
166
+ rescue Phronomy::ExecutionRehydrationRequiredError
167
+ # The parent retains its saved coordination wait for this child approval.
168
+ end
169
+ child = Phronomy::Agent::Base.live_for_execution(request.execution_id)
170
+ child_error = parent_error = nil
171
+ begin
172
+ child.approve_async(request.execution_id,
173
+ approval_request_id: request.id, approved: true).wait_result(timeout: 5)
174
+ rescue Phronomy::Error =&gt; error
175
+ child_error = {class: error.class.name, message: error.message}
176
+ end
177
+ begin
178
+ parent.resume(parent_id)
179
+ rescue Phronomy::Error =&gt; error
180
+ parent_error = {class: error.class.name, message: error.message}
181
+ end
182
+ parent_result = parent.resume(parent_id)
183
+ child_result = child.resume(request.execution_id)
184
+ released = begin
185
+ parent.unload_with_completed_child!(parent_id, execution_id: request.execution_id)
186
+ rescue Phronomy::AgentBusyError
187
+ false
188
+ end
189
+ {
190
+ child_status: child_result.fetch(:status), parent_status: parent_result.fetch(:status),
191
+ child_output: child_result[:output], parent_output: parent_result[:output],
192
+ child_error: child_error, parent_error: parent_error,
193
+ child_diagnostic: child_result[:error], parent_diagnostic: parent_result[:error],
194
+ tool_effects: G3fReviewTool.effects, provider_calls: adapter.calls, released: released,
195
+ history_holds: [parent.agent_id, child.agent_id].map do |id|
196
+ stores.agent.retained_references(agent_id: id).length
197
+ end
198
+ }
199
+ end</code></pre>
200
+ </td><td valign="top">
201
+ <!-- example: application-after --><pre><code># The approval request supplies the exact public child identity.
202
+ # The same complete application runs unchanged before and after the library fix.
203
+ def run_report(fail_review: false)
204
+ adapter, stores, approvals, parent = build_report_service(fail_review: fail_review)
205
+ parent_id = &quot;child-report-execution&quot;
206
+ reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
207
+ original = parent.start_hosted(reservation: reservation, input: &quot;Prepare the report&quot;)
208
+ request = Timeout.timeout(5) { approvals.pop }
209
+ begin
210
+ original.wait_result(timeout: 5)
211
+ rescue Phronomy::ExecutionRehydrationRequiredError
212
+ # The parent retains its saved coordination wait for this child approval.
213
+ end
214
+ child = Phronomy::Agent::Base.live_for_execution(request.execution_id)
215
+ child_error = parent_error = nil
216
+ begin
217
+ child.approve_async(request.execution_id,
218
+ approval_request_id: request.id, approved: true).wait_result(timeout: 5)
219
+ rescue Phronomy::Error =&gt; error
220
+ child_error = {class: error.class.name, message: error.message}
221
+ end
222
+ begin
223
+ parent.resume(parent_id)
224
+ rescue Phronomy::Error =&gt; error
225
+ parent_error = {class: error.class.name, message: error.message}
226
+ end
227
+ parent_result = parent.resume(parent_id)
228
+ child_result = child.resume(request.execution_id)
229
+ released = begin
230
+ parent.unload_with_completed_child!(parent_id, execution_id: request.execution_id)
231
+ rescue Phronomy::AgentBusyError
232
+ false
233
+ end
234
+ {
235
+ child_status: child_result.fetch(:status), parent_status: parent_result.fetch(:status),
236
+ child_output: child_result[:output], parent_output: parent_result[:output],
237
+ child_error: child_error, parent_error: parent_error,
238
+ child_diagnostic: child_result[:error], parent_diagnostic: parent_result[:error],
239
+ tool_effects: G3fReviewTool.effects, provider_calls: adapter.calls, released: released,
240
+ history_holds: [parent.agent_id, child.agent_id].map do |id|
241
+ stores.agent.retained_references(agent_id: id).length
242
+ end
243
+ }
244
+ end</code></pre>
245
+ </td></tr></tbody></table>
246
+
247
+ ### Complete application driver
248
+
249
+ The driver selects the ordinary or deliberately failed review and reports the same result structure. The example uses an isolated Runtime and in-memory history; a service must keep unresolved owners and its durable backend available according to its management policy.
250
+
251
+ For example, the ordinary invocation prints successful outputs, while `--fail-review` prints the preserved failure diagnostics and whether the local pair was released. This example has no outstanding child save-recovery operation at driver shutdown.
252
+
253
+ <!-- example: shared-driver -->
254
+ ```ruby
255
+ if $PROGRAM_NAME == __FILE__
256
+ begin
257
+ puts JSON.pretty_generate(run_report(fail_review: ARGV.include?("--fail-review")))
258
+ ensure
259
+ Phronomy.reset_runtime!
260
+ end
261
+ end
262
+ ```
263
+
264
+ ## Preserve symmetry without adding a management facade
265
+
266
+ Comparable operations share the existing distinction between recorded facts, business policy and physical ownership. The native parent gains one domain-specific persisted fact, while child recovery, Team coordination and history disposal retain their own responsibilities.
267
+
268
+ For example, a child terminal recovery receipt can prove that the child's saved failure is applied and its owner released. It cannot set the native parent's acknowledgement or release Team slots; those decisions belong to their respective parent domains.
269
+
270
+ | Concern | Existing ordinary import | Final native acknowledgement | Decision |
271
+ | --- | --- | --- | --- |
272
+ | Result meaning | Parent reaches ordinary continuation/import barrier | Parent accounts for exact terminal child while ending | Keep separate facts; neither implies the other |
273
+ | Public method and result shape | Existing Agent and Orchestrator API | Same public API and return shapes | Adopt existing operations; no new sync/async or stream variant |
274
+ | Parent error policy | `:raise` / `:skip`, with cancellation not skipped | Does not re-evaluate or rewrite that policy | Preserve |
275
+ | Saved evidence | Opaque native extension | Same extension with a versioned receipt | Keep with the coordinating domain |
276
+ | Child local recovery | Original child owns it | Original child still owns it | Preserve independent ownership |
277
+ | Local release | Exact completed-pair checks plus quiescence | Same checks, allowing valid acknowledgement as a second disposition | Extend evidence, retain safeguards |
278
+ | History release | Separate domain decision | Separate domain decision | Defer broader history-disposal changes |
279
+ | Team / Handoff / custom participant | Their own state and authority | No new inferred support | Defer to explicit acceptance for those domains |
280
+
281
+ Simply marking every observed terminal child as `imported` was rejected because it would invent business-import progress. A generic Tool completion flag was also rejected as sufficient proof of child result consumption: a wrapper can time out or cancel before the actual child callback. A final guarded adoption deliberately makes a narrower, explicit claim and needs no new Agent SPI, volatile receipt registry or public convenience layer.
282
+
283
+ ## Check boundaries and acceptance limits
284
+
285
+ The coordinating domain interprets native slots and acknowledgements, while Agent supplies existing execution observations, guarded transactions and local lifetime checks. Keeping the change in that domain avoids a reverse dependency from Agent into MultiAgent and avoids a separate cross-domain job manager.
286
+
287
+ For example, the same `Agent::ExecutionObservation` used for exact child observation supplies the materialized terminal result. The parent coordinator computes its own receipt and stores it as opaque extension content; Agent does not learn native child-slot semantics.
288
+
289
+ The behavioral production change is confined to `MultiAgent::DurableSubagentCoordinator`; the existing Orchestrator unload comment is updated to describe the additional acknowledgement disposition. No public API, RBS signature, dependency, persisted Agent execution format, Team implementation or Workflow implementation is added. Existing native extension objects remain readable; old unimported histories without an acknowledgement are not silently backfilled. Resuming an already-terminal historical parent only observes its saved result and does not create a new acknowledgement. Explicit history disposition remains a separate existing application decision. The single-child pair-unload API remains restricted to one direct child, even though parent finalization may acknowledge several terminal slots.
290
+
291
+ Both current Contract SVGs remain reference points for dependency direction and responsibility review. Their unchanged selected Contract graphs are not proof that the complete Ruby graph is acyclic. Candidate source-graph comparisons, Runtime acceptance and finite-model expectations are recorded with the delivery. The [bounded parent/child model](../../spec/models/parent_child_result_import/README.md) keeps parent custody, child physical ownership and caller observation separate; it is not a Ruby refinement proof. The complete application was run in four separate real-Runtime processes against exact baseline and candidate checkouts. The normal result objects match completely. For the failed review, only `released: false` becoming `released: true` differs; saved business diagnostics, Provider/Tool counts and history holds match.
292
+
293
+ Required bounded acceptance includes the six ordinary success/failure/cancellation and `:raise`/`:skip` combinations; unchanged business diagnostics, Provider/Tool counts and holds; exact-identity and outcome tampering; active, absent and suspended exclusions; atomic save rollback and committed-response loss; child-local recovery still blocking premature unload; earlier parent histories; and a separate parent/child/caller model. Each claim is limited to the cases actually recorded in the final evidence.
294
+
295
+ G3f advances the native parent-custody item within completion group 1. Native participant save recovery after unresolved immediate readback, Handoff, custom participant capability, nonterminal wait establishment and remaining cross-path acceptance stay open. Group 2 remains management after Runtime failure; group 3 remains MCP resource management; group 4 remains fallback child ownership; group 5 remains capability and existing-guarantee alignment; group 6 remains selected durable-backend/transport and combined final acceptance. No seventh completion group is introduced.
296
+
297
+ That paragraph records the G3f boundary. Subsequent [G3g native dispatch recovery](native-parent-dispatch-recovery.md) and [G3h native final/wait and own approval recovery](native-parent-outcome-recovery.md) advance the supported native participant paths within the same group 1. They preserve this acknowledgement contract and do not close Handoff, arbitrary participant support or the other completion groups.
@@ -33,9 +33,12 @@ reference this error or interpret recovery. Generic errors retain their original
33
33
  backtrace when wrapped; ToolError and CancellationError remain unchanged.
34
34
  Suppression logging uses C06's existing RuntimeSettings logger capability.
35
35
 
36
- An ordinary asynchronous subagent call still checks cancellation before schema
37
- validation, starts the child without occupying a waiting offload worker, maps
38
- its output and applies Tool policy. The subagent on_error option continues to
36
+ The unit 12 candidate described below allowed standalone generated Tool calls.
37
+ The subsequent ownership change requires a reserved parent slot. [Current contract and migration](../migrations/orchestrator-subagent-dispatch.md)
38
+
39
+ In the unit 12 candidate, an ordinary asynchronous subagent call checked cancellation before schema
40
+ validation, started the child without occupying a waiting offload worker, mapped
41
+ its output and applied Tool policy. The subagent on_error option continues to
39
42
  control child failure (raise or skip); it is distinct from Tool on_error policy.
40
43
 
41
44
  An admitted durable child follows the existing reconciliation path directly.
@@ -37,14 +37,23 @@ inputs only. In one outer `Persistence#atomic` scope the participant:
37
37
  3. Changes its own records and calls `change.commit_in(scope, state:, transfer_receipt:, pending:)` once.
38
38
  4. Returns after the outer commit. Agent publishes the captured result only then.
39
39
 
40
- The change is bound to the original thread, coordinator and prepared scope. It
40
+ The change is usable only during the original active synchronous `perform` call,
41
+ on its original thread, coordinator and prepared scope. It
41
42
  checks its Agent watermark and expected execution revision. A nested savepoint
42
43
  cannot authorize publication. Reconciliation compares Root, execution payload,
43
44
  appended journal, extension content, cancellation intent, and participant evidence
44
- in a consistent scope. Exact post-state proves commit; exact pre-state proves no
45
+ in a consistent scope. Participant evidence is a detached JSON snapshot at each
46
+ capture, so reusing its buffer cannot rewrite an earlier comparison value.
47
+ Exact post-state proves commit; exact pre-state proves no
45
48
  commit; different state or failed reads require recovery. There is no write retry.
46
49
  An updated record at the expected revision alone is insufficient evidence.
47
50
 
51
+ The later [synchronous participant custody contract](synchronous-participant-contract.md)
52
+ retains uncertain dispatch and outcome operations through the existing Agent
53
+ owners. Ordinary public participation grants no callback replay or fresh domain
54
+ continuation authority. Unsupported retained proofs produce explicit unavailable
55
+ observations while preserving responsibility.
56
+
48
57
  Subagent cancellation retains unresolved active work. Known business errors may
49
58
  follow `on_error: :skip`; unknown external outcomes cannot be skipped into success.
50
59
  Handoff Source transfer and Target terminal stabilization join the same Agent
@@ -0,0 +1,88 @@
1
+ # Completion facts: current implementation and extraction history
2
+
3
+ Agent outcome, approval and dispatch recovery and Workflow terminal recovery use
4
+ shared attempt management and completion evidence. Domain authorization,
5
+ persistence interpretation, application, continuation and release remain with
6
+ their original owners.
7
+
8
+ For example, a save worker can finish after its first observer is cancelled.
9
+ The common evidence record preserves the worker result, while Agent and Workflow
10
+ still make different decisions after a confirmed noncommit.
11
+
12
+ As of 2026-11-28, the current implementation is documented in
13
+ [shared retained-attempt management](retained-attempts.md). C13
14
+ `RetainedAttempts` manages the initial attempt, recovery lane and observers;
15
+ C13 `AttemptCompletion` stores completion evidence. The former
16
+ `Agent::PhysicalAttempt` class and source path are removed without an alias.
17
+ Workflow participates in this implementation. The historical figures below
18
+ apply only to the earlier Agent-only extraction.
19
+
20
+ ## Original Agent-only extraction
21
+
22
+ The first extraction shared completion bookkeeping between the Agent terminal
23
+ and approval owners while leaving their identity, admission and observation
24
+ management separate. It preceded the broader four-owner implementation.
25
+
26
+ For example, terminal recovery could apply a confirmed result or retain an
27
+ explicit save retry, while approval recovery could restore its original wait
28
+ or resume a retained continuation. Their completion mailbox was reusable even
29
+ though those domain decisions differed.
30
+
31
+ | Responsibility in the original extraction | Historical location |
32
+ | --- | --- |
33
+ | Task handle, logical/physical facts, worker result and registration error | `Agent::PhysicalAttempt` |
34
+ | Task callbacks, snapshot fallback and worker-result precedence | `Agent::PhysicalAttempt` |
35
+ | Identity, started/refused/unknown evidence and observer membership | Individual Agent recovery owner |
36
+ | Pre/post interpretation, retry authorization, live application and release | Individual Agent recovery owner |
37
+
38
+ Each original owner kept a slot containing its own facts and one completion
39
+ record. Workflow was excluded from that first extraction pending an independent
40
+ comparison. The later shared manager supersedes that placement and the mutable
41
+ slot interface; it does not supersede the distinct domain policies.
42
+
43
+ ## Atomicity and cleanup preserved by the first extraction
44
+
45
+ The extracted completion record used its owner's existing mutex to combine
46
+ completion evidence with domain decisions. Task methods and owner notifications
47
+ ran outside that mutex because callback registration could invoke a callback
48
+ immediately.
49
+
50
+ For example, an inline physical callback could publish its fact and notify the
51
+ owner before registration returned. A later logical snapshot could not replace
52
+ an explicitly recorded worker result, including a successful `nil` value.
53
+
54
+ The original protocol retained physical evidence when a poll was less
55
+ informative, kept a handle after partial notification registration, and isolated
56
+ old completion records from replacement attempts. It did not infer physical
57
+ completion from logical completion for a task offering a separate physical
58
+ protocol. Owner release or resolution controlled reference cleanup.
59
+
60
+ The first extraction also cleared a private registration-error reference that
61
+ terminal recovery had previously retained after release. That was a bounded
62
+ reference cleanup, not a new lifecycle state or a guarantee against arbitrary
63
+ nonstandard delayed callbacks. Current cleanup commands preserve the distinction
64
+ between releasing only the task and releasing all completion references.
65
+
66
+ ## Original cost and acceptance scope
67
+
68
+ The first extraction removed a second implementation of completion observation
69
+ and refresh. Its cost included another private class, a record per attempt,
70
+ temporary snapshots and a shared-lock precondition. Its size measurements did not
71
+ establish a large reduction across the framework.
72
+
73
+ For example, a correction to worker-result precedence then reached both Agent
74
+ owners through one implementation, while approval restoration and terminal save
75
+ retry still required their own Runtime acceptance tests.
76
+
77
+ Against `f08d26c59b77b0157e0fa7e267fb299516342c8f`, the two owners shrank from
78
+ 1,105 to 1,031 physical lines. The new record added 86 lines, so combined source
79
+ grew by 12 lines. Excluding blank and comment-only lines, the combined count
80
+ fell from 982 to 973, a reduction of nine lines. These are historical figures,
81
+ not measurements of the current shared manager or a performance claim.
82
+
83
+ The original record tests exercised inline callbacks, logical/physical
84
+ separation, worker-result precedence, partial registration failure, snapshot
85
+ races and old-attempt isolation. The current protocol additionally removes
86
+ preparation-time task reattachment and captures the completion record and task
87
+ in one refresh read. Its current responsibilities, lock rationale, model mapping
88
+ and acceptance obligations are in [the current design](retained-attempts.md).