Skip to content

Commit 8352944

Browse files
committed
Handle message collision fix
1 parent 6e35a85 commit 8352944

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

webview-ui/src/components/ResolutionsPage/ModifiedFile/ModifiedFileMessage.tsx

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,60 @@ export const ModifiedFileMessage: React.FC<ModifiedFileMessageProps> = ({
2828
const { state } = useExtensionStateContext();
2929
const hasActiveDecorators = !!(state.activeDecorators && state.activeDecorators[messageToken]);
3030

31-
// Get status from global state as fallback
32-
const currentMessage = state.chatMessages.find((msg) => msg.messageToken === messageToken);
31+
// Get status from global state ONLY for this specific message token
32+
// CRITICAL: MessageTokens are not unique (path-toolCall format causes collisions)
33+
// We need to find the EXACT message by comparing content AND diff to ensure uniqueness
34+
const messagesForToken = state.chatMessages.filter(
35+
(msg) =>
36+
msg.messageToken === messageToken &&
37+
msg.kind === ChatMessageType.ModifiedFile &&
38+
(msg.value as any)?.path === path,
39+
);
40+
41+
// If multiple messages with same token, find exact match by content AND diff
42+
const currentMessage =
43+
messagesForToken.length > 1
44+
? messagesForToken.find(
45+
(msg) => (msg.value as any)?.content === content && (msg.value as any)?.diff === diff,
46+
)
47+
: messagesForToken[0];
3348
const globalStatus =
3449
currentMessage?.kind === ChatMessageType.ModifiedFile
3550
? (currentMessage.value as any)?.status
3651
: null;
3752

53+
// Initialize with status from data or global state for THIS specific message only
3854
const [actionTaken, setActionTaken] = useState<"applied" | "rejected" | "processing" | null>(
3955
() => {
40-
if (status === "applied" || globalStatus === "applied") {
41-
return "applied";
56+
// Only use status if it's explicitly set for this message
57+
if (status === "applied" || status === "rejected") {
58+
return status;
4259
}
43-
if (status === "rejected" || globalStatus === "rejected") {
44-
return "rejected";
60+
if (globalStatus === "applied" || globalStatus === "rejected") {
61+
return globalStatus;
4562
}
46-
return null; // for "pending" or undefined
63+
return null; // Default to null - no action taken
4764
},
4865
);
4966

50-
// Use global state as fallback when local state is null
51-
const effectiveActionTaken =
52-
actionTaken ||
53-
(globalStatus === "applied" ? "applied" : globalStatus === "rejected" ? "rejected" : null);
67+
// HARD requirement: only use status if it's explicitly set for this message token
68+
// Do NOT use any fallback logic that could cause premature minimization
69+
const effectiveActionTaken = actionTaken;
70+
71+
console.log(
72+
`[ModifiedFileMessage] Status check - messageToken: ${messageToken}, path: ${path}, data.status: ${status}, globalStatus: ${globalStatus}, actionTaken: ${actionTaken}, effectiveActionTaken: ${effectiveActionTaken}, foundMessage: ${!!currentMessage}, totalMessagesForToken: ${messagesForToken.length}`,
73+
);
5474

55-
// Update local state when global state changes
75+
// Update local state ONLY when global state changes for this specific message
5676
useEffect(() => {
57-
if (globalStatus === "applied" || globalStatus === "rejected") {
77+
// Only update if we found the exact message and it has a status
78+
if (currentMessage && (globalStatus === "applied" || globalStatus === "rejected")) {
79+
console.log(
80+
`[ModifiedFileMessage] Updating actionTaken to ${globalStatus} for messageToken: ${messageToken}, path: ${path}`,
81+
);
5882
setActionTaken(globalStatus);
5983
}
60-
}, [globalStatus]);
84+
}, [globalStatus, currentMessage, messageToken, path]);
6185

6286
// Clear viewing diff state when status is finalized
6387
useEffect(() => {
@@ -171,6 +195,7 @@ export const ModifiedFileMessage: React.FC<ModifiedFileMessageProps> = ({
171195
};
172196

173197
// Render minimized version when any action is taken (including processing)
198+
console.log("effectiveActionTakenn", effectiveActionTaken);
174199
if (effectiveActionTaken) {
175200
const canOpenInEditor = !isNew && !isDeleted;
176201

@@ -183,9 +208,11 @@ export const ModifiedFileMessage: React.FC<ModifiedFileMessageProps> = ({
183208
<div className="modified-file-minimized-content">
184209
<div className="modified-file-minimized-status">
185210
<span className={`status-badge status-${effectiveActionTaken}`}>
186-
{effectiveActionTaken === "applied" ? "✓ Applied"
187-
: effectiveActionTaken === "rejected" ? "✗ Rejected"
188-
: "⏳ Processing..."}
211+
{effectiveActionTaken === "applied"
212+
? "✓ Applied"
213+
: effectiveActionTaken === "rejected"
214+
? "✗ Rejected"
215+
: "⏳ Processing..."}
189216
</span>
190217
<span className="modified-file-minimized-filename">{fileName}</span>
191218
</div>

0 commit comments

Comments
 (0)