fix(desktop): skip a coalesced composer flush that lands mid-IME-composition #136470
All Vouch review confidence checks passed
Residual risk 0.32 = Change Risk (0.57) × (1 − Review Confidence (0.45)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 604 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.383
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #136470"
general
weight: 0.35
PRATHAMESH75
What does this PR do?
Fixes an intermittent CJK IME composition leak in the Desktop chat composer on Linux/Wayland (fcitx5 + pinyin), where a stray Latin letter from the middle of a pinyin syllable lands in the draft as literal text and the fcitx5 candidate window visibly restarts (#136460).
Root cause:
scheduleFlushEditorToDraftqueues the editor→draft flush on a rAF, and that flush starts withnormalizeComposerEditorDom— a DOM pass that removes zero-length text nodes, unwraps stray block wrappers (editor.replaceChildren) and drops phantom breaks. The queueing input usually fires outside any composition, but under a busy renderer (agent response streaming) the rAF can be postponed past the nextcompositionstart: the trailinginputof the previous composition is what queued it. When the delayed frame finally runs inside a live composition, the DOM mutations abort that composition — the IME restarts it (candidate window flash-and-vanish, the doubledcompositionstartsignature) and Chromium commits the aborted preedit into the draft as plain Latin text. This also explains why the leak strikes mid-syllable (2nd–3rd letter) and why it never reproduces in other Electron apps.Fix: the rAF callback now drops the run when
composingRefsays a composition is active. Dropping (not deferring) is lossless:compositionendre-reads the contentEditable and flushes the committed text synchronously, and a wedged-composition ref is already self-healed by the existing keydown/blur guards (#86760), after which the next plain input re-queues the flush.Related Issue
Fixes #136460
Type of Change
Changes Made
apps/desktop/src/app/chat/composer/index.tsx— guard the coalesced-flush rAF callback with the composition flag: a run landing inside a fresh IME composition is skipped instead of running the DOM-normalizing pass mid-preedit.apps/desktop/src/app/chat/composer/delayed-flush-ime-guard.test.tsx— regression tests (mirror-harness pattern, same asenter-stale-ime-flag.test.tsx) covering: the delayed-rAF-inside-composition drop + re-arm, the normal delayed-frame flush, and that mid-composition input never queues a flush.How to Test
1.
cd apps/desktop && ../../node_modules/.bin/vitest run --project ui src/app/chat/composer/delayed-flush-ime-guard.test.tsx— Observed result: 3 passed (the first test fails with the guard removed, i.e. it reproduces the unguarded double-flush).2.
cd apps/desktop && ../../node_modules/.bin/vitest run --project ui src/app/chat/composer/— Observed result: 84 files / 611 tests passed, no regressions in the composer suite.3. Manual (Linux/Wayland + fcitx5, per the issue): type continuous pinyin while an agent response streams — no stray Latin letters should appear mid-syllable and the candidate window should stay up for the whole syllable. (Hardware IME environment not available to me; the event ordering is covered by the regression tests instead.)
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests pass — N/A (desktop/UI-only change; the desktop vitest suite above covers it)python scripts/checkpasses (the blocking lint and code-health checks CI runs) — raneslint+prettier --checkon the changed files: cleanDocumentation & Housekeeping
docs/, docstrings) — N/Acli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AFor New Skills
N/A
Screenshots / Logs
N/A (event-ordering bug; see the regression test file for the reproduced sequence)