Skip to content

fix(chat): lock the composer input while a chat is still opening - #213

Open
MihaelaStoica wants to merge 3 commits into
mainfrom
fix/composer-empty-thread
Open

MihaelaStoica wants to merge 3 commits into
mainfrom
fix/composer-empty-thread

Conversation

@MihaelaStoica

@MihaelaStoica MihaelaStoica commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Typing in the composer while a chat was still opening threw assistant-ui's "This is the empty thread…" error, unhandled in the renderer, and the typed text was lost. Until an opened chat's thread runtime attaches, assistant-ui shows an empty placeholder thread whose composer throws on every edit; the Lexical input's sync listener pushes each keystroke into it. The window lasts seconds when the user opens a chat right after launch, while the Kilo server is still starting, and is one of the most frequent renderer errors we report.
(Ticket: DESK-3510)

Solution

The Lexical editor is read-only while the placeholder thread is shown, so no edit reaches its composer. The placeholder is the only thread without extras: Kilo's runtime gives every real thread, a draft included, its message queue controls.

So a slow open doesn't leave an input that silently ignores clicks, the placeholder text reads "Loading chat…" (and the input is aria-busy) once the placeholder has been shown for 400 ms. Most chats replace it within a frame, where an immediate swap would flash.

Risk & Tradeoffs

  • The detection relies on use-chat-runtime passing queue user controls; both ends carry a comment. If that were removed, draft composers would stay read-only, which the existing draft tests would catch.
  • The lock repeats LexicalComposerInput's own editable rule (thread disabled, dictation blocking input) so it has the last word; worth rechecking on @assistant-ui/react-lexical upgrades.
  • Not covered: code that writes to the composer directly (draft restore, the composer domain object's insertText) while the placeholder is shown. No reports point to it yet.

Testing

  • Browser tests holding a chat's details on the fake server: the input is not editable until the chat opens and then takes typing; "Loading chat…" shows on a slow open and never appears for a chat that opens at once. Before the fix, typing in that window reproduced the error.
  • Chat plugin composer, starter and agent-pane tests; pnpm lint; typecheck.

Change Classification

  • Routine — small, well-tested, low-risk (typo, config, dependency bump)
  • Standard — normal feature/bugfix work with tests
  • Architectural — introduces new patterns, changes system boundaries, or affects multiple packages
  • Sensitive — touches auth, permissions, data deletion, migrations, security boundaries

… is shown

Until an opened chat's thread runtime attaches, assistant-ui shows its empty
placeholder thread, whose composer throws on every edit. Typing then sent
each keystroke into it from SyncPlugin's Lexical listener, so the
empty-thread error reached the renderer unhandled and the text was lost.
The window lasts seconds when the Kilo server is still starting.

The Lexical editor is now read-only while the placeholder is shown. Only
the placeholder has no extras: every real thread, a draft included, carries
its message queue controls.
…o open

While the empty placeholder thread is shown the composer input is locked,
which on a slow open left it ignoring clicks with no explanation. Its
placeholder now reads "Loading chat…" (and the input is aria-busy) once
the placeholder thread has been shown for 400 ms. Most chats replace it
within a frame, where an immediate swap would only flash.
@MihaelaStoica
MihaelaStoica requested a review from a team as a code owner November 23, 2026 11:43
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

React Doctor found no issues. 🎉

Reviewed by React Doctor for commit ca6163c.

});

await expect.element(input()).toHaveAttribute("contenteditable", "true");
watcher.disconnect();

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.

[SUGGESTION]: The MutationObserver leaks when an assertion above fails

watcher.disconnect() runs only on the happy path: if renderChat() throws or toHaveAttribute("contenteditable", "true") times out (a slow CI run would do it), the observer stays attached to document.body for the rest of this test file, retaining its callback and inspecting every later mutation. Disconnect it in a try/finally so a failed assertion can't leave it observing.

@kilo-code-bot

kilo-code-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • plugins/chat/src/test/fake-kilo-server.ts - no issues (unchanged since the previous review)
  • plugins/chat/src/web/composer/composer.browser.test.tsx - no issues (previous MutationObserver suggestion resolved: onTestFinished(() => watcher.disconnect()) now disconnects the observer even when an assertion fails; matches existing repo usage and vitest 5.1.1)
  • plugins/chat/src/web/composer/kilo-lexical-composer-input.tsx - no issues (unchanged since the previous review)
  • plugins/chat/src/web/runtime/use-chat-runtime.ts - no issues (unchanged since the previous review)
Previous Review Summary (commit f7789ce)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit f7789ce)

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/chat/src/web/composer/composer.browser.test.tsx 808 MutationObserver is disconnected only on the happy path: a failed assertion leaves it observing document.body for the rest of the file.
Files Reviewed (4 files)
  • plugins/chat/src/test/fake-kilo-server.ts - 0 issues (chatReadGate sits with the other test gates and follows the existing delay pattern)
  • plugins/chat/src/web/composer/composer.browser.test.tsx - 1 issue
  • plugins/chat/src/web/composer/kilo-lexical-composer-input.tsx - 0 issues (placeholder-thread detection matches react-opencode's patched withMessageQueueExtras, so every real thread, drafts included, keeps extras; timer is cleaned up in the effect; render-phase state reset matches the existing working-indicator pattern)
  • plugins/chat/src/web/runtime/use-chat-runtime.ts - 0 issues (comment only)

Reviewed by deepseek-v4.1-flash-1017 · Input: 56.1K · Output: 5.8K · Cached: 262.7K

@MihaelaStoica
MihaelaStoica added this pull request to the merge queue Nov 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Nov 23, 2026

This branch has not been deployed

No deployments
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.

2 participants