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,636 @@
1
+ # Finish retained outcome materialization without repeating business preparation
2
+
3
+ Agent owns accepted execution results and the observations returned to callers. Persistence owns committed facts, and MultiAgent owns native child relationships. A completed encoding must remain available when a later immutable-content read fails, so recovery can finish the known presentation work without asking the Provider, Tool or application conversion to run again.
4
+
5
+ For example, a report parent calls a Tool once, receives its final answer, and encodes its result and audit records. Reading an earlier transcript message then fails. The new private checkpoint retains those encoded facts and the fixed inputs for transcript reconstruction. A later explicit recovery can finish the read and save the same report.
6
+
7
+ > Historical G3k design and validation: the complete-input String-copy failure described below was a real boundary of that candidate. G3l removes the unused semantic mirrors from the detached persistence proof; see [detached outcome proof projection](detached-outcome-proof-projection.md). The original semantic outcome remains with its owner, and captured durable observation remains separate. The examples and G3k results below are preserved as historical evidence; they do not establish that the repaired implementation must invoke that redundant copy. General complete-input failure and one-shot protection remain distinct concerns.
8
+
9
+ This document compares applied G3j `9402709cd0ab4275825e550f3d6112198e5febe6` with the G3k candidate. Contract concept v55 and foundation v48 define the current ownership boundaries. [Native preparation](native-outcome-preparation.md), [native outcome recovery](native-parent-outcome-recovery.md) and [captured publication](retained-outcome-publication.md) remain the preceding contracts. The new stage adds no public API, participant SPI, automatic retry policy or general preparation-replay permission.
10
+
11
+ ## Encoded intent and result presentation are different stages
12
+
13
+ The native outcome worker prepares domain facts once, then reconstructs the ordinary transcript from captured and historical content. Encoded save intent can be complete before ordinary presentation is complete. A separate retained stage makes that distinction explicit without weakening complete persistence evidence.
14
+
15
+ For the report, final answer bytes, record identities, execution/root records and native retention facts have already been chosen before an old transcript message is read. Rereading that message by immutable reference is permitted. Calling the original output's conversion again, revalidating its schema or selecting new child acknowledgements is not.
16
+
17
+ | Responsibility | Captured or repeated work | Rule |
18
+ | --- | --- | --- |
19
+ | Business execution | Provider calls, Tool effects, output filtering and semantic validation | Do not repeat during outcome recovery. |
20
+ | Native planning | Planned child/approval/cancellation/retention facts | Capture once; do not rerun the planning policy to finish presentation. |
21
+ | Encoding | Output, diagnostics, audit content, record IDs and times | Reuse captured bytes and values. |
22
+ | Ordinary transcript presentation | Fixed root/record inputs, captured new content and immutable historical content | May finish on a worker after the original worker physically settles. |
23
+ | Complete persistence input | Full semantic outcome plus exact before/after facts and writes | Keep its strong contract. Construct it once and cache success or failure; copying an application-owned value is not generally repeatable. |
24
+ | Save confirmation and write retry | Exact readback, original Store/owner and current native authority | Reconcile reads; a caller-selected retry writes only an eligible captured plan. |
25
+ | Publication and release | Complete local result and G3j captured observation | Apply only on the original EventLoop under existing ownership rules. |
26
+
27
+ The private `OutcomePreparation` holds the intermediate data separately from `TerminalPersistenceEvidence::CapturedInput`. `ExecutionChange` retains it before hydration, and `OutcomeRecoveryOperation` completes it through the existing worker lane after physical settlement. Its read adapter uses retained new content and fresh historical content access, checking reference digests; it does not retain a transaction scope or call the native planning policy again.
28
+
29
+ Only the completed-result transcript path gains the new retained stage. Existing failure, approval and coordination preparation does not gain permission to repeat diagnostics or request conversion. After hydration succeeds, complete-input construction is attempted once: a String subclass can execute application code during copying, so constructor failure remains retained without reentry. If the original read failed before that step, recovery may execute the constructor for the first time. The guarantee is no repeated constructor execution, not an assertion that every recovery-worker operation is application-code-free. An already completed input still supports the existing data-only proof reconstruction.
30
+
31
+ The initial successful path still materializes its ordinary result before physical writes. Recovery does not retain a closed transaction reader or an arbitrary application continuation. Historical reads use the supplied original Store; new content comes from the retained encoded writes. A permanently unavailable or corrupt immutable reference remains an unresolved read failure.
32
+
33
+ ## Application scenario and behavioral contract
34
+
35
+ The application owns retry permission, observation and retention of unresolved responsibility. The framework owns the continuation of its explicitly classified immutable-content work and the fidelity of the result. The application must not reconstruct a parallel report or guess whether another Provider/Tool execution is safe.
36
+
37
+ For example, the report application uses a real Runtime and in-memory Persistence with an offline counted Provider and one counted Tool. A native parent declares a reviewer but does not dispatch it in this bounded example. The fixture makes a historical content read fail during final transcript materialization, after encoding is complete.
38
+
39
+ | Aspect | Shared contract |
40
+ | --- | --- |
41
+ | Input/output | Same report request, final answer, Tool result and existing result shapes. |
42
+ | Ordering/effects | Two Provider calls and one Tool effect; no semantic replay during recovery. |
43
+ | Errors | Original failed observation stays closed; later recovery produces a fresh observation. |
44
+ | Persistence | Actual transactions, readback and captured-write retry. Read faults are injected at the real repository boundary. |
45
+ | Ownership | Same original retained owner; release only after confirmed application and physical settlement. |
46
+ | Cancellation | Observer cancellation does not authorize overlapping work, cancel shared recovery or discard custody. |
47
+ | Retry policy | Only explicit permission after confirmed pre-state allows captured writes. |
48
+ | Cleanup | Successful cleanup and retained unresolved responsibility are reported separately; test process exit is not a recovery mechanism. |
49
+ | Public result shape | Ordinary invocation includes messages; exact resume returns its existing stored-result shape; recovery returns its existing execution observation. |
50
+
51
+ Ordinary behavior is equivalent. The intended failure behavior changes as follows.
52
+
53
+ | Condition | Before: applied G3j | After: G3k candidate |
54
+ | --- | --- | --- |
55
+ | No fault | Ordinary complete report and cleanup. | Same output, transcript, counts and cleanup. |
56
+ | Transient historical read failure after encoding | Original owner remains unavailable with no complete proposal to recover. | Retained stage can finish hydration; reconcile can report confirmed pre-state without writes. |
57
+ | Explicit retry after successful hydration | No permitted continuation for the lost intermediate stage. | Existing exact-write retry can commit the retained report without business or encoding replay. |
58
+ | Caller declines retry | Retained unresolved responsibility. | Hydration/readback may establish confirmed pre-state, but the owner stays retained and no writes occur. |
59
+ | Content remains unavailable | Retained unresolved responsibility. | Same retained responsibility; no fabricated transcript or terminal result. |
60
+ | Opaque conversion fails before the new checkpoint | No generic replay or forced terminalization is justified. | Still outside this repair and remains residual group 1. |
61
+
62
+ ## Shared setup and ordinary execution
63
+
64
+ Both application versions use the same definitions and ordinary execution policy. The counted Provider and Tool expose accidental repeated work, while the complete result comparison protects ordinary caller-visible behavior.
65
+
66
+ For the report, the normal path waits for the final result, observes its stored counterpart and performs explicit cleanup. The two ordinary functions below are identical. The fixture is a test adaptation using existing public APIs, not a separate production application repository.
67
+
68
+ Copy shared setup, shared observation helpers, one normal-function column, one recovery-function column, the fixture and driver into one Ruby file in that order. All dependencies and policy are shown. Run one case per fresh process because the fixture instruments that process.
69
+
70
+ <!-- g3k-code:shared-setup -->
71
+ ```ruby
72
+ require "phronomy"
73
+ require "json"
74
+
75
+ class G3kReportError < Phronomy::Error
76
+ def initialize
77
+ super("The report source is unavailable", code: "report.source_unavailable")
78
+ end
79
+ end
80
+
81
+ class G3kReportOutput
82
+ def initialize(counts)
83
+ @counts = counts
84
+ end
85
+
86
+ def to_s
87
+ @counts[:output_conversion] += 1
88
+ "Report completed"
89
+ end
90
+ end
91
+
92
+ class G3kReportTool < Phronomy::Tool::Base
93
+ tool_name "read_report_source"
94
+ description "Read the report source once"
95
+ param :topic, type: :string, desc: "Report topic"
96
+ class << self
97
+ attr_accessor :counts
98
+ end
99
+
100
+ def execute(topic:)
101
+ self.class.counts[:tool] += 1
102
+ raise "Unexpected repeated Tool work" if self.class.counts[:tool] > 1
103
+ "Source facts for #{topic}"
104
+ end
105
+ end
106
+
107
+ class G3kReportWorker < Phronomy::Agent::Base
108
+ agent_definition id: "materialized-report-worker", version: 1
109
+ model "offline-model"
110
+ end
111
+
112
+ class G3kReportParent < Phronomy::MultiAgent::Orchestrator
113
+ agent_definition id: "materialized-report-parent", version: 1
114
+ model "offline-model"
115
+ tools G3kReportTool => nil
116
+ subagent :reviewer, G3kReportWorker
117
+ end
118
+
119
+ class G3kReportAdapter < Phronomy::LLMAdapter::Base
120
+ def initialize(counts, error: nil)
121
+ @counts, @error = counts, error
122
+ end
123
+
124
+ def perform_complete(_request, cancellation_token:)
125
+ cancellation_token&.raise_if_cancelled!
126
+ @counts[:provider] += 1
127
+ case @counts[:provider]
128
+ when 1
129
+ Phronomy::LLMAdapter::Response.new(finish_reason: :tool_calls, tool_calls: [
130
+ Phronomy::Tool::CallRequest.new(id: "report-source-call", name: "read_report_source", arguments: {topic: "retained outcomes"})
131
+ ])
132
+ when 2
133
+ raise @error if @error
134
+ Phronomy::LLMAdapter::Response.new(content: "Report source text", finish_reason: :stop)
135
+ else
136
+ raise "Unexpected repeated Provider work"
137
+ end
138
+ end
139
+ end
140
+
141
+ def build_report_service(failure: false)
142
+ counts = Hash.new(0)
143
+ error = failure ? G3kReportError.new : nil
144
+ G3kReportTool.counts = counts
145
+ adapter = G3kReportAdapter.new(counts, error: error)
146
+ Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
147
+ stores = Phronomy::PersistenceComposition.in_memory
148
+ parent = G3kReportParent.create(agent_id: "materialized-report-parent", persistence: stores.agent,
149
+ coordination_store: stores.multi_agent)
150
+ output = G3kReportOutput.new(counts)
151
+ parent.add_output_filter(->(_text) { output }) unless failure
152
+ {counts: counts, stores: stores, parent: parent, output: output, error: error}
153
+ end
154
+ ```
155
+
156
+
157
+ <!-- g3k-code:common-observation -->
158
+ ```ruby
159
+ def report_messages(messages)
160
+ messages.map do |message|
161
+ message.to_h.reject { |key, _value| key == "metadata" }
162
+ end
163
+ end
164
+
165
+ def stored_report(service)
166
+ parent = service.fetch(:parent)
167
+ fact = service.fetch(:stores).agent.observe_execution(agent_id: parent.agent_id,
168
+ execution_id: service.fetch(:execution_id))
169
+ {status: fact.status, result: fact.result, raw_output: fact.raw_output, error: fact.error}
170
+ end
171
+
172
+ def report_receipt(receipt)
173
+ execution = receipt.execution
174
+ {outcome: receipt.outcome, application_state: receipt.application_state,
175
+ ownership_state: receipt.ownership_state, saved_outcome: receipt.saved_outcome,
176
+ execution: execution && {status: execution.status, result: execution.result,
177
+ raw_output: execution.raw_output, error: execution.error}}
178
+ end
179
+
180
+ def release_report(service)
181
+ service.fetch(:parent).unload!
182
+ end
183
+
184
+ def start_report(service)
185
+ service.fetch(:parent).invoke_async("Prepare one report")
186
+ end
187
+ ```
188
+
189
+
190
+ <table>
191
+ <thead><tr><th>Before: applied G3j</th><th>After: G3k candidate</th></tr></thead>
192
+ <tbody><tr>
193
+ <td><pre><code><!-- g3k-code:normal-function:before -->def run_report(failure: false)
194
+ service = build_report_service(failure: failure)
195
+ report_fault(read_failure: :none, save_loss: :none).call(service)
196
+ original = start_report(service)
197
+ result = nil
198
+ original_error = nil
199
+ begin
200
+ result = original.wait_result(timeout: 8)
201
+ rescue G3kReportError =&gt; error
202
+ original_error = error
203
+ end
204
+ transcript = service.fetch(:parent).transcript_messages
205
+ messages_match = result &amp;&amp; result.fetch(:messages).map(&amp;:to_h) == transcript.map(&amp;:to_h)
206
+ {state: :ordinary, stored: stored_report(service),
207
+ original_business_error_preserved: failure ? original_error.equal?(service.fetch(:error)) : nil,
208
+ original_output_preserved: result &amp;&amp; result.fetch(:output).equal?(service.fetch(:output)),
209
+ complete_result_messages_match_transcript: messages_match,
210
+ transcript: report_messages(transcript), counts: service.fetch(:counts),
211
+ released: release_report(service)}
212
+ end
213
+ </code></pre></td>
214
+ <td><pre><code><!-- g3k-code:normal-function:after -->def run_report(failure: false)
215
+ service = build_report_service(failure: failure)
216
+ report_fault(read_failure: :none, save_loss: :none).call(service)
217
+ original = start_report(service)
218
+ result = nil
219
+ original_error = nil
220
+ begin
221
+ result = original.wait_result(timeout: 8)
222
+ rescue G3kReportError =&gt; error
223
+ original_error = error
224
+ end
225
+ transcript = service.fetch(:parent).transcript_messages
226
+ messages_match = result &amp;&amp; result.fetch(:messages).map(&amp;:to_h) == transcript.map(&amp;:to_h)
227
+ {state: :ordinary, stored: stored_report(service),
228
+ original_business_error_preserved: failure ? original_error.equal?(service.fetch(:error)) : nil,
229
+ original_output_preserved: result &amp;&amp; result.fetch(:output).equal?(service.fetch(:output)),
230
+ complete_result_messages_match_transcript: messages_match,
231
+ transcript: report_messages(transcript), counts: service.fetch(:counts),
232
+ released: release_report(service)}
233
+ end
234
+ </code></pre></td>
235
+ </tr></tbody>
236
+ </table>
237
+
238
+
239
+ ## Explicit recovery and retained responsibility
240
+
241
+ The recovery function observes the exact retained owner, permits writes only under the application's declared policy, and keeps the failed original observer separate from new observations. The new implementation makes the existing function useful after the bounded read fault without adding an application-specific recovery branch.
242
+
243
+ For the report, reconciliation can finish transcript hydration and return confirmed pre-state. If retry is permitted, the same captured report is saved. If retry is declined or the read remains unavailable, the function reports the retained owner and incomplete cleanup instead of declaring the job finished.
244
+
245
+ <table>
246
+ <thead><tr><th>Before: applied G3j</th><th>After: G3k candidate</th></tr></thead>
247
+ <tbody><tr>
248
+ <td><pre><code><!-- g3k-code:recovery-function:before --># Retrying a confirmed pre-state is an explicit persistence policy. It does not
249
+ # authorize repeating the report, output conversion or native preparation.
250
+ def run_report_with_recovery(fault:, retry_confirmed_pre: false, late_observer: false)
251
+ service = build_report_service
252
+ fault.call(service)
253
+ parent = service.fetch(:parent)
254
+ original = start_report(service)
255
+ original_failure = nil
256
+ begin
257
+ original.wait_result(timeout: 8)
258
+ rescue Phronomy::Agent::OutcomeRecoveryError =&gt; error
259
+ original_failure = error
260
+ end
261
+ raise "Expected an ambiguous report observation" unless original_failure
262
+ recovery = original_failure.recovery
263
+ raise "Unexpected retained owner" unless parent.pending_outcome_recovery(execution_id: service.fetch(:execution_id)).equal?(recovery)
264
+ counts_after_failure = service.fetch(:counts).dup
265
+ resumed = late_observer ? parent.resume_async(service.fetch(:execution_id)) : nil
266
+ reconciled = parent.reconcile_outcome(recovery: recovery)
267
+ after_reconcile = stored_report(service)
268
+ first = reconciled
269
+ if first.outcome == :confirmed_pre &amp;&amp; retry_confirmed_pre
270
+ first = parent.retry_outcome(recovery: recovery)
271
+ end
272
+ second = parent.reconcile_outcome(recovery: recovery)
273
+ begin
274
+ original.wait_result(timeout: 8)
275
+ raise "Original failed observation reopened"
276
+ rescue Phronomy::Agent::OutcomeRecoveryError =&gt; error
277
+ raise "Original observation changed" unless error.equal?(original_failure)
278
+ end
279
+ released = first.ownership_state == :released
280
+ resumed_result = resumed.wait_result(timeout: 8) if resumed &amp;&amp; released
281
+ transcript = released ? parent.transcript_messages : nil
282
+ release_report(service) if released
283
+ {state: released ? :recovered : :retained, stored: stored_report(service),
284
+ reconciliation: report_receipt(reconciled), after_reconciliation: after_reconcile,
285
+ observations: [report_receipt(first), report_receipt(second)],
286
+ late_observer: resumed ? {requested: true, completed: resumed.done?,
287
+ result: resumed_result &amp;&amp; resumed_result.slice(:status, :result, :output)} : {requested: false},
288
+ transcript: transcript &amp;&amp; report_messages(transcript), counts: service.fetch(:counts),
289
+ counts_after_failure: counts_after_failure, released: released,
290
+ original_observation_closed: true,
291
+ retained_service: released ? nil : service, retained_recovery: released ? nil : recovery,
292
+ retained_observer: released ? nil : resumed}
293
+ end
294
+ </code></pre></td>
295
+ <td><pre><code><!-- g3k-code:recovery-function:after --># Retrying a confirmed pre-state is an explicit persistence policy. It does not
296
+ # authorize repeating the report, output conversion or native preparation.
297
+ def run_report_with_recovery(fault:, retry_confirmed_pre: false, late_observer: false)
298
+ service = build_report_service
299
+ fault.call(service)
300
+ parent = service.fetch(:parent)
301
+ original = start_report(service)
302
+ original_failure = nil
303
+ begin
304
+ original.wait_result(timeout: 8)
305
+ rescue Phronomy::Agent::OutcomeRecoveryError =&gt; error
306
+ original_failure = error
307
+ end
308
+ raise "Expected an ambiguous report observation" unless original_failure
309
+ recovery = original_failure.recovery
310
+ raise "Unexpected retained owner" unless parent.pending_outcome_recovery(execution_id: service.fetch(:execution_id)).equal?(recovery)
311
+ counts_after_failure = service.fetch(:counts).dup
312
+ resumed = late_observer ? parent.resume_async(service.fetch(:execution_id)) : nil
313
+ reconciled = parent.reconcile_outcome(recovery: recovery)
314
+ after_reconcile = stored_report(service)
315
+ first = reconciled
316
+ if first.outcome == :confirmed_pre &amp;&amp; retry_confirmed_pre
317
+ first = parent.retry_outcome(recovery: recovery)
318
+ end
319
+ second = parent.reconcile_outcome(recovery: recovery)
320
+ begin
321
+ original.wait_result(timeout: 8)
322
+ raise "Original failed observation reopened"
323
+ rescue Phronomy::Agent::OutcomeRecoveryError =&gt; error
324
+ raise "Original observation changed" unless error.equal?(original_failure)
325
+ end
326
+ released = first.ownership_state == :released
327
+ resumed_result = resumed.wait_result(timeout: 8) if resumed &amp;&amp; released
328
+ transcript = released ? parent.transcript_messages : nil
329
+ release_report(service) if released
330
+ {state: released ? :recovered : :retained, stored: stored_report(service),
331
+ reconciliation: report_receipt(reconciled), after_reconciliation: after_reconcile,
332
+ observations: [report_receipt(first), report_receipt(second)],
333
+ late_observer: resumed ? {requested: true, completed: resumed.done?,
334
+ result: resumed_result &amp;&amp; resumed_result.slice(:status, :result, :output)} : {requested: false},
335
+ transcript: transcript &amp;&amp; report_messages(transcript), counts: service.fetch(:counts),
336
+ counts_after_failure: counts_after_failure, released: released,
337
+ original_observation_closed: true,
338
+ retained_service: released ? nil : service, retained_recovery: released ? nil : recovery,
339
+ retained_observer: released ? nil : resumed}
340
+ end
341
+ </code></pre></td>
342
+ </tr></tbody>
343
+ </table>
344
+
345
+
346
+ The application does not become shorter. It benefits because the framework retains its own intermediate evidence and finishes its own read-only work. The application still owns retry, unresolved-owner lifetime and cleanup; it does not acquire a generic right to rerun semantic preparation.
347
+
348
+ ## Complete fault fixture and driver
349
+
350
+ The fixture changes only the environment at the real immutable-content and transaction boundaries. It leaves the Runtime, native policy, encoding, exact comparison and writes intact. Counts separate repeated presentation reads from forbidden repeated business work.
351
+
352
+ For example, a transient historical read failure can recover while a permanent read failure stays retained. A later committed-response loss remains a persistence-reconciliation case after the stage has completed. A late exact observer must retain its existing Store-result shape; it does not gain an ordinary transcript field.
353
+
354
+ <!-- g3k-code:fault-fixture -->
355
+ ```ruby
356
+ # The fixture counts actual terminal preparation and fails an actual immutable
357
+ # content read or a real transaction response. It never supplies an outcome.
358
+ module G3kReportFault
359
+ class << self
360
+ attr_accessor :current
361
+
362
+ def report
363
+ return {enabled: false} unless current
364
+ current.slice(:read_failure, :save_loss, :read_failures, :save_failures,
365
+ :committer_calls, :encoder_calls, :materialization_calls)
366
+ end
367
+ end
368
+ end
369
+
370
+ module G3kCommitScope
371
+ def commit_outcome(command, **options)
372
+ fault = G3kReportFault.current
373
+ selected = fault && command.root.agent_id == fault.fetch(:service).fetch(:parent).agent_id
374
+ previous = Thread.current[:g3k_report_outcome]
375
+ Thread.current[:g3k_report_outcome] = selected ? fault : nil
376
+ if selected
377
+ fault.fetch(:service)[:execution_id] = command.execution_id
378
+ fault[:committer_calls] += 1
379
+ end
380
+ super
381
+ ensure
382
+ Thread.current[:g3k_report_outcome] = previous
383
+ end
384
+ end
385
+
386
+ module G3kEncodingCount
387
+ def encode(*args, **options)
388
+ fault = Thread.current[:g3k_report_outcome]
389
+ fault[:encoder_calls] += 1 if fault
390
+ super
391
+ end
392
+ end
393
+
394
+ module G3kTranscriptScope
395
+ def materialize_transcript(root:, records:)
396
+ fault = G3kReportFault.current
397
+ selected = fault && root.agent_id == fault.fetch(:service).fetch(:parent).agent_id
398
+ previous = Thread.current[:g3k_report_transcript]
399
+ Thread.current[:g3k_report_transcript] = selected ? fault : nil
400
+ fault[:materialization_calls] += 1 if selected
401
+ super
402
+ ensure
403
+ Thread.current[:g3k_report_transcript] = previous
404
+ end
405
+ end
406
+
407
+ module G3kTranscriptRead
408
+ def fetch(reference)
409
+ fault = Thread.current[:g3k_report_transcript]
410
+ should_fail = fault && fault.fetch(:service).fetch(:counts)[:output_conversion] > 0 &&
411
+ (fault[:read_failure] == :permanent || (fault[:read_failure] == :once && fault[:read_failures].zero?))
412
+ if should_fail
413
+ fault[:read_failures] += 1
414
+ raise IOError, "Immutable report transcript content is unavailable"
415
+ end
416
+ super
417
+ end
418
+ end
419
+
420
+ module G3kSaveResponse
421
+ def atomic(*args, &transaction)
422
+ fault = Thread.current[:g3k_report_outcome]
423
+ return super unless fault && fault[:save_loss] != :none
424
+ if fault[:readback_loss]
425
+ fault[:readback_loss] = false
426
+ raise IOError, "Immediate report save readback unavailable"
427
+ end
428
+ return super unless fault[:save_armed]
429
+ fault[:save_armed] = false
430
+ if fault[:save_loss] == :pre
431
+ super(*args) do |scope|
432
+ transaction.call(scope)
433
+ fault[:save_failures] += 1
434
+ fault[:readback_loss] = true
435
+ raise IOError, "Report save rolled back and response lost"
436
+ end
437
+ else
438
+ super(*args, &transaction)
439
+ fault[:save_failures] += 1
440
+ fault[:readback_loss] = true
441
+ raise IOError, "Report save committed and response lost"
442
+ end
443
+ end
444
+ end
445
+
446
+ Phronomy::Agent::ExecutionOutcomeCommitter.prepend(G3kCommitScope)
447
+ Phronomy::Agent::RuntimeRecordEncoder.singleton_class.prepend(G3kEncodingCount)
448
+ Phronomy::Agent::RuntimeInput.prepend(G3kTranscriptScope)
449
+ Phronomy::Persistence::ContentRepository.prepend(G3kTranscriptRead)
450
+
451
+ def report_fault(read_failure:, save_loss:)
452
+ raise ArgumentError, "Unknown read failure" unless %i[none once permanent].include?(read_failure)
453
+ raise ArgumentError, "Unknown response loss" unless %i[none pre post].include?(save_loss)
454
+ lambda do |service|
455
+ service.fetch(:stores).agent.coordinator.singleton_class.prepend(G3kSaveResponse)
456
+ G3kReportFault.current = {service: service, read_failure: read_failure, save_loss: save_loss,
457
+ save_armed: true, readback_loss: false, read_failures: 0, save_failures: 0,
458
+ committer_calls: 0, encoder_calls: 0, materialization_calls: 0}
459
+ end
460
+ end
461
+ ```
462
+
463
+
464
+ <!-- g3k-code:shared-driver -->
465
+ ```ruby
466
+ # An unresolved result retains the live owner and exact capability. A service
467
+ # must keep these values; process exit is not a handoff or recovery mechanism.
468
+ def run_report_example(normal: false, failure: false, read_failure: :none,
469
+ save_loss: :none, retry_confirmed_pre: false, late_observer: false)
470
+ begin
471
+ report = if normal
472
+ run_report(failure: failure)
473
+ else
474
+ run_report_with_recovery(fault: report_fault(read_failure: read_failure, save_loss: save_loss),
475
+ retry_confirmed_pre: retry_confirmed_pre, late_observer: late_observer)
476
+ end
477
+ report = report.reject { |key, _value| %i[retained_service retained_recovery retained_observer].include?(key) }
478
+ ensure
479
+ fixture = G3kReportFault.report
480
+ Phronomy::Runtime.instance.shutdown(timeout: 0.03, cancel_grace: 0.2)
481
+ begin
482
+ Phronomy.reset_runtime!
483
+ cleanup_incomplete = false
484
+ rescue Phronomy::RuntimeShutdownError
485
+ cleanup_incomplete = true
486
+ end
487
+ end
488
+ report.merge(cleanup_incomplete: cleanup_incomplete, fixture: fixture)
489
+ end
490
+
491
+ if $PROGRAM_NAME == __FILE__
492
+ puts JSON.pretty_generate(run_report_example(normal: ENV["G3K_NORMAL"] == "true",
493
+ failure: ENV["G3K_FAILURE"] == "true", read_failure: ENV.fetch("G3K_READ_FAILURE", "none").to_sym,
494
+ save_loss: ENV.fetch("G3K_SAVE_LOSS", "none").to_sym,
495
+ retry_confirmed_pre: ENV["G3K_RETRY_CAPTURED_OUTCOME"] == "true",
496
+ late_observer: ENV["G3K_LATE_OBSERVER"] == "true"))
497
+ end
498
+ ```
499
+
500
+
501
+ The driver's bounded shutdown is fixture cleanup. A service that elects to retain responsibility must keep the original owner and recovery capability alive. The example does not establish failed-Runtime administration, process-loss recovery, real external-service acceptance or production SQL guarantees.
502
+
503
+ ## Public symmetry and preserved distinctions
504
+
505
+ The same exact owner and public recovery family manage the additional private stage. Comparable operations share their existing sync/async and custody rules, while business submission, approval decisions and factual resolution retain different authority.
506
+
507
+ For example, `reconcile_outcome` may read and finish the permitted suffix but cannot write a report merely because a read succeeded. `retry_outcome` expresses explicit write permission. `retry_outcome_submission` still requires positive original non-admission; a failed transcript read proves the opposite.
508
+
509
+ | Peer | Decision and rationale |
510
+ | --- | --- |
511
+ | Outcome reconcile, sync/async | Same required `recovery:` and result family. May finish only the recorded immutable-content suffix before readback. |
512
+ | Outcome retry, sync/async | Same explicit write authority; exact pre-state/current native authority remain required. |
513
+ | Original submission retry | Preserve positive refusal requirement. Never treat admitted incomplete materialization as non-admission. |
514
+ | Ordinary invoke/stream | Preserve existing semantic result, error and listener contracts. The bounded example does not exercise every streaming behavior. |
515
+ | Exact reserved execution observation | Preserve `Store#result`-based shape. The waiter ignores the internal result and rereads durable facts. |
516
+ | Recovery `ExecutionObservation` | Keep G3j captured result/raw-output/diagnostic representation, independent of later mutable application objects. |
517
+ | Approval/coordination waits | Keep existing kind, authority and lifetime; a wait is not final completion or permission to run a protected Tool. |
518
+ | Standalone/Handoff/custom preparation | No general new guarantee follows from the native checkpoint. Their unsupported paths remain separately scoped. |
519
+ | Generic preparation retry or forced failure | Not added. Arbitrary conversion may have unknown effects and cannot inherit immutable-read repeatability. |
520
+
521
+ A pre-read of old transcript content cannot eliminate this stage: newly encoded messages and final projection exist only after encoding. Writing before presentation would change initial save semantics, and omitting messages would weaken ordinary success. A distinct private capsule is the bounded choice.
522
+
523
+ ## Acceptance and limits of the model
524
+
525
+ Acceptance must link the exact candidate source to actual behavior and preserve the difference between ordinary results, exact observations and recovery receipts. The finite model checks the protocol under explicit assumptions; concrete Ruby tests check the content and conversion boundaries.
526
+
527
+ For the report, the accepted candidate must finish a transient read failure without increasing Provider/Tool/encoder/conversion counts, preserve complete ordinary messages, keep exact-observer shapes and publish a result equal to stored bytes. Permanent unavailability and refused explicit writes must remain visible retained outcomes.
528
+
529
+ | Recorded validation | Result | Scope |
530
+ | --- | --- | --- |
531
+ | Same complete application on baseline and candidate | Ten baseline cases and ten candidate cases match their version-specific expectations. | Ordinary success/failure reports are identical; selected read-recovery cases preserve Provider/Tool/conversion counts and explicit hold policies. |
532
+ | Loaded source provenance | All 407 baseline library files match the applied Git blobs; all 408 candidate files match the candidate source. | The five production differences are the four modified boundaries and the new private preparation class. |
533
+ | Published source correspondence | All eight complete units match the frozen source; both assembled files pass Ruby syntax and all 20 direct document executions match the application reports and loaded source hashes. | These are the same ten cases on two versions, rerun to verify the published source, not 20 additional independent scenarios. |
534
+
535
+ Runtime acceptance and complete regression totals are recorded with the exact delivery commit. The bounded application deliberately does not dispatch its declared child or contact external services. Independent Runtime cases exercise lifecycle/authority boundaries that this small example does not cover. Passing a retained-policy case means the expected responsibility remained retained, not that cleanup completed.
536
+
537
+ The existing [native outcome model family](../../spec/models/native_parent_outcome_recovery/README.md) is extended with a retained encoded stage and read-only hydration. The complete prior family remains the historical baseline. No new state diagram is needed merely to refine an existing preparation transition. Exact bounded configurations, expected negative outcomes and execution hashes accompany the change. Immutable-read eventual success, physical completion, original ownership and appropriate storage/authority assumptions remain premises; no unconditional progress or full Ruby refinement theorem is claimed.
538
+
539
+ ## Remaining preparation work
540
+
541
+ The new checkpoint closes only the post-encoding presentation class. Earlier reads, partial encoding, arbitrary conversion and unsupported participant paths still need an explicit recovery or disposition contract. Keeping an owner alive is a safety property, not completion of the lifecycle.
542
+
543
+ For example, a Tool's external effect may already have occurred when its result object's `to_h` raises. No unchanged Store or cancellation request proves that converting it again is safe. Writing a generic parent failure also does not dispose of an active child's responsibility.
544
+
545
+ | Remaining class | Required decision |
546
+ | --- | --- |
547
+ | Read-only prefix before the capsule | Fixed inputs and repeatability boundary, with native-policy selection and exact-state checks specified. |
548
+ | Failed arbitrary conversion/diagnostic or complete-input copying | Explicit retained-unresolved, exact-subject replacement or intentional-abandonment semantics; no silent retry. |
549
+ | Partially completed encoding | Reuse completed facts and generated identities without repeating application conversions. |
550
+ | Intentional terminal disposition | State what it means about accepted results, unavailable audit data, external effects and child obligations. |
551
+ | Handoff/custom participants | Establish their own supported preparation and ownership contracts. |
552
+
553
+ These remain in completion group 1. They are not relabeled as failed-Runtime or backend work to make the group appear complete. The next semantic resolution decision must preserve facts already accepted and define stable subject identity, revision binding, data-only replacement/abandonment rules and atomic responsibility transfer before implementation.
554
+
555
+ ## Preparing approval and coordination waits
556
+
557
+ An approval wait carries one request identity and one description of the batch. The outcome committer converts the request once, writes the canonical bytes as the approval journal content and derives the execution's approval field from those bytes. The original request still goes to the waiting caller. A protected Tool starts only after its existing approval operation succeeds. This applies to standalone approval persistence and to native parent preparation.
558
+
559
+ For example, if a request's display data can be converted once and a later conversion would raise, the original conversion supplies both stored representations. A failure of the first required conversion leaves the accepted native execution with its original owner. The coordinator has no encoded request to publish in that case.
560
+
561
+ Provider token usage follows the same one-time conversion rule during record encoding. The encoder reads the usage projection once to decide whether to save it and to obtain the values to write. A reported zero produces a usage record. An entirely absent measurement leaves the usage reference empty.
562
+
563
+ The native owner retains each fully encoded plan before constructing its complete proof input. An approval plan includes the encoded records and the original request. A coordination wait includes the selected parent state, child relationships, cancellation fact and original cause. Neither needs transcript hydration. The retained plan also covers encoded failure outcomes.
564
+
565
+ | Last established fact | What the original owner can do |
566
+ | --- | --- |
567
+ | Store identity could not be verified before input construction | On a fresh observation after physical settlement, verify the Store identity again and construct the input once. Reconciliation reads the guarded state. An explicit retry may write after the existing pre-state and native authority checks succeed. |
568
+ | Input construction began and failed | Return the same construction failure on reconciliation or captured-write retry. Retain the plan and custody. A partial input cannot establish a saved outcome or authorize another constructor attempt. |
569
+ | Complete input exists and proof construction failed | Rebuild the persistence proof from the retained input. Native selection, application conversion and Tool execution have already finished for this plan. |
570
+ | A child moved or a durable revision changed | Classify the exact observed state. A different parent state or revoked child authority prevents overwriting it with the captured proposal. |
571
+
572
+ Earlier stages still have distinct obligations. The native coordinator observes each child Agent and execution pair once under the original transaction guards. Its import, wait and terminal acknowledgement decisions share that observation. Subsequent guarded authority checks take fresh observations. A failure inside that selection can precede any retained plan. The runtime-record encoder's partial bytes, generated call records and identities also live in the current builder until the plan is complete. A genuine conversion or diagnostic failure can therefore leave an admitted operation without enough facts for either safe completion or a factual replacement. The existing owner keeps custody, but there is no supported operation that supplies the missing conversion or atomically disposes of the outstanding external and child obligations. These cases keep U-05 open.
573
+
574
+ ## Supplying the missing final text
575
+
576
+ A native parent can finish its already selected completion when an application
577
+ independently knows the exact final text that an output object's failed
578
+ conversion was meant to represent. Agent retains the preceding encoded
579
+ records, their timestamps, identities and content, together with the guarded
580
+ parent and child facts. The application owns the accuracy of the supplied
581
+ text. This capability is process-local.
582
+
583
+ For example, a report filter returns an object whose single-use reader fails
584
+ after a Tool has produced a verified report. An application with its own copy
585
+ of that exact final report can use the original Agent and recovery reference:
586
+
587
+ ```ruby
588
+ def finish_verified_report(agent, recovery, verified_report)
589
+ return unless recovery.output_text_required?
590
+ agent.supply_outcome_text(
591
+ recovery: recovery,
592
+ expected_revision: verified_report.fetch(:execution_revision),
593
+ text: verified_report.fetch(:final_text)
594
+ )
595
+ current = agent.reconcile_outcome(recovery: recovery)
596
+ return current unless current.outcome == :confirmed_pre
597
+ agent.retry_outcome(recovery: recovery)
598
+ end
599
+ ```
600
+
601
+ The example assumes the application has already matched its evidence to
602
+ `recovery.agent_id` and `recovery.execution_id`. Its verified execution
603
+ revision must also equal `recovery.expected_execution_revision`. A Provider's
604
+ raw text alone cannot establish a filtered result. When the application lacks
605
+ the final text, it keeps the original responsibility.
606
+
607
+ Supply requires the native positive completion path, a failed unstructured
608
+ output conversion, the original recovery capability and a quiescent worker
609
+ lane. It records valid UTF-8 text locally, returns true and performs no I/O.
610
+ Repeated identical submissions are accepted while that owner is retained and
611
+ quiescent. A different value, a different Agent or a mismatched revision is
612
+ rejected. Reconciliation remains read-only. Explicit captured-write retry
613
+ checks the current durable revision and child authority before publication.
614
+ The durable execution carries `outcome_text_source: application`. A new
615
+ terminal observation returns the supplied text. The original failed observer
616
+ retains its failure.
617
+
618
+ Structured validation, rejected results, approval data, diagnostics and
619
+ failures during earlier runtime-record encoding have different factual subjects.
620
+ An unstructured text fact cannot fill any of those fields.
621
+
622
+ ## Recover a native read before the first outcome decision
623
+
624
+ The original Agent retains the validated terminal subject and its expected parent and execution revisions. The native coordinator supplies the operations that observe child facts and select a terminal plan. Both use the original Store. An incomplete set of child observations expires with its transaction. The original failed caller keeps its original error.
625
+
626
+ For example, a hosted reviewer has completed its work and the parent has accepted a filtered report. Reading the parent's extension or the reviewer's execution fails before the first native decision. Once the original worker has physically settled, the application can reconcile that same recovery capability. The worker takes fresh guards, verifies the original revision and extension, and observes the reserved children. A matching source and a decision that never began establish `confirmed_pre`. The parent remains active, the original owner retains custody, and this observation invokes neither business conversion nor native selection.
627
+
628
+ | Operation | Expected behavior before any decision has begun |
629
+ | --- | --- |
630
+ | Reconcile | Prove the guarded pre-state without starting the decision, encoding a result, generating records or writing storage. A failed read or stale binding leaves the owner retained. |
631
+ | Retry outcome | Follow the same guarded reads, then start the first native decision and its preparation once. Save only after the complete proposal and existing current-authority checks permit it. |
632
+ | Retry original submission | The original worker was admitted. A missing observation provides no new permission to submit that worker. |
633
+
634
+ The framework preserves the bytes of an ordinary String before the fallible read while keeping its original identity for ordinary delivery. Structured validation already returns immutable JSON data. An application-specific output conversion has no known bytes until it first succeeds. Explicit outcome retry can run that conversion once on the retained object; applications that require a historical byte value must supply a stable output representation. Earlier Provider, Tool, filter and schema operations are never re-run.
635
+
636
+ A cancellation request that arrives while reads are unavailable is observed in the fresh transaction. A completed business result can therefore retain a true cancellation-requested fact. A changed parent revision prevents even the first selection. Loss of parent or child custody before the first recovered selection prevents even an application conversion. The native reader checks the same guarded child observations used for selection. A later loss of custody still prevents the captured write under the native retry authority rules. A stopped Runtime or loss of the process is outside this in-memory recovery capability.