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
|
@@ -136,7 +136,14 @@ module Phronomy
|
|
|
136
136
|
private_class_method :observed_usage
|
|
137
137
|
|
|
138
138
|
def submit_finish(handle, attributes)
|
|
139
|
-
|
|
139
|
+
# Diagnostic completion must not occupy a business-work admission slot.
|
|
140
|
+
# The existing Runtime pool registry owns this bounded pool and shutdown.
|
|
141
|
+
Phronomy::Execution.submit(
|
|
142
|
+
pool_name: :automatic_tracing,
|
|
143
|
+
size: 1,
|
|
144
|
+
queue_size: 100,
|
|
145
|
+
on_full: :raise
|
|
146
|
+
) do
|
|
140
147
|
finish_now(handle, attributes)
|
|
141
148
|
end.on_complete do |_value, error|
|
|
142
149
|
if error
|
data/lib/phronomy/version.rb
CHANGED
|
@@ -54,6 +54,40 @@ module Phronomy
|
|
|
54
54
|
expected_revision: expected_revision, event: event, input: input)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
+
# Observes a retained terminal operation through its original Workflow owner.
|
|
58
|
+
# Reads persistence only while its disposition remains unknown; never saves
|
|
59
|
+
# again or resumes graph actions. The capability is local to this process.
|
|
60
|
+
# Live reconciliation reports unavailable on a stopped retained owner. A
|
|
61
|
+
# terminal receipt transferred to StoppedTerminalCustody reports transferred.
|
|
62
|
+
# @param recovery [WorkflowTerminalRecovery] capability from a recovery error
|
|
63
|
+
# @return [TaskResult<WorkflowTerminalRecoveryResult>] a fresh observation
|
|
64
|
+
# @api public
|
|
65
|
+
def reconcile_terminal_async(recovery:)
|
|
66
|
+
@runner.reconcile_terminal_async(recovery: recovery)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Waits for an explicit terminal-reconciliation observation on a host thread.
|
|
70
|
+
# The original failed observation is never reopened by this operation.
|
|
71
|
+
# @param recovery [WorkflowTerminalRecovery] capability from a recovery error
|
|
72
|
+
# @return [WorkflowTerminalRecoveryResult]
|
|
73
|
+
# @raise [EventLoopReentrancyError] when called on EventLoop
|
|
74
|
+
# @api public
|
|
75
|
+
def reconcile_terminal(recovery:)
|
|
76
|
+
@runner.reconcile_terminal(recovery: recovery)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Finds a retained uncertain terminal operation belonging to this Workflow.
|
|
80
|
+
# This local lookup performs no persistence I/O and does not start a Runtime.
|
|
81
|
+
# Use it when the initial observation was cancelled or its error was dropped.
|
|
82
|
+
# Resolved operations leave the index; a previously held capability remains
|
|
83
|
+
# usable for repeat observation of its retained receipt.
|
|
84
|
+
# @param workflow_instance_id [String] nonempty Workflow identity
|
|
85
|
+
# @return [WorkflowTerminalRecovery, nil]
|
|
86
|
+
# @api public
|
|
87
|
+
def pending_terminal_recovery(workflow_instance_id:)
|
|
88
|
+
@runner.pending_terminal_recovery(workflow_instance_id: workflow_instance_id)
|
|
89
|
+
end
|
|
90
|
+
|
|
57
91
|
# Sends an event to an active Workflow execution without blocking.
|
|
58
92
|
#
|
|
59
93
|
# +workflow_instance_id+ is the logical/durable Workflow identity. EventLoop resolves it
|
|
@@ -23,6 +23,7 @@ module Phronomy
|
|
|
23
23
|
def compile_transitions(**definition) = raise(NotImplementedError)
|
|
24
24
|
def build_session(**options) = raise(NotImplementedError)
|
|
25
25
|
def register_session(session, completion:) = raise(NotImplementedError)
|
|
26
|
+
def retire_session(fsm_session_id:, error:) = raise(NotImplementedError)
|
|
26
27
|
def subscribe_cancellation(token, &callback) = raise(NotImplementedError)
|
|
27
28
|
end
|
|
28
29
|
end
|
|
@@ -19,6 +19,7 @@ module Phronomy
|
|
|
19
19
|
super
|
|
20
20
|
@workflow_admissions = {}
|
|
21
21
|
@task_executions = {}
|
|
22
|
+
@terminal_operations = {}
|
|
22
23
|
@draining = false
|
|
23
24
|
end
|
|
24
25
|
|
|
@@ -29,6 +30,8 @@ module Phronomy
|
|
|
29
30
|
def deliver(command)
|
|
30
31
|
assert_event_loop_thread!
|
|
31
32
|
case command
|
|
33
|
+
when WorkflowTerminalOperation::Observe, WorkflowTerminalOperation::Ready
|
|
34
|
+
command.operation.deliver(command)
|
|
32
35
|
when WorkflowTaskReception::Notification
|
|
33
36
|
task_execution_for(command.reception)&.receive(command)
|
|
34
37
|
when WorkflowTaskReception::DeliveryFailure
|
|
@@ -51,15 +54,108 @@ module Phronomy
|
|
|
51
54
|
mark_workflow_recovery_required_for_session(fsm_session_id) if reason == :recovery_required
|
|
52
55
|
end
|
|
53
56
|
|
|
57
|
+
def adopt_retirement(retirement)
|
|
58
|
+
assert_event_loop_thread!
|
|
59
|
+
operation = synchronize do
|
|
60
|
+
@terminal_operations.values.find { |item| item.fsm_session_id == retirement.fsm_session_id.to_s }
|
|
61
|
+
end
|
|
62
|
+
return nil unless operation && owns_terminal_operation?(operation)
|
|
63
|
+
return nil unless operation.adopt_retirement(retirement)
|
|
64
|
+
mark_workflow_recovery_required_for_session(retirement.fsm_session_id)
|
|
65
|
+
retirement.acceptance
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def acknowledge_retained_retirement(retirement)
|
|
69
|
+
assert_event_loop_thread!
|
|
70
|
+
operation = synchronize do
|
|
71
|
+
candidate = @terminal_operations.values.find { |item| item.fsm_session_id == retirement.fsm_session_id }
|
|
72
|
+
admission = @workflow_admissions[candidate.workflow_instance_id] if candidate
|
|
73
|
+
candidate if admission&.state == :recovery_required && admission.owner_token.equal?(candidate.owner_token)
|
|
74
|
+
end
|
|
75
|
+
operation&.acknowledge_retained_retirement(retirement)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def retain_terminal_operation(operation)
|
|
79
|
+
assert_event_loop_thread!
|
|
80
|
+
synchronize do
|
|
81
|
+
admission = @workflow_admissions[operation.workflow_instance_id]
|
|
82
|
+
unless admission&.owner_token&.equal?(operation.owner_token) &&
|
|
83
|
+
!@terminal_operations.key?(operation.owner_token)
|
|
84
|
+
raise Phronomy::Error, "Workflow terminal operation has no unique owner"
|
|
85
|
+
end
|
|
86
|
+
@terminal_operations[operation.owner_token] = operation
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def terminal_operation(owner_token)
|
|
91
|
+
synchronize { @terminal_operations[owner_token] }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def owns_terminal_operation?(operation)
|
|
95
|
+
synchronize do
|
|
96
|
+
@terminal_operations[operation.owner_token].equal?(operation) &&
|
|
97
|
+
@workflow_admissions[operation.workflow_instance_id]&.owner_token&.equal?(operation.owner_token)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def pending_terminal_recovery(workflow_instance_id, runner_identity:)
|
|
102
|
+
operation = synchronize do
|
|
103
|
+
owner = @workflow_admissions[workflow_instance_id]&.owner_token
|
|
104
|
+
@terminal_operations[owner]
|
|
105
|
+
end
|
|
106
|
+
operation.recovery if operation&.belongs_to?(runner_identity) && operation.pending?
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def stopped_cleanup_ready_locked?
|
|
110
|
+
!@discarded_stopped_custody && @workflow_admissions.empty? && @task_executions.empty? && @terminal_operations.empty?
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def shutdown_cleanup_ready?
|
|
114
|
+
synchronize { @draining && stopped_cleanup_ready_locked? }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def stopped_terminal_owner_locked(session_id)
|
|
118
|
+
admission = @workflow_admissions.values.find { |item| item.fsm_session_id == session_id }
|
|
119
|
+
if admission&.state == :persisting_terminal
|
|
120
|
+
operation = @terminal_operations[admission.owner_token]
|
|
121
|
+
operation if operation && operation.fsm_session_id == session_id &&
|
|
122
|
+
operation.workflow_instance_id == admission.workflow_instance_id
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def transfer_stopped_terminal(operation)
|
|
127
|
+
transfer_stopped_session(operation.fsm_session_id, operation) do |stopped_session|
|
|
128
|
+
admission = @workflow_admissions[operation.workflow_instance_id]
|
|
129
|
+
retained = stopped_session ? admission&.state == :persisting_terminal && admission.fsm_session_id == operation.fsm_session_id :
|
|
130
|
+
admission&.state == :recovery_required && operation.retirement_confirmed?
|
|
131
|
+
unless retained && admission.owner_token.equal?(operation.owner_token) &&
|
|
132
|
+
@terminal_operations[operation.owner_token].equal?(operation) && !@task_executions.key?(operation.owner_token)
|
|
133
|
+
raise Phronomy::Error, "original Workflow terminal authority is missing or busy"
|
|
134
|
+
end
|
|
135
|
+
yield
|
|
136
|
+
@terminal_operations.delete(operation.owner_token)
|
|
137
|
+
@workflow_admissions.delete(operation.workflow_instance_id)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
54
141
|
def shutdown(error:)
|
|
55
|
-
executions = synchronize do
|
|
56
|
-
@workflow_admissions.
|
|
142
|
+
executions, operations = synchronize do
|
|
143
|
+
@discarded_stopped_custody ||= (@workflow_admissions.values.map(&:owner_token) | @task_executions.keys)
|
|
144
|
+
.any? { |token| !@terminal_operations.key?(token) }
|
|
145
|
+
@workflow_admissions.delete_if { |_key, admission| !@terminal_operations.key?(admission.owner_token) }
|
|
57
146
|
values = @task_executions.values
|
|
58
147
|
@task_executions.clear
|
|
59
|
-
values
|
|
148
|
+
[values, @terminal_operations.values.dup]
|
|
60
149
|
end
|
|
61
150
|
failure = error || Phronomy::RuntimeShutdownError.new("Runtime stopped Workflow task execution")
|
|
62
|
-
|
|
151
|
+
operations.each { |operation| operation.shutdown(failure) }
|
|
152
|
+
executions.each do |execution|
|
|
153
|
+
if operations.any? { |operation| operation.owner_token.equal?(execution.owner_token) }
|
|
154
|
+
execution.close
|
|
155
|
+
else
|
|
156
|
+
execution.retire(failure)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
63
159
|
end
|
|
64
160
|
|
|
65
161
|
# Called under Runtime's lifecycle lock. Only queue owner-side decisions;
|
|
@@ -179,14 +275,19 @@ module Phronomy
|
|
|
179
275
|
assert_event_loop_thread!
|
|
180
276
|
key = workflow_instance_id.to_s
|
|
181
277
|
execution = nil
|
|
278
|
+
operation = nil
|
|
182
279
|
released = synchronize do
|
|
183
280
|
current = @workflow_admissions[key]
|
|
184
281
|
next false unless current&.owner_token&.equal?(owner_token)
|
|
282
|
+
operation = @terminal_operations[owner_token]
|
|
283
|
+
next false if operation && !operation.release_permitted?
|
|
185
284
|
|
|
186
285
|
@workflow_admissions.delete(key)
|
|
286
|
+
@terminal_operations.delete(owner_token)
|
|
187
287
|
execution = @task_executions.delete(owner_token)
|
|
188
288
|
true
|
|
189
289
|
end
|
|
290
|
+
operation&.released if released
|
|
190
291
|
execution&.close
|
|
191
292
|
released
|
|
192
293
|
end
|
|
@@ -249,9 +350,7 @@ module Phronomy
|
|
|
249
350
|
end
|
|
250
351
|
|
|
251
352
|
def workflow_admission_transition_in_progress_locked?
|
|
252
|
-
|
|
253
|
-
%i[admitting executing persisting_terminal].include?(admission.state)
|
|
254
|
-
end
|
|
353
|
+
!@workflow_admissions.empty?
|
|
255
354
|
end
|
|
256
355
|
end
|
|
257
356
|
end
|
|
@@ -30,10 +30,11 @@ module Phronomy
|
|
|
30
30
|
:repository,
|
|
31
31
|
:persist,
|
|
32
32
|
:expected_revision,
|
|
33
|
-
:cancellation_token
|
|
33
|
+
:cancellation_token,
|
|
34
|
+
:result_task
|
|
34
35
|
) do
|
|
35
|
-
def initialize(cancellation_token: nil, **fields)
|
|
36
|
-
super(**fields, cancellation_token: cancellation_token)
|
|
36
|
+
def initialize(cancellation_token: nil, result_task: nil, **fields)
|
|
37
|
+
super(**fields, cancellation_token: cancellation_token, result_task: result_task)
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
|
|
@@ -62,16 +63,9 @@ module Phronomy
|
|
|
62
63
|
|
|
63
64
|
# EventLoop -> Offload operation-specific immutable/value snapshots.
|
|
64
65
|
WorkflowLoadCommand = Data.define(:repository, :workflow_instance_id)
|
|
65
|
-
WorkflowTerminalPersistenceCommand = Data.define(
|
|
66
|
-
:repository,
|
|
67
|
-
:workflow_instance_id,
|
|
68
|
-
:expected_revision,
|
|
69
|
-
:snapshot
|
|
70
|
-
)
|
|
71
66
|
|
|
72
67
|
# Offload -> EventLoop/FSMSession operation results.
|
|
73
68
|
WorkflowLoadResult = Data.define(:repository, :snapshot, :revision)
|
|
74
|
-
WorkflowTerminalPersistenceResult = Data.define(:outcome, :revision, :error)
|
|
75
69
|
|
|
76
70
|
StartLoadReady = Data.define(:runner, :request, :result, :error)
|
|
77
71
|
ResumeLoadReady = Data.define(:runner, :request, :result, :error)
|
|
@@ -99,6 +93,7 @@ module Phronomy
|
|
|
99
93
|
@wait_state_names = wait_state_names
|
|
100
94
|
@task_states = task_states
|
|
101
95
|
@persistence = persistence
|
|
96
|
+
@recovery_identity = Object.new.freeze
|
|
102
97
|
@environment = WorkflowExecutionEnvironment.current
|
|
103
98
|
@phase_machine_class = @environment.compile_transitions(
|
|
104
99
|
entry_point: @entry_point,
|
|
@@ -120,6 +115,32 @@ module Phronomy
|
|
|
120
115
|
start_new_execution(input, config)
|
|
121
116
|
end
|
|
122
117
|
|
|
118
|
+
def reconcile_terminal_async(recovery:)
|
|
119
|
+
unless recovery.is_a?(Phronomy::WorkflowTerminalRecovery)
|
|
120
|
+
raise ArgumentError, "recovery must be a WorkflowTerminalRecovery"
|
|
121
|
+
end
|
|
122
|
+
operation = recovery.send(:operation)
|
|
123
|
+
unless operation.is_a?(Phronomy::WorkflowTerminalOperation) &&
|
|
124
|
+
operation.recovery.equal?(recovery) && operation.belongs_to?(@recovery_identity)
|
|
125
|
+
raise ArgumentError, "recovery belongs to another Workflow"
|
|
126
|
+
end
|
|
127
|
+
operation.observe
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def reconcile_terminal(recovery:)
|
|
131
|
+
ensure_blocking_call_allowed!(:reconcile_terminal, :reconcile_terminal_async)
|
|
132
|
+
reconcile_terminal_async(recovery: recovery).wait_result
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def pending_terminal_recovery(workflow_instance_id:)
|
|
136
|
+
unless workflow_instance_id.is_a?(String) && !workflow_instance_id.empty?
|
|
137
|
+
raise ArgumentError, "workflow_instance_id must be a nonempty String"
|
|
138
|
+
end
|
|
139
|
+
@environment.existing_registry&.pending_terminal_recovery(
|
|
140
|
+
workflow_instance_id, runner_identity: @recovery_identity
|
|
141
|
+
)
|
|
142
|
+
end
|
|
143
|
+
|
|
123
144
|
def stream(input, config: {}, &observer)
|
|
124
145
|
ensure_blocking_call_allowed!(:stream, :invoke_async)
|
|
125
146
|
raise ArgumentError, "stream requires a block" unless observer
|
|
@@ -624,8 +645,10 @@ module Phronomy
|
|
|
624
645
|
stable_observer: nil
|
|
625
646
|
)
|
|
626
647
|
assert_execution_owner!
|
|
648
|
+
execution = execution.with(result_task: result_task)
|
|
649
|
+
registry = @environment.registry
|
|
627
650
|
task_execution = unless @task_states.empty?
|
|
628
|
-
WorkflowTaskExecution.new(definitions: @task_states, registry:
|
|
651
|
+
WorkflowTaskExecution.new(definitions: @task_states, registry: registry,
|
|
629
652
|
environment: @environment, owner_token: execution.owner_token, result_task: result_task,
|
|
630
653
|
cancellation_token: execution.cancellation_token)
|
|
631
654
|
end
|
|
@@ -637,8 +660,8 @@ module Phronomy
|
|
|
637
660
|
stable_observer: stable_observer,
|
|
638
661
|
task_execution: task_execution
|
|
639
662
|
)
|
|
640
|
-
|
|
641
|
-
|
|
663
|
+
registry.bind_task_execution(task_execution) if task_execution
|
|
664
|
+
registry.bind_workflow_session(
|
|
642
665
|
execution.workflow_instance_id,
|
|
643
666
|
owner_token: execution.owner_token,
|
|
644
667
|
fsm_session_id: session.id
|
|
@@ -647,7 +670,7 @@ module Phronomy
|
|
|
647
670
|
source_task = Phronomy::TaskResult.deferred(name: "workflow-source:#{session.id}")
|
|
648
671
|
source_task.on_complete do |result, error|
|
|
649
672
|
finalize_execution(
|
|
650
|
-
execution: execution,
|
|
673
|
+
registry: registry, execution: execution,
|
|
651
674
|
result_task: result_task,
|
|
652
675
|
result: result,
|
|
653
676
|
error: error,
|
|
@@ -668,9 +691,18 @@ module Phronomy
|
|
|
668
691
|
|
|
669
692
|
# Called from source_task completion on EventLoop, after the FSMSession has
|
|
670
693
|
# accepted the durable terminal result (when a durable barrier is required).
|
|
671
|
-
def finalize_execution(execution:, result_task:, result:, error:, task_execution: nil)
|
|
694
|
+
def finalize_execution(registry:, execution:, result_task:, result:, error:, task_execution: nil)
|
|
672
695
|
assert_execution_owner!
|
|
673
|
-
|
|
696
|
+
operation = registry.terminal_operation(execution.owner_token)
|
|
697
|
+
if operation
|
|
698
|
+
operation.confirm_retirement(result) if result.is_a?(Phronomy::ExecutionRetirement)
|
|
699
|
+
unless operation.normal_finalization?
|
|
700
|
+
operation.fail_original(error || (result.error if result.is_a?(Phronomy::ExecutionRetirement)))
|
|
701
|
+
return
|
|
702
|
+
end
|
|
703
|
+
operation.apply_normal_finalization
|
|
704
|
+
end
|
|
705
|
+
registry.release_workflow(
|
|
674
706
|
execution.workflow_instance_id,
|
|
675
707
|
owner_token: execution.owner_token
|
|
676
708
|
)
|
|
@@ -694,107 +726,19 @@ module Phronomy
|
|
|
694
726
|
state: :persisting_terminal
|
|
695
727
|
)
|
|
696
728
|
|
|
697
|
-
operation = Phronomy::
|
|
729
|
+
operation = Phronomy::WorkflowTerminalPersistence::Command.new(
|
|
698
730
|
repository: execution.repository,
|
|
699
731
|
workflow_instance_id: execution.workflow_instance_id.to_s.freeze,
|
|
700
732
|
expected_revision: execution.expected_revision,
|
|
701
733
|
snapshot: deep_immutable_copy(snapshot_for(context))
|
|
702
734
|
)
|
|
703
735
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
task.on_complete do |result, operation_error|
|
|
708
|
-
deliver_terminal_persistence_result(execution, event_sink, result, operation_error)
|
|
709
|
-
end
|
|
736
|
+
Phronomy::WorkflowTerminalOperation.new(runner_identity: @recovery_identity, environment: @environment,
|
|
737
|
+
registry: @environment.registry, execution: execution, command: operation,
|
|
738
|
+
terminal_type: terminal_type, event_sink: event_sink, context_class: @state_class).start
|
|
710
739
|
terminal_type
|
|
711
740
|
end
|
|
712
741
|
|
|
713
|
-
def persist_terminal_snapshot(operation)
|
|
714
|
-
revision = operation.repository.save(
|
|
715
|
-
operation.workflow_instance_id,
|
|
716
|
-
expected_revision: operation.expected_revision,
|
|
717
|
-
snapshot: operation.snapshot
|
|
718
|
-
)
|
|
719
|
-
Phronomy::WorkflowRunner::WorkflowTerminalPersistenceResult.new(
|
|
720
|
-
outcome: :success,
|
|
721
|
-
revision: revision,
|
|
722
|
-
error: nil
|
|
723
|
-
)
|
|
724
|
-
rescue Phronomy::Persistence::ConflictError,
|
|
725
|
-
Phronomy::Persistence::NotFoundError,
|
|
726
|
-
Phronomy::Persistence::SerializationError,
|
|
727
|
-
Phronomy::Persistence::UnsupportedBackendError => error
|
|
728
|
-
Phronomy::WorkflowRunner::WorkflowTerminalPersistenceResult.new(
|
|
729
|
-
outcome: :known_failure,
|
|
730
|
-
revision: nil,
|
|
731
|
-
error: error
|
|
732
|
-
)
|
|
733
|
-
rescue => error
|
|
734
|
-
reconcile_workflow_terminal_f1(operation, error)
|
|
735
|
-
end
|
|
736
|
-
|
|
737
|
-
def deliver_terminal_persistence_result(execution, event_sink, result, operation_error)
|
|
738
|
-
delivery = if operation_error
|
|
739
|
-
Phronomy::WorkflowRunner::WorkflowTerminalPersistenceResult.new(
|
|
740
|
-
outcome: :outcome_unknown,
|
|
741
|
-
revision: nil,
|
|
742
|
-
error: operation_error
|
|
743
|
-
)
|
|
744
|
-
else
|
|
745
|
-
result
|
|
746
|
-
end
|
|
747
|
-
accepted = event_sink.post(:workflow_terminal_persistence_result, delivery)
|
|
748
|
-
unless accepted
|
|
749
|
-
Phronomy::RuntimeSettings.current.logger&.warn(
|
|
750
|
-
"[Phronomy] EventLoop rejected Workflow terminal persistence result " \
|
|
751
|
-
"for #{execution.workflow_instance_id.inspect}"
|
|
752
|
-
)
|
|
753
|
-
end
|
|
754
|
-
end
|
|
755
|
-
|
|
756
|
-
def reconcile_workflow_terminal_f1(operation, original_error)
|
|
757
|
-
record = operation.repository.load(operation.workflow_instance_id)
|
|
758
|
-
case Phronomy::Persistence::SnapshotComparison.compare_revisioned_snapshot(
|
|
759
|
-
record: record,
|
|
760
|
-
expected_pre_revision: operation.expected_revision,
|
|
761
|
-
intended_snapshot: operation.snapshot
|
|
762
|
-
)
|
|
763
|
-
when :post_state
|
|
764
|
-
revision = Phronomy::Persistence::SnapshotComparison.fetch_value(record, :revision)
|
|
765
|
-
Phronomy::WorkflowRunner::WorkflowTerminalPersistenceResult.new(
|
|
766
|
-
outcome: :success,
|
|
767
|
-
revision: revision,
|
|
768
|
-
error: nil
|
|
769
|
-
)
|
|
770
|
-
when :pre_state
|
|
771
|
-
# The uncertain save is now known not to have committed. Do not blindly
|
|
772
|
-
# retry it here; surface a known failure through the ordinary terminal
|
|
773
|
-
# barrier semantics.
|
|
774
|
-
Phronomy::WorkflowRunner::WorkflowTerminalPersistenceResult.new(
|
|
775
|
-
outcome: :known_failure,
|
|
776
|
-
revision: nil,
|
|
777
|
-
error: original_error
|
|
778
|
-
)
|
|
779
|
-
else
|
|
780
|
-
conflict = Phronomy::Persistence::StateConflictError.new(
|
|
781
|
-
"Workflow terminal Persistence outcome conflicts with both expected " \
|
|
782
|
-
"pre-state and intended post-state for #{operation.workflow_instance_id.inspect}"
|
|
783
|
-
)
|
|
784
|
-
Phronomy::WorkflowRunner::WorkflowTerminalPersistenceResult.new(
|
|
785
|
-
outcome: :outcome_unknown,
|
|
786
|
-
revision: nil,
|
|
787
|
-
error: conflict
|
|
788
|
-
)
|
|
789
|
-
end
|
|
790
|
-
rescue => reconciliation_error
|
|
791
|
-
Phronomy::WorkflowRunner::WorkflowTerminalPersistenceResult.new(
|
|
792
|
-
outcome: :outcome_unknown,
|
|
793
|
-
revision: nil,
|
|
794
|
-
error: reconciliation_error
|
|
795
|
-
)
|
|
796
|
-
end
|
|
797
|
-
|
|
798
742
|
def release_and_fail(request, error)
|
|
799
743
|
assert_execution_owner!
|
|
800
744
|
@environment.registry.release_workflow(
|
|
@@ -851,6 +795,7 @@ module Phronomy
|
|
|
851
795
|
context: context,
|
|
852
796
|
event_sink: event_sink
|
|
853
797
|
)
|
|
798
|
+
@environment.registry.terminal_operation(execution.owner_token)
|
|
854
799
|
}
|
|
855
800
|
end
|
|
856
801
|
|