Repository navigation
fix(desktop): retry text preparation when the grab bound expires - #248
Merged
Merged
Conversation
Under CPU contention the grabbed keymap phase can outlive the 250 ms grab bound, so desktop_type failed closed. Keep the bound and retry the grabbed phase up to three times on a fresh connection, with a short gap, inside the existing preparation budget. Each failed wire closes first, and each retry rereads the live keymap. Only a grab-bound expiry retries; deterministic refusals, protocol faults and a dead target still fail at once. Refs #222
This was referenced Oct 5, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under CPU contention, the grabbed phase of text preparation can outlive the 250 ms grab bound, so
desktop_typefails closed with "Desktop text preparation failed; no text was sent". This change keeps the bound and retries the grabbed phase.prepareTextnow runs the grabbed phase up to 3 times, each time on a fresh connection. The steps are hello, XKB setup, grab, keymap read, planning and verification. Each failed wire closes first, which drops the grab, so two connections or grabs never overlap. A 100 ms gap separates attempts, and the existing 3 s preparation budget and the caller's deadline bound every attempt. Only a grab-bound expiry retries.X11Wire.grabExpiredis true only when the wire's first failure was its own grab deadline afterboundGrab. Capacity exhaustion, malformed replies, socket loss, a dead target and verification failures still fail at once. A retry reads the live keymap again, so bindings left by a failed attempt count as available.X11_GRAB_MS,X11_SETUP_MSand the error text are unchanged.This is a partial fix. The retry helps when contention sits near the bound but not under heavy sustained load. The main cost while the server is grabbed is the target liveness check:
check()reads/proc/<pid>/statabout 1,500 times during planning. Throttling that check would change a safety check, so it is left for a separate decision on #222.QA pass: the real
desktop_typepath was driven throughdesktop-input-captures-live.test.tsunder load (table below). No visual surface changed.x11-anchor.test.tsx11-anchor.test.tsx11-anchor.test.tsx11-anchor.test.tsdesktop-input-captures-live.test.ts, vitest and 10 busy loops on one CPUbun run test:coverage--base origin/mainRefs #222