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,91 @@
1
+ # Team admission rejection
2
+
3
+ Team owns whether an accepted coordination run can continue. Agent owns whether
4
+ a particular child-start request was rejected before durable admission. A
5
+ confirmed rejection must reach Team without making storage failures or uncertain
6
+ execution outcomes look like completed failures.
7
+
8
+ For example, an earlier release could save a String as Team `durable_context`.
9
+ The child requires a canonical JSON-compatible Hash and rejects that request.
10
+ Team now records its own failure and becomes available for the next request,
11
+ instead of requiring the application to cancel and resume an unstartable run.
12
+
13
+ ## Input acceptance
14
+
15
+ Team validates the durable input it owns before creating its execution. The
16
+ accepted value is a JSON snapshot, so later caller mutation cannot change the
17
+ input used by reserved children.
18
+
19
+ For example, `team.invoke("plan", config: {durable_context: "invalid"})` raises
20
+ `ArgumentError` without creating a TeamExecution. A valid Hash remains the saved
21
+ input used after restart. `stream` has the same acceptance rule. Passing a new
22
+ context to `resume` does not replace an already saved context.
23
+
24
+ ## Reserved-start rejection
25
+
26
+ Agent reports positively identified validation failures separately from errors
27
+ that require recovery or observation. The rejection belongs to a particular
28
+ start request; it is not a durable execution outcome or a global absence claim.
29
+
30
+ For example, invalid durable context in a reserved start raises
31
+ `Agent::ExecutionRejectedError`. Its `agent_id` and `execution_id` identify the
32
+ reservation, its code is `agent.execution_rejected`, and its Ruby `cause` retains
33
+ the validation error. Another caller might already have started that reservation.
34
+
35
+ The marker covers durable-context snapshot validation, input extraction and
36
+ initial preparation metadata validation before admission is attempted. It does
37
+ not classify every `ArgumentError`, `ConfigurationError` or internal
38
+ `:not_established` result as a confirmed rejection. Persistence reads, admission
39
+ participants, commit responses, busy states, Runtime submission and recovery
40
+ wiring keep their existing error behavior. A saved failed child still returns
41
+ the ordinary exact-execution result with its saved status and diagnostic.
42
+
43
+ | Entry point | Rejected start | Saved child failure |
44
+ | --- | --- | --- |
45
+ | `start_reserved_async` | Task fails with the marker for the validation cases above | Task returns the saved result |
46
+ | Ordinary `invoke` / `stream` and their async forms | Original error contract | Original failure exception contract |
47
+ | `resume_async` / `resume` | No new start is accepted | Return the saved result |
48
+ | `start_hosted` | Original error contract | Existing hosted observation contract |
49
+
50
+ ## Team completion
51
+
52
+ Team combines the child's rejection fact with a guarded observation before
53
+ deciding its own final outcome. The Team admission guard serializes that decision
54
+ with other processes attempting to accept the same reserved child.
55
+
56
+ For example, if a worker rejects its initial preparation metadata, Team confirms
57
+ the matching reservation has no execution, then saves TeamExecution `failed`
58
+ and TeamRoot `idle` in one transaction. The reserved child identity remains in
59
+ the Team record, but no fictional failed child execution is created.
60
+
61
+ The coordinator and worker start paths use the same rule. A rejected start is a
62
+ coordination configuration failure even with `on_error: :skip`; that policy
63
+ continues to apply to outcomes of children that actually executed. The first
64
+ call and later `resume` raise the saved Team diagnostic through the existing
65
+ terminal-result contract. The original cause is retained in that diagnostic.
66
+
67
+ If the reserved child already exists, Team retains its unfinished run and reports
68
+ that recovery is required. A later resume observes the actual child. An unknown
69
+ observation or commit result also remains recoverable; it is never replaced with
70
+ a guessed failed or cancelled result. If a lost terminal commit response can be
71
+ confirmed by readback, the saved terminal result remains authoritative.
72
+
73
+ An application stream-consumer exception still leaves the accepted run available
74
+ for resume. It is an observation failure, not a child-start rejection.
75
+
76
+ ## Responsibility boundaries
77
+
78
+ The change uses the existing Agent result boundary and shared persistence scope.
79
+ Agent classifies its request; Team applies coordination policy; Persistence
80
+ provides the transaction and guards. Execution and Engine do not choose Team
81
+ failure policy.
82
+
83
+ For example, Team calls the public `Agent::Store#observe_execution` inside the
84
+ same scope used for its terminal write. It does not inspect Agent journals or
85
+ change the child's execution record. The existing Contract edges `C01 -> C04`
86
+ and `C01 -> C07` remain sufficient; no reverse edge or new delegation layer is
87
+ required.
88
+
89
+ The Team guard is acquired before reading the Team execution. Reserved child
90
+ admission already takes the same guard before accepting the child. Neither path
91
+ waits for Agent execution or provider I/O while holding that guard.
@@ -0,0 +1,245 @@
1
+ # Team cancellation delivery
2
+
3
+ Team owns delivery of an explicit cancellation request to the exact run it is
4
+ currently coordinating. The caller's token expresses intent; a confirmed Team
5
+ record authorizes signalling the internal token shared by its children. A
6
+ notification, a saved cancellation request and a child's physical stop are
7
+ different facts.
8
+
9
+ For example, a research service cancels a Team while a worker awaits an LLM.
10
+ The Team's host thread wakes, records cancellation under the existing Team
11
+ guard, then signals that child's token. A full ordinary worker queue cannot
12
+ discard this request because the cancellation bridge submits no additional
13
+ worker job.
14
+
15
+ ## Delivery and ownership
16
+
17
+ A synchronous Team call retains a run-local control request before registering
18
+ its external token callback. The callback only records intent and wakes the
19
+ host; persistence and business transitions remain on the Team's host thread.
20
+ The same host responds to child completion and cancellation without settling
21
+ or cancelling the child's result handle.
22
+
23
+ For example, registering a token that is already explicitly cancelled can call
24
+ the callback immediately. The request and its Runtime admission already exist,
25
+ so the host can confirm cancellation before starting a reserved absent child.
26
+
27
+ - Retain at most the applicable outstanding request for this Team owner.
28
+ - Deliver pending intent at control checkpoints before further child work or
29
+ aggregation, and while waiting for a child.
30
+ - Use the existing guarded, idempotent cancellation update and readback rules.
31
+ - Signal the run's internal token only after confirming the stored intent or
32
+ the authoritative terminal disposition.
33
+ - Preserve a confirmed terminal business outcome when cancellation arrives
34
+ too late to change it.
35
+ - Close each external subscription using its registration identity; an older
36
+ callback cannot become valid when the same run is resumed.
37
+
38
+ This is cooperative control of a synchronous Team call. It does not preempt a
39
+ blocked persistence operation, scheduler, aggregator or application callback.
40
+ Those operations must return before the host reaches its next checkpoint.
41
+ Deadline expiry alone is not promoted to explicit cancellation.
42
+
43
+ ## Delivery failure and exact retry
44
+
45
+ An unconfirmed cancellation write is an operation failure, not proof of a
46
+ cancelled or failed Team. Team preserves the local intent, original child
47
+ controls and relevant observations so a caller can retry the same target. The
48
+ failure carries the Team and run identities even when `invoke` allocated the
49
+ run ID internally.
50
+
51
+ For example, a storage outage can prevent both the cancel write and readback.
52
+ The call raises `MultiAgent::TeamCancellationDeliveryError`; after storage
53
+ recovers, `team.resume(error.team_execution_id)` retries the pending intent
54
+ before advancing that run. A new `invoke` is not recovery for the old run.
55
+
56
+ | Surface | Contract |
57
+ |---|---|
58
+ | `TeamCancellationDeliveryError#team_id` | Exact Team owner identity. |
59
+ | `TeamCancellationDeliveryError#team_execution_id` | Exact run whose cancellation is still unresolved. |
60
+ | `TeamCancellationDeliveryError#code` | `team.cancellation_delivery`. |
61
+ | `TeamCancellationDeliveryError#cause` | Original failure where available; preserve it for diagnosis. |
62
+ | `resume(id, config: ...)` | Under ordinary Runtime admission, retry retained intent for the same run before further coordination. |
63
+ | `cancel(id)` | Explicitly retry the guarded cancellation; discharge retained intent after confirmation, before the optional result query. |
64
+ | `result(id)` | Read the saved business state; it is not a local delivery-status query and initiates no retry. |
65
+ | `token.cancel!` | Existing notification API; its return is not a durable receipt or physical-stop acknowledgment. |
66
+
67
+ The new error inherits from `Phronomy::Error`, not `CancellationError`.
68
+ Control-delivery failure must not enter the rescue path that commits a Team's
69
+ business cancellation. A later result-query failure cannot undo confirmed
70
+ cancellation. No automatic storage retry loop is added beyond the existing
71
+ guarded-update/readback behavior; an unresolved return requires explicit host
72
+ action.
73
+
74
+ Fatal or control-flow exceptions outside `StandardError`, such as `Interrupt`,
75
+ still propagate unchanged. Pending intent remains retained in that case.
76
+
77
+ ## Complete application comparison
78
+
79
+ Applications retain business and operation outcomes separately and choose when
80
+ to retry. The following complete functions use the same host-supplied Team,
81
+ input and cancellation token. They run on a thread where synchronous Team
82
+ operations are permitted. Team construction, authentication and the decision
83
+ to cancel are supplied by the host; neither function starts another run as a
84
+ recovery attempt.
85
+
86
+ For example, an HTTP handler can store the returned run identity with its own
87
+ request and offer an explicit retry action after a delivery error. The example
88
+ does not automatically replay business work or persist exception objects.
89
+
90
+ <table>
91
+ <thead><tr><th>Baseline API application unit</th><th>Updated application unit</th></tr></thead>
92
+ <tbody><tr><td>
93
+
94
+ ```ruby
95
+ require "phronomy"
96
+
97
+ def coordinate(team:, input:, token:)
98
+ report = {
99
+ value: nil,
100
+ operation_error: nil,
101
+ team_id: team.team_id,
102
+ retry_run_id: nil
103
+ }
104
+
105
+ begin
106
+ report[:value] = team.invoke(
107
+ input, config: {cancellation_token: token}
108
+ )
109
+ rescue StandardError => error
110
+ report[:operation_error] = error
111
+ end
112
+
113
+ report.freeze
114
+ end
115
+ ```
116
+
117
+ </td><td>
118
+
119
+ ```ruby
120
+ require "phronomy"
121
+
122
+ def coordinate(team:, input:, token:)
123
+ report = {
124
+ value: nil,
125
+ operation_error: nil,
126
+ team_id: team.team_id,
127
+ retry_run_id: nil
128
+ }
129
+
130
+ begin
131
+ report[:value] = team.invoke(
132
+ input, config: {cancellation_token: token}
133
+ )
134
+ rescue Phronomy::MultiAgent::TeamCancellationDeliveryError => error
135
+ report[:operation_error] = error
136
+ report[:team_id] = error.team_id
137
+ report[:retry_run_id] = error.team_execution_id
138
+ rescue StandardError => error
139
+ report[:operation_error] = error
140
+ end
141
+
142
+ report.freeze
143
+ end
144
+ ```
145
+
146
+ </td></tr></tbody>
147
+ </table>
148
+
149
+ These are adapted application examples, not repository baseline excerpts.
150
+ The call signatures and ordinary result handling are equivalent; failure
151
+ behavior intentionally changes. The old bridge could log a rejected submission
152
+ and keep waiting without a recoverable control outcome. The new path removes
153
+ that submission and exposes unresolved persistence with an exact retry target.
154
+ The application still owns retry timing, request authorization, persistence of
155
+ its identifiers and handling of business cancellation.
156
+
157
+ ## Runtime lifetime and shutdown
158
+
159
+ The request belongs to the originating Team and Runtime. An accepted unresolved
160
+ intent retains an admission after its original caller returns, preventing
161
+ successful Runtime cleanup from silently clearing the Team owner. Confirmed
162
+ disposition releases that control obligation; it does not prove that the child
163
+ has stopped or that all other Runtime work has been released.
164
+
165
+ For example, shutdown during a storage outage can report incomplete cleanup
166
+ because a pending cancellation is still retained. An application must not
167
+ replace the default Runtime and report success merely because the original
168
+ Team call has returned an error.
169
+
170
+ An exact direct `cancel` remains a synchronous persistence/control operation on
171
+ the retained current-generation Team. It can confirm the durable fact without
172
+ starting another worker, even when new execution admission is closed. It does
173
+ not reopen a failed Runtime, make `resume` admissible, or revise a cached
174
+ incomplete shutdown result. A Team from a replaced Runtime is rejected before
175
+ its control operation writes storage.
176
+
177
+ The local request is not a crash-durable inbox. Process loss before the
178
+ cancellation record is confirmed requires host reconciliation using the exact
179
+ identity. Child release still follows Agent ownership, physical completion and
180
+ Team terminal-result rules; the control request never authorizes early unload.
181
+
182
+ ## Shared mechanisms and dependency boundaries
183
+
184
+ This repair reuses the existing result subscriptions, Team guard/readback,
185
+ Runtime admission and Agent lifetime contracts. The additional wait and intent
186
+ bookkeeping belongs to Team's synchronous host protocol. Its similarity to
187
+ Agent or Workflow uncertainty does not establish a shared implementation.
188
+
189
+ For example, Workflow applies readback on a retained serial owner, whereas this
190
+ Team path wakes a blocked host that already owns the synchronous turn. Moving
191
+ both behind a new manager would require extra scheduling and policy adapters;
192
+ this repair does not establish a net simplification from doing so.
193
+
194
+ | Concern | Owner |
195
+ |---|---|
196
+ | Exact run, cancellation record, host checkpoints and retained local intent | C01 MultiAgent / Team |
197
+ | Subscription and result-observation primitives | Existing C13 Execution |
198
+ | Guarded transaction and neutral persistence rules | Existing C07 Persistence, selected by Team |
199
+ | Child execution and unload eligibility | C04 Agent |
200
+ | Concrete execution resources and shutdown protocol | Engine through the existing environment binding |
201
+
202
+ No new Contract, reverse dependency, external library or public Job state
203
+ machine is introduced. Existing C01-to-C04/C07/C13 dependencies remain the
204
+ architecture boundary. The normative lifecycle specification and fault
205
+ scenarios can be shared without forcing one implementation across domains.
206
+
207
+ | Peer | Symmetry decision |
208
+ |---|---|
209
+ | Team `invoke`, `stream` and `resume` | Adopt the same retained request and host checkpoints; preserve their existing result/event surfaces. |
210
+ | Direct Team `cancel` | Preserve synchronous guarded persistence and signaling. Its caller receives the operation error directly; the host bridge adds exact identities when an external token callback has no return channel. |
211
+ | Agent and Workflow | Reuse the same distinction between business facts and observation failures; defer extraction because their serial execution owners differ from Team's synchronous host. |
212
+ | Shared delivery manager or separate worker | Withdraw for G1: no second scheduling path is needed to wake the current host, and it would add rejection and shutdown responsibilities. |
213
+
214
+ ## Acceptance and compatibility
215
+
216
+ Acceptance checks observable effects at the real Team, persistence and Runtime
217
+ boundaries. The bounded model explains the selected cooperative protocol and
218
+ its environment assumptions; neither syntax checks nor a mock implementation
219
+ alone demonstrates that cancellation reaches a real blocked child.
220
+
221
+ The [bounded TLA+ model](../../spec/models/team_cancellation_delivery/README.md)
222
+ includes the callback, Team host, persistence attempt, child and Runtime as
223
+ separate state components. Its checked progress claims require explicit host
224
+ retry after a visible error and cooperative return from blocking operations.
225
+
226
+ For example, an acceptance case blocks a real provider call, requests external
227
+ cancellation while another worker submission would fail, and verifies the
228
+ saved cancellation and child signal without creating a delivery job. The
229
+ child remains owned until its actual physical work completes.
230
+
231
+ Required cases include inline cancellation registration, full worker capacity,
232
+ write/response loss and readback, unresolved persistence followed by exact
233
+ retry, direct-cancel confirmation before result-query failure, terminal races,
234
+ stale registration callbacks, original-Runtime ownership and shutdown with
235
+ pending intent. Ordinary Team result formats, synchronous APIs, durable record
236
+ formats, explicit-token semantics and child-retirement rules remain unchanged.
237
+ The identity-bearing delivery error and rejection of new work while an older
238
+ intent is unresolved are intentional observable changes.
239
+
240
+ | Situation | Baseline | Updated behavior |
241
+ |---|---|---|
242
+ | Ordinary delivery queue is full | Cancellation submission can be rejected and logged. | No delivery submission; the current host wakes. |
243
+ | Cancellation write and readback remain unconfirmed | The submitted bridge can fail without returning a recovery identity to the Team caller. | The host reports the exact unresolved run and retains its intent. |
244
+ | A new turn is requested with older local intent pending | No retained bridge obligation blocks replacement. | Reject with the older exact run identity; retry that run explicitly. |
245
+ | Terminal result or physically unfinished child | Saved result and child retirement have separate meanings. | Preserve both meanings; a late child signal does not rewrite the terminal result. |
@@ -0,0 +1,104 @@
1
+ # Team child retirement
2
+
3
+ Team owns the process-local children it creates to execute a coordination run.
4
+ Agent owns whether an incarnation is safe to release, while the saved Team and
5
+ Agent records retain the durable history. Finishing the Team therefore ends its
6
+ need for live child objects without deleting or changing that history.
7
+
8
+ For example, a server can reuse one Team for many requests. After each run
9
+ commits its terminal result and its child operations finish physically, Team
10
+ releases the coordinator and worker Agent incarnations. `result` and a later
11
+ `resume` still read the saved outcome without running those children again.
12
+
13
+ ## Terminal facts and release eligibility
14
+
15
+ A confirmed terminal Team result permits retirement of its execution-only
16
+ children. An active run or an uncertain persistence result does not establish
17
+ that permission. Agent still checks its own accepted operations, execution state
18
+ and durable retentions before accepting a release.
19
+
20
+ For example, a rejected child start can leave a newly created Agent incarnation
21
+ without a child Execution. Once Team saves its own failure, that idle incarnation
22
+ can be released. Conversely, a worker waiting for approval leaves Team active;
23
+ Team retains the live owners and its coordinator class until the answer and
24
+ subsequent execution establish a terminal Team result.
25
+
26
+ The same retirement rule applies to committed success, failure and cancellation.
27
+ It also applies when a terminal Team result is confirmed but reading its output
28
+ or diagnostic fails. The release does not fabricate a failed child, modify a
29
+ saved assignment or convert an uncertain write into a terminal result.
30
+
31
+ ## Logical results and physical work
32
+
33
+ Team result delivery and process-local retirement have separate completion
34
+ boundaries. A caller can receive the saved Team result before child retirement
35
+ finishes. Retirement waits for every observed physical operation before asking
36
+ Agent to unload; it does not block a worker merely to wait for another worker.
37
+
38
+ For example, cancelling a child observation can return control while its provider
39
+ call is still physically executing. Team can report its committed cancellation
40
+ without unloading that Agent early. The existing completion finalizer starts
41
+ `unload_async` only after the child observation's physical boundary has finished.
42
+ When one worker Agent has several assignments, retirement includes all of its
43
+ observations, not only the last logical result.
44
+
45
+ The implementation composes the existing `AsyncOperation.finalize` and
46
+ `TaskResult.all_settled` mechanisms. It does not introduce another lifecycle
47
+ registry, scheduler, state machine or recursive child manager. Descendant Agent
48
+ Tools remain responsible for their own children under their existing contracts.
49
+
50
+ During asynchronous release, `Agent::Base.get` can raise `AgentBusyError` because
51
+ the incarnation is unloading, and returns `nil` after release succeeds. Team
52
+ does not promise that all children are already absent when `invoke`, `stream` or
53
+ `resume` returns its logical result.
54
+
55
+ ## Saved identities and live ownership
56
+
57
+ Team child identifiers describe durable execution history and recovery targets;
58
+ they do not transfer ownership of reusable Agent objects to the application.
59
+ Team returns task and aggregate values, whereas a direct Orchestrator helper
60
+ can deliberately return successful child owners for reuse.
61
+
62
+ For example, an application can read the worker ID from a saved Team execution
63
+ and inspect that worker's stored execution later. It cannot assume that the
64
+ process-local worker remains live after the Team finishes. Agent records are
65
+ preserved, and the normal explicit Agent loading rules remain available when
66
+ appropriate for the application.
67
+
68
+ The run-specific coordinator class is removed from Team's cache after confirmed
69
+ termination. A child whose release fails still retains its exact Ruby class.
70
+ Terminal result discovery and retry do not regenerate the coordinator class.
71
+
72
+ ## Failed retirement and retry
73
+
74
+ A process-local release failure must preserve the already committed Team outcome
75
+ and retain the Agent owner. Team reports the Team ID, run ID, Agent ID and cause;
76
+ reporting failure itself cannot replace the business result or interrupt another
77
+ child's release attempt.
78
+
79
+ For example, a temporary storage failure can prevent the worker's idle check
80
+ after the Team has committed success. The original success remains readable.
81
+ Calling `resume` for that terminal Team run retries release of currently loaded
82
+ children without replaying the coordinator, worker, scheduler or aggregator.
83
+ Calling `result` remains read-only and does not retry cleanup.
84
+
85
+ Retry uses the saved child IDs with public `Agent::Base.get` and `unload_async`.
86
+ It never creates or loads an absent child solely to release it. A live owner
87
+ backed by a different Agent Store is rejected and retained rather than unloaded.
88
+ There is no background retry loop or new public cleanup error or API.
89
+
90
+ ## Runtime shutdown
91
+
92
+ Retirement remains bound to the child object and Runtime that owned the work.
93
+ It does not look up a replacement incarnation after a delayed physical callback.
94
+ Normal Runtime admission and teardown rules continue to govern release attempts.
95
+
96
+ For example, Runtime draining may reject a new unload request. Team logs that
97
+ failure and preserves its saved result and the still-owned child. A successful
98
+ whole-Runtime shutdown separately clears process-local ownership; an incomplete
99
+ shutdown must not be described as successful retirement. Saved approval waits
100
+ do not acquire a new pending-unload obligation merely because Team owns them.
101
+
102
+ These rules use existing `C01 -> C04` and `C01 -> C13` relationships. Team decides
103
+ when its children are no longer needed, Agent decides whether release is safe,
104
+ and Execution composes completion without interpreting Team outcomes.
@@ -162,6 +162,32 @@ This guarantee is specific to Framework automatic instrumentation. It does not
162
162
  redefine the behavior of Application code that directly calls the public
