Skip to content

Host: keyboard layout read on the main thread; a call cut off mid-action is unknown (#244) - #248

Merged
iamnbutler merged 1 commit into
mainfrom
open-connection
Nov 12, 2026
Merged

iamnbutler merged 1 commit into
mainfrom
open-connection

Conversation

@iamnbutler

Copy link
Copy Markdown
Contributor

Part of #244: the "host closed the connection" report. The partial inventory part is discussed below.

Cause

The host crashed. ~/Library/Logs/DiagnosticReports on this Mac has three desktop-tools-app crashes: two from release 0.20.0 (2026-11-07) and one from the dev app (today). All three are an EXC_BREAKPOINT in libdispatch's dispatch_assert_queue, raised from HIToolbox TSMGetInputSourceProperty, called by Mac.systemState() → Mac.apps() (System.swift:63, tisString). systemState() read the keyboard layout through Text Input Sources off the main thread. Every other TIS read in native2 already runs on the main thread. The inventory that desktop_open returns reads it, so the host could crash after the open had already happened. The MCP server then reported only "The Desktop Tools host closed the connection." I hit this myself on the first call after approving the dev app.

Changes

  • System.swift: the keyboard layout is read on the main actor.
  • desktop-tools-mcp: when the host connection drops after a call was sent:
    • for an action, the result is now Outcome: unknown with retry_safety: unsafe, error HOST_CONNECTION_LOST, and advice to observe the target before acting again;
    • for a read, the error says nothing was changed and the read can be called again.

Checked

  • swift test --package-path native2 passes.
  • Live: I sent a desktop_click (Open Sheet on the sheet fixture) through the MCP server and killed the standalone host 150 ms later. The sheet opened, and the result was Outcome: unknown … HOST_CONNECTION_LOST. Before this change it was a plain error. A desktop_apps call sent after the drop got the read message.
  • I couldn't trigger the HIToolbox assertion on demand, since it fires only sometimes. The crash reports show the call path. The fix moves that read to the main thread, like every other TIS call.

Not reproduced: partial Xcode inventory

inventory_completeness: partial with "Accessibility window enrichment was incomplete" is reported when Accessibility gives up partway: a window's batched attribute read, its window number or the focused-window read returns an error other than "no value". That is likely while Xcode is busy distributing. I don't have an archive mid-distribution to reproduce it, so I left it alone. The listing already says it's partial honestly. #247 retries the follow-up observation once when the tree is incomplete, which covers the incomplete tree seen just after a sheet appears.

🤖 Generated with Claude Code

…-action is unknown (#244)

Mac.systemState(), which every desktop_apps inventory and the observation after
desktop_open read, called Text Input Sources off the main thread. HIToolbox traps on
a queue assertion there, and the host crashed mid-call; the crash reports show it in
the release app and the dev app. The agent saw only "The Desktop Tools host closed
the connection" although the open had happened. The MCP server now reports a
connection lost during an action as outcome unknown (HOST_CONNECTION_LOST,
retry_safety unsafe), and during a read as safe to call again.

Why: native2/Sources/DesktopMac/System.swift | Text Input Sources (TIS*) calls must run on the main thread: HIToolbox asserts its queue and traps the whole host otherwise, only sometimes, so it passes in tests
Why: native2/Sources/desktop-tools-mcp/main.swift | a connection that drops after an action was sent means the action may have run; report unknown, never a plain error an agent reads as nothing happened

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iamnbutler
iamnbutler merged commit 0297afb into main Nov 12, 2026
2 checks passed
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