Skip to content

Space key shortcut tests read the keyboard layout off the main thread and crash - #12618

Closed
ejc3 wants to merge 1 commit into
manaflow-ai:mainfrom
ejc3:fix/space-key-test-main-actor
Closed

ejc3 wants to merge 1 commit into
manaflow-ai:mainfrom
ejc3:fix/space-key-test-main-actor

Conversation

@ejc3

@ejc3 ejc3 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

KeyboardShortcutSpaceKeyTests.shortcutConfigParsingRoundTripsSpaceKey can crash the unit-test host. The crash report shows a SIGTRAP on a background thread inside KeyboardLayout.characterFromInputSource, called from ShortcutStroke.resolvedKeyCode() at line 60 of the test.

resolvedKeyCode() reads the current keyboard layout through Text Input Sources by default, and those calls must run on the main thread. This suite is not main-actor isolated, so Swift Testing runs it on a background thread. Every other suite that calls resolvedKeyCode() is @MainActor.

The suite is now @MainActor.

Testing

  • In a full run of the unit tests at main 4638e5b1ea plus the compile fixes in Fix the compile errors that keep main and its unit tests from building #12584, through scripts/ci/run-app-host-xcodebuild.sh in 12 batches the way CI runs app-host tests, a crash report shows this trap on a background thread from shortcutConfigParsingRoundTripsSpaceKey, and the host died.
  • The same 12 batches with the crash fixes applied: KeyboardShortcutSpaceKeyTests ran and passed twice in batch 1, with no layout-lookup crash report.
  • The same 12 batches with all seven crash fixes applied, run again after the review changes: batch 1 used its time budget relaunching the host after an unrelated index-out-of-range crash, so this suite did not get to run. No layout-lookup crash report appeared.

Demo Video

Not applicable. The change prevents a crash and has no visible effect.

Review Trigger (Copy/Paste as PR comment)

@codex review
@coderabbitai review
@greptile-apps review
@cubic-dev-ai review

Checklist

  • I tested the change locally
  • I added or updated tests for behavior changes
  • I updated docs/changelog if needed
  • I requested bot reviews after my latest commit (copy/paste block above or equivalent)
  • All code review bot comments are resolved
  • All human review comments are resolved

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

Runs KeyboardShortcutSpaceKeyTests on @MainActor so resolvedKeyCode() reads Text Input Sources on the main thread instead of Swift Testing’s background thread, preventing the unit-test host from crashing during space-key shortcut parsing.

Written for commit d215846. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Updated keyboard shortcut tests to run on the main thread, improving reliability when checking keyboard layout-dependent behavior.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 9f685aca-f878-48a2-8c91-1aa51f5ea6be

📥 Commits

Reviewing files that changed from the base of the PR and between 708c758 and 49d9644.

📒 Files selected for processing (1)
  • cmuxTests/KeyboardShortcutSpaceKeyTests.swift

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


📝 Walkthrough

Walkthrough

The KeyboardShortcutSpaceKeyTests suite now runs on the main actor. A comment documents that resolvedKeyCode() reads the current keyboard layout through Text Input Sources.

Changes

Keyboard shortcut test execution

Layer / File(s) Summary
Main-actor test annotation
cmuxTests/KeyboardShortcutSpaceKeyTests.swift
The test suite is annotated with @MainActor. A comment explains the main-thread requirement for resolvedKeyCode().

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Bug fix

Suggested reviewers: austinywang

Merge Risk: ⚪ Minimal · up to 49d96

This change only moves the affected keyboard shortcut tests to the main actor and does not alter production behavior, so merge risk is minimal.

