Skip to content

web/chat: lazy "new chat" creation + per-chat draft persistence#136

Open
GrigoryPervakov wants to merge 1 commit into
mainfrom
pervakovg/lazy-chat-and-drafts
Open

web/chat: lazy "new chat" creation + per-chat draft persistence#136
GrigoryPervakov wants to merge 1 commit into
mainfrom
pervakovg/lazy-chat-and-drafts

Conversation

@GrigoryPervakov

@GrigoryPervakov GrigoryPervakov commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

Defer session creation to the first message, and remember unfinished input per chat.

  • Lazy "new chat": the + button no longer POSTs a session up front — it opens a local virtual chat (temp id, never sent to the backend) and only calls POST /api/sessions when you send the first message, then adopts the server id for the turn. The virtual chat pins to the top of the sidebar, auto-discards on switch-away when its draft is empty, and becomes a real, selectable session on first send (survives switching away mid-turn).
  • Per-chat drafts: unsent input is kept per session id, so switching chats clears the composer and returning restores the unfinished message — fixing the old single shared textarea that leaked text across all chats. A pencil glyph marks non-active chats that hold a draft.
  • Composer autofocus on every chat switch.
  • View-event scoping: view-mutating WS events (stream / panels / interaction / session_status) are dropped when their session_id ≠ the active session, so a reconnect that rebinds the socket to another session can't bleed a phantom "Thinking…" badge or a disabled composer into the chat you're viewing.

Frontend-only — no REST API or DB schema changes. Uses the existing POST /api/sessions; getDateGroup is also hardened to tolerate a missing date.

Test plan

  • + opens an empty "New chat" pinned at the top with no POST /api/sessions
  • First message creates the session and streams a reply; it stays in the list
  • Send in a new chat, then switch away mid-turn → the chat stays in the sidebar (no crash)
  • Type in chat A → switch to B (empty composer) → back to A restores the draft
  • Empty new chat auto-discards on switch-away; a drafted one persists (pencil shows)
  • Switching to any chat focuses the composer
  • Background session running + open New chat → no phantom "Thinking…" badge

@GrigoryPervakov GrigoryPervakov requested a review from pufit June 22, 2026 14:05
@GrigoryPervakov GrigoryPervakov force-pushed the pervakovg/lazy-chat-and-drafts branch from 964ed65 to e15cea9 Compare June 22, 2026 15:27
The + button no longer POSTs a session up front. It mints a local
"virtual" chat (temp UUID, never sent to the backend) and defers the
POST /api/sessions to the first message, then adopts the server-minted
id for the turn — so a session is created only when you actually send,
and it becomes a real, selectable chat that survives switching away.

Unsent input is stored per session id, so switching chats shows an empty
composer and returning restores the unfinished message (fixing the
single shared textarea that leaked text across sessions). A pencil glyph
marks non-active chats that hold a draft, the virtual chat pins to the
top of the sidebar, and switching to any chat focuses the composer.

Also scope view-mutating WS events (stream/panels/interaction) to the
active session, so a reconnect that rebinds the socket to another session
can't hijack the current view with a phantom "Thinking..." badge or a
disabled composer.

POST /api/sessions returns a partial row (no updated_at), so the promoted
session fills the fields the sidebar needs locally, and getDateGroup
tolerates a missing date instead of throwing.

Frontend-only; no API or schema changes.
@GrigoryPervakov GrigoryPervakov force-pushed the pervakovg/lazy-chat-and-drafts branch from e15cea9 to 347ad53 Compare June 22, 2026 15:40
@GrigoryPervakov GrigoryPervakov changed the title web/chat: lazy session creation + per-chat draft persistence web/chat: lazy "new chat" creation + per-chat draft persistence Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant