aurora-agent 0.3.0__py3-none-any.whl
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.
- aurora_agent/__init__.py +39 -0
- aurora_agent/__main__.py +3 -0
- aurora_agent/adapters/__init__.py +4 -0
- aurora_agent/adapters/claude_agent_sdk.py +179 -0
- aurora_agent/adapters/jakrow_d3.py +418 -0
- aurora_agent/boundary.py +209 -0
- aurora_agent/canonical.py +92 -0
- aurora_agent/cli.py +31 -0
- aurora_agent/command.py +170 -0
- aurora_agent/exceptions.py +21 -0
- aurora_agent/ingestion.py +344 -0
- aurora_agent/ingestion_cli.py +37 -0
- aurora_agent/ingestion_constants.py +43 -0
- aurora_agent/ingestion_http.py +61 -0
- aurora_agent/ingestion_outbox.py +530 -0
- aurora_agent/model.py +82 -0
- aurora_agent/quickstart.py +362 -0
- aurora_agent/sdk.py +442 -0
- aurora_agent/store.py +256 -0
- aurora_agent/verifier.py +303 -0
- aurora_agent-0.3.0.dist-info/METADATA +89 -0
- aurora_agent-0.3.0.dist-info/RECORD +27 -0
- aurora_agent-0.3.0.dist-info/WHEEL +5 -0
- aurora_agent-0.3.0.dist-info/entry_points.txt +4 -0
- aurora_agent-0.3.0.dist-info/licenses/LICENSE +202 -0
- aurora_agent-0.3.0.dist-info/licenses/NOTICE +7 -0
- aurora_agent-0.3.0.dist-info/top_level.txt +1 -0
aurora_agent/__init__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""AURORA Agent Evidence SDK v0.3 with local and remote ingestion surfaces."""
|
|
2
|
+
|
|
3
|
+
from .boundary import Boundary, FieldRule
|
|
4
|
+
from .canonical import (
|
|
5
|
+
CANONICALIZATION_PROFILE,
|
|
6
|
+
CANONICALIZATION_VERSION,
|
|
7
|
+
HASH_ALGORITHM,
|
|
8
|
+
canonical_bytes,
|
|
9
|
+
commitment,
|
|
10
|
+
)
|
|
11
|
+
from .exceptions import (
|
|
12
|
+
AuroraAgentError,
|
|
13
|
+
BoundaryViolation,
|
|
14
|
+
CanonicalizationError,
|
|
15
|
+
LifecycleError,
|
|
16
|
+
VerificationError,
|
|
17
|
+
)
|
|
18
|
+
from .model import Authorization, OutcomeEvidenceStrength, Phase, PolicyPass, VerificationReport, Verdict
|
|
19
|
+
from .sdk import Action, Aurora, Execution
|
|
20
|
+
from .verifier import format_report, verify_bundle
|
|
21
|
+
from .ingestion import IngestionClient, RunSession
|
|
22
|
+
from .ingestion_outbox import IngestionOutbox, OutboxConflict, OutboxItem
|
|
23
|
+
from .adapters import ClaudeAgentCaptureAdapter, JAKROWD3IngestionObserver
|
|
24
|
+
from .quickstart import QuickstartError, QuickstartResult, QuickstartRunner
|
|
25
|
+
|
|
26
|
+
__version__ = "0.3.0"
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"Action", "Aurora", "Authorization", "AuroraAgentError", "Boundary",
|
|
30
|
+
"BoundaryViolation", "CANONICALIZATION_PROFILE", "CANONICALIZATION_VERSION",
|
|
31
|
+
"CanonicalizationError", "Execution", "FieldRule", "HASH_ALGORITHM",
|
|
32
|
+
"LifecycleError", "OutcomeEvidenceStrength", "Phase", "PolicyPass",
|
|
33
|
+
"VerificationError", "VerificationReport", "Verdict", "canonical_bytes",
|
|
34
|
+
"commitment", "format_report", "verify_bundle", "IngestionClient",
|
|
35
|
+
"RunSession", "IngestionOutbox", "OutboxConflict", "OutboxItem",
|
|
36
|
+
"ClaudeAgentCaptureAdapter",
|
|
37
|
+
"JAKROWD3IngestionObserver",
|
|
38
|
+
"QuickstartError", "QuickstartResult", "QuickstartRunner",
|
|
39
|
+
]
|
aurora_agent/__main__.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
from typing import Any, Iterator, Optional
|
|
5
|
+
|
|
6
|
+
from ..ingestion import RunSession
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ClaudeAgentCaptureAdapter:
|
|
10
|
+
"""Framework-light adapter for Claude Agent SDK lifecycle hooks.
|
|
11
|
+
|
|
12
|
+
It does not import Anthropic packages. Call these methods from the SDK's
|
|
13
|
+
prompt/model/tool hooks. The adapter preserves JAKROW's explicit approval
|
|
14
|
+
and ``execute_operation`` boundary references in AURORA event metadata.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, run: RunSession) -> None:
|
|
18
|
+
self.run = run
|
|
19
|
+
|
|
20
|
+
def prompt(self, value: Any, **metadata: Any) -> str:
|
|
21
|
+
return self.run.capture("prompt", value, metadata=metadata)
|
|
22
|
+
|
|
23
|
+
def retrieved_context(self, value: Any, **metadata: Any) -> str:
|
|
24
|
+
return self.run.capture("retrieved_context", value, metadata=metadata)
|
|
25
|
+
|
|
26
|
+
def model_invocation(
|
|
27
|
+
self,
|
|
28
|
+
*,
|
|
29
|
+
model: str,
|
|
30
|
+
provider: str = "anthropic",
|
|
31
|
+
parameters: Optional[dict] = None,
|
|
32
|
+
) -> str:
|
|
33
|
+
return self.run.capture(
|
|
34
|
+
"model_invocation",
|
|
35
|
+
{"model": model, "provider": provider, "parameters": parameters or {}},
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def model_response(self, value: Any, **metadata: Any) -> str:
|
|
39
|
+
return self.run.capture("model_response", value, metadata=metadata)
|
|
40
|
+
|
|
41
|
+
def authorization(
|
|
42
|
+
self,
|
|
43
|
+
*,
|
|
44
|
+
approval_ref: str,
|
|
45
|
+
authorization_digest: str,
|
|
46
|
+
actor: Optional[str] = None,
|
|
47
|
+
metadata: Optional[dict[str, Any]] = None,
|
|
48
|
+
) -> str:
|
|
49
|
+
return self.run.capture(
|
|
50
|
+
"authorization",
|
|
51
|
+
{
|
|
52
|
+
"approval_ref": approval_ref,
|
|
53
|
+
"authorization_digest": authorization_digest,
|
|
54
|
+
},
|
|
55
|
+
actor=actor,
|
|
56
|
+
authorization_ref=approval_ref,
|
|
57
|
+
metadata=metadata or {},
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def tool_request(
|
|
61
|
+
self,
|
|
62
|
+
*,
|
|
63
|
+
tool_name: str,
|
|
64
|
+
arguments: Any,
|
|
65
|
+
operation_ref: str,
|
|
66
|
+
approval_ref: Optional[str] = None,
|
|
67
|
+
metadata: Optional[dict[str, Any]] = None,
|
|
68
|
+
) -> str:
|
|
69
|
+
return self.run.capture(
|
|
70
|
+
"tool_request",
|
|
71
|
+
{"tool_name": tool_name, "arguments": arguments},
|
|
72
|
+
authorization_ref=approval_ref,
|
|
73
|
+
operation_ref=operation_ref,
|
|
74
|
+
metadata=metadata or {},
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
def tool_execution_started(
|
|
78
|
+
self,
|
|
79
|
+
*,
|
|
80
|
+
tool_name: str,
|
|
81
|
+
operation_ref: str,
|
|
82
|
+
request_event_id: str,
|
|
83
|
+
approval_ref: Optional[str] = None,
|
|
84
|
+
metadata: Optional[dict[str, Any]] = None,
|
|
85
|
+
) -> str:
|
|
86
|
+
return self.run.capture(
|
|
87
|
+
"tool_execution",
|
|
88
|
+
{
|
|
89
|
+
"tool_name": tool_name,
|
|
90
|
+
"operation_ref": operation_ref,
|
|
91
|
+
"request_event_id": request_event_id,
|
|
92
|
+
"dispatch_state": "ENTERED",
|
|
93
|
+
},
|
|
94
|
+
authorization_ref=approval_ref,
|
|
95
|
+
operation_ref=operation_ref,
|
|
96
|
+
metadata=metadata or {},
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def runtime_failure(
|
|
100
|
+
self,
|
|
101
|
+
*,
|
|
102
|
+
tool_name: str,
|
|
103
|
+
operation_ref: str,
|
|
104
|
+
failure_type: str,
|
|
105
|
+
approval_ref: Optional[str] = None,
|
|
106
|
+
metadata: Optional[dict[str, Any]] = None,
|
|
107
|
+
) -> str:
|
|
108
|
+
return self.run.capture(
|
|
109
|
+
"runtime_failure",
|
|
110
|
+
{
|
|
111
|
+
"tool_name": tool_name,
|
|
112
|
+
"operation_ref": operation_ref,
|
|
113
|
+
"dispatch_state": "UNKNOWN",
|
|
114
|
+
"failure_type": failure_type,
|
|
115
|
+
"retry_permitted": False,
|
|
116
|
+
},
|
|
117
|
+
authorization_ref=approval_ref,
|
|
118
|
+
operation_ref=operation_ref,
|
|
119
|
+
metadata=metadata or {},
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
@contextmanager
|
|
123
|
+
def execute_operation(
|
|
124
|
+
self,
|
|
125
|
+
*,
|
|
126
|
+
tool_name: str,
|
|
127
|
+
arguments: Any,
|
|
128
|
+
operation_ref: str,
|
|
129
|
+
approval_ref: Optional[str] = None,
|
|
130
|
+
metadata: Optional[dict[str, Any]] = None,
|
|
131
|
+
) -> Iterator[None]:
|
|
132
|
+
request_event = self.tool_request(
|
|
133
|
+
tool_name=tool_name,
|
|
134
|
+
arguments=arguments,
|
|
135
|
+
operation_ref=operation_ref,
|
|
136
|
+
approval_ref=approval_ref,
|
|
137
|
+
metadata=metadata,
|
|
138
|
+
)
|
|
139
|
+
self.tool_execution_started(
|
|
140
|
+
tool_name=tool_name,
|
|
141
|
+
operation_ref=operation_ref,
|
|
142
|
+
request_event_id=request_event,
|
|
143
|
+
approval_ref=approval_ref,
|
|
144
|
+
)
|
|
145
|
+
try:
|
|
146
|
+
yield
|
|
147
|
+
except BaseException as exc:
|
|
148
|
+
self.runtime_failure(
|
|
149
|
+
tool_name=tool_name,
|
|
150
|
+
operation_ref=operation_ref,
|
|
151
|
+
failure_type=type(exc).__name__,
|
|
152
|
+
approval_ref=approval_ref,
|
|
153
|
+
metadata={"exception_message_digest_only": True},
|
|
154
|
+
)
|
|
155
|
+
raise
|
|
156
|
+
|
|
157
|
+
def tool_outcome(
|
|
158
|
+
self,
|
|
159
|
+
value: Any,
|
|
160
|
+
*,
|
|
161
|
+
operation_ref: str,
|
|
162
|
+
outcome_ref: Optional[str] = None,
|
|
163
|
+
approval_ref: Optional[str] = None,
|
|
164
|
+
metadata: Optional[dict[str, Any]] = None,
|
|
165
|
+
) -> str:
|
|
166
|
+
return self.run.capture(
|
|
167
|
+
"tool_outcome",
|
|
168
|
+
value,
|
|
169
|
+
authorization_ref=approval_ref,
|
|
170
|
+
operation_ref=operation_ref,
|
|
171
|
+
outcome_ref=outcome_ref,
|
|
172
|
+
metadata=metadata or {},
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def human_review(self, value: Any, *, actor: Optional[str] = None) -> str:
|
|
176
|
+
return self.run.capture("human_review", value, actor=actor)
|
|
177
|
+
|
|
178
|
+
def final_decision(self, value: Any, *, actor: Optional[str] = None) -> str:
|
|
179
|
+
return self.run.capture("final_decision", value, actor=actor)
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
"""JAKROW D3 resumed-execution observer for AURORA ingestion.
|
|
2
|
+
|
|
3
|
+
The observer is local-first. Every hook writes deterministic events to the
|
|
4
|
+
SQLite outbox. Consequential execution is therefore separated from network
|
|
5
|
+
availability, while repeated recovery calls converge on the same event IDs and
|
|
6
|
+
one finalization request.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import hashlib
|
|
12
|
+
from typing import Any, Optional
|
|
13
|
+
|
|
14
|
+
from ..canonical import canonical_bytes
|
|
15
|
+
from ..ingestion import RunSession
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _to_dict(value: Any) -> dict[str, Any]:
|
|
19
|
+
if value is None:
|
|
20
|
+
return {}
|
|
21
|
+
if hasattr(value, "to_dict"):
|
|
22
|
+
result = value.to_dict()
|
|
23
|
+
if isinstance(result, dict):
|
|
24
|
+
return result
|
|
25
|
+
if isinstance(value, dict):
|
|
26
|
+
return dict(value)
|
|
27
|
+
return {"value": str(value)}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _stable_event_id(run_id: str, approval_ref: str, phase: str) -> str:
|
|
31
|
+
material = canonical_bytes(
|
|
32
|
+
{"run_id": run_id, "approval_ref": approval_ref, "phase": phase}
|
|
33
|
+
)
|
|
34
|
+
return "evt_jakrow_" + hashlib.sha256(material).hexdigest()[:32]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class JAKROWD3IngestionObserver:
|
|
38
|
+
"""Project one JAKROW D3 execution into an AURORA ingestion run.
|
|
39
|
+
|
|
40
|
+
Event IDs are deterministic for the tuple ``(run_id, approval_ref, phase)``.
|
|
41
|
+
A process restart may therefore complete missing terminal evidence without
|
|
42
|
+
adding duplicate nodes. By default the observer queues a ``final_decision``
|
|
43
|
+
event and finalization after every durable terminal, deterministic
|
|
44
|
+
pre-consequence abort, or honest outcome-unknown recovery.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, run: RunSession, *, auto_finalize: bool = True) -> None:
|
|
48
|
+
self.run = run
|
|
49
|
+
self.auto_finalize = bool(auto_finalize)
|
|
50
|
+
self.last_event_id: str | None = None
|
|
51
|
+
self.operation_ref: str | None = None
|
|
52
|
+
|
|
53
|
+
def _id(self, approval_ref: str, phase: str) -> str:
|
|
54
|
+
return _stable_event_id(self.run.run_id, approval_ref, phase)
|
|
55
|
+
|
|
56
|
+
def _capture_authorization_and_request(
|
|
57
|
+
self,
|
|
58
|
+
*,
|
|
59
|
+
request: Any,
|
|
60
|
+
approval_ref: str,
|
|
61
|
+
authorized_commitment: Any,
|
|
62
|
+
started_at: str,
|
|
63
|
+
dispatched_payload_digest: str,
|
|
64
|
+
) -> tuple[str, str]:
|
|
65
|
+
commitment_data = _to_dict(authorized_commitment)
|
|
66
|
+
authorization_digest = str(
|
|
67
|
+
commitment_data.get("authorization_digest")
|
|
68
|
+
or commitment_data.get("commitment_digest")
|
|
69
|
+
or commitment_data.get("commitment_id")
|
|
70
|
+
)
|
|
71
|
+
authorization_event = self.run.capture(
|
|
72
|
+
"authorization",
|
|
73
|
+
{
|
|
74
|
+
"approval_ref": approval_ref,
|
|
75
|
+
"authorization_digest": authorization_digest,
|
|
76
|
+
},
|
|
77
|
+
event_id=self._id(approval_ref, "authorization"),
|
|
78
|
+
parent_event_ids=[],
|
|
79
|
+
authorization_ref=approval_ref,
|
|
80
|
+
metadata={
|
|
81
|
+
"jakrow_authorized_commitment_id": commitment_data.get(
|
|
82
|
+
"commitment_id"
|
|
83
|
+
),
|
|
84
|
+
"jakrow_started_at": started_at,
|
|
85
|
+
"approved_payload_digest": commitment_data.get(
|
|
86
|
+
"proposal_payload_digest"
|
|
87
|
+
),
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
correlation_ref = f"action:{request.action_id}"
|
|
91
|
+
request_event = self.run.capture(
|
|
92
|
+
"tool_request",
|
|
93
|
+
{"tool_name": request.tool_name, "arguments": request.arguments},
|
|
94
|
+
event_id=self._id(approval_ref, "tool_request"),
|
|
95
|
+
parent_event_ids=[authorization_event],
|
|
96
|
+
authorization_ref=approval_ref,
|
|
97
|
+
operation_ref=correlation_ref,
|
|
98
|
+
metadata={
|
|
99
|
+
"jakrow_run_id": request.run_id,
|
|
100
|
+
"jakrow_action_id": request.action_id,
|
|
101
|
+
"dispatched_payload_digest": dispatched_payload_digest,
|
|
102
|
+
},
|
|
103
|
+
)
|
|
104
|
+
self.operation_ref = correlation_ref
|
|
105
|
+
return authorization_event, request_event
|
|
106
|
+
|
|
107
|
+
def _queue_final_decision(
|
|
108
|
+
self,
|
|
109
|
+
*,
|
|
110
|
+
request: Any,
|
|
111
|
+
approval_ref: str,
|
|
112
|
+
parent_event_id: str,
|
|
113
|
+
decision_state: str,
|
|
114
|
+
terminal_digest: Optional[str] = None,
|
|
115
|
+
failure_code: Optional[str] = None,
|
|
116
|
+
) -> tuple[str, Optional[str]]:
|
|
117
|
+
final_event = self.run.capture(
|
|
118
|
+
"final_decision",
|
|
119
|
+
{
|
|
120
|
+
"decision_state": decision_state,
|
|
121
|
+
"tool_name": request.tool_name,
|
|
122
|
+
"retry_permitted": False,
|
|
123
|
+
"terminal_digest": terminal_digest,
|
|
124
|
+
"failure_code": failure_code,
|
|
125
|
+
},
|
|
126
|
+
event_id=self._id(approval_ref, "final_decision"),
|
|
127
|
+
parent_event_ids=[parent_event_id],
|
|
128
|
+
authorization_ref=approval_ref,
|
|
129
|
+
operation_ref=self.operation_ref,
|
|
130
|
+
metadata={
|
|
131
|
+
"jakrow_run_id": request.run_id,
|
|
132
|
+
"jakrow_action_id": request.action_id,
|
|
133
|
+
"automatic_consequential_retry": False,
|
|
134
|
+
},
|
|
135
|
+
)
|
|
136
|
+
finalize_key: Optional[str] = None
|
|
137
|
+
if self.auto_finalize:
|
|
138
|
+
item = self.run.finalize(root_event_id=final_event)
|
|
139
|
+
finalize_key = item.request_key
|
|
140
|
+
self.last_event_id = final_event
|
|
141
|
+
return final_event, finalize_key
|
|
142
|
+
|
|
143
|
+
def before_consequence(
|
|
144
|
+
self,
|
|
145
|
+
*,
|
|
146
|
+
request: Any,
|
|
147
|
+
approval_ref: str,
|
|
148
|
+
authorized_commitment: Any,
|
|
149
|
+
started_at: str,
|
|
150
|
+
dispatched_payload_digest: str,
|
|
151
|
+
) -> dict[str, Any]:
|
|
152
|
+
authorization_event, request_event = self._capture_authorization_and_request(
|
|
153
|
+
request=request,
|
|
154
|
+
approval_ref=approval_ref,
|
|
155
|
+
authorized_commitment=authorized_commitment,
|
|
156
|
+
started_at=started_at,
|
|
157
|
+
dispatched_payload_digest=dispatched_payload_digest,
|
|
158
|
+
)
|
|
159
|
+
correlation_ref = f"action:{request.action_id}"
|
|
160
|
+
execution_event = self.run.capture(
|
|
161
|
+
"tool_execution",
|
|
162
|
+
{
|
|
163
|
+
"tool_name": request.tool_name,
|
|
164
|
+
"operation_ref": correlation_ref,
|
|
165
|
+
"request_event_id": request_event,
|
|
166
|
+
"dispatch_state": "ENTERED",
|
|
167
|
+
},
|
|
168
|
+
event_id=self._id(approval_ref, "tool_execution"),
|
|
169
|
+
parent_event_ids=[request_event],
|
|
170
|
+
authorization_ref=approval_ref,
|
|
171
|
+
operation_ref=correlation_ref,
|
|
172
|
+
metadata={"commit_before_consequence": True},
|
|
173
|
+
)
|
|
174
|
+
self.operation_ref = correlation_ref
|
|
175
|
+
self.last_event_id = execution_event
|
|
176
|
+
return {
|
|
177
|
+
"status": "QUEUED_LOCALLY",
|
|
178
|
+
"authorization_event_id": authorization_event,
|
|
179
|
+
"request_event_id": request_event,
|
|
180
|
+
"execution_event_id": execution_event,
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
def terminal(
|
|
184
|
+
self,
|
|
185
|
+
*,
|
|
186
|
+
request: Any,
|
|
187
|
+
approval_ref: str,
|
|
188
|
+
operation: Any,
|
|
189
|
+
terminal: Any,
|
|
190
|
+
verification: Any,
|
|
191
|
+
authorized_commitment: Any = None,
|
|
192
|
+
started_at: Optional[str] = None,
|
|
193
|
+
dispatched_payload_digest: Optional[str] = None,
|
|
194
|
+
) -> dict[str, Any]:
|
|
195
|
+
operation_data = _to_dict(operation)
|
|
196
|
+
terminal_data = _to_dict(terminal)
|
|
197
|
+
verification_data = _to_dict(verification)
|
|
198
|
+
operation_ref = str(
|
|
199
|
+
operation_data.get("operation_id")
|
|
200
|
+
or terminal_data.get("operation_reference")
|
|
201
|
+
or self.operation_ref
|
|
202
|
+
or f"action:{request.action_id}"
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
execution_event = self._id(approval_ref, "tool_execution")
|
|
206
|
+
execution_key = f"event:{self.run.run_id}:{execution_event}"
|
|
207
|
+
if self.run.client.outbox.get_item(execution_key) is None:
|
|
208
|
+
if (
|
|
209
|
+
authorized_commitment is None
|
|
210
|
+
or not started_at
|
|
211
|
+
or not dispatched_payload_digest
|
|
212
|
+
):
|
|
213
|
+
raise RuntimeError(
|
|
214
|
+
"terminal evidence recovery requires durable STARTED context "
|
|
215
|
+
"when pre-consequence events are absent"
|
|
216
|
+
)
|
|
217
|
+
_, request_event = self._capture_authorization_and_request(
|
|
218
|
+
request=request,
|
|
219
|
+
approval_ref=approval_ref,
|
|
220
|
+
authorized_commitment=authorized_commitment,
|
|
221
|
+
started_at=started_at,
|
|
222
|
+
dispatched_payload_digest=dispatched_payload_digest,
|
|
223
|
+
)
|
|
224
|
+
execution_event = self.run.capture(
|
|
225
|
+
"tool_execution",
|
|
226
|
+
{
|
|
227
|
+
"tool_name": request.tool_name,
|
|
228
|
+
"operation_ref": f"action:{request.action_id}",
|
|
229
|
+
"request_event_id": request_event,
|
|
230
|
+
"dispatch_state": "RECOVERED_FROM_DURABLE_TERMINAL",
|
|
231
|
+
},
|
|
232
|
+
event_id=execution_event,
|
|
233
|
+
parent_event_ids=[request_event],
|
|
234
|
+
authorization_ref=approval_ref,
|
|
235
|
+
operation_ref=f"action:{request.action_id}",
|
|
236
|
+
metadata={
|
|
237
|
+
"commit_before_consequence": True,
|
|
238
|
+
"reconstructed_from_durable_terminal": True,
|
|
239
|
+
},
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
self.operation_ref = operation_ref
|
|
243
|
+
terminal_state = str(terminal_data.get("terminal_state") or "UNKNOWN")
|
|
244
|
+
outcome_event = self.run.capture(
|
|
245
|
+
"tool_outcome",
|
|
246
|
+
{
|
|
247
|
+
"terminal_state": terminal_state,
|
|
248
|
+
"operation": operation_data,
|
|
249
|
+
"terminal_digest": terminal_data.get("terminal_digest"),
|
|
250
|
+
"verification_verdict": verification_data.get("verdict"),
|
|
251
|
+
"outcome_strength": terminal_data.get("outcome_strength", "O0"),
|
|
252
|
+
"provider_acknowledgement": terminal_data.get(
|
|
253
|
+
"provider_acknowledgement", "NOT_PRESENT"
|
|
254
|
+
),
|
|
255
|
+
"failure_code": terminal_data.get("failure_code"),
|
|
256
|
+
},
|
|
257
|
+
event_id=self._id(approval_ref, "tool_outcome"),
|
|
258
|
+
parent_event_ids=[execution_event],
|
|
259
|
+
authorization_ref=approval_ref,
|
|
260
|
+
operation_ref=operation_ref,
|
|
261
|
+
outcome_ref=terminal_data.get("terminal_digest"),
|
|
262
|
+
metadata={
|
|
263
|
+
"jakrow_terminal_persisted": True,
|
|
264
|
+
"jakrow_continuity_accepted": bool(
|
|
265
|
+
getattr(verification, "accepted", False)
|
|
266
|
+
),
|
|
267
|
+
},
|
|
268
|
+
)
|
|
269
|
+
final_event, finalize_key = self._queue_final_decision(
|
|
270
|
+
request=request,
|
|
271
|
+
approval_ref=approval_ref,
|
|
272
|
+
parent_event_id=outcome_event,
|
|
273
|
+
decision_state=terminal_state,
|
|
274
|
+
terminal_digest=terminal_data.get("terminal_digest"),
|
|
275
|
+
failure_code=terminal_data.get("failure_code"),
|
|
276
|
+
)
|
|
277
|
+
return {
|
|
278
|
+
"status": "QUEUED_LOCALLY",
|
|
279
|
+
"terminal_event_id": outcome_event,
|
|
280
|
+
"final_decision_event_id": final_event,
|
|
281
|
+
"finalize_request_key": finalize_key,
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
def precondition_failed(
|
|
285
|
+
self,
|
|
286
|
+
*,
|
|
287
|
+
request: Any,
|
|
288
|
+
approval_ref: str,
|
|
289
|
+
authorized_commitment: Any,
|
|
290
|
+
started_at: str,
|
|
291
|
+
dispatched_payload_digest: str,
|
|
292
|
+
failure_code: str,
|
|
293
|
+
verification: Any = None,
|
|
294
|
+
) -> dict[str, Any]:
|
|
295
|
+
_, request_event = self._capture_authorization_and_request(
|
|
296
|
+
request=request,
|
|
297
|
+
approval_ref=approval_ref,
|
|
298
|
+
authorized_commitment=authorized_commitment,
|
|
299
|
+
started_at=started_at,
|
|
300
|
+
dispatched_payload_digest=dispatched_payload_digest,
|
|
301
|
+
)
|
|
302
|
+
execution_event = self._id(approval_ref, "tool_execution")
|
|
303
|
+
execution_key = f"event:{self.run.run_id}:{execution_event}"
|
|
304
|
+
parent_event = (
|
|
305
|
+
execution_event
|
|
306
|
+
if self.run.client.outbox.get_item(execution_key) is not None
|
|
307
|
+
else request_event
|
|
308
|
+
)
|
|
309
|
+
dispatch_event_present = parent_event == execution_event
|
|
310
|
+
failure_event = self.run.capture(
|
|
311
|
+
"tool_outcome",
|
|
312
|
+
{
|
|
313
|
+
"terminal_state": "FAILED",
|
|
314
|
+
"decision_state": "FAILED_BEFORE_CONSEQUENCE",
|
|
315
|
+
"tool_name": request.tool_name,
|
|
316
|
+
"operation_ref": f"action:{request.action_id}",
|
|
317
|
+
"dispatch_state": (
|
|
318
|
+
"ENTERED_NO_CONSEQUENCE"
|
|
319
|
+
if dispatch_event_present
|
|
320
|
+
else "NOT_ENTERED"
|
|
321
|
+
),
|
|
322
|
+
"failure_code": failure_code,
|
|
323
|
+
"retry_permitted": False,
|
|
324
|
+
"consequence_occurred": False,
|
|
325
|
+
},
|
|
326
|
+
event_id=self._id(approval_ref, "precondition_failure"),
|
|
327
|
+
parent_event_ids=[parent_event],
|
|
328
|
+
authorization_ref=approval_ref,
|
|
329
|
+
operation_ref=f"action:{request.action_id}",
|
|
330
|
+
outcome_ref=failure_code,
|
|
331
|
+
metadata={
|
|
332
|
+
"jakrow_run_id": request.run_id,
|
|
333
|
+
"jakrow_action_id": request.action_id,
|
|
334
|
+
"consequence_invoked": False,
|
|
335
|
+
"dispatch_event_present": dispatch_event_present,
|
|
336
|
+
"known_preconsequence_failure": True,
|
|
337
|
+
"verification_verdict": _to_dict(verification).get("verdict"),
|
|
338
|
+
},
|
|
339
|
+
)
|
|
340
|
+
self.operation_ref = f"action:{request.action_id}"
|
|
341
|
+
final_event, finalize_key = self._queue_final_decision(
|
|
342
|
+
request=request,
|
|
343
|
+
approval_ref=approval_ref,
|
|
344
|
+
parent_event_id=failure_event,
|
|
345
|
+
decision_state="FAILED_BEFORE_CONSEQUENCE",
|
|
346
|
+
failure_code=failure_code,
|
|
347
|
+
)
|
|
348
|
+
return {
|
|
349
|
+
"status": "QUEUED_LOCALLY",
|
|
350
|
+
"failure_event_id": failure_event,
|
|
351
|
+
"final_decision_event_id": final_event,
|
|
352
|
+
"finalize_request_key": finalize_key,
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
def outcome_unknown(
|
|
356
|
+
self,
|
|
357
|
+
*,
|
|
358
|
+
request: Any,
|
|
359
|
+
approval_ref: str,
|
|
360
|
+
verification: Any,
|
|
361
|
+
authorized_commitment: Any = None,
|
|
362
|
+
started_at: Optional[str] = None,
|
|
363
|
+
dispatched_payload_digest: Optional[str] = None,
|
|
364
|
+
) -> dict[str, Any]:
|
|
365
|
+
verification_data = _to_dict(verification)
|
|
366
|
+
parent: list[str] = []
|
|
367
|
+
execution_key = f"event:{self.run.run_id}:{self._id(approval_ref, 'tool_execution')}"
|
|
368
|
+
existing_execution = self.run.client.outbox.get_item(execution_key)
|
|
369
|
+
if existing_execution is not None:
|
|
370
|
+
parent = [self._id(approval_ref, "tool_execution")]
|
|
371
|
+
elif authorized_commitment is not None and started_at and dispatched_payload_digest:
|
|
372
|
+
_, request_event = self._capture_authorization_and_request(
|
|
373
|
+
request=request,
|
|
374
|
+
approval_ref=approval_ref,
|
|
375
|
+
authorized_commitment=authorized_commitment,
|
|
376
|
+
started_at=started_at,
|
|
377
|
+
dispatched_payload_digest=dispatched_payload_digest,
|
|
378
|
+
)
|
|
379
|
+
parent = [request_event]
|
|
380
|
+
|
|
381
|
+
operation_ref = f"action:{request.action_id}"
|
|
382
|
+
failure_event = self.run.capture(
|
|
383
|
+
"runtime_failure",
|
|
384
|
+
{
|
|
385
|
+
"tool_name": request.tool_name,
|
|
386
|
+
"operation_ref": operation_ref,
|
|
387
|
+
"dispatch_state": "UNKNOWN",
|
|
388
|
+
"failure_type": "OUTCOME_UNKNOWN_AFTER_DURABLE_STARTED",
|
|
389
|
+
"retry_permitted": False,
|
|
390
|
+
},
|
|
391
|
+
event_id=self._id(approval_ref, "outcome_unknown"),
|
|
392
|
+
parent_event_ids=parent,
|
|
393
|
+
authorization_ref=approval_ref,
|
|
394
|
+
operation_ref=operation_ref,
|
|
395
|
+
metadata={
|
|
396
|
+
"jakrow_run_id": request.run_id,
|
|
397
|
+
"jakrow_action_id": request.action_id,
|
|
398
|
+
"retry_permitted": False,
|
|
399
|
+
"verification_verdict": verification_data.get("verdict"),
|
|
400
|
+
},
|
|
401
|
+
)
|
|
402
|
+
self.operation_ref = operation_ref
|
|
403
|
+
final_event, finalize_key = self._queue_final_decision(
|
|
404
|
+
request=request,
|
|
405
|
+
approval_ref=approval_ref,
|
|
406
|
+
parent_event_id=failure_event,
|
|
407
|
+
decision_state="OUTCOME_UNKNOWN",
|
|
408
|
+
failure_code="OUTCOME_UNKNOWN_AFTER_DURABLE_STARTED",
|
|
409
|
+
)
|
|
410
|
+
return {
|
|
411
|
+
"status": "QUEUED_LOCALLY",
|
|
412
|
+
"unknown_event_id": failure_event,
|
|
413
|
+
"final_decision_event_id": final_event,
|
|
414
|
+
"finalize_request_key": finalize_key,
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
__all__ = ["JAKROWD3IngestionObserver"]
|