execweave 1.0.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.
- execweave/__init__.py +3 -0
- execweave/__main__.py +5 -0
- execweave/_conversation_records_core.py +902 -0
- execweave/_dashboard_shell_base.py +148 -0
- execweave/_http_proxy_base.py +565 -0
- execweave/_http_proxy_bounded.py +560 -0
- execweave/_http_proxy_stage.py +509 -0
- execweave/acceptance_output.py +19 -0
- execweave/agent_bootstrap.py +395 -0
- execweave/agent_topology.py +313 -0
- execweave/agent_trace.py +1162 -0
- execweave/agy_preview_sanitize.py +102 -0
- execweave/analysis.py +427 -0
- execweave/anthropic.py +228 -0
- execweave/anthropic_cli.py +171 -0
- execweave/anthropic_full_fidelity.py +385 -0
- execweave/antigravity_adapter.py +112 -0
- execweave/antigravity_adapter_base.py +479 -0
- execweave/antigravity_full_fidelity.py +656 -0
- execweave/antigravity_full_fidelity_base.py +172 -0
- execweave/antigravity_full_fidelity_collaboration_base.py +451 -0
- execweave/antigravity_hook_cli.py +209 -0
- execweave/antigravity_record.py +96 -0
- execweave/antigravity_subagent_linkage.py +449 -0
- execweave/antigravity_trace_capability.py +39 -0
- execweave/auto_specialized.py +547 -0
- execweave/backends.py +102 -0
- execweave/benchmark.py +80 -0
- execweave/claude_adapter.py +517 -0
- execweave/claude_child_transcript.py +314 -0
- execweave/claude_delegation.py +136 -0
- execweave/claude_full_fidelity.py +396 -0
- execweave/claude_hook_cli.py +209 -0
- execweave/claude_hook_contract.py +943 -0
- execweave/claude_model_observer.py +353 -0
- execweave/claude_record.py +106 -0
- execweave/cli.py +629 -0
- execweave/codex_adapter.py +455 -0
- execweave/codex_conversation.py +621 -0
- execweave/codex_full_fidelity.py +287 -0
- execweave/codex_hook_cli.py +301 -0
- execweave/codex_hook_entry.py +207 -0
- execweave/codex_hook_lifecycle.py +363 -0
- execweave/codex_message_diagnostics.py +322 -0
- execweave/codex_message_transport_diagnostics.py +399 -0
- execweave/codex_record.py +199 -0
- execweave/codex_rollout_structures.py +402 -0
- execweave/codex_rollout_trace.py +56 -0
- execweave/codex_rollout_trace_base.py +1509 -0
- execweave/collector.py +768 -0
- execweave/command.py +157 -0
- execweave/command_privacy.py +20 -0
- execweave/content_evidence.py +101 -0
- execweave/content_integrity.py +289 -0
- execweave/content_store.py +273 -0
- execweave/controlled_checks.py +561 -0
- execweave/conversation_archive.py +338 -0
- execweave/conversation_message_identity.py +264 -0
- execweave/conversation_preview.py +66 -0
- execweave/conversation_preview_antigravity.py +32 -0
- execweave/conversation_preview_claude.py +31 -0
- execweave/conversation_preview_codex.py +107 -0
- execweave/conversation_preview_common.py +180 -0
- execweave/conversation_preview_generic.py +188 -0
- execweave/conversation_preview_lines.py +133 -0
- execweave/conversation_preview_transcript.py +121 -0
- execweave/conversation_records.py +349 -0
- execweave/conversation_records_antigravity.py +370 -0
- execweave/conversation_records_codex.py +83 -0
- execweave/conversation_records_common.py +17 -0
- execweave/conversation_records_ollama.py +39 -0
- execweave/correlation.py +818 -0
- execweave/cursor_adapter.py +349 -0
- execweave/cursor_delegation.py +87 -0
- execweave/cursor_delegation_base.py +220 -0
- execweave/cursor_full_fidelity.py +489 -0
- execweave/cursor_hook_cli.py +195 -0
- execweave/cursor_hook_contract.py +439 -0
- execweave/cursor_lifecycle.py +159 -0
- execweave/cursor_record.py +96 -0
- execweave/dashboard_shell.py +283 -0
- execweave/delivery_status.py +94 -0
- execweave/entry.py +98 -0
- execweave/evidence_availability.py +113 -0
- execweave/evidence_grade.py +166 -0
- execweave/fidelity.py +304 -0
- execweave/filesystem.py +327 -0
- execweave/finalization.py +92 -0
- execweave/focus.py +118 -0
- execweave/framework_adapters/__init__.py +34 -0
- execweave/framework_adapters/autogen.py +398 -0
- execweave/framework_adapters/base.py +580 -0
- execweave/framework_adapters/camel.py +270 -0
- execweave/framework_adapters/camel_channel.py +71 -0
- execweave/framework_adapters/metagpt.py +315 -0
- execweave/framework_adapters/metagpt_ollama_compat.py +54 -0
- execweave/framework_adapters/metagpt_recording.py +342 -0
- execweave/framework_adapters/registry.py +90 -0
- execweave/graph.py +590 -0
- execweave/graph_ops.py +472 -0
- execweave/hook_command.py +32 -0
- execweave/hook_delivery.py +32 -0
- execweave/hook_input.py +16 -0
- execweave/http_proxy.py +187 -0
- execweave/http_proxy_cli.py +84 -0
- execweave/inference_gateway.py +476 -0
- execweave/inference_gateway_cli.py +211 -0
- execweave/inference_gateway_full_fidelity.py +613 -0
- execweave/inference_identity.py +76 -0
- execweave/inference_identity_cli.py +60 -0
- execweave/integrity.py +235 -0
- execweave/integrity_cli.py +55 -0
- execweave/investigation_index.py +445 -0
- execweave/litellm_callback.py +211 -0
- execweave/litellm_callback_cli.py +42 -0
- execweave/live.py +445 -0
- execweave/live_core.py +972 -0
- execweave/live_view.py +109 -0
- execweave/live_view_extra_style.py +11 -0
- execweave/live_view_markup.py +29 -0
- execweave/live_view_process_layout.py +650 -0
- execweave/live_view_readability.py +502 -0
- execweave/live_view_script_a.py +59 -0
- execweave/live_view_script_b.py +97 -0
- execweave/live_view_script_c.py +59 -0
- execweave/live_view_script_d.py +40 -0
- execweave/live_view_style.py +34 -0
- execweave/model_runtime.py +560 -0
- execweave/model_runtime_cli.py +265 -0
- execweave/model_runtime_full_fidelity.py +519 -0
- execweave/observation.py +53 -0
- execweave/observation_demo.py +69 -0
- execweave/openai_agents.py +267 -0
- execweave/openai_agents_sdk.py +453 -0
- execweave/openai_compatible.py +239 -0
- execweave/openai_compatible_cli.py +189 -0
- execweave/openai_compatible_full_fidelity.py +438 -0
- execweave/opencode_adapter.py +325 -0
- execweave/opencode_event_contract.py +734 -0
- execweave/opencode_full_fidelity.py +198 -0
- execweave/opencode_hook_cli.py +119 -0
- execweave/opencode_plugin_cli.py +150 -0
- execweave/opencode_record.py +96 -0
- execweave/opencode_task_linkage.py +225 -0
- execweave/overhead_benchmark.py +440 -0
- execweave/privacy.py +84 -0
- execweave/private_io.py +465 -0
- execweave/provider_capability.py +578 -0
- execweave/provider_lifecycle.py +282 -0
- execweave/provider_record.py +290 -0
- execweave/reader_identity.py +13 -0
- execweave/redacted_archive.py +906 -0
- execweave/risk.py +106 -0
- execweave/rule_pack.py +359 -0
- execweave/rule_pack_cli.py +57 -0
- execweave/run_assessment.py +200 -0
- execweave/runtime_endpoint_availability.py +44 -0
- execweave/scalability_benchmark.py +195 -0
- execweave/schema.py +62 -0
- execweave/scope.py +85 -0
- execweave/semantic.py +453 -0
- execweave/session_summary.py +159 -0
- execweave/sink.py +71 -0
- execweave/strace_backend.py +927 -0
- execweave/stream_assembly.py +363 -0
- execweave/task_artifacts.py +192 -0
- execweave/task_validation.py +317 -0
- execweave/theme.py +40 -0
- execweave/top.py +599 -0
- execweave/top_cli.py +150 -0
- execweave/validate.py +196 -0
- execweave/vendor/dagre.min.js +815 -0
- execweave/view_cli.py +49 -0
- execweave/viewer.py +474 -0
- execweave/viewer_agent_panel.py +630 -0
- execweave/viewer_agent_panel_antigravity.py +31 -0
- execweave/viewer_agent_panel_claude.py +9 -0
- execweave/viewer_agent_panel_codex.py +50 -0
- execweave/viewer_agent_panel_cursor.py +9 -0
- execweave/viewer_agent_panel_default.py +79 -0
- execweave/viewer_agent_panel_ollama.py +20 -0
- execweave/viewer_agent_panel_opencode.py +9 -0
- execweave/viewer_agent_panel_registry.py +20 -0
- execweave/viewer_archive_verifier.py +178 -0
- execweave/viewer_background_files.py +86 -0
- execweave/viewer_content_browser.py +307 -0
- execweave/viewer_content_health.py +208 -0
- execweave/viewer_content_inspector.py +309 -0
- execweave/viewer_controlled_checks.py +258 -0
- execweave/viewer_conversation_sync.py +115 -0
- execweave/viewer_dashboard_clean.py +405 -0
- execweave/viewer_dashboard_focus.py +127 -0
- execweave/viewer_dashboard_hardening.py +264 -0
- execweave/viewer_dashboard_hardening_v2.py +62 -0
- execweave/viewer_dashboard_projection.py +261 -0
- execweave/viewer_delivery_status.py +155 -0
- execweave/viewer_edge_decross.py +117 -0
- execweave/viewer_execution_flow.py +611 -0
- execweave/viewer_execution_flow_provider_normalization.py +107 -0
- execweave/viewer_execution_flow_safety.py +349 -0
- execweave/viewer_external_endpoints.py +307 -0
- execweave/viewer_flow_canvas.py +1140 -0
- execweave/viewer_flow_layout.py +922 -0
- execweave/viewer_fold_state.py +31 -0
- execweave/viewer_framework_flow.py +68 -0
- execweave/viewer_framework_model_output.py +133 -0
- execweave/viewer_gif.py +278 -0
- execweave/viewer_history_browser.py +225 -0
- execweave/viewer_investigation.py +268 -0
- execweave/viewer_layout_geometry.py +192 -0
- execweave/viewer_layout_v2.py +429 -0
- execweave/viewer_layout_v2_detached.py +25 -0
- execweave/viewer_limits.py +93 -0
- execweave/viewer_live_layout.py +61 -0
- execweave/viewer_message_handoffs.py +114 -0
- execweave/viewer_projection.py +488 -0
- execweave/viewer_projection_base.py +522 -0
- execweave/viewer_projection_bridges.py +214 -0
- execweave/viewer_recorded_sources.py +146 -0
- execweave/viewer_run_assessment.py +274 -0
- execweave/viewer_run_guide.py +175 -0
- execweave/viewer_runtime_evidence.py +258 -0
- execweave/viewer_semantic_projection.py +641 -0
- execweave/viewer_session_flow.py +491 -0
- execweave/viewer_structure_share.py +132 -0
- execweave/viewer_task_validation.py +241 -0
- execweave/viewer_tool_mirror_identity.py +75 -0
- execweave/viewer_workflow_mode.py +127 -0
- execweave/workflow.py +183 -0
- execweave-1.0.0.dist-info/METADATA +462 -0
- execweave-1.0.0.dist-info/RECORD +234 -0
- execweave-1.0.0.dist-info/WHEEL +4 -0
- execweave-1.0.0.dist-info/entry_points.txt +30 -0
- execweave-1.0.0.dist-info/licenses/LICENSE +16 -0
|
@@ -0,0 +1,1509 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
from dataclasses import asdict, dataclass
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Mapping
|
|
9
|
+
|
|
10
|
+
from .codex_adapter import append_semantic_records
|
|
11
|
+
from .content_evidence import content_observation_event
|
|
12
|
+
from .content_store import ContentReference, FullFidelityContentStore
|
|
13
|
+
|
|
14
|
+
CODEX_ROLLOUT_TRACE_ROOT_ENV = "CODEX_ROLLOUT_TRACE_ROOT"
|
|
15
|
+
|
|
16
|
+
_STATE_FILE = "state.json"
|
|
17
|
+
_MANIFEST_FILE = "manifest.json"
|
|
18
|
+
_RAW_TRACE_FILE = "trace.jsonl"
|
|
19
|
+
_BUNDLE_PREFIX = "trace-"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True)
|
|
23
|
+
class CodexRolloutImportResult:
|
|
24
|
+
"""Summary of one post-run Codex rollout-trace import."""
|
|
25
|
+
|
|
26
|
+
status: str
|
|
27
|
+
trace_root: str
|
|
28
|
+
bundle_count: int = 0
|
|
29
|
+
reduced_bundle_count: int = 0
|
|
30
|
+
semantic_event_count: int = 0
|
|
31
|
+
raw_payload_count: int = 0
|
|
32
|
+
conversation_item_count: int = 0
|
|
33
|
+
reasoning_text_count: int = 0
|
|
34
|
+
reasoning_summary_count: int = 0
|
|
35
|
+
encoded_reasoning_count: int = 0
|
|
36
|
+
agent_message_count: int = 0
|
|
37
|
+
interaction_edge_count: int = 0
|
|
38
|
+
tool_call_count: int = 0
|
|
39
|
+
inference_call_count: int = 0
|
|
40
|
+
terminal_operation_count: int = 0
|
|
41
|
+
code_cell_count: int = 0
|
|
42
|
+
errors: tuple[str, ...] = ()
|
|
43
|
+
|
|
44
|
+
def to_dict(self) -> dict[str, object]:
|
|
45
|
+
return asdict(self)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def codex_rollout_trace_environment(run_dir: str | Path) -> dict[str, str]:
|
|
49
|
+
"""Environment needed to opt Codex into its local raw rollout trace."""
|
|
50
|
+
|
|
51
|
+
root = Path(run_dir).expanduser().resolve() / "codex-rollout-trace"
|
|
52
|
+
return {CODEX_ROLLOUT_TRACE_ROOT_ENV: str(root)}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _iso_from_unix_ms(value: object, *, fallback: str | None = None) -> str:
|
|
56
|
+
if isinstance(value, (int, float)) and not isinstance(value, bool):
|
|
57
|
+
return datetime.fromtimestamp(float(value) / 1000.0, timezone.utc).isoformat().replace(
|
|
58
|
+
"+00:00", "Z"
|
|
59
|
+
)
|
|
60
|
+
if fallback is not None:
|
|
61
|
+
return fallback
|
|
62
|
+
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _entity(
|
|
66
|
+
entity_type: str,
|
|
67
|
+
entity_id: str,
|
|
68
|
+
*,
|
|
69
|
+
name: str | None = None,
|
|
70
|
+
attributes: Mapping[str, Any] | None = None,
|
|
71
|
+
) -> dict[str, Any]:
|
|
72
|
+
return {
|
|
73
|
+
"type": entity_type,
|
|
74
|
+
"id": entity_id,
|
|
75
|
+
"name": name,
|
|
76
|
+
"attributes": dict(attributes or {}),
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _event(
|
|
81
|
+
*,
|
|
82
|
+
timestamp: str,
|
|
83
|
+
event_type: str,
|
|
84
|
+
relation: str,
|
|
85
|
+
source: dict[str, Any],
|
|
86
|
+
target: dict[str, Any],
|
|
87
|
+
attributes: Mapping[str, Any] | None = None,
|
|
88
|
+
) -> dict[str, Any]:
|
|
89
|
+
merged: dict[str, Any] = {
|
|
90
|
+
"backend": "semantic",
|
|
91
|
+
"provider": "codex",
|
|
92
|
+
"evidence_source": "codex_rollout_trace",
|
|
93
|
+
"attribution": "codex_rollout_trace",
|
|
94
|
+
"causal": False,
|
|
95
|
+
"inferred": False,
|
|
96
|
+
}
|
|
97
|
+
if attributes:
|
|
98
|
+
merged.update(attributes)
|
|
99
|
+
return {
|
|
100
|
+
"timestamp": timestamp,
|
|
101
|
+
"event_type": event_type,
|
|
102
|
+
"relation": relation,
|
|
103
|
+
"source": source,
|
|
104
|
+
"target": target,
|
|
105
|
+
"attributes": merged,
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _thread_entity(thread: Mapping[str, Any], *, rollout_id: str) -> dict[str, Any]:
|
|
110
|
+
thread_id = str(thread.get("thread_id") or "unknown")
|
|
111
|
+
path = thread.get("agent_path")
|
|
112
|
+
nickname = thread.get("nickname")
|
|
113
|
+
name = (
|
|
114
|
+
str(path)
|
|
115
|
+
if isinstance(path, str) and path
|
|
116
|
+
else str(nickname)
|
|
117
|
+
if isinstance(nickname, str) and nickname
|
|
118
|
+
else f"Codex agent {thread_id}"
|
|
119
|
+
)
|
|
120
|
+
attrs: dict[str, Any] = {
|
|
121
|
+
"provider": "codex",
|
|
122
|
+
"rollout_id": rollout_id,
|
|
123
|
+
"thread_id": thread_id,
|
|
124
|
+
}
|
|
125
|
+
for key in ("agent_path", "nickname", "origin", "execution", "default_model"):
|
|
126
|
+
value = thread.get(key)
|
|
127
|
+
if value is not None:
|
|
128
|
+
attrs[key] = value
|
|
129
|
+
return _entity(
|
|
130
|
+
"agent",
|
|
131
|
+
f"agent:codex:rollout:{rollout_id}:thread:{thread_id}",
|
|
132
|
+
name=name,
|
|
133
|
+
attributes=attrs,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _unknown_thread_entity(thread_id: str, *, rollout_id: str) -> dict[str, Any]:
|
|
138
|
+
return _entity(
|
|
139
|
+
"agent",
|
|
140
|
+
f"agent:codex:rollout:{rollout_id}:thread:{thread_id}",
|
|
141
|
+
name=f"Codex agent {thread_id}",
|
|
142
|
+
attributes={
|
|
143
|
+
"provider": "codex",
|
|
144
|
+
"rollout_id": rollout_id,
|
|
145
|
+
"thread_id": thread_id,
|
|
146
|
+
"unresolved_thread_metadata": True,
|
|
147
|
+
},
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _conversation_entity(
|
|
152
|
+
item_id: str, item: Mapping[str, Any], *, rollout_id: str
|
|
153
|
+
) -> dict[str, Any]:
|
|
154
|
+
attrs: dict[str, Any] = {"provider": "codex", "rollout_id": rollout_id, "item_id": item_id}
|
|
155
|
+
for key in ("thread_id", "codex_turn_id", "role", "channel", "kind", "call_id", "agent_message"):
|
|
156
|
+
value = item.get(key)
|
|
157
|
+
if value is not None:
|
|
158
|
+
attrs[key] = value
|
|
159
|
+
return _entity(
|
|
160
|
+
"conversation_item",
|
|
161
|
+
f"conversation-item:codex:{rollout_id}:{item_id}",
|
|
162
|
+
name=f"{item.get('role', 'conversation')}:{item.get('kind', 'item')}",
|
|
163
|
+
attributes=attrs,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _message_entity(item_id: str, item: Mapping[str, Any], *, rollout_id: str) -> dict[str, Any]:
|
|
168
|
+
routing = item.get("agent_message")
|
|
169
|
+
attrs: dict[str, Any] = {
|
|
170
|
+
"provider": "codex",
|
|
171
|
+
"rollout_id": rollout_id,
|
|
172
|
+
"conversation_item_id": item_id,
|
|
173
|
+
"model_visible": True,
|
|
174
|
+
}
|
|
175
|
+
if isinstance(routing, dict):
|
|
176
|
+
attrs["author"] = routing.get("author")
|
|
177
|
+
attrs["recipient"] = routing.get("recipient")
|
|
178
|
+
return _entity(
|
|
179
|
+
"agent_message",
|
|
180
|
+
f"agent-message:codex:{rollout_id}:{item_id}",
|
|
181
|
+
name="Codex agent message",
|
|
182
|
+
attributes=attrs,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _tool_call_entity(call_id: str, call: Mapping[str, Any], *, rollout_id: str) -> dict[str, Any]:
|
|
187
|
+
attrs: dict[str, Any] = {
|
|
188
|
+
"provider": "codex",
|
|
189
|
+
"rollout_id": rollout_id,
|
|
190
|
+
"tool_call_id": call_id,
|
|
191
|
+
}
|
|
192
|
+
for key in (
|
|
193
|
+
"mcp_call_id",
|
|
194
|
+
"model_visible_call_id",
|
|
195
|
+
"code_mode_runtime_tool_id",
|
|
196
|
+
"thread_id",
|
|
197
|
+
"started_by_codex_turn_id",
|
|
198
|
+
"execution",
|
|
199
|
+
"requester",
|
|
200
|
+
"kind",
|
|
201
|
+
"summary",
|
|
202
|
+
):
|
|
203
|
+
value = call.get(key)
|
|
204
|
+
if value is not None:
|
|
205
|
+
attrs[key] = value
|
|
206
|
+
kind = call.get("kind")
|
|
207
|
+
kind_name = _tag_name(kind) or "tool"
|
|
208
|
+
return _entity(
|
|
209
|
+
"tool_call",
|
|
210
|
+
f"tool-call:codex:rollout:{rollout_id}:{call_id}",
|
|
211
|
+
name=kind_name,
|
|
212
|
+
attributes=attrs,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _inference_entity(call_id: str, call: Mapping[str, Any], *, rollout_id: str) -> dict[str, Any]:
|
|
217
|
+
attrs: dict[str, Any] = {
|
|
218
|
+
"provider": "codex",
|
|
219
|
+
"rollout_id": rollout_id,
|
|
220
|
+
"inference_call_id": call_id,
|
|
221
|
+
}
|
|
222
|
+
for key in (
|
|
223
|
+
"thread_id",
|
|
224
|
+
"codex_turn_id",
|
|
225
|
+
"execution",
|
|
226
|
+
"model",
|
|
227
|
+
"provider_name",
|
|
228
|
+
"response_id",
|
|
229
|
+
"upstream_request_id",
|
|
230
|
+
"usage",
|
|
231
|
+
"request_item_ids",
|
|
232
|
+
"response_item_ids",
|
|
233
|
+
"tool_call_ids_started_by_response",
|
|
234
|
+
):
|
|
235
|
+
value = call.get(key)
|
|
236
|
+
if value is not None:
|
|
237
|
+
attrs[key] = value
|
|
238
|
+
return _entity(
|
|
239
|
+
"inference_call",
|
|
240
|
+
f"inference-call:codex:{rollout_id}:{call_id}",
|
|
241
|
+
name=str(call.get("model") or "Codex inference"),
|
|
242
|
+
attributes=attrs,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _terminal_entity(
|
|
247
|
+
operation_id: str, operation: Mapping[str, Any], *, rollout_id: str
|
|
248
|
+
) -> dict[str, Any]:
|
|
249
|
+
attrs: dict[str, Any] = {
|
|
250
|
+
"provider": "codex",
|
|
251
|
+
"rollout_id": rollout_id,
|
|
252
|
+
"operation_id": operation_id,
|
|
253
|
+
}
|
|
254
|
+
for key in ("terminal_id", "tool_call_id", "kind", "execution"):
|
|
255
|
+
value = operation.get(key)
|
|
256
|
+
if value is not None:
|
|
257
|
+
attrs[key] = value
|
|
258
|
+
return _entity(
|
|
259
|
+
"terminal_operation",
|
|
260
|
+
f"terminal-operation:codex:{rollout_id}:{operation_id}",
|
|
261
|
+
name=str(operation.get("kind") or "terminal operation"),
|
|
262
|
+
attributes=attrs,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _code_cell_entity(cell_id: str, cell: Mapping[str, Any], *, rollout_id: str) -> dict[str, Any]:
|
|
267
|
+
attrs: dict[str, Any] = {
|
|
268
|
+
"provider": "codex",
|
|
269
|
+
"rollout_id": rollout_id,
|
|
270
|
+
"code_cell_id": cell_id,
|
|
271
|
+
}
|
|
272
|
+
for key in (
|
|
273
|
+
"model_visible_call_id",
|
|
274
|
+
"thread_id",
|
|
275
|
+
"codex_turn_id",
|
|
276
|
+
"runtime_cell_id",
|
|
277
|
+
"execution",
|
|
278
|
+
"runtime_status",
|
|
279
|
+
"nested_tool_call_ids",
|
|
280
|
+
"wait_tool_call_ids",
|
|
281
|
+
):
|
|
282
|
+
value = cell.get(key)
|
|
283
|
+
if value is not None:
|
|
284
|
+
attrs[key] = value
|
|
285
|
+
return _entity(
|
|
286
|
+
"code_cell",
|
|
287
|
+
f"code-cell:codex:{rollout_id}:{cell_id}",
|
|
288
|
+
name="Codex code-mode cell",
|
|
289
|
+
attributes=attrs,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _interaction_entity(
|
|
294
|
+
edge_id: str, edge: Mapping[str, Any], *, rollout_id: str
|
|
295
|
+
) -> dict[str, Any]:
|
|
296
|
+
kind = _tag_name(edge.get("kind")) or str(edge.get("kind") or "interaction")
|
|
297
|
+
attrs = {
|
|
298
|
+
"provider": "codex",
|
|
299
|
+
"rollout_id": rollout_id,
|
|
300
|
+
"interaction_edge_id": edge_id,
|
|
301
|
+
"kind": edge.get("kind"),
|
|
302
|
+
"source_anchor": edge.get("source"),
|
|
303
|
+
"target_anchor": edge.get("target"),
|
|
304
|
+
"started_at_unix_ms": edge.get("started_at_unix_ms"),
|
|
305
|
+
"ended_at_unix_ms": edge.get("ended_at_unix_ms"),
|
|
306
|
+
"carried_item_ids": edge.get("carried_item_ids") or [],
|
|
307
|
+
"carried_raw_payload_ids": edge.get("carried_raw_payload_ids") or [],
|
|
308
|
+
}
|
|
309
|
+
return _entity(
|
|
310
|
+
"agent_interaction",
|
|
311
|
+
f"agent-interaction:codex:{rollout_id}:{edge_id}",
|
|
312
|
+
name=kind,
|
|
313
|
+
attributes=attrs,
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def _tag_name(value: object) -> str | None:
|
|
318
|
+
if isinstance(value, str):
|
|
319
|
+
return value
|
|
320
|
+
if isinstance(value, dict):
|
|
321
|
+
tagged = value.get("type")
|
|
322
|
+
if isinstance(tagged, str):
|
|
323
|
+
return tagged
|
|
324
|
+
return None
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def _content_kind_suffix(kind: object) -> str:
|
|
328
|
+
if isinstance(kind, str) and kind:
|
|
329
|
+
return kind
|
|
330
|
+
if isinstance(kind, dict):
|
|
331
|
+
value = kind.get("type")
|
|
332
|
+
if isinstance(value, str) and value:
|
|
333
|
+
extra = kind.get("value")
|
|
334
|
+
if isinstance(extra, str) and extra:
|
|
335
|
+
return f"{value}.{extra}"
|
|
336
|
+
return value
|
|
337
|
+
return "unknown"
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _raw_payload_reference(
|
|
341
|
+
*,
|
|
342
|
+
bundle: Path,
|
|
343
|
+
raw_payload_id: str,
|
|
344
|
+
raw_ref: Mapping[str, Any],
|
|
345
|
+
store: FullFidelityContentStore,
|
|
346
|
+
cache: dict[str, ContentReference],
|
|
347
|
+
) -> ContentReference | None:
|
|
348
|
+
cache_key = f"{bundle}:{raw_payload_id}"
|
|
349
|
+
if cache_key in cache:
|
|
350
|
+
return cache[cache_key]
|
|
351
|
+
relative = raw_ref.get("path")
|
|
352
|
+
if not isinstance(relative, str) or not relative:
|
|
353
|
+
return None
|
|
354
|
+
try:
|
|
355
|
+
path = (bundle / relative).resolve()
|
|
356
|
+
path.relative_to(bundle.resolve())
|
|
357
|
+
except (OSError, ValueError):
|
|
358
|
+
return None
|
|
359
|
+
if not path.is_file():
|
|
360
|
+
return None
|
|
361
|
+
kind = _content_kind_suffix(raw_ref.get("kind"))
|
|
362
|
+
raw = path.read_bytes()
|
|
363
|
+
try:
|
|
364
|
+
json.loads(raw.decode("utf-8"))
|
|
365
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
366
|
+
reference = store.put_bytes(
|
|
367
|
+
raw,
|
|
368
|
+
content_kind=f"codex.rollout.raw_payload.{kind}",
|
|
369
|
+
media_type="application/octet-stream",
|
|
370
|
+
representation="codex_rollout_raw_payload",
|
|
371
|
+
)
|
|
372
|
+
else:
|
|
373
|
+
reference = store.put_bytes(
|
|
374
|
+
raw,
|
|
375
|
+
content_kind=f"codex.rollout.raw_payload.{kind}",
|
|
376
|
+
media_type="application/json",
|
|
377
|
+
representation="codex_rollout_raw_json",
|
|
378
|
+
)
|
|
379
|
+
cache[cache_key] = reference
|
|
380
|
+
return reference
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _content_event(
|
|
384
|
+
*,
|
|
385
|
+
store: FullFidelityContentStore,
|
|
386
|
+
value: Any,
|
|
387
|
+
content_kind: str,
|
|
388
|
+
timestamp: str,
|
|
389
|
+
source: dict[str, Any],
|
|
390
|
+
relation: str,
|
|
391
|
+
observed_field: str,
|
|
392
|
+
attributes: Mapping[str, Any] | None = None,
|
|
393
|
+
) -> dict[str, Any]:
|
|
394
|
+
reference = (
|
|
395
|
+
store.put_text(value, content_kind=content_kind)
|
|
396
|
+
if isinstance(value, str)
|
|
397
|
+
else store.put_json(value, content_kind=content_kind)
|
|
398
|
+
)
|
|
399
|
+
return content_observation_event(
|
|
400
|
+
timestamp=timestamp,
|
|
401
|
+
provider="codex",
|
|
402
|
+
source=source,
|
|
403
|
+
reference=reference,
|
|
404
|
+
relation=relation,
|
|
405
|
+
observed_field=observed_field,
|
|
406
|
+
evidence_source="codex_rollout_trace",
|
|
407
|
+
attribution="codex_rollout_trace",
|
|
408
|
+
event_type="semantic.codex.rollout.content.observed",
|
|
409
|
+
attributes=dict(attributes or {}),
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def _raw_content_event(
|
|
414
|
+
*,
|
|
415
|
+
reference: ContentReference,
|
|
416
|
+
timestamp: str,
|
|
417
|
+
source: dict[str, Any],
|
|
418
|
+
relation: str,
|
|
419
|
+
observed_field: str,
|
|
420
|
+
attributes: Mapping[str, Any] | None = None,
|
|
421
|
+
) -> dict[str, Any]:
|
|
422
|
+
return content_observation_event(
|
|
423
|
+
timestamp=timestamp,
|
|
424
|
+
provider="codex",
|
|
425
|
+
source=source,
|
|
426
|
+
reference=reference,
|
|
427
|
+
relation=relation,
|
|
428
|
+
observed_field=observed_field,
|
|
429
|
+
evidence_source="codex_rollout_trace",
|
|
430
|
+
attribution="codex_rollout_trace",
|
|
431
|
+
event_type="semantic.codex.rollout.raw_payload.observed",
|
|
432
|
+
attributes=dict(attributes or {}),
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _body_parts(item: Mapping[str, Any]) -> list[dict[str, Any]]:
|
|
437
|
+
body = item.get("body")
|
|
438
|
+
if not isinstance(body, dict):
|
|
439
|
+
return []
|
|
440
|
+
parts = body.get("parts")
|
|
441
|
+
return [part for part in parts if isinstance(part, dict)] if isinstance(parts, list) else []
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def _find_thread_by_path(
|
|
445
|
+
path: object,
|
|
446
|
+
*,
|
|
447
|
+
threads: Mapping[str, Mapping[str, Any]],
|
|
448
|
+
rollout_id: str,
|
|
449
|
+
) -> dict[str, Any] | None:
|
|
450
|
+
if not isinstance(path, str) or not path:
|
|
451
|
+
return None
|
|
452
|
+
for thread in threads.values():
|
|
453
|
+
if thread.get("agent_path") == path:
|
|
454
|
+
return _thread_entity(thread, rollout_id=rollout_id)
|
|
455
|
+
return _entity(
|
|
456
|
+
"agent",
|
|
457
|
+
f"agent:codex:rollout:{rollout_id}:path:{path}",
|
|
458
|
+
name=path,
|
|
459
|
+
attributes={
|
|
460
|
+
"provider": "codex",
|
|
461
|
+
"rollout_id": rollout_id,
|
|
462
|
+
"agent_path": path,
|
|
463
|
+
"unresolved_thread_id": True,
|
|
464
|
+
},
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def _thread_for_item(
|
|
469
|
+
item: Mapping[str, Any],
|
|
470
|
+
*,
|
|
471
|
+
threads: Mapping[str, Mapping[str, Any]],
|
|
472
|
+
rollout_id: str,
|
|
473
|
+
) -> dict[str, Any]:
|
|
474
|
+
thread_id = item.get("thread_id")
|
|
475
|
+
if isinstance(thread_id, str):
|
|
476
|
+
thread = threads.get(thread_id)
|
|
477
|
+
if isinstance(thread, Mapping):
|
|
478
|
+
return _thread_entity(thread, rollout_id=rollout_id)
|
|
479
|
+
return _unknown_thread_entity(thread_id, rollout_id=rollout_id)
|
|
480
|
+
return _unknown_thread_entity("unknown", rollout_id=rollout_id)
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
def _anchor_entity(
|
|
484
|
+
anchor: object,
|
|
485
|
+
*,
|
|
486
|
+
rollout_id: str,
|
|
487
|
+
threads: Mapping[str, Mapping[str, Any]],
|
|
488
|
+
conversation_items: Mapping[str, Mapping[str, Any]],
|
|
489
|
+
tool_calls: Mapping[str, Mapping[str, Any]],
|
|
490
|
+
) -> dict[str, Any] | None:
|
|
491
|
+
if not isinstance(anchor, dict):
|
|
492
|
+
return None
|
|
493
|
+
anchor_type = anchor.get("type")
|
|
494
|
+
if anchor_type == "thread":
|
|
495
|
+
thread_id = anchor.get("thread_id")
|
|
496
|
+
if isinstance(thread_id, str):
|
|
497
|
+
thread = threads.get(thread_id)
|
|
498
|
+
return (
|
|
499
|
+
_thread_entity(thread, rollout_id=rollout_id)
|
|
500
|
+
if isinstance(thread, Mapping)
|
|
501
|
+
else _unknown_thread_entity(thread_id, rollout_id=rollout_id)
|
|
502
|
+
)
|
|
503
|
+
if anchor_type == "conversation_item":
|
|
504
|
+
item_id = anchor.get("item_id")
|
|
505
|
+
if isinstance(item_id, str):
|
|
506
|
+
item = conversation_items.get(item_id)
|
|
507
|
+
return _conversation_entity(
|
|
508
|
+
item_id,
|
|
509
|
+
item if isinstance(item, Mapping) else {},
|
|
510
|
+
rollout_id=rollout_id,
|
|
511
|
+
)
|
|
512
|
+
if anchor_type == "tool_call":
|
|
513
|
+
tool_call_id = anchor.get("tool_call_id")
|
|
514
|
+
if isinstance(tool_call_id, str):
|
|
515
|
+
call = tool_calls.get(tool_call_id)
|
|
516
|
+
return _tool_call_entity(
|
|
517
|
+
tool_call_id,
|
|
518
|
+
call if isinstance(call, Mapping) else {},
|
|
519
|
+
rollout_id=rollout_id,
|
|
520
|
+
)
|
|
521
|
+
return None
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
def _owner_agent_for_anchor(
|
|
525
|
+
anchor: object,
|
|
526
|
+
*,
|
|
527
|
+
rollout_id: str,
|
|
528
|
+
threads: Mapping[str, Mapping[str, Any]],
|
|
529
|
+
conversation_items: Mapping[str, Mapping[str, Any]],
|
|
530
|
+
tool_calls: Mapping[str, Mapping[str, Any]],
|
|
531
|
+
) -> dict[str, Any] | None:
|
|
532
|
+
if not isinstance(anchor, dict):
|
|
533
|
+
return None
|
|
534
|
+
anchor_type = anchor.get("type")
|
|
535
|
+
thread_id: object = None
|
|
536
|
+
if anchor_type == "thread":
|
|
537
|
+
thread_id = anchor.get("thread_id")
|
|
538
|
+
elif anchor_type == "conversation_item":
|
|
539
|
+
item_id = anchor.get("item_id")
|
|
540
|
+
item = conversation_items.get(str(item_id)) if item_id is not None else None
|
|
541
|
+
if isinstance(item, Mapping):
|
|
542
|
+
thread_id = item.get("thread_id")
|
|
543
|
+
elif anchor_type == "tool_call":
|
|
544
|
+
call_id = anchor.get("tool_call_id")
|
|
545
|
+
call = tool_calls.get(str(call_id)) if call_id is not None else None
|
|
546
|
+
if isinstance(call, Mapping):
|
|
547
|
+
thread_id = call.get("thread_id")
|
|
548
|
+
if not isinstance(thread_id, str) or not thread_id:
|
|
549
|
+
return None
|
|
550
|
+
thread = threads.get(thread_id)
|
|
551
|
+
return (
|
|
552
|
+
_thread_entity(thread, rollout_id=rollout_id)
|
|
553
|
+
if isinstance(thread, Mapping)
|
|
554
|
+
else _unknown_thread_entity(thread_id, rollout_id=rollout_id)
|
|
555
|
+
)
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def _direct_interaction_relation(kind: object) -> str:
|
|
559
|
+
normalized = _tag_name(kind) or str(kind or "")
|
|
560
|
+
mapping = {
|
|
561
|
+
"spawn_agent": "SPAWNED_AGENT",
|
|
562
|
+
"assign_agent_task": "ASSIGNED_AGENT_TASK",
|
|
563
|
+
"send_message": "SENT_AGENT_MESSAGE",
|
|
564
|
+
"agent_result": "RETURNED_AGENT_RESULT",
|
|
565
|
+
"close_agent": "CLOSED_AGENT",
|
|
566
|
+
}
|
|
567
|
+
return mapping.get(normalized, f"CODEX_INTERACTION_{normalized.upper() or 'UNKNOWN'}")
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
def _state_events(
|
|
571
|
+
state: Mapping[str, Any],
|
|
572
|
+
*,
|
|
573
|
+
bundle: Path,
|
|
574
|
+
store: FullFidelityContentStore,
|
|
575
|
+
) -> tuple[list[dict[str, Any]], dict[str, int]]:
|
|
576
|
+
rollout_id = str(state.get("rollout_id") or state.get("trace_id") or bundle.name)
|
|
577
|
+
trace_id = str(state.get("trace_id") or bundle.name)
|
|
578
|
+
started = _iso_from_unix_ms(state.get("started_at_unix_ms"))
|
|
579
|
+
ended = _iso_from_unix_ms(state.get("ended_at_unix_ms"), fallback=started)
|
|
580
|
+
|
|
581
|
+
threads_raw = state.get("threads")
|
|
582
|
+
conversations_raw = state.get("conversation_items")
|
|
583
|
+
tools_raw = state.get("tool_calls")
|
|
584
|
+
inferences_raw = state.get("inference_calls")
|
|
585
|
+
interactions_raw = state.get("interaction_edges")
|
|
586
|
+
terminal_ops_raw = state.get("terminal_operations")
|
|
587
|
+
code_cells_raw = state.get("code_cells")
|
|
588
|
+
raw_payloads_raw = state.get("raw_payloads")
|
|
589
|
+
|
|
590
|
+
threads = (
|
|
591
|
+
{str(key): value for key, value in threads_raw.items() if isinstance(value, dict)}
|
|
592
|
+
if isinstance(threads_raw, dict)
|
|
593
|
+
else {}
|
|
594
|
+
)
|
|
595
|
+
conversation_items = (
|
|
596
|
+
{str(key): value for key, value in conversations_raw.items() if isinstance(value, dict)}
|
|
597
|
+
if isinstance(conversations_raw, dict)
|
|
598
|
+
else {}
|
|
599
|
+
)
|
|
600
|
+
tool_calls = (
|
|
601
|
+
{str(key): value for key, value in tools_raw.items() if isinstance(value, dict)}
|
|
602
|
+
if isinstance(tools_raw, dict)
|
|
603
|
+
else {}
|
|
604
|
+
)
|
|
605
|
+
inference_calls = (
|
|
606
|
+
{str(key): value for key, value in inferences_raw.items() if isinstance(value, dict)}
|
|
607
|
+
if isinstance(inferences_raw, dict)
|
|
608
|
+
else {}
|
|
609
|
+
)
|
|
610
|
+
interaction_edges = (
|
|
611
|
+
{str(key): value for key, value in interactions_raw.items() if isinstance(value, dict)}
|
|
612
|
+
if isinstance(interactions_raw, dict)
|
|
613
|
+
else {}
|
|
614
|
+
)
|
|
615
|
+
terminal_operations = (
|
|
616
|
+
{str(key): value for key, value in terminal_ops_raw.items() if isinstance(value, dict)}
|
|
617
|
+
if isinstance(terminal_ops_raw, dict)
|
|
618
|
+
else {}
|
|
619
|
+
)
|
|
620
|
+
code_cells = (
|
|
621
|
+
{str(key): value for key, value in code_cells_raw.items() if isinstance(value, dict)}
|
|
622
|
+
if isinstance(code_cells_raw, dict)
|
|
623
|
+
else {}
|
|
624
|
+
)
|
|
625
|
+
raw_payloads = (
|
|
626
|
+
{str(key): value for key, value in raw_payloads_raw.items() if isinstance(value, dict)}
|
|
627
|
+
if isinstance(raw_payloads_raw, dict)
|
|
628
|
+
else {}
|
|
629
|
+
)
|
|
630
|
+
|
|
631
|
+
root_thread_id = str(state.get("root_thread_id") or "unknown")
|
|
632
|
+
root_thread = threads.get(root_thread_id)
|
|
633
|
+
root_agent = (
|
|
634
|
+
_thread_entity(root_thread, rollout_id=rollout_id)
|
|
635
|
+
if isinstance(root_thread, Mapping)
|
|
636
|
+
else _unknown_thread_entity(root_thread_id, rollout_id=rollout_id)
|
|
637
|
+
)
|
|
638
|
+
|
|
639
|
+
events: list[dict[str, Any]] = []
|
|
640
|
+
counts = {
|
|
641
|
+
"raw_payload_count": 0,
|
|
642
|
+
"conversation_item_count": len(conversation_items),
|
|
643
|
+
"reasoning_text_count": 0,
|
|
644
|
+
"reasoning_summary_count": 0,
|
|
645
|
+
"encoded_reasoning_count": 0,
|
|
646
|
+
"agent_message_count": 0,
|
|
647
|
+
"interaction_edge_count": len(interaction_edges),
|
|
648
|
+
"tool_call_count": len(tool_calls),
|
|
649
|
+
"inference_call_count": len(inference_calls),
|
|
650
|
+
"terminal_operation_count": len(terminal_operations),
|
|
651
|
+
"code_cell_count": len(code_cells),
|
|
652
|
+
}
|
|
653
|
+
raw_cache: dict[str, ContentReference] = {}
|
|
654
|
+
|
|
655
|
+
events.append(
|
|
656
|
+
_content_event(
|
|
657
|
+
store=store,
|
|
658
|
+
value=state,
|
|
659
|
+
content_kind="codex.rollout.reduced_state",
|
|
660
|
+
timestamp=ended,
|
|
661
|
+
source=root_agent,
|
|
662
|
+
relation="HAS_REDUCED_ROLLOUT_STATE",
|
|
663
|
+
observed_field="state.json",
|
|
664
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
665
|
+
)
|
|
666
|
+
)
|
|
667
|
+
manifest_path = bundle / _MANIFEST_FILE
|
|
668
|
+
if manifest_path.is_file():
|
|
669
|
+
try:
|
|
670
|
+
manifest_value: Any = json.loads(manifest_path.read_text(encoding="utf-8"))
|
|
671
|
+
except (OSError, UnicodeDecodeError, json.JSONDecodeError):
|
|
672
|
+
manifest_value = manifest_path.read_bytes().decode("utf-8", errors="replace")
|
|
673
|
+
events.append(
|
|
674
|
+
_content_event(
|
|
675
|
+
store=store,
|
|
676
|
+
value=manifest_value,
|
|
677
|
+
content_kind="codex.rollout.manifest",
|
|
678
|
+
timestamp=started,
|
|
679
|
+
source=root_agent,
|
|
680
|
+
relation="HAS_ROLLOUT_MANIFEST",
|
|
681
|
+
observed_field="manifest.json",
|
|
682
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
683
|
+
)
|
|
684
|
+
)
|
|
685
|
+
trace_path = bundle / _RAW_TRACE_FILE
|
|
686
|
+
if trace_path.is_file():
|
|
687
|
+
trace_reference = store.put_bytes(
|
|
688
|
+
trace_path.read_bytes(),
|
|
689
|
+
content_kind="codex.rollout.raw_event_log",
|
|
690
|
+
media_type="application/x-ndjson",
|
|
691
|
+
representation="codex_rollout_trace_jsonl",
|
|
692
|
+
)
|
|
693
|
+
events.append(
|
|
694
|
+
_raw_content_event(
|
|
695
|
+
reference=trace_reference,
|
|
696
|
+
timestamp=ended,
|
|
697
|
+
source=root_agent,
|
|
698
|
+
relation="HAS_RAW_ROLLOUT_EVENT_LOG",
|
|
699
|
+
observed_field="trace.jsonl",
|
|
700
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
701
|
+
)
|
|
702
|
+
)
|
|
703
|
+
|
|
704
|
+
for thread_id, thread in threads.items():
|
|
705
|
+
agent = _thread_entity(thread, rollout_id=rollout_id)
|
|
706
|
+
execution = thread.get("execution")
|
|
707
|
+
thread_started = (
|
|
708
|
+
execution.get("started_at_unix_ms")
|
|
709
|
+
if isinstance(execution, dict)
|
|
710
|
+
else state.get("started_at_unix_ms")
|
|
711
|
+
)
|
|
712
|
+
events.append(
|
|
713
|
+
_event(
|
|
714
|
+
timestamp=_iso_from_unix_ms(thread_started, fallback=started),
|
|
715
|
+
event_type="semantic.codex.rollout.agent.observed",
|
|
716
|
+
relation="HAS_AGENT_THREAD",
|
|
717
|
+
source=root_agent,
|
|
718
|
+
target=agent,
|
|
719
|
+
attributes={
|
|
720
|
+
"trace_id": trace_id,
|
|
721
|
+
"rollout_id": rollout_id,
|
|
722
|
+
"thread_id": thread_id,
|
|
723
|
+
"agent_path": thread.get("agent_path"),
|
|
724
|
+
"origin": thread.get("origin"),
|
|
725
|
+
"execution": execution,
|
|
726
|
+
},
|
|
727
|
+
)
|
|
728
|
+
)
|
|
729
|
+
origin = thread.get("origin")
|
|
730
|
+
if isinstance(origin, dict) and origin.get("type") == "spawned":
|
|
731
|
+
parent_id = origin.get("parent_thread_id")
|
|
732
|
+
if isinstance(parent_id, str):
|
|
733
|
+
parent = threads.get(parent_id)
|
|
734
|
+
parent_agent = (
|
|
735
|
+
_thread_entity(parent, rollout_id=rollout_id)
|
|
736
|
+
if isinstance(parent, Mapping)
|
|
737
|
+
else _unknown_thread_entity(parent_id, rollout_id=rollout_id)
|
|
738
|
+
)
|
|
739
|
+
events.append(
|
|
740
|
+
_event(
|
|
741
|
+
timestamp=_iso_from_unix_ms(thread_started, fallback=started),
|
|
742
|
+
event_type="semantic.codex.rollout.agent.spawned",
|
|
743
|
+
relation="SPAWNED_AGENT",
|
|
744
|
+
source=parent_agent,
|
|
745
|
+
target=agent,
|
|
746
|
+
attributes={
|
|
747
|
+
"trace_id": trace_id,
|
|
748
|
+
"rollout_id": rollout_id,
|
|
749
|
+
"spawn_edge_id": origin.get("spawn_edge_id"),
|
|
750
|
+
"task_name": origin.get("task_name"),
|
|
751
|
+
"agent_role": origin.get("agent_role"),
|
|
752
|
+
"source_semantics": "reduced_thread_origin",
|
|
753
|
+
},
|
|
754
|
+
)
|
|
755
|
+
)
|
|
756
|
+
|
|
757
|
+
for item_id, item in conversation_items.items():
|
|
758
|
+
item_ts = _iso_from_unix_ms(item.get("first_seen_at_unix_ms"), fallback=started)
|
|
759
|
+
item_entity = _conversation_entity(item_id, item, rollout_id=rollout_id)
|
|
760
|
+
owner = _thread_for_item(item, threads=threads, rollout_id=rollout_id)
|
|
761
|
+
relation = (
|
|
762
|
+
"PRODUCED_CONVERSATION_ITEM"
|
|
763
|
+
if item.get("role") in {"assistant", "tool"}
|
|
764
|
+
else "RECEIVED_CONVERSATION_ITEM"
|
|
765
|
+
)
|
|
766
|
+
events.append(
|
|
767
|
+
_event(
|
|
768
|
+
timestamp=item_ts,
|
|
769
|
+
event_type="semantic.codex.rollout.conversation.observed",
|
|
770
|
+
relation=relation,
|
|
771
|
+
source=owner,
|
|
772
|
+
target=item_entity,
|
|
773
|
+
attributes={
|
|
774
|
+
"trace_id": trace_id,
|
|
775
|
+
"rollout_id": rollout_id,
|
|
776
|
+
"role": item.get("role"),
|
|
777
|
+
"channel": item.get("channel"),
|
|
778
|
+
"kind": item.get("kind"),
|
|
779
|
+
"call_id": item.get("call_id"),
|
|
780
|
+
"model_visible": True,
|
|
781
|
+
},
|
|
782
|
+
)
|
|
783
|
+
)
|
|
784
|
+
events.append(
|
|
785
|
+
_content_event(
|
|
786
|
+
store=store,
|
|
787
|
+
value=item,
|
|
788
|
+
content_kind="codex.rollout.conversation_item",
|
|
789
|
+
timestamp=item_ts,
|
|
790
|
+
source=item_entity,
|
|
791
|
+
relation="HAS_CONVERSATION_PAYLOAD",
|
|
792
|
+
observed_field="conversation_item",
|
|
793
|
+
attributes={
|
|
794
|
+
"trace_id": trace_id,
|
|
795
|
+
"rollout_id": rollout_id,
|
|
796
|
+
"role": item.get("role"),
|
|
797
|
+
"channel": item.get("channel"),
|
|
798
|
+
"kind": item.get("kind"),
|
|
799
|
+
"model_visible": True,
|
|
800
|
+
},
|
|
801
|
+
)
|
|
802
|
+
)
|
|
803
|
+
|
|
804
|
+
kind = item.get("kind")
|
|
805
|
+
if kind == "reasoning":
|
|
806
|
+
for index, part in enumerate(_body_parts(item)):
|
|
807
|
+
part_type = part.get("type")
|
|
808
|
+
common = {
|
|
809
|
+
"trace_id": trace_id,
|
|
810
|
+
"rollout_id": rollout_id,
|
|
811
|
+
"conversation_item_id": item_id,
|
|
812
|
+
"part_index": index,
|
|
813
|
+
"channel": item.get("channel"),
|
|
814
|
+
"model_visible": True,
|
|
815
|
+
}
|
|
816
|
+
if part_type == "text" and isinstance(part.get("text"), str):
|
|
817
|
+
counts["reasoning_text_count"] += 1
|
|
818
|
+
events.append(
|
|
819
|
+
_content_event(
|
|
820
|
+
store=store,
|
|
821
|
+
value=part["text"],
|
|
822
|
+
content_kind="codex.reasoning.text",
|
|
823
|
+
timestamp=item_ts,
|
|
824
|
+
source=owner,
|
|
825
|
+
relation="PRODUCED_REASONING_TEXT",
|
|
826
|
+
observed_field=f"body.parts[{index}].text",
|
|
827
|
+
attributes={**common, "reasoning_representation": "plaintext"},
|
|
828
|
+
)
|
|
829
|
+
)
|
|
830
|
+
elif part_type == "summary" and isinstance(part.get("text"), str):
|
|
831
|
+
counts["reasoning_summary_count"] += 1
|
|
832
|
+
events.append(
|
|
833
|
+
_content_event(
|
|
834
|
+
store=store,
|
|
835
|
+
value=part["text"],
|
|
836
|
+
content_kind="codex.reasoning.summary",
|
|
837
|
+
timestamp=item_ts,
|
|
838
|
+
source=owner,
|
|
839
|
+
relation="PRODUCED_REASONING_SUMMARY",
|
|
840
|
+
observed_field=f"body.parts[{index}].text",
|
|
841
|
+
attributes={**common, "reasoning_representation": "summary"},
|
|
842
|
+
)
|
|
843
|
+
)
|
|
844
|
+
elif part_type == "encoded" and isinstance(part.get("value"), str):
|
|
845
|
+
counts["encoded_reasoning_count"] += 1
|
|
846
|
+
events.append(
|
|
847
|
+
_content_event(
|
|
848
|
+
store=store,
|
|
849
|
+
value=part["value"],
|
|
850
|
+
content_kind="codex.reasoning.encoded",
|
|
851
|
+
timestamp=item_ts,
|
|
852
|
+
source=owner,
|
|
853
|
+
relation="PRODUCED_ENCODED_REASONING",
|
|
854
|
+
observed_field=f"body.parts[{index}].value",
|
|
855
|
+
attributes={
|
|
856
|
+
**common,
|
|
857
|
+
"reasoning_representation": "encoded",
|
|
858
|
+
"reasoning_readable": False,
|
|
859
|
+
"encoded_label": part.get("label"),
|
|
860
|
+
},
|
|
861
|
+
)
|
|
862
|
+
)
|
|
863
|
+
|
|
864
|
+
routing = item.get("agent_message")
|
|
865
|
+
if isinstance(routing, dict):
|
|
866
|
+
author = _find_thread_by_path(
|
|
867
|
+
routing.get("author"), threads=threads, rollout_id=rollout_id
|
|
868
|
+
)
|
|
869
|
+
recipient = _find_thread_by_path(
|
|
870
|
+
routing.get("recipient"), threads=threads, rollout_id=rollout_id
|
|
871
|
+
)
|
|
872
|
+
if author is not None and recipient is not None:
|
|
873
|
+
counts["agent_message_count"] += 1
|
|
874
|
+
message = _message_entity(item_id, item, rollout_id=rollout_id)
|
|
875
|
+
events.append(
|
|
876
|
+
_event(
|
|
877
|
+
timestamp=item_ts,
|
|
878
|
+
event_type="semantic.codex.rollout.agent_message.sent",
|
|
879
|
+
relation="SENT_AGENT_MESSAGE",
|
|
880
|
+
source=author,
|
|
881
|
+
target=message,
|
|
882
|
+
attributes={
|
|
883
|
+
"trace_id": trace_id,
|
|
884
|
+
"rollout_id": rollout_id,
|
|
885
|
+
"conversation_item_id": item_id,
|
|
886
|
+
"author": routing.get("author"),
|
|
887
|
+
"recipient": routing.get("recipient"),
|
|
888
|
+
"model_visible": True,
|
|
889
|
+
},
|
|
890
|
+
)
|
|
891
|
+
)
|
|
892
|
+
events.append(
|
|
893
|
+
_event(
|
|
894
|
+
timestamp=item_ts,
|
|
895
|
+
event_type="semantic.codex.rollout.agent_message.delivered",
|
|
896
|
+
relation="DELIVERED_AGENT_MESSAGE",
|
|
897
|
+
source=message,
|
|
898
|
+
target=recipient,
|
|
899
|
+
attributes={
|
|
900
|
+
"trace_id": trace_id,
|
|
901
|
+
"rollout_id": rollout_id,
|
|
902
|
+
"conversation_item_id": item_id,
|
|
903
|
+
"author": routing.get("author"),
|
|
904
|
+
"recipient": routing.get("recipient"),
|
|
905
|
+
"model_visible": True,
|
|
906
|
+
},
|
|
907
|
+
)
|
|
908
|
+
)
|
|
909
|
+
events.append(
|
|
910
|
+
_content_event(
|
|
911
|
+
store=store,
|
|
912
|
+
value=item.get("body") or {},
|
|
913
|
+
content_kind="codex.agent_message.payload",
|
|
914
|
+
timestamp=item_ts,
|
|
915
|
+
source=message,
|
|
916
|
+
relation="HAS_AGENT_MESSAGE_PAYLOAD",
|
|
917
|
+
observed_field="body",
|
|
918
|
+
attributes={
|
|
919
|
+
"trace_id": trace_id,
|
|
920
|
+
"rollout_id": rollout_id,
|
|
921
|
+
"conversation_item_id": item_id,
|
|
922
|
+
"author": routing.get("author"),
|
|
923
|
+
"recipient": routing.get("recipient"),
|
|
924
|
+
"model_visible": True,
|
|
925
|
+
},
|
|
926
|
+
)
|
|
927
|
+
)
|
|
928
|
+
|
|
929
|
+
for call_id, call in inference_calls.items():
|
|
930
|
+
execution = call.get("execution")
|
|
931
|
+
call_ts = _iso_from_unix_ms(
|
|
932
|
+
execution.get("started_at_unix_ms") if isinstance(execution, dict) else None,
|
|
933
|
+
fallback=started,
|
|
934
|
+
)
|
|
935
|
+
inference = _inference_entity(call_id, call, rollout_id=rollout_id)
|
|
936
|
+
thread_id = call.get("thread_id")
|
|
937
|
+
thread = threads.get(str(thread_id)) if thread_id is not None else None
|
|
938
|
+
owner = (
|
|
939
|
+
_thread_entity(thread, rollout_id=rollout_id)
|
|
940
|
+
if isinstance(thread, Mapping)
|
|
941
|
+
else _unknown_thread_entity(str(thread_id or "unknown"), rollout_id=rollout_id)
|
|
942
|
+
)
|
|
943
|
+
events.append(
|
|
944
|
+
_event(
|
|
945
|
+
timestamp=call_ts,
|
|
946
|
+
event_type="semantic.codex.rollout.inference.started",
|
|
947
|
+
relation="MADE_INFERENCE_CALL",
|
|
948
|
+
source=owner,
|
|
949
|
+
target=inference,
|
|
950
|
+
attributes={
|
|
951
|
+
"trace_id": trace_id,
|
|
952
|
+
"rollout_id": rollout_id,
|
|
953
|
+
"execution": execution,
|
|
954
|
+
"usage": call.get("usage"),
|
|
955
|
+
},
|
|
956
|
+
)
|
|
957
|
+
)
|
|
958
|
+
model = call.get("model")
|
|
959
|
+
if isinstance(model, str) and model:
|
|
960
|
+
events.append(
|
|
961
|
+
_event(
|
|
962
|
+
timestamp=call_ts,
|
|
963
|
+
event_type="semantic.codex.rollout.inference.model",
|
|
964
|
+
relation="USED_MODEL",
|
|
965
|
+
source=inference,
|
|
966
|
+
target=_entity(
|
|
967
|
+
"model",
|
|
968
|
+
f"model:codex:{model}",
|
|
969
|
+
name=model,
|
|
970
|
+
attributes={
|
|
971
|
+
"provider": "codex",
|
|
972
|
+
"provider_name": call.get("provider_name"),
|
|
973
|
+
},
|
|
974
|
+
),
|
|
975
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
976
|
+
)
|
|
977
|
+
)
|
|
978
|
+
for field, relation in (
|
|
979
|
+
("raw_request_payload_id", "HAS_INFERENCE_REQUEST_PAYLOAD"),
|
|
980
|
+
("raw_response_payload_id", "HAS_INFERENCE_RESPONSE_PAYLOAD"),
|
|
981
|
+
):
|
|
982
|
+
raw_id = call.get(field)
|
|
983
|
+
raw_ref = raw_payloads.get(str(raw_id)) if raw_id is not None else None
|
|
984
|
+
if isinstance(raw_id, str) and isinstance(raw_ref, Mapping):
|
|
985
|
+
reference = _raw_payload_reference(
|
|
986
|
+
bundle=bundle,
|
|
987
|
+
raw_payload_id=raw_id,
|
|
988
|
+
raw_ref=raw_ref,
|
|
989
|
+
store=store,
|
|
990
|
+
cache=raw_cache,
|
|
991
|
+
)
|
|
992
|
+
if reference is not None:
|
|
993
|
+
events.append(
|
|
994
|
+
_raw_content_event(
|
|
995
|
+
reference=reference,
|
|
996
|
+
timestamp=call_ts,
|
|
997
|
+
source=inference,
|
|
998
|
+
relation=relation,
|
|
999
|
+
observed_field=field,
|
|
1000
|
+
attributes={
|
|
1001
|
+
"trace_id": trace_id,
|
|
1002
|
+
"rollout_id": rollout_id,
|
|
1003
|
+
"raw_payload_id": raw_id,
|
|
1004
|
+
"model_visible_boundary": True,
|
|
1005
|
+
},
|
|
1006
|
+
)
|
|
1007
|
+
)
|
|
1008
|
+
|
|
1009
|
+
for call_id, call in tool_calls.items():
|
|
1010
|
+
execution = call.get("execution")
|
|
1011
|
+
call_ts = _iso_from_unix_ms(
|
|
1012
|
+
execution.get("started_at_unix_ms") if isinstance(execution, dict) else None,
|
|
1013
|
+
fallback=started,
|
|
1014
|
+
)
|
|
1015
|
+
tool_call = _tool_call_entity(call_id, call, rollout_id=rollout_id)
|
|
1016
|
+
thread_id = call.get("thread_id")
|
|
1017
|
+
thread = threads.get(str(thread_id)) if thread_id is not None else None
|
|
1018
|
+
owner = (
|
|
1019
|
+
_thread_entity(thread, rollout_id=rollout_id)
|
|
1020
|
+
if isinstance(thread, Mapping)
|
|
1021
|
+
else _unknown_thread_entity(str(thread_id or "unknown"), rollout_id=rollout_id)
|
|
1022
|
+
)
|
|
1023
|
+
events.append(
|
|
1024
|
+
_event(
|
|
1025
|
+
timestamp=call_ts,
|
|
1026
|
+
event_type="semantic.codex.rollout.tool.started",
|
|
1027
|
+
relation="EXECUTED_TOOL_CALL",
|
|
1028
|
+
source=owner,
|
|
1029
|
+
target=tool_call,
|
|
1030
|
+
attributes={
|
|
1031
|
+
"trace_id": trace_id,
|
|
1032
|
+
"rollout_id": rollout_id,
|
|
1033
|
+
"tool_kind": call.get("kind"),
|
|
1034
|
+
"requester": call.get("requester"),
|
|
1035
|
+
"execution": execution,
|
|
1036
|
+
},
|
|
1037
|
+
)
|
|
1038
|
+
)
|
|
1039
|
+
kind_name = _tag_name(call.get("kind")) or "unknown"
|
|
1040
|
+
events.append(
|
|
1041
|
+
_event(
|
|
1042
|
+
timestamp=call_ts,
|
|
1043
|
+
event_type="semantic.codex.rollout.tool.kind",
|
|
1044
|
+
relation="USES_TOOL",
|
|
1045
|
+
source=tool_call,
|
|
1046
|
+
target=_entity(
|
|
1047
|
+
"tool",
|
|
1048
|
+
f"tool:codex:{kind_name}",
|
|
1049
|
+
name=kind_name,
|
|
1050
|
+
attributes={"provider": "codex", "native_kind": call.get("kind")},
|
|
1051
|
+
),
|
|
1052
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
1053
|
+
)
|
|
1054
|
+
)
|
|
1055
|
+
for field, relation in (
|
|
1056
|
+
("raw_invocation_payload_id", "HAS_TOOL_INPUT"),
|
|
1057
|
+
("raw_result_payload_id", "HAS_TOOL_OUTPUT"),
|
|
1058
|
+
):
|
|
1059
|
+
raw_id = call.get(field)
|
|
1060
|
+
raw_ref = raw_payloads.get(str(raw_id)) if raw_id is not None else None
|
|
1061
|
+
if isinstance(raw_id, str) and isinstance(raw_ref, Mapping):
|
|
1062
|
+
reference = _raw_payload_reference(
|
|
1063
|
+
bundle=bundle,
|
|
1064
|
+
raw_payload_id=raw_id,
|
|
1065
|
+
raw_ref=raw_ref,
|
|
1066
|
+
store=store,
|
|
1067
|
+
cache=raw_cache,
|
|
1068
|
+
)
|
|
1069
|
+
if reference is not None:
|
|
1070
|
+
events.append(
|
|
1071
|
+
_raw_content_event(
|
|
1072
|
+
reference=reference,
|
|
1073
|
+
timestamp=call_ts,
|
|
1074
|
+
source=tool_call,
|
|
1075
|
+
relation=relation,
|
|
1076
|
+
observed_field=field,
|
|
1077
|
+
attributes={
|
|
1078
|
+
"trace_id": trace_id,
|
|
1079
|
+
"rollout_id": rollout_id,
|
|
1080
|
+
"raw_payload_id": raw_id,
|
|
1081
|
+
"requester": call.get("requester"),
|
|
1082
|
+
"tool_kind": call.get("kind"),
|
|
1083
|
+
},
|
|
1084
|
+
)
|
|
1085
|
+
)
|
|
1086
|
+
runtime_ids = call.get("raw_runtime_payload_ids")
|
|
1087
|
+
if isinstance(runtime_ids, list):
|
|
1088
|
+
for index, raw_id in enumerate(runtime_ids):
|
|
1089
|
+
raw_ref = raw_payloads.get(str(raw_id)) if raw_id is not None else None
|
|
1090
|
+
if isinstance(raw_id, str) and isinstance(raw_ref, Mapping):
|
|
1091
|
+
reference = _raw_payload_reference(
|
|
1092
|
+
bundle=bundle,
|
|
1093
|
+
raw_payload_id=raw_id,
|
|
1094
|
+
raw_ref=raw_ref,
|
|
1095
|
+
store=store,
|
|
1096
|
+
cache=raw_cache,
|
|
1097
|
+
)
|
|
1098
|
+
if reference is not None:
|
|
1099
|
+
events.append(
|
|
1100
|
+
_raw_content_event(
|
|
1101
|
+
reference=reference,
|
|
1102
|
+
timestamp=call_ts,
|
|
1103
|
+
source=tool_call,
|
|
1104
|
+
relation="HAS_TOOL_RUNTIME_PAYLOAD",
|
|
1105
|
+
observed_field=f"raw_runtime_payload_ids[{index}]",
|
|
1106
|
+
attributes={
|
|
1107
|
+
"trace_id": trace_id,
|
|
1108
|
+
"rollout_id": rollout_id,
|
|
1109
|
+
"raw_payload_id": raw_id,
|
|
1110
|
+
},
|
|
1111
|
+
)
|
|
1112
|
+
)
|
|
1113
|
+
|
|
1114
|
+
for operation_id, operation in terminal_operations.items():
|
|
1115
|
+
execution = operation.get("execution")
|
|
1116
|
+
op_ts = _iso_from_unix_ms(
|
|
1117
|
+
execution.get("started_at_unix_ms") if isinstance(execution, dict) else None,
|
|
1118
|
+
fallback=started,
|
|
1119
|
+
)
|
|
1120
|
+
terminal = _terminal_entity(operation_id, operation, rollout_id=rollout_id)
|
|
1121
|
+
tool_call_id = operation.get("tool_call_id")
|
|
1122
|
+
call = tool_calls.get(str(tool_call_id)) if tool_call_id is not None else None
|
|
1123
|
+
source = (
|
|
1124
|
+
_tool_call_entity(str(tool_call_id), call, rollout_id=rollout_id)
|
|
1125
|
+
if tool_call_id is not None and isinstance(call, Mapping)
|
|
1126
|
+
else root_agent
|
|
1127
|
+
)
|
|
1128
|
+
events.append(
|
|
1129
|
+
_event(
|
|
1130
|
+
timestamp=op_ts,
|
|
1131
|
+
event_type="semantic.codex.rollout.terminal.operation",
|
|
1132
|
+
relation="STARTED_TERMINAL_OPERATION",
|
|
1133
|
+
source=source,
|
|
1134
|
+
target=terminal,
|
|
1135
|
+
attributes={
|
|
1136
|
+
"trace_id": trace_id,
|
|
1137
|
+
"rollout_id": rollout_id,
|
|
1138
|
+
"terminal_id": operation.get("terminal_id"),
|
|
1139
|
+
"operation_kind": operation.get("kind"),
|
|
1140
|
+
"execution": execution,
|
|
1141
|
+
},
|
|
1142
|
+
)
|
|
1143
|
+
)
|
|
1144
|
+
if "request" in operation:
|
|
1145
|
+
events.append(
|
|
1146
|
+
_content_event(
|
|
1147
|
+
store=store,
|
|
1148
|
+
value=operation["request"],
|
|
1149
|
+
content_kind="codex.terminal.request",
|
|
1150
|
+
timestamp=op_ts,
|
|
1151
|
+
source=terminal,
|
|
1152
|
+
relation="HAS_TERMINAL_REQUEST",
|
|
1153
|
+
observed_field="request",
|
|
1154
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
1155
|
+
)
|
|
1156
|
+
)
|
|
1157
|
+
if operation.get("result") is not None:
|
|
1158
|
+
events.append(
|
|
1159
|
+
_content_event(
|
|
1160
|
+
store=store,
|
|
1161
|
+
value=operation["result"],
|
|
1162
|
+
content_kind="codex.terminal.result",
|
|
1163
|
+
timestamp=_iso_from_unix_ms(
|
|
1164
|
+
execution.get("ended_at_unix_ms") if isinstance(execution, dict) else None,
|
|
1165
|
+
fallback=op_ts,
|
|
1166
|
+
),
|
|
1167
|
+
source=terminal,
|
|
1168
|
+
relation="HAS_TERMINAL_RESULT",
|
|
1169
|
+
observed_field="result",
|
|
1170
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
1171
|
+
)
|
|
1172
|
+
)
|
|
1173
|
+
|
|
1174
|
+
for cell_id, cell in code_cells.items():
|
|
1175
|
+
execution = cell.get("execution")
|
|
1176
|
+
cell_ts = _iso_from_unix_ms(
|
|
1177
|
+
execution.get("started_at_unix_ms") if isinstance(execution, dict) else None,
|
|
1178
|
+
fallback=started,
|
|
1179
|
+
)
|
|
1180
|
+
cell_entity = _code_cell_entity(cell_id, cell, rollout_id=rollout_id)
|
|
1181
|
+
thread_id = cell.get("thread_id")
|
|
1182
|
+
thread = threads.get(str(thread_id)) if thread_id is not None else None
|
|
1183
|
+
owner = (
|
|
1184
|
+
_thread_entity(thread, rollout_id=rollout_id)
|
|
1185
|
+
if isinstance(thread, Mapping)
|
|
1186
|
+
else _unknown_thread_entity(str(thread_id or "unknown"), rollout_id=rollout_id)
|
|
1187
|
+
)
|
|
1188
|
+
events.append(
|
|
1189
|
+
_event(
|
|
1190
|
+
timestamp=cell_ts,
|
|
1191
|
+
event_type="semantic.codex.rollout.code_cell.started",
|
|
1192
|
+
relation="EXECUTED_CODE_CELL",
|
|
1193
|
+
source=owner,
|
|
1194
|
+
target=cell_entity,
|
|
1195
|
+
attributes={
|
|
1196
|
+
"trace_id": trace_id,
|
|
1197
|
+
"rollout_id": rollout_id,
|
|
1198
|
+
"runtime_status": cell.get("runtime_status"),
|
|
1199
|
+
"execution": execution,
|
|
1200
|
+
},
|
|
1201
|
+
)
|
|
1202
|
+
)
|
|
1203
|
+
source_js = cell.get("source_js")
|
|
1204
|
+
if isinstance(source_js, str):
|
|
1205
|
+
events.append(
|
|
1206
|
+
_content_event(
|
|
1207
|
+
store=store,
|
|
1208
|
+
value=source_js,
|
|
1209
|
+
content_kind="codex.code_cell.source_js",
|
|
1210
|
+
timestamp=cell_ts,
|
|
1211
|
+
source=cell_entity,
|
|
1212
|
+
relation="HAS_CODE_CELL_SOURCE",
|
|
1213
|
+
observed_field="source_js",
|
|
1214
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
1215
|
+
)
|
|
1216
|
+
)
|
|
1217
|
+
for nested in cell.get("nested_tool_call_ids") or []:
|
|
1218
|
+
nested_call = tool_calls.get(str(nested))
|
|
1219
|
+
if isinstance(nested, str) and isinstance(nested_call, Mapping):
|
|
1220
|
+
events.append(
|
|
1221
|
+
_event(
|
|
1222
|
+
timestamp=cell_ts,
|
|
1223
|
+
event_type="semantic.codex.rollout.code_cell.tool",
|
|
1224
|
+
relation="ISSUED_NESTED_TOOL_CALL",
|
|
1225
|
+
source=cell_entity,
|
|
1226
|
+
target=_tool_call_entity(nested, nested_call, rollout_id=rollout_id),
|
|
1227
|
+
attributes={"trace_id": trace_id, "rollout_id": rollout_id},
|
|
1228
|
+
)
|
|
1229
|
+
)
|
|
1230
|
+
|
|
1231
|
+
for edge_id, edge in interaction_edges.items():
|
|
1232
|
+
edge_ts = _iso_from_unix_ms(edge.get("started_at_unix_ms"), fallback=started)
|
|
1233
|
+
interaction = _interaction_entity(edge_id, edge, rollout_id=rollout_id)
|
|
1234
|
+
source = _anchor_entity(
|
|
1235
|
+
edge.get("source"),
|
|
1236
|
+
rollout_id=rollout_id,
|
|
1237
|
+
threads=threads,
|
|
1238
|
+
conversation_items=conversation_items,
|
|
1239
|
+
tool_calls=tool_calls,
|
|
1240
|
+
)
|
|
1241
|
+
target = _anchor_entity(
|
|
1242
|
+
edge.get("target"),
|
|
1243
|
+
rollout_id=rollout_id,
|
|
1244
|
+
threads=threads,
|
|
1245
|
+
conversation_items=conversation_items,
|
|
1246
|
+
tool_calls=tool_calls,
|
|
1247
|
+
)
|
|
1248
|
+
relation = _direct_interaction_relation(edge.get("kind"))
|
|
1249
|
+
common = {
|
|
1250
|
+
"trace_id": trace_id,
|
|
1251
|
+
"rollout_id": rollout_id,
|
|
1252
|
+
"interaction_edge_id": edge_id,
|
|
1253
|
+
"interaction_kind": edge.get("kind"),
|
|
1254
|
+
"started_at_unix_ms": edge.get("started_at_unix_ms"),
|
|
1255
|
+
"ended_at_unix_ms": edge.get("ended_at_unix_ms"),
|
|
1256
|
+
"carried_item_ids": edge.get("carried_item_ids") or [],
|
|
1257
|
+
"carried_raw_payload_ids": edge.get("carried_raw_payload_ids") or [],
|
|
1258
|
+
"direct_information_flow": True,
|
|
1259
|
+
"source_semantics": "codex_reduced_interaction_edge",
|
|
1260
|
+
}
|
|
1261
|
+
if source is not None:
|
|
1262
|
+
events.append(
|
|
1263
|
+
_event(
|
|
1264
|
+
timestamp=edge_ts,
|
|
1265
|
+
event_type="semantic.codex.rollout.interaction.started",
|
|
1266
|
+
relation="STARTED_AGENT_INTERACTION",
|
|
1267
|
+
source=source,
|
|
1268
|
+
target=interaction,
|
|
1269
|
+
attributes=common,
|
|
1270
|
+
)
|
|
1271
|
+
)
|
|
1272
|
+
if target is not None:
|
|
1273
|
+
events.append(
|
|
1274
|
+
_event(
|
|
1275
|
+
timestamp=edge_ts,
|
|
1276
|
+
event_type="semantic.codex.rollout.interaction.targeted",
|
|
1277
|
+
relation="TARGETED_BY_AGENT_INTERACTION",
|
|
1278
|
+
source=interaction,
|
|
1279
|
+
target=target,
|
|
1280
|
+
attributes=common,
|
|
1281
|
+
)
|
|
1282
|
+
)
|
|
1283
|
+
if source is not None and target is not None:
|
|
1284
|
+
events.append(
|
|
1285
|
+
_event(
|
|
1286
|
+
timestamp=edge_ts,
|
|
1287
|
+
event_type="semantic.codex.rollout.interaction.flow",
|
|
1288
|
+
relation=relation,
|
|
1289
|
+
source=source,
|
|
1290
|
+
target=target,
|
|
1291
|
+
attributes=common,
|
|
1292
|
+
)
|
|
1293
|
+
)
|
|
1294
|
+
source_agent = _owner_agent_for_anchor(
|
|
1295
|
+
edge.get("source"),
|
|
1296
|
+
rollout_id=rollout_id,
|
|
1297
|
+
threads=threads,
|
|
1298
|
+
conversation_items=conversation_items,
|
|
1299
|
+
tool_calls=tool_calls,
|
|
1300
|
+
)
|
|
1301
|
+
target_agent = _owner_agent_for_anchor(
|
|
1302
|
+
edge.get("target"),
|
|
1303
|
+
rollout_id=rollout_id,
|
|
1304
|
+
threads=threads,
|
|
1305
|
+
conversation_items=conversation_items,
|
|
1306
|
+
tool_calls=tool_calls,
|
|
1307
|
+
)
|
|
1308
|
+
if (
|
|
1309
|
+
source_agent is not None
|
|
1310
|
+
and target_agent is not None
|
|
1311
|
+
and source_agent["id"] != target_agent["id"]
|
|
1312
|
+
):
|
|
1313
|
+
events.append(
|
|
1314
|
+
_event(
|
|
1315
|
+
timestamp=edge_ts,
|
|
1316
|
+
event_type="semantic.codex.rollout.agent_to_agent.flow",
|
|
1317
|
+
relation=relation,
|
|
1318
|
+
source=source_agent,
|
|
1319
|
+
target=target_agent,
|
|
1320
|
+
attributes={
|
|
1321
|
+
**common,
|
|
1322
|
+
"normalized_agent_to_agent": True,
|
|
1323
|
+
"source_anchor": edge.get("source"),
|
|
1324
|
+
"target_anchor": edge.get("target"),
|
|
1325
|
+
},
|
|
1326
|
+
)
|
|
1327
|
+
)
|
|
1328
|
+
for index, raw_id in enumerate(edge.get("carried_raw_payload_ids") or []):
|
|
1329
|
+
raw_ref = raw_payloads.get(str(raw_id)) if raw_id is not None else None
|
|
1330
|
+
if isinstance(raw_id, str) and isinstance(raw_ref, Mapping):
|
|
1331
|
+
reference = _raw_payload_reference(
|
|
1332
|
+
bundle=bundle,
|
|
1333
|
+
raw_payload_id=raw_id,
|
|
1334
|
+
raw_ref=raw_ref,
|
|
1335
|
+
store=store,
|
|
1336
|
+
cache=raw_cache,
|
|
1337
|
+
)
|
|
1338
|
+
if reference is not None:
|
|
1339
|
+
events.append(
|
|
1340
|
+
_raw_content_event(
|
|
1341
|
+
reference=reference,
|
|
1342
|
+
timestamp=edge_ts,
|
|
1343
|
+
source=interaction,
|
|
1344
|
+
relation="CARRIED_RAW_PAYLOAD",
|
|
1345
|
+
observed_field=f"carried_raw_payload_ids[{index}]",
|
|
1346
|
+
attributes={**common, "raw_payload_id": raw_id},
|
|
1347
|
+
)
|
|
1348
|
+
)
|
|
1349
|
+
|
|
1350
|
+
for raw_id, raw_ref in raw_payloads.items():
|
|
1351
|
+
reference = _raw_payload_reference(
|
|
1352
|
+
bundle=bundle,
|
|
1353
|
+
raw_payload_id=raw_id,
|
|
1354
|
+
raw_ref=raw_ref,
|
|
1355
|
+
store=store,
|
|
1356
|
+
cache=raw_cache,
|
|
1357
|
+
)
|
|
1358
|
+
if reference is not None:
|
|
1359
|
+
events.append(
|
|
1360
|
+
_raw_content_event(
|
|
1361
|
+
reference=reference,
|
|
1362
|
+
timestamp=ended,
|
|
1363
|
+
source=root_agent,
|
|
1364
|
+
relation="HAS_RAW_CODEX_PAYLOAD",
|
|
1365
|
+
observed_field=f"raw_payloads.{raw_id}",
|
|
1366
|
+
attributes={
|
|
1367
|
+
"trace_id": trace_id,
|
|
1368
|
+
"rollout_id": rollout_id,
|
|
1369
|
+
"raw_payload_id": raw_id,
|
|
1370
|
+
"raw_payload_kind": raw_ref.get("kind"),
|
|
1371
|
+
},
|
|
1372
|
+
)
|
|
1373
|
+
)
|
|
1374
|
+
counts["raw_payload_count"] = len(raw_cache)
|
|
1375
|
+
return events, counts
|
|
1376
|
+
|
|
1377
|
+
|
|
1378
|
+
def _load_json_object(path: Path) -> dict[str, Any]:
|
|
1379
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
1380
|
+
if not isinstance(payload, dict):
|
|
1381
|
+
raise ValueError(f"expected JSON object: {path}")
|
|
1382
|
+
return payload
|
|
1383
|
+
|
|
1384
|
+
|
|
1385
|
+
def _reduce_bundle(codex_executable: str, bundle: Path, state_path: Path) -> str | None:
|
|
1386
|
+
try:
|
|
1387
|
+
completed = subprocess.run(
|
|
1388
|
+
[
|
|
1389
|
+
codex_executable,
|
|
1390
|
+
"debug",
|
|
1391
|
+
"trace-reduce",
|
|
1392
|
+
str(bundle),
|
|
1393
|
+
"--output",
|
|
1394
|
+
str(state_path),
|
|
1395
|
+
],
|
|
1396
|
+
stdin=subprocess.DEVNULL,
|
|
1397
|
+
stdout=subprocess.PIPE,
|
|
1398
|
+
stderr=subprocess.PIPE,
|
|
1399
|
+
text=True,
|
|
1400
|
+
check=False,
|
|
1401
|
+
timeout=60,
|
|
1402
|
+
)
|
|
1403
|
+
except (OSError, subprocess.SubprocessError) as exc:
|
|
1404
|
+
return str(exc)
|
|
1405
|
+
if completed.returncode == 0 and state_path.is_file():
|
|
1406
|
+
return None
|
|
1407
|
+
detail = (completed.stderr or completed.stdout or "").strip()
|
|
1408
|
+
if len(detail) > 500:
|
|
1409
|
+
detail = detail[:497] + "..."
|
|
1410
|
+
return detail or f"trace-reduce exited {completed.returncode}"
|
|
1411
|
+
|
|
1412
|
+
|
|
1413
|
+
def _bundle_dirs(root: Path) -> list[Path]:
|
|
1414
|
+
if not root.is_dir():
|
|
1415
|
+
return []
|
|
1416
|
+
bundles: list[Path] = []
|
|
1417
|
+
for candidate in root.iterdir():
|
|
1418
|
+
if (
|
|
1419
|
+
candidate.is_dir()
|
|
1420
|
+
and candidate.name.startswith(_BUNDLE_PREFIX)
|
|
1421
|
+
and (candidate / _MANIFEST_FILE).is_file()
|
|
1422
|
+
and (candidate / _RAW_TRACE_FILE).is_file()
|
|
1423
|
+
):
|
|
1424
|
+
bundles.append(candidate)
|
|
1425
|
+
return sorted(bundles)
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
def import_codex_rollout_traces(
|
|
1429
|
+
*,
|
|
1430
|
+
trace_root: str | Path,
|
|
1431
|
+
semantic_sidecar: str | Path,
|
|
1432
|
+
codex_executable: str = "codex",
|
|
1433
|
+
) -> CodexRolloutImportResult:
|
|
1434
|
+
"""Import Codex's local rollout trace as full-fidelity ExecWeave semantics.
|
|
1435
|
+
|
|
1436
|
+
Newer Codex builds can record a first-party raw rollout bundle when
|
|
1437
|
+
``CODEX_ROLLOUT_TRACE_ROOT`` is set. ExecWeave enables that bundle for the
|
|
1438
|
+
child Codex process, invokes Codex's own offline reducer after the run, then
|
|
1439
|
+
imports both the reduced semantic objects and the raw payload evidence.
|
|
1440
|
+
|
|
1441
|
+
Plaintext or summarized reasoning is preserved when Codex actually exposes
|
|
1442
|
+
it in the reduced conversation. Encoded/encrypted reasoning is kept as opaque
|
|
1443
|
+
evidence and is never mislabeled as readable chain-of-thought.
|
|
1444
|
+
"""
|
|
1445
|
+
|
|
1446
|
+
root = Path(trace_root).expanduser().resolve()
|
|
1447
|
+
sidecar = Path(semantic_sidecar).expanduser().resolve()
|
|
1448
|
+
bundles = _bundle_dirs(root)
|
|
1449
|
+
if not bundles:
|
|
1450
|
+
return CodexRolloutImportResult(
|
|
1451
|
+
status="no_trace_bundles",
|
|
1452
|
+
trace_root=str(root),
|
|
1453
|
+
)
|
|
1454
|
+
|
|
1455
|
+
store = FullFidelityContentStore(sidecar.parent)
|
|
1456
|
+
all_events: list[dict[str, Any]] = []
|
|
1457
|
+
errors: list[str] = []
|
|
1458
|
+
totals = {
|
|
1459
|
+
"raw_payload_count": 0,
|
|
1460
|
+
"conversation_item_count": 0,
|
|
1461
|
+
"reasoning_text_count": 0,
|
|
1462
|
+
"reasoning_summary_count": 0,
|
|
1463
|
+
"encoded_reasoning_count": 0,
|
|
1464
|
+
"agent_message_count": 0,
|
|
1465
|
+
"interaction_edge_count": 0,
|
|
1466
|
+
"tool_call_count": 0,
|
|
1467
|
+
"inference_call_count": 0,
|
|
1468
|
+
"terminal_operation_count": 0,
|
|
1469
|
+
"code_cell_count": 0,
|
|
1470
|
+
}
|
|
1471
|
+
reduced_bundle_count = 0
|
|
1472
|
+
|
|
1473
|
+
for bundle in bundles:
|
|
1474
|
+
state_path = bundle / _STATE_FILE
|
|
1475
|
+
if not state_path.is_file():
|
|
1476
|
+
error = _reduce_bundle(codex_executable, bundle, state_path)
|
|
1477
|
+
if error is not None:
|
|
1478
|
+
errors.append(f"{bundle.name}: {error}")
|
|
1479
|
+
continue
|
|
1480
|
+
try:
|
|
1481
|
+
state = _load_json_object(state_path)
|
|
1482
|
+
events, counts = _state_events(state, bundle=bundle, store=store)
|
|
1483
|
+
except (OSError, TypeError, ValueError, json.JSONDecodeError) as exc:
|
|
1484
|
+
errors.append(f"{bundle.name}: {exc}")
|
|
1485
|
+
continue
|
|
1486
|
+
reduced_bundle_count += 1
|
|
1487
|
+
all_events.extend(events)
|
|
1488
|
+
for key in totals:
|
|
1489
|
+
totals[key] += counts[key]
|
|
1490
|
+
|
|
1491
|
+
if all_events:
|
|
1492
|
+
append_semantic_records(sidecar, all_events)
|
|
1493
|
+
|
|
1494
|
+
if reduced_bundle_count == len(bundles):
|
|
1495
|
+
status = "imported"
|
|
1496
|
+
elif reduced_bundle_count:
|
|
1497
|
+
status = "partial"
|
|
1498
|
+
else:
|
|
1499
|
+
status = "reduction_failed"
|
|
1500
|
+
|
|
1501
|
+
return CodexRolloutImportResult(
|
|
1502
|
+
status=status,
|
|
1503
|
+
trace_root=str(root),
|
|
1504
|
+
bundle_count=len(bundles),
|
|
1505
|
+
reduced_bundle_count=reduced_bundle_count,
|
|
1506
|
+
semantic_event_count=len(all_events),
|
|
1507
|
+
errors=tuple(errors),
|
|
1508
|
+
**totals,
|
|
1509
|
+
)
|