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
//! The **result message** (ARCH §2.6, §2.11): the deposit a returning
//! agent's executor makes on its behalf, and the durable mark that
//! outlives it.
//!
//! It is an ordinary [`super::deposit`] in every respect but two — its
//! frontmatter carries the two pinned fields `epitaph:` and
//! `terminal_ref:`, and it writes the returned mark — so it is built from
//! [`super::fields`] rather than beside it. Split from its parent at
//! bl-a457, when the sender-name read pushed the file to the per-file
//! cap: the ordinary deposit's shape and the terminal event's pinned
//! facts change for different reasons.
use ;
use crateClock;
use crateGitRunner;
use ;
use inbox_dir;
/// Ref-namespace prefix for the durable **returned** mark,
/// `refs/litany/returned/<child-id>` → the child's terminal ref — written
/// by [`deposit_result`] the moment a result message lands (ARCH §2.6,
/// §8). The fact's one durable home: the message file is consumed by
/// delivery or by a compaction landing, and even its delivered transcript
/// entry can be squashed away by a later compaction — so "this child
/// deposited a result" must outlive every downstream trace, or the §8
/// sweep re-derives a death for a child that returned cleanly. Shares
/// [`crate::workspace::MARK_REF_ROOT`], so §9.2 retention recycles it.
pub const RETURNED_REF_PREFIX: &str = "refs/litany/returned/";
/// The child's returned-mark ref, `refs/litany/returned/<child-id>`.
/// The pinned manner of an agent's ending, carried by a **result
/// message** (ARCH §2.6). A *total* field — the union over every
/// terminal event, never an exception set — so downstream code branches
/// on its **value**, never on the message's shape (§2.6). The on-disk
/// spelling is hyphenated (`final-response`, `budget-exhausted`).
/// Deposit a **result message** (ARCH §2.6) from a terminated agent
/// (`child_id`) into `recipient_id`'s inbox under `workspace`. Who the
/// recipient *is* is decided by the epitaph's value at the executor's
/// own seam ([`crate::prompt::dispatch`] — a reply answers the last
/// prompter, an obituary reports to the dispatcher); this deposit takes
/// the address and writes the file.
/// This is an ordinary [`deposit`] whose frontmatter additionally
/// carries the two pinned fields — `epitaph:` (always) and
/// `terminal_ref:` (always, the sha of the child's branch tip at
/// return) — and whose body is the terminal response iff the agent
/// spoke (`terminal_response` is `Some`); the body is absent exactly
/// when it never spoke (§2.6, §2.11). One file shape, no sidecar, no
/// variant kinds. Sender is the child, so the parent's sender-namespaced
/// inbox records "a message from the child exists" (§2.11) — which is
/// what lets the §8 sweep act as scribe for a crashed child.
///
/// Executor-side by construction: this is a plain filesystem deposit,
/// never a model `message` tool call ("Return is not a verb",
/// `docs/PRINCIPLES.md`). Total and reusable — the normal terminal
/// paths (§2.9, §6) and the §8 silent-death sweep (bl-d148) all deposit
/// through it — which is what makes it the one seam where the durable
/// **returned mark** is written ([`RETURNED_REF_PREFIX`]): every result
/// deposit, whoever makes it, leaves the mark, so the §8 sweep's
/// returned derivation survives the message's later consumption. The
/// mark lands *after* the file: in the crash window between the two the
/// file itself is the evidence (the sweep reads the inbox first), so
/// neither ordering half can strand or double-deposit.
// one deposit, every pinned fact it renders
/// Write the durable returned mark `refs/litany/returned/<child-id>` at
/// the child's terminal ref (module docs on [`RETURNED_REF_PREFIX`]).
/// Render a result message (§2.6, §2.11): the ordinary [`fields`] plus
/// `epitaph:` and `terminal_ref:` in the same frontmatter block, then the
/// terminal response as the body — present iff `Some`. When the agent
/// never spoke the file ends at the closing delimiter with no body, which
/// is exactly how delivery composes an empty user-role wire message for
/// it.