Repository navigation
Description
Problem
Typing to an architect from a phone through the dashboard terminal produces duplicated fragments. It never happens on desktop, is intermittent, and is tied to the mobile keyboard's autocomplete: accepting a suggestion adds characters. Reported 2026-11-08 by the owner.
Verbatim samples received that day:
check again. i fwel really fatigued but at the same time cant rest check afain. gain. i fwel really fatigued but at the same time cant rest. .makes no sense. under normal ciecumakes nonsense. sense. under normal circumstances rcumstances thr thing i love most is thr fredom to chose what i dowhat have you done since we last spoke what have you done since we last spoke. .
Pattern: at the point where autocomplete replaced a word, the composer ends up with the partial word, the completed word, and a repeat of the preceding clause.
Root cause (as far as read)
apps/web/src/components/Terminal.tsx, the term.onData handler, carries the mobile dedup from #253 and #517. That guard only suppresses an exact duplicate onData payload within 150 ms while composing or on a coarse-pointer device.
An autocomplete acceptance is not an exact duplicate. The mobile IME performs a replace (delete the surrounding partial word, commit the full word), and xterm.js, which has no way to retract characters already sent to the PTY, surfaces the committed text as new onData. On some keyboards the textarea's whole current value is re-emitted on compositionend, which is the repeated clause. None of that matches data === lastSentData, so every byte reaches the PTY as fresh keystrokes.
#253 and #517 fixed the simple double-fire case. This is the replace case, which the same dedup cannot catch by design.
Fix (prescribed)
Handle composition as a replace, not as a stream of appends, in the same handler:
- Listen to
beforeinputonterm.textareaand, during composition on a touch device, trackinputTypevaluesinsertCompositionText,insertReplacementText,deleteContentBackwardandinsertFromCompositionwith theirdata/getTargetRanges(). - At
compositionend, compute the diff between what was already sent for this composition and the committed text. Send the minimal edit: N backspaces (\x7f) for the characters being replaced, then the new characters. Suppress the intermediateonDatapayloads xterm emits during the composition rather than forwarding them. - Guard against the whole-value re-emit: when a
compositionendpayload has the already-sent text as a prefix, send only the suffix. - Keep the existing exact-duplicate guard; it still covers the Mobile: duplicate letters and extra periods when typing #517 case.
Prefer a small pure function reconcileComposition(sent: string, committed: string): string that returns the byte sequence to send, unit-tested in isolation, with the DOM wiring thin around it.
Testing
- Unit tests for
reconcileCompositionwith the three samples above decomposed into sent/committed pairs, plus: plain append, replace of the last word, replace mid-sentence, whole-value re-emit, empty commit. - A Playwright test that drives the textarea with synthetic
compositionstart,beforeinput(insertReplacementText) andcompositionendevents on a coarse-pointer emulated device and asserts the bytes written to the PTY mock. - Manual: on a real phone (iOS Safari and Android Chrome), type a sentence accepting at least two autocomplete suggestions, and confirm the architect receives it exactly once with no fragments. The dashboard is a UI surface, so the browser check is required before the PR is called done.
Protocol: BUGFIX.
Activity
waleedkadous commentedon Nov 8, 2026
Addendum from the owner (2026-11-08): it also happens without pressing an autocomplete suggestion. Treat the suggestion tap as one trigger, not the cause. The broader suspect is the mobile IME's composition behaviour in general, including predictive text correcting a word in place after a space or punctuation. The prescribed fix above already targets composition replace events rather than the suggestion UI, so it still applies; the test matrix should include the no-tap case: type a misspelled word, then a space, and let the keyboard auto-correct it in place.
waleedkadous commentedon Nov 9, 2026
On it! Working on a fix now.
waleedkadous commentedon Nov 9, 2026
Root cause correction (from the bugfix-1883 investigation)
The root cause in the issue body is partly wrong. Reproduced against the real xterm.js 5.5.0 bundle in Chromium, with the keyboard edits driven through CDP's real IME pipeline (
Input.imeSetCompositionwith replacement ranges,Input.insertText, each preceded bykeydown229 the way Chrome on Android sends them).xterm.js keeps everything typed since the last Enter in its hidden textarea. The mobile keyboard edits that text in place, because it is the keyboard's autocomplete context. All three of xterm's textarea-derived emitters assume the textarea only ever grows by appends:
CompositionHelper._handleAnyTextareaChangesruns on keydown 229 outside a composition and sendsnewValue.replace(oldValue, ''). Once the IME has edited text it already committed,oldValueis no longer a substring ofnewValue, so the whole textarea is resent. An equal-length change also resends the whole value. This produces the repeated clause in samples 1 and 3. It is not thecompositionendpath the issue guessed.CompositionHelper._finalizeCompositionsendsvalue.substring(start), wherestartwas recorded at the end of the value oncompositionstart. When the IME recomposes a word that begins earlier, the result is a misaligned tail, e.g.ciecufollowed by a fragment ofcircumstances.Terminal._inputEventforwardsinsertTextdata as an append.spoke→spoke.since we last spoke.since we last spoke since we last spoke.ciecu→circumstancesunder normal circumstancesunder normal ciecumstancesunder normal circumstancesConsequence: a fix scoped to
compositionendwould leave the clause repeats in place. The fix (approved by the architect) treats every IME-driven textarea edit on a touch device as a replace. It sends the minimal edit (DELs for the diverging tail, then the new text), computed against a mirror of what the PTY already has, and keeps xterm's append-only IME paths out of it. The desktop path is unchanged.Upstream context: xterm.js PR #5704 — handle
insertReplacementTextfor Korean IME on WKWebView/Safari (open, changes requested) hits the same failure family on WKWebView. It buffersinsertReplacementTextthat_inputEventused to drop, and suppresses_handleAnyTextareaChangeson keyCode 229 during that replacement composition. It patches xterm internals and is not merged, so it does not fix this case for us.Fix #1883: send mobile keyboard replaces to the PTY as DELs plus new …
[Bugfix #1883] Fix: IME bridge follows xterm's blur clear, fails loud…
[Bugfix #1883] Hoist the IME bridge binding above the key handler tha…
[Bugfix #1883] Fix: rebase the IME mirror only for input sent to the …
[Bugfix #1883] Fix: account for swallowed sticky-modifier chars, drop…
[Bugfix #1883] Thread: CMAP round 4 and follow-up #1887
Merge pull request #1884 from cluesmith/builder/bugfix-1883
[Spec 1658] Merge main before A2-1 (#1883 mobile IME)
waleedkadous commentedon Nov 10, 2026
Real-device confirmation from the owner, 2026-11-10: typing to an architect from a phone through the cloud tunnel, on the build from main at 4291dab (PR #1884 plus PR #1888 installed). Message received intact, with ordinary typos but no duplicated fragments or repeated clauses. Device, browser and keyboard not yet recorded; iOS Safari versus Android Chrome coverage remains as noted in #1887.
waleedkadous commentedon Nov 10, 2026
Device for the confirmation above: Android Chrome. That path is now proven on a real device. iOS Safari remains emulated only (hand-built insertReplacementText events), tracked in #1887.