New chat leaves an empty session if the socket closes after allocation

Author: dongwook-chanCreated Sep 27, 2026Updated Sep 27, 2026

Summary

A new chat can leave a titled, empty session when its WebSocket closes after POST /api/providers/sessions succeeds but before the first chat.send frame is handed to an open socket.

This is the remaining new-chat race called out in #1407 (the fix for #1270). That PR keeps the prompt as a draft, but it navigates into the already-created empty session. If the user does not retry, the empty row remains.

Reproduction

  1. Open a project's New Session composer with a connected chat socket.
  2. Start a send and let the session creation POST return a session ID.
  3. Close the chat socket before sendMessage runs, so it returns false.
  4. Observe a session row with no received prompt or provider transcript.

The race can be reproduced deterministically by making sendMessage return false after the mocked creation POST in the composer test. On one self-hosted instance, two Codex session rows had titles but no provider transcript or messages; the row state is consistent with this race, although it does not prove their exact timing.

Expected behavior

If the first frame was not handed to the socket, keep the prompt in the New Session composer and remove the unused app session row. If cleanup fails, keep the draft associated with that row so retry does not create another one.

Scope

This concerns only sends for which the client knows sendMessage returned false. A socket reporting a successful send without server acknowledgment is a separate delivery problem.