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,308 @@
1
+ # Original-owner Agent dispatch preparation recovery
2
+
3
+ G3c retains pre-dispatch preparation across an uncertain save or a rejected setup-failure notification. The Agent owns the execution and its next transition; persistence establishes whether the captured change was saved; the Runtime accounts for physical work and serializes application by the same owner. Caller observation, saved permission and actual external dispatch remain separate facts.
4
+
5
+ For example, a report Agent has already read a Tool result and prepares the next Provider input. The dispatch-barrier transaction commits, but its response and immediate readback are unavailable. The same live Agent needs a way to establish that saved fact and continue the original input. Calling `invoke` again or rebuilding Provider preparation could repeat the report read, application hooks or context Policy.
6
+
7
+ Baseline: G3a2 `fba34a0ed4c98da94bfeaad4946dfee234f4b0e0`. This document describes the G3c implementation candidate. Contract concept v55 and foundation v48 identify the responsible boundaries; the delivery evidence records the final source, architecture review and validation results. Same-process failed-Runtime management remains a separate completion group.
8
+
9
+ The later [correlated-child execution recovery contract](agent-child-execution-recovery.md) extends supported follow-up dispatch to original correlated child owners, with a fresh child-footprint check before new admission. The later [native parent dispatch contract](native-parent-dispatch-recovery.md) adds the native coordinator's bounded captured Provider/Tool prerequisites, with opaque domain persistence evidence and fresh child-authority checks. The [synchronous participant custody contract](synchronous-participant-contract.md) additionally retains ordinary participant uncertainty, including participants without an execution extension, without granting callback replay. Initial admission remains a separate contract.
10
+
11
+ ## Keep a captured preparation and an external effect separate
12
+
13
+ The retained preparation contains the original input and the complete before/after save evidence, tied to its execution, session and operation identities. A successful readback may establish saved permission, but cannot establish whether an external request was admitted or completed. Only an original continuation whose first dispatch is still authorized may advance.
14
+
15
+ For example, a Tool batch with a saved dispatch record must not be regenerated from a later conversation snapshot. If any corresponding Tool dispatch is already admitted or uncertain, its external outcome needs the existing external-outcome recovery contract; this API does not infer that outcome by invoking the Tool again.
16
+
17
+ | Responsibility | Owner and evidence | Not implied by success |
18
+ | --- | --- | --- |
19
+ | Caller observation | One original or later `TaskResult` and its received result/error | Saved outcome, worker termination or release of the execution |
20
+ | Barrier persistence | Complete root, execution, journal, content and cancellation evidence under the original Store guard | Owner application or external dispatch |
21
+ | Original continuation | Original Agent, exact live session and captured prepared input or batch | Provider/Tool success after continuation admission |
22
+ | Physical work | Original preparation and each explicit recovery worker | Whole Agent job completion |
23
+ | External outcome | Existing Provider/Tool execution and recovery contracts | Permission to replay because a barrier was saved |
24
+
25
+ A confirmed pre-state remains retained. The application may explicitly request a guarded retry of the complete captured write proposal. That retry neither reruns preparation hooks/Policy nor reconstructs the input from mutable live state. A missing or incomplete proposal cannot be repaired by repeating preparation through this API.
26
+
27
+ For example, after a rolled-back barrier, `reconcile_dispatch` reports `confirmed_pre` without invoking the Tool. A later explicit `retry_dispatch` can save the held proposal when the original preconditions still match. If cancellation or another writer changed those preconditions, the retry must report unresolved responsibility rather than apply stale writes.
28
+
29
+ ## Observe through the original Agent
30
+
31
+ A process-local recovery capability identifies one operation held by one exact Agent incarnation. Public identifiers are diagnostic; neither a copied handle nor another Agent with the same durable ID is recovery authority. Each asynchronous method returns a fresh observation, and its synchronous counterpart waits only on a permitted host thread.
32
+
33
+ For example, an `invoke_async` observation can end with `DispatchRecoveryError`. A later reconciliation can resume the same execution while that original observation remains failed. The new receipt supplies a different execution observation; it does not revive the old invocation or create a replacement Agent.
34
+
35
+ | Public method or value | Contract |
36
+ | --- | --- |
37
+ | `pending_dispatch_recovery(execution_id:)` | Local lookup on the exact Agent's existing registry. Requires a nonempty String; performs no I/O and creates no Runtime. |
38
+ | `reconcile_dispatch_async(recovery:)` / `reconcile_dispatch(recovery:)` | Read the barrier and, when all guards permit, apply confirmed post-state and continue the original work. Does not retry writes. |
39
+ | `retry_dispatch_async(recovery:)` / `retry_dispatch(recovery:)` | Explicit guarded retry of the already captured barrier writes, followed by the same application/continuation checks. |
40
+ | `DispatchRecovery` | Frozen, privately constructed capability with `agent_id`, `execution_id`, `recovery_id`, and `dispatch_kind` (`provider` or `tool`). |
41
+ | `DispatchRecoveryError` | Code `agent.dispatch_recovery`; preserves the capability, the original error and the immediate cause. It is not a saved job-failure verdict. |
42
+
43
+ After a stream observation fails with retained dispatch responsibility, its original stream callback is closed and is not resumed by reconciliation. The recovered execution task observes the aggregate result; this API does not create a replacement stream subscriber. The configured approval listener remains a separate application policy callback.
44
+
45
+ For example, a stream caller can receive some earlier events and then a dispatch recovery error. Later reconciliation may finish the same execution, but does not replay or deliver later events through that failed stream callback.
46
+
47
+ Cancelling a recovery observation does not cancel its retained work. The existing execution cancellation API is the control operation. Cancellation is checked again before continuation dispatch; restoring a saved barrier never overrides authoritative cancellation. Resolution removes pending lookup, but a held capability can still report its final receipt without redispatch.
48
+
49
+ For example, a caller can time out while awaiting a recovery read, retain the Agent and capability, and explicitly observe later. It must not submit another report request merely because that observation timed out. Likewise, `physical_complete?` on the recovery receipt does not mean the resumed report Tool has stopped.
50
+
51
+ ## Read the receipt as evidence rather than a business result
52
+
53
+ The immutable receipt separates saved outcome, owner application, continuation handoff and preparation/recovery worker completion. Only the execution observation reports the continuing job's result. Resolving the barrier obligation leaves that same job under its ordinary ownership and release conditions.
54
+
55
+ For example, confirmed post-state can be applied while continuation remains pending after a scheduling failure. A subsequent receipt can report `resumed` while the Provider is still running. Cancellation or a post-save input materialization error can instead send the original FSM through its existing terminal path without making a Provider call.
56
+
57
+ | Reader | Meaning |
58
+ | --- | --- |
59
+ | `outcome` | `confirmed_pre`, `confirmed_post`, `not_prepared`, `unresolved` or `unavailable`. `not_prepared` requires positive evidence that preparation ended before entering the barrier; missing proof alone is insufficient. |
60
+ | `application_state` | `pending` or `applied` by the original Agent. Confirmed post-state or positively established pre-barrier failure can be applied; confirmed pre-state cannot. |
61
+ | `continuation_state` | `pending`, `resumed` or `stopped`. Resumed hands off a confirmed barrier continuation, including cancellation/error. Stopped hands off only a positively established pre-barrier failure notification. Neither proves whole-job termination or external success. |
62
+ | `physical_complete?` | Original preparation and recovery workers have stopped; continued business work may still be active. |
63
+ | `resolved?` | A confirmed barrier or positively established pre-barrier failure has been applied, preparation/recovery work is physically complete, and its resumed/stopped continuation has been handed off. |
64
+ | `revision` | The exact confirmed pre/post execution revision; nil for `not_prepared` and unclassified persistence. |
65
+ | `execution_task` | A fresh independent execution observation, available only after applied/resumed post-state or applied/stopped pre-barrier failure. It observes the same job, including its original setup error. |
66
+ | `error` | Recovery/read/application error. The continuing job's own error is observed through `execution_task`. |
67
+
68
+ A `not_prepared` receipt requires an observed preparation boundary: the barrier was never entered and the original worker physically ended, or the execution mechanism positively refused admission before a worker could begin. It does not classify storage rollback from missing evidence. Once the owner adopts that known failure, a rejected notification can leave application applied while continuation remains pending. Only the exact retained failure notification is redelivered; hooks, Policy, preparation and business dispatch are never repeated.
69
+
70
+ For example, an input hook fails before `ExecutionChange.perform`, and its `llm_setup_failed` notification is explicitly refused. Recovery can later deliver that same failure and return `not_prepared`/`stopped` with an execution observation of the original error. A barrier that may have started but left no complete proof must remain unresolved instead.
71
+
72
+ A confirmed pre-state cannot be marked applied or resumed. A saved post-state alone also cannot create an execution observer before the handoff. These restrictions keep the public value shape consistent with the retained owner protocol.
73
+
74
+ For example, constructing a receipt with `confirmed_pre` plus `resumed` is rejected. A valid resolved receipt can still contain an execution TaskResult that subsequently fails; that later failure does not rewrite the earlier persistence proof or falsely reopen the original caller's closed observation.
75
+
76
+ ## Preserve the ordinary application
77
+
78
+ The ordinary report application has the same inputs, Provider/Tool effects, output, persistence and observation contract before and after G3c. Its adapter is deterministic and sends no network request; the Agent, Store and Runtime are real. The extra record reads in the function measure behavior and are not a proposed application API.
79
+
80
+ For example, both versions read one report Tool and return `report ready` after two Provider completions. Run one copy of the shared setup, either complete function below, and the shared driver. The delivery compares actual baseline and candidate reports; the source listings are tied to the executed helper.
81
+
82
+ ### Shared application setup
83
+
84
+ The fixture defines the report Tool, the Agent that exposes it, and the Provider adapter used by both versions.
85
+
86
+ For example, the first Provider response requests `read_dispatch_report`; the second returns the final report text. The Tool counter detects any duplicate effect.
87
+
88
+ <!-- example: shared-setup -->
89
+ ```ruby
90
+ # frozen_string_literal: true
91
+
92
+ require "phronomy"
93
+ require "json"
94
+
95
+ class G3cReportTool < Phronomy::Tool::Base
96
+ tool_name "read_dispatch_report"
97
+ description "Read one report through a deterministic fixture"
98
+ class << self
99
+ attr_accessor :calls
100
+ end
101
+
102
+ def execute
103
+ self.class.calls += 1
104
+ "report content"
105
+ end
106
+ end
107
+
108
+ class G3cReportAgent < Phronomy::Agent::Base
109
+ agent_definition id: "dispatch-report", version: 1
110
+ model "offline-model"
111
+ tools G3cReportTool => nil
112
+ end
113
+
114
+ class G3cReportAdapter < Phronomy::LLMAdapter::Base
115
+ attr_reader :calls
116
+
117
+ def initialize
118
+ @calls = 0
119
+ end
120
+
121
+ def perform_complete(_request, cancellation_token:)
122
+ cancellation_token&.raise_if_cancelled!
123
+ @calls += 1
124
+ if @calls == 1
125
+ Phronomy::LLMAdapter::Response.new(tool_calls: [
126
+ Phronomy::Tool::CallRequest.new(id: "report-read", name: "read_dispatch_report", arguments: {})
127
+ ], finish_reason: :tool_calls)
128
+ else
129
+ Phronomy::LLMAdapter::Response.new(content: "report ready", finish_reason: :stop)
130
+ end
131
+ end
132
+ end
133
+ ```
134
+
135
+ ### Complete before-and-after functions
136
+
137
+ The same function starts one invocation, observes its result and records the saved execution and call counts. The comparison is equivalent only for the ordinary successful path; the intended fault-path changes are listed separately below.
138
+
139
+ For example, neither side requires application-managed dispatch identity or Store reconciliation when no failure occurs.
140
+
141
+ <table>
142
+ <thead><tr><th>Before: G3a2 baseline</th><th>After: G3c candidate</th></tr></thead>
143
+ <tbody><tr><td>
144
+ <!-- example: normal-before -->
145
+ <pre><code># The ordinary application requests one report and observes its final result.
146
+ # The adapter is deterministic; the Agent, Store and Runtime are real.
147
+ def run_dispatch_report
148
+ G3cReportTool.calls = 0
149
+ adapter = G3cReportAdapter.new
150
+ Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
151
+ store = Phronomy::PersistenceComposition.in_memory.agent
152
+ agent = G3cReportAgent.create(agent_id: &quot;dispatch-report&quot;, persistence: store)
153
+ invocation = agent.invoke_async(&quot;Read the report&quot;)
154
+ result = invocation.wait_result(timeout: 5)
155
+ execution = store.executions.load(result.fetch(:execution_id))
156
+ {
157
+ output: result.fetch(:output), execution_status: execution.status,
158
+ execution_revision: execution.execution_revision,
159
+ agent_revision: agent.agent_root.agent_revision,
160
+ root_status: agent.agent_root.lifecycle_status,
161
+ provider_calls: adapter.calls, tool_calls: G3cReportTool.calls,
162
+ invocation_logical_complete: invocation.done?,
163
+ invocation_physical_complete: invocation.physical_complete?
164
+ }
165
+ end</code></pre>
166
+ </td><td>
167
+ <!-- example: normal-after -->
168
+ <pre><code># The ordinary application requests one report and observes its final result.
169
+ # The adapter is deterministic; the Agent, Store and Runtime are real.
170
+ def run_dispatch_report
171
+ G3cReportTool.calls = 0
172
+ adapter = G3cReportAdapter.new
173
+ Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
174
+ store = Phronomy::PersistenceComposition.in_memory.agent
175
+ agent = G3cReportAgent.create(agent_id: &quot;dispatch-report&quot;, persistence: store)
176
+ invocation = agent.invoke_async(&quot;Read the report&quot;)
177
+ result = invocation.wait_result(timeout: 5)
178
+ execution = store.executions.load(result.fetch(:execution_id))
179
+ {
180
+ output: result.fetch(:output), execution_status: execution.status,
181
+ execution_revision: execution.execution_revision,
182
+ agent_revision: agent.agent_root.agent_revision,
183
+ root_status: agent.agent_root.lifecycle_status,
184
+ provider_calls: adapter.calls, tool_calls: G3cReportTool.calls,
185
+ invocation_logical_complete: invocation.done?,
186
+ invocation_physical_complete: invocation.physical_complete?
187
+ }
188
+ end</code></pre>
189
+ </td></tr></tbody>
190
+ </table>
191
+
192
+ ### Shared measurement driver
193
+
194
+ The driver validates the business output and call counts, writes the measured report and records the loaded source path. The caller selects output paths with `G3C_NORMAL_REPORT` and `G3C_NORMAL_SOURCE`.
195
+
196
+ For example, the baseline report must identify `g3c-baseline` as its loaded gem location, while the candidate report identifies the changed checkout. Equal hard-coded expected JSON would not establish that comparison.
197
+
198
+ <!-- example: normal-driver -->
199
+ ```ruby
200
+ if $PROGRAM_NAME == __FILE__
201
+ begin
202
+ report = run_dispatch_report
203
+ raise "Unexpected output" unless report[:output] == "report ready"
204
+ raise "Unexpected business replay" unless report[:provider_calls] == 2 && report[:tool_calls] == 1
205
+ File.write(ENV.fetch("G3C_NORMAL_REPORT"), JSON.pretty_generate(report) + "\n")
206
+ File.write(ENV.fetch("G3C_NORMAL_SOURCE"), JSON.pretty_generate({
207
+ application: method(:run_dispatch_report).source_location,
208
+ preparation: Phronomy::Agent::DispatchPreparation.instance_method(:prepare_provider).source_location,
209
+ gem: Gem.loaded_specs.fetch("phronomy").full_gem_path
210
+ }) + "\n")
211
+ ensure
212
+ Phronomy.reset_runtime!
213
+ end
214
+ end
215
+ ```
216
+
217
+ ## Add recovery policy only to the uncertain path
218
+
219
+ The complete helper below starts an invocation once and handles its retained dispatch error. It performs one reconciliation and, only with explicit caller policy, one guarded retry for confirmed pre-state. A pending result preserves the capability for a later observation; it is not permission to invoke the original request again.
220
+
221
+ For example, a read-only report application can choose `retry_confirmed_pre: true` for the captured barrier writes. A caller that needs separate approval for each write attempt leaves the default false and obtains `recovery_pending`. Neither choice retries the report Tool or Provider operation.
222
+
223
+ <!-- example: recovery-handler -->
224
+ ```ruby
225
+ # frozen_string_literal: true
226
+
227
+ require "phronomy"
228
+
229
+ # Observe one retained obligation. The caller chooses whether one confirmed
230
+ # pre-state may receive an explicit persistence-only retry. There is no loop,
231
+ # replacement Agent, provider retry, Tool retry or repeated preparation here.
232
+ def observe_dispatch_recovery(agent:, recovery:, retry_confirmed_pre: false)
233
+ receipt = agent.reconcile_dispatch(recovery: recovery)
234
+ if retry_confirmed_pre && receipt.outcome == :confirmed_pre && !receipt.resolved?
235
+ receipt = agent.retry_dispatch(recovery: recovery)
236
+ end
237
+ if receipt.resolved?
238
+ {state: receipt.continuation_state, recovery: recovery, receipt: receipt,
239
+ execution_task: receipt.execution_task}.freeze
240
+ else
241
+ {state: :recovery_pending, recovery: recovery, receipt: receipt}.freeze
242
+ end
243
+ end
244
+
245
+ # Start once, then observe the same execution. After recovery_pending, retain
246
+ # the Agent and capability and call observe_dispatch_recovery again when useful;
247
+ # do not call this start helper again for the unresolved original request.
248
+ def invoke_with_dispatch_recovery(agent:, input:, retry_confirmed_pre: false)
249
+ result = agent.invoke(input)
250
+ {state: :completed, result: result}.freeze
251
+ rescue Phronomy::Agent::DispatchRecoveryError => failure
252
+ observe_dispatch_recovery(agent: agent, recovery: failure.recovery,
253
+ retry_confirmed_pre: retry_confirmed_pre)
254
+ end
255
+ ```
256
+
257
+ The application retains its Agent and unresolved capability, decides when another observation is useful and whether to permit the persistence-only retry, and observes any returned execution task. Phronomy owns the complete proof, original continuation identity, worker accounting and exactly one local application decision. This API does not remove application policy or promise exactly-once external effects.
258
+
259
+ For example, after `resumed` or `stopped`, call `execution_task.wait_result` to receive the same job's ordinary result/error. The helper uses the actual continuation state rather than labelling a stopped setup as resumed work. After `recovery_pending`, call `observe_dispatch_recovery` with the same capability. Calling `invoke_with_dispatch_recovery` again would start another request and is deliberately not the pending path.
260
+
261
+ | Trigger | G3a2 baseline | G3c intentional change |
262
+ | --- | --- | --- |
263
+ | Ordinary success | Original invoke/stream result and effects | Preserved ordinary contract |
264
+ | Saved barrier, lost response and unavailable immediate readback | Admission retained as recovery-required without a usable dispatch recovery API; original observation may remain pending | Typed retained error and independent explicit observation; confirmed proof can advance the original continuation once |
265
+ | Confirmed rollback/pre-state | No captured-proposal public dispatch retry | Confirmed pre-state remains pending; explicit retry writes only the original captured proposal under guards |
266
+ | Read unavailable or conflicting state | Original failure cannot classify persistence | Explicit unavailable/unresolved receipt with retained responsibility |
267
+ | Ready delivery rejected or delayed | Completion does not by itself repair the original owner | Physical facts and captured proof remain available to an explicit later recovery observation |
268
+ | Positively known pre-barrier failure and rejected setup notification | A failed setup notification may leave the original FSM awaiting progress | `not_prepared` and retained failure notification; successful handoff reports `stopped` without repeating preparation |
269
+ | Original Runtime stopped | A different Runtime cannot repair its local owner safely | Unavailable/retained responsibility; no claim of successful transfer or release |
270
+
271
+ ## Preserve symmetry and domain responsibility
272
+
273
+ The new operations follow existing retained-owner recovery naming, identity validation, observation isolation and host-thread waiting. Differences reflect the continuation being recovered: terminal proof can release a terminal job, approval proof can restore a human wait, and dispatch proof can permit the original next step.
274
+
275
+ For example, approval confirmed pre-state can restore the same approval request without rewriting it. Dispatch confirmed pre-state has no human wait to restore, so it remains retained until the application explicitly permits a guarded retry. The terminal submission retry is not a generic template for repeating Provider preparation.
276
+
277
+ | Aspect | Terminal recovery | Approval recovery | Dispatch recovery decision |
278
+ | --- | --- | --- | --- |
279
+ | Local capability and lookup | Original owner, process-local | Original owner, process-local | Adopt the same exact-incarnation authority |
280
+ | Sync/async observation | `reconcile_terminal` pair | `reconcile_approval` pair | Adopt `reconcile_dispatch` pair |
281
+ | Captured-write retry | Explicit `retry_terminal` pair | No automatic repeated human decision | Adopt explicit `retry_dispatch` pair |
282
+ | Initial submission retry | Separate mechanism proof and API | Original approval wait can be restored after proved non-admission | Defer; no preparation rerun. Positively established pre-barrier failure can redeliver only its exact failed-setup notification |
283
+ | Confirmed pre-state | Retain terminal obligation | Restore original approval wait | Retain captured barrier; no invented restored state |
284
+ | Continued work observation | Terminal execution observation | Fresh execution task after resumed decision | Fresh execution task after resumed barrier or stopped pre-barrier failure |
285
+ | Release | Requires terminal and physical conditions | Approval resolution does not release the job | Dispatch resolution does not release the job |
286
+ | Cross-process takeover | Not provided by the capability | Not provided by the capability | Not provided by the capability |
287
+
288
+ As of 2026-11-28, dispatch recovery uses the same C13 `RetainedAttempts` manager and `AttemptCompletion` evidence record as Agent outcome/approval and Workflow terminal recovery. Domain-specific save authority, cancellation checks, continuation admission and release remain with their current owners. A unified public Job API is not required. See [shared retained-attempt management](retained-attempts.md).
289
+
290
+ For example, using a terminal helper that releases Agent admission after successful dispatch proof would lose an executing job's responsibility. Reusing `AttemptCompletion` to record a stopped recovery worker preserves the domain boundary without adopting that incorrect release policy.
291
+
292
+ ## Bound the supported recovery conditions
293
+
294
+ The original G3c stage retains the live standalone Agent, its exact Store and captured preparation. G3e adds the supported correlated-child follow-up dispatch paths described in [child execution recovery](agent-child-execution-recovery.md). G3g adds the bounded native parent participant dispatch paths described in [native parent dispatch recovery](native-parent-dispatch-recovery.md). [Handoff dispatch](handoff-dispatch-recovery.md) and [synchronous participant custody](synchronous-participant-contract.md) define later bounded extensions. Ordinary public callbacks do not establish the private proof required for a fresh continuation after the original observer closes; absent that proof, the operation stays unavailable and retained. Other hosted profiles and initial reserved-admission paths require their own applicability evidence; the capability never grants takeover. A draining Runtime may process already retained work; full administration after Runtime failure remains a separate completion group.
295
+
296
+ For example, another Agent with the same execution identifier cannot use a copied `DispatchRecovery` to dispatch the prepared Tool. The original owner must still satisfy identity, session, revision, cancellation and non-dispatch conditions before it continues.
297
+
298
+ The Store must establish prior transaction settlement, authoritative ordered readback, guarded exclusion and atomicity. Physical worker termination or an InMemory fixture alone does not establish those assumptions for a remote database. Existing external-effect uncertainty remains separate, and missing evidence remains retained rather than guessed successful.
299
+
300
+ For example, a backend that can commit the old transaction after readback needs an ordering mechanism before a read can prove confirmed pre-state. Repeatedly reading until a convenient value appears is not that mechanism.
301
+
302
+ ## Validate models, implementation and application separately
303
+
304
+ The finite [dispatch preparation model](../../spec/models/dispatch_preparation_recovery/README.md) tests explicit safety and conditional progress assumptions; real Runtime fault tests exercise the implementation; complete application comparisons check the public use case. The delivery records their exact scope instead of treating one category as proof of the others.
305
+
306
+ For example, a model mutation that permits two dispatches must fail its safety check. A real fault test must also lose the dispatch save response, delay or reject Ready delivery, obtain the held capability, and establish the observed Provider/Tool call counts and responsibility retention.
307
+
308
+ The delivery includes baseline reproductions, Provider/Tool pre/post/conflicting/unavailable evidence cases, observer and physical-work separation, duplicate/stale recovery requests, cancellation before dispatch and post-save materialization failure. It separately records unsupported or untested backend/ownership profiles. Passing the model does not constitute a refinement proof for all Ruby code or an exactly-once guarantee across external services.