163
163
  `Tracing::Base#trace` template method.
164
164
 
165
+ Automatic span completion that must leave the EventLoop uses the existing
166
+ Execution contract's bounded `automatic_tracing` named pool: one worker and
167
+ 100 waiting slots, owned by the default Runtime. Its admission capacity is
168
+ separate from the default business-work pool. This is an internal allocation,
169
+ not an additional application scheduling API.
170
+
171
+ For example, a Tool can finish before its completion callback is registered.
172
+ The callback then runs immediately on the EventLoop. Recording that Tool's
173
+ completion must not consume the only default-pool slot needed to prepare the
174
+ next provider call. Conversely, a full default pool does not refuse a tracing
175
+ completion while the tracing pool still has capacity.
176
+
177
+ Submission never waits for queue space. If the tracing pool is full or the
178
+ Runtime rejects new work during shutdown, the automatic boundary reports a
179
+ warning and does not retry or run the tracer inline on the EventLoop. Accepted
180
+ trace work remains owned by Runtime shutdown; a worker that exceeds the shutdown
181
+ budget can leave cleanup incomplete. A completed business TaskResult does not
182
+ prove that its trace has been exported, and trace delivery is not durable.
183
+
184
+ This separates deferred completion admission, not all tracing execution cost.
185
+ `start_span` and completion from a blocking-allowed caller keep their existing
186
+ synchronous behavior. Named pools do not isolate process CPU or memory, and
187
+ configured tracers remain responsible for their own I/O timeouts. The tracer
188
+ SPI, redaction, logical span boundaries and public invocation results are
189
+ unchanged.
190
+
165
191
  ## 10. Observed token counts
