Skip to content

fix(terminal): stop a Hangul-terminating digit being eaten as a candidate pick - #15429

Merged
nwparker merged 2 commits into
mainfrom
nwparker/hangul-terminating-digit
Aug 19, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/hangul-terminating-digit

Conversation

@nwparker

@nwparker nwparker commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​203 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​203
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​42

Closes #15299 — a digit typed immediately after a Hangul syllable is dropped in the terminal on Wayland. Typing 아1 produces 아. The syllable composes and commits correctly; only the keystroke that ends it is lost.

Reproduced and fixed under measurement, on Ubuntu 24.04 / GNOME Shell 46 / ibus-hangul 1.5.5, in a nested Wayland session with real key injection through the compositor.

configuration bytes at the pty
Wayland 아\n ×3
Wayland + --enable-wayland-ime --wayland-text-input-version=3 아\n ×3
X11 control, same machine and engine 아1\n ×3
GTK control (gnome-text-editor, same Wayland session) 아1 ×3

The compositor, the input method and the digit are all fine. Orca's terminal is the only thing that loses it.

Why Wayland and not X11

The two paths deliver the digit differently, and the traces show it plainly.

X11 — ibus-hangul swallows the digit into the preedit and commits 아1 as composition text:

keydown key="Process" code=Digit1 keyCode=229    <- consumed by the IME
compositionupdate data="아1"                      <- digit lives inside the preedit
compositionend    data="아1"
onData: "아1"

Wayland — it commits 아 and lets the digit through as an ordinary key. And the jamo before it arrive with no keydown at all, only keyups:

compositionupdate data="ㅇ" / beforeinput / input
keyup  key="d"  code=KeyD  keyCode=68  isComposing=true    <- NO matching keydown
compositionupdate data="아" / beforeinput / input
keyup  key="k"  code=KeyK  keyCode=75  isComposing=true    <- NO matching keydown
compositionend  data="아"
keydown key="1" code=Digit1 keyCode=49 isComposing=false   <- real key event
onData: "아"                                               <- digit gone

Root cause

