From d684820e1967cb27bbd8614b5b9b353c6e1f45fd Mon Sep 17 00:00:00 2001 From: "posthog[bot]" <206114724+posthog[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:16:37 +0000 Subject: [PATCH] fix(daemon): skip a stash event with no target oid instead of failing the side effect A stash pop, apply, branch, or drop with no resolvable target oid returned a hard error from rewrite synthesis. That failed the whole side effect and logged an error-level event with the sid in the message. A failed pop on an empty stack always hit this. Now the daemon skips only that stash event. A failed command logs at debug level, because git changed nothing. A successful command logs a warning. Add an integration test that pops an empty stack in daemon mode. Generated-By: PostHog Desktop Task-Id: e014bc24-9ad8-451b-8113-247b76d4543b --- src/daemon.rs | 45 ++++++++++++++++++-------- tests/integration/stash_attribution.rs | 30 +++++++++++++++++ 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index 1ad5cbf..7f32444 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -8391,6 +8391,38 @@ impl ActorDaemonCoordinator { }; let stash_sha = Self::resolve_stash_sha_for_event(cmd, &operation, stash_ref.as_deref())?; + if stash_sha.is_none() + && matches!( + operation, + StashOperation::Apply + | StashOperation::Pop + | StashOperation::Branch + | StashOperation::Drop + ) + { + // A failed command with no target (a `pop` on an empty + // stack) changed nothing. A successful one with no + // target loses only this stash's attribution. + if cmd.exit_code != 0 { + tracing::debug!( + component = "daemon", + root_sid = %cmd.root_sid, + ?operation, + ?stash_ref, + exit_code = cmd.exit_code, + "skipping failed stash event without a target oid" + ); + } else { + tracing::warn!( + component = "daemon", + root_sid = %cmd.root_sid, + ?operation, + ?stash_ref, + "skipping stash event: target oid is unresolved" + ); + } + continue; + } let head_sha = match operation { StashOperation::Create => Self::resolve_stash_create_head_for_event( cmd, @@ -8412,19 +8444,6 @@ impl ActorDaemonCoordinator { } else { Vec::new() }; - if matches!( - operation, - StashOperation::Apply - | StashOperation::Pop - | StashOperation::Branch - | StashOperation::Drop - ) && stash_sha.is_none() - { - return Err(AutterError::Generic(format!( - "stash {:?} missing resolvable target oid sid={} ref={:?}", - operation, cmd.root_sid, stash_ref - ))); - } if matches!( operation, StashOperation::Create diff --git a/tests/integration/stash_attribution.rs b/tests/integration/stash_attribution.rs index 92a1565..768828b 100644 --- a/tests/integration/stash_attribution.rs +++ b/tests/integration/stash_attribution.rs @@ -349,6 +349,36 @@ fn test_stash_pop_empty_repo() { assert!(result.is_err(), "Should fail when no stash exists"); } +#[test] +fn test_stash_pop_empty_stack_does_not_fail_daemon_side_effects() { + let repo = TestRepo::new(); + + let mut readme = repo.filename("README.md"); + readme.set_contents(vec!["# Test Repo".to_string()]); + repo.stage_all_and_commit("initial commit") + .expect("commit should succeed"); + readme.assert_committed_lines(vec!["# Test Repo".human()]); + + // Pop with no stash ever created. + assert!(repo.git(&["stash", "pop"]).is_err()); + // Panics if the daemon recorded a side-effect error for the failed pop. + repo.sync_daemon(); + + let mut example = repo.filename("example.txt"); + example.set_contents(vec!["AI content".ai()]); + repo.git(&["stash"]).expect("stash should succeed"); + repo.git(&["stash", "pop"]) + .expect("stash pop should succeed"); + + // Pop again after the stack is empty. + assert!(repo.git(&["stash", "pop"]).is_err()); + repo.sync_daemon(); + + repo.stage_all_and_commit("apply stashed changes") + .expect("commit should succeed"); + example.assert_committed_lines(vec!["AI content".ai()]); +} + #[test] fn test_stash_mixed_human_and_ai() { let repo = TestRepo::new();