fix: filter pending comments by session to prevent cross-session leakage (#408)
This commit is contained in:
@@ -257,9 +257,10 @@ export function useCommentsState(resolvedSessionId: string | null): CommentsStat
|
||||
useEffect(() => {
|
||||
if (resolvedSessionId) hydrateComments(resolvedSessionId);
|
||||
}, [resolvedSessionId, hydrateComments]);
|
||||
const planComments = usePendingPlanComments();
|
||||
const pendingCommentsByFile = usePendingDiffCommentsByFile();
|
||||
const pendingPRFeedback = usePendingPRFeedback();
|
||||
// Filter pending comments by sessionId to prevent cross-session leakage
|
||||
const planComments = usePendingPlanComments(resolvedSessionId);
|
||||
const pendingCommentsByFile = usePendingDiffCommentsByFile(resolvedSessionId);
|
||||
const pendingPRFeedback = usePendingPRFeedback(resolvedSessionId);
|
||||
const markCommentsSent = useCommentsStore((state) => state.markCommentsSent);
|
||||
const removeComment = useCommentsStore((state) => state.removeComment);
|
||||
const clearSessionPlanComments = useCallback(() => {
|
||||
@@ -287,13 +288,17 @@ export function useCommentsState(resolvedSessionId: string | null): CommentsStat
|
||||
[removeComment],
|
||||
);
|
||||
const handleClearPRFeedback = useCallback(() => {
|
||||
if (!resolvedSessionId) return;
|
||||
const state = useCommentsStore.getState();
|
||||
const allPending = [...state.pendingForChat];
|
||||
for (const id of allPending) {
|
||||
const c = state.byId[id];
|
||||
if (c && isPRFeedbackComment(c)) state.removeComment(id);
|
||||
// Only clear PR feedback for the current session
|
||||
if (c && isPRFeedbackComment(c) && c.sessionId === resolvedSessionId) {
|
||||
state.removeComment(id);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
}, [resolvedSessionId]);
|
||||
return {
|
||||
planComments,
|
||||
pendingCommentsByFile,
|
||||
|
||||
@@ -34,8 +34,11 @@ const EMPTY_BY_FILE: Record<string, DiffComment[]> = {};
|
||||
|
||||
/**
|
||||
* Get all pending diff comments grouped by file path.
|
||||
* If sessionId is provided, only returns comments belonging to that session.
|
||||
*/
|
||||
export function usePendingDiffCommentsByFile(): Record<string, DiffComment[]> {
|
||||
export function usePendingDiffCommentsByFile(
|
||||
sessionId?: string | null,
|
||||
): Record<string, DiffComment[]> {
|
||||
const byId = useCommentsStore((state) => state.byId);
|
||||
const pendingForChat = useCommentsStore((state) => state.pendingForChat);
|
||||
|
||||
@@ -45,10 +48,12 @@ export function usePendingDiffCommentsByFile(): Record<string, DiffComment[]> {
|
||||
for (const id of pendingForChat) {
|
||||
const comment = byId[id];
|
||||
if (comment && isDiffComment(comment)) {
|
||||
// Filter by sessionId if provided
|
||||
if (sessionId && comment.sessionId !== sessionId) continue;
|
||||
if (!byFile[comment.filePath]) byFile[comment.filePath] = [];
|
||||
byFile[comment.filePath].push(comment);
|
||||
}
|
||||
}
|
||||
return Object.keys(byFile).length === 0 ? EMPTY_BY_FILE : byFile;
|
||||
}, [byId, pendingForChat]);
|
||||
}, [byId, pendingForChat, sessionId]);
|
||||
}
|
||||
|
||||
@@ -51,8 +51,9 @@ export function usePendingDiffComments(): DiffComment[] {
|
||||
|
||||
/**
|
||||
* Get all pending plan comments.
|
||||
* If sessionId is provided, only returns comments belonging to that session.
|
||||
*/
|
||||
export function usePendingPlanComments(): PlanComment[] {
|
||||
export function usePendingPlanComments(sessionId?: string | null): PlanComment[] {
|
||||
const byId = useCommentsStore((state) => state.byId);
|
||||
const pendingForChat = useCommentsStore((state) => state.pendingForChat);
|
||||
|
||||
@@ -61,16 +62,21 @@ export function usePendingPlanComments(): PlanComment[] {
|
||||
const pending: PlanComment[] = [];
|
||||
for (const id of pendingForChat) {
|
||||
const comment = byId[id];
|
||||
if (comment && isPlanComment(comment)) pending.push(comment);
|
||||
if (comment && isPlanComment(comment)) {
|
||||
// Filter by sessionId if provided
|
||||
if (sessionId && comment.sessionId !== sessionId) continue;
|
||||
pending.push(comment);
|
||||
}
|
||||
}
|
||||
return pending.length === 0 ? EMPTY_PLAN_COMMENTS : pending;
|
||||
}, [byId, pendingForChat]);
|
||||
}, [byId, pendingForChat, sessionId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all pending PR feedback comments.
|
||||
* If sessionId is provided, only returns comments belonging to that session.
|
||||
*/
|
||||
export function usePendingPRFeedback(): PRFeedbackComment[] {
|
||||
export function usePendingPRFeedback(sessionId?: string | null): PRFeedbackComment[] {
|
||||
const byId = useCommentsStore((state) => state.byId);
|
||||
const pendingForChat = useCommentsStore((state) => state.pendingForChat);
|
||||
|
||||
@@ -79,8 +85,12 @@ export function usePendingPRFeedback(): PRFeedbackComment[] {
|
||||
const pending: PRFeedbackComment[] = [];
|
||||
for (const id of pendingForChat) {
|
||||
const comment = byId[id];
|
||||
if (comment && isPRFeedbackComment(comment)) pending.push(comment);
|
||||
if (comment && isPRFeedbackComment(comment)) {
|
||||
// Filter by sessionId if provided
|
||||
if (sessionId && comment.sessionId !== sessionId) continue;
|
||||
pending.push(comment);
|
||||
}
|
||||
}
|
||||
return pending.length === 0 ? EMPTY_PR_FEEDBACK_COMMENTS : pending;
|
||||
}, [byId, pendingForChat]);
|
||||
}, [byId, pendingForChat, sessionId]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user