That orphaned keyup is what breaks it. terminal-ime-linux-candidate-state.ts:175 sees a plain-letter keyup with no pending keydown for that code and arms a 1500 ms window in which a bare digit is treated as a candidate selection — because a Pinyin engine indexes its candidate list by digit (#7543, #8241).

The digit lands microseconds later, inside that window, and is suppressed. The window disarms after exactly one digit, which is why the syllable survives and only the terminating key vanishes.

A Hangul engine has no numbered candidates over its preedit. The guard was spending its one suppression on a keystroke meant for the shell.

The fix

The composition tracker records whether the current preedit is Hangul; the guard declines to claim a digit that preedit has already made literal.

Read from compositionupdate, never compositionend — a Pinyin preedit is the Latin spelling being narrowed while its commit is the Han text, so reading the commit would misclassify Pinyin and reopen the bugs the guard exists for. A test pins that. Space is untouched; only digits are reclassified.

Two things the earlier draft of this PR got wrong

Both were corrected by the reproduction rather than by argument:

  • Only one guard is involved, not two. The 250 ms post-composition guard never arms here — it requires an empty compositionupdate, and every update in this trace carries data (ㅇ, 아, 아). The orphan-keyup guard is solely responsible.
  • The "competing cause" is disproven. The digit arrives as a real keydown with keyCode 49 and isComposing=false, so xterm's _keyDownSeen check is never reached — Orca's policy suppresses the key before xterm's handler runs. That path is not what the reporter hits.

Verification

A/B/A on the reproducing machine: unfixed drops the digit, this change preserves it, reverting drops it again — three runs each, deterministic.

The oracle is the literal byte stream: a node process on the pty echoes each line as hex, ec9584 0a broken versus ec9584 31 0a fixed. terminal.onData agrees independently. orca terminal read was deliberately not used — it accumulates the stream and stacks output, and would have shown a false result.

No regression: the X11 case still passes with the fix, and both existing terminal-ibus-hangul-native.spec.ts cases pass at 5 repetitions.

targeted              5 files /   71 tests passed
full terminal-pane  378 files / 3675 tests passed

config/patches/ untouched — no xterm change was needed.

Also cleared

PR #14469 is not the cause, contrary to the initial hypothesis. resolveNonLatinControlChordInput returns null unless ctrlKey is set, only claims Key[A-Z] codes, and requires a codepoint above 0x7f — a bare 1 fails all three gates.

Follow-up worth having

The reproduction harness exists and is reusable, but lives on a scratch machine rather than in the repo. It is the first setup we have that can drive a real IME through a real compositor, and three IME issues this week were unreproducible without one. Details are in the issue thread; the spec is injector-agnostic and parameterised by keys and expected text, so other IME bugs can reuse it unchanged.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change tracks whether the active IME preedit contains Hangul characters. Terminal keyboard handling passes this state to the bypass policy. Candidate-digit suppression and native default prevention use a shared Hangul-aware predicate. Tests cover Hangul terminating digits, Linux orphan-keyup handling, stale preedit state, composition resets, and Pinyin candidate selection.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement issue #15299 by preserving the terminating Hangul digit while retaining Pinyin candidate handling and existing composition behavior.
Out of Scope Changes check ✅ Passed The production changes and tests are focused on the linked Hangul terminal-input issue, with no unrelated code or configuration changes.
Title check ✅ Passed The title clearly identifies the primary fix: preserving a digit that follows a Hangul composition in the terminal.
Description check ✅ Passed The description provides detailed context, root cause, fix rationale, linked issue, reproduction evidence, and test results, but omits several template headings and checklist items.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…date pick

A digit typed immediately after a Hangul syllable is dropped in the
terminal on Wayland. Typing 아1 produces 아. The syllable composes and
commits correctly; only the keystroke that ends it is lost.

Reproduced on Ubuntu 24.04, GNOME Shell 46, ibus-hangul 1.5.5, in a
nested Wayland session with real key injection. The pty receives 아 on
Wayland and 아1 under X11 on the same machine with the same engine, and
a GTK client in the same Wayland session receives 아1 - so the
compositor, the input method and the digit are all behaving.

The difference is where the digit is delivered. Under X11 ibus-hangul
swallows it into the preedit and commits 아1 as composition text. Under
Wayland it commits 아 and lets the digit through as an ordinary key -
and the jamo before it arrive with no keydown at all, only keyups.

That orphaned keyup is what breaks it. A plain letter keyup with no
matching keydown arms a 1500ms window in which a bare digit is treated
as a candidate selection, because a Pinyin engine indexes its candidate
list by digit. The digit lands microseconds later, inside the window,
and is suppressed. The window disarms after exactly one digit, which is
why the syllable survives and only the terminating key vanishes.

A Hangul engine has no numbered candidates over its preedit - a digit
ends the syllable and is literal text - so the guard was spending its
one suppression on a keystroke meant for the shell. The tracker now
records whether the current preedit is Hangul and the guard declines.

Read from compositionupdate rather than compositionend: a Pinyin preedit
is the Latin spelling being narrowed while its commit is the Han text,
so reading the commit would misclassify Pinyin and reopen the bugs the
guard was added for. Space is untouched; only digits are reclassified.

Verified A/B/A on that machine: unfixed drops the digit, this change
preserves it, reverting drops it again, three runs each. The X11 case
and both existing ibus-hangul specs still pass.

Closes #15299
…emption

Review of the #15299 fix found the Hangul classification could not be
retired and that it exempted more than the reported bug.

The flag was written only on a non-empty compositionupdate and cleared
only on blur, so it latched for the whole focus session. Switching input
engine (Hangul -> Pinyin) under fcitx/ibus moves no DOM focus, and the
#8241 orphan-digit path emits no composition and no input events, so
nothing could refresh or clear it. The stale flag then turned the
#8241/#7543 Pinyin candidate-digit guard off silently and permanently -
the regression those guards exist to prevent. It now expires against
lastCompositionEventAt on the same staleness window as the neighbouring
guards, and compositionstart clears it because the following
compositionupdate re-reads the preedit script.

It is deliberately not cleared on compositionend or on input: the bug is
a digit arriving after the commit, and both recordings deliver the
commit's own insertText before it. Clearing on either reverts the fix -
the orphan-window test fails when input clears it.

The exemption also gated suppressCandidateKey as a whole, so it fired
during a live composition as well. That is broader than the bug, which
is exclusively a digit after compositionend, and it is unsafe: the
earlier claim that no Hangul engine indexes candidates by digit over a
preedit is wrong. ibus-hangul's Hanja conversion (Hanja key / F9) puts a
numbered lookup table over a live Hangul preedit, and its symbol table
behaves the same. Only the orphan-keyup guard - which arms off a bare
keyup and cannot see which engine produced it - now declines.

The tests drove a shape neither recording produces: an empty
compositionupdate immediately before compositionend, which armed the
250ms post-composition window. The Wayland reproduction has no empty
update, and the X11 fixture follows its empty update with
deleteContentBackward + insertText, which disarms that window. The suite
now follows the recorded trace, asserts the 250ms window never arms, and
covers both the expiry and the live-preedit Hanja case.

Refs #15299

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3906366a-68c4-41a1-9354-997099478890

📥 Commits

Reviewing files that changed from the base of the PR and between cf47b68b8f424335ed0fa99631d2b943da28c8e3 and 4ca2526.

📒 Files selected for processing (3)
  • src/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.ts
  • src/renderer/src/components/terminal-pane/terminal-ime-hangul-terminating-digit.test.ts
  • src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment on lines +15 to +17
// Jamo, compatibility jamo, extended jamo, and precomposed syllables — every
// form a Hangul preedit can take while a syllable is being assembled.
const HANGUL_PREEDIT_PATTERN = /[ᄀ-ᇿ㄰-㆏ꥠ-꥿가-힣]/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- candidate files ---'
fd -i 'terminal-ime-composition-tracker|terminal-ime.*test|composition.*test' . || true

printf '%s\n' '--- tracker outline ---'
tracker=$(fd -i -t f 'terminal-ime-composition-tracker' . | head -n 1)
if [ -n "${tracker:-}" ]; then
  ast-grep outline "$tracker" || true
  printf '%s\n' '--- tracker source ---'
  cat -n "$tracker"
fi

printf '%s\n' '--- tracker references and Hangul classification ---'
rg -n -C 4 'HANGUL_PREEDIT_PATTERN|isHangulPreedit|orphan|terminating digit|composition tracker|preedit' . \
  -g '*.{ts,tsx,js,jsx}' || true

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- terminal IME files ---'
fd -i -t f 'terminal-ime' src/renderer/src/components/terminal-pane | sort

printf '%s\n' '--- exact tracker path ---'
tracker='src/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.ts'
test -f "$tracker" && cat -n "$tracker"

printf '%s\n' '--- focused references ---'
rg -n -C 5 'HANGUL_PREEDIT_PATTERN|isHangulPreedit|orphan|pending.*digit|digit' \
  src/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.ts \
  src/renderer/src/components/terminal-pane \
  -g 'terminal-ime*.ts' -g 'terminal-ime*.tsx' -g 'terminal-ime*.test.ts' \
  --glob '!**/node_modules/**' | head -n 500

Repository: stablyai/orca

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- tracker API consumers ---'
rg -n -C 8 'isHangulPreedit\(\)|isHangulPreedit' src/renderer/src --glob '*.{ts,tsx}' \
  | head -n 300

printf '%s\n' '--- tracker tests ---'
cat -n src/renderer/src/components/terminal-pane/terminal-ime-composition-tracker.test.ts

printf '%s\n' '--- Hangul terminating-digit test ---'
cat -n src/renderer/src/components/terminal-pane/terminal-ime-hangul-terminating-digit.test.ts

printf '%s\n' '--- Hangul code point names and ranges ---'
python3 - <<'PY'
import unicodedata
ranges = [
    ('U+1100..U+11FF', 0x1100, 0x11ff),
    ('U+3130..U+318F', 0x3130, 0x318f),
    ('U+A960..U+A97F', 0xa960, 0xa97f),
    ('U+AC00..U+D7A3', 0xac00, 0xd7a3),
    ('U+D7B0..U+D7FF', 0xd7b0, 0xd7ff),
    ('U+FFA0..U+FFDC', 0xffa0, 0xffdc),
]
for label, start, end in ranges:
    assigned = [(cp, unicodedata.name(chr(cp), '<unassigned>')) for cp in range(start, end + 1)
                if unicodedata.name(chr(cp), None)]
    print(label, 'assigned=', len(assigned), 'first=', assigned[:2], 'last=', assigned[-2:])
PY

Repository: stablyai/orca

Length of output: 41148


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- keyboard suppression policy ---'
rg -n -C 12 'function shouldSuppressTerminalImeKeyboardEvent|shouldSuppressTerminalImeKeyboardEvent|hangulPreedit|linuxOrphanCandidateDigitGuardActive' \
  src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts \
  src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts

printf '%s\n' '--- policy structure ---'
ast-grep outline src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts || true
cat -n src/renderer/src/components/terminal-pane/xterm-bypass-policy.ts | sed -n '1,240p'

printf '%s\n' '--- Unicode block metadata from local Unicode database ---'
python3 - <<'PY'
import unicodedata
for cp in (0xD7B0, 0xD7FF, 0xFFA0, 0xFFDC):
    ch = chr(cp)
    print(f'U+{cp:04X}', unicodedata.name(ch), 'category=', unicodedata.category(ch))
PY

printf '%s\n' '--- repository fixture/test references to omitted ranges ---'
rg -n -S 'D7B0|D7FF|FFA0|FFDC|ᇰ|ힰ|ᅠ|ᅵ|Halfwidth Hangul|Jamo Extended-B' \
  src/renderer __fixtures__ tests 2>/dev/null | head -n 200 || true

Repository: stablyai/orca

Length of output: 26206


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- exact code-point behavior of the current and proposed patterns ---'
node - <<'JS'
const current = /[ᄀ-ᇿ㄰-㆏ꥠ-꥿가-힣]/
const proposed = /[\u1100-\u11ff\u3130-\u318f\ua960-\ua97f\uac00-\ud7a3\ud7b0-\ud7ff\uffa0-\uffdc]/
for (const cp of [0x1100, 0x3130, 0xa960, 0xac00, 0xd7b0, 0xd7ff, 0xffa0, 0xffdc]) {
  const char = String.fromCodePoint(cp)
  console.log(
    `U+${cp.toString(16).toUpperCase().padStart(4, '0')}`,
    JSON.stringify(char),
    `current=${current.test(char)}`,
    `proposed=${proposed.test(char)}`
  )
}
JS

printf '%s\n' '--- assigned code points in the omitted blocks ---'
python3 - <<'PY'
import unicodedata
for label, start, end in [
    ('Hangul Jamo Extended-B block', 0xD7B0, 0xD7FF),
    ('Halfwidth Hangul Jamo block range', 0xFFA0, 0xFFDC),
]:
    assigned = [cp for cp in range(start, end + 1) if unicodedata.name(chr(cp), None)]
    print(label, f'U+{start:04X}-U+{end:04X}', 'assigned_count=', len(assigned))
    if assigned:
        print(' assigned_span=', f'U+{min(assigned):04X}-U+{max(assigned):04X}')
PY

Repository: stablyai/orca

Length of output: 770


🌐 Web query:

Unicode 17.0 Core Specification Chapter 18 Hangul Jamo Extended-B U+D7B0 U+D7FF Halfwidth Hangul Jamo U+FFA0 U+FFDC

💡 Result:

In the Unicode 17.0 standard, the specified ranges are categorized as follows: Hangul Jamo Extended-B (U+D7B0–U+D7FF) This block is part of the Basic Multilingual Plane (BMP) and contains 72 assigned code points used for archaic Hangul jamo (specifically positional jungseong and jongseong) [1][2][3]. These characters are designed for use with composed Hangul syllables, particularly those not required for standard modern Korean [2]. Halfwidth Hangul Jamo (U+FFA0–U+FFDC) These characters are located within the Halfwidth and Fullwidth Forms block (U+FF00–U+FFEF) [4]. This range encodes halfwidth variants of compatibility jamo characters [5][4]. They were included in Unicode primarily to ensure lossless translation (round-trip compatibility) with legacy character encodings, such as IBM code page 933, which utilized Shift Out/Shift In mechanisms to toggle between single-byte and double-byte character sets [4]. Unicode Specification Context Chapter 18 of the Unicode Standard (East Asia) provides broader context regarding the Hangul script [6][7]. It notes that Hangul jamos are grouped into syllabic blocks that, while visually resembling Chinese ideographs, are not directly influenced by them [6]. The standard specifies that conjoining jamo behavior (governed by the rules in Section 3.12) is the primary method for representing Korean, while compatibility jamos (including the halfwidth forms) and precomposed syllables are also supported for specific legacy and compatibility requirements [6].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- exact code-point behavior of the current and proposed patterns ---'
node - <<'JS'
const current = /[ᄀ-ᇿ㄰-㆏ꥠ-꥿가-힣]/
const proposed = /[\u1100-\u11ff\u3130-\u318f\ua960-\ua97f\uaC00-\ud7a3\ud7b0-\ud7ff\uffa0-\uffdc]/
for (const cp of [0x1100, 0x3130, 0xa960, 0xac00, 0xd7b0, 0xd7ff, 0xffa0, 0xffdc]) {
  const char = String.fromCodePoint(cp)
  console.log(
    `U+${cp.toString(16).toUpperCase().padStart(4, '0')}`,
    JSON.stringify(char),
    `current=${current.test(char)}`,
    `proposed=${proposed.test(char)}`
  )
}
JS

printf '%s\n' '--- assigned code points in the omitted blocks ---'
python3 - <<'PY'
import unicodedata
for label, start, end in [
    ('Hangul Jamo Extended-B block', 0xD7B0, 0xD7FF),
    ('Halfwidth Hangul Jamo block range', 0xFFA0, 0xFFDC),
]:
    assigned = [cp for cp in range(start, end + 1) if unicodedata.name(chr(cp), None)]
    print(label, f'U+{start:04X}-U+{end:04X}', 'assigned_count=', len(assigned))
    if assigned:
        print(' assigned_span=', f'U+{min(assigned):04X}-U+{max(assigned):04X}')
PY

Repository: stablyai/orca

Length of output: 770


Extend Hangul preedit detection to the omitted ranges.

HANGUL_PREEDIT_PATTERN misses Hangul Jamo Extended-B (U+D7B0–U+D7FF) and Halfwidth Hangul Jamo (U+FFA0–U+FFDC). For either range, isHangulPreedit() returns false, so the Linux orphan-digit guard can suppress a terminating digit. Add both ranges and regression cases.

@nwparker

Copy link
Copy Markdown
Contributor Author

Readiness review found a P0 in the first version of this fix, now corrected here.

P0 — the Hangul classification latched. hangulPreedit was written only on a non-empty compositionupdate and cleared only on blur, so it survived for the whole focus session. An fcitx/ibus engine switch (Hangul → Pinyin) moves no DOM focus, and the #8241 orphan-digit path emits no composition or input events, so nothing could refresh or clear it. The stale flag then turned the #8241/#7543 Pinyin candidate-digit guard off silently and permanently — the exact regression those guards exist to prevent. It now expires against lastCompositionEventAt on the same staleness window as the neighbouring guards.

P1 — the exemption was broader than the bug. It gated suppressCandidateKey as a whole, so it also fired during a live composition. The claim in the original comment — that no Hangul engine indexes candidates by digit over a Hangul preedit — was false: ibus-hangul's Hanja conversion puts a numbered lookup table over a live Hangul preedit. Now narrowed to the orphan-keyup path, which is the only one the reported bug needs.

Measured on real hardware (ibus-hangul 1.5.5, IBus 1.5.29-rc2), with the candidate table visually confirmed open:

Hanja table open table closed (this bug)
X11 keydown key="Process" keyCode=229 keydown key="1" keyCode=49
Wayland no keydown at all keydown key="1" keyCode=49

Same harness both rows, so the absence is a real negative. ibus consumes the Hanja digit on both platforms, meaning the P1 was not exploitable in practice — the narrowing is defence-in-depth plus a correction to a false comment. The digit's keyup does arrive as a real key="1" in every case including Hanja, but terminal-ime-linux-candidate-state.ts:141 gates the orphan guard on event.type === 'keydown', so that path is inert.

Verification: 4/4 mutations of the load-bearing lines each fail a test (previously, deleting the exemption at the old :117 failed zero tests — it was dead code). 416 IME tests pass. Tests now follow the recorded trace rather than a synthetic shape neither hardware recording produces.

@nwparker
nwparker merged commit d4460d3 into main Aug 19, 2026
49 checks passed
@nwparker
nwparker deleted the nwparker/hangul-terminating-digit branch August 19, 2026 06:15
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
…date pick (stablyai#15429)

* fix(terminal): stop a Hangul-terminating digit being eaten as a candidate pick

A digit typed immediately after a Hangul syllable is dropped in the
terminal on Wayland. Typing 아1 produces 아. The syllable composes and
commits correctly; only the keystroke that ends it is lost.

Reproduced on Ubuntu 24.04, GNOME Shell 46, ibus-hangul 1.5.5, in a
nested Wayland session with real key injection. The pty receives 아 on
Wayland and 아1 under X11 on the same machine with the same engine, and
a GTK client in the same Wayland session receives 아1 - so the
compositor, the input method and the digit are all behaving.

The difference is where the digit is delivered. Under X11 ibus-hangul
swallows it into the preedit and commits 아1 as composition text. Under
Wayland it commits 아 and lets the digit through as an ordinary key -
and the jamo before it arrive with no keydown at all, only keyups.

That orphaned keyup is what breaks it. A plain letter keyup with no
matching keydown arms a 1500ms window in which a bare digit is treated
as a candidate selection, because a Pinyin engine indexes its candidate
list by digit. The digit lands microseconds later, inside the window,
and is suppressed. The window disarms after exactly one digit, which is
why the syllable survives and only the terminating key vanishes.

A Hangul engine has no numbered candidates over its preedit - a digit
ends the syllable and is literal text - so the guard was spending its
one suppression on a keystroke meant for the shell. The tracker now
records whether the current preedit is Hangul and the guard declines.

Read from compositionupdate rather than compositionend: a Pinyin preedit
is the Latin spelling being narrowed while its commit is the Han text,
so reading the commit would misclassify Pinyin and reopen the bugs the
guard was added for. Space is untouched; only digits are reclassified.

Verified A/B/A on that machine: unfixed drops the digit, this change
preserves it, reverting drops it again, three runs each. The X11 case
and both existing ibus-hangul specs still pass.

Closes stablyai#15299

* fix(terminal): expire the Hangul preedit flag and narrow its digit exemption

Review of the stablyai#15299 fix found the Hangul classification could not be
retired and that it exempted more than the reported bug.

The flag was written only on a non-empty compositionupdate and cleared
only on blur, so it latched for the whole focus session. Switching input
engine (Hangul -> Pinyin) under fcitx/ibus moves no DOM focus, and the
stablyai#8241 orphan-digit path emits no composition and no input events, so
nothing could refresh or clear it. The stale flag then turned the
stablyai#8241/stablyai#7543 Pinyin candidate-digit guard off silently and permanently -
the regression those guards exist to prevent. It now expires against
lastCompositionEventAt on the same staleness window as the neighbouring
guards, and compositionstart clears it because the following
compositionupdate re-reads the preedit script.

It is deliberately not cleared on compositionend or on input: the bug is
a digit arriving after the commit, and both recordings deliver the
commit's own insertText before it. Clearing on either reverts the fix -
the orphan-window test fails when input clears it.

The exemption also gated suppressCandidateKey as a whole, so it fired
during a live composition as well. That is broader than the bug, which
is exclusively a digit after compositionend, and it is unsafe: the
earlier claim that no Hangul engine indexes candidates by digit over a
preedit is wrong. ibus-hangul's Hanja conversion (Hanja key / F9) puts a
numbered lookup table over a live Hangul preedit, and its symbol table
behaves the same. Only the orphan-keyup guard - which arms off a bare
keyup and cannot see which engine produced it - now declines.

The tests drove a shape neither recording produces: an empty
compositionupdate immediately before compositionend, which armed the
250ms post-composition window. The Wayland reproduction has no empty
update, and the X11 fixture follows its empty update with
deleteContentBackward + insertText, which disarms that window. The suite
now follows the recorded trace, asserts the 250ms window never arms, and
covers both the expiry and the live-preedit Hanja case.

Refs stablyai#15299
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…date pick (stablyai#15429)

* fix(terminal): stop a Hangul-terminating digit being eaten as a candidate pick

A digit typed immediately after a Hangul syllable is dropped in the
terminal on Wayland. Typing 아1 produces 아. The syllable composes and
commits correctly; only the keystroke that ends it is lost.

Reproduced on Ubuntu 24.04, GNOME Shell 46, ibus-hangul 1.5.5, in a
nested Wayland session with real key injection. The pty receives 아 on
Wayland and 아1 under X11 on the same machine with the same engine, and
a GTK client in the same Wayland session receives 아1 - so the
compositor, the input method and the digit are all behaving.

The difference is where the digit is delivered. Under X11 ibus-hangul
swallows it into the preedit and commits 아1 as composition text. Under
Wayland it commits 아 and lets the digit through as an ordinary key -
and the jamo before it arrive with no keydown at all, only keyups.

That orphaned keyup is what breaks it. A plain letter keyup with no
matching keydown arms a 1500ms window in which a bare digit is treated
as a candidate selection, because a Pinyin engine indexes its candidate
list by digit. The digit lands microseconds later, inside the window,
and is suppressed. The window disarms after exactly one digit, which is
why the syllable survives and only the terminating key vanishes.

A Hangul engine has no numbered candidates over its preedit - a digit
ends the syllable and is literal text - so the guard was spending its
one suppression on a keystroke meant for the shell. The tracker now
records whether the current preedit is Hangul and the guard declines.

Read from compositionupdate rather than compositionend: a Pinyin preedit
is the Latin spelling being narrowed while its commit is the Han text,
so reading the commit would misclassify Pinyin and reopen the bugs the
guard was added for. Space is untouched; only digits are reclassified.

Verified A/B/A on that machine: unfixed drops the digit, this change
preserves it, reverting drops it again, three runs each. The X11 case
and both existing ibus-hangul specs still pass.

Closes stablyai#15299

* fix(terminal): expire the Hangul preedit flag and narrow its digit exemption

Review of the stablyai#15299 fix found the Hangul classification could not be
retired and that it exempted more than the reported bug.

The flag was written only on a non-empty compositionupdate and cleared
only on blur, so it latched for the whole focus session. Switching input
engine (Hangul -> Pinyin) under fcitx/ibus moves no DOM focus, and the
stablyai#8241 orphan-digit path emits no composition and no input events, so
nothing could refresh or clear it. The stale flag then turned the
stablyai#8241/stablyai#7543 Pinyin candidate-digit guard off silently and permanently -
the regression those guards exist to prevent. It now expires against
lastCompositionEventAt on the same staleness window as the neighbouring
guards, and compositionstart clears it because the following
compositionupdate re-reads the preedit script.

It is deliberately not cleared on compositionend or on input: the bug is
a digit arriving after the commit, and both recordings deliver the
commit's own insertText before it. Clearing on either reverts the fix -
the orphan-window test fails when input clears it.

The exemption also gated suppressCandidateKey as a whole, so it fired
during a live composition as well. That is broader than the bug, which
is exclusively a digit after compositionend, and it is unsafe: the
earlier claim that no Hangul engine indexes candidates by digit over a
preedit is wrong. ibus-hangul's Hanja conversion (Hanja key / F9) puts a
numbered lookup table over a live Hangul preedit, and its symbol table
behaves the same. Only the orphan-keyup guard - which arms off a bare
keyup and cannot see which engine produced it - now declines.

The tests drove a shape neither recording produces: an empty
compositionupdate immediately before compositionend, which armed the
250ms post-composition window. The Wayland reproduction has no empty
update, and the X11 fixture follows its empty update with
deleteContentBackward + insertText, which disarms that window. The suite
now follows the recorded trace, asserts the 250ms window never arms, and
covers both the expiry and the live-preedit Hanja case.

Refs stablyai#15299
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…date pick (stablyai#15429)

* fix(terminal): stop a Hangul-terminating digit being eaten as a candidate pick

A digit typed immediately after a Hangul syllable is dropped in the
terminal on Wayland. Typing 아1 produces 아. The syllable composes and
commits correctly; only the keystroke that ends it is lost.

Reproduced on Ubuntu 24.04, GNOME Shell 46, ibus-hangul 1.5.5, in a
nested Wayland session with real key injection. The pty receives 아 on
Wayland and 아1 under X11 on the same machine with the same engine, and
a GTK client in the same Wayland session receives 아1 - so the
compositor, the input method and the digit are all behaving.

The difference is where the digit is delivered. Under X11 ibus-hangul
swallows it into the preedit and commits 아1 as composition text. Under
Wayland it commits 아 and lets the digit through as an ordinary key -
and the jamo before it arrive with no keydown at all, only keyups.

That orphaned keyup is what breaks it. A plain letter keyup with no
matching keydown arms a 1500ms window in which a bare digit is treated
as a candidate selection, because a Pinyin engine indexes its candidate
list by digit. The digit lands microseconds later, inside the window,
and is suppressed. The window disarms after exactly one digit, which is
why the syllable survives and only the terminating key vanishes.

A Hangul engine has no numbered candidates over its preedit - a digit
ends the syllable and is literal text - so the guard was spending its
one suppression on a keystroke meant for the shell. The tracker now
records whether the current preedit is Hangul and the guard declines.

Read from compositionupdate rather than compositionend: a Pinyin preedit
is the Latin spelling being narrowed while its commit is the Han text,
so reading the commit would misclassify Pinyin and reopen the bugs the
guard was added for. Space is untouched; only digits are reclassified.

Verified A/B/A on that machine: unfixed drops the digit, this change
preserves it, reverting drops it again, three runs each. The X11 case
and both existing ibus-hangul specs still pass.

Closes stablyai#15299

* fix(terminal): expire the Hangul preedit flag and narrow its digit exemption

Review of the stablyai#15299 fix found the Hangul classification could not be
retired and that it exempted more than the reported bug.

The flag was written only on a non-empty compositionupdate and cleared
only on blur, so it latched for the whole focus session. Switching input
engine (Hangul -> Pinyin) under fcitx/ibus moves no DOM focus, and the
stablyai#8241 orphan-digit path emits no composition and no input events, so
nothing could refresh or clear it. The stale flag then turned the
stablyai#8241/stablyai#7543 Pinyin candidate-digit guard off silently and permanently -
the regression those guards exist to prevent. It now expires against
lastCompositionEventAt on the same staleness window as the neighbouring
guards, and compositionstart clears it because the following
compositionupdate re-reads the preedit script.

It is deliberately not cleared on compositionend or on input: the bug is
a digit arriving after the commit, and both recordings deliver the
commit's own insertText before it. Clearing on either reverts the fix -
the orphan-window test fails when input clears it.

The exemption also gated suppressCandidateKey as a whole, so it fired
during a live composition as well. That is broader than the bug, which
is exclusively a digit after compositionend, and it is unsafe: the
earlier claim that no Hangul engine indexes candidates by digit over a
preedit is wrong. ibus-hangul's Hanja conversion (Hanja key / F9) puts a
numbered lookup table over a live Hangul preedit, and its symbol table
behaves the same. Only the orphan-keyup guard - which arms off a bare
keyup and cannot see which engine produced it - now declines.

The tests drove a shape neither recording produces: an empty
compositionupdate immediately before compositionend, which armed the
250ms post-composition window. The Wayland reproduction has no empty
update, and the X11 fixture follows its empty update with
deleteContentBackward + insertText, which disarms that window. The suite
now follows the recorded trace, asserts the 250ms window never arms, and
covers both the expiry and the live-preedit Hanja case.

Refs stablyai#15299
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.

[Bug]: Digit typed right after Hangul composition is dropped in the integrated terminal on Wayland (works under XWayland)

1 participant