Skip to content

Typing while a Bot's answer streams in keeps every key where it was typed - #3030

Open
ataibarkai wants to merge 3 commits into
mainfrom
claude/composer-caret-jump-cfa4fe
Open

ataibarkai wants to merge 3 commits into
mainfrom
claude/composer-caret-jump-cfa4fe

Conversation

@ataibarkai

@ataibarkai ataibarkai commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Before and after

Typing at a quick typist's pace (a key every 60 ms) while a Bot's answer streams in, a word every 33 ms. Top: main. After the first letter the caret jumps to the start, so everything typed after it lands ahead of it, and the box ends up "ctually, … directA". Bottom: this branch. Every key lands where it was typed.

caret-before-after.mp4

Both are the real composer in a real Chromium, bundled from the browser test's fixture with the app's stylesheet, under a conversation that renders again for every streamed word, as channel-chat.tsx does. Where the caret slips depends on timing: at other paces it slips back one letter mid-word instead ("Actully … directa", "Actually,make … direct ").

The two recordings separately

main:

caret-before-main.mp4

This branch:

caret-after-branch.mp4

What this changes

#2910 (by ykakade) found the same race two days ago, from a CI flake. This one should land, and #2910 can close once it does. This one also covers Home's box locked to a Bot, which came after #2910, and it is checked in Chromium and WebKit. What #2910 has that this doesn't is cover for a caller that passes new skills on every render, and no caller does today. The differences are under "Compared with #2910" below.

Atai reported that the message box sometimes jumps to the beginning while he types, and what he types gets garbled, perhaps more while a Bot is writing. Sometimes it jumps twice, and the text comes out right.

Why it happened. prompt-area writes the box's words from value in an effect (useEffect). That effect also runs again whenever its triggers or its onChange are new objects. When it runs, it compares value with the last words the person typed, not with the previous value. The screens hand the composer its Bots as a new array on every render (toAgentOptions(...) in channel-chat.tsx and on Home). So every render gave prompt-area new triggers, and a conversation renders again for every word of a streamed answer.

A streamed word renders at the default priority, so React runs that render's effects in a later task. A key pressed after the render is drawn and before its effects run was not in that render's value. The effect then redrew the box with the words from before the key, and put the caret back at the same offset, clamped to those shorter words. The key's own render then drew the letter back and put the caret where the shorter words had ended: in front of the letter just typed. The next letters went in front of it ("teh"). In an empty box the caret went to the start, and the whole message landed ahead of its first letter. Typed into the middle of the words, the same pair of redraws puts the caret back where it was, so the words come out right, but the box is drawn twice for that key: the double jump. During a streamed answer the effect ran on every word, so a quick typist hit it within a sentence.

The fix. The composer keeps its Bots, and the Bot Home's box is locked to, as the same objects while they say the same thing (keyed on what the box shows of each Bot: id, name, description, avatar seed). The triggers built from them change only when a Bot does. So a streamed answer no longer re-runs prompt-area's effect, and the box is only drawn from value when the words really change. Callers keep passing what they pass today. commands is left alone: both callers already keep it the same while a Bot's skills are unchanged, and a command carries a run function that a content key would freeze.

Compared with #2910.

Upstream. prompt-area 0.7.2, the latest, has the same effect, so upgrading doesn't fix it. A fix there would redraw only when the value prop changed since the effect last ran, rather than whenever value differs from the last words typed.

How it was found
  • A probe in the running app recorded every time the box's DOM was rebuilt from scratch rather than typed into, every programmatic caret placement with its stack, and every remount. Typing during a live answer from OpenBot Cloud showed none of them, because that Bot wrote its answers as documents and streamed nothing into the transcript.
  • The real composer, under a parent that renders again every 16 ms the way a streamed answer does, garbled a typed sentence in Chromium and in WebKit on the first try. The probe showed the box redrawn under the keys with words a key behind ("Atuac" while typing "Actua…").
  • The same fixture with a stable agents array: no redraws, words intact, in both engines. That pins the cause to the new triggers on each render, not to the stream itself.
  • Ruled out: a late saved draft, dictation, or a kept first message writing older words. Only typing, dictation and a send write the box's value. Also ruled out: the composer remounting mid-turn. Its key changes only when a kept first message is put back.

Where it runs

  • New state that outlives a request? None. A change inside one composer in the browser.
  • What happens on the second replica? Nothing different: no server change.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • No acting call, refusal or failure is touched.
  • Nothing new is trusted from the client.

API and database

  • This changes nothing under api/, no app requests, no database and no release-policy.json.

Changelog

Web app and OpenBot Desktop.

  • Fixed: typing while a Bot answers. The caret could jump back while a reply streamed in, so letters landed out of order, or the whole message ended up ahead of its first letter. Every key now lands where it was typed.

Proof

New browser test app/tests/composer-typing-while-streaming.test.tsx, on CI's cross-browser list: the real composer under an answer that streams a word every 16 ms, typed into with the keyboard at a key every 30 ms. It checks that the words read as typed, the caret is where the last key left it, and the box was never redrawn under the keys. Four cases, each in Chromium and WebKit:

  • a conversation's box with the answer streaming throughout;
  • the answer starting and ending mid-sentence;
  • words typed into the middle of the box, the double jump;
  • Home's box locked to a Bot.

On main, the three cases typed at the end fail in both engines in every run, for example Received: "ctually, make the second section shorter and keep the tone warm but directA". The middle case fails in 5 of 6 runs: the words come out right, and the box was redrawn under the keys ("Actually, make the secondsection shorter", drawn without the space just typed). On this branch all 8 pass, in every run.

CI is green on 86b89c3ee: format, lint and types, the unit tests, and the real-browser lists in Chromium and WebKit, where the new test runs. Locally, typecheck, lint and the composer's unit tests pass, and the new test passes 8 of 8 in both engines. The full local browser lists, run eight at a time on a laptop also serving other branches, had timeouts in unrelated files (the terms, apps to reconnect after a move, the Recorder). Run on their own, those files pass.

🤖 Generated with Claude Code

ataibarkai and others added 3 commits December 5, 2026 10:15
…yped

The screens hand the message box its Bots as new objects on every render, and a conversation
renders again for every word of a streamed answer. Each new list was a new set of triggers for
prompt-area, and a new locked Bot a new value, and either makes prompt-area draw the box again from
`value` in an effect that runs after the render. A key pressed in between was not in that value: the
box was drawn without the letter just typed, then with it, and the caret was left where the shorter
words ended, so the next letters went in front of it, and in an empty box the caret went to the
start. The composer now keeps the Bots and the locked Bot the same objects while they say the same
thing, so a streaming answer never draws the box again under somebody typing.

A real-browser test types a sentence under an answer streaming a word every 16 ms, in a
conversation (throughout, and as the answer starts and ends) and in Home's box locked to a Bot, in
Chromium and WebKit. It fails on main in all six and passes here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… watching

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ver drawn twice

The second half of the report: a jump, twice, with the words right afterwards. In the middle of the
words, the redraw with the words from a key ago puts the caret back where it was, so nothing is
garbled, but the box is drawn twice for that key. On main the new case fails in 5 of 6 runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ataibarkai
ataibarkai marked this pull request as ready for review December 5, 2026 20:04

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.

1 participant