From 96b0faf6169bc62609235c1dcff20c7622fc1fed Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 2 Jul 2026 15:32:39 -0400 Subject: [PATCH 1/2] fix(status): classify re-created cross-view files as Added, not invisible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The status tree scan skipped any file whose creating change is not visible on the current view. Correct when the file is absent from the working copy (another view's file must not show up here, e.g. as Deleted) — but when the working copy HAS the file (re-created on this view after a switch), skipping it opened a permanent gap: 'add' refuses it because the global TREE already tracks it, while status called it untracked-and-clean, so 'record' could never see it — every agent turn that re-created such a file became a false EmptyTurn, forever. Now a cross-view tree entry that exists on disk falls through with no visible graph content and classifies as Added, exactly what the scan's own comment prescribes for tree entries without a visible position. The extra disk stat runs only for cross-view entries, which are rare. Found doing real multi-session work in one repo (a file created by an earlier session on another view, re-created by a later session). Regression test drives two real orchestrator sessions end-to-end. --- atomic-agent/src/turn/orchestrator/tests.rs | 75 +++++++++++++++++++++ atomic-repository/src/repository/status.rs | 34 +++++++--- 2 files changed, 101 insertions(+), 8 deletions(-) diff --git a/atomic-agent/src/turn/orchestrator/tests.rs b/atomic-agent/src/turn/orchestrator/tests.rs index 45bcd299..f704c776 100644 --- a/atomic-agent/src/turn/orchestrator/tests.rs +++ b/atomic-agent/src/turn/orchestrator/tests.rs @@ -769,3 +769,78 @@ fn test_orchestrator_debug() { assert!(debug.contains("TurnOrchestrator")); assert!(debug.contains("repo_root")); } + +#[tokio::test] +async fn test_file_recorded_on_another_view_records_again_on_new_view() { + // Regression (found doing real work in a real repo): the tracking TREE + // is global, but status's tree scan SKIPPED files whose creating change + // is not visible on the current view. A file recorded by an earlier + // session on ANOTHER view, then re-created on disk under a new view, + // fell into a permanent gap: status called it untracked-and-clean while + // `add` refused it (TREE already tracks it) — so `record` could never + // see it again (false EmptyTurn forever). + let dir = TempDir::new().unwrap(); + Repository::init(dir.path()).unwrap(); + + // Session A records shared.rs on its own per-session view. + let store_a = SessionStore::for_repo(dir.path()).unwrap(); + let watcher_a = FallbackWatcher::new(WatcherConfig::new(dir.path())); + let mut orch_a = TurnOrchestrator::with_watcher(dir.path(), store_a, Box::new(watcher_a)); + orch_a.set_agent("claude-code", "Claude Code"); + orch_a + .dispatch(session_start_event("sess-A")) + .await + .unwrap(); + orch_a + .dispatch(turn_start_event("sess-A", "create shared")) + .await + .unwrap(); + fs::write(dir.path().join("shared.rs"), "fn shared() {}\n").unwrap(); + let ra = orch_a.dispatch(turn_end_event("sess-A")).await.unwrap(); + assert!(ra.was_recorded(), "session A must record shared.rs"); + orch_a.dispatch(session_end_event("sess-A")).await.unwrap(); + + // Session end re-materializes the parent view; shared.rs (recorded only + // on session A's view) leaves the working tree. Tolerate either. + let _ = fs::remove_file(dir.path().join("shared.rs")); + + // Session B on a NEW view: turn 1 records something else (the view now + // exists), turn 2 re-creates the SAME file session A recorded. + let store_b = SessionStore::for_repo(dir.path()).unwrap(); + let watcher_b = FallbackWatcher::new(WatcherConfig::new(dir.path())); + let mut orch_b = TurnOrchestrator::with_watcher(dir.path(), store_b, Box::new(watcher_b)); + orch_b.set_agent("claude-code", "Claude Code"); + orch_b + .dispatch(session_start_event("sess-B")) + .await + .unwrap(); + + orch_b + .dispatch(turn_start_event("sess-B", "unrelated work")) + .await + .unwrap(); + fs::write(dir.path().join("other.rs"), "fn other() {}\n").unwrap(); + let rb1 = orch_b.dispatch(turn_end_event("sess-B")).await.unwrap(); + assert!(rb1.was_recorded(), "session B turn 1 must record"); + + orch_b + .dispatch(turn_start_event("sess-B", "recreate shared")) + .await + .unwrap(); + fs::write(dir.path().join("shared.rs"), "fn shared_v2() {}\n").unwrap(); + let rb2 = orch_b.dispatch(turn_end_event("sess-B")).await.unwrap(); + assert!( + rb2.was_recorded(), + "re-creating a file another view already tracks must record — \ + regression: add=already-tracked + status=untracked ⇒ false EmptyTurn" + ); + let outcome = rb2.change_recorded.as_ref().unwrap(); + assert!( + outcome + .recorded_file_list() + .iter() + .any(|f| f.contains("shared.rs")), + "the re-created file itself must be in the recorded change: {:?}", + outcome.recorded_file_list() + ); +} diff --git a/atomic-repository/src/repository/status.rs b/atomic-repository/src/repository/status.rs index 22fb835c..44e421a7 100644 --- a/atomic-repository/src/repository/status.rs +++ b/atomic-repository/src/repository/status.rs @@ -88,19 +88,37 @@ impl Repository { for result in tree_iter { let (path, inode) = result.map_err(|e| RepositoryError::Database(e.to_string()))?; - // View filter: skip files whose creating change is not on - // the current view. Files in TREE without a graph position - // must be classified as Added, not Clean. Files whose - // creating change is not in the current view's filter are - // skipped entirely — they belong to other views and must not - // appear in this view's status. + // View filter: files whose creating change is not on the + // current view belong to other views. When such a file is + // absent from the working copy it is skipped entirely — it + // must not appear in this view's status (e.g. as Deleted). + // + // But when the working copy HAS the file (it was re-created + // on this view after a switch), it is new content FOR THIS + // VIEW and must classify as Added. Skipping it here opened a + // permanent gap: `add` refuses it (the TREE already tracks + // it) while status called it untracked-and-clean, so `record` + // could never see it again. Fall through with has_graph=false + // so the classifier reports Added. The extra disk stat only + // runs for cross-view files, which exist on disk only after a + // re-create — rare. let has_graph = if let Ok(Some(position)) = txn.inode_position(inode) { if let Some(ref ids) = current_view_change_ids { if !position.change.is_root() && !ids.contains(&position.change) { - continue; + let on_disk = self + .root + .join(normalize_tracked_path(&path, &self.root)) + .is_file(); + if !on_disk { + continue; + } + false + } else { + true } + } else { + true } - true } else { false }; From df8a810f32fb4812d63e43a5034ed8bcbee2a385 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 2 Jul 2026 23:39:52 -0400 Subject: [PATCH 2/2] docs: shorten cross-view status comments --- atomic-agent/src/turn/orchestrator/tests.rs | 13 ++----------- atomic-repository/src/repository/status.rs | 17 +++-------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/atomic-agent/src/turn/orchestrator/tests.rs b/atomic-agent/src/turn/orchestrator/tests.rs index f704c776..4f21d1ec 100644 --- a/atomic-agent/src/turn/orchestrator/tests.rs +++ b/atomic-agent/src/turn/orchestrator/tests.rs @@ -772,13 +772,6 @@ fn test_orchestrator_debug() { #[tokio::test] async fn test_file_recorded_on_another_view_records_again_on_new_view() { - // Regression (found doing real work in a real repo): the tracking TREE - // is global, but status's tree scan SKIPPED files whose creating change - // is not visible on the current view. A file recorded by an earlier - // session on ANOTHER view, then re-created on disk under a new view, - // fell into a permanent gap: status called it untracked-and-clean while - // `add` refused it (TREE already tracks it) — so `record` could never - // see it again (false EmptyTurn forever). let dir = TempDir::new().unwrap(); Repository::init(dir.path()).unwrap(); @@ -800,12 +793,10 @@ async fn test_file_recorded_on_another_view_records_again_on_new_view() { assert!(ra.was_recorded(), "session A must record shared.rs"); orch_a.dispatch(session_end_event("sess-A")).await.unwrap(); - // Session end re-materializes the parent view; shared.rs (recorded only - // on session A's view) leaves the working tree. Tolerate either. + // Session A's file should not be present on the parent view. let _ = fs::remove_file(dir.path().join("shared.rs")); - // Session B on a NEW view: turn 1 records something else (the view now - // exists), turn 2 re-creates the SAME file session A recorded. + // Session B re-creates the same path on a different view. let store_b = SessionStore::for_repo(dir.path()).unwrap(); let watcher_b = FallbackWatcher::new(WatcherConfig::new(dir.path())); let mut orch_b = TurnOrchestrator::with_watcher(dir.path(), store_b, Box::new(watcher_b)); diff --git a/atomic-repository/src/repository/status.rs b/atomic-repository/src/repository/status.rs index 44e421a7..70a29b6e 100644 --- a/atomic-repository/src/repository/status.rs +++ b/atomic-repository/src/repository/status.rs @@ -88,20 +88,9 @@ impl Repository { for result in tree_iter { let (path, inode) = result.map_err(|e| RepositoryError::Database(e.to_string()))?; - // View filter: files whose creating change is not on the - // current view belong to other views. When such a file is - // absent from the working copy it is skipped entirely — it - // must not appear in this view's status (e.g. as Deleted). - // - // But when the working copy HAS the file (it was re-created - // on this view after a switch), it is new content FOR THIS - // VIEW and must classify as Added. Skipping it here opened a - // permanent gap: `add` refuses it (the TREE already tracks - // it) while status called it untracked-and-clean, so `record` - // could never see it again. Fall through with has_graph=false - // so the classifier reports Added. The extra disk stat only - // runs for cross-view files, which exist on disk only after a - // re-create — rare. + // Cross-view entries are hidden from this view unless the file + // exists on disk again. In that case it is new content for the + // current view and should classify as Added. let has_graph = if let Ok(Some(position)) = txn.inode_position(inode) { if let Some(ref ids) = current_view_change_ids { if !position.change.is_root() && !ids.contains(&position.change) {