qa: input-capture QA log — gates green, four findings, verdict REWORK

Verified every Status/TODO tick against InputHook.cs/Event.cs/VK.cs/WM.cs/
WinAPI.cs/Common.cs and docs/protocol.md §10.4, docs/contracts.md C2-C4.
Findings: EventTap.thread unguarded across start()/stop() despite the
class's own Sendable-safety claim; screens.layout fetched unconditionally
on the hot local-mouse-move path; README's lock-count claim undercounts
actual acquisitions; a disabled-by-default Switch2AllPC swallow quirk vs
Windows. No typos fixed (all findings need real changes).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
lucioandClaude Sonnet 5 committed 2026-09-16 02:31:07 -07:00
1 parent 84aa59a512
commit 2aa08946ad
1 file changed
+100
+100
View File
@@ -425,4 +425,104 @@ position rather than by label.
## QA log
### 2026-09-16 — QA (Sonnet)
`tools/guard.sh -m 8 -t 600 -- tools/gates.sh` green (swift-format lint
--strict, MWBCore layering, `swift build -Xswiftc -warnings-as-errors`). No
event tap was created, no `CGEvent` posted, no cursor warped, no permission
requested or preflighted — build/read-only per instruction.
Checked every Status/TODO tick against its Windows source
(`Class/InputHook.cs` whole file, `Core/Event.cs`, `Core/VK.cs`, `Core/WM.cs`,
`Core/WinAPI.cs:70-184`, `Core/Common.cs:1482-1496`,
`Class/EasyMouseOption.cs`, `MouseWithoutBordersProperties.cs`) and against
docs/protocol.md §4.3–§4.5, §5, §10.4 and docs/contracts.md C2–C4:
- Spot-checked 30+ `KeyMap` entries against `VK.cs` and the standard Win32 VK
list (letters, digits, punctuation/OEM keys, F1–F20, keypad, volume, all
eight modifiers, Insert/Delete/Help, Num Lock) — all correct, including the
ones VK.cs itself doesn't define (OEM_4/5/6/7/102, F13–F20, volume), which
are real Win32 constants InputSimulation.cs would still accept.
- Hotkey defaults (`HotkeyConfig.init`) cross-checked against
`MouseWithoutBordersProperties.cs:33-39,188,192` and
`HotkeySettings(win,ctrl,alt,shift,code)` at `HotkeySettings.cs:51-59` —
Win+Ctrl+Alt (no Shift) for lock/reconnect/toggle-EasyMouse, `0x70` for
switch-machine, Switch2AllPC disabled — all match.
- Modifier device masks, `rightControlMask 0x2000`, Caps Lock toggle,
wheel×120 accumulation and sign, absolute-move formula
(`Event.cs:112-113`), Easy Mouse gating (`Event.cs:71-79`,
`InputHook.cs:467-473`), the Shift/⌘ veto scoped to the switch-machine
family only (`InputHook.cs:604-610` vs `Common.HotkeyMatched`,
`Common.cs:127-129`), the 500 ms double-press lock rule, `Cursor.park`'s
`HideMouseCursor` gate (`Common.cs:1482-1496,1488`), and `Screens`' corner
half-open convention vs `MonitorEnumProc` (`WinAPI.cs:70-113`) — all
reproduce the cited Windows behaviour. Nothing in the nine files logs a
keystroke, a VK, or a modifier state.
Four findings, none of them wire/protocol breaks — all host-side Mac
code-quality issues, listed most to least severe:
1. **`EventTap.thread` is unguarded shared state, and the class's own safety
comment says otherwise.** `EventTap.swift:82` declares
`private var thread: Thread?`, read at `:112` and written at `:118, :122`
(both in `start()`) and `:133` (in `stop()`) — none of it behind a lock.
`stop()` is documented "Safe to call from any thread" (`:127`), which is
exactly the shape of the contracts-C2 crash/signal-handler recovery row
("best effort: re-associate the cursor and release keys" — the handler
would call `EventTap.stop()`/`Cursor.restoreEverything()` off the tap
thread), and the class-level comment at `:60-67` asserts "every field that
crosses a thread boundary is behind a lock" — true of `runLoopStorage`
(guarded by `runLoopLock`) but not of `thread`, which sits right next to
it and isn't. A `start()` racing a signal-handler `stop()` is a genuine,
if narrow, data race on a plain `var`, not proven safe by anything in
this file. Fix: fold `thread` into `runLoopLock` (or its own lock) the
same way `runLoopStorage` already is.
2. **`screens.layout` is fetched unconditionally on the single hottest path
through the callback, for a value the majority case never reads.**
`EventTap.swift:346` calls `screens.layout` (a locked read of `Screens`'
`OSAllocatedUnfairLock<ScreenLayout>`) before branching on
`snapshot.destination.isRemote`; `layout` is only actually used inside
that `isRemote` branch (`:352-353`). The `else` (local) branch
(`:361-367`) — which is what runs for essentially every mouse move on a
Mac that isn't currently controlling a peer, i.e. most of the time this
tap is live — never touches `layout`, so it pays for a lock acquisition
it throws away. `handleScroll` gets this right: it checks
`snapshot.destination.isRemote` at `:438` *before* reading
`screens.layout` at `:441`. Move the `handleMouse` read inside the
`isRemote` branch to match.
3. **The README's per-event lock-count claim doesn't match the code.**
`docs/features/input-capture/README.md:40` says "Three uncontended
`OSAllocatedUnfairLock` acquisitions per event at most (snapshot, virtual
cursor, counters)." A remote mouse-move event actually acquires:
`counters` (1), `RoutingState`'s box lock twice (`routing.read()` +
`routing.advanceVirtualCursor`), `Screens`' lock (finding 2), and
`CaptureQueue`'s ring lock once or twice (`.mouse` and, on a move,
`.edgeCandidate` are two separate `enqueue()` calls) — up to 6
acquisitions across 4 distinct lock objects, two of which (`Screens`,
`CaptureQueue`) the claim never mentions at all. Not a functional bug
(all four locks are uncontended, per-process, non-blocking), but it's a
concrete, checkable claim in a feature README that CLAUDE.md's own perf
rule ("Budget is measured, not asserted") says should be either accurate
or removed.
4. **A Windows quirk this port doesn't reproduce, reachable only with a
non-default `Switch2AllPCShortcut`.** `InputHook.ProcessHotKeys`
(`InputHook.cs:518-522`) never returns `false` for a matched
`HotKeySwitch2AllPC`, unlike every other hotkey branch — so on Windows,
if that hotkey is configured to something that doesn't *also* require
Ctrl+Alt, the key reaches the OS (`CallNextHookEx`) in addition to
toggling ALL-machines mode. `HotkeyMatcher.match` (`Hotkeys.swift:65-67`)
and `EventTap.handleKey` (`EventTap.swift:280-284`) always swallow a
matched hotkey. Unreachable today — `Switch2AllPCShortcut` ships disabled
(`Code=0`, `MouseWithoutBordersProperties.cs:30`) and
`Common.HotkeyMatched` requires `!hotkey.IsEmpty()`
(`Common.cs:127-129`) — so this only matters once app-shell exposes a
hotkey editor and a user picks a non-default, non-Ctrl+Alt combo for it.
Worth a one-line note in the Assumptions section so app-shell doesn't
have to rediscover it.
No typos or trivially-wrong comments found to fix directly; all four
findings need an actual code or prose change, so none were applied here.
Verdict: REWORK
## Review