Skip to content

Commit dc80952

Browse files
authored
fix: Plan is stale only if a turn-ending response came after it (#484)
1 parent 2074bbc commit dc80952

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

apps/array/src/renderer/features/sessions/components/SessionView.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,20 @@ export function SessionView({
104104
const latestPlan = useMemo((): Plan | null => {
105105
let planIndex = -1;
106106
let plan: Plan | null = null;
107-
let responseIndex = -1;
107+
let turnEndResponseIndex = -1;
108108

109-
// Find the most recent plan and response in one pass
109+
// Find the most recent plan and turn-ending response in one pass
110110
for (let i = events.length - 1; i >= 0; i--) {
111111
const msg = events[i].message;
112112

113-
if (responseIndex === -1 && isJsonRpcResponse(msg)) {
114-
responseIndex = i;
113+
// Only consider responses that end a turn (session/prompt responses have stopReason)
114+
// Other responses (like tool completions) should not invalidate the plan
115+
if (
116+
turnEndResponseIndex === -1 &&
117+
isJsonRpcResponse(msg) &&
118+
(msg.result as { stopReason?: string })?.stopReason !== undefined
119+
) {
120+
turnEndResponseIndex = i;
115121
}
116122

117123
if (
@@ -127,11 +133,11 @@ export function SessionView({
127133
}
128134
}
129135

130-
if (planIndex !== -1 && responseIndex !== -1) break;
136+
if (planIndex !== -1 && turnEndResponseIndex !== -1) break;
131137
}
132138

133-
// Plan is stale if the most recent response came after it (turn completed)
134-
if (responseIndex > planIndex) return null;
139+
// Plan is stale only if a turn-ending response came after it
140+
if (turnEndResponseIndex > planIndex) return null;
135141

136142
return plan;
137143
}, [events]);

0 commit comments

Comments
 (0)