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
//! Response-segment classification (ARCH §4.4 "On-disk response shape:
//! appended attempt segments"; §2.9 Stopped branches; §2.10 Retries and
//! failures; §3.5 Branch-state classification).
//!
//! `response.json` is JSONL: one canonical event per line, appended
//! across one or more attempt **segments**, each terminated by its
//! `{"type":"end"}` line (§4.4). brazen guarantees every stream —
//! success, refusal, or failure — ends with exactly one `End`, so the
//! file is a sequence of self-delimiting segments and the last segment
//! is authoritative; earlier segments are the audit trail of failed
//! attempts. This module is the single seam that reads that framing
//! tail and classifies a **closed** response file's last segment. It
//! reads only framing — the terminal `End` line and whether the last
//! segment carries an `Error` — never event content, honoring the §2.3
//! diagnostic-only contract (framing-yes / content-no).
//!
//! The vocabulary is brazen's `v=1` [`brazen::Event`] type — its single
//! source of truth — so no `"end"`/`"error"` string literal duplicates
//! it here (the v0.6 legacy-vocabulary seam is retired: bl-56ee).
//!
//! Terminal classification is evaluated ONLY on a closed file. The
//! `in_flight` state (fd still open) is observed elsewhere — the §3.5
//! `IN_CLOSE_WRITE` watch and the §2.9 `/proc` writer scan — never
//! derived from these bytes.
use Event;
/// Outcome of the last attempt segment of a **closed** `response.json`
/// (the §4.4 reading rules). `in_flight` is deliberately not a variant:
/// it is the fd-open observation the caller makes, not a property of the
/// bytes.
/// Classify the last segment of a `response.json` payload. `bytes` is
/// the whole file; only complete (`\n`-terminated) lines are examined,
/// so a partially-written trailing line is ignored — the writer may be
/// mid-append (§3.5 mid-write tolerance).
/// A brazen segment ends with `Event::End`; its outcome is decided by
/// whether the **last** segment (the lines after the previous `End`)
/// carries an `Event::Error`. A refusal is a `Finish`, never an
/// `Error`, so it reads *complete* (§4.4). Earlier segments — the audit
/// trail of failed attempts before a retry succeeded — are skipped by
/// starting the scan after the previous `End`.