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,298 @@
|
|
|
1
|
+
# Original-owner Agent terminal recovery
|
|
2
|
+
|
|
3
|
+
The later [stopped terminal custody contract](../runtime-and-concurrency.md#transfer-a-stopped-terminal-disposition) adds an explicit same-process recipient after the original Runtime stops. The live-owner procedures below retain their original admission rules.
|
|
4
|
+
|
|
5
|
+
Phronomy separates a saved Agent outcome from the original live owner's application of that outcome. The Agent owns terminal interpretation, live state, accepted-job responsibility and observation. Persistence supplies atomic guarded records; a Runtime supplies serial delivery and workers. G3b-2 connects the private G3b-1 proof to the original Agent owner without moving domain decisions into those lower layers.
|
|
6
|
+
|
|
7
|
+
For example, a research Agent calculates an answer, commits its terminal records, then loses the save response and its first confirmation read. Another `resume` may retrieve that answer while the original invocation remains pending and the Agent stays busy. The new recovery operation addresses the retained original owner instead of treating that separate read as completion.
|
|
8
|
+
|
|
9
|
+
Baseline: G3b-1 `e4a57fa278ed5136679ad884a8a4c51fa585382e`. This document describes the G3b-2 implementation candidate and its explicit acceptance boundary. The delivery evidence records the exact final commit and actual check results. Contract concept v55 and foundation v48 are the canonical architecture references.
|
|
10
|
+
|
|
11
|
+
The later [correlated-child execution recovery contract](agent-child-execution-recovery.md) extends actual terminal recovery to supported original correlated child owners. Child-local release remains separate from parent result import and retention-based peer release.
|
|
12
|
+
|
|
13
|
+
G3h adds a separate [native outcome recovery contract](native-parent-outcome-recovery.md) for native parent final, coordination-wait and approval-wait saves. `TerminalRecovery` remains actually final only. The private retained-attempt owner is shared, while the new `OutcomeRecoveryResult#saved_outcome` distinguishes saved waits from a final execution.
|
|
14
|
+
|
|
15
|
+
The later [synchronous participant custody contract](synchronous-participant-contract.md)
|
|
16
|
+
connects ordinary participant outcomes and accepted setup failures to the existing
|
|
17
|
+
outcome owner. It retains uncertainty without inferring persistence replay from
|
|
18
|
+
the public synchronous callback contract. `TerminalRecovery` and `OutcomeRecovery`
|
|
19
|
+
keep their distinct public result meanings.
|
|
20
|
+
|
|
21
|
+
## Preserve responsibility after an observation ends
|
|
22
|
+
|
|
23
|
+
The original Agent owner retains an uncertain terminal operation before exposing its recovery capability. The original caller's observation can then end with an explicit recovery error while the accepted job remains owned. A later recovery request creates a new observation; it does not reopen an earlier failed or cancelled TaskResult.
|
|
24
|
+
|
|
25
|
+
For example, an application awaiting `invoke_async` receives `Agent::TerminalRecoveryError`. Its recovery reference remains usable even if that application discards the failed task. If the original observer cancelled before receiving the error, `pending_terminal_recovery(execution_id:)` discovers the retained operation by the accepted execution identity.
|
|
26
|
+
|
|
27
|
+
This intentionally changes the baseline fault path from an unexplained indefinite wait to an observation error with retained responsibility. It is not a business-failure verdict. Ending an observer's lease is not permission to release the accepted job: the retained terminal operation, Agent admission and physical-attempt tracking continue to enforce custody. A source task's physical completion describes its tracked work, not durable job resolution.
|
|
28
|
+
|
|
29
|
+
Normal initial completion still uses the existing success, failure, cancellation and event-listener behavior. Once the original observation has ended, later recovery does not replay its event or stream listener. Its result is delivered only through the new recovery observation.
|
|
30
|
+
|
|
31
|
+
## Separate readback from persistence retry
|
|
32
|
+
|
|
33
|
+
An explicit readback determines the saved fact and may apply a confirmed post-state to the original owner. An explicit save retry has the additional authority to repeat captured persistence writes. Neither operation recomputes a terminal decision or repeats application work.
|
|
34
|
+
|
|
35
|
+
For example, after a rollback, `reconcile_terminal` returns `confirmed_pre` and leaves the Agent's accepted job active. If the application permits saving the already computed answer, `retry_terminal` rechecks the complete pre-state inside the write transaction and restores the retained bytes, references, journal identities and records.
|
|
36
|
+
|
|
37
|
+
| Method | Behavior |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `pending_terminal_recovery(execution_id:)` | Local lookup on the original Runtime's existing registry. No persistence I/O, new Runtime or coordinator. Returns nil when absent or owned by a different Agent incarnation. |
|
|
40
|
+
| `reconcile_terminal_async(recovery:)` | A fresh `TaskResult<TerminalRecoveryResult>` for classification and original-owner application. It performs no persistence write. |
|
|
41
|
+
| `reconcile_terminal(recovery:)` | Blocking host-thread form of the same operation. EventLoop blocking is rejected. |
|
|
42
|
+
| `retry_terminal_async(recovery:)` | A fresh observation of an explicitly requested captured-write retry. An exact post-state causes no duplicate write; changed evidence prevents replay. |
|
|
43
|
+
| `retry_terminal(recovery:)` | Blocking host-thread form of the same persistence retry. |
|
|
44
|
+
|
|
45
|
+
The lookup requires a nonempty String. Recovery calls require the exact process-local `Agent::TerminalRecovery` belonging to this Agent object and operation. Invalid references raise ArgumentError before persistence access. A capability contains diagnostic `agent_id`, `execution_id` and `recovery_id` readers and has no public constructor. Copying those strings does not reconstruct authority.
|
|
46
|
+
|
|
47
|
+
`resume` retains its separate meaning: continue or observe an execution through durable Agent recovery. `resolve` retains its meaning of supplying a factual outcome for an ambiguous provider/Tool subject. Neither is an alias for terminal save-only retry.
|
|
48
|
+
|
|
49
|
+
## Report saved facts and owner progress independently
|
|
50
|
+
|
|
51
|
+
A recovery result distinguishes persistence classification, application by the original serial owner, and release of accepted-job responsibility. The optional execution observation represents the saved job, while the top-level error describes the recovery operation.
|
|
52
|
+
|
|
53
|
+
For example, saving a failed execution successfully produces a fulfilled recovery observation with `execution.status == :failed` and a saved diagnostic in `execution.error`. It does not reject the recovery task merely because the job failed. An unavailable read is instead a recovery error and leaves the job's status unclassified.
|
|
54
|
+
|
|
55
|
+
| Result field | Meaning |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `recovery`, `agent_id`, `execution_id`, `recovery_id` | The same retained operation and its diagnostic identities. |
|
|
58
|
+
| `outcome` | `confirmed_post`, `confirmed_pre`, `unresolved` or `unavailable`. |
|
|
59
|
+
| `application_state` | `pending` or `applied` on the original Agent owner. |
|
|
60
|
+
| `ownership_state` | `retained` or `released`; release requires application and physical quiescence. |
|
|
61
|
+
| `revision` | The positive execution revision of a confirmed post-state; otherwise nil. |
|
|
62
|
+
| `execution` | An immutable `Agent::ExecutionObservation` of the confirmed terminal job, if available; otherwise nil. |
|
|
63
|
+
| `error` | A recovery/application error, separate from `execution.error`. |
|
|
64
|
+
|
|
65
|
+
Only a confirmed post-state permits application and release. A confirmed pre-state remains `pending` / `retained`; it is not permission to abandon the active Agent job. Conflicting evidence is `unresolved`. An unavailable worker, read or original owner is `unavailable`. A previously confirmed post-state remains a confirmed fact even if subsequent application or delivery becomes unavailable: it can report `confirmed_post` / `pending` / `retained` with an error.
|
|
66
|
+
|
|
67
|
+
The error's code is `agent.terminal_recovery`. `TerminalRecoveryError.original_error` preserves the original persistence/operation failure; `cause` preserves the immediate operation failure. The private owner separately retains the actual computed terminal exception, including an OutputError created during validation. Reconstructing arbitrary original exceptions from persistence diagnostics or rerunning validation is unnecessary and unsafe.
|
|
68
|
+
|
|
69
|
+
## Keep normal application code equivalent
|
|
70
|
+
|
|
71
|
+
Normal public invocation and exact-result observation use the same application code before and after this change. The equivalence claim is limited to the measured normal path: output, saved execution, transcript, revisions, provider count and completion. The fault path intentionally changes and is described separately below.
|
|
72
|
+
|
|
73
|
+
For example, the deterministic local adapter returns the structured answer `ordinary answer`. Both versions invoke it once, observe the result through `resume`, and produce the same functional report. The application function uses only public Agent APIs; the separate measurement function reads private records strictly as test evidence.
|
|
74
|
+
|
|
75
|
+
<table>
|
|
76
|
+
<thead><tr><th>G3b-1 baseline</th><th>G3b-2 candidate</th></tr></thead>
|
|
77
|
+
<tbody><tr><td><pre lang="ruby">def run_normal_application(persistence:)
|
|
78
|
+
agent = G3NormalApplicationAgent.create(agent_id: "g3-normal-agent", persistence: persistence)
|
|
79
|
+
source_task = agent.invoke_async("ordinary question", output_schema: {
|
|
80
|
+
type: "object", properties: {answer: {type: "string"}},
|
|
81
|
+
required: ["answer"], additionalProperties: false
|
|
82
|
+
})
|
|
83
|
+
source_result = source_task.wait_result(timeout: 5)
|
|
84
|
+
observed_result = agent.resume(source_result.fetch(:execution_id))
|
|
85
|
+
[agent, source_task, source_result, observed_result]
|
|
86
|
+
end</pre></td><td><pre lang="ruby">def run_normal_application(persistence:)
|
|
87
|
+
agent = G3NormalApplicationAgent.create(agent_id: "g3-normal-agent", persistence: persistence)
|
|
88
|
+
source_task = agent.invoke_async("ordinary question", output_schema: {
|
|
89
|
+
type: "object", properties: {answer: {type: "string"}},
|
|
90
|
+
required: ["answer"], additionalProperties: false
|
|
91
|
+
})
|
|
92
|
+
source_result = source_task.wait_result(timeout: 5)
|
|
93
|
+
observed_result = agent.resume(source_result.fetch(:execution_id))
|
|
94
|
+
[agent, source_task, source_result, observed_result]
|
|
95
|
+
end</pre></td></tr></tbody>
|
|
96
|
+
</table>
|
|
97
|
+
|
|
98
|
+
The following shared setup precedes either complete function. It defines the Agent and the deterministic adapter; no private recovery or capture hook is installed by the example.
|
|
99
|
+
|
|
100
|
+
For example, replacing only the framework checkout while retaining this setup and the function above provides a controlled normal-behavior comparison without a network LLM.
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
# frozen_string_literal: true
|
|
104
|
+
|
|
105
|
+
# Run from the repository root with its bundled dependencies. This deterministic
|
|
106
|
+
# fixture adapter performs no network request. The application operation uses
|
|
107
|
+
# public Agent APIs without installing any private capture or recovery hook.
|
|
108
|
+
# The separate measurement helper reads private persistence records solely as
|
|
109
|
+
# test evidence; production capture behavior is whatever the tested version provides.
|
|
110
|
+
require "phronomy"
|
|
111
|
+
require "json"
|
|
112
|
+
|
|
113
|
+
class G3NormalFixtureAdapter < Phronomy::LLMAdapter::Base
|
|
114
|
+
attr_reader :request_count
|
|
115
|
+
|
|
116
|
+
def initialize
|
|
117
|
+
@request_count = 0
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def perform_complete(_request, cancellation_token:)
|
|
121
|
+
cancellation_token&.raise_if_cancelled!
|
|
122
|
+
@request_count += 1
|
|
123
|
+
Phronomy::LLMAdapter::Response.new(
|
|
124
|
+
content: '{"answer":"ordinary answer"}', finish_reason: :stop,
|
|
125
|
+
usage: Phronomy::LLMAdapter::TokenUsage.new(input: 4, output: 2)
|
|
126
|
+
)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
class G3NormalApplicationAgent < Phronomy::Agent::Base
|
|
131
|
+
agent_definition id: "g3-normal-behavior", version: 1
|
|
132
|
+
end
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The shared measurement and driver below follow either complete function. They record equivalent observable values and shut down the normal-path Runtime after measurement. They are test scaffolding, not hidden application recovery policy.
|
|
136
|
+
|
|
137
|
+
For example, the JSON report omits random execution identifiers and wall-clock timestamps while retaining execution revision, journal shape, output, physical completion and exact provider count.
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
def functional_observation(agent:, source_task:, source_result:, observed_result:, adapter:)
|
|
141
|
+
store = agent.persistence
|
|
142
|
+
execution = store.executions.load(source_result.fetch(:execution_id))
|
|
143
|
+
journal = store.journals.read(agent.agent_id, after: 0)
|
|
144
|
+
{
|
|
145
|
+
result: source_result.slice(:output, :raw_output, :agent_revision, :context_revision, :journal_position)
|
|
146
|
+
.merge(usage: source_result.fetch(:usage).to_h),
|
|
147
|
+
transcript: source_result.fetch(:messages).map(&:to_h),
|
|
148
|
+
durable_status: execution.status,
|
|
149
|
+
durable_phase: execution.phase,
|
|
150
|
+
durable_revision: execution.execution_revision,
|
|
151
|
+
durable_result: store.contents.fetch_text(execution.result_ref),
|
|
152
|
+
durable_raw_output: store.contents.fetch_text(execution.metadata.fetch("raw_output_ref")),
|
|
153
|
+
journal: journal.map { |record| record.to_h.slice("kind", "channel", "role", "sequence", "context_candidate") },
|
|
154
|
+
stored_llm_calls: execution.llm_calls.size,
|
|
155
|
+
live_root_status: agent.agent_root.lifecycle_status,
|
|
156
|
+
source_done: source_task.done?,
|
|
157
|
+
source_physical_complete: source_task.physical_complete?,
|
|
158
|
+
provider_calls: adapter.request_count,
|
|
159
|
+
resumed_output: observed_result.fetch(:output)
|
|
160
|
+
}
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
if $PROGRAM_NAME == __FILE__
|
|
164
|
+
begin
|
|
165
|
+
adapter = G3NormalFixtureAdapter.new
|
|
166
|
+
Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
|
|
167
|
+
agent, source_task, source_result, observed_result =
|
|
168
|
+
run_normal_application(persistence: Phronomy::PersistenceComposition.in_memory.agent)
|
|
169
|
+
raise "Unexpected output" unless source_result.fetch(:output) == {"answer" => "ordinary answer"}
|
|
170
|
+
raise "Resume changed the output" unless observed_result.fetch(:output) == source_result.fetch(:output)
|
|
171
|
+
raise "Provider was replayed" unless adapter.request_count == 1
|
|
172
|
+
observation = functional_observation(agent: agent, source_task: source_task,
|
|
173
|
+
source_result: source_result, observed_result: observed_result, adapter: adapter)
|
|
174
|
+
File.write(ENV.fetch("G3_NORMAL_REPORT"), JSON.pretty_generate(observation) + "\n")
|
|
175
|
+
ensure
|
|
176
|
+
Phronomy.reset_runtime!
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Run the assembled source with the repository's bundled dependencies and set `G3_NORMAL_REPORT` to an output filename. The full source is included in the delivery evidence. The exact normal function was executed against the G3b-1 baseline and this candidate with equal functional JSON reports. The documented application check also executes that same function directly and compares it with the baseline report; syntax alone is not used as evidence of equivalence.
|
|
183
|
+
|
|
184
|
+
## Make the application's retry policy explicit
|
|
185
|
+
|
|
186
|
+
Applications choose whether to retry a captured save and what to do when recovery remains unresolved. Phronomy retains the exact original responsibility and prevents business work from being repeated; it does not choose an application's retry schedule, escalation or publication policy.
|
|
187
|
+
|
|
188
|
+
For example, the complete function below performs one readback and at most one explicitly permitted save retry. It returns the recovery reference and receipt when still pending. Its caller continues to own the Agent and Runtime and can schedule another explicit observation without invoking the provider again.
|
|
189
|
+
|
|
190
|
+
```ruby
|
|
191
|
+
# frozen_string_literal: true
|
|
192
|
+
|
|
193
|
+
require "phronomy"
|
|
194
|
+
|
|
195
|
+
# The caller owns this Agent and its Runtime, and explicitly chooses whether a
|
|
196
|
+
# confirmed pre-state may be saved again. No provider or Tool is started here
|
|
197
|
+
# after the initial invocation. Pending recovery is returned to that owner.
|
|
198
|
+
def run_recoverable_request(agent:, input:, retry_save: false)
|
|
199
|
+
result = agent.invoke(input)
|
|
200
|
+
{state: :completed, result: result}.freeze
|
|
201
|
+
rescue Phronomy::Agent::TerminalRecoveryError => failure
|
|
202
|
+
recovery = failure.recovery
|
|
203
|
+
receipt = agent.reconcile_terminal(recovery: recovery)
|
|
204
|
+
if retry_save && receipt.outcome == :confirmed_pre
|
|
205
|
+
receipt = agent.retry_terminal(recovery: recovery)
|
|
206
|
+
end
|
|
207
|
+
if receipt.outcome == :confirmed_post && receipt.application_state == :applied &&
|
|
208
|
+
receipt.ownership_state == :released && receipt.execution
|
|
209
|
+
{state: :observed, execution: receipt.execution.to_result,
|
|
210
|
+
recovery: recovery, receipt: receipt}.freeze
|
|
211
|
+
else
|
|
212
|
+
{state: :recovery_pending, recovery: recovery, receipt: receipt}.freeze
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The function requires an already created live Agent and a host thread. `retry_save` defaults to false. Its normal return preserves the invocation result; its recovered return exposes a saved execution outcome, which may be completed, failed or cancelled. The application must inspect that status before treating it as a business success. The `recovery_pending` branch does not unload the Agent, create another Runtime or claim cleanup succeeded.
|
|
218
|
+
|
|
219
|
+
The exact function above was executed in five real-Runtime scenarios: ordinary success, committed reply loss, rollback with retry disabled, rollback with retry enabled, and a failed job whose terminal save was retried. Together with the exact normal comparison, all six documented-application checks passed. Only the storage failure is injected; the Agent, Runtime, admission, terminal construction, readback and owner application are real. These six checks do not establish the other race, shutdown or external-backend properties listed below.
|
|
220
|
+
|
|
221
|
+
The application no longer needs to guess whether a returned durable result released the old owner, retain private transaction snapshots, reconstruct journal writes, or replay provider work to make progress. It still decides whether a save retry is permitted, how long to observe, how to report a failed saved job, and how to retain or escalate unresolved responsibility.
|
|
222
|
+
|
|
223
|
+
## Bound observation and physical-attempt lifetimes
|
|
224
|
+
|
|
225
|
+
Each request returns a fresh observation while the original owner serializes physical persistence attempts. Cancelling or timing out one observation does not revoke an accepted physical attempt or the accepted Agent job. A subsequent observation can inspect the retained fact or result.
|
|
226
|
+
|
|
227
|
+
For example, two concurrent reconciliation requests join one physical read. Cancelling the first observer leaves the second observer and the owner intact. A retry requested while a read is physically active is refused as unavailable rather than silently promoting that read into a write.
|
|
228
|
+
|
|
229
|
+
Same-kind requests can share one physical attempt. A different-kind request does not start a concurrent attempt. After an unavailable or unresolved attempt, a later explicit request may try again. Confirmed-pre is not cached as a final receipt: the still-active job's cancellation ledger or records may change, so a new observation rereads them. Every write retry rechecks the full pre-state in its transaction.
|
|
230
|
+
|
|
231
|
+
A confirmed, applied and released post-state remains available through a previously held capability without persistence I/O, callback replay or a new owner. Resolved operations leave the pending index. Old references cannot affect later Agent incarnations or sessions. Recovery validates original Agent identity, execution, session, expected revision and retained operation, and release waits for the original save and any recovery attempt to be physically complete.
|
|
232
|
+
|
|
233
|
+
## Preserve custody through Runtime drain and stop
|
|
234
|
+
|
|
235
|
+
Runtime cleanup and accepted-job resolution are distinct. The original running or draining owner may finish an accepted recovery. If uncertainty remains when the Runtime stops, the retained capability reports unavailability and cleanup remains incomplete; no operation is redirected to another Runtime.
|
|
236
|
+
|
|
237
|
+
For example, shutdown during a blocked retry cannot claim complete cleanup solely because the original observation has already failed. If that attempt finishes and its confirmed outcome is applied before shutdown ends, cleanup can complete. If it cannot finish, the unresolved owner remains retained.
|
|
238
|
+
|
|
239
|
+
A stopped owner is not recoverable through this process-local API. Transfer to another Runtime, a durable recovery-ticket format, process-crash recovery and cross-process coordination are outside this stage. Retaining an in-memory capability is not durable storage. An application must not discard its owning process and infer that the job was resolved.
|
|
240
|
+
|
|
241
|
+
## State the proof and backend boundaries
|
|
242
|
+
|
|
243
|
+
The integration can reconcile or retry only a complete captured terminal proposal whose original owner is still running or draining. Physical worker completion is required for local serialization but does not prove that an arbitrary remote backend transaction has settled or that a later read is authoritative.
|
|
244
|
+
|
|
245
|
+
For example, if terminal submission is rejected before the worker starts, the accepted Agent job still needs custody but no complete encoded proposal exists. The original observer receives a recovery error and the owner stays retained; readback/retry reports unavailable rather than inventing records or rerunning the encoder.
|
|
246
|
+
|
|
247
|
+
The same limitation applies to a failure before full proposal capture. This stage does not add first-time terminal encoding or business replay through the save-only retry API, and it does not complete every Agent terminal failure case. A known complete late worker outcome can still supply conclusive evidence under the original operation's protocol.
|
|
248
|
+
|
|
249
|
+
The later [terminal submission recovery contract](agent-terminal-submission-recovery.md) adds a separate explicit operation for mechanism-proven non-admission. It does not broaden `retry_terminal`: accepted work that fails before complete capture still cannot be resubmitted through that operation.
|
|
250
|
+
|
|
251
|
+
The caller/backend must establish that the prior backend transaction has settled and that authoritative readback is ordered after it. The Store must provide its guard exclusion and atomic transaction semantics. Local worker return, revisions or CAS alone do not establish those remote conditions. External database/LLM acceptance is separate from in-memory fault injection.
|
|
252
|
+
|
|
253
|
+
The original G3b stage covered an installed standalone Agent's completed, failed or cancelled terminal save. G3e additionally supports the correlated-child actual terminal paths described in [child execution recovery](agent-child-execution-recovery.md). Parent participant coordination, execution extensions, approval suspension, handoff, initial preparation and dispatch recovery retain separate contracts; the child eligibility extension does not include those boundaries.
|
|
254
|
+
|
|
255
|
+
## Preserve domain differences in shared recovery
|
|
256
|
+
|
|
257
|
+
Agent and Workflow share the rule that persistence evidence, observation and ownership release are different facts. Their saved representations and pre-state obligations differ, so shared attempt machinery leaves terminal decisions in each domain.
|
|
258
|
+
|
|
259
|
+
For example, a Workflow segment's confirmed pre-state can release its failed terminal attempt under G2 policy. An Agent's confirmed pre-state still contains an active accepted job and needs retained custody plus a guarded save retry. Forcing both through one release callback would erase that difference.
|
|
260
|
+
|
|
261
|
+
The table below retains the historical G3b-2 comparison with Workflow G2. As of 2026-11-28, the common initial/recovery attempt and observer machinery is implemented by C13 `RetainedAttempts` and `AttemptCompletion`; the domain-policy differences in the table remain. See [the current shared design](retained-attempts.md).
|
|
262
|
+
|
|
263
|
+
| Dimension | Workflow G2 | Agent G3b-2 | Decision |
|
|
264
|
+
| --- | --- | --- | --- |
|
|
265
|
+
| Recovery reference | Original compiled Workflow, process-local | Original Agent incarnation, process-local | Adopt the same capability rule. |
|
|
266
|
+
| Observation names | `reconcile_terminal[_async]` | Same verbs and keyword | Adopt symmetry. |
|
|
267
|
+
| Pending discovery | `workflow_instance_id:` | `execution_id:` within this Agent | Use each domain's accepted-job identity. |
|
|
268
|
+
| Read/write distinction | Reconciliation never saves | Reconciliation never saves; explicit `retry_terminal[_async]` can save captured bytes | Retain justified extra operation. |
|
|
269
|
+
| Confirmed pre-state | G2 policy may apply and release | Pending and retained | Preserve domain semantics. |
|
|
270
|
+
| Saved result | Workflow context and revision | ExecutionObservation and execution revision | Reuse existing domain views. |
|
|
271
|
+
| Error and observation | Recovery error does not prove business failure; original observation stays closed | Same rule, including failed/cancelled saved executions | Adopt symmetry. |
|
|
272
|
+
| Lifetime | Physical-attempt serialization and stopped-owner unavailability | Same rule with Agent admission and original terminal ownership; G3b standalone and the later G3e supported child scope | Reuse neutral facilities; keep domain application local. |
|
|
273
|
+
|
|
274
|
+
The G3b-2 stage did not adopt a generic recovery manager. The subsequent four-owner attempt-management extraction is documented separately; its assessment includes removed duplicate code, adapter burden, comprehension, duplicate state authority, shared defect corrections, total tests and execution/retention cost together. Similar public verbs alone do not prove that a shared implementation simplifies Agent, Team and Workflow.
|
|
275
|
+
|
|
276
|
+
## Verify the original-owner behavior
|
|
277
|
+
|
|
278
|
+
Acceptance must exercise actual Agent, Runtime, persistence and observation interactions, including races and injected delivery failures. Finite models check stated transition rules and premises; they do not prove that Ruby implements the model or that every backend satisfies it.
|
|
279
|
+
|
|
280
|
+
For example, commit/reply-loss/read-loss must later produce the saved answer, update the original live Agent, release its exact admission only after physical completion, avoid old listener replay, and allow a new invocation. A passing constructor test alone establishes none of those properties.
|
|
281
|
+
|
|
282
|
+
The delivery's validation summary records measured test counts and limits. Required cases include confirmed post, retained confirmed pre, exact content retry, failed/cancelled/OutputError outcomes, cancelled original and recovery observers, same-kind concurrency, mixed-kind refusal, rejected/lost delivery, stale identity/session, changed cancellation evidence, repeated resolved receipts, draining success and stopped incomplete cleanup. Normal compatibility uses the complete comparison above; fault behavior is intentionally different:
|
|
283
|
+
|
|
284
|
+
| Trigger | G3b-1 baseline | G3b-2 candidate |
|
|
285
|
+
| --- | --- | --- |
|
|
286
|
+
| Complete terminal proposal, initial readback unavailable | Original call can remain pending without public recovery | Original observation ends with a recovery capability; original job remains owned. |
|
|
287
|
+
| Later confirmed post | Separate resume can return data while old owner stays busy | Explicit recovery applies and releases the exact original owner, then returns a new receipt. |
|
|
288
|
+
| Later confirmed pre | No connected public save-only remedy | Explicit retry may persist the same proposal after full guarded recheck. |
|
|
289
|
+
| Complete proposal unavailable | No complete saved retry material | Custody remains retained and recovery is unavailable; no fabricated write. |
|
|
290
|
+
| Unresolved shutdown | Cleanup could discard local Agent custody | Cleanup remains incomplete and the stopped original owner is not replaced. |
|
|
291
|
+
|
|
292
|
+
Both canonical Contract diagrams require review for direction, responsibility, cycles and unjustified layer skipping. The source dependency graph has existing cycles; acyclicity of selected Contract diagrams is not a claim that all source files form a DAG. Public API snapshots, RBS, annotations, full changed-file English checks, archive integrity and actual bundle application are additional delivery checks, not substitutes for the lifecycle acceptance cases.
|
|
293
|
+
|
|
294
|
+
## Preserve custody when submission is uncertain
|
|
295
|
+
|
|
296
|
+
Terminal recovery retains the original owner whenever a submitted worker may still execute. Positive executor rejection, returned handles and physical completion remain separate from whether the caller received a response.
|
|
297
|
+
|
|
298
|
+
For example, an adapter that queues a reconciliation read and then loses its handle must not permit a second read or release the owner. See [recovery submission custody](recovery-submission-custody.md) for the shared evidence rules, deliberate fault-behavior change, compatibility limits and validation scope.
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# Recover rejected Agent terminal submission
|
|
2
|
+
|
|
3
|
+
An Agent can finish its provider and Tool work yet fail to admit the terminal persistence work to its execution mechanism. The Agent still owns the accepted job, but it has no encoded terminal proposal to replay. G3b-3 adds explicit first-submission recovery to the same retained Agent operation while keeping captured-write retry separate.
|
|
4
|
+
|
|
5
|
+
For example, a research Agent calculates `retained answer`, then the worker queue rejects the terminal submission before accepting a handle or running its block. Once capacity becomes available, the application may explicitly authorize submission of that retained terminal command. Provider and Tool work remain finished; validation and encoding run for the first time.
|
|
6
|
+
|
|
7
|
+
The baseline is applied G3b-2 `b88eeb55cb1d9a888cc65ac1cdb75d2b1d8398a5`. This document describes the G3b-3 candidate; exact acceptance results belong to the delivery evidence. Contract concept v55 and foundation v48 remain the architecture references. The [G3b-2 recovery contract](agent-terminal-recovery.md) continues to define original-owner identity, observation, physical completion, application, release and shutdown custody.
|
|
8
|
+
|
|
9
|
+
## Require positive non-admission evidence
|
|
10
|
+
|
|
11
|
+
The original owner may authorize first submission only when the execution mechanism positively proves that the prior submission was not admitted. The owner must also have no returned task handle and no observed worker entry. A missing handle, an exception message or an exception class alone cannot establish that proof.
|
|
12
|
+
|
|
13
|
+
For example, the built-in OffloadPool can report a rejected enqueue through its explicit rejection callback. A custom backend that merely raises the same BackpressureError without that callback supplies no admission proof and leaves `submission_state` unknown.
|
|
14
|
+
|
|
15
|
+
A returned handle consumes first-submission permission even when its worker is still queued, is cancelled before entry, times out or loses its completion notification. An entered worker also consumes permission regardless of whether it produced complete persistence evidence. Neither case can be submitted again through this new operation. The owner consumes its permission before attempting resubmission; another mechanism-proven rejection can establish fresh `not_admitted` evidence.
|
|
16
|
+
|
|
17
|
+
This is an admission fact about terminal work, not a claim that the accepted Agent job was rejected. Its provider and Tool effects may already exist, and its job responsibility remains retained.
|
|
18
|
+
|
|
19
|
+
## Expose a distinct public operation and a fact
|
|
20
|
+
|
|
21
|
+
Applications need separate permissions for first terminal-work submission and replay of an already encoded save. The public result exposes the mechanism's admission fact so applications do not parse error strings to decide which request to make. The original owner revalidates current authority before every request.
|
|
22
|
+
|
|
23
|
+
For example, an earlier receipt can say `not_admitted` while another caller subsequently obtains admission. Retrying with the old capability must observe or refuse according to the current operation; the old receipt cannot authorize a second worker.
|
|
24
|
+
|
|
25
|
+
| Public surface | Meaning |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `retry_terminal_submission_async(recovery:)` | Fresh TaskResult for explicit first terminal-work submission after positive non-admission proof. |
|
|
28
|
+
| `retry_terminal_submission(recovery:)` | Same operation, waited on a host thread; EventLoop blocking is rejected before submission. |
|
|
29
|
+
| `TerminalRecoveryResult#submission_state` | Immutable fact: `not_admitted`, `admitted` or `unknown`. |
|
|
30
|
+
| `not_admitted` | Mechanism-proven non-admission and no contradictory handle or worker-start fact. It can justify a new request only after the owner rechecks its present state. |
|
|
31
|
+
| `admitted` | A handle or worker entry established admission. First submission cannot be repeated, including when the accepted worker never started. |
|
|
32
|
+
| `unknown` | No usable positive admission decision; this is the default when facts are unavailable. It grants no first-submission permission. |
|
|
33
|
+
|
|
34
|
+
The existing capability, recovery error and result types are reused. Result fields for persistence outcome, live application and ownership remain independent. A non-admitted attempt has no captured pre/post persistence disposition; it remains unavailable with pending application and retained ownership. The result constructor rejects a `not_admitted` / `confirmed_pre` or `confirmed_post` contradiction.
|
|
35
|
+
|
|
36
|
+
Wrong capability types and another Agent incarnation's capability are rejected before I/O, as with existing recovery methods. The caller cannot select a replacement Store, Runtime or Agent. Resolved capabilities still return their retained receipt without new work. The source observation stays closed and its old event/stream listener is not replayed.
|
|
37
|
+
|
|
38
|
+
## Preserve the existing retry guarantees
|
|
39
|
+
|
|
40
|
+
Each recovery operation has a bounded, distinct authority. Readback only classifies and applies existing facts. Captured-save retry writes the already encoded bytes and records. First-submission recovery may perform the terminal validation and encoding that has never been admitted, but it must not repeat provider, Tool or other business work.
|
|
41
|
+
|
|
42
|
+
For example, `retry_terminal` still returns unavailable when no complete proposal exists. It does not silently call the new submission operation. Conversely, once a submission was accepted and failed during validation or encoding, this new method cannot restart it merely because no complete proof was produced.
|
|
43
|
+
|
|
44
|
+
| Operation | May run validation/encoding? | May write? | Required authority |
|
|
45
|
+
| --- | --- | --- | --- |
|
|
46
|
+
| `reconcile_terminal[_async]` | No | No | Retained complete proof or conclusive original worker result. |
|
|
47
|
+
| `retry_terminal[_async]` | No | Exact captured bytes and records only | Full guarded pre-state comparison, or recognize an already committed post-state. |
|
|
48
|
+
| `retry_terminal_submission[_async]` | First run only | First terminal save | Positive mechanism rejection proof with no admitted handle or observed worker entry. |
|
|
49
|
+
|
|
50
|
+
If a newly admitted submission later produces complete proof but loses its result, the existing readback/save-retry operations can handle that proof. It does not regain first-submission permission. A failure after admission but before full capture remains retained and unavailable for this first-submission operation. This stage intentionally does not add general encoder retry.
|
|
51
|
+
|
|
52
|
+
## Keep normal application behavior unchanged
|
|
53
|
+
|
|
54
|
+
The added operation does not require normal callers to change their code. Normal compatibility is evaluated with the same inputs, adapter, public invocation, saved-result observation and cleanup in both checkouts. Fault recovery is a separate intentional behavior change.
|
|
55
|
+
|
|
56
|
+
For example, a deterministic local provider returns the structured answer `ordinary answer` once. The complete function below invokes and observes it identically before and after the change; measurement records output, transcript, revisions, journal shape and physical completion.
|
|
57
|
+
|
|
58
|
+
<table>
|
|
59
|
+
<thead><tr><th>G3b-2 baseline</th><th>G3b-3 candidate</th></tr></thead>
|
|
60
|
+
<tbody><tr><td><pre lang="ruby">def run_normal_application(persistence:)
|
|
61
|
+
agent = G3NormalApplicationAgent.create(agent_id: "g3-normal-agent", persistence: persistence)
|
|
62
|
+
source_task = agent.invoke_async("ordinary question", output_schema: {
|
|
63
|
+
type: "object", properties: {answer: {type: "string"}},
|
|
64
|
+
required: ["answer"], additionalProperties: false
|
|
65
|
+
})
|
|
66
|
+
source_result = source_task.wait_result(timeout: 5)
|
|
67
|
+
observed_result = agent.resume(source_result.fetch(:execution_id))
|
|
68
|
+
[agent, source_task, source_result, observed_result]
|
|
69
|
+
end</pre></td><td><pre lang="ruby">def run_normal_application(persistence:)
|
|
70
|
+
agent = G3NormalApplicationAgent.create(agent_id: "g3-normal-agent", persistence: persistence)
|
|
71
|
+
source_task = agent.invoke_async("ordinary question", output_schema: {
|
|
72
|
+
type: "object", properties: {answer: {type: "string"}},
|
|
73
|
+
required: ["answer"], additionalProperties: false
|
|
74
|
+
})
|
|
75
|
+
source_result = source_task.wait_result(timeout: 5)
|
|
76
|
+
observed_result = agent.resume(source_result.fetch(:execution_id))
|
|
77
|
+
[agent, source_task, source_result, observed_result]
|
|
78
|
+
end</pre></td></tr></tbody>
|
|
79
|
+
</table>
|
|
80
|
+
|
|
81
|
+
The following shared setup precedes either function. It defines the Agent and deterministic adapter and installs no private recovery hook.
|
|
82
|
+
|
|
83
|
+
For example, changing only the framework checkout with this same setup avoids confounding normal compatibility with a different provider or application policy.
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
# frozen_string_literal: true
|
|
87
|
+
|
|
88
|
+
# Run from the repository root with its bundled dependencies. This deterministic
|
|
89
|
+
# fixture adapter performs no network request. The application operation uses
|
|
90
|
+
# public Agent APIs without installing any private capture or recovery hook.
|
|
91
|
+
# The separate measurement helper reads private persistence records solely as
|
|
92
|
+
# test evidence; production capture behavior is whatever the tested version provides.
|
|
93
|
+
require "phronomy"
|
|
94
|
+
require "json"
|
|
95
|
+
|
|
96
|
+
class G3NormalFixtureAdapter < Phronomy::LLMAdapter::Base
|
|
97
|
+
attr_reader :request_count
|
|
98
|
+
|
|
99
|
+
def initialize
|
|
100
|
+
@request_count = 0
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def perform_complete(_request, cancellation_token:)
|
|
104
|
+
cancellation_token&.raise_if_cancelled!
|
|
105
|
+
@request_count += 1
|
|
106
|
+
Phronomy::LLMAdapter::Response.new(
|
|
107
|
+
content: '{"answer":"ordinary answer"}', finish_reason: :stop,
|
|
108
|
+
usage: Phronomy::LLMAdapter::TokenUsage.new(input: 4, output: 2)
|
|
109
|
+
)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class G3NormalApplicationAgent < Phronomy::Agent::Base
|
|
114
|
+
agent_definition id: "g3-normal-behavior", version: 1
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The shared measurement and driver below follow either function. They read private persistence records only as test evidence and shut down the normal-path Runtime after reporting. They are not hidden recovery policy.
|
|
119
|
+
|
|
120
|
+
For example, the functional report omits random IDs and timestamps while retaining exact provider count and execution/journal revisions. Set `G3_NORMAL_REPORT` to the report path and execute with the checkout's bundled dependencies.
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
def functional_observation(agent:, source_task:, source_result:, observed_result:, adapter:)
|
|
124
|
+
store = agent.persistence
|
|
125
|
+
execution = store.executions.load(source_result.fetch(:execution_id))
|
|
126
|
+
journal = store.journals.read(agent.agent_id, after: 0)
|
|
127
|
+
{
|
|
128
|
+
result: source_result.slice(:output, :raw_output, :agent_revision, :context_revision, :journal_position)
|
|
129
|
+
.merge(usage: source_result.fetch(:usage).to_h),
|
|
130
|
+
transcript: source_result.fetch(:messages).map(&:to_h),
|
|
131
|
+
durable_status: execution.status,
|
|
132
|
+
durable_phase: execution.phase,
|
|
133
|
+
durable_revision: execution.execution_revision,
|
|
134
|
+
durable_result: store.contents.fetch_text(execution.result_ref),
|
|
135
|
+
durable_raw_output: store.contents.fetch_text(execution.metadata.fetch("raw_output_ref")),
|
|
136
|
+
journal: journal.map { |record| record.to_h.slice("kind", "channel", "role", "sequence", "context_candidate") },
|
|
137
|
+
stored_llm_calls: execution.llm_calls.size,
|
|
138
|
+
live_root_status: agent.agent_root.lifecycle_status,
|
|
139
|
+
source_done: source_task.done?,
|
|
140
|
+
source_physical_complete: source_task.physical_complete?,
|
|
141
|
+
provider_calls: adapter.request_count,
|
|
142
|
+
resumed_output: observed_result.fetch(:output)
|
|
143
|
+
}
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
if $PROGRAM_NAME == __FILE__
|
|
147
|
+
begin
|
|
148
|
+
adapter = G3NormalFixtureAdapter.new
|
|
149
|
+
Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
|
|
150
|
+
agent, source_task, source_result, observed_result =
|
|
151
|
+
run_normal_application(persistence: Phronomy::PersistenceComposition.in_memory.agent)
|
|
152
|
+
raise "Unexpected output" unless source_result.fetch(:output) == {"answer" => "ordinary answer"}
|
|
153
|
+
raise "Resume changed the output" unless observed_result.fetch(:output) == source_result.fetch(:output)
|
|
154
|
+
raise "Provider was replayed" unless adapter.request_count == 1
|
|
155
|
+
observation = functional_observation(agent: agent, source_task: source_task,
|
|
156
|
+
source_result: source_result, observed_result: observed_result, adapter: adapter)
|
|
157
|
+
File.write(ENV.fetch("G3_NORMAL_REPORT"), JSON.pretty_generate(observation) + "\n")
|
|
158
|
+
ensure
|
|
159
|
+
Phronomy.reset_runtime!
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The unchanged complete source was executed against the applied baseline and the candidate. Its normalized functional JSON matched exactly, including one provider call and logical/physical source completion. The source, reports and checkout provenance are included in the delivery evidence; the comparison covers this deterministic local normal path.
|
|
166
|
+
|
|
167
|
+
## Add explicit application permission for rejected submission
|
|
168
|
+
|
|
169
|
+
An application can authorize first submission separately from a captured save retry and retain unresolved responsibility when either request cannot proceed. Phronomy prevents duplicate terminal workers and business replay; it does not choose an application's retry schedule or escalation policy.
|
|
170
|
+
|
|
171
|
+
For example, the baseline function below can observe or save captured records but cannot recover a positively rejected terminal submission. The new function adds a separate `retry_submission` permission, checks the immutable admission fact, and makes at most one new submission request. The existing `retry_save` permission retains its distinct meaning.
|
|
172
|
+
|
|
173
|
+
<table>
|
|
174
|
+
<thead><tr><th>G3b-2: captured-save recovery</th><th>G3b-3: explicit submission permission</th></tr></thead>
|
|
175
|
+
<tbody><tr><td><pre lang="ruby"># frozen_string_literal: true
|
|
176
|
+
|
|
177
|
+
require "phronomy"
|
|
178
|
+
|
|
179
|
+
# The caller owns this Agent and its Runtime, and explicitly chooses whether a
|
|
180
|
+
# confirmed pre-state may be saved again. No provider or Tool is started here
|
|
181
|
+
# after the initial invocation. Pending recovery is returned to that owner.
|
|
182
|
+
def run_recoverable_request(agent:, input:, retry_save: false)
|
|
183
|
+
result = agent.invoke(input)
|
|
184
|
+
{state: :completed, result: result}.freeze
|
|
185
|
+
rescue Phronomy::Agent::TerminalRecoveryError => failure
|
|
186
|
+
recovery = failure.recovery
|
|
187
|
+
receipt = agent.reconcile_terminal(recovery: recovery)
|
|
188
|
+
if retry_save && receipt.outcome == :confirmed_pre
|
|
189
|
+
receipt = agent.retry_terminal(recovery: recovery)
|
|
190
|
+
end
|
|
191
|
+
if receipt.outcome == :confirmed_post && receipt.application_state == :applied &&
|
|
192
|
+
receipt.ownership_state == :released && receipt.execution
|
|
193
|
+
{state: :observed, execution: receipt.execution.to_result,
|
|
194
|
+
recovery: recovery, receipt: receipt}.freeze
|
|
195
|
+
else
|
|
196
|
+
{state: :recovery_pending, recovery: recovery, receipt: receipt}.freeze
|
|
197
|
+
end
|
|
198
|
+
end</pre></td><td><pre lang="ruby"># frozen_string_literal: true
|
|
199
|
+
|
|
200
|
+
require "phronomy"
|
|
201
|
+
|
|
202
|
+
# The caller owns the Agent and Runtime. Each permission authorizes a different
|
|
203
|
+
# bounded operation: first terminal-work submission or captured-byte save retry.
|
|
204
|
+
# Pending responsibility and its newest receipt are returned to that caller.
|
|
205
|
+
def run_submission_recoverable_request(agent:, input:, retry_submission: false, retry_save: false)
|
|
206
|
+
result = agent.invoke(input)
|
|
207
|
+
{state: :completed, result: result}.freeze
|
|
208
|
+
rescue Phronomy::Agent::TerminalRecoveryError => failure
|
|
209
|
+
recovery = failure.recovery
|
|
210
|
+
receipt = agent.reconcile_terminal(recovery: recovery)
|
|
211
|
+
if retry_submission && receipt.submission_state == :not_admitted
|
|
212
|
+
receipt = agent.retry_terminal_submission(recovery: recovery)
|
|
213
|
+
end
|
|
214
|
+
if retry_save && receipt.outcome == :confirmed_pre
|
|
215
|
+
receipt = agent.retry_terminal(recovery: recovery)
|
|
216
|
+
end
|
|
217
|
+
if receipt.outcome == :confirmed_post && receipt.application_state == :applied &&
|
|
218
|
+
receipt.ownership_state == :released && receipt.execution
|
|
219
|
+
{state: :observed, execution: receipt.execution.to_result,
|
|
220
|
+
recovery: recovery, receipt: receipt}.freeze
|
|
221
|
+
else
|
|
222
|
+
{state: :recovery_pending, recovery: recovery, receipt: receipt}.freeze
|
|
223
|
+
end
|
|
224
|
+
end</pre></td></tr></tbody>
|
|
225
|
+
</table>
|
|
226
|
+
|
|
227
|
+
These complete functions require an already created Agent and a host thread; the caller owns the Agent and Runtime. Their names identify the old recovery helper and the extended helper. Both permissions default to false. The new branch intentionally changes only recovery behavior for positive non-admission, so this is not an equivalence claim for that fault.
|
|
228
|
+
|
|
229
|
+
The helper returns `recovery_pending` with the capability and newest receipt when unresolved. It does not loop, create another Runtime, unload a busy Agent or label a saved failed/cancelled job as successful. A recovered `observed` result is a durable execution observation whose status the application must inspect. Subsequent uncertain saves may require a later explicit readback; the helper does not hide that extra decision.
|
|
230
|
+
|
|
231
|
+
Applications no longer need to inspect error strings or reach into private submission machinery. They still choose whether first validation/encoding and saving are permitted, whether captured bytes may be saved again, and how to keep or escalate unresolved responsibility.
|
|
232
|
+
|
|
233
|
+
## Serialize authority and observations
|
|
234
|
+
|
|
235
|
+
The original retained operation owns the one physical lane and admission decision. Fresh observation requests may join an accepted same-kind attempt, but they cannot create another submission. Cancellation of an observer does not revoke admitted work or restore consumed permission.
|
|
236
|
+
|
|
237
|
+
For example, two simultaneous first-submission requests after a queue rejection share one admitted terminal worker. If one observer cancels, the other still receives its receipt. A concurrent readback or captured-write retry does not change the submission's kind and cannot start another physical attempt.
|
|
238
|
+
|
|
239
|
+
Late or duplicate signals must identify their exact physical attempt. A stale signal from the rejected initial attempt cannot mark a later admitted worker complete, misclassify its result or release its owner. A rejected resubmission can reestablish `not_admitted`; any accepted handle remains consumed even if its block never enters. Repeated resolved requests return only the retained receipt.
|
|
240
|
+
|
|
241
|
+
Admission remains local to the original running or draining Runtime. Stopped-owner transfer and process-crash recovery remain outside scope. Shutdown cannot report complete cleanup while accepted physical work or unresolved responsibility remains.
|
|
242
|
+
|
|
243
|
+
## Keep mechanism proof and persistence authority separate
|
|
244
|
+
|
|
245
|
+
The mechanism's non-admission proof is a narrow statement that no submitted block can execute. Persistence still owns transaction and guard semantics, and the Agent owns its terminal command, result interpretation and release decision. Rejection notification does not authorize a backend read/write or classify a saved job.
|
|
246
|
+
|
|
247
|
+
For example, a supported execution backend emits its rejection callback only on a path where enqueue failed and no accepted task exists. A custom backend that cannot supply that guarantee leaves the operation unknown. Once a first save runs, its later reconciliation still requires settled backend transactions and authoritative read ordering; worker completion alone does not prove those remote facts.
|
|
248
|
+
|
|
249
|
+
No new manager or second responsibility registry is introduced. The existing Agent terminal operation stores the admission fact and physical attempt; the existing execution mechanism provides the proof. Workflow's confirmed-pre release policy and Agent's retained-active-job policy stay separate. The optional mechanism capability is needed only for positive rejection proof. A custom submitter opts in with `supports_submission_rejection? == true` and a `submit` method accepting `on_rejected:`; the callback must truthfully report synchronous refusal before any accepted work exists. A legacy custom backend with a fixed-keyword `submit` can still run ordinary work; the binding must not pass an unsupported rejection keyword or retry a failed call to discover support. A failure without that capability remains unknown. This preserves the covered ordinary-call contract, not a claim of compatibility with every custom backend.
|
|
250
|
+
|
|
251
|
+
## Verify the bounded extension
|
|
252
|
+
|
|
253
|
+
Acceptance must distinguish rejection before admission from accepted-but-queued work and failure after entry. It must also show that existing byte-only retry and original-owner release remain unchanged. Models and tests cover their explicit premises, not arbitrary backend implementations.
|
|
254
|
+
|
|
255
|
+
For example, a test should inject the same exception both with and without a valid rejection callback. Only the positively proven case may start the first terminal worker later; the other must remain unavailable without validation or encoding.
|
|
256
|
+
|
|
257
|
+
Required scenarios include normal compatibility, original observer failure with retained custody, first known rejection, unknown rejection, contradictory callback/start or callback/handle facts, repeated mechanism rejection, queued acceptance followed by cancellation/timeout, same-kind observer joining, mixed-kind refusal, stale notifications, commit/reply loss after first submission, failure before full capture after admission, closed-listener preservation, and incomplete shutdown. Provider/Tool counters must remain unchanged; validation/encoding counters can advance only for the first admitted terminal work.
|
|
258
|
+
|
|
259
|
+
The public snapshot adds two Agent methods, their inherited Orchestrator methods and one result reader. No existing method is removed. RBS, annotations, complete changed-file English checks, both canonical Contract diagrams, source dependencies, model results and actual bundle application remain delivery checks. The final validation report records actual counts and limits; no external database/LLM or distributed recovery acceptance is implied.
|
|
260
|
+
|
|
261
|
+
The exact source functions displayed above were also executed through nine tagged application examples, all passing. The fixture calls the real Runtime and persistence implementation. For rejected submission, it saturates the real OffloadPool, then releases capacity before the application decides whether to submit again. No new recovery API is mocked.
|
|
262
|
+
|
|
263
|
+
| Executed application case | Observed result |
|
|
264
|
+
| --- | --- |
|
|
265
|
+
| Unchanged complete normal function | Baseline/candidate functional JSON equal; one provider call and physical completion. |
|
|
266
|
+
| Recovery helper without a fault | Ordinary result and one normal completion event. |
|
|
267
|
+
| Committed save with lost reply | Confirmed post-state, application/release complete, no old completion event replay. |
|
|
268
|
+
| Rolled-back save without save permission | Confirmed pre-state, active job and responsibility retained. |
|
|
269
|
+
| Rolled-back save with explicit save permission | Captured save completes; provider remains called once. |
|
|
270
|
+
| Saved failed job | Recovery succeeds while the saved execution remains failed. |
|
|
271
|
+
| Proven rejected terminal submission with permission | First terminal worker runs once; two original provider calls and one Tool call are not replayed. |
|
|
272
|
+
| Proven rejection without permission | Not admitted; no terminal committer or encoder runs; responsibility remains retained. |
|
|
273
|
+
| Custom wrapper loses an admitted handle | Admission remains unknown while queued; no second worker is submitted despite application permission. |
|
|
274
|
+
|
|
275
|
+
These application examples complement the acceptance tests and model checks. They do not establish support for arbitrary providers, remote storage transactions, crash recovery or every possible application policy.
|
|
@@ -23,6 +23,35 @@ used merely to wait for the child or its release. The existing Agent release can
|
|
|
23
23
|
perform its ordinary asynchronous persistence checks. Records are not purged,
|
|
24
24
|
and unrelated Agents or shared stores are not shut down.
|
|
25
25
|
|
|
26
|
+
## Child invocation context
|
|
27
|
+
|
|
28
|
+
A private child shares the caller's application context and operation controls,
|
|
29
|
+
but starts its own Agent execution. The Tool separates those inputs at the
|
|
30
|
+
fresh-child boundary; ordinary Tool dispatch continues to receive its owner's
|
|
31
|
+
invocation context.
|
|
32
|
+
|
|
33
|
+
For example, a reserved Team worker can call an Agent Tool without giving the
|
|
34
|
+
private child the worker's reservation or completion observers. Cancelling the
|
|
35
|
+
shared operation still reaches the child, while the Team observes only its own
|
|
36
|
+
reserved worker and the private child obtains a distinct execution ID.
|
|
37
|
+
|
|
38
|
+
| Input | Fresh private child |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| Application keys, including `durable_context`, `approval_context` and `user_id` | Forward unchanged; child validation still applies |
|
|
41
|
+
| `invocation_context` and `cancellation_token` | Preserve the existing context, scope, deadline and cancellation behavior |
|
|
42
|
+
| Existing `phronomy_timeout_deadline` guard | Preserve the same deadline object; do not restart its budget |
|
|
43
|
+
| Parent `execution_id` and other `phronomy_*` runtime bindings | Do not forward; the child builds its own execution wiring |
|
|
44
|
+
|
|
45
|
+
The reserved runtime namespace includes admission participants, reservations,
|
|
46
|
+
exact-result observers, Handoff controls, runtime projections and output
|
|
47
|
+
contracts. Symbol and String names follow the same filtering rule without
|
|
48
|
+
normalizing or modifying the caller's Hash. Application code should use public
|
|
49
|
+
invocation controls rather than supply these private runtime bindings.
|
|
50
|
+
|
|
51
|
+
This does not make an Agent Tool child a registered durable subagent or add
|
|
52
|
+
cross-process recovery for a private approval wait. The existing private-child
|
|
53
|
+
approval and release contracts below continue to apply.
|
|
54
|
+
|
|
26
55
|
## Graceful Runtime shutdown
|
|
27
56
|
|
|
28
57
|
An accepted private child's final release is part of its existing Agent
|