166
192
 
167
193
  Tracing receives a plain `Hash[Symbol, Integer?]` in `usage:`. Supported keys are:
@@ -6,6 +6,17 @@ Implementation baseline: core `01cd2f57549f6d1e60825254f4520d0f123e651c`
6
6
  `fcd434c45ad98e5c93953cbce1ffef3c12246894` (Refactor 33). The adopted private contract is
7
7
  [ADR-056](../decisions/056-workflow-terminal-policy-ownership.md).
8
8
 
9
+ This document records the historical W2a/W2b design and validation, not the current
10
+ terminal-recovery API contract. The policy/Engine responsibility separation still
11
+ applies. The uncertainty observation, completion-custody and shutdown behavior
12
+ below has been superseded by the implemented
13
+ [Workflow terminal reconciliation contract](workflow-terminal-reconciliation.md).
14
+ That contract supports explicit recovery through the same running or draining
15
+ Runtime, retains unresolved responsibility at shutdown, and does not implement
16
+ stopped-owner takeover or process-crash recovery. For example, an unknown save
17
+ now yields a typed recovery reference instead of leaving the ordinary caller
18
+ pending through successful shutdown.
19
+
9
20
  ## Role and consumers
10
21
 
11
22
  FSMSession drives one live state machine on EventLoop. WorkflowRunner assembles
