Skip to main content

agentmux_srv/sagas/
teardown_hooks.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The sagas' side of `backend::teardown_hooks`: the watchdog, the controller replace and the tab close call
5//! these through the hook, so `backend/` does not name the agent teardown.
6
7use std::sync::Arc;
8
9use crate::backend::blockcontroller::Controller;
10use crate::backend::teardown_hooks::TeardownHooks;
11
12struct Hooks;
13
14/// The teardown's entries, for `backend::teardown_hooks::install`.
15pub(crate) fn hooks() -> Arc<dyn TeardownHooks> {
16    Arc::new(Hooks)
17}
18
19/// Register them. Called once at startup, before any controller runs.
20pub(crate) fn install() {
21    crate::backend::teardown_hooks::install(hooks());
22}
23
24impl TeardownHooks for Hooks {
25    fn stop_now(&self, block_id: &str, graceful: bool) -> Result<(), String> {
26        super::agent_teardown::stop_now(block_id, graceful)
27    }
28
29    fn replace_now(&self, ctrl: &dyn Controller) -> Result<(), String> {
30        super::agent_teardown::replace_now(ctrl)
31    }
32
33    fn discard(&self, block_id: &str) {
34        super::agent_teardown::discard(block_id)
35    }
36}