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
//! `session.get_transcript`'s response shape (#2058).
//!
//! Why: `SessionRegistry::set_run_outcome` (#2056) already persists a
//! finished execution's turn-by-turn transcript, aggregate token usage, and
//! priced cost onto the `SessionEntry` — this is the M1 cut-line's "inspect
//! transcript" verb, exposing that stored record over the wire without
//! recomputing anything. Kept as its own small file (rather than growing
//! `registry.rs`) so the wire shape has one obvious home and stays decoupled
//! from the registry's storage/locking internals.
//! What: [`TranscriptRecord`] is a plain, `Serialize`+`Deserialize` DTO
//! (#2060: the `Deserialize` half lets `tcode`'s CLI thin client — see
//! `crate::cli_client` — parse `session.get_transcript`'s JSON-RPC result
//! straight back into this type rather than picking fields off a raw
//! `serde_json::Value`): `session_id`,
//! the ordered `turns` (each already `role`/`model`/`text`/`tool_calls`/
//! `usage` — see `crate::run_task::TurnRecord`), the aggregate `usage`, and
//! `cost_usd` exactly as stored (`None` either because pricing was
//! unavailable for the run, or because no run has ever completed on this
//! session — the two cases are indistinguishable here by design, matching
//! `RunReport::cost_usd`'s existing convention). A session that has never
//! run a task returns `turns: []`, `usage` all-zero, `cost_usd: null` — a
//! valid, empty transcript, not an error. `mode` (#2059) is the resolved
//! `HarnessMode` `task.run` set via `SessionRegistry::set_mode` — `None` for
//! the same "never run" case. `compaction_events` (#2349, epic #2343) is the
//! session's `pm_transcript`'s cumulative count of #2308 threshold-compactor
//! fires — `0` for a never-run session, and the field epic #2343's success
//! metric ("500+ turn session with `compaction_events == 0`") reads. (#2350)
//! `goals` is a serialisable snapshot of the session's 5 fixed goal slots at
//! the moment `get_transcript` was called, so a client round-tripping
//! `session.get_transcript` sees the same goal state `session.get_goals`
//! reports, with no separate call needed.
//! Test: `session::registry_tests::get_transcript_*`,
//! `session::registry_tests::get_transcript_round_trips_goal_state`.
use ;
use ;
use crate;
use crateHarnessMode;
use crateTokenUsage;
use crateTurnRecord;
use crateMemoryFailureCategory;
/// Per-session durable-memory degradation status (#2425).
///
/// Why: the turn recorder is fail-open by design — a failed `chat_turn_append`
/// or `memory_remember` is logged and dropped so the turn still completes. That
/// makes a session whose durable history is silently thinning indistinguishable
/// from a healthy one at the operator surface. This is the retained counterpart
/// to those per-turn warnings: `session.get_transcript` reports how much of the
/// session's history failed to land.
/// What: `total_failed_turns` counts every degraded turn for the session's
/// lifetime; `consecutive_failed_turns` is the current streak and resets to `0`
/// on the next durable turn; `latest_failure_category`/`latest_failure_at`
/// describe the most recent degradation in LOGICAL turn order, not arrival
/// order. `unrecorded_outcomes` counts outcomes that could not be folded in at
/// all (see [`super::registry`]'s `record_memory_durability`) — a non-zero
/// value means the three counters above UNDER-report.
/// Every field is `#[serde(default)]`, so a transcript serialised before #2425
/// still deserialises.
/// Test: `registry_tests::memory_durability_retains_counts_resets_streak_and_warns_at_one_and_three`,
/// `registry_tests::outcome_beyond_the_reorder_bound_is_counted_as_unrecorded`,
/// `transcript::tests::old_transcript_json_defaults_memory_durability_status`.
/// A serialisable snapshot of one occupied goal slot, as
/// `TranscriptRecord.goals` and `session.get_goals` (#2350) expose it.
///
/// Why: `agent_loop::goals::GoalSlot` carries the slot's content but not its
/// own index (it lives at a position in `GoalSlots`'s internal array); the
/// wire shape needs the 1-based `slot` alongside the content so a client can
/// refer back to it in a subsequent `session.set_goal`/`session.clear_goal`
/// call without re-deriving the index.
/// What: `slot` (1-based), `text`, `source`, `updated_at` — field-for-field
/// from `GoalSlot` plus the index `GoalSlots::occupied` pairs it with.
/// Test: `session::registry_tests::get_transcript_round_trips_goal_state`,
/// `session::registry_tests::get_goals_returns_operator_and_model_sources`.
/// The full stored run record for one session, as `session.get_transcript`
/// returns it.
///
/// Why: see module docs — this is the read-only DTO wrapping whatever
/// `SessionRegistry::set_run_outcome` last stored (or the all-empty default
/// for a session that has never run a task).
/// What: field-for-field passthrough of `SessionEntry`'s transcript/usage/
/// cost, plus the `session_id` for a self-describing response (the wire
/// method already takes `session_id` as a param, but echoing it back keeps
/// the result self-contained for a caller inspecting the JSON alone).
/// `mode` (#2059) mirrors `Session.mode` — the same field, read at
/// `get_transcript` time. `compaction_events` (#2349) mirrors
/// `agent_loop::Transcript::compaction_events()` on the session's
/// `pm_transcript` — `0` when that transcript has never fired the #2308
/// threshold compactor, or the session has never run. (#2350) `goals` mirrors
/// `session.get_goals` — empty when the session has no `pm_transcript` yet
/// (never run a task) or simply has no goal set.
/// Test: `session::registry_tests::get_transcript_returns_stored_record`,
/// `session::registry_tests::get_transcript_on_never_run_session_is_empty`,
/// `session::registry_tests::get_transcript_reports_compaction_events`,
/// `session::registry_tests::get_transcript_round_trips_goal_state`.