1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//! Deployed run audit: one outcome event per flow TURN, so the admin can list
//! the runs of a deployed unit as *completed*, *in progress* (read back as
//! *dropped off* once its response is overdue, or once idle) or *technical
//! error* — for plain flows and agentic runs alike.
//!
//! Design: greentic-designer
//! `docs/superpowers/specs/2026-09-25-deployed-run-audit-design.md` §3.1 (v1)
//! and `docs/superpowers/specs/2026-09-26-operate-audit-v1-1-design.md` with
//! the Slice B wire contract v2 (`seq`, `wait_kind`, `response_due_at`,
//! `worker_*`, `error_ref`, the `error` excerpt), plus the additive v3
//! `path` / `path_truncated` ([`path`]).
//!
//! # Why the runner emits it
//!
//! `PackFlowAdapter::call_traced` (`engine/runtime.rs`) is the one place that
//! sees all three terminal shapes of a turn — `FlowStatus::Completed`,
//! `FlowStatus::Waiting` (with the node the user is parked on) and the engine
//! error. By the time the embedding host sees the reply, "waiting" has been
//! folded into it. A session also never announces that it ENDED (waits expire
//! silently), so every turn writes its status as it happens and "dropped off"
//! is derived at read time from an `in_progress` row whose `response_due_at`
//! passed (or, for a v1 row with no deadline, that went idle).
//!
//! # A run spans turns
//!
//! A `run_id` (ULID) is minted when a turn starts with NO resume snapshot, and
//! stored beside the parked snapshot (`FlowResumeRecord.run`) so every resume
//! of that run reports under the same id. A snapshot parked by a runtime that
//! predates this field carries none, and its resume mints a fresh id — the
//! only cost is that such an in-flight run is split in two, once.
//!
//! Every event carries `seq`: 1 on a run's first event, +1 on each later one.
//! The count is stored in the same marker (`RunMarker.seq`; a marker written
//! before the field decodes as 0, so its next event is 1). The admin applies
//! an event only when its `seq` is greater than the stored one.
//!
//! Journey identity inside one turn: a `flow.call` sub-flow and a `flow:` tool
//! a worker invokes run INSIDE the caller's turn (`FlowEngine::execute` /
//! `PackRuntime::run_flow_for_tool`, never through `call_traced`), so they
//! mint no run and emit nothing of their own. A `flow.goto` is a jump in the
//! SAME walk: the run continues under the same `run_id`, and the event
//! reports the flow the walk ended in (a parked target's resumes carry it as
//! `next_flow`).
//!
//! Card-driven packs whose pause points are rendered cards (they re-enter via
//! `entry_node` and never park) leave no snapshot, so each of their turns is a
//! run of its own. So does an agent-forward flow (`start → dw.agent`): it
//! reaches its end every turn, so each turn is its own journey. Both are
//! properties of those packs, not of this module.
//!
//! # Agentic runs
//!
//! A run that executed an agentic node carries `kind: agentic` (sticky across
//! its turns) and otherwise the SAME status rules as a flow — `completed`,
//! `in_progress` (+ `wait_kind`) or `technical_error`, with `last_step` and
//! `error_code`. v1 reported such a run as `status: agentic` with nothing
//! else; v2 never emits that status.
//!
//! # What never leaves the process
//!
//! Message text and node payloads. The v3 `path` carries node IDS only.
//! `error_code` is a short class (`timeout`, `secret_missing`, …) computed
//! here. The error's own text leaves ONLY in the
//! technical-error `error` excerpt, redacted and capped
//! ([`error`]) — `safe_summary` is built from identifiers alone. `outcome_json`
//! is reserved for a flow's DECLARED output map; flows do not declare one
//! today, so it is always absent rather than filled with the reply (which is
//! user-visible text).
//!
//! # No sink, no change
//!
//! Nothing here runs unless the embedding host installs a sink through
//! [`crate::runtime::RevisionHostOptions::with_run_outcome_sink`]. Without one
//! no id is minted, no observer is installed and the persisted wait is
//! byte-identical to before.
pub
pub
pub
pub
use Serialize;
use Value;
pub use ErrorExcerpt;
pub use ;
/// What kind of run an event describes. Serialised `snake_case`.
/// A turn's outcome. Serialised `snake_case`. `dropped_off` is deliberately
/// absent: it is derived by the reader from an idle `in_progress` run.
/// What an `in_progress` run is waiting for. Serialised `snake_case`.
/// The wait an `in_progress` event reports.
/// Who did the work: for an agentic run the agent, for a flow run the pack.
/// Every field is optional on the wire.
/// One turn's outcome, as the runtime hands it to a [`RunOutcomeSink`]. The
/// sink adds the attribution (tenant, deployment, unit, revision) and the
/// event id; nothing here is message content.
/// Receives one [`RunOutcome`] per flow turn.
///
/// `record` is called on the turn's own task, after the flow has run and
/// before the reply is returned: it must not block, must not fail, and must
/// not wait on the network. [`HttpRunOutcomeSink`] spawns its POST.
/// RFC 3339 with millisecond precision and a literal `Z`, the shape the
/// admin's ingest doors parse (same as the worker-usage meter).
pub