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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +87 -0
- data/README.md +24 -2
- data/SECURITY.md +1 -1
- data/docs/architecture/agent-approval-recovery.md +320 -0
- data/docs/architecture/agent-child-approval-recovery.md +387 -0
- data/docs/architecture/agent-child-execution-recovery.md +425 -0
- data/docs/architecture/agent-dispatch-recovery.md +308 -0
- data/docs/architecture/agent-terminal-persistence-evidence.md +360 -0
- data/docs/architecture/agent-terminal-recovery.md +298 -0
- data/docs/architecture/agent-terminal-submission-recovery.md +275 -0
- data/docs/architecture/agent-tool-child-lifetime.md +29 -0
- data/docs/architecture/agent-transition-ownership.md +24 -0
- data/docs/architecture/backend-groups.md +6 -0
- data/docs/architecture/detached-outcome-proof-projection.md +576 -0
- data/docs/architecture/execution-abstraction-review.md +5 -0
- data/docs/architecture/handoff-dispatch-recovery.md +205 -0
- data/docs/architecture/handoff-initial-terminal-application.md +321 -0
- data/docs/architecture/initial-preparation-recovery.md +308 -0
- data/docs/architecture/multi-agent-handoff.md +17 -0
- data/docs/architecture/native-outcome-preparation.md +715 -0
- data/docs/architecture/native-parent-dispatch-recovery.md +460 -0
- data/docs/architecture/native-parent-outcome-recovery.md +644 -0
- data/docs/architecture/parent-child-terminal-acknowledgement.md +297 -0
- data/docs/architecture/r8-unit12.md +6 -3
- data/docs/architecture/r8-unit4.md +11 -2
- data/docs/architecture/recovery-physical-attempt.md +88 -0
- data/docs/architecture/recovery-submission-custody.md +247 -0
- data/docs/architecture/retained-attempts.md +229 -0
- data/docs/architecture/retained-outcome-materialization.md +636 -0
- data/docs/architecture/retained-outcome-publication.md +506 -0
- data/docs/architecture/storage-execution-boundaries.md +1 -1
- data/docs/architecture/structured-output-and-scope.md +15 -0
- data/docs/architecture/synchronous-participant-application.md +397 -0
- data/docs/architecture/synchronous-participant-contract.md +195 -0
- data/docs/architecture/team-admission-rejection.md +91 -0
- data/docs/architecture/team-cancellation-delivery.md +245 -0
- data/docs/architecture/team-child-retirement.md +104 -0
- data/docs/architecture/tracing.md +26 -0
- data/docs/architecture/workflow-terminal-ownership-design.md +25 -9
- data/docs/architecture/workflow-terminal-reconciliation.md +221 -0
- data/docs/architecture.md +16 -9
- data/docs/decisions/025-process-local-agent-ownership-and-runtime-admission.md +8 -0
- data/docs/features.md +3 -3
- data/docs/mcp-client.md +138 -5
- data/docs/migrations/orchestrator-subagent-dispatch.md +89 -0
- data/docs/migrations/vector-async-clients.md +18 -3
- data/docs/persistence-backends.md +30 -4
- data/docs/runtime-and-concurrency.md +235 -11
- data/lib/phronomy/agent/admission.rb +37 -17
- data/lib/phronomy/agent/api/agent.rb +25 -0
- data/lib/phronomy/agent/approval_recovery.rb +30 -0
- data/lib/phronomy/agent/approval_recovery_api.rb +61 -0
- data/lib/phronomy/agent/approval_recovery_error.rb +39 -0
- data/lib/phronomy/agent/approval_recovery_result.rb +94 -0
- data/lib/phronomy/agent/async_event_api.rb +22 -5
- data/lib/phronomy/agent/base.rb +76 -48
- data/lib/phronomy/agent/context_preparation.rb +10 -8
- data/lib/phronomy/agent/dispatch_recovery.rb +29 -0
- data/lib/phronomy/agent/dispatch_recovery_api.rb +84 -0
- data/lib/phronomy/agent/dispatch_recovery_error.rb +36 -0
- data/lib/phronomy/agent/dispatch_recovery_result.rb +93 -0
- data/lib/phronomy/agent/execution/agent_invocation.rb +11 -3
- data/lib/phronomy/agent/execution/approval_continuation_plan.rb +131 -0
- data/lib/phronomy/agent/execution/approval_parent_evidence.rb +116 -0
- data/lib/phronomy/agent/execution/approval_persistence_evidence.rb +111 -0
- data/lib/phronomy/agent/execution/approval_recovery_operation.rb +496 -0
- data/lib/phronomy/agent/execution/approval_resume_commit.rb +174 -10
- data/lib/phronomy/agent/execution/dispatch_continuation_delivery.rb +96 -0
- data/lib/phronomy/agent/execution/dispatch_persistence_evidence.rb +147 -0
- data/lib/phronomy/agent/execution/dispatch_preparation.rb +63 -7
- data/lib/phronomy/agent/execution/dispatch_recovery_operation.rb +495 -0
- data/lib/phronomy/agent/execution/execution_coordinator.rb +724 -158
- data/lib/phronomy/agent/execution/execution_outcome_committer.rb +312 -39
- data/lib/phronomy/agent/execution/execution_registry.rb +508 -13
- data/lib/phronomy/agent/execution/initial_persistence_evidence.rb +269 -0
- data/lib/phronomy/agent/execution/initial_preparation.rb +132 -40
- data/lib/phronomy/agent/execution/initial_preparation_recovery_operation.rb +513 -0
- data/lib/phronomy/agent/execution/invocation_transitions.rb +3 -0
- data/lib/phronomy/agent/execution/outcome_planning.rb +108 -0
- data/lib/phronomy/agent/execution/outcome_preparation.rb +81 -0
- data/lib/phronomy/agent/execution/outcome_recovery_operation.rb +609 -0
- data/lib/phronomy/agent/execution/outcome_text_projection.rb +73 -0
- data/lib/phronomy/agent/execution/outcome_write_plan.rb +48 -0
- data/lib/phronomy/agent/execution/runtime_record_encoder.rb +7 -4
- data/lib/phronomy/agent/execution/terminal_persistence_evidence.rb +280 -0
- data/lib/phronomy/agent/execution/terminal_recovery_operation.rb +38 -0
- data/lib/phronomy/agent/execution_change.rb +138 -26
- data/lib/phronomy/agent/execution_environment.rb +29 -0
- data/lib/phronomy/agent/execution_rejected_error.rb +34 -0
- data/lib/phronomy/agent/initial_preparation_recovery.rb +32 -0
- data/lib/phronomy/agent/initial_preparation_recovery_api.rb +85 -0
- data/lib/phronomy/agent/initial_preparation_recovery_error.rb +41 -0
- data/lib/phronomy/agent/initial_preparation_recovery_result.rb +115 -0
- data/lib/phronomy/agent/lifecycle/hosted_approval_context.rb +86 -0
- data/lib/phronomy/agent/lifecycle/hosted_invocation.rb +42 -10
- data/lib/phronomy/agent/lifecycle/identity_write.rb +101 -0
- data/lib/phronomy/agent/lifecycle/lifetime_api.rb +28 -0
- data/lib/phronomy/agent/lifecycle/ownership_registry.rb +136 -70
- data/lib/phronomy/agent/lifecycle/scope.rb +3 -3
- data/lib/phronomy/agent/outcome_recovery.rb +47 -0
- data/lib/phronomy/agent/outcome_recovery_api.rb +114 -0
- data/lib/phronomy/agent/outcome_recovery_error.rb +36 -0
- data/lib/phronomy/agent/outcome_recovery_result.rb +92 -0
- data/lib/phronomy/agent/output_contract.rb +16 -6
- data/lib/phronomy/agent/persistence/identity_receipt_repository.rb +61 -0
- data/lib/phronomy/agent/persistence/records.rb +2 -0
- data/lib/phronomy/agent/persistence/storage_schema.rb +2 -0
- data/lib/phronomy/agent/recovery/invocation_restorer.rb +8 -5
- data/lib/phronomy/agent/recovery/recovery_coordinator/continuation.rb +6 -4
- data/lib/phronomy/agent/recovery/recovery_coordinator/installation.rb +21 -43
- data/lib/phronomy/agent/recovery/recovery_coordinator.rb +19 -6
- data/lib/phronomy/agent/runtime_binding/engine_environment.rb +12 -0
- data/lib/phronomy/agent/state_writer.rb +4 -3
- data/lib/phronomy/agent/store.rb +7 -1
- data/lib/phronomy/agent/terminal_recovery.rb +41 -0
- data/lib/phronomy/agent/terminal_recovery_api.rb +101 -0
- data/lib/phronomy/agent/terminal_recovery_error.rb +36 -0
- data/lib/phronomy/agent/terminal_recovery_result.rb +67 -0
- data/lib/phronomy/agent/tool_execution/tool_approval_request.rb +25 -1
- data/lib/phronomy/common/values/serializable.rb +37 -4
- data/lib/phronomy/engine/concurrency/offload_pool.rb +32 -4
- data/lib/phronomy/engine/concurrency/pool_registry.rb +6 -0
- data/lib/phronomy/engine/event_loop.rb +161 -11
- data/lib/phronomy/engine/execution_binding.rb +4 -2
- data/lib/phronomy/engine/execution_receiver_binding.rb +5 -0
- data/lib/phronomy/engine/runtime/shutdown_result.rb +21 -0
- data/lib/phronomy/engine/runtime/timer_queue.rb +7 -2
- data/lib/phronomy/engine/runtime.rb +119 -15
- data/lib/phronomy/execution/attempt_completion.rb +91 -0
- data/lib/phronomy/execution/concurrency/cancellation_token.rb +7 -2
- data/lib/phronomy/execution/concurrency/physical_completion_task.rb +7 -2
- data/lib/phronomy/execution/execution.rb +17 -2
- data/lib/phronomy/execution/execution_receiver.rb +27 -0
- data/lib/phronomy/execution/execution_retirement.rb +30 -0
- data/lib/phronomy/execution/invocation_controls.rb +2 -2
- data/lib/phronomy/execution/retained_attempts.rb +179 -0
- data/lib/phronomy/execution/stopped_terminal_custody.rb +99 -0
- data/lib/phronomy/llm_adapter/response.rb +7 -1
- data/lib/phronomy/multi_agent/admission_registry.rb +6 -0
- data/lib/phronomy/multi_agent/durable_subagent_coordinator.rb +175 -39
- data/lib/phronomy/multi_agent/handoff_dispatch_evidence.rb +176 -0
- data/lib/phronomy/multi_agent/handoff_finalization_error.rb +33 -0
- data/lib/phronomy/multi_agent/handoff_history_release.rb +80 -0
- data/lib/phronomy/multi_agent/handoff_participant.rb +31 -6
- data/lib/phronomy/multi_agent/handoff_runner.rb +195 -21
- data/lib/phronomy/multi_agent/handoff_terminal_finalization.rb +176 -0
- data/lib/phronomy/multi_agent/native_approval_evidence.rb +26 -0
- data/lib/phronomy/multi_agent/native_child_authority.rb +135 -0
- data/lib/phronomy/multi_agent/native_dispatch_evidence.rb +43 -0
- data/lib/phronomy/multi_agent/native_outcome_evidence.rb +46 -0
- data/lib/phronomy/multi_agent/native_persistence_plan.rb +93 -0
- data/lib/phronomy/multi_agent/orchestrator.rb +28 -52
- data/lib/phronomy/multi_agent/reserved_child_admission.rb +90 -1
- data/lib/phronomy/multi_agent/store.rb +5 -34
- data/lib/phronomy/multi_agent/subagent_history_release.rb +88 -0
- data/lib/phronomy/multi_agent/team_cancellation_delivery_error.rb +21 -0
- data/lib/phronomy/multi_agent/team_cancellation_request.rb +134 -0
- data/lib/phronomy/multi_agent/team_coordinator.rb +174 -27
- data/lib/phronomy/persistence_composition/stores.rb +10 -3
- data/lib/phronomy/runtime_composition/execution_defaults.rb +18 -0
- data/lib/phronomy/storage/backends/in_memory.rb +3 -1
- data/lib/phronomy/storage/resource.rb +10 -1
- data/lib/phronomy/tools/agent.rb +7 -1
- data/lib/phronomy/tools/mcp.rb +210 -91
- data/lib/phronomy/tools/mcp_http_close_response.rb +23 -0
- data/lib/phronomy/tools/mcp_transport_registry.rb +210 -0
- data/lib/phronomy/tools/vector_search.rb +28 -5
- data/lib/phronomy/tracing/automatic.rb +8 -1
- data/lib/phronomy/version.rb +1 -1
- data/lib/phronomy/workflow/execution/workflow.rb +34 -0
- data/lib/phronomy/workflow/execution/workflow_execution_environment.rb +1 -0
- data/lib/phronomy/workflow/execution/workflow_execution_registry.rb +106 -7
- data/lib/phronomy/workflow/execution/workflow_runner.rb +53 -108
- data/lib/phronomy/workflow/execution/workflow_terminal_operation.rb +489 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_persistence.rb +81 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_recovery.rb +38 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_recovery_error.rb +34 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_recovery_result.rb +56 -0
- data/lib/phronomy/workflow/runtime_binding/workflow_engine_environment.rb +10 -1
- data/lib/phronomy/workflow/runtime_binding/workflow_task_session.rb +3 -1
- data/lib/phronomy/workflow/runtime_binding/workflow_terminal_policy.rb +2 -1
- data/scripts/api_snapshot.rb +46 -1
- data/sig/_private/phronomy/multi_agent/team_cancellation_request.rbs +19 -0
- data/sig/phronomy/agent/approval_recovery.rbs +54 -0
- data/sig/phronomy/agent/dispatch_recovery.rbs +49 -0
- data/sig/phronomy/agent/execution_contract.rbs +4 -1
- data/sig/phronomy/agent/execution_environment.rbs +2 -0
- data/sig/phronomy/agent/initial_preparation_recovery.rbs +48 -0
- data/sig/phronomy/agent/outcome_recovery.rbs +51 -0
- data/sig/phronomy/agent/store.rbs +1 -0
- data/sig/phronomy/agent/terminal_persistence_evidence.rbs +111 -0
- data/sig/phronomy/agent/terminal_recovery.rbs +46 -0
- data/sig/phronomy/agent.rbs +36 -0
- data/sig/phronomy/engine/concurrency/timer_bindings.rbs +2 -0
- data/sig/phronomy/engine/execution_binding.rbs +2 -1
- data/sig/phronomy/engine/execution_receiver.rbs +4 -0
- data/sig/phronomy/engine/observability.rbs +22 -1
- data/sig/phronomy/execution/execution.rbs +16 -1
- data/sig/phronomy/execution/execution_receiver.rbs +12 -0
- data/sig/phronomy/execution/execution_retirement.rbs +18 -0
- data/sig/phronomy/execution/stopped_terminal_custody.rbs +19 -0
- data/sig/phronomy/handoff.rbs +1 -0
- data/sig/phronomy/multi_agent/handoff_finalization_error.rbs +18 -0
- data/sig/phronomy/multi_agent/store.rbs +1 -1
- data/sig/phronomy/multi_agent/team_cancellation_delivery_error.rbs +9 -0
- data/sig/phronomy/persistence_composition.rbs +2 -1
- data/sig/phronomy/storage/contracts.rbs +2 -1
- data/sig/phronomy/tools/mcp.rbs +27 -0
- data/sig/phronomy/workflow.rbs +42 -0
- metadata +104 -2
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
# Native parent final, wait and approval recovery
|
|
2
|
+
|
|
3
|
+
A native coordinating Agent owns its accepted execution even when the reply to a saved final outcome or wait is lost. Its native participant owns the child relationships and persistence effects that accompany that outcome. G3h retains those captured facts, applies them through the original live owner and exposes the saved kind explicitly. A saved wait and a finished job have different meanings.
|
|
4
|
+
|
|
5
|
+
For example, a report parent first waits for its review child, then waits for approval of its own publishing Tool, and finally completes the report. Any of those three saves can commit without a reply. Recovering the first or second save establishes the same wait; it does not publish the report, decide approval or manufacture a final execution result.
|
|
6
|
+
|
|
7
|
+
Baseline: applied G3g commit `44288e1239701bf16aa67854a48c830b7295e2d4`, tree `31193090f7305c82da780765f803b955742330c7`. This document describes the G3h implementation candidate. Contract concept v55 and foundation v48 remain the responsibility references. Exact source identity, Runtime results, complete application comparison and model results belong to the delivery evidence. The preceding [native dispatch contract](native-parent-dispatch-recovery.md) remains the reference for Provider/Tool prerequisites.
|
|
8
|
+
|
|
9
|
+
## Represent the saved kind without changing terminal recovery
|
|
10
|
+
|
|
11
|
+
`TerminalRecovery` continues to mean recovery of an actually final execution. The new `OutcomeRecovery` family represents a native parent's final, coordination-wait or approval-wait save. Both use one private retained-operation mechanism, with a thin terminal specialization preserving the existing public types. Sharing physical-attempt and observer handling does not merge their domain meanings.
|
|
12
|
+
|
|
13
|
+
For example, a receipt with `saved_outcome: :coordination_wait` has no terminal `ExecutionObservation`. Its original child may still be suspended. Calling the wait a successful terminal result would cause the application to discard unfinished responsibility.
|
|
14
|
+
|
|
15
|
+
| Candidate | Decision | Reason |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| Permit active/suspended executions in `TerminalRecoveryResult` | Withdraw | Would change the published meaning of terminal recovery |
|
|
18
|
+
| Add separate final, coordination-wait and approval-wait managers | Withdraw | Would duplicate retained-attempt, observation and submission mechanics |
|
|
19
|
+
| Add `OutcomeRecovery` with an explicit saved-kind receipt | Adopt | Distinguishes the domain outcomes while sharing the substantial owner mechanism |
|
|
20
|
+
| Return a new public execution task for every saved wait | Withdraw | Publishing a wait does not admit a new continuation; existing approval/resume APIs supply later observations |
|
|
21
|
+
| Add a universal Job API or participant recovery SPI | Defer | The native domain has bounded evidence; Handoff and arbitrary participants need their own authority and failure contracts |
|
|
22
|
+
|
|
23
|
+
`pending_outcome_recovery(execution_id:)` performs local lookup on the original Agent's existing Runtime registry. It performs no persistence I/O and creates no Runtime. Recovery methods require the exact issued `OutcomeRecovery`, operation profile and Agent incarnation; diagnostic identifiers cannot reconstruct this authority. A resolved capability can still return its receipt after pending lookup no longer finds it.
|
|
24
|
+
|
|
25
|
+
For example, after an invocation observer closes before receiving its recovery error, the host can retain the original parent and accepted execution identity, then find the still-retained obligation locally. Loading another parent with the same durable identifier is not an alternative recovery owner.
|
|
26
|
+
|
|
27
|
+
## Separate persistence facts, application and custody
|
|
28
|
+
|
|
29
|
+
The receipt records what was saved, whether the original owner applied it and whether that save-recovery responsibility was released. A captured proposal is not yet a saved fact. Only confirmed post-state has a saved kind, positive revision and its corresponding payload. Recovery release does not assert that an execution waiting on a child or human decision has finished.
|
|
30
|
+
|
|
31
|
+
For example, a confirmed approval wait can remain `application_state: :pending` after EventLoop publication is refused. Its request is evidence of the saved wait, not permission to bypass owner admission. Once applied, the same suspended execution retains its approval and cancellation ownership.
|
|
32
|
+
|
|
33
|
+
| Receipt reader | Contract |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `recovery`, `agent_id`, `execution_id`, `recovery_id` | Original process-local capability and diagnostic identity |
|
|
36
|
+
| `outcome` | `confirmed_post`, `confirmed_pre`, `unresolved` or `unavailable` |
|
|
37
|
+
| `saved_outcome` | Nil unless confirmed post; then `terminal`, `coordination_wait` or `approval_wait` |
|
|
38
|
+
| `revision` | Exact positive saved execution revision only for confirmed post |
|
|
39
|
+
| `execution` | Exact terminal `ExecutionObservation` only for `saved_outcome: :terminal` |
|
|
40
|
+
| `approval_request` | Exact `ToolApprovalRequest` for this execution only for `saved_outcome: :approval_wait` |
|
|
41
|
+
| Coordination-wait payload | Neither terminal execution nor approval request; saved kind, identity and revision identify the fact |
|
|
42
|
+
| `application_state` | `pending` or `applied` by the original owner |
|
|
43
|
+
| `ownership_state` | `retained` or `released` for save-recovery custody; release requires applied confirmed post-state |
|
|
44
|
+
| `submission_state` | `not_admitted`, `admitted` or `unknown`; positive non-admission cannot coexist with captured pre/post proof |
|
|
45
|
+
| `error` | Recovery diagnostic; an actual final business failure is separately represented by `execution.error` |
|
|
46
|
+
|
|
47
|
+
The result is immutable and rejects contradictory combinations. It has no `resolved?` or `execution_task` convenience field. The application checks confirmed post, applied state and released recovery custody, then branches on `saved_outcome`. `OutcomeRecoveryError` preserves the immediate failure as `cause`, the original save failure as `original_error` and the retained capability as `recovery`.
|
|
48
|
+
|
|
49
|
+
For example, terminal recovery can succeed as a persistence operation while returning a saved failed execution. An application must inspect the terminal execution status/error before announcing a successful report; absence of a recovery error does not imply business success.
|
|
50
|
+
|
|
51
|
+
## Keep each observer closed and publish waits through their owner
|
|
52
|
+
|
|
53
|
+
An uncertain save can end the original invocation observation with `OutcomeRecoveryError` while the retained operation keeps responsibility. Reconciliation returns a fresh observation and never reopens that failed or cancelled task or replays its old stream/event listener. The recovered state is published through the original coordinator and registry on EventLoop after physical-work and identity checks.
|
|
54
|
+
|
|
55
|
+
For example, a recovered own approval wait returns its exact request directly in the new receipt. The application uses that request with existing `approve_async`; it must not wait for the old listener to emit the same approval event again. Ordinary successful wait establishment keeps its existing event behavior.
|
|
56
|
+
|
|
57
|
+
A recovered coordination wait installs the existing private coordination-wait reference, allowing the existing child approval and parent resume flow. A recovered own approval wait installs a private canonical wait observer and cancellation binding; the execution remains suspended and owned. Actual final publication uses the existing terminal application and release rules. Parent/child unloading and retained-history policy remain separate from resolving the save operation.
|
|
58
|
+
|
|
59
|
+
For example, after the child's exact approval finishes, `parent.resume_async(parent_id)` can move the same report process to its own publishing approval. The application still supplies that second decision explicitly and unloads the pair only after the final parent and child conditions hold.
|
|
60
|
+
|
|
61
|
+
## Bound readback, captured retry and first submission
|
|
62
|
+
|
|
63
|
+
The three outcome operations have different authority. Readback classifies saved facts and applies a confirmed result. Captured retry writes only an already complete immutable proposal. First-submission retry is available only after positive execution-mechanism evidence proves the initial save worker was not admitted and no handle or worker entry contradicts that fact.
|
|
64
|
+
|
|
65
|
+
For example, a rolled-back coordination-wait save can be retried with the exact captured extension, holds, content and execution records. It cannot rerun child reservation, select a new child, repeat provider input preparation, re-encode the result or call the original participant's business decision again.
|
|
66
|
+
|
|
67
|
+
| Public operation | Preparation/encoding | Persistence writes | Authority |
|
|
68
|
+
| --- | --- | --- | --- |
|
|
69
|
+
| `reconcile_outcome[_async](recovery:)` | No | None | Complete retained proof or a conclusive original worker result |
|
|
70
|
+
| `retry_outcome[_async](recovery:)` | No | Exact captured writes only | Full guarded pre-state and native relationship checks; known post is read-only |
|
|
71
|
+
| `retry_outcome_submission[_async](recovery:)` | First run only | First save | Positive non-admission, no returned handle and no worker entry |
|
|
72
|
+
|
|
73
|
+
The retry runs under the original Store identity, an outer atomic transaction and ordered affected Agent guards. It rechecks the complete parent proof and permitted native child relationship, replays bounded captured writes, then verifies complete post-state. Missing, conflicting or unavailable evidence grants no guessed rollback or replacement-owner permission.
|
|
74
|
+
|
|
75
|
+
For example, an exact unimported child may legally progress from active to suspended while the parent wait save is being recovered. That is compatible with saving the same wait. An imported or acknowledged child must retain the required terminal history, and a captured terminal acknowledgement must still match the exact child outcome.
|
|
76
|
+
|
|
77
|
+
| Boundary | Native child rule |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| Captured outcome pre-state retry | Existing unimported/unacknowledged child may remain exactly correlated and active, suspended or terminal, or be fully absent under the saved reservation |
|
|
80
|
+
| Imported child or captured terminal acknowledgement | Exact terminal identity, definition, native correlation, required hold and applicable acknowledgement |
|
|
81
|
+
| New or replaced child slot | Refused by the outcome plan, which preserves the existing slot set; native dispatch has its separate reservation proof |
|
|
82
|
+
| Confirmed saved outcome publication | Publishes captured history; does not itself admit Provider/Tool work or decide an approval |
|
|
83
|
+
| First dispatch or approval continuation | Fresh stricter authority for exact terminal or permitted fully absent/unimported/unacknowledged children |
|
|
84
|
+
|
|
85
|
+
An admitted worker that fails before producing complete outcome proof remains a retained, unavailable obligation. Neither absence of proof nor a stopped worker proves non-admission, and this increment does not add general encoder/preparation retry. That case remains explicit within completion group 1.
|
|
86
|
+
|
|
87
|
+
For example, if encoding raises after the worker accepted the command but before a full proposal exists, `retry_outcome_submission` cannot repeat it. Retaining the original owner is the supported safe disposition; automatic invocation retry would risk repeating earlier report effects.
|
|
88
|
+
|
|
89
|
+
## Recover the native parent's own approval decision
|
|
90
|
+
|
|
91
|
+
Saving an approval wait and saving its decision are separate operations. G3h extends existing `ApprovalRecovery` to a supported native parent's own Tool approval decision. It captures the complete parent pre/post proof and detached native authority, then checks current child authority under ordered guards before restoring or admitting the decision's continuation. It adds no approval-write retry API.
|
|
92
|
+
|
|
93
|
+
For example, the report parent has already imported its completed review child when the human approves publication. A lost decision response can leave a committed approval with a locally suspended parent. `reconcile_approval` can apply that same decision once and return its existing fresh execution observation without asking the human to decide again.
|
|
94
|
+
|
|
95
|
+
| Decision proof | Original-owner action |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| Confirmed pre-state with current authority | Restore the exact original request/wait; a subsequent approval is a separate explicit application decision |
|
|
98
|
+
| Confirmed post-state with current authority | Apply the captured approved/rejected decision once and resume the existing Tool batch |
|
|
99
|
+
| Confirmed post-state with changed authority | Preserve the historical committed decision but withhold continuation; no rewritten history or repeated decision |
|
|
100
|
+
| Unavailable or conflicting proof | Retain responsibility; do not guess approval or rejection |
|
|
101
|
+
| Complete captured decision before a failed first content write | Reconcile that full pre/post proof; no decision replay |
|
|
102
|
+
| Failure before complete proof with positive no-write-started evidence | After original physical completion, explicitly validate and restore only the same original wait through read-only recovery |
|
|
103
|
+
|
|
104
|
+
The proof captures decision bytes, reference and proposed records before the first content write, so a content-store failure does not unnecessarily discard available evidence. A pure capture/read failure preceding complete proof has the narrower no-write-started restoration route described above. This positive evidence is not a general retry permission for an admitted incomplete outcome proposal.
|
|
105
|
+
|
|
106
|
+
For example, after confirmed pre-state the report application may explicitly choose `approve_after_restore: true` and call `approve_async` again for the same request. Reconciliation itself never makes that fresh choice. After confirmed post-state it observes the already authorized continuation through `ApprovalRecoveryResult#execution_task`.
|
|
107
|
+
|
|
108
|
+
A Provider batch containing both an ordinary protected Tool and native child dispatch has an additional existing boundary. Exact G3g ordinary-flow characterization reaches a factual-resolution requirement after the child completes. G3h decision recovery preserves the captured decision and effect counts on that path, but does not make subsequent parent resume automatically finish it. The existing public factual-resolution operation completes the supported flow once the application supplies an independently known ordinary Tool result; recovery does not invent that result or silently resolve its subject.
|
|
109
|
+
|
|
110
|
+
For example, the complete application below uses sequential batches: child review finishes before the parent asks to publish. That path completes its five Provider calls and two Tool effects. Separate mixed-batch pre/post decision-loss acceptance uses `recovery_resolution_required` to obtain the exact execution revision and ordinary Tool subject, then calls `parent.resolve_async(execution_id, expected_execution_revision: revision, subject: subject, outcome: :succeeded, result: independently_known_result)`. Both cases finish with four Provider calls, one parent and one child effect, and eligible pair unload. The framework's native child slot resumes through its own contract; the application does not supply a fabricated framework Tool result. This verifies the explicit factual-resolution route, not automatic mixed-batch completion.
|
|
111
|
+
|
|
112
|
+
## Preserve public symmetry without merging operation meanings
|
|
113
|
+
|
|
114
|
+
Lookup, exact capability identity, fresh observation, host-thread waiting and original-owner custody follow the existing recovery conventions. Domain-specific results preserve the difference between a final fact, a saved wait and permission to start protected work. The public names and RBS signatures remain paired with their existing families.
|
|
115
|
+
|
|
116
|
+
For example, both terminal and outcome save retry are explicit captured-write operations, while approval recovery remains read-only. Adding a similarly named approval retry merely for surface symmetry would authorize a different decision and change the contract.
|
|
117
|
+
|
|
118
|
+
| Dimension | Terminal recovery | Outcome recovery | Approval recovery | Dispatch recovery |
|
|
119
|
+
| --- | --- | --- | --- | --- |
|
|
120
|
+
| Local lookup | `pending_terminal_recovery` | `pending_outcome_recovery` | `pending_approval_recovery` | `pending_dispatch_recovery` |
|
|
121
|
+
| Readback | `reconcile_terminal[_async]` | `reconcile_outcome[_async]` | `reconcile_approval[_async]` | `reconcile_dispatch[_async]` |
|
|
122
|
+
| Captured writes | `retry_terminal[_async]` | `retry_outcome[_async]` | None | `retry_dispatch[_async]` |
|
|
123
|
+
| Positive first-submission retry | `retry_terminal_submission[_async]` | `retry_outcome_submission[_async]` | Existing decision-owner policy | No new operation |
|
|
124
|
+
| Saved meaning | Actually final execution | Final, coordination wait or approval wait | One approval decision | Dispatch prerequisite |
|
|
125
|
+
| Later execution observation | Saved terminal `execution` | Terminal `execution` only; exact approval request for approval wait | Existing `execution_task` after resumed decision | Existing `execution_task` after continuation handoff |
|
|
126
|
+
| Resolved custody | Terminal save owner released | Save owner released; waiting job is not thereby final | Wait restored or continuation admitted | Continuing job remains owned |
|
|
127
|
+
| Observer policy | Earlier task stays closed | Same | Same | Same |
|
|
128
|
+
| Domain authority | Exact original owner and captured final proof | Native immutable outcome plan and bounded relationship proof | Fresh native child authority before decision application | Fresh native child authority before first continuation |
|
|
129
|
+
|
|
130
|
+
The substantial private physical-attempt machinery is shared by terminal and outcome owners. Native captured content/hold/execution plan and child-identity checks are shared within MultiAgent across dispatch, outcome and approval evidence where their meanings coincide. Agent consumes opaque native evidence; it does not interpret child-slot schema or call a concrete native coordinator class. These are bounded internal collaborators, not an external library or broad extension SPI.
|
|
131
|
+
|
|
132
|
+
For example, sharing an identity/correlation check avoids inconsistent replacement-child rules, while an outcome-specific flag still permits legal unfinished-child progress during wait-save retry. Forcing the stricter dispatch rule onto that retry would block a valid coordination wait.
|
|
133
|
+
|
|
134
|
+
## Preserve the complete report application
|
|
135
|
+
|
|
136
|
+
The complete application below creates one native parent, approves one review child, resumes the same parent, explicitly approves its own publishing Tool, observes the final report and unloads the eligible pair. The deterministic Provider adapter sends no network request; Agent, Store, Runtime, approval and ownership paths are real.
|
|
137
|
+
|
|
138
|
+
For example, the normal baseline report has child output `review ready`, parent output `report ready`, five Provider calls, one review effect and one publication effect. Both saved executions complete, with parent/child revisions 9/6 and one retained-history hold each. The candidate comparison uses the same complete normal source; fault recovery is a separate intentional behavior change, not an equivalence claim for ambiguous saves.
|
|
139
|
+
|
|
140
|
+
### Shared service and equivalent normal functions
|
|
141
|
+
|
|
142
|
+
The shared definitions contain both approval-requiring Tools, the exact parent/child definitions, a deterministic adapter and the public approval listener. Assemble them with one of the complete normal functions and the driver to reproduce the ordinary flow. The normal before/after columns intentionally contain identical source.
|
|
143
|
+
|
|
144
|
+
For example, the approval event's exact execution identity selects the child, while the second request must identify the parent. The application never parses native extension content to discover either approval target.
|
|
145
|
+
|
|
146
|
+
<!-- generated-application:shared-and-normal -->
|
|
147
|
+
|
|
148
|
+
<!-- example: shared-setup -->
|
|
149
|
+
```ruby
|
|
150
|
+
# frozen_string_literal: true
|
|
151
|
+
|
|
152
|
+
require "phronomy"
|
|
153
|
+
require "json"
|
|
154
|
+
require "timeout"
|
|
155
|
+
|
|
156
|
+
require "phronomy"
|
|
157
|
+
require "json"
|
|
158
|
+
require "timeout"
|
|
159
|
+
class G3hReviewTool < Phronomy::Tool::Base
|
|
160
|
+
tool_name "review_one_report"
|
|
161
|
+
description "Review the approved report once"
|
|
162
|
+
requires_approval true
|
|
163
|
+
|
|
164
|
+
class << self
|
|
165
|
+
attr_accessor :effects
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def execute(query:)
|
|
169
|
+
self.class.effects << query
|
|
170
|
+
"reviewed #{query}"
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
class G3hPublishTool < Phronomy::Tool::Base
|
|
175
|
+
tool_name "publish_one_report"
|
|
176
|
+
description "Publish the approved report once"
|
|
177
|
+
requires_approval true
|
|
178
|
+
|
|
179
|
+
class << self
|
|
180
|
+
attr_accessor :effects
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def execute(query:)
|
|
184
|
+
self.class.effects << query
|
|
185
|
+
"published #{query}"
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
class G3hReviewAgent < Phronomy::Agent::Base
|
|
190
|
+
agent_definition id: "native-outcome-reviewer", version: 1
|
|
191
|
+
model "offline-model"
|
|
192
|
+
tools G3hReviewTool => nil
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
class G3hReportParent < Phronomy::MultiAgent::Orchestrator
|
|
196
|
+
agent_definition id: "native-outcome-parent", version: 1
|
|
197
|
+
model "offline-model"
|
|
198
|
+
tools G3hPublishTool => nil
|
|
199
|
+
subagent :reviewer, G3hReviewAgent
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
class G3hReportAdapter < Phronomy::LLMAdapter::Base
|
|
203
|
+
attr_reader :calls
|
|
204
|
+
|
|
205
|
+
def initialize
|
|
206
|
+
@calls = 0
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def perform_complete(_request, cancellation_token:)
|
|
210
|
+
cancellation_token&.raise_if_cancelled!
|
|
211
|
+
@calls += 1
|
|
212
|
+
name, arguments = case @calls
|
|
213
|
+
when 1 then ["dispatch_to_reviewer", {input: "Review the report"}]
|
|
214
|
+
when 2 then ["review_one_report", {query: "quarterly report"}]
|
|
215
|
+
when 3
|
|
216
|
+
return Phronomy::LLMAdapter::Response.new(content: "review ready", finish_reason: :stop)
|
|
217
|
+
when 4 then ["publish_one_report", {query: "quarterly report"}]
|
|
218
|
+
when 5
|
|
219
|
+
return Phronomy::LLMAdapter::Response.new(content: "report ready", finish_reason: :stop)
|
|
220
|
+
else
|
|
221
|
+
raise "Unexpected repeated Provider work"
|
|
222
|
+
end
|
|
223
|
+
Phronomy::LLMAdapter::Response.new(tool_calls: [
|
|
224
|
+
Phronomy::Tool::CallRequest.new(id: "call-#{@calls}", name: name, arguments: arguments)
|
|
225
|
+
], finish_reason: :tool_calls)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def build_report_service
|
|
230
|
+
G3hReviewTool.effects = []
|
|
231
|
+
G3hPublishTool.effects = []
|
|
232
|
+
adapter = G3hReportAdapter.new
|
|
233
|
+
Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
|
|
234
|
+
stores = Phronomy::PersistenceComposition.in_memory
|
|
235
|
+
approvals = Queue.new
|
|
236
|
+
parent = G3hReportParent.create(agent_id: "native-outcome-parent", persistence: stores.agent,
|
|
237
|
+
coordination_store: stores.multi_agent,
|
|
238
|
+
on_event: ->(event) { approvals << event.payload.fetch(:request) if event.type == :approval_required })
|
|
239
|
+
[adapter, stores, approvals, parent]
|
|
240
|
+
end
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
<table>
|
|
244
|
+
<thead><tr><th>Before: applied G3g baseline</th><th>After: G3h candidate</th></tr></thead>
|
|
245
|
+
<tbody><tr><td>
|
|
246
|
+
<!-- example: normal-before -->
|
|
247
|
+
<pre><code># The exact approval request identifies which entity may accept the decision.
|
|
248
|
+
def run_report
|
|
249
|
+
adapter, stores, approvals, parent = build_report_service
|
|
250
|
+
parent_id = "native-report-execution"
|
|
251
|
+
reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
|
|
252
|
+
original = parent.start_hosted(reservation: reservation, input: "Prepare and publish the report")
|
|
253
|
+
child_request = Timeout.timeout(5) { approvals.pop }
|
|
254
|
+
begin
|
|
255
|
+
original.wait_result(timeout: 5)
|
|
256
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
257
|
+
# The parent waits for this approval-driven child.
|
|
258
|
+
end
|
|
259
|
+
child = Phronomy::Agent::Base.live_for_execution(child_request.execution_id)
|
|
260
|
+
child_result = child.approve_async(child_request.execution_id,
|
|
261
|
+
approval_request_id: child_request.id, approved: true).wait_result(timeout: 5)
|
|
262
|
+
continued = parent.resume_async(parent_id)
|
|
263
|
+
parent_request = Timeout.timeout(5) { approvals.pop }
|
|
264
|
+
raise "Expected the parent's own approval" unless parent_request.execution_id == parent_id
|
|
265
|
+
begin
|
|
266
|
+
continued.wait_result(timeout: 5)
|
|
267
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
268
|
+
# The parent now waits for its own publication decision.
|
|
269
|
+
end
|
|
270
|
+
parent_result = parent.approve_async(parent_id,
|
|
271
|
+
approval_request_id: parent_request.id, approved: true).wait_result(timeout: 5)
|
|
272
|
+
released = parent.unload_with_completed_child!(parent_id, execution_id: child_request.execution_id)
|
|
273
|
+
{
|
|
274
|
+
child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
|
|
275
|
+
review_effects: G3hReviewTool.effects, publication_effects: G3hPublishTool.effects,
|
|
276
|
+
provider_calls: adapter.calls, released: released,
|
|
277
|
+
statuses: [parent_id, child_request.execution_id].map { |id| stores.agent.executions.load(id).status },
|
|
278
|
+
revisions: [parent_id, child_request.execution_id].map { |id| stores.agent.executions.load(id).execution_revision },
|
|
279
|
+
history_holds: [parent.agent_id, child.agent_id].map { |id| stores.agent.retained_references(agent_id: id).size }
|
|
280
|
+
}
|
|
281
|
+
end</code></pre>
|
|
282
|
+
</td><td>
|
|
283
|
+
<!-- example: normal-after -->
|
|
284
|
+
<pre><code># The exact approval request identifies which entity may accept the decision.
|
|
285
|
+
def run_report
|
|
286
|
+
adapter, stores, approvals, parent = build_report_service
|
|
287
|
+
parent_id = "native-report-execution"
|
|
288
|
+
reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
|
|
289
|
+
original = parent.start_hosted(reservation: reservation, input: "Prepare and publish the report")
|
|
290
|
+
child_request = Timeout.timeout(5) { approvals.pop }
|
|
291
|
+
begin
|
|
292
|
+
original.wait_result(timeout: 5)
|
|
293
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
294
|
+
# The parent waits for this approval-driven child.
|
|
295
|
+
end
|
|
296
|
+
child = Phronomy::Agent::Base.live_for_execution(child_request.execution_id)
|
|
297
|
+
child_result = child.approve_async(child_request.execution_id,
|
|
298
|
+
approval_request_id: child_request.id, approved: true).wait_result(timeout: 5)
|
|
299
|
+
continued = parent.resume_async(parent_id)
|
|
300
|
+
parent_request = Timeout.timeout(5) { approvals.pop }
|
|
301
|
+
raise "Expected the parent's own approval" unless parent_request.execution_id == parent_id
|
|
302
|
+
begin
|
|
303
|
+
continued.wait_result(timeout: 5)
|
|
304
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
305
|
+
# The parent now waits for its own publication decision.
|
|
306
|
+
end
|
|
307
|
+
parent_result = parent.approve_async(parent_id,
|
|
308
|
+
approval_request_id: parent_request.id, approved: true).wait_result(timeout: 5)
|
|
309
|
+
released = parent.unload_with_completed_child!(parent_id, execution_id: child_request.execution_id)
|
|
310
|
+
{
|
|
311
|
+
child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
|
|
312
|
+
review_effects: G3hReviewTool.effects, publication_effects: G3hPublishTool.effects,
|
|
313
|
+
provider_calls: adapter.calls, released: released,
|
|
314
|
+
statuses: [parent_id, child_request.execution_id].map { |id| stores.agent.executions.load(id).status },
|
|
315
|
+
revisions: [parent_id, child_request.execution_id].map { |id| stores.agent.executions.load(id).execution_revision },
|
|
316
|
+
history_holds: [parent.agent_id, child.agent_id].map { |id| stores.agent.retained_references(agent_id: id).size }
|
|
317
|
+
}
|
|
318
|
+
end</code></pre>
|
|
319
|
+
</td></tr></tbody>
|
|
320
|
+
</table>
|
|
321
|
+
|
|
322
|
+
<!-- /generated-application:shared-and-normal -->
|
|
323
|
+
|
|
324
|
+
### Complete recovery helper and application function
|
|
325
|
+
|
|
326
|
+
The recovery branch uses only the original parent and public recovery APIs. It performs one reconciliation and, only when explicitly configured, one captured-write retry for confirmed pre-state. An unresolved result returns the original parent, capability and receipt to the host; it does not invoke a replacement job, loop indefinitely or release unresolved responsibility.
|
|
327
|
+
|
|
328
|
+
For example, a recovered approval-wait receipt supplies the exact request directly. A recovered approval decision uses the existing decision receipt's continuation state. Its confirmed-pre branch sends a fresh decision only when the separate `approve_after_restore` policy permits it.
|
|
329
|
+
|
|
330
|
+
<!-- generated-application:recovery -->
|
|
331
|
+
|
|
332
|
+
<!-- example: recovery-helper -->
|
|
333
|
+
```ruby
|
|
334
|
+
# This example retries only captured outcome persistence when its application
|
|
335
|
+
# explicitly permits that action. Wait recovery is not job completion.
|
|
336
|
+
def settle_parent_outcome(parent:, failure:, retry_confirmed_pre:, recoveries:)
|
|
337
|
+
recovery = parent.pending_outcome_recovery(execution_id: failure.recovery.execution_id)
|
|
338
|
+
raise "The exact outcome owner was not retained" unless recovery.equal?(failure.recovery)
|
|
339
|
+
receipt = parent.reconcile_outcome(recovery: recovery)
|
|
340
|
+
if retry_confirmed_pre && receipt.outcome == :confirmed_pre
|
|
341
|
+
receipt = parent.retry_outcome(recovery: recovery)
|
|
342
|
+
end
|
|
343
|
+
applied = receipt.outcome == :confirmed_post && receipt.application_state == :applied && receipt.ownership_state == :released
|
|
344
|
+
return {state: :recovery_pending, parent: parent, recovery: recovery, receipt: receipt} unless applied
|
|
345
|
+
|
|
346
|
+
recoveries << {operation: :outcome, saved_outcome: receipt.saved_outcome, outcome: receipt.outcome}
|
|
347
|
+
case receipt.saved_outcome
|
|
348
|
+
when :coordination_wait then {state: :coordination_wait}
|
|
349
|
+
when :approval_wait then {state: :approval_wait, request: receipt.approval_request}
|
|
350
|
+
when :terminal
|
|
351
|
+
execution = receipt.execution
|
|
352
|
+
raise "Report failed: #{execution.error.inspect}" unless execution.status == :completed
|
|
353
|
+
{state: :completed, result: {output: execution.result}}
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
# expected_wait describes this report's two known waiting points. It is not a
|
|
358
|
+
# general classification of every ExecutionRehydrationRequiredError.
|
|
359
|
+
def await_parent_outcome(parent:, task:, expected_wait:, retry_confirmed_pre:, recoveries:)
|
|
360
|
+
{state: :completed, result: task.wait_result(timeout: 5)}
|
|
361
|
+
rescue Phronomy::Agent::OutcomeRecoveryError => failure
|
|
362
|
+
observed = settle_parent_outcome(parent: parent, failure: failure,
|
|
363
|
+
retry_confirmed_pre: retry_confirmed_pre, recoveries: recoveries)
|
|
364
|
+
begin
|
|
365
|
+
task.wait_result(timeout: 5)
|
|
366
|
+
raise "The earlier failed observation reopened"
|
|
367
|
+
rescue Phronomy::Agent::OutcomeRecoveryError => repeated
|
|
368
|
+
raise "The earlier failure changed" unless repeated.equal?(failure)
|
|
369
|
+
end
|
|
370
|
+
observed
|
|
371
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
372
|
+
{state: expected_wait}
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
# Approval recovery only reconciles the old decision. A confirmed pre-state
|
|
376
|
+
# restores the exact wait; sending an approval again is a separate user policy.
|
|
377
|
+
def approve_report(parent:, execution_id:, request:, approve_after_restore:, retry_confirmed_pre:, recoveries:)
|
|
378
|
+
task = parent.approve_async(execution_id, approval_request_id: request.id, approved: true)
|
|
379
|
+
begin
|
|
380
|
+
await_parent_outcome(parent: parent, task: task, expected_wait: :approval_wait,
|
|
381
|
+
retry_confirmed_pre: retry_confirmed_pre, recoveries: recoveries)
|
|
382
|
+
rescue Phronomy::Agent::ApprovalRecoveryError => failure
|
|
383
|
+
recovery = parent.pending_approval_recovery(execution_id: execution_id)
|
|
384
|
+
raise "The exact approval owner was not retained" unless recovery.equal?(failure.recovery)
|
|
385
|
+
receipt = parent.reconcile_approval(recovery: recovery)
|
|
386
|
+
unless receipt.resolved?
|
|
387
|
+
return {state: :recovery_pending, parent: parent, recovery: recovery, receipt: receipt}
|
|
388
|
+
end
|
|
389
|
+
begin
|
|
390
|
+
task.wait_result(timeout: 5)
|
|
391
|
+
raise "The earlier failed decision reopened"
|
|
392
|
+
rescue Phronomy::Agent::ApprovalRecoveryError => repeated
|
|
393
|
+
raise "The earlier decision failure changed" unless repeated.equal?(failure)
|
|
394
|
+
end
|
|
395
|
+
recoveries << {operation: :approval, outcome: receipt.outcome, continuation_state: receipt.continuation_state}
|
|
396
|
+
if receipt.continuation_state == :restored
|
|
397
|
+
unless approve_after_restore
|
|
398
|
+
return {state: :approval_wait, parent: parent, request: request, receipt: receipt}
|
|
399
|
+
end
|
|
400
|
+
next_task = parent.approve_async(execution_id, approval_request_id: request.id, approved: true)
|
|
401
|
+
else
|
|
402
|
+
next_task = receipt.execution_task
|
|
403
|
+
end
|
|
404
|
+
await_parent_outcome(parent: parent, task: next_task, expected_wait: :approval_wait,
|
|
405
|
+
retry_confirmed_pre: retry_confirmed_pre, recoveries: recoveries)
|
|
406
|
+
end
|
|
407
|
+
end
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
<!-- example: recovery-function -->
|
|
411
|
+
```ruby
|
|
412
|
+
# The same business process has two independent application approvals. Neither
|
|
413
|
+
# persistence recovery nor a recovered wait silently supplies either decision.
|
|
414
|
+
def run_report_with_recovery(fault:, retry_confirmed_pre: false, approve_after_restore: false)
|
|
415
|
+
adapter, stores, approvals, parent = build_report_service
|
|
416
|
+
parent_id = "native-report-execution"
|
|
417
|
+
fault.call(stores.agent, parent_id)
|
|
418
|
+
reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
|
|
419
|
+
recoveries = []
|
|
420
|
+
original = parent.start_hosted(reservation: reservation, input: "Prepare and publish the report")
|
|
421
|
+
first = await_parent_outcome(parent: parent, task: original, expected_wait: :coordination_wait,
|
|
422
|
+
retry_confirmed_pre: retry_confirmed_pre, recoveries: recoveries)
|
|
423
|
+
return first.merge(stores: stores, execution_id: parent_id, provider_calls: adapter.calls) if first.fetch(:state) == :recovery_pending
|
|
424
|
+
raise "Expected the child coordination wait" unless first.fetch(:state) == :coordination_wait
|
|
425
|
+
child_request = Timeout.timeout(5) { approvals.pop }
|
|
426
|
+
child = Phronomy::Agent::Base.live_for_execution(child_request.execution_id)
|
|
427
|
+
child_result = child.approve_async(child_request.execution_id,
|
|
428
|
+
approval_request_id: child_request.id, approved: true).wait_result(timeout: 5)
|
|
429
|
+
continued = parent.resume_async(parent_id)
|
|
430
|
+
second = await_parent_outcome(parent: parent, task: continued, expected_wait: :approval_wait,
|
|
431
|
+
retry_confirmed_pre: retry_confirmed_pre, recoveries: recoveries)
|
|
432
|
+
return second.merge(stores: stores, child: child, execution_id: parent_id, provider_calls: adapter.calls) if second.fetch(:state) == :recovery_pending
|
|
433
|
+
raise "Expected the parent's own approval" unless second.fetch(:state) == :approval_wait
|
|
434
|
+
parent_request = second[:request] || Timeout.timeout(5) { approvals.pop }
|
|
435
|
+
raise "Approval identifies another execution" unless parent_request.execution_id == parent_id
|
|
436
|
+
final = approve_report(parent: parent, execution_id: parent_id, request: parent_request,
|
|
437
|
+
approve_after_restore: approve_after_restore, retry_confirmed_pre: retry_confirmed_pre, recoveries: recoveries)
|
|
438
|
+
unless final.fetch(:state) == :completed
|
|
439
|
+
return final.merge(stores: stores, child: child, execution_id: parent_id, provider_calls: adapter.calls)
|
|
440
|
+
end
|
|
441
|
+
released = parent.unload_with_completed_child!(parent_id, execution_id: child_request.execution_id)
|
|
442
|
+
{
|
|
443
|
+
state: :observed, child_output: child_result.fetch(:output), parent_output: final.fetch(:result).fetch(:output),
|
|
444
|
+
review_effects: G3hReviewTool.effects, publication_effects: G3hPublishTool.effects,
|
|
445
|
+
provider_calls: adapter.calls, released: released,
|
|
446
|
+
statuses: [parent_id, child_request.execution_id].map { |id| stores.agent.executions.load(id).status },
|
|
447
|
+
history_holds: [parent.agent_id, child.agent_id].map { |id| stores.agent.retained_references(agent_id: id).size },
|
|
448
|
+
recoveries: recoveries
|
|
449
|
+
}
|
|
450
|
+
end
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
<!-- /generated-application:recovery -->
|
|
454
|
+
|
|
455
|
+
### Fault fixture and executable driver
|
|
456
|
+
|
|
457
|
+
The fault fixture is test infrastructure, separate from the application's public API. It rolls back or commits one selected parent transaction and loses its response, with immediate readback suppression where needed to expose retained recovery. It does not modify Provider or Tool behavior. The shared driver defaults to the complete normal function and selects recovery through explicit scenario, boundary/mode and independent captured-retry and fresh-approval policies.
|
|
458
|
+
|
|
459
|
+
For example, a terminal post-state fault should produce the same two effects as the normal report and a terminal outcome receipt. An approval-decision pre-state fault requires restoring the old wait and an explicitly permitted new decision before publication can run.
|
|
460
|
+
|
|
461
|
+
<!-- generated-application:fixture-and-driver -->
|
|
462
|
+
|
|
463
|
+
<!-- example: fault-fixture -->
|
|
464
|
+
```ruby
|
|
465
|
+
# This optional persistence response-loss fixture is separate from application
|
|
466
|
+
# policy. It does not alter Provider responses, approvals or Tool results.
|
|
467
|
+
module G3hOutcomeFaultScope
|
|
468
|
+
def perform
|
|
469
|
+
fault = coordinator.instance_variable_get(:@g3h_parent_fault)
|
|
470
|
+
previous = Thread.current[:g3h_parent_fault]
|
|
471
|
+
selected = fault && execution_id == fault.fetch(:execution_id) && kind == :terminal &&
|
|
472
|
+
case fault.fetch(:boundary)
|
|
473
|
+
when :terminal then finishing?
|
|
474
|
+
when :coordination_wait then recovery_required
|
|
475
|
+
when :approval_wait then !finishing? && !recovery_required
|
|
476
|
+
else false
|
|
477
|
+
end
|
|
478
|
+
Thread.current[:g3h_parent_fault] = selected ? fault : nil
|
|
479
|
+
super
|
|
480
|
+
ensure
|
|
481
|
+
Thread.current[:g3h_parent_fault] = previous
|
|
482
|
+
end
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
module G3hApprovalFaultScope
|
|
486
|
+
def commit(operation)
|
|
487
|
+
with_g3h_decision_fault(operation) { super }
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
def commit_retained(operation, **options)
|
|
491
|
+
with_g3h_decision_fault(operation) { super }
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
private
|
|
495
|
+
|
|
496
|
+
def with_g3h_decision_fault(operation)
|
|
497
|
+
fault = @persistence.coordinator.instance_variable_get(:@g3h_parent_fault)
|
|
498
|
+
previous = Thread.current[:g3h_parent_fault]
|
|
499
|
+
selected = fault && fault.fetch(:boundary) == :approval_decision && operation.execution_id == fault.fetch(:execution_id)
|
|
500
|
+
Thread.current[:g3h_parent_fault] = selected ? fault : nil
|
|
501
|
+
yield
|
|
502
|
+
ensure
|
|
503
|
+
Thread.current[:g3h_parent_fault] = previous
|
|
504
|
+
end
|
|
505
|
+
end
|
|
506
|
+
|
|
507
|
+
module G3hAtomicFault
|
|
508
|
+
def atomic(*args, &transaction)
|
|
509
|
+
fault = Thread.current[:g3h_parent_fault]
|
|
510
|
+
return super unless fault
|
|
511
|
+
if fault[:readback]
|
|
512
|
+
fault[:readback] = false
|
|
513
|
+
raise IOError, "Immediate native parent readback unavailable"
|
|
514
|
+
end
|
|
515
|
+
return super unless fault[:armed]
|
|
516
|
+
fault[:armed] = false
|
|
517
|
+
fault[:attempts] += 1
|
|
518
|
+
if fault.fetch(:mode) == :pre
|
|
519
|
+
super do |scope|
|
|
520
|
+
transaction.call(scope)
|
|
521
|
+
fault[:readback] = fault.fetch(:boundary) != :approval_decision
|
|
522
|
+
raise IOError, "Native parent transaction rolled back; response lost"
|
|
523
|
+
end
|
|
524
|
+
else
|
|
525
|
+
super
|
|
526
|
+
fault[:readback] = fault.fetch(:boundary) != :approval_decision
|
|
527
|
+
raise IOError, "Native parent transaction committed; response lost"
|
|
528
|
+
end
|
|
529
|
+
end
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
Phronomy::Agent::ExecutionChange.prepend(G3hOutcomeFaultScope)
|
|
533
|
+
Phronomy::Agent::ApprovalResumeCommit.prepend(G3hApprovalFaultScope)
|
|
534
|
+
|
|
535
|
+
def parent_reply_loss(boundary:, mode:)
|
|
536
|
+
raise ArgumentError, "Unsupported native boundary" unless %i[terminal coordination_wait approval_wait approval_decision].include?(boundary)
|
|
537
|
+
raise ArgumentError, "Unsupported save outcome" unless %i[pre post].include?(mode)
|
|
538
|
+
lambda do |store, execution_id|
|
|
539
|
+
store.coordinator.singleton_class.prepend(G3hAtomicFault)
|
|
540
|
+
store.coordinator.instance_variable_set(:@g3h_parent_fault,
|
|
541
|
+
{boundary: boundary, mode: mode, execution_id: execution_id, armed: true, readback: false, attempts: 0})
|
|
542
|
+
end
|
|
543
|
+
end
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
<!-- example: shared-driver -->
|
|
547
|
+
```ruby
|
|
548
|
+
# A running service keeps the returned parent, capability and receipt when
|
|
549
|
+
# recovery is pending. This one-shot demonstration reports that state and its
|
|
550
|
+
# cleanup result before the process ends; it is not a crash recovery service.
|
|
551
|
+
def run_report_example(scenario:, boundary: :terminal, mode: :post,
|
|
552
|
+
retry_confirmed_pre: false, approve_after_restore: false)
|
|
553
|
+
raise ArgumentError, "Unknown report scenario" unless %i[normal recovery].include?(scenario)
|
|
554
|
+
begin
|
|
555
|
+
value = if scenario == :normal
|
|
556
|
+
run_report
|
|
557
|
+
else
|
|
558
|
+
run_report_with_recovery(fault: parent_reply_loss(boundary: boundary, mode: mode),
|
|
559
|
+
retry_confirmed_pre: retry_confirmed_pre, approve_after_restore: approve_after_restore)
|
|
560
|
+
end
|
|
561
|
+
if %i[recovery_pending approval_wait].include?(value[:state])
|
|
562
|
+
receipt = value.fetch(:receipt)
|
|
563
|
+
report = {state: value.fetch(:state), outcome: receipt.outcome,
|
|
564
|
+
application_state: receipt.application_state,
|
|
565
|
+
saved_outcome: (receipt.saved_outcome if receipt.respond_to?(:saved_outcome)),
|
|
566
|
+
ownership_state: (receipt.ownership_state if receipt.respond_to?(:ownership_state)),
|
|
567
|
+
continuation_state: (receipt.continuation_state if receipt.respond_to?(:continuation_state)),
|
|
568
|
+
provider_calls: value.fetch(:provider_calls),
|
|
569
|
+
review_effects: G3hReviewTool.effects.dup, publication_effects: G3hPublishTool.effects.dup}
|
|
570
|
+
else
|
|
571
|
+
report = value
|
|
572
|
+
end
|
|
573
|
+
ensure
|
|
574
|
+
Phronomy::Runtime.instance.shutdown(timeout: 0.03, cancel_grace: 0.2)
|
|
575
|
+
begin
|
|
576
|
+
Phronomy.reset_runtime!
|
|
577
|
+
cleanup_incomplete = false
|
|
578
|
+
rescue Phronomy::RuntimeShutdownError
|
|
579
|
+
cleanup_incomplete = true
|
|
580
|
+
end
|
|
581
|
+
end
|
|
582
|
+
report.merge(cleanup_incomplete: cleanup_incomplete)
|
|
583
|
+
end
|
|
584
|
+
|
|
585
|
+
if $PROGRAM_NAME == __FILE__
|
|
586
|
+
puts JSON.pretty_generate(run_report_example(
|
|
587
|
+
scenario: ENV.fetch("G3H_SCENARIO", "normal").to_sym,
|
|
588
|
+
boundary: ENV.fetch("G3H_BOUNDARY", "terminal").to_sym,
|
|
589
|
+
mode: ENV.fetch("G3H_MODE", "post").to_sym,
|
|
590
|
+
retry_confirmed_pre: ENV["G3H_RETRY_CAPTURED_OUTCOME"] == "true",
|
|
591
|
+
approve_after_restore: ENV["G3H_APPROVE_RESTORED_WAIT"] == "true"
|
|
592
|
+
))
|
|
593
|
+
end
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
<!-- /generated-application:fixture-and-driver -->
|
|
597
|
+
|
|
598
|
+
Assemble the documented blocks into one Ruby file, choosing either identical normal function, and run it with the repository's bundled dependencies. These examples explicitly permit captured outcome retry or a new decision after restoring a rolled-back approval; the default policies permit neither.
|
|
599
|
+
|
|
600
|
+
```sh
|
|
601
|
+
bundle exec ruby /absolute/path/native_parent_outcome_application.rb
|
|
602
|
+
|
|
603
|
+
G3H_SCENARIO=recovery G3H_BOUNDARY=approval_wait G3H_MODE=pre \
|
|
604
|
+
G3H_RETRY_CAPTURED_OUTCOME=true \
|
|
605
|
+
bundle exec ruby /absolute/path/native_parent_outcome_application.rb
|
|
606
|
+
|
|
607
|
+
G3H_SCENARIO=recovery G3H_BOUNDARY=approval_decision G3H_MODE=pre \
|
|
608
|
+
G3H_APPROVE_RESTORED_WAIT=true \
|
|
609
|
+
bundle exec ruby /absolute/path/native_parent_outcome_application.rb
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
The one-shot driver summarizes pending receipts and reports `cleanup_incomplete` when retained unresolved work prevents clean shutdown. A running service instead keeps the parent/capability returned by `run_report_with_recovery` and makes its later observation or escalation decision. This demonstration does not turn process exit into durable recovery ownership.
|
|
613
|
+
|
|
614
|
+
For example, leaving captured retry disabled after a terminal pre-state returns `recovery_pending`, with the report's existing effects preserved and custody retained. Leaving reapproval disabled after an approval-decision pre-state returns the restored approval wait without running the publication Tool.
|
|
615
|
+
|
|
616
|
+
## Bound acceptance and remaining work
|
|
617
|
+
|
|
618
|
+
Acceptance distinguishes normal behavioral equivalence, intentionally changed uncertainty handling, finite model properties and remaining operations. Complete application reports and focused Runtime cases must establish the claimed paths; a passing value-object test or model alone does not prove live owner cleanup or external exactly-once effects.
|
|
619
|
+
|
|
620
|
+
For example, checking `saved_outcome: :approval_wait` is insufficient without showing that the exact request can later be approved, the old observation remains closed and the publication Tool runs once. Likewise, final save recovery must preserve actual failed/cancelled business outcomes rather than reporting all recovered facts as success.
|
|
621
|
+
|
|
622
|
+
The complete application matrix passes 14 cases: exact G3g and candidate normal runs, eight pre/post fault runs across final/coordination-wait/approval-wait/approval-decision saves, and four explicit no-retry/no-reapproval policy runs. The seven documented source blocks match the tested complete source; assembled documentation copies reproduce all 14 functional reports under source-identity checks. These application cases are separate evidence from the broader Runtime suite and finite-model checks; their counts are not added together as one coverage total.
|
|
623
|
+
|
|
624
|
+
| Acceptance boundary | Required evidence |
|
|
625
|
+
| --- | --- |
|
|
626
|
+
| Native final, coordination-wait and own approval-wait pre/post uncertainty | Same original parent, typed saved-kind receipt, complete proof and exact captured retry where authorized |
|
|
627
|
+
| Native own approval decision pre/post uncertainty | Same request/decision, fresh child authority, restored wait or once-only continuation |
|
|
628
|
+
| Mixed protected Tool and native dispatch batch | Preserve baseline factual-resolution requirement and existing effects through pre/post decision recovery; complete through the exact public resolution subject/result, without claiming automatic final resume |
|
|
629
|
+
| Changed, missing or unavailable authority | Retained obligation, no guessed rollback, replacement child or unauthorized continuation |
|
|
630
|
+
| Source and recovery observers | Earlier failed/cancelled observations stay closed; fresh receipts; no old callback replay |
|
|
631
|
+
| Physical work and delivery races | No stale/duplicate application, premature recovery release or unproven resubmission |
|
|
632
|
+
| Cancellation and lifetime | Existing authoritative cancellation and saved business meaning preserved; waits retain their applicable execution custody |
|
|
633
|
+
| Complete ordinary application | Same outputs, exact two Tool effects, five Provider calls, durable histories and final pair release |
|
|
634
|
+
| Model, API and architecture | Separate entity/observer state views; safety/conditional progress; public snapshot/RBS; unchanged responsibility direction |
|
|
635
|
+
|
|
636
|
+
The [finite native outcome model](../../spec/models/native_parent_outcome_recovery/README.md) separates saved facts, original-owner application, wait/final lifetime and client observation. Its positive model, deliberate mutations and missing-premise counterexamples have distinct expected results. It is not a refinement proof of Ruby or a guarantee that a remote Store has settled prior transactions.
|
|
637
|
+
|
|
638
|
+
The [parent outcome owner](../../spec/models/native_parent_outcome_recovery/parent-owner.svg), [approval decision owner](../../spec/models/native_parent_outcome_recovery/approval-owner.svg), [child owner](../../spec/models/native_parent_outcome_recovery/child-owner.svg) and [client observer](../../spec/models/native_parent_outcome_recovery/client-observer.svg) have separate state views. Conditional progress reaches the saved final/wait publication or approval restoration/continuation boundary; it does not assert eventual human approval, child completion or whole-job success. Fresh decision admission additionally requires stable authority between its guarded read and admission, whereas historical outcome publication allows legal later child progress.
|
|
639
|
+
|
|
640
|
+
For example, a counterexample after removing original-observer closure or after allowing release to mean job completion at an approval wait demonstrates a required invariant. A positive check still relies on explicit scheduling, authoritative settled readback and original-owner availability premises.
|
|
641
|
+
|
|
642
|
+
G3h advances completion group 1 for supported native outcomes and own approval decisions. Its own scope does not close Handoff outcome/approval/transfer lineage and current routing, arbitrary custom-participant capability/unsupported disposition, initial reserved-admission uncertainty, admitted outcome workers without complete proposals, or remaining cross-path acceptance. The later [synchronous participant custody contract](synchronous-participant-contract.md) addresses bounded public-participant custody and unsupported proof disposition; it does not make arbitrary callbacks replayable or close all Handoff lineage. Mixed own protected Tool/native-dispatch batches retain their existing factual-resolution requirement; automatic completion of every native batch is not claimed. Group 2 remains failed-Runtime administration; group 3 MCP resource management; group 4 fallback child ownership; group 5 capability and existing-guarantee alignment; group 6 selected durable-backend/transport and combined final acceptance. No seventh group or process-loss takeover is introduced.
|
|
643
|
+
|
|
644
|
+
For example, a Handoff Agent can also request approval of an ordinary Tool, but its routing and custody facts cannot be proved by a native child-slot adapter. A stopped original Runtime and an unresolved remote transaction likewise require their existing separate guarantees. Ordered local guards and physical worker completion alone do not provide those guarantees.
|