Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/components/chat/hooks/useChatRealtimeHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ export function useChatRealtimeHandlers({

// Clear pending session
const pendingSessionId = sessionStorage.getItem('pendingSessionId');
if (pendingSessionId && !currentSessionId && msg.exitCode === 0) {
const completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode === 0;

if (pendingSessionId && !currentSessionId && completedSuccessfully) {
Comment on lines +276 to +278
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Tighten success detection to avoid false-positive session finalization

On Line 276, typeof msg.exitCode !== 'number' marks all non-numeric values as success. That includes malformed payloads like "1" or null, which can wrongly clear pendingSessionId on Line 278.

Proposed fix
-const completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode === 0;
+const completedSuccessfully = msg.exitCode === undefined || msg.exitCode === 0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode === 0;
if (pendingSessionId && !currentSessionId && completedSuccessfully) {
const completedSuccessfully = msg.exitCode === undefined || msg.exitCode === 0;
if (pendingSessionId && !currentSessionId && completedSuccessfully) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/chat/hooks/useChatRealtimeHandlers.ts` around lines 276 - 278,
The current success detection treats any non-number exitCode as success
(completedSuccessfully = typeof msg.exitCode !== 'number' || msg.exitCode ===
0), which lets malformed values like "1" or null pass; change the logic so
success is only when exitCode is explicitly absent/undefined or the numeric
value 0—e.g. compute completedSuccessfully by checking (msg.exitCode ===
undefined || (typeof msg.exitCode === 'number' && msg.exitCode === 0)) so that
strings, null, or other malformed payloads do not clear pendingSessionId when
pendingSessionId and !currentSessionId are true.

const actualId = msg.actualSessionId || pendingSessionId;
setCurrentSessionId(actualId);
if (msg.actualSessionId) {
Expand Down