Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions apps/staged/src-tauri/src/session_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1466,15 +1466,10 @@ fn cancel_in_flight_auto_review_for_branch(
if !cancelled {
let current = store.get_session(session_id).map_err(|e| e.to_string())?;
return match current.map(|session| session.status) {
None => Ok(true),
Some(store::SessionStatus::Cancelled) => {
store.delete_review(&review.id).map_err(|e| e.to_string())?;
Ok(true)
}
None | Some(store::SessionStatus::Cancelled) => Ok(true),
_ => Ok(false),
};
}
store.delete_review(&review.id).map_err(|e| e.to_string())?;

Ok(true)
}
Expand Down Expand Up @@ -2680,8 +2675,10 @@ mod tests {
cancel_in_flight_auto_review_for_branch(&store, &registry, &branch.id).unwrap();

assert!(cancelled);
assert!(store.get_session(&session.id).unwrap().is_none());
assert!(store.get_review(&review.id).unwrap().is_none());
// Session transitions to Cancelled but both records survive for potential adoption
let session = store.get_session(&session.id).unwrap().unwrap();
assert_eq!(session.status, store::SessionStatus::Cancelled);
assert!(store.get_review(&review.id).unwrap().is_some());
}

#[test]
Expand All @@ -2695,8 +2692,10 @@ mod tests {
cancel_in_flight_auto_review_for_branch(&store, &registry, &branch.id).unwrap();

assert!(cancelled);
assert!(store.get_session(&session.id).unwrap().is_none());
assert!(store.get_review(&review.id).unwrap().is_none());
// Session transitions to Cancelled but both records survive for potential adoption
let session = store.get_session(&session.id).unwrap().unwrap();
assert_eq!(session.status, store::SessionStatus::Cancelled);
assert!(store.get_review(&review.id).unwrap().is_some());
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ export default class BranchCardSessionManager {
projectStateStore.addRunningSession(branch.projectId, this.autoReviewSessionId);
}

// If the autoreview was interrupted before completing, resume it
const needsResume = !review.completedAt && review.sessionId && !this.autoReviewSessionId;
if (needsResume) {
await commands.resumeSession(
review.sessionId!,
Comment on lines +197 to +200

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Guard autoreview resume against already-running sessions

This resume check relies on !this.autoReviewSessionId instead of the persisted session status, so after a branch card remount/reload (where autoReviewSessionId is empty until a new event arrives) an already-running auto review is treated as needing resume. The new block then calls resumeSession for that running session, but backend resume_session rejects it when transition_to_running returns false for running sessions; tryAdoptAutoReview falls into catch and returns false, so callers proceed to start a new review session and you can end up with duplicate concurrent reviews on the same branch.

Useful? React with 馃憤聽/ 馃憥.

'Continue reviewing the code changes on this branch.',
undefined,
branch.id
);
sessionRegistry.register(review.sessionId!, branch.projectId, 'review', branch.id);
projectStateStore.addRunningSession(branch.projectId, review.sessionId!);
}

this.autoReviewSessionId = null;
this.autoReviewId = null;

Expand Down
2 changes: 2 additions & 0 deletions packages/diff-viewer/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export interface Review {
referenceFiles: string[];
createdAt: number;
updatedAt: number;
/** When the AI session finished producing this review. `null` while running. */
completedAt: number | null;
}

// =============================================================================
Expand Down