🚥 Pre-merge checks | ✅ 24 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (24 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main issue: space-key shortcut tests read keyboard layout data off the main thread and crash.
Description check ✅ Passed The description includes the required Summary, Testing, Demo Video, Review Trigger, and Checklist sections. It clearly explains the crash, the @MainActor fix, and the test results. The unchecked check…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Cmux Swift Actor Isolation ✅ Passed PASS. The authoritative diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift and adds @MainActor to a test suite. The custom check explicitly allows tests, and the diff does not introdu…
Cmux Swift Blocking Runtime ✅ Passed PASS. The diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift. It adds a comment and @MainActor; it adds no semaphore, wait, sleep, delayed dispatch, polling, main-queue sync, or manua…
Cmux Browser Automation Off-Main ✅ Passed PASS. The authoritative diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift by adding @MainActor to KeyboardShortcutSpaceKeyTests and a comment about keyboard-layout lookup. It adds …
Cmux Expensive Synchronous Load ✅ Passed PASS. The authoritative diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift and adds @MainActor plus a comment. It adds no production Swift code and no agent-history loader, transcript…
Cmux Cache Substitution Correctness ✅ Passed PASS. The review-scoped diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift. It adds @MainActor and a comment; it does not replace an authoritative read with a cache or alter a persist…
Cmux No Hacky Sleeps ✅ Passed PASS. The pull request changes only the Swift test file cmuxTests/KeyboardShortcutSpaceKeyTests.swift. It adds @MainActor and a comment; it introduces no sleeps, timers, polling, delays, or wall-c…
Cmux Algorithmic Complexity ✅ Passed The pull request changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift. It adds @MainActor and a comment to a test suite. It does not add or modify production iteration, sorting, filtering, j…
Cmux Swift Concurrency ✅ Passed PASS: The PR changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift by adding a comment and @MainActor. It adds no Dispatch queues, Combine state, completion-handler API, or fire-and-forget `T…
Cmux Swift @Concurrent ✅ Passed PASS: The diff only adds @MainActor and a comment to KeyboardShortcutSpaceKeyTests. The suite contains no async, nonisolated async, or @concurrent declarations or call-site changes. `resolve…
Cmux Swift Package Boundaries ✅ Passed PASS. The authoritative diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift and adds @MainActor plus a comment. This is test code, not a production Swift feature in an app target. The …
Cmux Swiftpm Lockfiles ✅ Passed PASS: The reviewed range changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift, adding @MainActor and a comment. It does not change a Package.swift, Package.resolved, .gitignore, workfl…
Cmux Swift Logging ✅ Passed The pull request adds only a comment and @MainActor to cmuxTests/KeyboardShortcutSpaceKeyTests.swift. The changed code is test code, and the added-line scan found no print, debugPrint, dump,…
Cmux User-Facing Error Privacy ✅ Passed PASS. The authoritative PR diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift, a test suite. The three added lines are a @MainActor annotation and a developer comment about `resolvedK…
Cmux Full Internationalization ✅ Passed PASS: The PR changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift. It adds @MainActor and a developer-only comment to a test suite. The added text is not user-facing, and the rule explicitly…
Cmux Swiftui State Layout ✅ Passed PASS. The pull request changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift. The diff adds a comment and @MainActor to a test suite. It does not add or modify SwiftUI state, layout measureme…
Cmux Architecture Rethink ✅ Passed PASS. The PR changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift and adds @MainActor plus a comment that documents the Text Input Sources requirement. resolvedKeyCode() directly calls `Ke…
Cmux Swift Auxiliary Window Close Shortcuts ✅ Passed PASS. The authoritative PR diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift. It adds @MainActor and a comment. It does not add or materially change any NSWindow, NSPanel, `NSWin…
Cmux Source Artifacts ✅ Passed The PR changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift, a hand-written test source file. The diff adds a @MainActor annotation and explanatory comments. It adds no logs, screenshots, ca…
Cmux No Test Or Debug Seam In Production Source ✅ Passed The pull request changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift. The diff adds @MainActor and a comment to a test suite; it adds no Swift file under a production Sources/ path and no…
Cmux No Ambient Global State ✅ Passed PASS. The authoritative diff changes only cmuxTests/KeyboardShortcutSpaceKeyTests.swift and adds a comment plus @MainActor to the existing test suite. It adds no production Swift code, file-scope …
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions

Copy link
Copy Markdown
Contributor

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

@ejc3
ejc3 marked this pull request as ready for review September 14, 2026 18:14
`shortcutConfigParsingRoundTripsSpaceKey` calls `resolvedKeyCode()`, which by
default reads the current keyboard layout through Text Input Sources. Those
calls must run on the main thread. `KeyboardShortcutSpaceKeyTests` is not
main-actor isolated, so Swift Testing ran it on a background thread, where the
layout lookup trapped and took the test host down with every test running
beside it.

Isolate the suite to the main actor, like the other suites that call
`resolvedKeyCode()`.
@teamleaderleo

teamleaderleo commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

You actually had this one first! You opened it on Sep 14 and we ended up landing the same fix days later without spotting your PR, which is on us. Closing since main has it now, but the credit is yours. Thank you for tracking it down :)

@teamleaderleo

Copy link
Copy Markdown
Collaborator

@ejc3 one more note, since these deserve a proper thank you: a bunch of your Sep 14 fixes (the Space key layout crash, the sidebar drag recursion, the offscreen blur reset crash, the window route recursion, the digit shortcut test) got redone on main about a week later because we did not look at your PRs first. You found and fixed them before we did. That is on us, and we are going to check contributor PRs before starting on a bug from now on. Thank you for all of this, seriously!

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.

2 participants