Skip to content

desktop: desktop_type fails closed under CPU contention because of the 250 ms grab bound #222

Closed

Description

@ElbertePlinio

Found while reproducing #217 for PR #221.

With vitest pinned to one CPU and 7 busy-loop burners on that core, desktop_type fails closed with "Desktop text preparation failed; no text was sent" in most runs. It failed in 8 of 8 runs on main and 9 of 10 runs with #221. The failure happens in prepareText while the X server is grabbed. X11Wire.check() throws once the grab deadline from boundGrab has passed. X11_GRAB_MS is 250 ms in packages/desktop-linux/src/x11-wire.ts.

When the bound was raised to 2500 ms locally, 6 of 6 loaded runs passed. Raising X11_SETUP_MS alone did not help.

The short bound is deliberate, because a held server grab freezes the display. CI has not shown this failure yet. A loaded runner could still hit it in desktop-input-captures-live.test.ts, and so could real agent use on a busy machine. We need to decide whether the bound should scale, whether preparation should retry before the grab, or whether the limit should stay and be documented.

  • Decide the intended desktop_type behavior under CPU contention
  • Implement or document that behavior
  • Add a check that covers it

Activity

  1. added
    bug
    on Oct 3, 2026
  2. ElbertePlinio commented on Oct 5, 2026

    @ElbertePlinio
    MemberAuthor

    PR #248 keeps the 250 ms grab bound and retries the grabbed preparation up to 3 times on a fresh connection, within the 3 s preparation budget. Only a grab-bound expiry retries. With vitest and 10 busy loops on one CPU, desktop-input-captures-live.test.ts passed 5 of 6 with the retry and 2 of 6 without it. With 15 busy loops it still fails closed in every run.

    The main cost while the server is grabbed is the target liveness check. X11Wire.check() reads /proc/<pid>/stat about 1,500 times during planning. The grabbed phase takes about 38 ms idle, 165 ms with 7 loops and over 250 ms with 15. Two options would cut it further. One is to throttle the liveness check, for example to once per reply or every few milliseconds. That weakens a safety check, so it needs an owner decision. The other is to read the keymap before the grab, then grab, re-read, change and verify. This issue stays open for that decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions