Skip to content

Fix TextBox IME replacement range crash - #14786

Merged
teamleaderleo merged 1 commit into
mainfrom
revive/5346-textbox-ime-range-clamp
Sep 26, 2026
Merged

teamleaderleo merged 1 commit into
mainfrom
revive/5346-textbox-ime-range-clamp

Conversation

@teamleaderleo

@teamleaderleo teamleaderleo commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Revives #5346 (closed as stale in the 09-23 bulk close)

What / why

TextBoxInputTextView still forwards the IME's raw replacementRange to NSTextView.insertText / setMarkedText. When an IME hands back a stale range past the end of the UTF-16 storage (seen with Japanese input at the end of the text), AppKit raises NSRangeException (Sentry CMUXTERM-MACOS-VD0). This clamps the replacement range to the storage bounds, and normalizes an NSNotFound marked-text selection to the end of the marked text.

Changes vs the original

  • Same fix, ported onto the current insertText override (which now also tracks nested didChangeText). The sanitized range is also what queueAutomaticAttachmentFileCleanup sees.
  • Same two regression tests in cmuxTests/TextBoxMentionCompletionTests.swift.

Testing

  • CI (cmuxTests TextBoxMentionCompletionTests).

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes a crash in TextBoxInputTextView (Sentry CMUXTERM-MACOS-VD0) where an IME can return a stale replacementRange past the end of the UTF-16 text storage, raising NSRangeException in AppKit. insertText and setMarkedText now clamp the range to the storage bounds, and an NSNotFound marked-text selection is normalized to the end of the marked text.

  • Adds two regression tests in cmuxTests/TextBoxMentionCompletionTests.swift for the UTF-16-end clamp and the selection normalization.
  • Revives PR Fix TextBox IME replacement range crash #5346 with the same fix ported onto the current code.

Written for commit 7a4c430. Summary will update on new commits.

Review in cubic

Clamp NSTextInputClient replacement ranges to the current UTF-16 storage
bounds before handing them to NSTextView.insertText/setMarkedText, and
normalize a missing marked-text selection to the end of the marked text.
A stale IME range past the end raised NSRangeException (Sentry
CMUXTERM-MACOS-VD0).

Co-authored-by: Lawrence Chen <54008264+lawrencecchen@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: manaflow-ai/cmux/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 929f1c2f-2325-4403-b166-6c4c48cdda6f

📥 Commits

Reviewing files that changed from the base of the PR and between f39a1e5 and 7a4c430.

📒 Files selected for processing (2)
  • Sources/TextBoxInput.swift
  • cmuxTests/TextBoxMentionCompletionTests.swift

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.

@github-actions

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@teamleaderleo
teamleaderleo merged commit 049eb4e into main Sep 26, 2026
62 checks passed
@teamleaderleo
teamleaderleo deleted the revive/5346-textbox-ime-range-clamp branch September 26, 2026 03:22
@github-actions

Copy link
Copy Markdown
Contributor

Merge receipt for 7a4c43099f: every check was green at merge (16 verified; 14 skipped by policy). Full suite runs on main after merge.

rustybret pushed a commit to rustybret/bmux that referenced this pull request Sep 26, 2026
6319fbe PR catch-up: run automatically when main goes green (manaflow-ai#14790)
8e4e505 iOS: replace a silent control stream instead of closing a live connection (manaflow-ai#14695)
c4b36fd Code session snapshots on a main-sized stack to fix deep split SIGBUS (manaflow-ai#14787)
5a69850 ci: fetch compiled products from another owned mini over the LAN first (manaflow-ai#14779)
d3d8941 ci: record warm-state distance per owned admission, fit a cost model, route admission by it (manaflow-ai#14778)
ea5a166 Fix main-thread deadlock in session autosave via ghostty_surface_needs_confirm_quit (manaflow-ai#14784)
049eb4e Fix TextBox IME replacement range crash (manaflow-ai#14786)
afd8ec0 Bound process-tree recursion depth in cmux top payloads (manaflow-ai#14785)
7cf0c92 iOS: release closed browser stream panels and display links (manaflow-ai#14782)

# Conflicts:
#	.github/workflows/ci-artifact-transport.yml
#	.github/workflows/ci-guards.yml
#	.github/workflows/ci-macos.yml
#	.github/workflows/pr-catch-up.yml
bn-l pushed a commit to bn-l/cmux that referenced this pull request Oct 4, 2026
Ported from upstream manaflow-ai#14786 (049eb4e): "Fix TextBox IME replacement range crash (manaflow-ai#14786)".
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.

1 participant