@@ -58,11 +69,14 @@ The retirement action reuses the existing recovery-required management route.
58
69
  An observer exception still uses Refactor 32's ordinary error path, with the
59
70
  already confirmed snapshot retained. No observer retry or extra save is added.
60
71
 
61
- Unresolved uncertainty instead retires the session and retains recovery-required
62
- admission without falsely settling the caller. Normal shutdown clears that
63
- ownership and ends the dispatcher, while the caller remains pending; unexpected
64
- dispatcher failure retains its separate existing waiter-cleanup behavior. This
65
- change does not promise that normal shutdown resolves an unknown commit.
72
+ At the W2b baseline, unresolved uncertainty instead retired the session and
73
+ retained recovery-required admission without settling the caller. Normal shutdown
74
+ cleared that ownership and ended the dispatcher while the caller remained pending;
75
+ unexpected dispatcher failure retained its separate waiter-cleanup behavior.
76
+ Those historical observations did not establish that normal shutdown resolved an
77
+ unknown commit. They are not the current acceptance requirements: current recovery
78
+ keeps the obligation, fails the original observation with a typed recovery error,
79
+ and prevents complete cleanup while responsibility remains unresolved.
66
80
 
67
81
  ## Alternatives and compatibility
68
82
 
@@ -76,11 +90,13 @@ The internal constructor changes from terminal_barrier to terminal_policy;
76
90
  there is no compatibility alias or new public plugin API. Without a policy,
77
91
  Engine does not reserve a Workflow-specific event name. Production Workflow
78
92
  emits the result event only when it has injected its durable policy.
79
- Public signatures, Workflow command/result identities, data records and Storage
80
- SPI stay unchanged. One policy class and one decision value type are added;
81
- this is responsibility separation, not a total-line-count reduction.
93
+ At W2b, public signatures, Workflow command/result identities, data records and
94
+ Storage SPI stayed unchanged. One policy class and one decision value type were
95
+ added; this was responsibility separation, not a total-line-count reduction.
96
+ The later reconciliation APIs and result types are documented separately in the
97
+ [current contract](workflow-terminal-reconciliation.md).
82
98
 
83
- ## Acceptance evidence
99
+ ## Historical W2b acceptance evidence
84
100
 
85
101
  | Scenario | Test boundary |
86
102
  |---|---|