Repository navigation
Typing while a Bot's answer streams in keeps every key where it was typed - #3030
Open
ataibarkai wants to merge 3 commits into
Open
ataibarkai wants to merge 3 commits into
ataibarkai wants to merge 3 commits into
Conversation
…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
marked this pull request as ready for review
December 5, 2026 20:04
ataibarkai
requested review from
MikeRyanDev,
davidmckayv,
dustywusty,
mxmzb,
samjulien and
tylerslaton
as code owners
December 5, 2026 20:04
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsxdoes. 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
valuein an effect (useEffect). That effect also runs again whenever its triggers or itsonChangeare new objects. When it runs, it comparesvaluewith the last words the person typed, not with the previousvalue. The screens hand the composer its Bots as a new array on every render (toAgentOptions(...)inchannel-chat.tsxand 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
valuewhen the words really change. Callers keep passing what they pass today.commandsis left alone: both callers already keep it the same while a Bot's skills are unchanged, and a command carries arunfunction that a content key would freeze.Compared with #2910.
onChange. That covers a caller passing newcommandson every render too, which this branch doesn't. It changestriggers.tsx's builders to take a list or a function.valuefor prompt-area: the same race, for the first letter typed into Home's box. That is a narrow window: my test doesn't catch it on fix(composer): keep the caret after the first typed letter #2910 (10 runs).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
valueprop changed since the effect last ran, rather than whenevervaluediffers from the last words typed.How it was found
agentsarray: no redraws, words intact, in both engines. That pins the cause to the new triggers on each render, not to the stream itself.value. Also ruled out: the composer remounting mid-turn. Its key changes only when a kept first message is put back.Where it runs
Boundary and audit
API and database
api/, no app requests, no database and norelease-policy.json.Changelog
Web app and OpenBot Desktop.
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: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