Skip to main content

agentmux_srv_core/backend/blockcontroller/persistent/
segments.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! This controller's side of the segment index
5//! (`backend::continuity_segments`): each spawn is one segment of its
6//! agent's conversation. Best-effort throughout: a failed write is logged and
7//! never affects the process.
8
9use super::*;
10use crate::backend::continuity_segments as segs;
11
12/// The segment a spawned process belongs to: `(agent_uid, segment_id)`.
13pub(super) type SegmentRef = Option<(String, String)>;
14
15/// The config dir the spawn gives its provider: the provider's own
16/// `auth_config_dir_env_var` (Gemini's is `GEMINI_CLI_HOME`, not the
17/// `GEMINI_CONFIG_DIR` a hand-kept list here once named), else the first
18/// known provider's variable the env carries.
19fn spawn_config_dir(provider: &str, env: &std::collections::HashMap<String, String>) -> Option<String> {
20    if let Some(p) = crate::backend::providers::get_provider(provider) {
21        if let Some(v) = env.get(p.auth_config_dir_env_var) {
22            return Some(v.clone());
23        }
24    }
25    crate::backend::providers::all_providers().find_map(|p| env.get(p.auth_config_dir_env_var).cloned())
26}
27
28use agentmux_common::time::now_ms;
29
30/// Size of `output` in the global zone, read from the database rather than
31/// this process's cache, so another channel's appends count.
32fn zone_size(zone: &str) -> Option<i64> {
33    let gfs = crate::backend::transcript::damage::global_for(zone)?;
34    match gfs.line_state(zone, crate::backend::agent_session::OUTPUT_FILE) {
35        Ok(state) => state.map(|s| s.size),
36        Err(e) => {
37            crate::backend::transcript::damage::note_if_shared(&gfs, zone, "tail read", &e);
38            None
39        }
40    }
41}
42
43impl PersistentSubprocessController {
44    /// Claims this agent's single-live-instance lease, then runs the resume
45    /// gate ([`apply_resume_gate_with`](Self::apply_resume_gate_with)) under it.
46    ///
47    /// The lease is one live instance per agent across every AgentMux instance
48    /// on this host (SPEC_AGENT_SINGLE_LIVE_INSTANCE_2026_09_24.md Phase 1),
49    /// held for the spawned process's lifetime. Claiming it FIRST means the
50    /// gate's sweep, relocation and settle (spec §4.3) run for one spawn of an
51    /// agent at a time: two controllers of one agent racing those steps kept
52    /// opening narrower windows (#3924). The session is only a hint to the
53    /// lease — recorded, not a key — so the gate settling the final id
54    /// afterwards changes nothing about the claim.
55    ///
56    /// When leasing is unavailable (no store, or no agent UID) the gate runs
57    /// unguarded, as it did before Phase 1.
58    pub(super) fn lease_then_gate(
59        &self,
60        config: &PersistentSpawnConfig,
61        gfs: Option<&FileStore>,
62        history_session: Option<String>,
63    ) -> Result<Option<Arc<crate::backend::agent_admission::HeldAgentLease>>, String> {
64        let candidate = if config.resume_flag.is_empty() {
65            None
66        } else {
67            self.inner.lock().unwrap().session_id.clone().or_else(|| history_session.clone())
68        };
69        let lease = match self.acquire_agent_lease(config, candidate.as_deref()) {
70            Ok(lease) => lease,
71            // The agent is open in another pane of this process (it holds the
72            // lease, whatever session either pane holds), or this conversation
73            // is live or still closing there. Report that as the held-elsewhere
74            // refusal it is: callers treat only that one as "don't fall back to
75            // a fresh session" (`is_held_elsewhere_error`), and the wording is
76            // "another pane", not "another instance".
77            Err(e) => {
78                let uid = config.env_vars.get("AGENTMUX_AGENT_UID").map(|u| u.trim()).filter(|u| !u.is_empty());
79                if let Some(other) = uid.and_then(|uid| self.agent_held_by_other_pane(uid)) {
80                    return Err(super::held_elsewhere_error(&other, false));
81                }
82                if let Some((other, closing)) = candidate.as_deref().and_then(|sid| self.session_held_elsewhere(sid)) {
83                    return Err(super::held_elsewhere_error(&other, closing));
84                }
85                return Err(e);
86            }
87        };
88        self.apply_resume_gate_with(config, gfs, history_session);
89        Ok(lease)
90    }
91
92    /// The one resume gate
93    /// (SPEC_RESUME_GATE_AND_SAME_IDENTITY_CONTINUATION_2026_09_25.md §4.2):
94    /// before this spawn passes `--resume`, only the head of the agent's
95    /// segment chain may be the session it resumes. A stale id — the
96    /// conversation moved on in another channel, build or pane — is
97    /// redirected to the head when this config dir reaches it, and cleared
98    /// otherwise, so the spawn goes fresh and carries AgentMux's record.
99    /// Runs after every path that sets the id (hydrate from config, first
100    /// spawn onto rendered history) and under the agent's lease
101    /// ([`lease_then_gate`](Self::lease_then_gate)), before the held-elsewhere
102    /// check, which then applies to whatever id survives. Never fails the
103    /// spawn: anything unknown leaves the id as it was.
104    ///
105    /// `history_session`: on a first spawn holding no id, the session of the
106    /// history the pane renders when `--resume` can't reach it here. It is a
107    /// candidate for relocation only (a rebuild onto a new login of the same
108    /// identity); any other decision leaves the spawn holding no id, as
109    /// before.
110    pub(super) fn apply_resume_gate_with(
111        &self,
112        config: &PersistentSpawnConfig,
113        gfs: Option<&FileStore>,
114        history_session: Option<String>,
115    ) {
116        if config.resume_flag.is_empty() {
117            return;
118        }
119        let (held, poisoned) = {
120            let inner = self.inner.lock().unwrap();
121            (inner.session_id.clone(), inner.resume_poisoned.clone())
122        };
123        let relocate_only = held.is_none();
124        let Some(candidate) = held.or(history_session).filter(|c| poisoned.as_deref() != Some(c.as_str())) else {
125            return;
126        };
127        // Reachability is a file check under the provider's config dir; only
128        // Claude's is known. Without one the head can't be checked, so the
129        // gate stays out of the way.
130        let Some(config_dir) = config.env_vars.get("CLAUDE_CONFIG_DIR") else { return };
131        // A non-Claude spawn can still inherit that variable; its sessions
132        // aren't under it, so checking there would refuse every resume.
133        let provider = self
134            .mstore
135            .as_deref()
136            .and_then(|s| s.get::<crate::backend::obj::Block>(&self.block_id).ok().flatten())
137            .map(|b| crate::backend::obj::meta_get_string(&b.meta, "agentProvider", ""))
138            .unwrap_or_default();
139        if !matches!(provider.as_str(), "" | "claude" | "claude-code") {
140            return;
141        }
142        let (Some(gfs), Some(uid)) = (gfs, config.env_vars.get("AGENTMUX_AGENT_UID").filter(|u| !u.trim().is_empty()))
143        else {
144            return;
145        };
146        let uid = uid.trim();
147        let cwd = config.working_dir.as_str();
148        // A copy this agent relocated earlier and whose fork never reported an
149        // id (the process died) goes first: left in place, it would look
150        // reachable and be resumed in place, a lasting second file with the
151        // head's id (spec §3 I4).
152        let swept = crate::backend::continuity_relocate::sweep(config_dir, cwd, uid);
153        if swept > 0 {
154            tracing::info!(target: "continuity", block_id = %self.block_id, swept, "resume gate: removed relocated copies a dead spawn left");
155        }
156        let head = segs::chain_head(gfs, uid).map(segs::with_legacy_identity);
157        // A fork with no chain of its own starts from the agent it was forked from.
158        let fork_source = if head.is_none() { self.mstore.as_deref().and_then(|s| segs::fork_source_head(s, gfs, uid)) } else { None };
159        let identity = crate::identity::account_email::identity_key_from_oauth_dir("claude", config_dir);
160        let input = segs::GateInput {
161            candidate: &candidate,
162            head: head.as_ref(),
163            identity: identity.as_deref(),
164            poisoned: poisoned.as_deref(),
165            config_dir,
166            cwd,
167            fork_source: fork_source.as_ref(),
168        };
169        let decision = segs::resume_gate(
170            &input,
171            |sid| provider_file_size(config_dir, cwd, sid),
172            crate::backend::continuity_relocate::can_relocate,
173        );
174        // Copy a session file in from where it was recorded, for `--fork-session`.
175        let place = |from_config_dir: &str, from_cwd: &str, head: &str| {
176            crate::backend::continuity_relocate::source_file(from_config_dir, from_cwd, head)
177                .ok_or_else(|| "source gone".to_string())
178                .and_then(|src| crate::backend::continuity_relocate::relocate(&src, config_dir, cwd, head, uid))
179        };
180        let refuse = |head: &str, why: &str| {
181            tracing::info!(
182                target: "continuity",
183                block_id = %self.block_id,
184                candidate = %candidate,
185                head = %head,
186                why,
187                "resume gate: the conversation is in a session this spawn can't resume; starting fresh with the record"
188            );
189            (None, None, false)
190        };
191        if relocate_only && !matches!(decision, segs::ResumeGate::Relocate { .. } | segs::ResumeGate::ForkFrom { .. }) {
192            return;
193        }
194        let (next, fork_copy, fork) = match decision {
195            segs::ResumeGate::Allow => return,
196            segs::ResumeGate::Fork { head } => {
197                tracing::info!(
198                    target: "continuity",
199                    block_id = %self.block_id,
200                    candidate = %candidate,
201                    head = %head,
202                    "resume gate: the session grew after AgentMux last saw it (continued outside AgentMux); forking it"
203                );
204                (Some(head), None, true)
205            }
206            segs::ResumeGate::Redirect { head } => {
207                tracing::info!(
208                    target: "continuity",
209                    block_id = %self.block_id,
210                    candidate = %candidate,
211                    head = %head,
212                    "resume gate: the conversation moved on; resuming the chain head instead"
213                );
214                (Some(head), None, false)
215            }
216            segs::ResumeGate::Refuse { head } => refuse(&head, "out of reach, or another identity's"),
217            segs::ResumeGate::Relocate { head, from_config_dir } => {
218                match place(&from_config_dir, cwd, &head) {
219                    Ok(copy) => {
220                        tracing::info!(
221                            target: "continuity",
222                            block_id = %self.block_id,
223                            candidate = %candidate,
224                            head = %head,
225                            from = %from_config_dir,
226                            "resume gate: the conversation is under another login of the same identity; relocated it to fork from"
227                        );
228                        (Some(head), Some(copy), true)
229                    }
230                    Err(e) => refuse(&head, &format!("relocation failed: {e}")),
231                }
232            }
233            segs::ResumeGate::ForkFrom { head, from_config_dir, from_cwd } => match place(&from_config_dir, &from_cwd, &head) {
234                Ok(copy) => {
235                    tracing::info!(
236                        target: "continuity",
237                        block_id = %self.block_id,
238                        head = %head,
239                        from = %from_config_dir,
240                        "resume gate: a fork's first spawn; copied the conversation it was forked from to fork from"
241                    );
242                    (Some(head), Some(copy), true)
243                }
244                Err(e) => refuse(&head, &format!("copying the conversation it was forked from failed: {e}")),
245            },
246        };
247        {
248            let mut inner = self.inner.lock().unwrap();
249            // Only replace what the gate judged: another path may have moved
250            // the id meanwhile.
251            let judged = if relocate_only { None } else { Some(candidate.as_str()) };
252            if inner.session_id.as_deref() != judged {
253                drop(inner);
254                if let Some(copy) = fork_copy {
255                    crate::backend::continuity_relocate::remove(&copy);
256                }
257                return;
258            }
259            inner.session_id = next.clone();
260            inner.fork_copy = fork_copy;
261            inner.fork_next = fork;
262        }
263        core::persist_session_id(&self.block_id, next.as_deref().unwrap_or(""), &self.mstore, &self.event_bus);
264    }
265
266    /// Reconcile the agent's memory record with the folder this spawn is
267    /// about to use, before the provider starts, within
268    /// [`reconcile::RECONCILE_BUDGET`](crate::backend::memory::reconcile::RECONCILE_BUDGET)
269    /// (SPEC_MEMORY_FOLLOWS_THE_AGENT_2026_09_24.md §2.1.3). Never fails the
270    /// spawn. Off for an agent with `agent:memoryrecord` = `off`.
271    pub(super) fn reconcile_memory_before_spawn(&self, config: &PersistentSpawnConfig) {
272        let (Some(gfs), Some(mstore)) = (crate::backend::agent_session::global_transcript_store(), self.mstore.as_deref()) else {
273            return;
274        };
275        let Some(uid) = config.env_vars.get("AGENTMUX_AGENT_UID").filter(|u| !u.is_empty()) else {
276            return;
277        };
278        // A memory record found corrupt is not reconciled with: the agent's folder is used as it is.
279        if crate::backend::transcript::damage::is_damaged(&crate::backend::transcript::damage::memory_zone(uid)) {
280            tracing::info!(block_id = %self.block_id, uid, "memory reconcile skipped: the agent's shared memory record is damaged");
281            return;
282        }
283        let meta = mstore
284            .get::<crate::backend::obj::Block>(&self.block_id)
285            .ok()
286            .flatten()
287            .map(|b| b.meta)
288            .unwrap_or_default();
289        if crate::backend::obj::meta_get_string(&meta, "agent:memoryrecord", "") == "off" {
290            return;
291        }
292        // The same agent live in another pane (a second pane starting fresh
293        // beside it) writes the same folder while the pass would run: leave
294        // it to that agent's next spawn.
295        let live_elsewhere = super::super::get_all_controllers().into_iter().any(|(block_id, ctrl)| {
296            block_id != self.block_id
297                && ctrl.as_any().downcast_ref::<PersistentSubprocessController>().is_some_and(|other| {
298                    other.stable_agent_uid.lock().unwrap().as_deref() == Some(uid.as_str())
299                        && other.inner.lock().unwrap().current_pid.is_some()
300                })
301        });
302        if live_elsewhere {
303            tracing::info!(block_id = %self.block_id, uid, "memory reconcile skipped: the agent is live in another pane");
304            return;
305        }
306        let provider = crate::backend::obj::meta_get_string(&meta, "agentProvider", "");
307        let reconcile = || {
308            crate::backend::memory::reconcile::reconcile_before_spawn(
309                gfs,
310                mstore,
311                &crate::backend::memory::reconcile::SpawnMemory {
312                    uid,
313                    provider: &provider,
314                    config_dir: config.env_vars.get("CLAUDE_CONFIG_DIR").map(String::as_str),
315                    cwd: &config.working_dir,
316                    overridden: crate::backend::memory::reconcile::spawn_overrides_memory_dir(&config.env_vars, &config.cli_args),
317                    history_stores: None,
318                },
319                crate::backend::memory::reconcile::RECONCILE_BUDGET,
320            )
321        };
322        // Up to a second of blocking file and SQLite I/O: on the async
323        // callers' runtime (run_agent_turn, agent.send) hand the worker's
324        // other tasks off first. block_in_place panics on a current-thread
325        // runtime, where there is no other worker to hand them to.
326        let on_multi_thread = tokio::runtime::Handle::try_current()
327            .is_ok_and(|h| h.runtime_flavor() == tokio::runtime::RuntimeFlavor::MultiThread);
328        let report = if on_multi_thread { tokio::task::block_in_place(reconcile) } else { reconcile() };
329        if report.deferred {
330            tracing::info!(block_id = %self.block_id, uid, "memory reconcile deferred: over budget");
331        } else if report != Default::default() {
332            tracing::info!(block_id = %self.block_id, uid, ?report, "memory reconciled before spawn");
333        }
334    }
335
336    /// Records the start of the segment this spawn begins. `None` when the
337    /// spawn carries no agent UID (quick-launch panes, a continuation that
338    /// resumes before its row exists) or the write fails.
339    #[allow(clippy::too_many_arguments)]
340    pub(super) fn record_segment_start(
341        &self,
342        agent_uid: &str,
343        config: &PersistentSpawnConfig,
344        attempted_resume_sid: Option<&str>,
345        forked_from: Option<&str>,
346        relocated: bool,
347        carries_packet: bool,
348        lease_epoch: Option<u64>,
349    ) -> SegmentRef {
350        let gfs = crate::backend::agent_session::global_transcript_store()?;
351        let start = self.segment_start(agent_uid, config, attempted_resume_sid, forked_from, relocated, carries_packet, lease_epoch);
352        let rung = start.continuity_rung;
353        match segs::record_start(gfs, start) {
354            Ok(id) => {
355                tracing::info!(block_id = %self.block_id, segment_id = %id, rung = ?rung, "continuity: segment started");
356                Some((agent_uid.to_string(), id))
357            }
358            Err(e) => {
359                tracing::warn!(block_id = %self.block_id, error = %e, "continuity: segment start not recorded");
360                None
361            }
362        }
363    }
364
365    /// The `Start` event [`record_segment_start`](Self::record_segment_start)
366    /// writes. A relocated fork records no session until it reports its own:
367    /// the attempted id names the copy, which is swept if the process dies
368    /// first, so as the head it would send the next spawn to `--resume` a
369    /// file that is gone instead of relocating again (spec §4.3).
370    #[allow(clippy::too_many_arguments)]
371    pub(super) fn segment_start(
372        &self,
373        agent_uid: &str,
374        config: &PersistentSpawnConfig,
375        attempted_resume_sid: Option<&str>,
376        forked_from: Option<&str>,
377        relocated: bool,
378        carries_packet: bool,
379        lease_epoch: Option<u64>,
380    ) -> segs::Start {
381        let meta = self
382            .mstore
383            .as_deref()
384            .and_then(|s| s.get::<crate::backend::obj::Block>(&self.block_id).ok().flatten())
385            .map(|b| b.meta)
386            .unwrap_or_default();
387        let definition_id = Some(crate::backend::obj::meta_get_string(&meta, "agentId", "")).filter(|d| !d.is_empty());
388        let provider = crate::backend::obj::meta_get_string(&meta, "agentProvider", "");
389        let zone = crate::backend::agent_session::agent_zone_for_block_meta(&meta);
390        let config_dir = spawn_config_dir(&provider, &config.env_vars);
391        let identity_key = config_dir
392            .as_deref()
393            .and_then(|dir| crate::identity::account_email::identity_key_from_oauth_dir(&provider, dir));
394        segs::Start {
395            segment_id: String::new(),
396            agent_uid: agent_uid.to_string(),
397            definition_id,
398            config_dir,
399            identity_key,
400            forked_from: forked_from.map(str::to_string),
401            provider,
402            provider_session_id: attempted_resume_sid.filter(|_| !relocated).map(str::to_string),
403            cwd: config.working_dir.clone(),
404            channel: crate::backend::reactive::registry::local_channel_id(),
405            agentmux_version: crate::backend::base::get_version().to_string(),
406            block_id: self.block_id.clone(),
407            byte_start: zone.as_deref().and_then(zone_size),
408            zone,
409            started_at_ms: now_ms(),
410            continuity_rung: segs::rung_for_spawn(attempted_resume_sid.is_some(), carries_packet),
411            predecessor_segment_id: None,
412            lease_epoch,
413        }
414    }
415}
416
417/// A fresh process reported its provider session id.
418pub(super) fn record_segment_session(segment: &SegmentRef, provider_session_id: &str) {
419    let (Some((uid, id)), Some(gfs)) = (segment, crate::backend::agent_session::global_transcript_store()) else {
420        return;
421    };
422    if let Err(e) = segs::record_session(gfs, uid, id, provider_session_id, now_ms()) {
423        tracing::warn!(segment_id = %id, error = %e, "continuity: segment session not recorded");
424    }
425}
426
427/// The segment's process went away. `zone` is its global transcript zone.
428/// Size of the Claude session file `sid` for `cwd` under `config_dir`;
429/// `None` when it isn't there.
430fn provider_file_size(config_dir: &str, cwd: &str, sid: &str) -> Option<u64> {
431    let path = crate::backend::session_backfill::session_file_path(config_dir, cwd, sid)?;
432    std::fs::metadata(path).ok().filter(|m| m.is_file()).map(|m| m.len())
433}
434
435/// The provider session file's size for segment `id`, from what its own
436/// record says about where it ran (spec §4.4). Claude only.
437fn provider_bytes_for_segment(gfs: &FileStore, uid: &str, id: &str) -> Option<i64> {
438    let segment = segs::segments(gfs, uid).into_iter().find(|s| s.start.segment_id == id)?;
439    let start = segment.start;
440    if !matches!(start.provider.as_str(), "claude" | "claude-code") {
441        return None;
442    }
443    let size = provider_file_size(start.config_dir.as_deref()?, &start.cwd, start.provider_session_id.as_deref()?)?;
444    i64::try_from(size).ok()
445}
446
447pub(super) fn record_segment_end(segment: &SegmentRef, reason: segs::EndReason, zone: Option<&str>) {
448    let (Some((uid, id)), Some(gfs)) = (segment, crate::backend::agent_session::global_transcript_store()) else {
449        return;
450    };
451    let provider_bytes = provider_bytes_for_segment(gfs, uid, id);
452    if let Err(e) = segs::record_end_with_provider_bytes(gfs, uid, id, reason, zone.and_then(zone_size), provider_bytes, now_ms()) {
453        tracing::warn!(segment_id = %id, error = %e, "continuity: segment end not recorded");
454    } else {
455        tracing::info!(segment_id = %id, reason = ?reason, "continuity: segment ended");
456    }
457}
458
459#[cfg(test)]
460mod config_dir_tests {
461    use super::spawn_config_dir;
462
463    fn env(pairs: &[(&str, &str)]) -> std::collections::HashMap<String, String> {
464        pairs.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect()
465    }
466
467    #[test]
468    fn each_provider_records_its_own_config_dir() {
469        assert_eq!(spawn_config_dir("claude", &env(&[("CLAUDE_CONFIG_DIR", "/c")])).as_deref(), Some("/c"));
470        assert_eq!(spawn_config_dir("gemini", &env(&[("GEMINI_CLI_HOME", "/g")])).as_deref(), Some("/g"));
471    }
472
473    #[test]
474    fn the_providers_own_variable_wins_over_another_in_the_env() {
475        let e = env(&[("CLAUDE_CONFIG_DIR", "/c"), ("CODEX_HOME", "/x")]);
476        assert_eq!(spawn_config_dir("codex", &e).as_deref(), Some("/x"));
477        assert_eq!(spawn_config_dir("", &env(&[])), None);
478    }
479}
480
481/// The outcome of a relocated resume (spec §4.3): the fork reports its own
482/// id, which `persistent_resume` reads as the CLI starting fresh. Carrying
483/// the whole conversation into a new id is the resume succeeding.
484pub(super) fn forked_outcome(
485    outcome: persistent_resume::SessionOutcome,
486    forked_from: Option<&str>,
487    attempted_sid: &str,
488    actual_sid: Option<&str>,
489) -> persistent_resume::SessionOutcome {
490    let forked = forked_from == Some(attempted_sid) && actual_sid.is_some_and(|a| a != attempted_sid);
491    if forked {
492        persistent_resume::SessionOutcome::Resumed
493    } else {
494        outcome
495    }
496}
497
498/// A relocated resume the CLI kept under the attempted id, resumed in place
499/// rather than forked. Capture skips an id the controller already holds, so
500/// this is settled on its own, once a result frame proves the resume worked
501/// (an earlier frame echoes the attempted id even when the resume goes on to
502/// fail). Left unsettled, the segment would hold no session (a relocated
503/// Start records none) and the next spawn would sweep the live copy.
504/// `holds_current`: the reader's generation is still current and holds the
505/// id; a superseded one's copy path may already be the replacement's.
506pub(super) fn kept_relocated_id(
507    adopted: bool,
508    confirmed: bool,
509    holds_current: bool,
510    has_copy: bool,
511    forked_from: Option<&str>,
512    captured: &str,
513) -> bool {
514    !adopted && confirmed && holds_current && has_copy && forked_from == Some(captured)
515}
516
517/// Once a relocated resume reports its session: a fork (a new id) never
518/// wrote the copy, so it goes. The same id back means the CLI resumed the
519/// copy in place instead of forking; it is live now, so only its marker
520/// goes, and the duplicate is logged (spec §3 I4). Returns whether the copy
521/// was still this spawn's: a replacement's sweep may have taken it and
522/// placed its own at the same path, which is then left alone.
523pub(super) fn settle_relocated_copy(
524    block_id: &str,
525    copy: &crate::backend::continuity_relocate::Relocated,
526    forked_from: Option<&str>,
527    captured: &str,
528) -> bool {
529    if forked_from == Some(captured) {
530        let owned = crate::backend::continuity_relocate::unmark(copy);
531        if owned {
532            tracing::warn!(
533                target: "continuity",
534                block_id,
535                session_id = captured,
536                "relocated resume did not fork; keeping the copy as the live session"
537            );
538        }
539        owned
540    } else {
541        crate::backend::continuity_relocate::remove(copy)
542    }
543}