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,425 @@
1
+ # Original-owner recovery for correlated child execution
2
+
3
+ An accepted child owns the preparation and completion of its execution even when a coordinating parent reserved that execution. The child must retain an uncertain dispatch barrier or terminal save until the same owner can establish and apply the saved outcome. The parent separately owns result import and its own continuation. G3e extends the existing retained Agent operations to correlated children without adding another manager or parent recovery facade.
4
+
5
+ For example, a report parent starts a reviewer child. The child asks permission to read one report. After the host approves, the child either loses its Tool-dispatch save response or loses the response that records the completed review. Recovery must use the already accepted child and original work, while keeping the parent's independent import and release rules intact.
6
+
7
+ Baseline: applied G3d `ae2070e36687f376754128deea1a41c69f416a0c`, tree `4b786f3359f481263c598e7ac66a50082b4bf29f`. This document describes the G3e implementation candidate. Contract concept v55 and foundation v48 remain current; exact candidate identity and final validation are in the delivery evidence.
8
+
9
+ ## Keep the child obligation separate from parent progress
10
+
11
+ The child's captured proposal includes its execution identity and opaque reservation correlation. Dispatch proof permits only the original next action; terminal proof describes an already computed outcome. Neither proof updates the parent's child slot or decides whether that parent has imported a result.
12
+
13
+ For example, a parent can read a committed child terminal result while the original child's terminal recovery is still retained. That read does not release the child's local owner. Conversely, a child can finish recovery while the parent remains at its coordination wait and needs an explicit `resume` under the parent's existing protocol.
14
+
15
+ | Responsibility | Owner and evidence | What it does not establish |
16
+ | --- | --- | --- |
17
+ | Accepted child identity | Original Agent incarnation, execution, session and immutable reservation correlation | A new parent instruction or permission to create another child |
18
+ | Saved dispatch barrier | Complete captured child pre/post footprint; the original prepared input and continuation | Admission or completion of an external Provider/Tool request |
19
+ | Fresh dispatch continuation | Original unconsumed continuation right plus a current matching child snapshot | A distributed fence through a later external call |
20
+ | Saved actual terminal outcome | Complete child root/execution/journal/content/cancellation evidence | Parent import or arbitrary participant transaction outcome |
21
+ | Parent result import | Coordinating domain's existing exact child slot and guarded import protocol | Physical completion of child recovery work |
22
+ | Peer release | Existing retention and matching completed-pair checks | Permission inferred from a failed caller or a terminal row alone |
23
+
24
+ A saved failed or cancelled child does not imply successful parent import. At the G3e baseline, the native parent's default `on_error: :raise` policy can fail the parent while its child slot remains `imported: false`, leaving completed-pair unload refused even after both local execution admissions are released. The subsequent [parent terminal-acknowledgement change](parent-child-terminal-acknowledgement.md) keeps that import flag unchanged and adds a distinct guarded parent disposition that can permit local unload. Neither child recovery nor that acknowledgement drops the durable history holds.
25
+
26
+ The child treats reservation data as opaque. It does not import native parent types, interpret child slots, freeze a parent revision or require unchanged parent retention history to finish an already accepted child obligation. Participant-owned changes and execution extensions remain excluded. Retentions continue to govern domain release, separately from the child-only saved-state comparison.
27
+
28
+ ## Revalidate before new dispatch admission
29
+
30
+ A previously confirmed dispatch post-state remains historical knowledge of a saved barrier. A correlated child that has not yet consumed its original continuation right must establish that the current child footprint still matches before granting that right. Later parent progress does not replace that child check.
31
+
32
+ For example, if the child reservation, revision or cancellation evidence changes after a saved post-state was observed but before continuation admission succeeds, a later receipt can still say `confirmed_post` while continuation remains pending. A missing read cannot authorize Tool work. Once admission was already authorized or is uncertain, another observation cannot grant a second admission.
33
+
34
+ This is a guarded snapshot under the selected Store, not a distributed lock held through external dispatch. The existing cooperative-writer, authoritative-read and cancellation assumptions remain. A later cancellation may leave a retained obligation when its captured preconditions no longer match; this increment does not invent an administrative resolution for every stopped or externally modified owner.
35
+
36
+ ## Recover through the original child API
37
+
38
+ A recovery capability belongs to one exact child incarnation and retained operation. Existing local lookup, read-only reconciliation and explicit persistence retry are sufficient; the parent does not reconstruct or adopt the child's capability.
39
+
40
+ For example, an approval-driven service receives `request.execution_id` in the public ApprovalRequest and resolves its original child with `Agent::Base.live_for_execution`. A direct child observation can raise a typed recovery error. When a coordinating observer hides that error, the host can use the same known identity to query the child's pending recovery instead.
41
+
42
+ | Public contract | Dispatch boundary | Actual terminal boundary |
43
+ | --- | --- | --- |
44
+ | Local pending lookup | `pending_dispatch_recovery(execution_id:)` | `pending_terminal_recovery(execution_id:)` |
45
+ | Read-only reconciliation | `reconcile_dispatch[_async](recovery:)` | `reconcile_terminal[_async](recovery:)` |
46
+ | Explicit captured-write retry | `retry_dispatch[_async](recovery:)` | `retry_terminal[_async](recovery:)` |
47
+ | Mechanism-proven first submission retry | No generic replay of preparation | Existing `retry_terminal_submission[_async]`, only after positively proven non-admission |
48
+ | Completion observation | Independent `execution_task` after resolved continuation handoff | Immutable terminal `execution` after saved post-state |
49
+ | Pending result | Retain child, capability, Runtime and claim | Same requirement |
50
+ | Parent continuation | Existing parent protocol | Existing parent protocol |
51
+
52
+ The selected parent profiles are native Orchestrator children and Team coordinator/worker children. Their opaque reservation values use the same child protocol; the parent adapters keep their own import and cleanup rules. Team forwards typed child recovery errors unchanged when they reach the caller, so those errors supply the child identity and capability directly. A Team can also complete from a saved terminal child result while child-local recovery still blocks cleanup; a later existing Team resume can finish that cleanup after child reconciliation. These cases do not establish arbitrary participant or Handoff recovery.
53
+
54
+ Synchronous variants retain host-thread waiting and EventLoop reentrancy checks. Asynchronous variants retain independent observations. Cancelling a recovery observation does not cancel canonical work. Dispatch receipt physical completion concerns its preparation/recovery workers, not the later Tool or entire job. Terminal release remains conditional on the original operation's physical quiescence. Resolved capabilities preserve historical receipts without reopening failed observations or replaying work.
55
+
56
+ Terminal recovery preserves the child's existing `ReservedExecution` reservation value in its returned execution observation; this is consistency of an existing field, not a new result shape.
57
+
58
+ A native coordinating task can wrap a child operation error in `ExecutionRehydrationRequiredError`. An exact execution observer can instead fulfill from a committed terminal record even after an internal save error. Therefore, not every original observer fails, and parent success is not a child-cleanup acknowledgement. After a successful exact-child or parent observation, a host holding the original child reference and its known execution identity must still check `child.pending_terminal_recovery(execution_id: child_execution_id)` before claiming local recovery cleanup. If it returns a capability, use `child.reconcile_terminal(recovery: recovery)` and, only by explicit policy, `child.retry_terminal(recovery: recovery)` for confirmed pre-state; require confirmed post, applied state and released ownership before completing that cleanup. The ordinary domain unload/import checks still apply. This management instruction is supported by the separate native and Team terminal-post acceptance; the seven Runtime application cases below deliberately use a direct approval observation and do not claim general successful-observer discovery coverage.
59
+
60
+ General child discovery from an arbitrary parent error is not added; the example below deliberately uses a public approval request to obtain the identity.
61
+
62
+ ## Preserve the ordinary report application
63
+
64
+ The ordinary report preserves its input, approval policy, one protected Tool effect, output, parent import and completed-pair release. Extending recovery eligibility requires no application source change on this ordinary path.
65
+
66
+ For example, both source columns below run four deterministic Provider calls, read the quarterly report exactly once, save the child and parent as completed, and release the matching pair. They use the same real Runtime, in-memory persistence and offline Provider. The response-loss fixture is inactive for this comparison.
67
+
68
+ ### Shared application setup
69
+
70
+ The shared setup defines the parent and reviewer roles, the approval Tool, the offline Provider and the application event queue. The queue conveys only the public approval request; it does not expose native slot internals.
71
+
72
+ For example, the parent Provider requests its reviewer, the reviewer requests one report read, and the two remaining Provider responses complete the child and parent outputs. The recorded Tool effects detect accidental repeated business work.
73
+
74
+ <!-- example: shared-setup -->
75
+ ```ruby
76
+ # frozen_string_literal: true
77
+
78
+ require "phronomy"
79
+ require "json"
80
+ require "timeout"
81
+
82
+ class G3eReviewTool < Phronomy::Tool::Base
83
+ tool_name "review_one_report"
84
+ description "Read the approved report once"
85
+ requires_approval true
86
+
87
+ class << self
88
+ attr_accessor :effects
89
+ end
90
+
91
+ def execute(query:)
92
+ self.class.effects << query
93
+ "reviewed #{query}"
94
+ end
95
+ end
96
+
97
+ class G3eReviewAgent < Phronomy::Agent::Base
98
+ agent_definition id: "child-execution-reviewer", version: 1
99
+ model "offline-model"
100
+ tools G3eReviewTool => nil
101
+ end
102
+
103
+ class G3eReportParent < Phronomy::MultiAgent::Orchestrator
104
+ agent_definition id: "child-execution-parent", version: 1
105
+ model "offline-model"
106
+ subagent :reviewer, G3eReviewAgent
107
+ end
108
+
109
+ class G3eReportAdapter < Phronomy::LLMAdapter::Base
110
+ attr_reader :calls
111
+
112
+ def initialize
113
+ @calls = 0
114
+ end
115
+
116
+ def perform_complete(_request, cancellation_token:)
117
+ cancellation_token&.raise_if_cancelled!
118
+ @calls += 1
119
+ name, arguments = case @calls
120
+ when 1 then ["dispatch_to_reviewer", {input: "Review the report"}]
121
+ when 2 then ["review_one_report", {query: "quarterly report"}]
122
+ when 3
123
+ return Phronomy::LLMAdapter::Response.new(content: "review ready", finish_reason: :stop)
124
+ when 4
125
+ return Phronomy::LLMAdapter::Response.new(content: "report ready", finish_reason: :stop)
126
+ else
127
+ raise "Unexpected repeated Provider work"
128
+ end
129
+ Phronomy::LLMAdapter::Response.new(tool_calls: [
130
+ Phronomy::Tool::CallRequest.new(id: "call-#{@calls}", name: name, arguments: arguments)
131
+ ], finish_reason: :tool_calls)
132
+ end
133
+ end
134
+
135
+ def build_report_service
136
+ G3eReviewTool.effects = []
137
+ adapter = G3eReportAdapter.new
138
+ Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
139
+ stores = Phronomy::PersistenceComposition.in_memory
140
+ approvals = Queue.new
141
+ parent = G3eReportParent.create(agent_id: "child-execution-parent", persistence: stores.agent,
142
+ coordination_store: stores.multi_agent,
143
+ on_event: ->(event) { approvals << event.payload.fetch(:request) if event.type == :approval_required })
144
+ [adapter, stores, approvals, parent]
145
+ end
146
+ ```
147
+
148
+ ### Equivalent before and after source
149
+
150
+ The normal function holds the same parent and child identities and follows the same approval and import policy on the baseline and candidate. Each column is the complete function, with shared setup and the driver shown separately.
151
+
152
+ For example, the public approval request supplies the child identity before either version approves the read. The parent has already reached its saved coordination wait in this particular application, so both versions explicitly resume it after the child's ordinary completion.
153
+
154
+ <table class="source-comparison">
155
+ <thead><tr><th>Applied G3d baseline</th><th>G3e candidate</th></tr></thead>
156
+ <tbody><tr><td valign="top">
157
+ <!-- example: normal-before --><pre><code># The public approval request supplies the exact child identity.
158
+ def run_report
159
+ adapter, stores, approvals, parent = build_report_service
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 has its saved coordination wait for this approval-driven child.
168
+ end
169
+ child = Phronomy::Agent::Base.live_for_execution(request.execution_id)
170
+ child_result = child.approve_async(request.execution_id,
171
+ approval_request_id: request.id, approved: true).wait_result(timeout: 5)
172
+ parent_result = parent.resume(parent_id)
173
+ released = parent.unload_with_completed_child!(parent_id, execution_id: request.execution_id)
174
+ {
175
+ child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
176
+ tool_effects: G3eReviewTool.effects, provider_calls: adapter.calls, released: released,
177
+ statuses: [parent_id, request.execution_id].map { |id| stores.agent.executions.load(id).status },
178
+ revisions: [parent_id, request.execution_id].map { |id| stores.agent.executions.load(id).execution_revision }
179
+ }
180
+ end</code></pre>
181
+ </td><td valign="top">
182
+ <!-- example: normal-after --><pre><code># The public approval request supplies the exact child identity.
183
+ def run_report
184
+ adapter, stores, approvals, parent = build_report_service
185
+ parent_id = &quot;child-report-execution&quot;
186
+ reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
187
+ original = parent.start_hosted(reservation: reservation, input: &quot;Prepare the report&quot;)
188
+ request = Timeout.timeout(5) { approvals.pop }
189
+ begin
190
+ original.wait_result(timeout: 5)
191
+ rescue Phronomy::ExecutionRehydrationRequiredError
192
+ # The parent has its saved coordination wait for this approval-driven child.
193
+ end
194
+ child = Phronomy::Agent::Base.live_for_execution(request.execution_id)
195
+ child_result = child.approve_async(request.execution_id,
196
+ approval_request_id: request.id, approved: true).wait_result(timeout: 5)
197
+ parent_result = parent.resume(parent_id)
198
+ released = parent.unload_with_completed_child!(parent_id, execution_id: request.execution_id)
199
+ {
200
+ child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
201
+ tool_effects: G3eReviewTool.effects, provider_calls: adapter.calls, released: released,
202
+ statuses: [parent_id, request.execution_id].map { |id| stores.agent.executions.load(id).status },
203
+ revisions: [parent_id, request.execution_id].map { |id| stores.agent.executions.load(id).execution_revision }
204
+ }
205
+ end</code></pre>
206
+ </td></tr></tbody></table>
207
+
208
+ ### Ordinary executable driver
209
+
210
+ The driver owns the demonstration Runtime for the completed ordinary example. A long-running service handling an unresolved recovery result must instead retain its original Runtime and external claim until its explicit recovery policy resolves that obligation.
211
+
212
+ For example, running this file without fault injection produces the complete report and then resets its now-finished Runtime. The recovery function below returns retained context when unresolved; it must not be treated as a fresh invocation request.
213
+
214
+ <!-- example: shared-driver -->
215
+ ```ruby
216
+ # This driver runs the ordinary completed example. A long-running service keeps
217
+ # a recovery_pending result and its live Runtime for a later explicit decision.
218
+ if $PROGRAM_NAME == __FILE__
219
+ begin
220
+ puts JSON.pretty_generate(run_report)
221
+ ensure
222
+ Phronomy.reset_runtime!
223
+ end
224
+ end
225
+ ```
226
+
227
+ ## Make save retry an explicit application decision
228
+
229
+ The application distinguishes reading saved evidence from retrying captured writes and distinguishes child completion from parent import. The recovery helper performs one reconciliation and at most one separately authorized captured-write retry. It returns the retained owner and capability when responsibility remains pending.
230
+
231
+ For example, a confirmed rollback of the Tool barrier leaves the report unread. With retry disabled, the host receives `recovery_pending`. A later explicit call with the same capability can retry the original save and execute the protected read once. A terminal rollback retains the already computed review rather than running the Tool again.
232
+
233
+ <!-- example: recovery-helper -->
234
+ ```ruby
235
+ # Reconciliation reads evidence; write retry is a separate application choice.
236
+ def recover_child_boundary(child:, recovery:, retry_confirmed_pre: false)
237
+ receipt = case recovery
238
+ when Phronomy::Agent::DispatchRecovery
239
+ observed = child.reconcile_dispatch(recovery: recovery)
240
+ if retry_confirmed_pre && observed.outcome == :confirmed_pre
241
+ observed = child.retry_dispatch(recovery: recovery)
242
+ end
243
+ observed
244
+ when Phronomy::Agent::TerminalRecovery
245
+ observed = child.reconcile_terminal(recovery: recovery)
246
+ if retry_confirmed_pre && observed.outcome == :confirmed_pre
247
+ observed = child.retry_terminal(recovery: recovery)
248
+ end
249
+ observed
250
+ else
251
+ raise ArgumentError, "Expected this child's dispatch or terminal capability"
252
+ end
253
+ result = if receipt.is_a?(Phronomy::Agent::DispatchRecoveryResult) && receipt.resolved?
254
+ receipt.execution_task.wait_result(timeout: 5)
255
+ elsif receipt.is_a?(Phronomy::Agent::TerminalRecoveryResult) &&
256
+ receipt.outcome == :confirmed_post && receipt.application_state == :applied &&
257
+ receipt.ownership_state == :released && receipt.execution
258
+ receipt.execution.to_result
259
+ end
260
+ if result
261
+ {state: :observed, result: result, receipt: receipt}.freeze
262
+ else
263
+ # The service must retain this owner, capability, Runtime and external claim.
264
+ {state: :recovery_pending, child: child, recovery: recovery, receipt: receipt}.freeze
265
+ end
266
+ end
267
+ ```
268
+
269
+ ### Complete response-loss example
270
+
271
+ The complete example keeps the same public child identity and makes the human approval exactly once. Its additional branches handle an uncertain child boundary and preserve the parent context when that boundary remains unresolved.
272
+
273
+ For example, after a lost terminal response, the helper can confirm the completed child and release its local recovery owner. This example's parent is still at its coordination wait, so it then resumes and imports the saved review. Other native parents may already have imported the result; that independent behavior does not change the child's recovery receipt.
274
+
275
+ <!-- example: recovery-example -->
276
+ ```ruby
277
+ # The injected fault is optional test setup; approving remains a single action.
278
+ def run_report_with_recovery(fault:, retry_confirmed_pre: false)
279
+ adapter, stores, approvals, parent = build_report_service
280
+ parent_id = "child-report-execution"
281
+ reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
282
+ original = parent.start_hosted(reservation: reservation, input: "Prepare the report")
283
+ request = Timeout.timeout(5) { approvals.pop }
284
+ begin
285
+ original.wait_result(timeout: 5)
286
+ rescue Phronomy::ExecutionRehydrationRequiredError
287
+ # This example deliberately begins at the same coordination wait as normal.
288
+ end
289
+ child = Phronomy::Agent::Base.live_for_execution(request.execution_id)
290
+ fault.call(stores.agent, request.execution_id)
291
+ decision = child.approve_async(request.execution_id,
292
+ approval_request_id: request.id, approved: true)
293
+ failure = begin
294
+ decision.wait_result(timeout: 5)
295
+ raise "The injected child save uncertainty was not observed"
296
+ rescue Phronomy::Agent::DispatchRecoveryError, Phronomy::Agent::TerminalRecoveryError => error
297
+ error
298
+ end
299
+ observed = recover_child_boundary(child: child, recovery: failure.recovery,
300
+ retry_confirmed_pre: retry_confirmed_pre)
301
+ if observed.fetch(:state) == :recovery_pending
302
+ return observed.merge(parent: parent, parent_execution_id: parent_id, stores: stores).freeze
303
+ end
304
+ child_result = observed.fetch(:result)
305
+ # This particular parent is at a coordination wait. Other native parents may
306
+ # already have imported a saved terminal result; their status is independent.
307
+ parent_result = parent.resume(parent_id)
308
+ released = parent.unload_with_completed_child!(parent_id, execution_id: request.execution_id)
309
+ begin
310
+ decision.wait_result(timeout: 5)
311
+ raise "The original failed observation reopened"
312
+ rescue Phronomy::Agent::DispatchRecoveryError, Phronomy::Agent::TerminalRecoveryError => original_failure
313
+ raise "The original failure changed" unless original_failure.equal?(failure)
314
+ end
315
+ {
316
+ state: :observed, child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
317
+ tool_effects: G3eReviewTool.effects, provider_calls: adapter.calls, released: released,
318
+ statuses: [parent_id, request.execution_id].map { |id| stores.agent.executions.load(id).status },
319
+ revisions: [parent_id, request.execution_id].map { |id| stores.agent.executions.load(id).execution_revision },
320
+ recovery_outcome: observed.fetch(:receipt).outcome
321
+ }
322
+ end
323
+ ```
324
+
325
+ ### Optional deterministic failure fixture
326
+
327
+ The fixture changes only the observation of an actual child persistence transaction and its immediate readback. It scopes the fault to one known child and boundary, then leaves later explicit recovery reads and retries available. It is test setup, not application retry policy or a public framework extension.
328
+
329
+ For example, `child_reply_loss(kind: :dispatch, mode: :pre)` executes the selected atomic body once and rolls it back before losing the response. The `post` variant commits before losing the response. `run_report_with_recovery(fault: child_reply_loss(kind: :terminal, mode: :post), retry_confirmed_pre: false)` exercises terminal confirmation without another save.
330
+
331
+ <!-- example: fault-fixture -->
332
+ ```ruby
333
+ # Optional response-loss fixture; application recovery below uses public APIs.
334
+ # The original atomic body runs once, and the immediate readback is unavailable.
335
+ module G3eChangeFaultScope
336
+ def perform
337
+ fault = coordinator.instance_variable_get(:@g3e_child_fault)
338
+ previous = Thread.current[:g3e_child_fault]
339
+ selected = fault && execution_id == fault.fetch(:execution_id) && kind == fault.fetch(:kind)
340
+ Thread.current[:g3e_child_fault] = selected ? fault : nil
341
+ super
342
+ ensure
343
+ Thread.current[:g3e_child_fault] = previous
344
+ end
345
+ end
346
+
347
+ module G3eAtomicFault
348
+ def atomic(*args, &transaction)
349
+ fault = Thread.current[:g3e_child_fault]
350
+ return super unless fault
351
+ if fault[:readback]
352
+ fault[:readback] = false
353
+ raise IOError, "Immediate child readback unavailable"
354
+ end
355
+ return super unless fault[:armed]
356
+ fault[:armed] = false
357
+ if fault.fetch(:mode) == :pre
358
+ super do |scope|
359
+ transaction.call(scope)
360
+ fault[:readback] = true
361
+ raise IOError, "Child transaction rolled back; response lost"
362
+ end
363
+ else
364
+ super
365
+ fault[:readback] = true
366
+ raise IOError, "Child transaction committed; response lost"
367
+ end
368
+ end
369
+ end
370
+
371
+ Phronomy::Agent::ExecutionChange.prepend(G3eChangeFaultScope)
372
+
373
+ def child_reply_loss(kind:, mode:)
374
+ raise ArgumentError, "Unsupported child boundary" unless %i[dispatch terminal].include?(kind)
375
+ raise ArgumentError, "Unsupported save outcome" unless %i[pre post].include?(mode)
376
+ lambda do |store, execution_id|
377
+ store.coordinator.singleton_class.prepend(G3eAtomicFault)
378
+ store.coordinator.instance_variable_set(:@g3e_child_fault,
379
+ {kind: kind, mode: mode, execution_id: execution_id, armed: true, readback: false})
380
+ end
381
+ end
382
+ ```
383
+
384
+ ## Identify the behavior improvement and its limits
385
+
386
+ G3e adds retained recovery for supported correlated child boundaries while preserving ordinary behavior and existing public value shapes. It removes the need to discard the original child and reconstruct work merely because a save response was lost. The application still chooses retry timing, holds its external claim and coordinates parent progression.
387
+
388
+ For example, a failed original child approval observation stays failed after its later dispatch recovery succeeds. The application receives a separate continuing execution observation and can finish the original report without approving or invoking it again. A pending receipt is not converted into success to simplify application source.
389
+
390
+ | Case | Applied G3d baseline | G3e candidate |
391
+ | --- | --- | --- |
392
+ | Ordinary correlated child | Existing reserved child execution and parent import | Same application contract |
393
+ | Follow-up child dispatch with unknown save outcome | No retained dispatch capability on the reserved path; parent can remain pending | Original child retains the proposal and exposes existing dispatch recovery |
394
+ | Actual child terminal with unknown pre-state | Alternate error path can relinquish local child ownership without retained terminal recovery | Retained child obligation and explicit guarded terminal save retry |
395
+ | Saved child terminal with lost response | A parent may read/import the terminal result independently | Parent observation remains independent; retained child recovery still requires local application/release |
396
+ | Later child state conflicts with cached dispatch proof | No correlated retained continuation protocol | Historical post knowledge is preserved but new admission is withheld |
397
+ | Parent participant save or Handoff uncertainty | Separate existing contract | Still a separate residual obligation |
398
+
399
+ ## Preserve symmetry and responsibility boundaries
400
+
401
+ The supported child path reuses the same domain operations as an ordinary Agent. Dispatch and terminal retain different completion semantics because one permits future work and the other records finished work. Parent import remains a coordinating-domain decision, rather than an extra flag on either child receipt.
402
+
403
+ For example, giving `DispatchRecoveryResult` a terminal-style `released` verdict would imply a running child no longer needs ownership. Giving terminal recovery a new execution task would obscure its already-computed result. The existing shapes preserve these distinctions without new methods or RBS fields.
404
+
405
+ | Comparison | Decision and reason |
406
+ | --- | --- |
407
+ | Ordinary versus correlated child operation names | Adopt unchanged names and argument defaults |
408
+ | Sync versus async | Adopt existing pairs and reentrancy/observation rules |
409
+ | Dispatch versus terminal pre-state | Retain both obligations until explicit captured-write retry; neither starts a replacement request |
410
+ | Approval versus dispatch/terminal pre-state | Preserve approval's separate restored-wait meaning; no automatic repeated human decision |
411
+ | Parent result import versus child recovery | Keep separate existing owners and operations |
412
+ | New generic child-recovery manager or parent facade | Reject: existing child capability and domain methods are sufficient for the supported use case |
413
+ | Arbitrary child discovery from parent errors | Defer: not required for the named public-approval-request scenario and not implemented here |
414
+
415
+ ## Validate the selected boundaries
416
+
417
+ Acceptance combines exact baseline comparisons, real Runtime fault cases and bounded model properties. Each category checks a different claim: application equivalence, concrete saved-state/ownership behavior, or the abstract protocol under explicit premises.
418
+
419
+ For example, the documented normal report must match on baseline and candidate, while each dispatch/terminal pre/post loss must preserve one Tool effect and complete only through the original child capability. A negative model that releases a pending owner or permits a second dispatch must produce its expected counterexample.
420
+
421
+ The separate Team fault matrix covers coordinator/worker roles across Provider, Tool and actual terminal pre/post uncertainty (12 cases); it does not repeat a Team coordinator or worker to reconstruct accepted child work. General Workflow regression is compatibility evidence, not a new reserved-child fault claim.
422
+
423
+ The documented application checks comprise seven Runtime cases (ordinary; dispatch and terminal pre/post; and two separately authorized retry decisions) plus one complete-source consistency check. Final measured results and source hashes are recorded in the delivery evidence. The standalone [dispatch](agent-dispatch-recovery.md), [terminal](agent-terminal-recovery.md), and [terminal submission](agent-terminal-submission-recovery.md) contracts continue to define common receipt, physical-completion and admission conditions.
424
+
425
+ The scope is follow-up dispatch preparation and actual success/failure/cancellation terminal saves on supported original live children. Initial reserved admission, initial preparation, establishing an approval/coordination wait, parent participant commits, Handoff, custom execution extensions, stopped-owner administration and selected durable-backend acceptance are not completed by this eligibility change. A successful approval-driven application is not exhaustive proof of all reserved ownership paths.