@@ -28,36 +28,60 @@ export const ModifiedFileMessage: React.FC<ModifiedFileMessageProps> = ({
28
28
const { state } = useExtensionStateContext ( ) ;
29
29
const hasActiveDecorators = ! ! ( state . activeDecorators && state . activeDecorators [ messageToken ] ) ;
30
30
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 ] ;
33
48
const globalStatus =
34
49
currentMessage ?. kind === ChatMessageType . ModifiedFile
35
50
? ( currentMessage . value as any ) ?. status
36
51
: null ;
37
52
53
+ // Initialize with status from data or global state for THIS specific message only
38
54
const [ actionTaken , setActionTaken ] = useState < "applied" | "rejected" | "processing" | null > (
39
55
( ) => {
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 ;
42
59
}
43
- if ( status === "rejected " || globalStatus === "rejected" ) {
44
- return "rejected" ;
60
+ if ( globalStatus === "applied " || globalStatus === "rejected" ) {
61
+ return globalStatus ;
45
62
}
46
- return null ; // for "pending" or undefined
63
+ return null ; // Default to null - no action taken
47
64
} ,
48
65
) ;
49
66
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
+ ) ;
54
74
55
- // Update local state when global state changes
75
+ // Update local state ONLY when global state changes for this specific message
56
76
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
+ ) ;
58
82
setActionTaken ( globalStatus ) ;
59
83
}
60
- } , [ globalStatus ] ) ;
84
+ } , [ globalStatus , currentMessage , messageToken , path ] ) ;
61
85
62
86
// Clear viewing diff state when status is finalized
63
87
useEffect ( ( ) => {
@@ -171,6 +195,7 @@ export const ModifiedFileMessage: React.FC<ModifiedFileMessageProps> = ({
171
195
} ;
172
196
173
197
// Render minimized version when any action is taken (including processing)
198
+ console . log ( "effectiveActionTakenn" , effectiveActionTaken ) ;
174
199
if ( effectiveActionTaken ) {
175
200
const canOpenInEditor = ! isNew && ! isDeleted ;
176
201
@@ -183,9 +208,11 @@ export const ModifiedFileMessage: React.FC<ModifiedFileMessageProps> = ({
183
208
< div className = "modified-file-minimized-content" >
184
209
< div className = "modified-file-minimized-status" >
185
210
< 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..." }
189
216
</ span >
190
217
< span className = "modified-file-minimized-filename" > { fileName } </ span >
191
218
</ div >
0 commit comments