Skip to content

fix(desktop): read and plan the keymap before the text grab - #257

Merged
ElbertePlinio merged 7 commits into
mainfrom
fix/222-keymap-before-grab
Oct 6, 2026
Merged

ElbertePlinio merged 7 commits into
mainfrom
fix/222-keymap-before-grab

Conversation

@ElbertePlinio

@ElbertePlinio ElbertePlinio commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

desktop_type now reads and plans the keymap before it grabs the X server, so CPU contention no longer spends the 250 ms grab bound on parsing.

Under the grab it rereads the live keymap. It reuses the pre-grab plan only when the modifier, core and XKB replies are byte-identical apart from the sequence number and the keycode range matches. Any other read is planned again under the grab. Changes, the verification read, ungrab and sync all stay under the grab. Every liveness check, the 250 ms bound, the 3-attempt retry from #248, the fail-closed error and the rule that bindings are never restored are unchanged. A test clock fixture now uses whole milliseconds, because a fractional start made the budget assertions fail at random.

Closes #222

Requirement Verification Scenario Result Evidence
Decide the behavior under CPU contention Owner decision Keep the bound and liveness checks, plan before the grab Implemented issue comment
Implement that behavior Automated tests plus measurement Grabbed phase median, idle 21.7/27.5 ms before, 3.6/11.8 ms after (ascii/bind) 222/grab-phase-table.txt
Plan reuse only for an identical grabbed read Automated test plus mutation Unchanged map, changed core map, changed modifier map Reuse and re-plan tests pass; wrong reuse, missing reuse and a sequence-byte comparison each fail tests 222/mutations.log
Fail closed on every failure path Automated tests Capacity, malformed, dead target, reply faults in both the free and the grabbed read Pass 222/final-alone-*.log
Typing under load (QA) Live MCP test desktop-input-captures-live.test.ts 15 busy loops on one pinned CPU, paired with origin/main origin/main 0/6, branch 3/6 and 5/6; failures fail closed 222/captures-paired.log, captures-summary.log
Preparation under heavy load Paired harness 15 busy loops origin/main 0/20, branch 19/20 222/rt-*.json
Lint, typecheck, PickCheck, full suite Automated Final head Pass, 2901 tests 222/coverage-3.log

Evidence lives in ~/Artifacts/pickforge-kickoff-2026-10-06/ on the dev host. Under the heaviest load, the first grab can still expire. Further cuts would need pipelined keymap requests or reuse of the first free read across retries. Those options are filed as #266.

Parse the keymap and plan bindings before the server grab. Under the
grab, reread the live map and reuse the plan only when every reply is
byte-identical apart from its sequence number; otherwise plan again
under the grab. Changes, verification and every liveness check stay
under the grab, and X11_GRAB_MS stays at 250 ms.

Refs #222
A fractional performance.now() start made now + 3000 - now round to
2999.999... for some start values, so floor() returned 2999 and the
budget assertions failed at random. The new module mock shifted the
start time into that range more often.
@ElbertePlinio
ElbertePlinio merged commit adbf4a3 into main Oct 6, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the fix/222-keymap-before-grab branch October 6, 2026 14:31
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.

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

1 participant