From a6e4aee8b4be9c380de1c56ef95b6d58587ae902 Mon Sep 17 00:00:00 2001 From: Bradley Axen Date: Tue, 17 Mar 2026 16:01:49 -0700 Subject: [PATCH] fix: capture pre_head_sha for pending commits on session resume When resuming a commit session where the original run didn't produce a commit (sha is None), the pre_head_sha was not being captured. This caused the post-completion hook to skip commit detection entirely, leaving the pending commit as 'failed' on the timeline even if the resumed session successfully created a commit. The fix removes the conditional that only captured pre_head_sha when commit.sha.is_some(). Now pre_head_sha is always captured when a commit record is linked to the session, enabling commit detection for both: - Pending commits (first run failed, resumed run succeeds) - Completed commits (detecting amended commits on resume) Notes do not have this issue since note extraction in run_post_completion_hooks is not gated on pre_head_sha. --- apps/staged/src-tauri/src/session_commands.rs | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/staged/src-tauri/src/session_commands.rs b/apps/staged/src-tauri/src/session_commands.rs index 064e3505..674fa3ee 100644 --- a/apps/staged/src-tauri/src/session_commands.rs +++ b/apps/staged/src-tauri/src/session_commands.rs @@ -213,24 +213,22 @@ pub fn resume_session( .map(|note| note.project_id); // If this session is linked to a commit, capture the current HEAD so we - // can detect amended commits when the session completes. + // can detect new or amended commits when the session completes. + // This applies both when the commit already has a SHA (amend case) and + // when it's still pending (no SHA — the previous run didn't produce a + // commit, so we need to detect if this resumed run does). let (pre_head_sha, workspace_name) = if let Ok(Some(commit)) = store.get_commit_by_session(&session_id) { - // Only bother if the commit already has a SHA (i.e. was previously completed). - if commit.sha.is_some() { - let branch = store.get_branch(&commit.branch_id).ok().flatten(); - let ws_name = branch.as_ref().and_then(|b| b.workspace_name.clone()); - let head = if let Some(ref ws) = ws_name { - crate::blox::ws_exec(ws, &["git", "rev-parse", "HEAD"]) - .map(|s| s.trim().to_string()) - .ok() - } else { - crate::git::get_head_sha(&working_dir).ok() - }; - (head, ws_name) + let branch = store.get_branch(&commit.branch_id).ok().flatten(); + let ws_name = branch.as_ref().and_then(|b| b.workspace_name.clone()); + let head = if let Some(ref ws) = ws_name { + crate::blox::ws_exec(ws, &["git", "rev-parse", "HEAD"]) + .map(|s| s.trim().to_string()) + .ok() } else { - (None, None) - } + crate::git::get_head_sha(&working_dir).ok() + }; + (head, ws_name) } else { (None, None) };