Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
feat(move-project): require an explicit opt-in for a lossy merge
AkitaOnRails10dc287c8e7c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e53e5220..5954295a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -122,6 +122,16 @@ version in [`docs/changelog/`](docs/changelog/):### Changed+- `move-project` now refuses the **copy+purge merge** — the path taken when the+ destination workspace already holds a project of the same name — unless+ `--allow-lossy-merge` is passed as well as `--confirm`. That path keeps only+ the source's latest pages and deletes the project with its sessions,+ observations, handoffs and older page versions, which `--confirm` written for+ "move this project" did not say; the refusal answers `409` with the counts it+ would discard. A true-move (fresh destination, everything preserved) is+ unchanged, and `merge-workspace`, whose command already says merge, keeps+ working without the extra flag (#1713).+- `memory_install_self_routing(compact: true)` and `ai-memoryinstall-instructions --compact` now return a block that is actually compact:2.1 KB instead of 5.9 KB, close to the 7.9 KB full block it was supposed todiff --git a/crates/ai-memory-cli/src/cli.rs b/crates/ai-memory-cli/src/cli.rsindex eee5f01f..caf7ed07 100644--- a/crates/ai-memory-cli/src/cli.rs+++ b/crates/ai-memory-cli/src/cli.rs@@ -1703,6 +1703,15 @@ pub struct MoveProjectArgs {/// lands under a de-duplicated path).#[arg(long, value_parser = ["block", "overwrite", "duplicate"], default_value = "block")]pub on_conflict: String,+ /// Allow the copy+purge merge when the destination workspace already holds+ /// a project of the same name.+ ///+ /// That path is not a move: it copies the source's latest pages and+ /// deletes the project with its sessions, observations, handoffs and older+ /// page versions. Without this flag the server refuses and reports the+ /// counts it would discard (#1713).+ #[arg(long)]+ pub allow_lossy_merge: bool,}/// Arguments for `move-session`.diff --git a/crates/ai-memory-cli/src/commands/move_project.rs b/crates/ai-memory-cli/src/commands/move_project.rsindex 08920d97..ffa389a7 100644--- a/crates/ai-memory-cli/src/commands/move_project.rs+++ b/crates/ai-memory-cli/src/commands/move_project.rs@@ -23,6 +23,8 @@ struct MoveProjectRequest {confirm: bool,force: bool,on_conflict: String,+ /// Acknowledge the copy+purge merge (#1713).+ allow_lossy_merge: bool,}/// The exact command that performs the move the refusal just described.@@ -46,6 +48,9 @@ fn confirm_command(from_workspace: &str, target_flag: &str, args: &MoveProjectArif args.force {cmd.push_str(" --force");}+ if args.allow_lossy_merge {+ cmd.push_str(" --allow-lossy-merge");+ }if args.on_conflict != "block" {cmd.push_str(&format!(" --on-conflict {}",@@ -133,6 +138,7 @@ pub async fn run(config: &Config, args: MoveProjectArgs) -> Result<()> {confirm: true,force: args.force,on_conflict: args.on_conflict.clone(),+ allow_lossy_merge: args.allow_lossy_merge,},).await?;@@ -230,6 +236,7 @@ mod tests {confirm: false,force: false,on_conflict: "block".into(),+ allow_lossy_merge: false,}}diff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rsindex 5d721bf5..9b00f18c 100644--- a/crates/ai-memory-mcp/src/admin.rs+++ b/crates/ai-memory-mcp/src/admin.rs@@ -6383,6 +6383,13 @@ struct MoveProjectRequest {/// live managed-workstream lease in the destructive copy-purge path.#[serde(default)]force: bool,+ /// Acknowledge that this move is a **copy+purge merge** rather than a+ /// true-move, and that the source project's history goes with it (#1713).+ /// The server picks the strategy from the destination; when it resolves to+ /// the merge path and this is absent, the move is refused with the record+ /// counts it would discard.+ #[serde(default)]+ allow_lossy_merge: bool,/// Policy for the copy-purge MERGE path when a source page's path already/// exists in the destination with DIFFERENT content. Ignored by true-move/// (no copy). Default `block` — the safe choice for a destructive op.@@ -6909,6 +6916,39 @@ async fn move_project_core(// MERGE: the destination already holds a same-named project. Get-or-create// it (auto-creating the destination workspace) and copy the source's// latest pages into it, then purge the source.+ //+ // That second half is not a move: the source's sessions, observations,+ // handoffs and older page versions are deleted, while a true-move keeps+ // them. A `--confirm` written for "move this project" does not say that,+ // so the merge path needs its own acknowledgement and shows the counts it+ // would discard (#1713).+ if !req.allow_lossy_merge {+ let counts = state+ .reader+ .project_record_counts(src_ws, src_proj)+ .await+ .unwrap_or_default();+ return Err((+ StatusCode::CONFLICT,+ Json(serde_json::json!({+ "error": format!(+ "the destination workspace already holds a project named '{project_name}', so \+ this move would be a copy+purge merge: it copies its {} latest page(s) into \+ that project and deletes the source project with its {} session(s), {} \+ observation(s) and {} handoff(s). A true-move keeps all of that; to merge, \+ re-run with --allow-lossy-merge (allow_lossy_merge=true)",+ counts.pages, counts.sessions, counts.observations, counts.handoffs,+ ),+ "strategy": "copy-purge",+ "discarded": {+ "pages_copied": counts.pages,+ "sessions": counts.sessions,+ "observations": counts.observations,+ "handoffs": counts.handoffs,+ },+ })),+ ));+ }let destination = create_ws_proj(state, &req.to_workspace, &project_name).await?;let (dst_ws, dst_proj) = destination.scope.as_tuple();@@ -8416,6 +8456,10 @@ async fn handle_merge_workspace(confirm: true,force: req.force,on_conflict: req.on_conflict,+ // `merge-workspace` is the explicit merge command: the operator+ // already asked for the two workspaces to be combined, so a+ // same-named project is merged rather than refused (#1713).+ allow_lossy_merge: true,};match move_project_core(&state, &move_req, actor.clone()).await {Ok(report) => merged.push(report),diff --git a/crates/ai-memory-mcp/tests/suite/admin_move.rs b/crates/ai-memory-mcp/tests/suite/admin_move.rsindex 4bfbb67b..3c822590 100644--- a/crates/ai-memory-mcp/tests/suite/admin_move.rs+++ b/crates/ai-memory-mcp/tests/suite/admin_move.rs@@ -236,7 +236,7 @@ async fn move_project_true_move_into_fresh_dest() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK, "move must succeed");@@ -364,7 +364,7 @@ async fn move_project_merge_surfaces_destination_promotion_manifest_warning() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "acme-api", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "acme-api", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -420,7 +420,7 @@ async fn move_project_404_on_unknown_source() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "nope", "project": "ghost", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "nope", "project": "ghost", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::NOT_FOUND);@@ -428,6 +428,107 @@ async fn move_project_404_on_unknown_source() {/// Moving into a workspace that already has a same-named project MERGES:/// the destination ends up with both the pre-existing and the moved pages.+/// #1713: the copy+purge merge is not a move. A `--confirm` written for "move+/// this project" must not delete a source's sessions and observations just+/// because the destination happens to hold a project of the same name. The+/// refusal names the counts it would discard and leaves the source intact;+/// the same request with `allow_lossy_merge` proceeds.+#[tokio::test]+async fn a_copy_purge_merge_requires_its_own_acknowledgement() {+ let tmp = TempDir::new().unwrap();+ let (state, store) = make_state(&tmp).await;+ seed_page(&store, &state.wiki, "src", "proj", "notes/a.md", "body a").await;+ seed_page(&store, &state.wiki, "dst", "proj", "notes/b.md", "body b").await;+ let session = SessionId::new();+ store+ .writer+ .begin_session(NewSession {+ occurred_at: None,+ id: session,+ workspace_id: store+ .reader+ .find_workspace("src".to_string())+ .await+ .unwrap()+ .unwrap(),+ project_id: store+ .reader+ .find_project(+ store+ .reader+ .find_workspace("src".to_string())+ .await+ .unwrap()+ .unwrap(),+ "proj".to_string(),+ )+ .await+ .unwrap()+ .unwrap(),+ agent_kind: AgentKind::Codex,+ cwd: Some("/src/proj".into()),+ actor_user: None,+ })+ .await+ .unwrap();++ let resp = post(+ state.clone(),+ "/admin/move-project",+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ )+ .await;+ assert_eq!(resp.status(), StatusCode::CONFLICT);+ let body = body_json(resp).await;+ assert_eq!(body["strategy"], "copy-purge", "{body}");+ assert_eq!(body["discarded"]["sessions"], 1, "{body}");+ assert_eq!(body["discarded"]["pages_copied"], 1, "{body}");+ let error = body["error"].as_str().unwrap_or_default();+ assert!(error.contains("--allow-lossy-merge"), "{error}");+ assert!(error.contains("1 session(s)"), "{error}");++ // The source is untouched: its page and its session are both still there.+ assert_eq!(+ store.reader.list_pages("src", "proj").await.unwrap().len(),+ 1+ );+ let src_ws = store+ .reader+ .find_workspace("src".to_string())+ .await+ .unwrap()+ .unwrap();+ let src_proj = store+ .reader+ .find_project(src_ws, "proj".to_string())+ .await+ .unwrap()+ .unwrap();+ assert_eq!(+ store+ .reader+ .project_record_counts(src_ws, src_proj)+ .await+ .unwrap()+ .sessions,+ 1,+ "the refusal must not delete the source's history"+ );++ // The same request with the acknowledgement proceeds; the merge tests+ // below cover that path end to end.+ let resp = post(+ state,+ "/admin/move-project",+ json!({+ "from_workspace": "src", "project": "proj", "to_workspace": "dst",+ "confirm": true, "allow_lossy_merge": true+ }),+ )+ .await;+ assert_eq!(resp.status(), StatusCode::OK);+}+#[tokio::test]async fn move_project_merges_into_existing_dest() {let tmp = TempDir::new().unwrap();@@ -438,7 +539,7 @@ async fn move_project_merges_into_existing_dest() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -489,7 +590,7 @@ async fn move_project_same_workspace_rejected() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "w", "project": "proj", "to_workspace": "w", "confirm": true }),+ json!({ "from_workspace": "w", "project": "proj", "to_workspace": "w", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::UNPROCESSABLE_ENTITY);@@ -510,7 +611,7 @@ async fn move_project_refuses_a_private_profile() {"from_workspace": "default","project": "_profile.00000000000000000000000000000001","to_workspace": "elsewhere",- "confirm": true+ "confirm": true, "allow_lossy_merge": true}),).await;@@ -609,7 +710,7 @@ async fn move_project_carries_source_embedding() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -710,7 +811,7 @@ async fn move_project_true_move_preserves_sessions_and_observations() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -753,7 +854,7 @@ async fn true_move_stale_source_write_fails_before_creating_file() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -856,7 +957,7 @@ async fn true_move_notifies_admission_with_destination_names() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -956,7 +1057,7 @@ async fn true_move_refuses_an_invalid_destination_namespace_without_db_changes()let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR);@@ -1004,7 +1105,7 @@ async fn move_refuses_active_project_without_force() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::CONFLICT);@@ -1025,7 +1126,7 @@ async fn move_active_project_with_force_succeeds_and_republishes() {state,"/admin/move-project",json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst",- "confirm": true, "force": true }),+ "confirm": true, "allow_lossy_merge": true, "force": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -1079,7 +1180,7 @@ async fn copy_purge_force_never_deletes_a_live_managed_workstream() {"from_workspace": "src","project": "proj","to_workspace": "dst",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,"force": true}),)@@ -1155,7 +1256,7 @@ async fn copy_purge_conflict_duplicates_keeping_both() {state,"/admin/move-project",json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst",- "confirm": true, "on_conflict": "duplicate" }),+ "confirm": true, "allow_lossy_merge": true, "on_conflict": "duplicate" }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -1221,7 +1322,7 @@ async fn copy_purge_conflict_blocks_by_default() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::CONFLICT);@@ -1298,7 +1399,7 @@ async fn copy_purge_conflict_blocks_metadata_difference_by_default() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::CONFLICT);@@ -1330,7 +1431,7 @@ async fn copy_purge_conflict_overwrites() {state,"/admin/move-project",json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst",- "confirm": true, "on_conflict": "overwrite" }),+ "confirm": true, "allow_lossy_merge": true, "on_conflict": "overwrite" }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -1404,7 +1505,7 @@ async fn copy_purge_duplicate_avoids_clobbering_dedup_slot() {state,"/admin/move-project",json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst",- "confirm": true, "on_conflict": "duplicate" }),+ "confirm": true, "allow_lossy_merge": true, "on_conflict": "duplicate" }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -1495,7 +1596,7 @@ async fn copy_purge_carries_source_embedding() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -1549,7 +1650,7 @@ async fn copy_purge_partial_skips_and_preserves_source() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK);@@ -1646,7 +1747,7 @@ async fn true_move_aborts_when_admission_rejects() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(@@ -1749,7 +1850,7 @@ async fn copy_purge_purge_admission_runs_before_db_destruction() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(@@ -1868,7 +1969,7 @@ async fn move_copy_skips_contributors_webhook_but_runs_others() {let resp = post(state,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(resp.status(), StatusCode::OK, "merge move should succeed");@@ -1898,7 +1999,7 @@ async fn copy_purge_rerun_is_idempotent() {let r1 = post(s1,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;assert_eq!(r1.status(), StatusCode::OK);@@ -1915,7 +2016,7 @@ async fn copy_purge_rerun_is_idempotent() {let r2 = post(s2,"/admin/move-project",- json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true }),+ json!({ "from_workspace": "src", "project": "proj", "to_workspace": "dst", "confirm": true, "allow_lossy_merge": true }),).await;// Flaky under heavy parallel load / on Windows (observed in the 2.0@@ -3120,7 +3221,7 @@ async fn move_project_accepts_project_id_instead_of_name() {"from_workspace": "default","project_id": proj.to_string(),"to_workspace": "elsewhere",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,}),).await;@@ -3159,7 +3260,7 @@ async fn move_project_rejects_a_malformed_project_id_with_400() {"from_workspace": "default","project_id": "not-a-uuid","to_workspace": "elsewhere",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,}),).await;@@ -3180,7 +3281,7 @@ async fn move_project_unknown_project_id_is_404() {"from_workspace": "default","project_id": "00000000-0000-0000-0000-0000000000ff","to_workspace": "elsewhere",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,}),).await;@@ -3217,7 +3318,7 @@ async fn move_project_refuses_a_real_id_from_another_workspace() {"from_workspace": "default","project_id": foreign.to_string(),"to_workspace": "target",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,}),).await;@@ -3243,7 +3344,7 @@ async fn move_project_refuses_a_real_id_from_another_workspace() {"from_workspace": "elsewhere","project_id": foreign.to_string(),"to_workspace": "target",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,}),).await;@@ -3275,7 +3376,7 @@ async fn move_project_refuses_both_project_and_project_id() {"project": "movable","project_id": proj.to_string(),"to_workspace": "elsewhere",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,}),).await;@@ -3317,7 +3418,7 @@ async fn move_project_still_accepts_a_bare_project_name() {"from_workspace": "default","project": "movable","to_workspace": "elsewhere",- "confirm": true,+ "confirm": true, "allow_lossy_merge": true,}),).await;diff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rsindex 5a489c72..7d5672bb 100644--- a/crates/ai-memory-store/src/reader.rs+++ b/crates/ai-memory-store/src/reader.rs@@ -2234,6 +2234,24 @@ pub struct ProjectSummary {pub last_updated: Option<String>,}+/// Counts of the records a destructive project operation would discard+/// (#1713).+///+/// Used as the preflight a `move-project` refusal shows: the copy+purge merge+/// keeps the source's latest pages only, so the rest of this is what the+/// operator is about to delete.+#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize)]+pub struct ProjectRecordCounts {+ /// Unxpired latest pages.+ pub pages: u64,+ /// Sessions recorded in the project.+ pub sessions: u64,+ /// Observations captured for those sessions.+ pub observations: u64,+ /// Handoffs created or accepted in the project.+ pub handoffs: u64,+}+/// Pending inbox depth for one recipient project. Returned by/// [`ReaderPool::pending_inbox_counts`]; projects with nothing pending have no/// row.@@ -12899,6 +12917,44 @@ impl ReaderPool {.await}+ /// Count the records of one project, for a destructive operation's+ /// preflight (#1713).+ ///+ /// # Errors+ /// Propagates any SQL or pool error.+ pub async fn project_record_counts(+ &self,+ workspace_id: WorkspaceId,+ project_id: ProjectId,+ ) -> StoreResult<ProjectRecordCounts> {+ self.with_conn(move |conn| {+ let count = |sql: &str| -> StoreResult<u64> {+ let n: i64 = conn.query_row(+ sql,+ params![workspace_id.as_bytes(), project_id.as_bytes()],+ |row| row.get(0),+ )?;+ Ok(u64::try_from(n).unwrap_or(0))+ };+ Ok(ProjectRecordCounts {+ pages: count(+ "SELECT COUNT(*) FROM pages WHERE workspace_id = ?1 AND project_id = ?2 \+ AND is_latest = 1",+ )?,+ sessions: count(+ "SELECT COUNT(*) FROM sessions WHERE workspace_id = ?1 AND project_id = ?2",+ )?,+ observations: count(+ "SELECT COUNT(*) FROM observations WHERE workspace_id = ?1 AND project_id = ?2",+ )?,+ handoffs: count(+ "SELECT COUNT(*) FROM handoffs WHERE workspace_id = ?1 AND project_id = ?2",+ )?,+ })+ })+ .await+ }+/// Physical storage figures for the database file.////// Three `PRAGMA` reads, no table scan, so it is cheap enough to sit indiff --git a/docs/lifecycle-ops.md b/docs/lifecycle-ops.mdindex 4fe26ea6..ecf1ecbd 100644--- a/docs/lifecycle-ops.md+++ b/docs/lifecycle-ops.md@@ -14,7 +14,7 @@ on a homelab box where mistakes are harder to undo.| `rename-project --from --to` | ✅ yes | no | yes (rename back) | Column-only update on `projects.name`. The on-disk dir is keyed by `project_id` (UUID), so the rename never moves a file. || `/admin/rename-workspace` | ✅ yes | no | yes (rename back) | Column-only update on `workspaces.name`; refreshes `_meta.md` scope manifests and checkpoints the wiki tree. || `/admin/delete-workspace` | ✅ yes | the workspace and every child project, **plus** any observation stamped into a different workspace by one of this workspace's sessions (cascades regardless of the observation's own `workspace_id`), and it nulls (does not delete) the session reference on any handoff in a different workspace that this workspace's sessions authored or accepted | no | Runs `purge_workspace` admission first, deletes SQLite rows in one cascade, removes the UUID-keyed workspace directory and managed-workstream raw segments, reports filesystem partial failures, and dispatches mirror notification after durable work. Logical delete by default; `"compact": true` additionally rebuilds the FTS indexes and `VACUUM`s (see below). `"dry_run": true` previews the same counts, including the cross-workspace ones, without deleting anything (see below). |-| `move-project --confirm` | ✅ yes | source only in the merge case (a `Reject`-policy `purge_project` webhook can still abort the source teardown leaving everything intact) | no | Fresh destination → lossless **true move** (re-stamp `workspace_id`, keep `project_id`, rename the dir): sessions/observations/handoffs + history all survive. Destination with a same-named project → **copy+purge merge**: only latest pages migrate. |+| `move-project --confirm` | ✅ yes | source only in the merge case (a `Reject`-policy `purge_project` webhook can still abort the source teardown leaving everything intact) | no | Fresh destination → lossless **true move** (re-stamp `workspace_id`, keep `project_id`, rename the dir): sessions/observations/handoffs + history all survive. Destination with a same-named project → **copy+purge merge**: only latest pages migrate. An existing same-named destination project makes this a **copy+purge merge**, which deletes the source's sessions, observations, handoffs and older page versions: it now needs `--allow-lossy-merge` as well, and without it the server answers `409` naming the counts it would discard (#1713). || `move-session <id> --to --confirm` | ✅ yes | no | yes (move it back) | Re-stamps one session (or every session touching `--from-project`) into another project: `sessions`, `observations`, its `handoffs`, consolidation jobs, auto-improve runs/claims, profile prompt candidates, ingest keys and its `sessions/<id>.md` page, one transaction per session; the page file moves with it (`--pages move`, default) or is retired for regeneration. Without `--confirm` it is a real dry run (rolled back). Refuses with `409` an open session or a pending consolidation job unless `--force`. || `repair-backfill-timestamps --project --confirm` | ✅ yes | no | yes, if the operator kept the audit row or the CLI's before/after report (nothing else) | Corrects `sessions.started_at`/`ended_at` for sessions an older `backfill` imported before it carried the transcript's own event time. The CLI reads the operator's local transcripts read-only and posts candidate `(session_id, started_at, ended_at)` tuples to `POST /admin/repair-session-times`, which validates each one against `(workspace, project)` (a candidate outside that scope is `not_found` and untouched), only rewrites a row whose `started_at` postdates the candidate's own end (`not_flattened` otherwise, so a correctly hook-captured session or a re-run is a no-op), refuses negative/inverted/future-dated times, and never assigns an end time to a session still open. Without `--confirm` the server validates and reports inside a rolled-back transaction, so it is a real dry run; a confirmed run writes one `audit_log` row per request with the before/after times. Touches only the two timestamp columns of rows already in scope; `observations` and pages (including the session's own page frontmatter) are untouched. || `backup --to` | ✅ yes | no | n/a | Streams a gzipped tarball from the server's online `sqlite3 .backup` plus the wiki tree. Safe alongside the live writer. |