Skip to main content

agentmux_srv_core/backend/
dev_keepalive.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Dev servers that outlive their container.
5//!
6//! A container agent's dev server is a process in its container, so it goes when the container is recreated
7//! (an AgentMux upgrade, an image update). An agent that registers one with the command that starts it
8//! (`RegisterDevServer` with `command`) has AgentMux start it and keep it up: when the container next runs a turn
9//! and the server is not listening, srv runs the command again, detached, in the same folder, and registers the
10//! route with the container's new address. What is remembered is the command the agent itself gave, and it only
11//! ever runs in the container it was registered from.
12
13use std::collections::HashSet;
14use std::path::PathBuf;
15use std::sync::{Mutex, OnceLock};
16use std::time::{Duration, Instant};
17
18use agentmux_common::time::now_secs_u64;
19use serde::{Deserialize, Serialize};
20
21use crate::backend::container::ContainerManager;
22use crate::backend::dev_proxy::Target;
23
24/// The folder dev servers start in, and the container's name for it.
25const WORKSPACE: &str = "/workspace";
26/// What one container may keep up.
27const MAX_PER_CONTAINER: usize = 8;
28/// A command is a line or a short script.
29const MAX_COMMAND_BYTES: usize = 4096;
30/// How long a freshly started server gets to begin listening.
31const STARTUP_WAIT_SECS: u64 = 90;
32const STARTUP_WAIT: Duration = Duration::from_secs(STARTUP_WAIT_SECS);
33/// A server nobody has run a turn beside for this long is no longer kept up.
34const FORGET_AFTER_SECS: u64 = 30 * 24 * 3600;
35
36/// One dev server to keep up.
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
38pub struct Spec {
39    /// The agent id its route is under (`<project>-<agent_id>.localhost`).
40    pub agent_id: String,
41    /// The container it runs in.
42    pub container: String,
43    pub project: String,
44    pub port: u16,
45    pub command: String,
46    /// Where the command runs, as a path in the container.
47    pub dir: String,
48    /// When the container last ran a turn with this kept up (unix seconds): one nobody has used for a month is let go.
49    #[serde(default)]
50    pub seen: u64,
51}
52
53impl Spec {
54    /// Where the server's output goes, inside the container.
55    pub fn log(&self) -> String {
56        format!("/tmp/amx-dev-{}.log", self.project)
57    }
58}
59
60/// The folder a command runs in: `/workspace/...`, or a path relative to it; nothing that leaves it.
61pub fn clean_dir(dir: Option<&str>) -> Result<String, String> {
62    let raw = dir.map(str::trim).filter(|d| !d.is_empty()).unwrap_or(WORKSPACE);
63    let rel = match raw.strip_prefix(WORKSPACE) {
64        Some("") => "",
65        Some(rest) if rest.starts_with('/') => rest.trim_start_matches('/'),
66        Some(_) => return Err(format!("dir {raw:?} is not in {WORKSPACE}")),
67        None if raw.starts_with('/') => return Err(format!("dir {raw:?} is not in {WORKSPACE}")),
68        None => raw,
69    };
70    if rel.split('/').any(|part| part == "..") || rel.contains('\0') {
71        return Err(format!("dir {raw:?} leaves {WORKSPACE}"));
72    }
73    Ok(if rel.is_empty() { WORKSPACE.to_string() } else { format!("{WORKSPACE}/{}", rel.trim_end_matches('/')) })
74}
75
76/// A command worth running: not empty, and short enough to be one.
77pub fn clean_command(command: &str) -> Result<String, String> {
78    let command = command.trim();
79    if command.is_empty() {
80        return Err("command must not be empty".to_string());
81    }
82    if command.len() > MAX_COMMAND_BYTES || command.contains('\0') {
83        return Err(format!("command must be text of at most {MAX_COMMAND_BYTES} bytes"));
84    }
85    Ok(command.to_string())
86}
87
88/// The dev servers kept up, in a file in this instance's data folder (which an upgrade keeps, and no other channel or
89/// checkout shares) so they outlive srv too.
90pub struct Store {
91    path: Option<PathBuf>,
92    specs: Mutex<Vec<Spec>>,
93}
94
95impl Store {
96    /// The store in `path` (as left by an earlier run); in memory only when there is none.
97    pub fn open(path: Option<PathBuf>) -> Self {
98        let mut specs: Vec<Spec> = path
99            .as_ref()
100            .and_then(|p| std::fs::read_to_string(p).ok())
101            .and_then(|text| serde_json::from_str(&text).ok())
102            .unwrap_or_default();
103        let now = now_secs_u64();
104        specs.retain(|s| s.seen == 0 || now.saturating_sub(s.seen) < FORGET_AFTER_SECS);
105        Self { path, specs: Mutex::new(specs) }
106    }
107
108    fn lock(&self) -> std::sync::MutexGuard<'_, Vec<Spec>> {
109        self.specs.lock().unwrap_or_else(|poisoned| poisoned.into_inner())
110    }
111
112    fn save(&self, specs: &[Spec]) {
113        let Some(path) = &self.path else { return };
114        let tmp = path.with_extension("json.tmp");
115        let written = serde_json::to_vec_pretty(specs).map_err(|e| e.to_string()).and_then(|bytes| {
116            std::fs::create_dir_all(path.parent().unwrap_or(std::path::Path::new("."))).map_err(|e| e.to_string())?;
117            std::fs::write(&tmp, bytes).and_then(|()| std::fs::rename(&tmp, path)).map_err(|e| e.to_string())
118        });
119        if let Err(e) = written {
120            tracing::warn!(error = %e, "[dev-keepalive] couldn't save the dev servers kept up");
121        }
122    }
123
124    /// Whether `spec` can be kept: the container has room for it, or it replaces its project's.
125    pub fn can_keep(&self, spec: &Spec) -> Result<(), String> {
126        let specs = self.lock();
127        let others = specs.iter().filter(|s| s.container == spec.container && s.project != spec.project).count();
128        if others >= MAX_PER_CONTAINER {
129            return Err(format!("at most {MAX_PER_CONTAINER} dev servers can be kept up per container"));
130        }
131        Ok(())
132    }
133
134    /// Keep `spec` up, replacing the one for the same project in the same container.
135    pub fn keep(&self, mut spec: Spec) -> Result<(), String> {
136        self.can_keep(&spec)?;
137        spec.seen = now_secs_u64();
138        let mut specs = self.lock();
139        specs.retain(|s| !(s.container == spec.container && s.project == spec.project));
140        specs.push(spec);
141        self.save(&specs);
142        Ok(())
143    }
144
145    /// `container` ran a turn: what is kept up in it is in use.
146    fn touch(&self, container: &str) {
147        let mut specs = self.lock();
148        let now = now_secs_u64();
149        for s in specs.iter_mut().filter(|s| s.container == container) {
150            s.seen = now;
151        }
152        // And those nobody has used for a month: this runs on every turn, so a long-lived srv lets them go too.
153        specs.retain(|s| s.seen == 0 || now.saturating_sub(s.seen) < FORGET_AFTER_SECS);
154        self.save(&specs);
155    }
156
157    /// Stop keeping `project` up in `container` (it was registered again without a command).
158    pub fn drop_project(&self, container: &str, project: &str) {
159        let mut specs = self.lock();
160        let before = specs.len();
161        specs.retain(|s| !(s.container == container && s.project == project));
162        if specs.len() != before {
163            self.save(&specs);
164        }
165    }
166
167    /// Whether `spec` is still what is kept for its project: not dropped, and not replaced by another command or port.
168    pub fn is_current(&self, spec: &Spec) -> bool {
169        self.lock().iter().any(|s| {
170            (&s.container, &s.project, s.port, &s.command, &s.dir) == (&spec.container, &spec.project, spec.port, &spec.command, &spec.dir)
171        })
172    }
173
174    pub fn for_container(&self, container: &str) -> Vec<Spec> {
175        self.lock().iter().filter(|s| s.container == container).cloned().collect()
176    }
177}
178
179/// The store every dev server is kept in.
180pub fn store() -> &'static Store {
181    static STORE: OnceLock<Store> = OnceLock::new();
182    STORE.get_or_init(|| Store::open(agentmux_common::DataPaths::from_env().map(|p| p.data_dir.join("dev-servers.json"))))
183}
184
185/// Why a route to a container's dev server can't be made.
186#[derive(Debug)]
187pub enum RouteError {
188    /// No running container of that name on the agents network.
189    NoContainer,
190    /// The relay a Docker Desktop host reaches containers through isn't available.
191    Relay(String),
192    /// The container's address isn't one.
193    Address(String),
194}
195
196/// How the proxy reaches `port` in `container`: its address on the agents network, or through the relay where the
197/// daemon runs in a VM and that address isn't routable from here.
198pub async fn route_target(cm: &ContainerManager, container: &str, port: u16) -> Result<Target, RouteError> {
199    let ip = cm.agent_network_ip(container).await.ok_or(RouteError::NoContainer)?;
200    if crate::backend::dev_relay::needed(cm).await {
201        let image = cm.docker().inspect_container(container, None).await.ok().and_then(|c| c.config?.image).unwrap_or_default();
202        let via = crate::backend::dev_relay::ensure(cm, &image).await.map_err(RouteError::Relay)?;
203        return Ok(Target::Relay { via, container: container.to_string(), port });
204    }
205    format!("{ip}:{port}").parse::<std::net::SocketAddr>().map(Target::Direct).map_err(|e| RouteError::Address(format!("{ip}:{port}: {e}")))
206}
207
208/// One start at a time per container, and a server started a moment ago is waited for, not started again.
209fn start_lock(container: &str) -> std::sync::Arc<tokio::sync::Mutex<()>> {
210    static LOCKS: OnceLock<Mutex<std::collections::HashMap<String, std::sync::Arc<tokio::sync::Mutex<()>>>>> = OnceLock::new();
211    LOCKS.get_or_init(Default::default).lock().unwrap_or_else(|p| p.into_inner()).entry(container.to_string()).or_default().clone()
212}
213
214/// When each `(container, project)` was last started, and in which incarnation of the container (its Docker id): a
215/// recreated container has none of what ran in the old one. Tells a server that is slow to listen from one not running.
216fn started_recently(container: &str, project: &str, incarnation: &str, set: bool) -> bool {
217    static STARTED: OnceLock<Mutex<std::collections::HashMap<(String, String), (Instant, String)>>> = OnceLock::new();
218    let mut started = STARTED.get_or_init(Default::default).lock().unwrap_or_else(|p| p.into_inner());
219    let key = (container.to_string(), project.to_string());
220    if set {
221        started.insert(key, (Instant::now(), incarnation.to_string()));
222        return true;
223    }
224    started.get(&key).is_some_and(|(at, id)| id == incarnation && at.elapsed() < STARTUP_WAIT)
225}
226
227/// Start `spec`'s command unless the server is listening already or was started within the startup wait. With `only_if_kept`
228/// (a restore), nothing is started once the agent has dropped the project or replaced its registration, however long this waited.
229pub async fn start(cm: &ContainerManager, spec: &Spec, only_if_kept: bool) -> Result<(), String> {
230    let lock = start_lock(&spec.container);
231    let _one_at_a_time = lock.lock().await;
232    if only_if_kept && !store().is_current(spec) {
233        return Ok(());
234    }
235    // The container's Docker id and when it last started: a stopped container that starts again keeps its id.
236    let incarnation = incarnation_of(cm, &spec.container).await;
237    // And what was started: another port, command or folder is a different launch, not one still starting.
238    let incarnation = format!("{incarnation}|{}|{}|{}", spec.port, spec.command, spec.dir);
239    if cm.port_listening(&spec.container, spec.port).await || started_recently(&spec.container, &spec.project, &incarnation, false) {
240        return Ok(());
241    }
242    let env = crate::backend::container::credential::watcher_polling_env(cfg!(any(windows, target_os = "macos")), &[]);
243    cm.start_dev_server(&spec.container, &spec.command, &spec.dir, &env, &spec.log())
244        .await
245        .map_err(|e| format!("couldn't start {:?}: {e}", spec.command))?;
246    started_recently(&spec.container, &spec.project, &incarnation, true);
247    Ok(())
248}
249
250/// Whether `spec`'s server is listening within `wait`.
251pub async fn wait_listening(cm: &ContainerManager, spec: &Spec, wait: Duration) -> bool {
252    let deadline = Instant::now() + wait;
253    loop {
254        if cm.port_listening(&spec.container, spec.port).await {
255            return true;
256        }
257        if Instant::now() >= deadline {
258            return false;
259        }
260        tokio::time::sleep(Duration::from_millis(500)).await;
261    }
262}
263
264/// Make sure `spec`'s server is listening: start it if it isn't, and wait up to the startup wait.
265pub async fn bring_up(cm: &ContainerManager, spec: &Spec, only_if_kept: bool) -> Result<(), String> {
266    start(cm, spec, only_if_kept).await?;
267    if only_if_kept && !store().is_current(spec) {
268        return Ok(());
269    }
270    if wait_listening(cm, spec, STARTUP_WAIT).await {
271        return Ok(());
272    }
273    Err(format!("{:?} didn't start listening on port {} within {}s; its output is in {} in the container", spec.command, spec.port, STARTUP_WAIT_SECS, spec.log()))
274}
275
276/// Register `spec`'s route once its server listens, in the background; for a server too slow to wait for in a request.
277pub fn route_when_listening(cm: &ContainerManager, spec: Spec) {
278    let cm = cm.clone();
279    tokio::spawn(async move {
280        if !wait_listening(&cm, &spec, STARTUP_WAIT).await {
281            tracing::warn!(container = %spec.container, project = %spec.project, "[dev-keepalive] the dev server never listened; its output is in {}", spec.log());
282            return;
283        }
284        match route_target(&cm, &spec.container, spec.port).await {
285            // Only if the agent hasn't registered the project again, or dropped it, while this waited.
286            Ok(target) if store().is_current(&spec) => {
287                if let Some(registry) = cm.dev_proxy_registry() {
288                    registry.register_from(&spec.project, &spec.agent_id, Some(&spec.container), target).await;
289                }
290            }
291            Ok(_) => {}
292            Err(e) => tracing::warn!(container = %spec.container, error = ?e, "[dev-keepalive] no route to the dev server"),
293        }
294    });
295}
296
297/// The incarnation of `container` (its Docker id and when it last started), as [`start`] tells containers apart.
298async fn incarnation_of(cm: &ContainerManager, container: &str) -> String {
299    cm.docker()
300        .inspect_container(container, None)
301        .await
302        .ok()
303        .map(|c| format!("{}@{}", c.id.unwrap_or_default(), c.state.and_then(|s| s.started_at).unwrap_or_default()))
304        .unwrap_or_default()
305}
306
307/// Start the dev servers kept up in `container` that aren't listening, and register their routes, without holding
308/// up the caller. Called when the container is ready for a turn. One restore runs per incarnation of the container: a
309/// turn while it is still going has nothing to add, but a container that was recreated meanwhile is restored afresh.
310pub fn restore_in_background(cm: &ContainerManager, container: &str) {
311    static RESTORING: OnceLock<Mutex<HashSet<(String, String)>>> = OnceLock::new();
312    if store().for_container(container).is_empty() {
313        return;
314    }
315    store().touch(container);
316    let (cm, container) = (cm.clone(), container.to_string());
317    tokio::spawn(async move {
318        /// Clears the incarnation's entry however the task ends.
319        struct Done((String, String));
320        impl Drop for Done {
321            fn drop(&mut self) {
322                RESTORING.get_or_init(Default::default).lock().unwrap_or_else(|p| p.into_inner()).remove(&self.0);
323            }
324        }
325        let key = (container.clone(), incarnation_of(&cm, &container).await);
326        if !RESTORING.get_or_init(Default::default).lock().unwrap_or_else(|p| p.into_inner()).insert(key.clone()) {
327            return;
328        }
329        let _done = Done(key);
330        for spec in &store().for_container(&container) {
331            let routed = async {
332                bring_up(&cm, spec, true).await?;
333                let target = route_target(&cm, &spec.container, spec.port).await.map_err(|e| format!("{e:?}"))?;
334                let registry = cm.dev_proxy_registry().ok_or("no dev proxy")?;
335                // Only if it is still what the agent wants kept: it may have registered the project again while this ran.
336                if store().is_current(spec) {
337                    registry.register_from(&spec.project, &spec.agent_id, Some(&spec.container), target).await;
338                }
339                Ok::<(), String>(())
340            }
341            .await;
342            match routed {
343                Ok(()) => tracing::info!(container = %spec.container, project = %spec.project, port = spec.port, "[dev-keepalive] dev server up"),
344                Err(e) => tracing::warn!(container = %spec.container, project = %spec.project, error = %e, "[dev-keepalive] couldn't bring the dev server up"),
345            }
346        }
347    });
348}
349
350#[cfg(test)]
351mod tests {
352    use super::*;
353
354    fn spec(container: &str, project: &str) -> Spec {
355        Spec {
356            agent_id: "kcont".into(),
357            container: container.into(),
358            project: project.into(),
359            port: 4600,
360            command: "npm run dev".into(),
361            dir: "/workspace/landing".into(),
362            seen: 0,
363        }
364    }
365
366    /// What a store holds for `container`, without the time each was last used.
367    fn kept(store: &Store, container: &str) -> Vec<Spec> {
368        store.for_container(container).into_iter().map(|s| Spec { seen: 0, ..s }).collect()
369    }
370
371    #[test]
372    fn a_dir_stays_in_the_workspace() {
373        assert_eq!(clean_dir(None).unwrap(), "/workspace");
374        assert_eq!(clean_dir(Some("  ")).unwrap(), "/workspace");
375        assert_eq!(clean_dir(Some("/workspace")).unwrap(), "/workspace");
376        assert_eq!(clean_dir(Some("landing")).unwrap(), "/workspace/landing");
377        assert_eq!(clean_dir(Some("/workspace/landing/")).unwrap(), "/workspace/landing");
378        for bad in ["/etc", "/workspacefoo", "../x", "/workspace/../etc", "a/../../b"] {
379            assert!(clean_dir(Some(bad)).is_err(), "{bad}");
380        }
381    }
382
383    #[test]
384    fn a_command_is_text_of_a_sensible_size() {
385        assert_eq!(clean_command("  npm run dev \n").unwrap(), "npm run dev");
386        assert!(clean_command("   ").is_err());
387        assert!(clean_command(&"x".repeat(MAX_COMMAND_BYTES + 1)).is_err());
388        assert!(clean_command("a\0b").is_err());
389    }
390
391    #[test]
392    fn a_container_keeps_a_project_once_and_only_so_many() {
393        let store = Store::open(None);
394        store.keep(spec("c1", "landing")).unwrap();
395        let mut again = spec("c1", "landing");
396        again.command = "npm start".into();
397        store.keep(again.clone()).unwrap();
398        assert_eq!(kept(&store, "c1"), vec![again], "the same project is replaced, not added");
399        assert!(store.for_container("c2").is_empty());
400        for i in 1..MAX_PER_CONTAINER {
401            store.keep(spec("c1", &format!("p{i}"))).unwrap();
402        }
403        assert!(store.can_keep(&spec("c1", "one-too-many")).is_err(), "the cap is known before anything is started");
404        assert!(store.can_keep(&spec("c1", "landing")).is_ok(), "replacing a project needs no room");
405        assert!(store.keep(spec("c1", "one-too-many")).is_err());
406        store.keep(spec("c2", "other")).unwrap();
407        store.drop_project("c1", "landing");
408        assert!(store.for_container("c1").iter().all(|s| s.project != "landing"));
409        assert_eq!(store.for_container("c2").len(), 1, "another container's servers are untouched");
410    }
411
412    #[test]
413    fn a_spec_is_current_only_until_the_project_is_registered_again_or_dropped() {
414        let store = Store::open(None);
415        store.keep(spec("c1", "landing")).unwrap();
416        assert!(store.is_current(&spec("c1", "landing")));
417        let mut moved = spec("c1", "landing");
418        moved.port = 5000;
419        store.keep(moved.clone()).unwrap();
420        assert!(!store.is_current(&spec("c1", "landing")), "the old port is no longer wanted");
421        assert!(store.is_current(&moved));
422        store.drop_project("c1", "landing");
423        assert!(!store.is_current(&moved));
424    }
425
426    #[test]
427    fn what_is_kept_up_survives_a_restart() {
428        let dir = tempfile::tempdir().unwrap();
429        let path = dir.path().join("dev-servers.json");
430        let store = Store::open(Some(path.clone()));
431        store.keep(spec("c1", "landing")).unwrap();
432        let reopened = Store::open(Some(path.clone()));
433        assert_eq!(kept(&reopened, "c1"), vec![spec("c1", "landing")]);
434        reopened.drop_project("c1", "landing");
435        assert!(Store::open(Some(path)).for_container("c1").is_empty());
436        std::fs::write(dir.path().join("bad.json"), "not json").unwrap();
437        assert!(Store::open(Some(dir.path().join("bad.json"))).for_container("c1").is_empty(), "a damaged file is no servers, not a crash");
438    }
439
440    #[test]
441    fn a_server_nobody_has_run_a_turn_beside_for_a_month_is_let_go() {
442        let dir = tempfile::tempdir().unwrap();
443        let path = dir.path().join("dev-servers.json");
444        let (old, fresh) = (Spec { seen: now_secs_u64() - FORGET_AFTER_SECS - 10, ..spec("c1", "old") }, Spec { seen: now_secs_u64(), ..spec("c1", "fresh") });
445        std::fs::write(&path, serde_json::to_vec(&[old, fresh]).unwrap()).unwrap();
446        let store = Store::open(Some(path));
447        assert_eq!(store.for_container("c1").iter().map(|s| s.project.as_str()).collect::<Vec<_>>(), ["fresh"]);
448    }
449
450    /// Against a real daemon: a server is started for a container, and started again in a recreated one.
451    ///   cargo test -p agentmux-srv-core --lib -- --ignored --nocapture itest_dev_keepalive
452    #[tokio::test]
453    #[ignore]
454    async fn itest_dev_keepalive_starts_the_server_again_in_a_recreated_container() {
455        use bollard::container::{Config, CreateContainerOptions, RemoveContainerOptions, StartContainerOptions};
456        use bollard::models::HostConfig;
457        let cm = ContainerManager::connect().expect("connect to docker (set DOCKER_HOST)");
458        cm.check_available().await.expect("docker daemon must be reachable");
459        let docker = cm.docker();
460        let (image, name) = ("ghcr.io/agentmuxai/agent-base:0.60.3", "agentmux-itest-keepalive");
461        let network = crate::backend::container::AGENTMUX_DOCKER_NETWORK;
462        let _ = docker.create_network(bollard::network::CreateNetworkOptions { name: network, driver: "bridge", ..Default::default() }).await;
463        async fn fresh(docker: &bollard::Docker, image: &str, name: &str, network: &str) {
464            let _ = docker.remove_container(name, Some(RemoveContainerOptions { force: true, ..Default::default() })).await;
465            docker
466                .create_container(
467                    Some(CreateContainerOptions { name, platform: None }),
468                    Config {
469                        image: Some(image.to_string()),
470                        cmd: Some(vec!["sleep".into(), "300".into()]),
471                        user: Some("agent".into()),
472                        host_config: Some(HostConfig { network_mode: Some(network.to_string()), ..Default::default() }),
473                        ..Default::default()
474                    },
475                )
476                .await
477                .expect("create");
478            docker.start_container(name, None::<StartContainerOptions<String>>).await.expect("start");
479        }
480        let spec = Spec {
481            agent_id: "itest".into(),
482            container: name.into(),
483            project: "itest".into(),
484            port: 7000,
485            command: "node -e \"require('http').createServer((q,r)=>r.end('hi')).listen(7000,'0.0.0.0')\"".into(),
486            dir: "/tmp".into(),
487            seen: 0,
488        };
489        fresh(docker, image, name, network).await;
490        assert!(!cm.port_listening(name, 7000).await);
491        bring_up(&cm, &spec, false).await.expect("started");
492        assert!(cm.port_listening(name, 7000).await);
493        bring_up(&cm, &spec, false).await.expect("already up: nothing is started twice");
494        // The same project on another port straight away is another launch, not the first one still starting.
495        let moved = Spec { port: 7001, command: spec.command.replace("7000", "7001"), ..spec.clone() };
496        bring_up(&cm, &moved, false).await.expect("the new port is started at once");
497        assert!(cm.port_listening(name, 7001).await);
498        // The container is recreated: the server is gone, and comes back.
499        fresh(docker, image, name, network).await;
500        assert!(!cm.port_listening(name, 7000).await, "a recreated container starts empty");
501        bring_up(&cm, &spec, false).await.expect("started again");
502        assert!(cm.port_listening(name, 7000).await);
503        let _ = docker.remove_container(name, Some(RemoveContainerOptions { force: true, ..Default::default() })).await;
504    }
505}