← Back to Pull requests

fix(desktop): skip a coalesced composer flush that lands mid-IME-composition #136470

Open
unknown opened this pull request with 604 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 11, 2026 06:22 UTC
Author

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: scheduleFlushEditorToDraft queues the editor→draft flush on a rAF, and that flush starts with normalizeComposerEditorDom — 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 next compositionstart: the trailing input of 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 doubled compositionstart signature) 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 composingRef says a composition is active. Dropping (not deferring) is lossless: compositionend re-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

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • 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 as enter-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

  • I've read the Contributing Guide

  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)

  • I searched for existing PRs to make sure this isn't a duplicate

  • My PR contains only changes related to this fix/feature (no unrelated commits)

  • I've run pytest tests/ -q and all tests pass — N/A (desktop/UI-only change; the desktop vitest suite above covers it)

  • python scripts/check passes (the blocking lint and code-health checks CI runs) — ran eslint + prettier --check on the changed files: clean

  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)

  • I've tested on my platform: macOS 26 (darwin 25.4, arm64) — the bug itself is Linux/Wayland-specific; covered by event-ordering regression tests
  • Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — N/A

  • I've updated cli-config.yaml.example if I added/changed config keys — N/A

  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — N/A

  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — N/A (guard only skips a redundant flush path; non-IME typists are unaffected because the flag is never set)

  • I've updated tool descriptions/schemas if I changed tool behavior — N/A
  • For New Skills

    N/A

    Screenshots / Logs

    N/A (event-ordering bug; see the regression test file for the reproduced sequence)

    Diff: 604 lines (+453 / -151) across 7 files Reviewer: PRATHAMESH75 Review duration: 77414m
    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
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57.1% (MEDIUM) · Higher = larger blast radius
    57.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.6% · Safe to merge
    31.6%