#6814 · Late terminal text insertion is not forwarded
Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high for the event-order mechanism; native iOS keyboard behavior is unverified.
1. TL;DR
The issue reports that selecting a Chinese keyboard candidate on an iPhone produces no terminal input. On the current trusted main commit, the exact xterm dependency used by bb loses inserted text when the textarea is updated after its keydown timer but before keyup. An original executable test reproduces that loss in two separate clean checkouts; three nearby control cases pass in each. The underlying problem is that xterm equates a preceding keydown with input already being handled, even when its earlier textarea check emitted nothing. This is a partial reproduction because this investigation uses synthetic DOM events in jsdom, not a physical iPhone, Safari, or a live bb terminal.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Late non-composition insertion after a process-key keydown can disappear. | Verified for the tested event sequence | Real pinned xterm bundle: expected one 中文 data event, actual zero, in both checkouts. |
| Timing of insertion relative to the timer and keyup is decisive. | Verified | Insertion before the timer and insertion after keyup each emit exactly once. |
| Direct Latin input still works. | Verified in the harness | A normal q keydown emits q once in both checkouts. |
| The affected xterm version is pinned in bb and its textarea has no late-insertion recovery. | Verified by trusted source | The app pins 6.1.0-beta.292; terminal creation and data forwarding use xterm directly. |
| The physical iOS Pinyin keyboard emits this event sequence on the reported phone. | Unverified | No iOS device or simulator was available. The issue's trace was treated as a claim, not as independently captured evidence. |
| Newer upstream releases have identical behavior. | Unverified | No additional dependency was installed or executed. |
3. Environment
- Public repository:
get-bb/bb, trustedorigin/maincommit916d684ac23d0b0de82c09cfc7553a50287d2188. - Linux, Node
v22.19.0, pnpm9.15.0, pinned@xterm/xterm 6.1.0-beta.292, existing lockfile-resolvedjsdom 29.0.1. - Two fresh clones named
baseandverifyunder one temporary investigation directory. Both use the same recorded trusted commit and separate frozen installs; no linked-PR checkout was used. - No bb server, PTY, provider, network-facing plugin, browser session, temporary port, or bb data directory was started. The test runs entirely in new jsdom windows.
- The Browser Automation plugin could not open a session because Chrome/Chromium is not installed. No alternative browser automation was used.
- The normal frozen installation succeeded. A full Turbo build was attempted but failed in the existing GitHub plugin because Plugin SDK
dist/process.jsanddist/host.jswere unavailable at build time. This is outside the tested xterm path; no full-build success is claimed.
4. Minimal reproduction
This is a dependency-boundary reproduction, not an end-to-end bb or native iOS test. The test evaluates the actual installed xterm UMD bundle in a new jsdom window for each case, then observes only its public onData callback. The harness supplies structured cloning, media-query, and canvas text-measurement shims needed to mount a terminal; it does not replace xterm input handlers, timers, or data emission.
- Clone the trusted repository and check out the recorded base:
git clone https://github.com/get-bb/bb.git bb-6814 cd bb-6814 git checkout --detach 916d684ac23d0b0de82c09cfc7553a50287d2188 pnpm install --frozen-lockfile --prefer-offline
- Save the complete original regression harness below as
../event-order.cjsoutside the checkout and run it with the checkout as its argument:node ../event-order.cjs . expected exit after a correct repair: 0 observed exit on the trusted base: 1
- The failing case dispatches keydown with keyCode 229 and no composition, waits for the next timer task, inserts
中文into the textarea, dispatches composedbeforeinput/inputevents of typeinsertText, and releases the key. It expects the public terminal data callback to emit the candidate exactly once.
late insert before release: expected ["中文"], actual []
insert before timer: expected ["中文"], actual ["中文"]
late insert after release: expected ["中文"], actual ["中文"]
direct Latin key: expected ["q"], actual ["q"]
{"passed":3,"failed":1}
Evidence is included in this self-contained report: first run, exact output · second run, exact output · installed dependency source excerpts and hashes. Raw local files are not published.
Complete executable regression harness
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { createRequire } = require('node:module');
const checkout = path.resolve(process.argv[2] || process.cwd());
const rootRequire = createRequire(path.join(checkout, 'package.json'));
const vitestRequire = createRequire(rootRequire.resolve('vitest/package.json'));
const { JSDOM } = vitestRequire('jsdom');
const appRequire = createRequire(path.join(checkout, 'apps/app/package.json'));
const bundle = fs.readFileSync(appRequire.resolve('@xterm/xterm'), 'utf8');
const candidate = '\u4e2d\u6587';
async function exercise(name, mode) {
const dom = new JSDOM('<!doctype html><div id="terminal"></div>', {
pretendToBeVisual: true,
runScripts: 'outside-only',
});
const { window } = dom;
window.structuredClone = structuredClone;
window.matchMedia = () => ({ matches: false, addListener() {}, removeListener() {} });
window.HTMLCanvasElement.prototype.getContext = () => ({
measureText: (text) => ({ width: text.length * 8 }),
});
window.eval(bundle);
const terminal = new window.Terminal({ cols: 32, rows: 4 });
const received = [];
const events = [];
try {
terminal.open(window.document.getElementById('terminal'));
terminal.onData((data) => received.push(data));
const textarea = terminal.textarea;
assert.ok(textarea);
for (const type of ['keydown', 'beforeinput', 'input', 'keyup']) {
textarea.addEventListener(type, (event) => events.push({
type,
keyCode: event.keyCode ?? null,
composed: event.composed,
value: textarea.value,
received: [...received],
}));
}
const nextTask = () => new Promise((resolve) => window.setTimeout(resolve, 0));
const release = () => textarea.dispatchEvent(new window.KeyboardEvent('keyup', {
key: 'Unidentified', bubbles: true, keyCode: 0,
}));
const insert = () => {
const options = { bubbles: true, composed: true, data: candidate, inputType: 'insertText' };
textarea.dispatchEvent(new window.InputEvent('beforeinput', options));
textarea.value = candidate;
textarea.dispatchEvent(new window.InputEvent('input', options));
};
if (mode === 'latin') {
textarea.dispatchEvent(new window.KeyboardEvent('keydown', {
bubbles: true, key: 'q', code: 'KeyQ', keyCode: 81,
}));
release();
} else {
textarea.dispatchEvent(new window.KeyboardEvent('keydown', {
bubbles: true, key: 'Unidentified', keyCode: 229,
}));
if (mode !== 'early') await nextTask();
if (mode === 'released') release();
insert();
if (mode !== 'released') release();
}
await nextTask();
const expected = mode === 'latin' ? ['q'] : [candidate];
const result = { name, expected, actual: received, events };
console.log(JSON.stringify(result));
assert.deepEqual(received, expected);
return true;
} catch (error) {
if (error.code !== 'ERR_ASSERTION') throw error;
console.log('CONTRACT FAILURE: ' + name);
return false;
} finally {
terminal.dispose();
window.close();
}
}
(async () => {
const results = [];
for (const [name, mode] of [
['late insert before release', 'late'],
['insert before timer', 'early'],
['late insert after release', 'released'],
['direct Latin key', 'latin'],
]) results.push(await exercise(name, mode));
console.log(JSON.stringify({ passed: results.filter(Boolean).length, failed: results.filter((value) => !value).length }));
process.exitCode = results.every(Boolean) ? 0 : 1;
})().catch((error) => {
console.error(error.message);
process.exitCode = 2;
});
5. Root cause
Trusted bb source pins the dependency at apps/app/package.json:73. The terminal mounts at ThreadTerminalView.tsx:1143. Its public onData subscription at line 1281 forwards what xterm emits; it cannot recover data xterm never emits.
The following dependency excerpts are from that pinned package, not from a linked pull request. The inline source evidence records source filenames, exact line numbers, and SHA-256 hashes; dependency files themselves are not tracked in the bb repository.
CoreBrowserTerminal.ts:845: keydown sets_keyDownSeen = truebefore calling the composition helper.CompositionHelper.ts:131: a non-composition process-key event schedules_handleAnyTextareaChanges()and returns without ordinary key processing.CompositionHelper.ts:212: the helper compares textarea values in a zero-delay timer. In the failing case both values are empty, so it emits nothing.CoreBrowserTerminal.ts:1032: the later composed input is rejected while the earlier keydown is still recorded:ev.data && ev.inputType === 'insertText' && (!ev.composed || !this._keyDownSeen) && !this.optionsService.rawOptions.screenReaderMode
CoreBrowserTerminal.ts:950: keyup clears the flag, but does not retry the rejected input. The candidate therefore never reachesonData.
The deeper issue is using “keydown observed” as a proxy for “text delivered.” The nearby passing controls establish that this is an ordering-dependent loss, not a generally nonfunctional terminal in the harness. Actual iOS generation of the sequence remains outside the verified boundary.
6. Proposed fix
Recover a non-composing late text insertion only when the process-key textarea check has completed without delivering input. Route it through xterm's public input path, suppress recovery if any equivalent data was already emitted, and clear pending state on composition, replacement key activity, and disposal. Do not forward all input events unconditionally: that would duplicate ordinary key and composition delivery. Extend the focused test to cover multiple candidates, real composition, cancellation, paste, and teardown, then verify on Safari with a native Pinyin keyboard.
No production change was made. Open PR #6815 already links this issue through GitHub closing-issue metadata. Opening a duplicate fix would violate the autopilot rule; moreover native-device reproduction is still incomplete.
7. Linked PR review
#6815 — static review only
The read-only diff introduces a terminal-local listener that tracks a pending process key, whether xterm's check has completed, and whether data has already been emitted. It installs the listener after terminal open and disposes it during terminal cleanup. Its guarded call to the public terminal input method addresses the demonstrated missed-delivery path rather than changing the PTY transport.
Static findings: the timer and already-sent gates align with the verified root cause; composition-start cancellation and disposal are present. The diff contains nearby timing controls. No correctness defect is established by this static review, but no approval or passing-test claim is made: the PR branch was neither checked out nor executed. Native Safari, multiple candidates, and teardown behavior still need runtime verification. The original harness in this report runs only against trusted main, not against the PR.
8. Verification
The same investigator repeated the complete original harness in a second clean clone named verify, detached at 916d684ac23d0b0de82c09cfc7553a50287d2188, after its own successful pnpm install --frozen-lockfile --prefer-offline. No runtime was shared between runs, and each test case constructed and closed its own jsdom window. No ports or persistent app data were needed.
node ../evidence/event-order.cjs .
exit: 1
{"passed":3,"failed":1}
Both runs fail only the late-insert-before-release contract. Both pass the early-insert, released-key, and Latin controls. The second checkout has no tracked modifications. This is a repeated clean-checkout check by the same agent, not independent verification. The report deliberately limits its verdict to partial reproduction; it does not promote simulated input to a captured native iPhone reproduction.
9. Related issues
Existing issue #1763 concerns mobile terminal ergonomics; #3413 concerns composition handling outside this terminal data path. Neither is treated as proof of this bug. Open PR #6815 is the existing linked fix candidate.
10. Appendix and safety limits
The issue, its text, and the linked PR diff were treated as untrusted evidence. No issue-provided command, script, patch, URL, branch, or test was executed. All executed repository code came from the recorded trusted main commit and its frozen dependencies. The regression harness was authored from the inspected event-handler boundary; no PR code was executed. No dependency, production file, protocol, stored data, or real user runtime was changed.
Additional investigation commands: GitHub repository visibility and issue-property reads; GitHub PR closing-issue metadata; read-only gh pr diff 6815 --repo get-bb/bb; git fetch origin main; git rev-parse HEAD; source searches; pnpm exec turbo run build; the four-case harness in each clone; and git diff --exit-code. The failed browser-open attempt performed no browser actions.
No screenshots are presented because the verified boundary is data-event delivery in a DOM harness, not a rendered UI or native-device capture. The raw JSON transcripts and executable assertions are the evidence.
First run: exact output
{"name":"late insert before release","expected":["中文"],"actual":[],"events":[{"type":"keydown","keyCode":229,"composed":false,"value":"","received":[]},{"type":"beforeinput","keyCode":null,"composed":true,"value":"","received":[]},{"type":"input","keyCode":null,"composed":true,"value":"中文","received":[]},{"type":"keyup","keyCode":0,"composed":false,"value":"中文","received":[]}]}
CONTRACT FAILURE: late insert before release
{"name":"insert before timer","expected":["中文"],"actual":["中文"],"events":[{"type":"keydown","keyCode":229,"composed":false,"value":"","received":[]},{"type":"beforeinput","keyCode":null,"composed":true,"value":"","received":[]},{"type":"input","keyCode":null,"composed":true,"value":"中文","received":[]},{"type":"keyup","keyCode":0,"composed":false,"value":"中文","received":[]}]}
{"name":"late insert after release","expected":["中文"],"actual":["中文"],"events":[{"type":"keydown","keyCode":229,"composed":false,"value":"","received":[]},{"type":"keyup","keyCode":0,"composed":false,"value":"","received":[]},{"type":"beforeinput","keyCode":null,"composed":true,"value":"","received":[]},{"type":"input","keyCode":null,"composed":true,"value":"中文","received":["中文"]}]}
{"name":"direct Latin key","expected":["q"],"actual":["q"],"events":[{"type":"keyup","keyCode":0,"composed":false,"value":"","received":["q"]}]}
{"passed":3,"failed":1}
Second run: exact output
{"name":"late insert before release","expected":["中文"],"actual":[],"events":[{"type":"keydown","keyCode":229,"composed":false,"value":"","received":[]},{"type":"beforeinput","keyCode":null,"composed":true,"value":"","received":[]},{"type":"input","keyCode":null,"composed":true,"value":"中文","received":[]},{"type":"keyup","keyCode":0,"composed":false,"value":"中文","received":[]}]}
CONTRACT FAILURE: late insert before release
{"name":"insert before timer","expected":["中文"],"actual":["中文"],"events":[{"type":"keydown","keyCode":229,"composed":false,"value":"","received":[]},{"type":"beforeinput","keyCode":null,"composed":true,"value":"","received":[]},{"type":"input","keyCode":null,"composed":true,"value":"中文","received":[]},{"type":"keyup","keyCode":0,"composed":false,"value":"中文","received":[]}]}
{"name":"late insert after release","expected":["中文"],"actual":["中文"],"events":[{"type":"keydown","keyCode":229,"composed":false,"value":"","received":[]},{"type":"keyup","keyCode":0,"composed":false,"value":"","received":[]},{"type":"beforeinput","keyCode":null,"composed":true,"value":"","received":[]},{"type":"input","keyCode":null,"composed":true,"value":"中文","received":["中文"]}]}
{"name":"direct Latin key","expected":["q"],"actual":["q"],"events":[{"type":"keyup","keyCode":0,"composed":false,"value":"","received":["q"]}]}
{"passed":3,"failed":1}
Pinned dependency source evidence
@xterm/xterm 6.1.0-beta.292 / src/browser/CoreBrowserTerminal.ts (SHA256 f9d9f008ece31d1ca63bd3bfab5401afd905c71525a7628f02cf8fef731a02be)
845 protected _keyDown(event: KeyboardEvent): boolean | undefined {
846 this._keyDownHandled = false;
847 this._keyDownSeen = true;
848
849 if (this._customKeyEventHandler && this._customKeyEventHandler(event) === false) {
850 return false;
851 }
852
853 // Ignore composing with Alt key on Mac when macOptionIsMeta is enabled
854 const shouldIgnoreComposition = this.browser.isMac && this.options.macOptionIsMeta && event.altKey;
855
856 if (!shouldIgnoreComposition && !this._compositionHelper!.keydown(event)) {
857 if (this.options.scrollOnUserInput && this.buffer.ybase !== this.buffer.ydisp) {
858 this.scrollToBottom(true);
859 }
860 return false;
861 }
862
863 if (!shouldIgnoreComposition && (event.key === 'Dead' || event.key === 'AltGraph')) {
@xterm/xterm 6.1.0-beta.292 / src/browser/CoreBrowserTerminal.ts (SHA256 f9d9f008ece31d1ca63bd3bfab5401afd905c71525a7628f02cf8fef731a02be)
950 protected _keyUp(ev: KeyboardEvent): void {
951 this._keyDownSeen = false;
952
953 if (this._customKeyEventHandler && this._customKeyEventHandler(ev) === false) {
954 return;
955 }
@xterm/xterm 6.1.0-beta.292 / src/browser/CoreBrowserTerminal.ts (SHA256 f9d9f008ece31d1ca63bd3bfab5401afd905c71525a7628f02cf8fef731a02be)
1028 protected _inputEvent(ev: InputEvent): boolean {
1029 // Only support emoji IMEs when screen reader mode is disabled as the event must bubble up to
1030 // support reading out character input which can doubling up input characters
1031 // Based on these event traces: https://github.com/xtermjs/xterm.js/issues/3679
1032 if (ev.data && ev.inputType === 'insertText' && (!ev.composed || !this._keyDownSeen) && !this.optionsService.rawOptions.screenReaderMode) {
1033 if (this._keyPressHandled) {
1034 return false;
1035 }
1036
1037 // The key was handled so clear the dead key state, otherwise certain keystrokes like arrow
1038 // keys could be ignored
1039 this._unprocessedDeadKey = false;
1040
1041 const text = ev.data;
1042 this.coreService.triggerDataEvent(text, true);
1043 return true;
1044 }
1045
1046 return false;
1047 }
@xterm/xterm 6.1.0-beta.292 / src/browser/input/CompositionHelper.ts (SHA256 1e935e66830ca171456466987cb45ed0a270553901729f11dfa91f6b702e0845)
115 public keydown(ev: KeyboardEvent): boolean {
116 if (this._isComposing || this._isSendingComposition) {
117 if (ev.keyCode === 20 || ev.keyCode === 229) {
118 // 20 is CapsLock, 229 is Enter
119 // Continue composing if the keyCode is the "composition character"
120 return false;
121 }
122 if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) {
123 // Continue composing if the keyCode is a modifier key
124 return false;
125 }
126 // Finish composition immediately. This is mainly here for the case where enter is
127 // pressed and the handler needs to be triggered before the command is executed.
128 this._finalizeComposition(false);
129 }
130
131 if (ev.keyCode === 229) {
132 // If the "composition character" is used but gets to this point it means a non-composition
133 // character (eg. numbers and punctuation) was pressed when the IME was active.
134 this._handleAnyTextareaChanges();
135 return false;
136 }
137
138 return true;
139 }
@xterm/xterm 6.1.0-beta.292 / src/browser/input/CompositionHelper.ts (SHA256 1e935e66830ca171456466987cb45ed0a270553901729f11dfa91f6b702e0845)
212 private _handleAnyTextareaChanges(): void {
213 if (this._textareaChangeTimer) {
214 return;
215 }
216 const oldValue = this._textarea.value;
217 this._textareaChangeTimer = window.setTimeout(() => {
218 this._textareaChangeTimer = undefined;
219 // Ignore if a composition has started since the timeout
220 if (!this._isComposing) {
221 const newValue = this._textarea.value;
222
223 const diff = newValue.replace(oldValue, '');
224
225 this._dataAlreadySent = diff;
226
227 if (newValue.length > oldValue.length) {
228 this._coreService.triggerDataEvent(diff, true);
229 } else if (newValue.length < oldValue.length) {
230 this._coreService.triggerDataEvent(`${C0.DEL}`, true);
231 } else if ((newValue.length === oldValue.length) && (newValue !== oldValue)) {
232 this._coreService.triggerDataEvent(newValue, true);
233 }
234
235 }
236 }, 0);
237 }
238
239 /**
240 * Positions the composition view on top of the cursor and the textarea just below it (so the
241 * IME helper dialog is positioned correctly).
> AGENT GENERATED