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,387 @@
|
|
|
1
|
+
# Original-owner approval recovery for child and restored waits
|
|
2
|
+
|
|
3
|
+
The Agent that owns an approval decision retains its saved outcome and continuation even when the wait belongs to a coordinated child or was restored from persistence. A hosted parent additionally owns the authority to answer that child's wait and to detach a later wait. G3d extends the existing approval recovery operation to those relationships; it does not introduce a second job manager.
|
|
4
|
+
|
|
5
|
+
For example, a report service starts a reviewer child, releases both local owners at the first approval, and restores them on another host. The host approves the first report, but the successful decision transaction's reply is lost. Recovery must apply that exact decision once, allow the second report to request approval, and give the host a valid handle for releasing that next wait.
|
|
6
|
+
|
|
7
|
+
Baseline: applied G3c `c9b2f3d8f989aab87f7e04feafeb9e35f0c0763a`. This document describes the G3d implementation candidate. Contract concept v55 and foundation v48 remain the architectural references. Final commit identity, validation and limits are recorded in the delivery evidence.
|
|
8
|
+
|
|
9
|
+
## Keep the child decision and hosted authority together
|
|
10
|
+
|
|
11
|
+
A child owns its approval state, cancellation and execution. Its parent's saved coordination wait authorizes a hosted decision for one exact child. The recovery owner retains both facts while distinguishing saved-state proof, local application, continuation admission and each caller's observation.
|
|
12
|
+
|
|
13
|
+
For example, a readable child post-state does not by itself permit dispatch if the parent revision, child slot content, retention or cancellation facts no longer match the captured authority. Likewise, a previous `confirmed_post` receipt remains historical knowledge of the decision while a later handoff can remain pending after authority changes.
|
|
14
|
+
|
|
15
|
+
| Path | Retained owner and proof | Continuation observation |
|
|
16
|
+
| --- | --- | --- |
|
|
17
|
+
| Existing live standalone wait | Original Agent, invocation and cancellation binding; complete approval pre/post evidence | Existing independent `execution_task` |
|
|
18
|
+
| Direct correlated child decision | Exact child incarnation and reservation, complete child evidence and retained references | Existing independent `execution_task`; no hosted detach capability is invented |
|
|
19
|
+
| Restored standalone wait | Exact loaded Agent and reconstructed invocation; no earlier live cancellation binding is assumed | Existing independent `execution_task` |
|
|
20
|
+
| Restored parent using `approve_hosted_child` | Exact child plus the original recovered parent wait; guarded immutable parent/child authority capture | Independent `execution_task` and, while authority remains available, `hosted_invocation` |
|
|
21
|
+
|
|
22
|
+
The hosted evidence is captured before asynchronous submission using the existing relation reader in an outer guarded transaction. Later persistence checks compare the complete captured parent footprint and validate the child decision separately. Owner application checks the same local parent wait and child incarnation on EventLoop. No arbitrary participant callback is replayed to infer a save outcome.
|
|
23
|
+
|
|
24
|
+
The storage check is a snapshot under the selected Store's guard, not a distributed fence held until external dispatch. The guarantee depends on the existing cooperative-writer and cancellation protocol. Concurrent external mutation after a validated snapshot is not a new cross-process exactly-once guarantee.
|
|
25
|
+
|
|
26
|
+
## Recover through the same child API
|
|
27
|
+
|
|
28
|
+
A recovery capability identifies the original child that owns the uncertain decision. Existing process-local lookup and approval reconciliation are sufficient to reach that owner; a parent does not gain permission to reconstruct another child's capability from identifiers.
|
|
29
|
+
|
|
30
|
+
For example, after `decision.wait_result` raises `ApprovalRecoveryError`, the host can use `Agent::Base.live_for_execution(error.execution_id)` and call that child's `reconcile_approval(recovery: error.recovery)`. Wrong-incarnation and copied-capability checks remain unchanged. Reconciliation observes and applies the original decision; it never makes that decision again.
|
|
31
|
+
|
|
32
|
+
| Public operation or value | G3d behavior |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `pending_approval_recovery(execution_id:)` | Same local lookup; supported child/restored obligations now remain discoverable |
|
|
35
|
+
| `reconcile_approval[_async](recovery:)` | Same sync/async contract and process-local capability; no new parent reconciliation facade |
|
|
36
|
+
| `ApprovalRecoveryResult#execution_task` | Fresh independent observation after a resolved post-state; a successful hosted detach completes it with `ApprovalWait` |
|
|
37
|
+
| `ApprovalRecoveryResult#hosted_invocation` | New optional `HostedInvocation` for the recovered hosted continuation; it has its own independent observation and the exact private detach authority |
|
|
38
|
+
| `HostedInvocation#wait_result / #on_complete / #detach!` | Existing public methods; a fresh recovered handle preserves the next-wait detach behavior |
|
|
39
|
+
|
|
40
|
+
A hosted handle is available only for a resumed hosted continuation while the original authority can still be represented. It is nil for direct child and standalone recovery, before continuation admission, after canonical physical completion retires the authority, or when the original host is no longer available. A historical resolved receipt can still provide `execution_task` after `hosted_invocation` becomes nil. An earlier receipt's handle keeps its result observation, but later detach attempts fail once its authority ends.
|
|
41
|
+
|
|
42
|
+
## Separate observations from detach rights
|
|
43
|
+
|
|
44
|
+
The original failed decision observation remains closed. Each recovery receipt supplies fresh observations, while the private canonical continuation owns the physical lifetime and exact detach right. Closing an observation does not cancel that continuation or authorize another dispatch.
|
|
45
|
+
|
|
46
|
+
For example, cancelling `receipt.execution_task` does not prevent `receipt.hosted_invocation` from observing the next wait and detaching it. Both observations are distinct from the canonical detach task. Two fresh handles can refer to the same continuation, but only a matching, still-owned wait can be detached; the first successful release makes subsequent attempts stale.
|
|
47
|
+
|
|
48
|
+
Normal successful hosted calls retain their existing handle behavior. Internally, a still-open original decision handle follows its exact continuation when its operation lease is handed over. The detach command resolves that bridge on EventLoop. A failed or cancelled original observation cannot use the bridge to adopt a recovered continuation.
|
|
49
|
+
|
|
50
|
+
Physical completion of the canonical continuation retires the captured reader, saved parent evidence and live-owner references. Existing recovered handles drop detach authority while retaining their result observation. This does not apply to an original `start_hosted` parent handle: that handle must retain its authority after the parent's committed coordination wait so that the host can detach the child.
|
|
51
|
+
|
|
52
|
+
## Preserve the normal application
|
|
53
|
+
|
|
54
|
+
The normal report workflow retains the same inputs, two human decisions, two wait transfers, outputs and release policy before and after G3d. The framework removes the unsupported recovery gap; the application still chooses each approval and controls its external claim and retry policy.
|
|
55
|
+
|
|
56
|
+
For example, both versions below run five deterministic Provider calls, execute each report Tool once, finish both saved executions and release the completed pair. The extra response-loss fixture is disabled for this equivalence comparison. Runtime, Store and native parent/child coordination are real; the Provider is offline.
|
|
57
|
+
|
|
58
|
+
### Shared setup
|
|
59
|
+
|
|
60
|
+
The shared setup defines both Agent roles, one approval Tool, the deterministic Provider, the event queue and the selected in-memory stores. The optional transaction wrapper injects only a lost reply after a real successful save.
|
|
61
|
+
|
|
62
|
+
For example, the Provider asks the parent to dispatch the reviewer, then asks the reviewer for the first and second report in sequence. Tool effects are recorded so the comparison detects repeated business work.
|
|
63
|
+
|
|
64
|
+
<!-- example: shared-setup -->
|
|
65
|
+
```ruby
|
|
66
|
+
# frozen_string_literal: true
|
|
67
|
+
|
|
68
|
+
require "phronomy"
|
|
69
|
+
require "json"
|
|
70
|
+
require "timeout"
|
|
71
|
+
|
|
72
|
+
class G3dReviewTool < Phronomy::Tool::Base
|
|
73
|
+
tool_name "review_report"
|
|
74
|
+
description "Read one report after its human approval"
|
|
75
|
+
requires_approval true
|
|
76
|
+
|
|
77
|
+
class << self
|
|
78
|
+
attr_accessor :effects
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def execute(query:)
|
|
82
|
+
self.class.effects << query
|
|
83
|
+
"reviewed #{query}"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class G3dReviewAgent < Phronomy::Agent::Base
|
|
88
|
+
agent_definition id: "hosted-report-reviewer", version: 1
|
|
89
|
+
model "offline-model"
|
|
90
|
+
tools G3dReviewTool => nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class G3dReportOrchestrator < Phronomy::MultiAgent::Orchestrator
|
|
94
|
+
agent_definition id: "hosted-report-parent", version: 1
|
|
95
|
+
model "offline-model"
|
|
96
|
+
subagent :reviewer, G3dReviewAgent
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
class G3dReportAdapter < Phronomy::LLMAdapter::Base
|
|
100
|
+
attr_reader :calls
|
|
101
|
+
|
|
102
|
+
def initialize
|
|
103
|
+
@calls = 0
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def perform_complete(_request, cancellation_token:)
|
|
107
|
+
cancellation_token&.raise_if_cancelled!
|
|
108
|
+
@calls += 1
|
|
109
|
+
name, arguments = case @calls
|
|
110
|
+
when 1 then ["dispatch_to_reviewer", {input: "Review both reports"}]
|
|
111
|
+
when 2 then ["review_report", {query: "first report"}]
|
|
112
|
+
when 3 then ["review_report", {query: "second report"}]
|
|
113
|
+
when 4
|
|
114
|
+
return Phronomy::LLMAdapter::Response.new(content: "reviews ready", finish_reason: :stop)
|
|
115
|
+
when 5
|
|
116
|
+
return Phronomy::LLMAdapter::Response.new(content: "report ready", finish_reason: :stop)
|
|
117
|
+
else
|
|
118
|
+
raise "Unexpected repeated Provider work"
|
|
119
|
+
end
|
|
120
|
+
Phronomy::LLMAdapter::Response.new(tool_calls: [
|
|
121
|
+
Phronomy::Tool::CallRequest.new(id: "call-#{@calls}", name: name, arguments: arguments)
|
|
122
|
+
], finish_reason: :tool_calls)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# This optional fault injector loses a successful transaction's reply. The
|
|
127
|
+
# transaction and Runtime are real; no Provider or Tool calls are mocked.
|
|
128
|
+
module G3dLostApprovalResponse
|
|
129
|
+
attr_accessor :lose_next_approval_response
|
|
130
|
+
|
|
131
|
+
def transaction(&block)
|
|
132
|
+
armed = @lose_next_approval_response
|
|
133
|
+
@lose_next_approval_response = false if armed
|
|
134
|
+
result = super(&block)
|
|
135
|
+
raise IOError, "Approval response lost after commit" if armed
|
|
136
|
+
result
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def build_report_host
|
|
141
|
+
G3dReviewTool.effects = []
|
|
142
|
+
adapter = G3dReportAdapter.new
|
|
143
|
+
Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
|
|
144
|
+
stores = Phronomy::PersistenceComposition.in_memory
|
|
145
|
+
stores.agent.extend(G3dLostApprovalResponse)
|
|
146
|
+
approvals = Queue.new
|
|
147
|
+
options = {
|
|
148
|
+
persistence: stores.agent, coordination_store: stores.multi_agent,
|
|
149
|
+
on_event: ->(event) { approvals << event.payload.fetch(:request) if event.type == :approval_required }
|
|
150
|
+
}
|
|
151
|
+
parent = G3dReportOrchestrator.create(agent_id: "hosted-report-parent", **options)
|
|
152
|
+
[adapter, stores, approvals, options, parent]
|
|
153
|
+
end
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Complete normal functions before and after
|
|
157
|
+
|
|
158
|
+
Both functions below contain the complete host sequence from the first reservation through the final release. Each catches a coordination-wait signal and still requires the matching guarded detach operation; an exception by itself is not treated as proof of a transferable wait.
|
|
159
|
+
|
|
160
|
+
For example, the second host answers the first report, then releases the next wait so a third host can make the second decision. Either column can be combined with the shared setup and driver using the default normal scenario.
|
|
161
|
+
|
|
162
|
+
<table><thead><tr><th>Before: applied G3c</th><th>After: G3d candidate</th></tr></thead><tbody><tr><td><!-- example: normal-before --><pre><code># The host explicitly hands over each committed wait and decides each approval.
|
|
163
|
+
def run_hosted_report
|
|
164
|
+
adapter, stores, approvals, options, parent = build_report_host
|
|
165
|
+
parent_id = "hosted-report-execution"
|
|
166
|
+
reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
|
|
167
|
+
start = parent.start_hosted(reservation: reservation, input: "Prepare the report")
|
|
168
|
+
first = Timeout.timeout(5) { approvals.pop }
|
|
169
|
+
begin
|
|
170
|
+
start.wait_result(timeout: 5)
|
|
171
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
172
|
+
# The native parent committed its coordination wait; detach validates it.
|
|
173
|
+
end
|
|
174
|
+
start.detach!(execution_id: first.execution_id, approval_request_id: first.id)
|
|
175
|
+
|
|
176
|
+
middle = G3dReportOrchestrator.load(parent.agent_id, **options)
|
|
177
|
+
restore = middle.resume_async(parent_id)
|
|
178
|
+
restored = Timeout.timeout(5) { approvals.pop }
|
|
179
|
+
raise "Approval identity changed" unless restored.id == first.id
|
|
180
|
+
begin
|
|
181
|
+
restore.wait_result(timeout: 5)
|
|
182
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
183
|
+
# The restored parent owns the same child's saved wait.
|
|
184
|
+
end
|
|
185
|
+
decision = middle.approve_hosted_child(parent_id, execution_id: first.execution_id,
|
|
186
|
+
approval_request_id: first.id, approved: true)
|
|
187
|
+
second = Timeout.timeout(5) { approvals.pop }
|
|
188
|
+
wait = decision.detach!(execution_id: second.execution_id, approval_request_id: second.id)
|
|
189
|
+
raise "Detach observation changed" unless decision.wait_result(timeout: 5) == wait
|
|
190
|
+
|
|
191
|
+
last = G3dReportOrchestrator.load(parent.agent_id, **options)
|
|
192
|
+
restore = last.resume_async(parent_id)
|
|
193
|
+
restored = Timeout.timeout(5) { approvals.pop }
|
|
194
|
+
raise "Second approval identity changed" unless restored.id == second.id
|
|
195
|
+
begin
|
|
196
|
+
restore.wait_result(timeout: 5)
|
|
197
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
198
|
+
# The next host makes the second decision explicitly.
|
|
199
|
+
end
|
|
200
|
+
child_result = last.approve_hosted_child(parent_id, execution_id: second.execution_id,
|
|
201
|
+
approval_request_id: second.id, approved: true).wait_result(timeout: 5)
|
|
202
|
+
parent_result = last.resume(parent_id)
|
|
203
|
+
released = last.unload_with_completed_child!(parent_id, execution_id: second.execution_id)
|
|
204
|
+
{
|
|
205
|
+
child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
|
|
206
|
+
tool_effects: G3dReviewTool.effects, provider_calls: adapter.calls, released: released,
|
|
207
|
+
statuses: [parent_id, second.execution_id].map { |id| stores.agent.executions.load(id).status },
|
|
208
|
+
revisions: [parent_id, second.execution_id].map { |id| stores.agent.executions.load(id).execution_revision }
|
|
209
|
+
}
|
|
210
|
+
end</code></pre></td><td><!-- example: normal-after --><pre><code># The host explicitly hands over each committed wait and decides each approval.
|
|
211
|
+
def run_hosted_report
|
|
212
|
+
adapter, stores, approvals, options, parent = build_report_host
|
|
213
|
+
parent_id = "hosted-report-execution"
|
|
214
|
+
reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
|
|
215
|
+
start = parent.start_hosted(reservation: reservation, input: "Prepare the report")
|
|
216
|
+
first = Timeout.timeout(5) { approvals.pop }
|
|
217
|
+
begin
|
|
218
|
+
start.wait_result(timeout: 5)
|
|
219
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
220
|
+
# The native parent committed its coordination wait; detach validates it.
|
|
221
|
+
end
|
|
222
|
+
start.detach!(execution_id: first.execution_id, approval_request_id: first.id)
|
|
223
|
+
|
|
224
|
+
middle = G3dReportOrchestrator.load(parent.agent_id, **options)
|
|
225
|
+
restore = middle.resume_async(parent_id)
|
|
226
|
+
restored = Timeout.timeout(5) { approvals.pop }
|
|
227
|
+
raise "Approval identity changed" unless restored.id == first.id
|
|
228
|
+
begin
|
|
229
|
+
restore.wait_result(timeout: 5)
|
|
230
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
231
|
+
# The restored parent owns the same child's saved wait.
|
|
232
|
+
end
|
|
233
|
+
decision = middle.approve_hosted_child(parent_id, execution_id: first.execution_id,
|
|
234
|
+
approval_request_id: first.id, approved: true)
|
|
235
|
+
second = Timeout.timeout(5) { approvals.pop }
|
|
236
|
+
wait = decision.detach!(execution_id: second.execution_id, approval_request_id: second.id)
|
|
237
|
+
raise "Detach observation changed" unless decision.wait_result(timeout: 5) == wait
|
|
238
|
+
|
|
239
|
+
last = G3dReportOrchestrator.load(parent.agent_id, **options)
|
|
240
|
+
restore = last.resume_async(parent_id)
|
|
241
|
+
restored = Timeout.timeout(5) { approvals.pop }
|
|
242
|
+
raise "Second approval identity changed" unless restored.id == second.id
|
|
243
|
+
begin
|
|
244
|
+
restore.wait_result(timeout: 5)
|
|
245
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
246
|
+
# The next host makes the second decision explicitly.
|
|
247
|
+
end
|
|
248
|
+
child_result = last.approve_hosted_child(parent_id, execution_id: second.execution_id,
|
|
249
|
+
approval_request_id: second.id, approved: true).wait_result(timeout: 5)
|
|
250
|
+
parent_result = last.resume(parent_id)
|
|
251
|
+
released = last.unload_with_completed_child!(parent_id, execution_id: second.execution_id)
|
|
252
|
+
{
|
|
253
|
+
child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
|
|
254
|
+
tool_effects: G3dReviewTool.effects, provider_calls: adapter.calls, released: released,
|
|
255
|
+
statuses: [parent_id, second.execution_id].map { |id| stores.agent.executions.load(id).status },
|
|
256
|
+
revisions: [parent_id, second.execution_id].map { |id| stores.agent.executions.load(id).execution_revision }
|
|
257
|
+
}
|
|
258
|
+
end</code></pre></td></tr></tbody></table>
|
|
259
|
+
|
|
260
|
+
### Complete recovery function
|
|
261
|
+
|
|
262
|
+
The recovery function intentionally changes only the lost-response path. It keeps the first approval decision and resolves that same saved transition, then uses the recovered hosted handle for the second wait. An unresolved receipt leaves the claim with the application instead of causing automatic replay.
|
|
263
|
+
|
|
264
|
+
For example, the injected transaction commits the first approval and raises before returning. The function requires confirmed post-state, resolved continuation and an available hosted handle together. It verifies that the failed original observation remains failed and that both fresh observations receive the successful detach receipt.
|
|
265
|
+
|
|
266
|
+
<!-- example: recovery-example -->
|
|
267
|
+
```ruby
|
|
268
|
+
# Recovery resolves the first decision without making that decision again.
|
|
269
|
+
def run_hosted_report_with_recovery
|
|
270
|
+
adapter, stores, approvals, options, parent = build_report_host
|
|
271
|
+
parent_id = "hosted-report-execution"
|
|
272
|
+
reservation = Phronomy::Agent::ReservedExecution.new(agent_id: parent.agent_id, execution_id: parent_id)
|
|
273
|
+
start = parent.start_hosted(reservation: reservation, input: "Prepare the report")
|
|
274
|
+
first = Timeout.timeout(5) { approvals.pop }
|
|
275
|
+
begin
|
|
276
|
+
start.wait_result(timeout: 5)
|
|
277
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
278
|
+
# A matching committed wait, not the error alone, permits this detach.
|
|
279
|
+
end
|
|
280
|
+
start.detach!(execution_id: first.execution_id, approval_request_id: first.id)
|
|
281
|
+
|
|
282
|
+
middle = G3dReportOrchestrator.load(parent.agent_id, **options)
|
|
283
|
+
restore = middle.resume_async(parent_id)
|
|
284
|
+
restored = Timeout.timeout(5) { approvals.pop }
|
|
285
|
+
raise "Approval identity changed" unless restored.id == first.id
|
|
286
|
+
begin
|
|
287
|
+
restore.wait_result(timeout: 5)
|
|
288
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
289
|
+
# The original parent and child now own this restored coordination wait.
|
|
290
|
+
end
|
|
291
|
+
stores.agent.lose_next_approval_response = true
|
|
292
|
+
decision = middle.approve_hosted_child(parent_id, execution_id: first.execution_id,
|
|
293
|
+
approval_request_id: first.id, approved: true)
|
|
294
|
+
failure = begin
|
|
295
|
+
decision.wait_result(timeout: 5)
|
|
296
|
+
raise "The injected response loss was not observed"
|
|
297
|
+
rescue Phronomy::Agent::ApprovalRecoveryError => error
|
|
298
|
+
error
|
|
299
|
+
end
|
|
300
|
+
child = Phronomy::Agent::Base.live_for_execution(failure.execution_id)
|
|
301
|
+
receipt = child.reconcile_approval(recovery: failure.recovery)
|
|
302
|
+
unless receipt.outcome == :confirmed_post && receipt.resolved? && receipt.hosted_invocation
|
|
303
|
+
raise "Retain the claim: approval or hosted continuation is still unresolved"
|
|
304
|
+
end
|
|
305
|
+
recovered = receipt.hosted_invocation
|
|
306
|
+
second = Timeout.timeout(5) { approvals.pop }
|
|
307
|
+
wait = recovered.detach!(execution_id: second.execution_id, approval_request_id: second.id)
|
|
308
|
+
raise "Recovered detach observation changed" unless recovered.wait_result(timeout: 5) == wait
|
|
309
|
+
raise "Execution observation changed" unless receipt.execution_task.wait_result(timeout: 5) == wait
|
|
310
|
+
begin
|
|
311
|
+
decision.wait_result(timeout: 5)
|
|
312
|
+
raise "The original failed observation reopened"
|
|
313
|
+
rescue Phronomy::Agent::ApprovalRecoveryError => original
|
|
314
|
+
raise "The original failure changed" unless original.equal?(failure)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
last = G3dReportOrchestrator.load(parent.agent_id, **options)
|
|
318
|
+
restore = last.resume_async(parent_id)
|
|
319
|
+
restored = Timeout.timeout(5) { approvals.pop }
|
|
320
|
+
raise "Second approval identity changed" unless restored.id == second.id
|
|
321
|
+
begin
|
|
322
|
+
restore.wait_result(timeout: 5)
|
|
323
|
+
rescue Phronomy::ExecutionRehydrationRequiredError
|
|
324
|
+
# Only this next host issues the second, distinct approval decision.
|
|
325
|
+
end
|
|
326
|
+
child_result = last.approve_hosted_child(parent_id, execution_id: second.execution_id,
|
|
327
|
+
approval_request_id: second.id, approved: true).wait_result(timeout: 5)
|
|
328
|
+
parent_result = last.resume(parent_id)
|
|
329
|
+
released = last.unload_with_completed_child!(parent_id, execution_id: second.execution_id)
|
|
330
|
+
{
|
|
331
|
+
child_output: child_result.fetch(:output), parent_output: parent_result.fetch(:output),
|
|
332
|
+
tool_effects: G3dReviewTool.effects, provider_calls: adapter.calls, released: released,
|
|
333
|
+
statuses: [parent_id, second.execution_id].map { |id| stores.agent.executions.load(id).status },
|
|
334
|
+
revisions: [parent_id, second.execution_id].map { |id| stores.agent.executions.load(id).execution_revision },
|
|
335
|
+
recovery_outcome: receipt.outcome, continuation_state: receipt.continuation_state
|
|
336
|
+
}
|
|
337
|
+
end
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Shared executable driver
|
|
341
|
+
|
|
342
|
+
The driver chooses one complete function and shuts down the Runtime after the observation finishes. It is verification scaffolding; production claim ownership and worker supervision remain application responsibilities.
|
|
343
|
+
|
|
344
|
+
For example, concatenate the shared setup, one normal function and this driver for the normal comparison. For the fault case, concatenate the setup, recovery function and driver, then set `G3D_SCENARIO=recovery`. The selected branch alone is executed.
|
|
345
|
+
|
|
346
|
+
<!-- example: shared-driver -->
|
|
347
|
+
```ruby
|
|
348
|
+
if $PROGRAM_NAME == __FILE__
|
|
349
|
+
begin
|
|
350
|
+
result = ENV.fetch("G3D_SCENARIO", "normal") == "recovery" ?
|
|
351
|
+
run_hosted_report_with_recovery : run_hosted_report
|
|
352
|
+
puts JSON.pretty_generate(result)
|
|
353
|
+
ensure
|
|
354
|
+
Phronomy.reset_runtime!
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Preserve symmetry and state the intentional differences
|
|
360
|
+
|
|
361
|
+
The added behavior extends the existing approval recovery capability rather than creating another set of reconciliation methods. The hosted result adds a separate capability because a result observation and the authority to detach a parent/child pair have different lifetimes.
|
|
362
|
+
|
|
363
|
+
For example, making `execution_task` a hosted handle would break callers that use TaskResult cancellation and callbacks. Instead it remains a TaskResult, while the optional hosted handle carries the exact existing detach contract.
|
|
364
|
+
|
|
365
|
+
| Comparison | Decision | Reason |
|
|
366
|
+
| --- | --- | --- |
|
|
367
|
+
| Ordinary, child and restored approval lookup/reconciliation | Adopt existing names, arguments, outcomes and sync/async methods | They resolve the same captured approval decision |
|
|
368
|
+
| Approval reconciliation versus terminal/dispatch retry | Keep approval readback without a new retry method | Confirmed pre-state restores the original wait; the application may issue a fresh explicit decision |
|
|
369
|
+
| `execution_task` versus `hosted_invocation` | Add the optional hosted reader | Observation cancellation must not spend or recreate detach authority |
|
|
370
|
+
| Parent-level reconciliation facade | Withdraw | Existing `live_for_execution` reaches the exact child; another facade would add no authority |
|
|
371
|
+
| Reusing the failed original hosted handle | Reject | A closed observation must not silently adopt a later canonical continuation |
|
|
372
|
+
| Arbitrary participant replay or new generic manager | Defer outside this change | Captured child/hosted approval proof does not establish participant-specific commit semantics |
|
|
373
|
+
|
|
374
|
+
| Trigger | Applied G3c | G3d candidate |
|
|
375
|
+
| --- | --- | --- |
|
|
376
|
+
| Lost reply to a supported direct correlated child approval | Live owner remains busy without retained approval lookup | Explicit recovery retains and applies the same decision |
|
|
377
|
+
| Lost reply after a restored standalone approval | Original loaded wait lacks the required live binding | Existing approval recovery supports the exact restored invocation |
|
|
378
|
+
| Lost hosted child decision reply followed by another approval | No recovered hosted continuation with detach authority | Receipt can supply a fresh handle for the exact next wait |
|
|
379
|
+
| Parent authority changes during unresolved hosted recovery | No general recovery guarantee | Readback/application remain pending; historical saved-decision knowledge does not grant new authority |
|
|
380
|
+
|
|
381
|
+
## Bound validation and remaining work
|
|
382
|
+
|
|
383
|
+
The executable examples establish normal behavior equivalence and one concrete saved-response-loss continuation. Fault tests and the finite model separately cover retained ownership, changed evidence, cancellation, rejected delivery and physical lifetime. Their counts and exact source identities are recorded in the delivery evidence.
|
|
384
|
+
|
|
385
|
+
For example, a recovered hosted run must execute each report Tool once, preserve the original failed observation, detach the second wait and complete the parent after the next explicit decision. An invalid parent revision or mismatched relation must keep the obligation retained instead of attempting that business work.
|
|
386
|
+
|
|
387
|
+
This closes the implemented child/restored approval paths only. Participant-aware dispatch and terminal recovery remain within residual group 1; failed-Runtime administration and selected durable-backend acceptance remain their existing groups. It does not claim all G3 work, process-loss recovery, arbitrary extension support, or real external Provider acceptance is complete. Contract directions remain Agent to Execution/Persistence; new Agent proof and handle objects do not call concrete MultiAgent coordination implementations.
|