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,360 @@
|
|
|
1
|
+
# Agent terminal persistence evidence: private preparation stage
|
|
2
|
+
|
|
3
|
+
Agent terminal persistence needs to preserve what it intended to save before an
|
|
4
|
+
ambiguous transaction result can discard that proposal. This stage adds a private
|
|
5
|
+
value-based persistence path; it does not connect recovery to the original live
|
|
6
|
+
Agent owner. The default `ExecutionCoordinator` remains unchanged, and no public
|
|
7
|
+
Agent recovery API or shutdown correction is provided by this stage.
|
|
8
|
+
|
|
9
|
+
For example, an Agent can finish a provider request, prepare its terminal records,
|
|
10
|
+
and lose both the transaction response and the first authoritative read. A future
|
|
11
|
+
recovery owner needs that exact proposal to distinguish a committed result from a
|
|
12
|
+
rolled-back write. Re-running the provider or parsing its output again would
|
|
13
|
+
produce a new computation rather than establish the original persistence fact.
|
|
14
|
+
|
|
15
|
+
The implementation baseline is G2 commit
|
|
16
|
+
`802176d2afacf3d28f8ca03468ca970729ae8660`; the working branch is
|
|
17
|
+
`fix/agent-terminal-evidence`. G2's implemented
|
|
18
|
+
[Workflow terminal reconciliation](workflow-terminal-reconciliation.md) remains
|
|
19
|
+
a separate, domain-specific recovery contract. This document describes G3b-1,
|
|
20
|
+
not completion of G3b, G3, or the full lifecycle redesign.
|
|
21
|
+
|
|
22
|
+
## Responsibility and the retained proposal
|
|
23
|
+
|
|
24
|
+
The persistence helper preserves a completed proposal and classifies repository
|
|
25
|
+
evidence. A caller owns the lifetime of that value and any decision to use it.
|
|
26
|
+
Only the Agent execution owner can eventually apply a confirmed result to live
|
|
27
|
+
state, settle the original operation, and release its admission. Neither a
|
|
28
|
+
persistence classification nor the helper's return value grants that authority.
|
|
29
|
+
|
|
30
|
+
For example, a confirmed pre-state leaves the durable execution active. A helper
|
|
31
|
+
can prepare to persist the already-computed terminal outcome, but it cannot
|
|
32
|
+
declare that accepted job finished merely because the first write rolled back.
|
|
33
|
+
This differs from Workflow's existing known-terminal-save-failure disposition.
|
|
34
|
+
|
|
35
|
+
| Responsibility | This private stage | Still outside this stage |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| Capture | Complete eligible standalone terminal evidence, semantic Outcome, and referenced content bytes | A production owner that retains the evidence after the worker returns |
|
|
38
|
+
| Readback | Compare the retained proposal with an authoritative repository snapshot under the required guards | Live Agent state updates or original observer settlement |
|
|
39
|
+
| Save-only retry | Persist the retained proposal only when the exact pre-state still matches | Provider, Tool, parser, graph, or arbitrary business retries |
|
|
40
|
+
| Ownership | Preserve Agent's existing authority boundary | Admission release, original operation acknowledgement, or Runtime custody transfer |
|
|
41
|
+
| Public observation | Existing Agent methods remain in place | Recovery capability, pending lookup, independent recovery observers, or a new public result type |
|
|
42
|
+
|
|
43
|
+
`ExecutionChange` remains a single-use, thread-bound transaction operation. The
|
|
44
|
+
retained value must not keep its executable write closure, Agent, participant, or
|
|
45
|
+
original scope as a retry mechanism. A fresh permitted persistence operation
|
|
46
|
+
consumes the captured facts instead.
|
|
47
|
+
|
|
48
|
+
## Complete evidence includes content bytes
|
|
49
|
+
|
|
50
|
+
Evidence must describe every fact that the transaction can change or that guards
|
|
51
|
+
the proposed terminal transition. It must also retain the content necessary to
|
|
52
|
+
write that same proposal after rollback. Record references alone do not preserve
|
|
53
|
+
bytes whose insertion belonged to the rolled-back transaction.
|
|
54
|
+
|
|
55
|
+
For example, a structured result can create an output content object and a raw
|
|
56
|
+
provider-output object before saving execution and journal records that refer to
|
|
57
|
+
them. If the outer transaction rolls back, those new objects can disappear too.
|
|
58
|
+
Keeping the intended `result_ref` without its bytes cannot reconstruct the same
|
|
59
|
+
terminal save; calling the parser or provider again would change the operation.
|
|
60
|
+
|
|
61
|
+
| Evidence category | Why it is required |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| Agent root and execution | Check exact identities, revisions, lifecycle state, terminal fields, and referenced metadata |
|
|
64
|
+
| Journal suffix | Preserve exact record identities, sequence, payload references, and expected stream position |
|
|
65
|
+
| Extension and cancellation state | Reject a changed obligation even when root or execution revisions appear unchanged |
|
|
66
|
+
| Semantic Outcome | Preserve the already-computed result or failure for later owner application |
|
|
67
|
+
| Referenced content bytes | Recreate transaction-local content lost in rollback without recomputing output or runtime records |
|
|
68
|
+
| Detached error diagnostic | Preserve terminal failure meaning without retaining an arbitrary exception that may reference a live Agent |
|
|
69
|
+
|
|
70
|
+
The eligible scope is already-installed, active standalone terminal completion,
|
|
71
|
+
failure, or cancellation. Approval suspension, dispatch, preparation, participant-owned
|
|
72
|
+
transactions, extension-bound execution, and responsibility transfer need their
|
|
73
|
+
own evidence and ownership contracts. They must not silently enter this path.
|
|
74
|
+
|
|
75
|
+
## Private persistence operations
|
|
76
|
+
|
|
77
|
+
A caller may opt into evidence capture without changing the ordinary Agent
|
|
78
|
+
execution route. Capture, later classification, and a guarded save-only retry
|
|
79
|
+
are separate operations. No helper schedules retries or assumes ownership of the
|
|
80
|
+
original execution merely because the callback retained a value.
|
|
81
|
+
|
|
82
|
+
For example, a private test harness can retain an eligible proposal through
|
|
83
|
+
`on_evidence`, observe a transaction failure, and later read the same proposal.
|
|
84
|
+
The default coordinator supplies no such callback, so an ordinary application
|
|
85
|
+
does not gain this recovery behavior just by upgrading to this stage.
|
|
86
|
+
|
|
87
|
+
| Private operation | Contract |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| `ExecutionOutcomeCommitter#commit_outcome(operation, on_evidence: nil)` | The default path captures no evidence. An eligible opt-in call gives its callback a complete value after the original perform/readback path finishes, including a complete proposal from a rolled-back attempt. |
|
|
90
|
+
| `TerminalPersistenceEvidence#reconcile(persistence:, original_error: nil)` | Reads and classifies the complete retained proof under the original Store's coordinator and Agent guard. It performs no writes or live owner application. |
|
|
91
|
+
| `TerminalPersistenceEvidence#retry(persistence:, original_error: nil)` | Rechecks the complete proof in a fresh outer transaction. It writes the retained content and records only for an exact pre-state; an already committed state causes no duplicate write. Conflicting state is refused. |
|
|
92
|
+
|
|
93
|
+
The frozen evidence exposes `before`, `after`, `outcome`, `content_writes`,
|
|
94
|
+
`attempt_id`, `agent_id`, and `execution_id`. Each captured content write has its
|
|
95
|
+
reference, bytes, and canonicalization version. The detached Outcome preserves
|
|
96
|
+
its type, root, execution, appended records, result, and `error_diagnostic`;
|
|
97
|
+
it does not retain the arbitrary terminal exception itself as live wiring.
|
|
98
|
+
The ordinary committer's existing Outcome and exception behavior remain separate.
|
|
99
|
+
|
|
100
|
+
Read and retry results expose `disposition` (`committed`, `not_committed`, or
|
|
101
|
+
`unknown`), `evidence`, `original_error`, and `read_error`. The original error is
|
|
102
|
+
supplied by the private caller, while a failed retry can supply that attempt's
|
|
103
|
+
error. An unavailable read and conflicting evidence both remain unknown; this is
|
|
104
|
+
not Workflow's public four-outcome result type. The evidence ID identifies the
|
|
105
|
+
captured proposal, not a managed registry entry or a new physical-attempt lane.
|
|
106
|
+
|
|
107
|
+
These are private signatures, not additions to the Stable/Beta public API
|
|
108
|
+
inventory. A private identity rejects a different Store before repository I/O,
|
|
109
|
+
even if its records have equal values. The caller must retain the evidence,
|
|
110
|
+
preserve any original error it needs, and satisfy prior-attempt settlement
|
|
111
|
+
conditions. Applications must not treat these helpers as a supported recovery
|
|
112
|
+
surface. Capture after the original worker path is not the future protocol that
|
|
113
|
+
retains custody before publishing uncertainty.
|
|
114
|
+
|
|
115
|
+
The collector runs synchronously and must retain the value before returning.
|
|
116
|
+
On an original persistence failure, a collector failure must not replace that
|
|
117
|
+
original failure. After a successful commit, collector failure propagates and
|
|
118
|
+
does not mean the commit rolled back. Neither case establishes that a production
|
|
119
|
+
owner has accepted custody; no default coordinator collector exists yet.
|
|
120
|
+
|
|
121
|
+
## Transaction and backend prerequisites
|
|
122
|
+
|
|
123
|
+
Classifying an original write as absent requires settled write semantics and an
|
|
124
|
+
authoritative read ordered after that settlement. Applying a retained proposal
|
|
125
|
+
requires a fresh outermost atomic scope with the same ordered Agent guards,
|
|
126
|
+
revision/CAS checks, and complete evidence comparison. A savepoint or local
|
|
127
|
+
worker return alone cannot establish these conditions.
|
|
128
|
+
|
|
129
|
+
For example, a remote database request can return a transport error while the
|
|
130
|
+
server still has a commit in flight. Even if the Ruby worker has exited and a
|
|
131
|
+
replica shows the old revision, a second write is not authorized. The adapter
|
|
132
|
+
must establish original-write settlement and the required authoritative ordering
|
|
133
|
+
before this helper's pre-state classification can be relied on.
|
|
134
|
+
|
|
135
|
+
Cancellation is part of the compared facts. If cancellation was recorded after
|
|
136
|
+
the proposal was captured, a later retry must refuse the changed pre-state rather
|
|
137
|
+
than persist an obsolete successful outcome. The helper does not reinterpret
|
|
138
|
+
that conflict as permission to release the Agent or manufacture a replacement
|
|
139
|
+
cancellation outcome.
|
|
140
|
+
|
|
141
|
+
The journal's actual head must also match the root's declared position. Extra
|
|
142
|
+
records beyond an otherwise matching captured suffix are conflicting evidence,
|
|
143
|
+
not permission to classify the proposal as committed or retry it.
|
|
144
|
+
|
|
145
|
+
Nested transaction use is rejected for the retained-evidence path. Successful
|
|
146
|
+
save-only retry must mean outermost commit, not temporary savepoint success.
|
|
147
|
+
An ambiguous retry result is classified from the same retained pre/post proof;
|
|
148
|
+
there is no automatic retry loop. Unsupported backend ordering remains outside
|
|
149
|
+
the guarantee, even if that adapter implements the repository method names.
|
|
150
|
+
|
|
151
|
+
## Public application comparison
|
|
152
|
+
|
|
153
|
+
Applications continue to use the existing invocation and observation methods.
|
|
154
|
+
The normal result shape, error handling, and ownership of application cleanup do
|
|
155
|
+
not become simpler in this private stage. The potential benefit is a future
|
|
156
|
+
same-owner recovery path that avoids replaying completed computation; that path
|
|
157
|
+
has not yet been connected.
|
|
158
|
+
|
|
159
|
+
For example, a service that invokes an Agent for a structured answer still calls
|
|
160
|
+
the same public method and reads the same result. Resuming a durable completed
|
|
161
|
+
execution remains a separate observation; it does not prove that the original
|
|
162
|
+
live owner has applied the result or released its admission.
|
|
163
|
+
|
|
164
|
+
The complete application function is identical before and after this private
|
|
165
|
+
stage. Both sides use the same configured fixture Agent, input, output schema,
|
|
166
|
+
timeout, and persistence. It retains the original task as well as the separate
|
|
167
|
+
resume observation. This is a normal-path comparison, not evidence that an
|
|
168
|
+
ambiguous terminal save can now recover its original live owner.
|
|
169
|
+
|
|
170
|
+
<table>
|
|
171
|
+
<thead><tr><th>Baseline public operation</th><th>Operation after G3b-1</th></tr></thead>
|
|
172
|
+
<tbody><tr><td><pre><code>def run_normal_application(persistence:)
|
|
173
|
+
agent = G3NormalApplicationAgent.create(agent_id: "g3-normal-agent", persistence: persistence)
|
|
174
|
+
source_task = agent.invoke_async("ordinary question", output_schema: {
|
|
175
|
+
type: "object", properties: {answer: {type: "string"}},
|
|
176
|
+
required: ["answer"], additionalProperties: false
|
|
177
|
+
})
|
|
178
|
+
source_result = source_task.wait_result(timeout: 5)
|
|
179
|
+
observed_result = agent.resume(source_result.fetch(:execution_id))
|
|
180
|
+
[agent, source_task, source_result, observed_result]
|
|
181
|
+
end
|
|
182
|
+
</code></pre></td><td><pre><code>def run_normal_application(persistence:)
|
|
183
|
+
agent = G3NormalApplicationAgent.create(agent_id: "g3-normal-agent", persistence: persistence)
|
|
184
|
+
source_task = agent.invoke_async("ordinary question", output_schema: {
|
|
185
|
+
type: "object", properties: {answer: {type: "string"}},
|
|
186
|
+
required: ["answer"], additionalProperties: false
|
|
187
|
+
})
|
|
188
|
+
source_result = source_task.wait_result(timeout: 5)
|
|
189
|
+
observed_result = agent.resume(source_result.fetch(:execution_id))
|
|
190
|
+
[agent, source_task, source_result, observed_result]
|
|
191
|
+
end
|
|
192
|
+
</code></pre></td></tr></tbody>
|
|
193
|
+
</table>
|
|
194
|
+
|
|
195
|
+
The following complete shared source supplies the deterministic adapter, Agent
|
|
196
|
+
class, dependencies, invocation, assertions, and Runtime cleanup. The
|
|
197
|
+
`functional_observation` helper reads private persistence/live-state records
|
|
198
|
+
solely to measure the comparison; it is not public application guidance or a
|
|
199
|
+
recovery API. Run it with the repository's bundle and `-Ilib`, and set
|
|
200
|
+
`G3_NORMAL_REPORT` to an output JSON path. Each comparison run uses a fresh
|
|
201
|
+
in-memory store and process. No sample installs the private evidence callback.
|
|
202
|
+
|
|
203
|
+
<details>
|
|
204
|
+
<summary>Complete shared setup, application function, measurement, and cleanup</summary>
|
|
205
|
+
|
|
206
|
+
```ruby
|
|
207
|
+
# frozen_string_literal: true
|
|
208
|
+
|
|
209
|
+
# Run from the repository root with its bundled dependencies. This deterministic
|
|
210
|
+
# fixture adapter performs no network request. The application operation uses
|
|
211
|
+
# public Agent APIs; G3b's private evidence callback is not installed. The separate
|
|
212
|
+
# measurement helper reads private persistence records solely as test evidence.
|
|
213
|
+
require "phronomy"
|
|
214
|
+
require "json"
|
|
215
|
+
|
|
216
|
+
class G3NormalFixtureAdapter < Phronomy::LLMAdapter::Base
|
|
217
|
+
attr_reader :request_count
|
|
218
|
+
|
|
219
|
+
def initialize
|
|
220
|
+
@request_count = 0
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def perform_complete(_request, cancellation_token:)
|
|
224
|
+
cancellation_token&.raise_if_cancelled!
|
|
225
|
+
@request_count += 1
|
|
226
|
+
Phronomy::LLMAdapter::Response.new(
|
|
227
|
+
content: '{"answer":"ordinary answer"}', finish_reason: :stop,
|
|
228
|
+
usage: Phronomy::LLMAdapter::TokenUsage.new(input: 4, output: 2)
|
|
229
|
+
)
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
class G3NormalApplicationAgent < Phronomy::Agent::Base
|
|
234
|
+
agent_definition id: "g3-normal-behavior", version: 1
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def run_normal_application(persistence:)
|
|
238
|
+
agent = G3NormalApplicationAgent.create(agent_id: "g3-normal-agent", persistence: persistence)
|
|
239
|
+
source_task = agent.invoke_async("ordinary question", output_schema: {
|
|
240
|
+
type: "object", properties: {answer: {type: "string"}},
|
|
241
|
+
required: ["answer"], additionalProperties: false
|
|
242
|
+
})
|
|
243
|
+
source_result = source_task.wait_result(timeout: 5)
|
|
244
|
+
observed_result = agent.resume(source_result.fetch(:execution_id))
|
|
245
|
+
[agent, source_task, source_result, observed_result]
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def functional_observation(agent:, source_task:, source_result:, observed_result:, adapter:)
|
|
249
|
+
store = agent.persistence
|
|
250
|
+
execution = store.executions.load(source_result.fetch(:execution_id))
|
|
251
|
+
journal = store.journals.read(agent.agent_id, after: 0)
|
|
252
|
+
{
|
|
253
|
+
result: source_result.slice(:output, :raw_output, :agent_revision, :context_revision, :journal_position)
|
|
254
|
+
.merge(usage: source_result.fetch(:usage).to_h),
|
|
255
|
+
transcript: source_result.fetch(:messages).map(&:to_h),
|
|
256
|
+
durable_status: execution.status,
|
|
257
|
+
durable_phase: execution.phase,
|
|
258
|
+
durable_revision: execution.execution_revision,
|
|
259
|
+
durable_result: store.contents.fetch_text(execution.result_ref),
|
|
260
|
+
durable_raw_output: store.contents.fetch_text(execution.metadata.fetch("raw_output_ref")),
|
|
261
|
+
journal: journal.map { |record| record.to_h.slice("kind", "channel", "role", "sequence", "context_candidate") },
|
|
262
|
+
stored_llm_calls: execution.llm_calls.size,
|
|
263
|
+
live_root_status: agent.agent_root.lifecycle_status,
|
|
264
|
+
source_done: source_task.done?,
|
|
265
|
+
source_physical_complete: source_task.physical_complete?,
|
|
266
|
+
provider_calls: adapter.request_count,
|
|
267
|
+
resumed_output: observed_result.fetch(:output)
|
|
268
|
+
}
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
if $PROGRAM_NAME == __FILE__
|
|
272
|
+
begin
|
|
273
|
+
adapter = G3NormalFixtureAdapter.new
|
|
274
|
+
Phronomy.configure { |configuration| configuration.llm_adapter = adapter }
|
|
275
|
+
agent, source_task, source_result, observed_result =
|
|
276
|
+
run_normal_application(persistence: Phronomy::PersistenceComposition.in_memory.agent)
|
|
277
|
+
raise "Unexpected output" unless source_result.fetch(:output) == {"answer" => "ordinary answer"}
|
|
278
|
+
raise "Resume changed the output" unless observed_result.fetch(:output) == source_result.fetch(:output)
|
|
279
|
+
raise "Provider was replayed" unless adapter.request_count == 1
|
|
280
|
+
observation = functional_observation(agent: agent, source_task: source_task,
|
|
281
|
+
source_result: source_result, observed_result: observed_result, adapter: adapter)
|
|
282
|
+
File.write(ENV.fetch("G3_NORMAL_REPORT"), JSON.pretty_generate(observation) + "\n")
|
|
283
|
+
ensure
|
|
284
|
+
Phronomy.reset_runtime!
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
</details>
|
|
290
|
+
|
|
291
|
+
The unchanged source was executed before and after the private change with the
|
|
292
|
+
real Agent and Runtime, an in-memory repository, and the deterministic provider
|
|
293
|
+
fixture. The functional result, transcript, durable revisions/status, and resumed
|
|
294
|
+
output matched exactly in the measured fields; generated execution IDs and record
|
|
295
|
+
timestamps are excluded, and usage is compared through `TokenUsage#to_h`.
|
|
296
|
+
Each run called the provider once, and its original
|
|
297
|
+
source task was both logically done and physically complete. This establishes
|
|
298
|
+
the tested normal-path behavior; it does not establish same-owner recovery from
|
|
299
|
+
an ambiguous save or acceptance of an external database or provider service.
|
|
300
|
+
|
|
301
|
+
## Workflow comparison and common implementation decision
|
|
302
|
+
|
|
303
|
+
Agent and Workflow can share rules about retained evidence, independent
|
|
304
|
+
observations, physical completion, and exact owner application. Their evidence
|
|
305
|
+
structures and the action permitted by a confirmed pre-state remain domain
|
|
306
|
+
decisions. Common invariants do not by themselves justify another manager.
|
|
307
|
+
|
|
308
|
+
For example, Workflow compares one terminal snapshot with an exact revision.
|
|
309
|
+
Agent compares root, execution, journal, cancellation, and referenced content;
|
|
310
|
+
its accepted durable execution may remain active after a rolled-back terminal
|
|
311
|
+
save. A generic pre-state handler that releases both owners would be incorrect.
|
|
312
|
+
|
|
313
|
+
The following tables retain the historical G3b-1 assessment before original-owner recovery was connected. As of 2026-11-28, [shared retained-attempt management](retained-attempts.md) documents the later Agent/Workflow machinery; these historical tables do not describe its current implementation status.
|
|
314
|
+
|
|
315
|
+
| Comparison | Workflow G2 | Agent G3b-1 |
|
|
316
|
+
| --- | --- | --- |
|
|
317
|
+
| Persistence proposal | Exact revisioned snapshot | Multi-record terminal proposal plus referenced content and semantic Outcome |
|
|
318
|
+
| Confirmed post | Existing recovery owner may apply and release after its gates | Private classification only; owner integration remains pending |
|
|
319
|
+
| Confirmed pre | Existing known-save-failure disposition can end the segment | Active accepted execution remains; guarded save-only retry is a distinct remedy |
|
|
320
|
+
| Public observation | Local capability, lookup, sync/async reconciliation | Existing public API only |
|
|
321
|
+
| Lifetime | Captured running/draining Runtime retains unresolved responsibility | Private caller must retain the evidence; default coordinator does not |
|
|
322
|
+
| Shared mechanisms | Existing persistence comparison, results, physical completion, neutral custody | Existing atomic coordination, guarded records, comparison, and immutable values |
|
|
323
|
+
|
|
324
|
+
| Commonality criterion | Historical G3b-1 assessment |
|
|
325
|
+
| --- | --- |
|
|
326
|
+
| Removed duplication | Proof comparison is reusable; complete proposal shape and terminal disposition differ. No cross-domain line reduction is established. |
|
|
327
|
+
| Connection and comprehension cost | A generic manager would need adapters for Agent's multi-record/content proposal and Workflow's segment outcome. Their cost is not justified yet. |
|
|
328
|
+
| Duplicate state management | Avoid a second registry mirroring the existing execution owner. This private value does not create a registry. |
|
|
329
|
+
| Shared defect corrections | Guarding immutable evidence and separating facts from release are shared rules. Domain-specific persistence and application corrections remain separate. |
|
|
330
|
+
| Total verification burden | Shared fault scenarios can help, but real Agent and Workflow owner tests remain necessary. Additional adapters would also need tests. |
|
|
331
|
+
| Dependency and execution cost | Keep persistence interpretation and owner release in their domains. No new generic manager, Engine-to-Agent dependency, or performance benefit is claimed. |
|
|
332
|
+
|
|
333
|
+
The G3b-1 decision was to retain existing neutral primitives and add only the
|
|
334
|
+
Agent-specific evidence path. It deferred smaller common components until a real
|
|
335
|
+
Agent owner was connected and both domains could be compared at the same
|
|
336
|
+
capability level. The later four-owner extraction addresses that comparison.
|
|
337
|
+
|
|
338
|
+
## Historical next-stage acceptance boundary
|
|
339
|
+
|
|
340
|
+
The original G3b-1 plan required G3b-2 to connect persistence evidence to the
|
|
341
|
+
exact original execution owner, retain responsibility before publishing
|
|
342
|
+
uncertainty, serialize attempts, apply facts once and define observation and
|
|
343
|
+
shutdown behavior. Those requirements were not implied by the evidence value
|
|
344
|
+
alone. The later [original-owner contract](agent-terminal-recovery.md) and
|
|
345
|
+
[current shared attempt design](retained-attempts.md) describe the implemented
|
|
346
|
+
boundaries as of 2026-11-28.
|
|
347
|
+
|
|
348
|
+
For example, after a lost terminal-save response, the planned recovery request could
|
|
349
|
+
read a committed outcome and deliver it to the original owner. It must validate
|
|
350
|
+
Agent, execution, session, recovery generation, and required physical completion
|
|
351
|
+
before settling the original operation or releasing admission. A durable result
|
|
352
|
+
visible through `resume` alone does not meet that acceptance condition.
|
|
353
|
+
|
|
354
|
+
The planned scope included cancelled or discarded observers, rejected and lost
|
|
355
|
+
deliveries, concurrent requests, unknown retry outcomes, changed cancellation,
|
|
356
|
+
stopped owners and incomplete cleanup. Public method names, receipt lifetime,
|
|
357
|
+
supported Runtime states and post-stop transfer required explicit decisions.
|
|
358
|
+
The G3b-1 evidence stage did not claim that the original-owner and shutdown gaps
|
|
359
|
+
were fixed. Neither that historical stage nor the current shared component
|
|
360
|
+
establishes crash recovery or arbitrary external database conformance.
|