Skip to main content

agentmux_srv/migrations/
m0003_template_sessions_v1.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::sync::Arc;
5use crate::backend::storage::store::Store;
6use crate::backend::storage::filestore::FileStore;
7use super::{Migration, MigrationContext, MigrationError, MigrationScope};
8
9pub struct M0003TemplateSessionsV1;
10
11impl Migration for M0003TemplateSessionsV1 {
12    fn id(&self) -> &'static str { "0003_template_sessions_v1" }
13    fn scope(&self) -> MigrationScope { MigrationScope::Channel }
14    fn description(&self) -> &'static str { "Promote template sessions to user-owned definitions" }
15
16    fn up(&self, ctx: &MigrationContext) -> Result<(), MigrationError> {
17        if !ctx.channel_store_path.exists() {
18            return Ok(());
19        }
20        let mstore = Arc::new(
21            Store::open(&ctx.channel_store_path)
22                .map_err(|e| MigrationError(format!("template_sessions_v1: open mstore: {}", e)))?,
23        );
24        let filestore_path = ctx.data_dir.join("db").join("filestore.db");
25        let filestore = Arc::new(
26            FileStore::open(&filestore_path)
27                .map_err(|e| MigrationError(format!("template_sessions_v1: open filestore: {}", e)))?,
28        );
29        crate::backend::agent_session::migrate_promote_template_sessions_v1(&mstore, &filestore, &ctx.data_dir);
30        Ok(())
31    }
32
33    // No `verify()` on purpose. SPEC_MIGRATION_SYSTEM_HARDENING_2026_08_03
34    // Phase 1 lists 0003 alongside 0002 as "the same legacy-marker pattern",
35    // but it is not: `migrate_promote_template_sessions_v1` explicitly
36    // IGNORES its marker file and re-asserts the data invariant ("no seeded
37    // definition has a session zone") on every startup — see
38    // `agent_session/migrations/v1_templates.rs`'s doc comment. A mismatch
39    // here is self-healing on the next start, so a doctor check would report
40    // a condition that cannot persist. Reporting `NotVerifiable` is more
41    // honest than a check whose "mismatch" means nothing.
42}