agentmux_srv_core/backend/reactive/deliver_steps.rs
1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The steps of [`Handler::deliver_audited`], one function each, in the order they ran: tidy the
5//! request, resolve its target, confirm the recipient's identity, decide the jekt tier, then
6//! deliver through the controller's structured channel or as keystrokes. Moved out of
7//! `deliver_audited` without a change in behaviour.
8
9use super::*;
10
11/// What the tier rules decided for one message.
12pub(super) struct TierDecision {
13 pub effective_tier: &'static str,
14 pub requires_stop: bool,
15}
16
17/// A refusal made before the tier is known: no tier fields on the response.
18pub(super) fn early_refusal(request_id: String, block_id: Option<String>, error: String, now: u64) -> InjectionResponse {
19 InjectionResponse {
20 deferred: None,
21 success: false,
22 request_id,
23 block_id,
24 error: Some(error),
25 timestamp: now,
26 effective_tier: None,
27 requires_stop: None,
28 channel_verified: None,
29 }
30}
31
32/// The facts of one delivery once its target and tier are settled.
33pub(super) struct Delivery<'a> {
34 pub req: &'a InjectionRequest,
35 pub sanitized: &'a str,
36 pub request_id: String,
37 pub now: u64,
38 pub block_id: String,
39 pub effective_tier: &'static str,
40 pub requires_stop: bool,
41 pub delivery_tier: &'a str,
42 pub outcome_on_success: Option<&'a str>,
43 pub outcome_on_failure: Option<&'a str>,
44}
45
46impl Delivery<'_> {
47 /// The response for this delivery: a success when `error` is `None`.
48 fn response(&self, error: Option<String>, deferred: Option<bool>) -> InjectionResponse {
49 InjectionResponse {
50 deferred,
51 success: error.is_none(),
52 request_id: self.request_id.clone(),
53 block_id: Some(self.block_id.clone()),
54 error,
55 timestamp: self.now,
56 effective_tier: Some(self.effective_tier.to_string()),
57 requires_stop: Some(self.requires_stop),
58 channel_verified: self.req.channel_verified,
59 }
60 }
61}
62
63/// Only the trusted production key makes a verified reagent sender.
64/// The verifiers already apply this; enforce it here too for any
65/// caller that sets `reagent_verified` directly.
66fn downgrade_untrusted_reagent(req: &mut InjectionRequest) {
67 if req.reagent_verified == Some(true)
68 && !req
69 .reagent_key_id
70 .as_deref()
71 .is_some_and(agentmux_common::jekt_sign::is_reagent_trusted_signing_key)
72 {
73 req.reagent_verified = Some(false);
74 }
75}
76
77// Determine effective jekt tier.
78// Escalation rules (spec §5.2, extended by
79// SPEC_JEKT_TRUST_LAYER_COMPLETION_2026_08_13.md §2.2, by
80// SPEC_JEKT_REAGENT_TRUST_RELAXATION_2026_08_14.md §1 for the
81// network-tier exception below, and NARROWED by
82// SPEC_JEKT_SENSITIVE_TIER_NARROWING_2026_08_15.md — repo-owner-
83// confirmed directly in a live conversation, not a jekt/muxbus claim):
84// 1. WAN delivery, a reagent signature was present but failed, or
85// was valid only under an untrusted key such as `reagent-v1-dev`
86// (SIG=invalid) → always SENSITIVE, regardless of declared tier
87// or keyword content. No reagent signature at all is NOT this
88// case; that is rule 5's default. Failed LAN and WAN-instance
89// checks are their own forcing rules below.
90// 1b. WAN delivery, sender verified via reagent's pinned Ed25519
91// key (`reagent_verified == Some(true)`) → NOT forced to
92// SENSITIVE by delivery tier alone. As of the 2026-08-15
93// narrowing this is NOT a distinct check anymore — it's simply
94// rule 1 not matching (`Some(true)` isn't `Some(false)`).
95// `Some(true)` only ever means the trusted `reagent-v1` key:
96// the verifiers use `verify_trusted_reagent_jekt`, and
97// `deliver_audited` downgrades any other key to `Some(false)`.
98// Rules 3/4 below still apply on top: a verified reagent
99// message that declares SENSITIVE or matches the keyword scan
100// still escalates.
101// 2. Host check failed, on any delivery tier (the claimed sender
102// has a host key on file and the signature is missing or wrong,
103// or it is a slug its agent was renamed from) → always
104// SENSITIVE (see `sig_verified` on `InjectionRequest` for
105// exactly when this applies vs. is skipped). Same "an active
106// verification FAILURE is the red flag, not mere absence of
107// one" logic as rule 1 — this rule was already scoped that way.
108// 3. Declared SENSITIVE (any tier) → SENSITIVE.
109// 4. Keyword match (any tier) → SENSITIVE.
110// 5. Otherwise → use declared tier (default: coord). This is now
111// reachable by ordinary unverified LAN/WAN traffic with clean
112// content — `TRUST` in the marker is UNCHANGED by this
113// narrowing (still reads `network-claimed`, still exactly as
114// forgeable as ever); only whether that lack of proof alone
115// is sufficient grounds to interrupt the human has changed.
116/// Decide the effective jekt tier and whether it stops the receiver.
117pub(super) fn decide_tier(req: &InjectionRequest, sanitized: &str) -> TierDecision {
118 let declared_tier = req.jekt_tier.as_ref();
119 let delivery_tier = req.delivery_tier.as_deref().unwrap_or("host");
120 let is_network_tier = delivery_tier == "wan" || delivery_tier == "lan";
121 // A reagent_sig that was PRESENT but didn't verify — someone tried to
122 // forge it. `reagent_verified` is WAN-only by construction
123 // (`sync_agent_reactive`/`verify_reagent_signature` never compute it
124 // off the WAN tier, so it's always `None` for LAN — reagent is a
125 // WAN-only service sender, this never applied to LAN). A signature
126 // that verified only under a key other than the trusted production
127 // key IS this case (it arrives as `Some(false)`, see
128 // `deliver_audited`); absence of a signature attempt (`None`) falls
129 // through to rule 5 like any other self-declared sender.
130 let is_network_tier_sig_invalid = is_network_tier && req.reagent_verified == Some(false);
131 // A lan_sig that was PRESENT, whose claimed sender's public key WAS
132 // found, but didn't cryptographically verify — a specific agent's
133 // identity was actively forged, not merely unproven. Scoped to LAN
134 // only, same reasoning as reagent's WAN scoping above — see
135 // docs/specs/SPEC_JEKT_LAN_TIER_SIGNING_2026_08_15.md §2.4/§2.5.
136 let is_lan_sig_invalid = delivery_tier == "lan" && req.lan_verified == Some(false);
137 let is_unverified_sender = req.sig_verified == Some(false);
138 // W3-S (SPEC_WAN_JEKT_VERIFICATION_2026_09_24.md §2.6): a same-account
139 // agent's WAN signature that actively failed (envelope, certificate
140 // chain, record match, signature or replay), or one from an instance
141 // its owner has revoked — the key is known to be out of its owner's
142 // control — is forced sensitive, like `SIG=invalid`.
143 let wan_instance_status = req.wan_instance.as_ref().map(|i| i.status);
144 let is_wan_sig_invalid = delivery_tier == "wan"
145 && (req.wan_verified == Some(false)
146 || (req.wan_verified == Some(true)
147 && wan_instance_status == Some(crate::backend::reactive::types::WanInstanceStatus::Revoked)));
148 // SPEC_JEKT_TRANSCRIPT_REQUEST_TIER_RULES_2026_08_22.md rule 1: a
149 // transcript_request (muxspect Phase B/C's LAN/WAN conversation-
150 // visibility protocol) is forced sensitive unconditionally, on any
151 // tier, regardless of trust — the existing credential/destructive-
152 // keyword scan (is_sensitive_message) doesn't catch a content-
153 // disclosure *request* at all. `req.is_transcript_request` is
154 // server-computed in `handle_reactive_inject` by re-parsing
155 // `message` itself (never attacker-settable — see its own doc
156 // comment), so this can't be spoofed by a client claiming/denying it.
157 let is_sensitive = is_network_tier_sig_invalid
158 || is_lan_sig_invalid
159 || is_wan_sig_invalid
160 || is_unverified_sender
161 || matches!(declared_tier, Some(crate::backend::reactive::types::JektTier::Sensitive))
162 || is_sensitive_message(sanitized)
163 // A file's name is scanned like its message (file transfer spec §6.4).
164 || req.files.iter().flatten().any(|f| is_sensitive_message(&f.name))
165 || req.is_transcript_request;
166 let effective_tier = if is_sensitive { "sensitive" } else {
167 declared_tier.map_or("coord", |t| match t {
168 crate::backend::reactive::types::JektTier::Info => "info",
169 crate::backend::reactive::types::JektTier::Coord => "coord",
170 crate::backend::reactive::types::JektTier::Sensitive => "sensitive",
171 })
172 };
173 let is_cryptographically_verified = is_cryptographically_verified(req, delivery_tier);
174 // SPEC_JEKT_TRANSCRIPT_REQUEST_TIER_RULES_2026_08_22.md rule 2: the
175 // ONE named exception to the verified-sender relaxation above. A
176 // transcript_request's ESCALATE=required is not relaxed by a
177 // verified sender when the RESPONDING agent's own
178 // conversation_visibility is `ask` (or `trusted_peers` with a
179 // non-allow-listed requester) — `req.transcript_request_escalate_forced`,
180 // resolved by the server (`resolve_transcript_request_tier_fields`)
181 // against that agent's own setting before the marker is rendered,
182 // and meaningful only with `is_transcript_request`. A valid signature
183 // answers *who is asking*, not *whether to disclose this content* —
184 // identity proof alone doesn't relax that question, unlike every
185 // other TIER=sensitive case above.
186 let requires_stop = is_sensitive
187 && (!is_cryptographically_verified || req.transcript_request_escalate_forced);
188 TierDecision { effective_tier, requires_stop }
189}
190
191/// Whether this message's sender is verified on some tier, with no failed verdict anywhere.
192fn is_cryptographically_verified(req: &InjectionRequest, delivery_tier: &str) -> bool {
193 let wan_instance_status = req.wan_instance.as_ref().map(|i| i.status);
194 // Whether TIER=sensitive should actually STOP the receiving agent and
195 // require human confirmation, vs. just carry the tag for visual
196 // indication (SPEC_JEKT_SENSITIVE_TIER_VERIFIED_SENDER_NO_STOP_2026_08_17.md,
197 // repo-owner-confirmed directly in a live conversation, same channel
198 // this policy's own STOP rule already treats as authoritative).
199 //
200 // Cryptographic proof of identity is what the STOP rule guards the
201 // absence of (a spoofed jekt followed by a spoofed "confirmation").
202 // Once this message's sender is verified on some tier (host
203 // `sig_verified`, reagent `reagent_verified` under the trusted key,
204 // `lan_verified`, cross-channel `channel_verified`
205 // (SPEC_JEKT_CROSS_CHANNEL_TRUST_2026_09_02.md §D3), or `wan_verified`
206 // from an `approved` or `new` install, W3-S §2.6), that attack is
207 // ruled out, whatever made the message sensitive (a declared tier, or
208 // a keyword in content a verified sender may legitimately discuss).
209 //
210 // Any failed verdict vetoes the relaxation (`any_failed`), so it never
211 // covers an active-forgery case and another tier's success can't
212 // cancel a failure. A failed `channel_verified` is not a forcing rule
213 // above, but it still blocks the relaxation. A revoked install is
214 // forcing, above; a WAN verdict with no instance relaxes nothing.
215 // (see https://docs.agentmux.ai/internals/jekt-protocol/)
216 let any_failed = [req.sig_verified, req.reagent_verified, req.lan_verified, req.channel_verified, req.wan_verified].contains(&Some(false));
217 !any_failed
218 && (req.sig_verified == Some(true)
219 || req.reagent_verified == Some(true)
220 || req.lan_verified == Some(true)
221 || req.channel_verified == Some(true)
222 || (delivery_tier == "wan"
223 && req.wan_verified == Some(true)
224 && matches!(
225 wan_instance_status,
226 Some(crate::backend::reactive::types::WanInstanceStatus::Approved | crate::backend::reactive::types::WanInstanceStatus::New)
227 )))
228}
229
230impl Handler {
231 /// Tidy the request before anything reads it, and return its request ID (made here if the
232 /// caller gave none).
233 pub(super) fn prepare_request(&mut self, req: &mut InjectionRequest) -> String {
234 downgrade_untrusted_reagent(req);
235 req.prove_scheduler_fire(); // the scheduler's own in-process fire: proven (`types.rs`)
236
237 self.refuse_former_slug_sender(req); // never speaks, on any path (`former_slug.rs`)
238 // Generate request ID if missing
239 if req.request_id.is_none() || req.request_id.as_deref() == Some("") {
240 req.request_id = Some(uuid::Uuid::new_v4().to_string());
241 }
242 req.request_id.clone().unwrap_or_default()
243 }
244
245 /// Resolve the target to its block, and the UID it resolved by, if any. A refusal is audited
246 /// and returned as the response.
247 pub(super) fn resolve_delivery_target(
248 &mut self,
249 req: &InjectionRequest,
250 sanitized: &str,
251 request_id: &str,
252 now: u64,
253 outcome_on_failure: Option<&str>,
254 ) -> Result<(String, Option<String>), InjectionResponse> {
255 // Resolve the target (identity M2, spec §4.4.3): UID first, then a
256 // name held by exactly one live block. A name held by several is
257 // refused WITH the candidates — the only place a collision is
258 // visible is the only place it can be resolved (§5.2). The error
259 // string deliberately does not begin with "agent not found": that
260 // prefix is what `handle_reactive_inject` forwards to other
261 // instances, and a local collision must not be forwarded.
262 // The UID a target resolved by: its own, or the agent's whose
263 // former slug it is. `None` for a name.
264 Ok(match self.resolve_target(&req.target_agent) {
265 TargetResolution::Uid(b) => (b, Some(req.target_agent.clone())),
266 TargetResolution::FormerSlug { block, uid } => (block, Some(uid)),
267 TargetResolution::Name(b) => (b, None),
268 TargetResolution::Ambiguous(candidates) => {
269 let err = format!(
270 "ambiguous agent name: '{}' is held by {} live agents — address one by uid: {}",
271 req.target_agent,
272 candidates.len(),
273 describe_candidates(&candidates)
274 );
275 self.log_audit(
276 req.source_agent.as_deref(),
277 &req.target_agent,
278 "",
279 sanitized,
280 false,
281 Some(&err),
282 request_id,
283 outcome_on_failure,
284 None,
285 );
286 return Err(early_refusal(request_id.to_string(), None, err, now));
287 }
288 TargetResolution::NotFound => {
289 let err = format!("agent not found: {}", req.target_agent);
290 self.log_audit(
291 req.source_agent.as_deref(),
292 &req.target_agent,
293 "",
294 sanitized,
295 false,
296 Some(&err),
297 request_id,
298 outcome_on_failure,
299 None,
300 );
301 return Err(early_refusal(request_id.to_string(), None, err, now));
302 }
303 })
304 }
305
306 /// Identity M2: a target that resolved by UID is confirmed by UID only.
307 pub(super) fn confirm_uid_identity(
308 &mut self,
309 req: &InjectionRequest,
310 sanitized: &str,
311 request_id: &str,
312 now: u64,
313 block_id: &str,
314 resolved_uid: Option<&str>,
315 ) -> Result<(), InjectionResponse> {
316 // Identity M2: a target that resolved by UID is confirmed by UID
317 // only (`uid_identity_confirmer`); `None` is unverifiable and
318 // delivery proceeds — see that field's doc comment for the
319 // registered-but-unspawned case this protects. The name checks
320 // below apply only to targets that resolved by name.
321 if let Some(expected_uid) = resolved_uid {
322 let own_uid = self
323 .uid_identity_confirmer
324 .as_ref()
325 .and_then(|c| c(block_id));
326 if let Some(own_uid) = own_uid {
327 if !own_uid.eq_ignore_ascii_case(expected_uid) {
328 let err = format!(
329 "identity mismatch: block {} resolved for uid '{}' but its own uid is '{}'",
330 block_id, expected_uid, own_uid
331 );
332 tracing::error!(
333 target = %req.target_agent,
334 block_id = %block_id,
335 own_uid = %own_uid,
336 "reactive inject: recipient uid mismatch — rejecting delivery"
337 );
338 return Err(self.refuse_identity_mismatch(req, sanitized, request_id, now, block_id, err));
339 }
340 }
341 }
342 Ok(())
343 }
344
345 /// The recipient-identity check for a target that resolved by name.
346 pub(super) fn confirm_name_identity(
347 &mut self,
348 req: &InjectionRequest,
349 sanitized: &str,
350 request_id: &str,
351 now: u64,
352 block_id: &str,
353 resolved_by_uid: bool,
354 ) -> Result<(), InjectionResponse> {
355 // Recipient-identity check (issue #2695): before delivering, compare
356 // the resolved block's own live, spawn-time-captured identity
357 // (queried via `agent_identity_confirmer`, which goes straight to
358 // the controller — independent of this handler's own agent_to_block
359 // map) against who this jekt is addressed to. Checking agent_to_block
360 // against itself would be a tautology and catch nothing; this is a
361 // genuine second, independently-written source of truth that can
362 // drift from the registry (e.g. a stale registry entry survived a
363 // respawn, or a resync overwrote registration without updating the
364 // block's own field).
365 //
366 // `None` (no confirmer configured, or this controller type doesn't
367 // implement `agent_id()`) is "unverifiable," not "confirmed absent" —
368 // delivery proceeds exactly as before this check existed. Matches
369 // this codebase's existing jekt trust philosophy elsewhere (see the
370 // TRUST=/ESCALATE= rules): only an ACTIVE mismatch is a red flag,
371 // mere absence of proof is not.
372 //
373 // Checked against BOTH the live identity (`agent_identity_confirmer`)
374 // and the stable one (`stable_agent_identity_confirmer`) — a target
375 // resolved via the alias registry is legitimately the stable ID, not
376 // the live display name, and would otherwise always fail this check
377 // once the primary key has moved on post-rename. Either source
378 // reporting a match is sufficient; both reporting `None` is
379 // "unverifiable" exactly as before.
380 if !resolved_by_uid
381 && (self.agent_identity_confirmer.is_some()
382 || self.stable_agent_identity_confirmer.is_some())
383 {
384 let live_agent_id = self
385 .agent_identity_confirmer
386 .as_ref()
387 .and_then(|c| c(block_id));
388 let stable_agent_id = self
389 .stable_agent_identity_confirmer
390 .as_ref()
391 .and_then(|c| c(block_id));
392 // Both `None` is "unverifiable" (see above) — only proceed to
393 // the check below if at least one source reported an identity.
394 if live_agent_id.is_some() || stable_agent_id.is_some() {
395 let target_lower = req.target_agent.to_lowercase();
396 let matches = |id: &Option<String>| {
397 id.as_deref().is_some_and(|id| id.to_lowercase() == target_lower)
398 };
399 if !matches(&live_agent_id) && !matches(&stable_agent_id) {
400 let err = format!(
401 "identity mismatch: block {} resolved for target '{}' but its own identity is '{}'",
402 block_id,
403 req.target_agent,
404 live_agent_id
405 .as_deref()
406 .or(stable_agent_id.as_deref())
407 .unwrap_or("<unknown>")
408 );
409 tracing::error!(
410 target = %req.target_agent,
411 block_id = %block_id,
412 live_agent_id = ?live_agent_id,
413 stable_agent_id = ?stable_agent_id,
414 "reactive inject: recipient identity mismatch — rejecting delivery"
415 );
416 return Err(self.refuse_identity_mismatch(req, sanitized, request_id, now, block_id, err));
417 }
418 }
419 }
420 Ok(())
421 }
422
423 /// Controller-aware delivery. `Some(response)` ends the delivery; `None` falls through to
424 /// keystroke injection.
425 pub(super) fn deliver_structured(&mut self, d: &Delivery<'_>, final_msg: &str) -> Option<InjectionResponse> {
426 // Controller-aware delivery (SPEC_AGENT_CONTROL_PROTOCOL §6 / Phase 3).
427 // Persistent (stream-json) and ACP agents have no PTY — their inbox is a
428 // structured channel (live stdin NDJSON / `session/prompt`). Delivering there
429 // also lands the message mid-turn (steering) instead of waiting for idle.
430 // PTY-based shell/term agents report back so we fall through to keystrokes.
431 if let Some(ref deliver) = self.message_sender {
432 let joins_turn = crate::backend::reactive::turn_audit::turn_in_flight(&d.block_id);
433 match deliver(&d.block_id, final_msg, d.req.files_delivery.as_ref().map_or(&[][..], |f| &f.inline), &crate::backend::reactive::sanitize::jekt_origin(d.req, d.effective_tier, d.delivery_tier, &d.request_id, d.now as i64), d.req.expires_at_ms) {
434 Ok(outcome @ (SenderDelivery::Delivered | SenderDelivery::Deferred)) => {
435 let deferred = outcome == SenderDelivery::Deferred;
436 self.delivery_turn = Some(if joins_turn && !deferred { "joined" } else { "started" });
437 tracing::info!(
438 target_agent = %d.req.target_agent,
439 block_id = %d.block_id,
440 deferred,
441 "inject: structured delivery to non-PTY controller"
442 );
443 self.audit_delivery(d, None);
444 return Some(d.response(None, Some(deferred)));
445 }
446 Ok(SenderDelivery::Pty) => {
447 // PTY-based controller — fall through to keystroke injection.
448 }
449 Err(e) => {
450 // Structured controller but delivery failed (e.g. persistent
451 // process not running). Do NOT fall back to PTY keystrokes — the
452 // persistent controller rejects raw input. Surface the error.
453 tracing::warn!(
454 target_agent = %d.req.target_agent,
455 block_id = %d.block_id,
456 error = %e,
457 "inject: structured delivery failed"
458 );
459 self.audit_delivery(d, Some(&e));
460 return Some(d.response(Some(e), None));
461 }
462 }
463 }
464 None
465 }
466
467 /// Deliver as keystrokes through the input sender, then audit the outcome.
468 pub(super) fn deliver_to_pty(&mut self, d: &Delivery<'_>, final_msg: &str) -> InjectionResponse {
469 // Send message via input sender
470 let sender = match &self.input_sender {
471 Some(s) => s.clone(),
472 None => {
473 let err = "input sender not configured".to_string();
474 self.audit_delivery(d, Some(&err));
475 return d.response(Some(err), None);
476 }
477 };
478
479 // Jekt inject sequence (see docs/specs/jekt-inject-timing.md):
480 // 1. \r to clear any partial input on the line
481 // 2. message\r as single payload (proven to display text — v0.31.122/125)
482 // 3. Three delayed \r at 200ms intervals as separate PTY writes to submit
483 let _ = sender(&d.block_id, b"\r");
484 let payload = format!("{}\r", final_msg);
485 tracing::info!(
486 target_agent = %d.req.target_agent,
487 block_id = %d.block_id,
488 msg_len = payload.len(),
489 "inject: sending payload to PTY"
490 );
491 if let Err(e) = sender(&d.block_id, payload.as_bytes()) {
492 tracing::error!(
493 target_agent = %d.req.target_agent,
494 block_id = %d.block_id,
495 error = %e,
496 "inject: sender failed"
497 );
498 self.audit_delivery(d, Some(&e));
499 return d.response(Some(e), None);
500 }
501
502 // Spawn 3 delayed \r sends as separate PTY events to ensure submission.
503 let sender_enter = sender.clone();
504 let block_id_enter = d.block_id.clone();
505 tokio::spawn(async move {
506 tokio::time::sleep(std::time::Duration::from_millis(200)).await;
507 let _ = sender_enter(&block_id_enter, b"\r");
508 tokio::time::sleep(std::time::Duration::from_millis(200)).await;
509 let _ = sender_enter(&block_id_enter, b"\r");
510 tokio::time::sleep(std::time::Duration::from_millis(200)).await;
511 let _ = sender_enter(&block_id_enter, b"\r");
512 });
513
514 // Success
515 self.audit_delivery(d, None);
516 d.response(None, None)
517 }
518
519 /// Audit and answer a recipient-identity mismatch.
520 fn refuse_identity_mismatch(
521 &mut self,
522 req: &InjectionRequest,
523 sanitized: &str,
524 request_id: &str,
525 now: u64,
526 block_id: &str,
527 err: String,
528 ) -> InjectionResponse {
529 self.log_audit(
530 req.source_agent.as_deref(),
531 &req.target_agent,
532 block_id,
533 sanitized,
534 false,
535 Some(&err),
536 request_id,
537 Some("identity-mismatch"),
538 None,
539 );
540 early_refusal(request_id.to_string(), Some(block_id.to_string()), err, now)
541 }
542
543 /// Write the audit entry for a delivery that reached its target.
544 fn audit_delivery(&mut self, d: &Delivery<'_>, error: Option<&str>) {
545 let (success, outcome) = if error.is_none() { (true, d.outcome_on_success) } else { (false, d.outcome_on_failure) };
546 self.log_audit(
547 d.req.source_agent.as_deref(),
548 &d.req.target_agent,
549 &d.block_id,
550 d.sanitized,
551 success,
552 error,
553 &d.request_id,
554 outcome,
555 None,
556 );
557 }
558}