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
|
@@ -36,9 +36,22 @@ module Phronomy
|
|
|
36
36
|
AgentAdmission = Data.define(:agent_id, :owner_token, :execution_id, :state)
|
|
37
37
|
private_constant :AgentAdmission
|
|
38
38
|
|
|
39
|
+
# The admission token is retained independently of the durable execution
|
|
40
|
+
# ID, so an old recovery reference cannot release a replacement owner.
|
|
41
|
+
TerminalOperationEntry = Data.define(
|
|
42
|
+
:operation, :agent, :coordinator, :owner_token, :agent_id,
|
|
43
|
+
:execution_id, :fsm_session_id, :sessionless
|
|
44
|
+
) do
|
|
45
|
+
def initialize(sessionless: false, **values)
|
|
46
|
+
super
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
private_constant :TerminalOperationEntry
|
|
50
|
+
|
|
39
51
|
UNSET = Object.new.freeze
|
|
40
52
|
PhysicalCompletion = Data.define(:execution_id, :token)
|
|
41
|
-
|
|
53
|
+
CustodyQuery = Data.define(:agent_id, :execution_id, :environment, :completion)
|
|
54
|
+
private_constant :UNSET, :PhysicalCompletion, :CustodyQuery
|
|
42
55
|
|
|
43
56
|
def initialize(channel:)
|
|
44
57
|
super
|
|
@@ -47,6 +60,10 @@ module Phronomy
|
|
|
47
60
|
@agent_completion_waiters = Hash.new { |hash, key| hash[key] = [] }
|
|
48
61
|
@agent_inflight_work = Hash.new { |hash, key| hash[key] = {} }
|
|
49
62
|
@agent_deferred_terminals = {}
|
|
63
|
+
@terminal_operations = {}
|
|
64
|
+
@approval_operations = {}
|
|
65
|
+
@dispatch_operations = {}
|
|
66
|
+
@initial_preparations = {}
|
|
50
67
|
end
|
|
51
68
|
|
|
52
69
|
def post(command, admission: false, completion: nil)
|
|
@@ -55,39 +72,425 @@ module Phronomy
|
|
|
55
72
|
|
|
56
73
|
def deliver(command)
|
|
57
74
|
assert_event_loop_thread!
|
|
58
|
-
|
|
75
|
+
case command
|
|
76
|
+
when PhysicalCompletion
|
|
59
77
|
complete_agent_physical_work(command)
|
|
78
|
+
when CustodyQuery
|
|
79
|
+
deliver_custody_query(command)
|
|
80
|
+
when OutcomeRecoveryOperation::Observe, OutcomeRecoveryOperation::Ready,
|
|
81
|
+
ApprovalRecoveryOperation::Observe, ApprovalRecoveryOperation::Ready,
|
|
82
|
+
DispatchRecoveryOperation::Observe, DispatchRecoveryOperation::Ready,
|
|
83
|
+
InitialPreparationRecoveryOperation::Observe, InitialPreparationRecoveryOperation::Ready
|
|
84
|
+
command.operation.deliver(command)
|
|
60
85
|
else
|
|
61
86
|
command.coordinator.deliver_on_event_loop(command)
|
|
62
87
|
end
|
|
63
88
|
end
|
|
64
89
|
|
|
90
|
+
# Queue behind ordinary delivery so settling a waiter before owner release
|
|
91
|
+
# does not expose the intermediate state to a coordinating host caller.
|
|
92
|
+
# @api private
|
|
93
|
+
def observe_execution_custody(agent_id:, execution_id:, environment:)
|
|
94
|
+
completion = Phronomy::TaskResult.deferred(name: "agent-custody:#{execution_id}")
|
|
95
|
+
query = CustodyQuery.new(agent_id: agent_id.to_s.dup.freeze,
|
|
96
|
+
execution_id: execution_id.to_s.dup.freeze, environment: environment, completion: completion)
|
|
97
|
+
unless post(query, completion: completion)
|
|
98
|
+
completion.fail(Phronomy::RuntimeShutdownError.new("Agent custody observation was rejected"))
|
|
99
|
+
end
|
|
100
|
+
completion
|
|
101
|
+
rescue => error
|
|
102
|
+
completion&.fail(error)
|
|
103
|
+
completion || raise
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
private def deliver_custody_query(query)
|
|
107
|
+
query.environment.assert_custody_query_available!
|
|
108
|
+
pending = synchronize do
|
|
109
|
+
key = query.execution_id
|
|
110
|
+
admission = @agent_admissions[query.agent_id]
|
|
111
|
+
# Nil admission identity is conservative. Same-ID foreign entries are
|
|
112
|
+
# also ambiguous custody, never proof that this Agent owns their work.
|
|
113
|
+
!!((admission && (admission.execution_id.nil? || admission.execution_id == key)) ||
|
|
114
|
+
@initial_preparations.values.any? { |operation| operation.execution_id == key } ||
|
|
115
|
+
@agent_executions.key?(key) || @terminal_operations.key?(key) ||
|
|
116
|
+
@approval_operations.key?(key) || @dispatch_operations.key?(key) ||
|
|
117
|
+
@agent_inflight_work.fetch(key, nil)&.any? || @agent_deferred_terminals.key?(key) ||
|
|
118
|
+
@agent_completion_waiters.fetch(key, nil)&.any?)
|
|
119
|
+
end
|
|
120
|
+
query.completion.complete(pending)
|
|
121
|
+
rescue => error
|
|
122
|
+
query.completion.fail(error)
|
|
123
|
+
end
|
|
124
|
+
|
|
65
125
|
# Called under the EventLoop lifecycle lock, including during shutdown.
|
|
66
126
|
def idle?
|
|
67
127
|
@agent_inflight_work.values.all?(&:empty?) &&
|
|
68
128
|
@agent_deferred_terminals.empty? &&
|
|
69
|
-
|
|
129
|
+
@terminal_operations.empty? && @approval_operations.empty? && @dispatch_operations.empty? &&
|
|
130
|
+
@initial_preparations.empty? && !agent_admission_transition_in_progress_locked?
|
|
70
131
|
end
|
|
71
132
|
|
|
72
133
|
# A dispatcher failure runs this on EventLoop; normal teardown runs it only
|
|
73
134
|
# after that thread has joined. Task callbacks run outside the lifecycle lock.
|
|
74
135
|
def shutdown(error:)
|
|
75
|
-
pending = synchronize do
|
|
76
|
-
|
|
136
|
+
pending, retained = synchronize do
|
|
137
|
+
retained_ids = @terminal_operations.keys | @approval_operations.keys | @dispatch_operations.keys |
|
|
138
|
+
@initial_preparations.values.map(&:execution_id)
|
|
139
|
+
# A cleared directory alone cannot certify a dropped live obligation.
|
|
140
|
+
@discarded_stopped_custody ||= (@agent_executions.keys | @agent_inflight_work.keys |
|
|
141
|
+
@agent_deferred_terminals.keys | @agent_completion_waiters.keys).any? { |id| !retained_ids.include?(id) } ||
|
|
142
|
+
@agent_admissions.any? { |id, entry| !@initial_preparations.key?(id) && !retained_ids.include?(entry.execution_id) }
|
|
143
|
+
waiters = @agent_completion_waiters.dup
|
|
77
144
|
@agent_completion_waiters.clear
|
|
78
|
-
@agent_inflight_work.
|
|
79
|
-
@agent_deferred_terminals.
|
|
80
|
-
@agent_admissions.
|
|
81
|
-
@agent_executions.
|
|
82
|
-
waiters
|
|
145
|
+
@agent_inflight_work.delete_if { |id, _work| !retained_ids.include?(id) }
|
|
146
|
+
@agent_deferred_terminals.delete_if { |id, _command| !retained_ids.include?(id) }
|
|
147
|
+
@agent_admissions.delete_if { |id, admission| !@initial_preparations.key?(id) && !retained_ids.include?(admission.execution_id) }
|
|
148
|
+
@agent_executions.delete_if { |id, _state| !retained_ids.include?(id) }
|
|
149
|
+
[waiters, (@terminal_operations.values + @approval_operations.values + @dispatch_operations.values).map(&:operation) + @initial_preparations.values]
|
|
83
150
|
end
|
|
84
|
-
return if pending.empty?
|
|
85
151
|
|
|
86
|
-
error
|
|
152
|
+
failure = error || Phronomy::ExecutionRehydrationRequiredError.new(
|
|
87
153
|
"Runtime terminated while Agent execution remained nonterminal; " \
|
|
88
154
|
"process-local TaskResult handles are not rehydrated"
|
|
89
155
|
)
|
|
90
|
-
|
|
156
|
+
retained.each do |operation|
|
|
157
|
+
waiters = pending.delete(operation.execution_id)
|
|
158
|
+
operation.retain_original_waiters(Array(waiters))
|
|
159
|
+
diagnostic = operation.shutdown(failure)
|
|
160
|
+
fail_shutdown_waiters(waiters,
|
|
161
|
+
diagnostic.is_a?(Exception) ? diagnostic : failure)
|
|
162
|
+
end
|
|
163
|
+
pending.each_value { |waiters| fail_shutdown_waiters(waiters, failure) }
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def stopped_cleanup_ready_locked?
|
|
167
|
+
!@discarded_stopped_custody && @agent_admissions.empty? && @agent_executions.empty? &&
|
|
168
|
+
@agent_completion_waiters.empty? && idle?
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Check exact local custody before a stopped terminal retry can write.
|
|
172
|
+
# The caller already owns the stopped-operation reservation and all
|
|
173
|
+
# original workers are quiescent.
|
|
174
|
+
# @api private
|
|
175
|
+
def verify_stopped_terminal_transfer!(operation)
|
|
176
|
+
synchronize { verify_stopped_terminal_transfer_locked!(operation) }
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def transfer_stopped_terminal(operation)
|
|
180
|
+
synchronize do
|
|
181
|
+
verify_stopped_terminal_transfer_locked!(operation)
|
|
182
|
+
key = operation.execution_id
|
|
183
|
+
yield
|
|
184
|
+
@terminal_operations.delete(key)
|
|
185
|
+
@agent_inflight_work.delete(key)
|
|
186
|
+
@agent_executions.delete(key)
|
|
187
|
+
@agent_admissions.delete(operation.agent_id)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
private def verify_stopped_terminal_transfer_locked!(operation)
|
|
192
|
+
key = operation.execution_id
|
|
193
|
+
unless owns_terminal_operation_locked?(operation) && !@initial_preparations.key?(operation.agent_id) &&
|
|
194
|
+
!@agent_inflight_work.fetch(key, nil)&.any? && !@agent_deferred_terminals.key?(key) &&
|
|
195
|
+
!@approval_operations.key?(key) && !@dispatch_operations.key?(key) &&
|
|
196
|
+
!@agent_completion_waiters.fetch(key, nil)&.any?
|
|
197
|
+
raise Phronomy::Error, "original Agent terminal authority is missing or busy"
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# Retain custody before a terminal worker can start. Live Agent mutation
|
|
202
|
+
# remains on this receiver; workers may only record evidence in the owner.
|
|
203
|
+
# @api private
|
|
204
|
+
def retain_terminal_operation(operation)
|
|
205
|
+
assert_event_loop_thread!
|
|
206
|
+
key = operation.execution_id.to_s
|
|
207
|
+
synchronize do
|
|
208
|
+
state = @agent_executions[key]
|
|
209
|
+
admission = @agent_admissions[operation.agent_id.to_s]
|
|
210
|
+
token = operation.admission_token if operation.respond_to?(:admission_token)
|
|
211
|
+
sessionless = !token.nil?
|
|
212
|
+
matches = if sessionless
|
|
213
|
+
!state && !operation.command.state_required && admission&.owner_token&.equal?(token)
|
|
214
|
+
else
|
|
215
|
+
state && state.agent.equal?(operation.agent) &&
|
|
216
|
+
state.coordinator.equal?(operation.coordinator) &&
|
|
217
|
+
state.execution.execution_revision == operation.expected_execution_revision &&
|
|
218
|
+
state.fsm_session_id.to_s == operation.fsm_session_id.to_s
|
|
219
|
+
end
|
|
220
|
+
unless matches && admission&.execution_id == key && !@terminal_operations.key?(key)
|
|
221
|
+
raise Phronomy::Error, "Agent terminal operation has no unique matching owner"
|
|
222
|
+
end
|
|
223
|
+
@terminal_operations[key] = TerminalOperationEntry.new(
|
|
224
|
+
operation: operation, agent: operation.agent, coordinator: operation.coordinator,
|
|
225
|
+
owner_token: admission.owner_token, agent_id: admission.agent_id,
|
|
226
|
+
execution_id: key.freeze, fsm_session_id: state&.fsm_session_id, sessionless: sessionless
|
|
227
|
+
)
|
|
228
|
+
end
|
|
229
|
+
operation
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# @api private
|
|
233
|
+
def terminal_operation(execution_id)
|
|
234
|
+
synchronize { @terminal_operations[execution_id.to_s]&.operation }
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# The owner checks its expected pre-revision before applying, and may then
|
|
238
|
+
# retry release at the applied post-revision. This predicate checks custody.
|
|
239
|
+
# @api private
|
|
240
|
+
def owns_terminal_operation?(operation)
|
|
241
|
+
synchronize { owns_terminal_operation_locked?(operation) }
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Read-only lookup through the existing original Runtime, including after
|
|
245
|
+
# stopped delivery. It never creates an owner or performs persistence I/O.
|
|
246
|
+
# @api private
|
|
247
|
+
def pending_agent_terminal_recovery(execution_id, agent:)
|
|
248
|
+
entry = synchronize { @terminal_operations[execution_id.to_s] }
|
|
249
|
+
entry.operation.recovery if entry&.agent&.equal?(agent) &&
|
|
250
|
+
entry.operation.recovery_kind == :terminal && entry.operation.pending?
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
def pending_agent_outcome_recovery(execution_id, agent:)
|
|
254
|
+
entry = synchronize { @terminal_operations[execution_id.to_s] }
|
|
255
|
+
entry.operation.recovery if entry&.agent&.equal?(agent) &&
|
|
256
|
+
entry.operation.recovery_kind == :outcome && entry.operation.pending?
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# One atomic custody release after live application and physical quiescence.
|
|
260
|
+
# @api private
|
|
261
|
+
def release_terminal_operation(operation)
|
|
262
|
+
assert_event_loop_thread!
|
|
263
|
+
return false unless operation.release_permitted?
|
|
264
|
+
|
|
265
|
+
released = synchronize do
|
|
266
|
+
next false unless owns_terminal_operation_locked?(operation)
|
|
267
|
+
key = operation.execution_id.to_s
|
|
268
|
+
work = @agent_inflight_work.fetch(key, nil)
|
|
269
|
+
next false if work && !work.empty?
|
|
270
|
+
next false if @agent_deferred_terminals.key?(key) || @approval_operations.key?(key) || @dispatch_operations.key?(key)
|
|
271
|
+
|
|
272
|
+
entry = @terminal_operations.delete(key)
|
|
273
|
+
@agent_inflight_work.delete(key)
|
|
274
|
+
@agent_executions.delete(key)
|
|
275
|
+
@agent_admissions.delete(entry.agent_id)
|
|
276
|
+
true
|
|
277
|
+
end
|
|
278
|
+
operation.released if released
|
|
279
|
+
released
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
# A committed approval wait resolves only the save owner. The logical
|
|
283
|
+
# execution, admission and cancellation responsibility remain suspended.
|
|
284
|
+
def resolve_outcome_approval_wait(operation)
|
|
285
|
+
assert_event_loop_thread!
|
|
286
|
+
return false unless operation.release_permitted?
|
|
287
|
+
|
|
288
|
+
released = synchronize do
|
|
289
|
+
next false unless owns_terminal_operation_locked?(operation)
|
|
290
|
+
key = operation.execution_id.to_s
|
|
291
|
+
state = @agent_executions.fetch(key)
|
|
292
|
+
next false unless state.execution.status == :suspended
|
|
293
|
+
work = @agent_inflight_work.fetch(key, nil)
|
|
294
|
+
next false if work && !work.empty?
|
|
295
|
+
next false if @agent_deferred_terminals.key?(key) || @approval_operations.key?(key) || @dispatch_operations.key?(key)
|
|
296
|
+
|
|
297
|
+
entry = @terminal_operations.delete(key)
|
|
298
|
+
@agent_executions[key] = state.with(fsm_session_id: nil)
|
|
299
|
+
@agent_admissions[entry.agent_id] = @agent_admissions.fetch(entry.agent_id).with(state: :suspended)
|
|
300
|
+
true
|
|
301
|
+
end
|
|
302
|
+
operation.released if released
|
|
303
|
+
released
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# Approval decision custody ends at restored waiting or accepted continuation;
|
|
307
|
+
# it never releases the Agent execution's admission.
|
|
308
|
+
def retain_approval_operation(operation)
|
|
309
|
+
assert_event_loop_thread!
|
|
310
|
+
key = operation.execution_id.to_s
|
|
311
|
+
synchronize do
|
|
312
|
+
state = @agent_executions[key]
|
|
313
|
+
admission = @agent_admissions[operation.agent_id.to_s]
|
|
314
|
+
unless state && state.agent.equal?(operation.agent) && state.coordinator.equal?(operation.coordinator) &&
|
|
315
|
+
state.execution.execution_revision == operation.command.expected_execution_revision &&
|
|
316
|
+
state.invocation.equal?(operation.invocation) && state.fsm_session_id.nil? &&
|
|
317
|
+
admission&.execution_id == key && !@approval_operations.key?(key)
|
|
318
|
+
raise Phronomy::Error, "Agent approval decision has no unique matching owner"
|
|
319
|
+
end
|
|
320
|
+
@approval_operations[key] = TerminalOperationEntry.new(operation: operation,
|
|
321
|
+
agent: state.agent, coordinator: state.coordinator, owner_token: admission.owner_token,
|
|
322
|
+
agent_id: admission.agent_id, execution_id: key.freeze, fsm_session_id: nil)
|
|
323
|
+
end
|
|
324
|
+
operation
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
def approval_operation(execution_id)
|
|
328
|
+
synchronize { @approval_operations[execution_id.to_s]&.operation }
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def owns_approval_operation?(operation)
|
|
332
|
+
synchronize { owns_approval_operation_locked?(operation) }
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def pending_agent_approval_recovery(execution_id, agent:)
|
|
336
|
+
entry = synchronize { @approval_operations[execution_id.to_s] }
|
|
337
|
+
entry.operation.recovery if entry&.agent&.equal?(agent) && entry.operation.pending?
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
def resolve_approval_operation(operation)
|
|
341
|
+
assert_event_loop_thread!
|
|
342
|
+
return false unless operation.resolution_permitted?
|
|
343
|
+
synchronize do
|
|
344
|
+
next false unless owns_approval_operation_locked?(operation)
|
|
345
|
+
@approval_operations.delete(operation.execution_id.to_s)
|
|
346
|
+
operation.resolution_released!
|
|
347
|
+
true
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# A dispatch barrier owns the captured preparation until it hands the same
|
|
352
|
+
# invocation onward. Resolving it never releases execution admission.
|
|
353
|
+
def retain_dispatch_operation(operation)
|
|
354
|
+
assert_event_loop_thread!
|
|
355
|
+
key = operation.execution_id.to_s
|
|
356
|
+
synchronize do
|
|
357
|
+
state = @agent_executions[key]
|
|
358
|
+
admission = @agent_admissions[operation.agent_id.to_s]
|
|
359
|
+
unless state && state.agent.equal?(operation.agent) && state.coordinator.equal?(operation.coordinator) &&
|
|
360
|
+
state.execution.execution_revision == operation.command.expected_execution_revision &&
|
|
361
|
+
state.invocation.equal?(operation.invocation) &&
|
|
362
|
+
state.fsm_session_id.to_s == operation.command.fsm_session_id.to_s &&
|
|
363
|
+
admission&.execution_id == key && !@dispatch_operations.key?(key)
|
|
364
|
+
raise Phronomy::Error, "Agent dispatch preparation has no unique matching owner"
|
|
365
|
+
end
|
|
366
|
+
@dispatch_operations[key] = TerminalOperationEntry.new(operation: operation,
|
|
367
|
+
agent: state.agent, coordinator: state.coordinator, owner_token: admission.owner_token,
|
|
368
|
+
agent_id: admission.agent_id, execution_id: key.freeze, fsm_session_id: state.fsm_session_id)
|
|
369
|
+
end
|
|
370
|
+
operation
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
def dispatch_operation(execution_id)
|
|
374
|
+
synchronize { @dispatch_operations[execution_id.to_s]&.operation }
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def owns_dispatch_operation?(operation)
|
|
378
|
+
synchronize { owns_dispatch_operation_locked?(operation) }
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
def pending_agent_dispatch_recovery(execution_id, agent:)
|
|
382
|
+
entry = synchronize { @dispatch_operations[execution_id.to_s] }
|
|
383
|
+
entry.operation.recovery if entry&.agent&.equal?(agent) && entry.operation.pending?
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
def resolve_dispatch_operation(operation)
|
|
387
|
+
assert_event_loop_thread!
|
|
388
|
+
return false unless operation.resolution_permitted?
|
|
389
|
+
synchronize do
|
|
390
|
+
next false unless owns_dispatch_operation_locked?(operation)
|
|
391
|
+
@dispatch_operations.delete(operation.execution_id.to_s)
|
|
392
|
+
operation.resolution_released!
|
|
393
|
+
true
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
def retain_initial_preparation(operation)
|
|
398
|
+
assert_event_loop_thread!
|
|
399
|
+
synchronize do
|
|
400
|
+
admission = @agent_admissions[operation.agent_id]
|
|
401
|
+
unless admission&.owner_token&.equal?(operation.request.admission_token) &&
|
|
402
|
+
admission.execution_id.nil? && !@initial_preparations.key?(operation.agent_id)
|
|
403
|
+
raise Phronomy::Error, "Initial preparation has no unique original admission"
|
|
404
|
+
end
|
|
405
|
+
@initial_preparations[operation.agent_id] = operation
|
|
406
|
+
end
|
|
407
|
+
operation
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def owns_initial_preparation?(operation)
|
|
411
|
+
synchronize { owns_initial_preparation_locked?(operation) }
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
def bind_initial_preparation(operation)
|
|
415
|
+
assert_event_loop_thread!
|
|
416
|
+
synchronize do
|
|
417
|
+
unless owns_initial_preparation_locked?(operation)
|
|
418
|
+
raise Phronomy::Error, "Initial preparation lost its original admission token"
|
|
419
|
+
end
|
|
420
|
+
current = @agent_admissions.fetch(operation.agent_id)
|
|
421
|
+
@agent_admissions[operation.agent_id] = current.with(execution_id: operation.execution_id, state: :executing)
|
|
422
|
+
end
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
# The caller has positively established that the cached session was never
|
|
426
|
+
# admitted. Remove only this owner's exact, physically quiet projection.
|
|
427
|
+
def discard_initial_projection(operation)
|
|
428
|
+
assert_event_loop_thread!
|
|
429
|
+
synchronize do
|
|
430
|
+
return false unless owns_initial_preparation_locked?(operation)
|
|
431
|
+
state = @agent_executions[operation.execution_id]
|
|
432
|
+
return true unless state
|
|
433
|
+
session = operation.initial_session
|
|
434
|
+
unless session && state.agent.equal?(operation.agent) && state.coordinator.equal?(operation.coordinator) &&
|
|
435
|
+
state.fsm_session_id == session.id && state.invocation.equal?(session.context) &&
|
|
436
|
+
@agent_inflight_work[operation.execution_id].empty? && !@agent_deferred_terminals.key?(operation.execution_id)
|
|
437
|
+
return false
|
|
438
|
+
end
|
|
439
|
+
@agent_executions.delete(operation.execution_id)
|
|
440
|
+
true
|
|
441
|
+
end
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
def pending_initial_preparation_recovery(agent:)
|
|
445
|
+
operation = synchronize { @initial_preparations[agent.agent_id] }
|
|
446
|
+
operation.recovery if operation&.belongs_to?(agent) && operation.pending?
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
# Transfer only the initial index. The exact admission token and any
|
|
450
|
+
# live state/waiters remain owned by the existing terminal protocol.
|
|
451
|
+
def transfer_initial_terminal_custody(operation, custody)
|
|
452
|
+
assert_event_loop_thread!
|
|
453
|
+
synchronize do
|
|
454
|
+
next false unless owns_initial_preparation_locked?(operation)
|
|
455
|
+
admission = @agent_admissions.fetch(operation.agent_id)
|
|
456
|
+
command = custody.operation
|
|
457
|
+
next false unless custody.coordinator.equal?(operation.coordinator) &&
|
|
458
|
+
command.execution_id == operation.execution_id && command.execution.agent_id == operation.agent_id &&
|
|
459
|
+
admission.execution_id == operation.execution_id && %i[terminalizing recovery_required].include?(admission.state)
|
|
460
|
+
accepted = if custody.retained_owner
|
|
461
|
+
@terminal_operations[operation.execution_id]&.operation.equal?(custody.retained_owner)
|
|
462
|
+
else
|
|
463
|
+
custody.task.is_a?(Phronomy::TaskResult)
|
|
464
|
+
end
|
|
465
|
+
next false unless accepted
|
|
466
|
+
@initial_preparations.delete(operation.agent_id)
|
|
467
|
+
true
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def resolve_initial_preparation(operation, state:)
|
|
472
|
+
assert_event_loop_thread!
|
|
473
|
+
return false unless operation.resolution_permitted?
|
|
474
|
+
synchronize do
|
|
475
|
+
next false unless owns_initial_preparation_locked?(operation)
|
|
476
|
+
admission = @agent_admissions.fetch(operation.agent_id)
|
|
477
|
+
if state == :resumed
|
|
478
|
+
next false unless admission.execution_id == operation.execution_id && @agent_executions.key?(operation.execution_id)
|
|
479
|
+
else
|
|
480
|
+
next false if @agent_executions.key?(operation.execution_id)
|
|
481
|
+
@agent_admissions.delete(operation.agent_id)
|
|
482
|
+
end
|
|
483
|
+
@initial_preparations.delete(operation.agent_id)
|
|
484
|
+
operation.resolution_released!
|
|
485
|
+
true
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
private def owns_initial_preparation_locked?(operation)
|
|
490
|
+
admission = @agent_admissions[operation.agent_id]
|
|
491
|
+
@initial_preparations[operation.agent_id].equal?(operation) &&
|
|
492
|
+
admission&.owner_token&.equal?(operation.request.admission_token) &&
|
|
493
|
+
(admission.execution_id.nil? || admission.execution_id == operation.execution_id)
|
|
91
494
|
end
|
|
92
495
|
|
|
93
496
|
# Process-local read-only admission check used by destructive Agent lifecycle
|
|
@@ -96,6 +499,28 @@ module Phronomy
|
|
|
96
499
|
synchronize { @agent_admissions.key?(agent_id.to_s) }
|
|
97
500
|
end
|
|
98
501
|
|
|
502
|
+
# Close only this failed installation, before continuation dispatch.
|
|
503
|
+
# An unrelated owner's admission and state survive a rejected attempt.
|
|
504
|
+
def rollback_recovery_installation(agent, execution_id:, owner_token:)
|
|
505
|
+
assert_event_loop_thread!
|
|
506
|
+
synchronize do
|
|
507
|
+
admission = @agent_admissions[agent.agent_id]
|
|
508
|
+
state = @agent_executions[execution_id]
|
|
509
|
+
owns_state = state&.agent&.equal?(agent)
|
|
510
|
+
next !owns_state unless admission&.owner_token&.equal?(owner_token)
|
|
511
|
+
next false if admission.execution_id && admission.execution_id != execution_id
|
|
512
|
+
next false if owns_state && state.fsm_session_id
|
|
513
|
+
next false if @initial_preparations.key?(agent.agent_id) || @terminal_operations.key?(execution_id) ||
|
|
514
|
+
@approval_operations.key?(execution_id) || @dispatch_operations.key?(execution_id) ||
|
|
515
|
+
@agent_inflight_work.fetch(execution_id, nil)&.any? || @agent_deferred_terminals.key?(execution_id) ||
|
|
516
|
+
@agent_completion_waiters.fetch(execution_id, nil)&.any?
|
|
517
|
+
|
|
518
|
+
@agent_executions.delete(execution_id) if owns_state
|
|
519
|
+
@agent_admissions.delete(agent.agent_id)
|
|
520
|
+
true
|
|
521
|
+
end
|
|
522
|
+
end
|
|
523
|
+
|
|
99
524
|
# Reserves the one top-level logical execution slot for agent_id before any
|
|
100
525
|
# Persistence execution admission is attempted.
|
|
101
526
|
# @api private
|
|
@@ -214,6 +639,9 @@ module Phronomy
|
|
|
214
639
|
false
|
|
215
640
|
end
|
|
216
641
|
next false unless authoritative
|
|
642
|
+
next false if @initial_preparations.key?(key)
|
|
643
|
+
next false if @terminal_operations.key?(current.execution_id) || @approval_operations.key?(current.execution_id) ||
|
|
644
|
+
@dispatch_operations.key?(current.execution_id)
|
|
217
645
|
|
|
218
646
|
@agent_admissions.delete(key)
|
|
219
647
|
true
|
|
@@ -245,6 +673,22 @@ module Phronomy
|
|
|
245
673
|
@agent_executions[execution_id.to_s]
|
|
246
674
|
end
|
|
247
675
|
|
|
676
|
+
# Preserve the existing admission across a recovered preparing session's
|
|
677
|
+
# replacement. The token stays on EventLoop and never enters worker input.
|
|
678
|
+
def agent_execution_admission_token(execution_id, agent:, coordinator:)
|
|
679
|
+
assert_event_loop_thread!
|
|
680
|
+
key = execution_id.to_s
|
|
681
|
+
synchronize do
|
|
682
|
+
state = @agent_executions[key]
|
|
683
|
+
admission = @agent_admissions[agent.agent_id.to_s]
|
|
684
|
+
unless state&.agent&.equal?(agent) && state.coordinator.equal?(coordinator) &&
|
|
685
|
+
admission&.execution_id == key
|
|
686
|
+
raise Phronomy::Error, "Recovered Agent execution has no matching admission"
|
|
687
|
+
end
|
|
688
|
+
admission.owner_token
|
|
689
|
+
end
|
|
690
|
+
end
|
|
691
|
+
|
|
248
692
|
# @api private
|
|
249
693
|
def install_agent_execution(
|
|
250
694
|
execution_id:,
|
|
@@ -326,6 +770,11 @@ module Phronomy
|
|
|
326
770
|
task
|
|
327
771
|
end
|
|
328
772
|
|
|
773
|
+
# Snapshot only: observation failure does not remove job-completion leases.
|
|
774
|
+
def agent_completion_waiters(execution_id)
|
|
775
|
+
synchronize { @agent_completion_waiters.fetch(execution_id.to_s, []).dup.freeze }
|
|
776
|
+
end
|
|
777
|
+
|
|
329
778
|
# Atomically detaches all process-local completion waiters at authoritative
|
|
330
779
|
# terminal delivery. A fallback TaskResult is included for pre-install terminal
|
|
331
780
|
# paths that never acquired a live execution directory entry.
|
|
@@ -424,6 +873,9 @@ module Phronomy
|
|
|
424
873
|
assert_event_loop_thread!
|
|
425
874
|
key = execution_id.to_s
|
|
426
875
|
synchronize do
|
|
876
|
+
if @terminal_operations.key?(key) || @approval_operations.key?(key) || @dispatch_operations.key?(key)
|
|
877
|
+
raise Phronomy::Error, "Agent execution #{key.inspect} requires terminal operation release"
|
|
878
|
+
end
|
|
427
879
|
work = @agent_inflight_work.fetch(key, nil)
|
|
428
880
|
unless work.nil? || work.empty?
|
|
429
881
|
raise Phronomy::Error,
|
|
@@ -440,6 +892,49 @@ module Phronomy
|
|
|
440
892
|
|
|
441
893
|
private
|
|
442
894
|
|
|
895
|
+
def owns_dispatch_operation_locked?(operation)
|
|
896
|
+
entry = @dispatch_operations[operation.execution_id.to_s]
|
|
897
|
+
return false unless entry&.operation&.equal?(operation)
|
|
898
|
+
admission = @agent_admissions[entry.agent_id]
|
|
899
|
+
state = @agent_executions[entry.execution_id]
|
|
900
|
+
admission&.owner_token&.equal?(entry.owner_token) && admission.execution_id == entry.execution_id &&
|
|
901
|
+
state&.agent&.equal?(entry.agent) && state.coordinator.equal?(entry.coordinator) &&
|
|
902
|
+
state.invocation.equal?(operation.invocation) && state.fsm_session_id.to_s == entry.fsm_session_id.to_s
|
|
903
|
+
end
|
|
904
|
+
|
|
905
|
+
def owns_approval_operation_locked?(operation)
|
|
906
|
+
entry = @approval_operations[operation.execution_id.to_s]
|
|
907
|
+
return false unless entry&.operation&.equal?(operation)
|
|
908
|
+
admission = @agent_admissions[entry.agent_id]
|
|
909
|
+
state = @agent_executions[entry.execution_id]
|
|
910
|
+
admission&.owner_token&.equal?(entry.owner_token) && admission.execution_id == entry.execution_id &&
|
|
911
|
+
state&.agent&.equal?(entry.agent) && state.coordinator.equal?(entry.coordinator) &&
|
|
912
|
+
state.invocation.equal?(operation.invocation)
|
|
913
|
+
end
|
|
914
|
+
|
|
915
|
+
def owns_terminal_operation_locked?(operation)
|
|
916
|
+
entry = @terminal_operations[operation.execution_id.to_s]
|
|
917
|
+
return false unless entry&.operation&.equal?(operation)
|
|
918
|
+
admission = @agent_admissions[entry.agent_id]
|
|
919
|
+
state = @agent_executions[entry.execution_id]
|
|
920
|
+
return false unless admission&.owner_token&.equal?(entry.owner_token) &&
|
|
921
|
+
admission.execution_id == entry.execution_id
|
|
922
|
+
if entry.sessionless
|
|
923
|
+
!state && operation.agent.equal?(entry.agent) && operation.coordinator.equal?(entry.coordinator) &&
|
|
924
|
+
operation.admission_token.equal?(entry.owner_token)
|
|
925
|
+
else
|
|
926
|
+
state&.agent&.equal?(entry.agent) && state.coordinator.equal?(entry.coordinator) &&
|
|
927
|
+
state.fsm_session_id.to_s == entry.fsm_session_id.to_s
|
|
928
|
+
end
|
|
929
|
+
end
|
|
930
|
+
|
|
931
|
+
# Stopped observation delivery is not domain-operation completion. Only a
|
|
932
|
+
# retained terminal owner with known quiescence may acknowledge its work;
|
|
933
|
+
# ordinary suspended executions keep their existing physical boundary.
|
|
934
|
+
def fail_shutdown_waiters(waiters, error)
|
|
935
|
+
Array(waiters).each { |waiter| waiter.fail(error) }
|
|
936
|
+
end
|
|
937
|
+
|
|
443
938
|
def complete_agent_physical_work(payload)
|
|
444
939
|
key = payload.execution_id.to_s
|
|
445
940
|
token = payload.token
|