diff --git a/docs/features/session-matrix/README.md b/docs/features/session-matrix/README.md index a6bead5..30c166d 100644 --- a/docs/features/session-matrix/README.md +++ b/docs/features/session-matrix/README.md @@ -443,4 +443,113 @@ through one. ## QA log -## Review +### 2026-09-16 — QA (Sonnet) + +Process: `tools/gates.sh` (green — swift-format lint --strict, MWBCore +layering, `swift build -Xswiftc -warnings-as-errors`), then every +Status/TODO tick read against the cited Windows source +(`SocketStuff.cs` `MainTCPRoutine` 1261-1565, `Receiver.cs`, +`Common.cs`, `MachineStuff.cs`, `MachinePool.cs`/`MachinePoolHelpers.cs`, +`Event.cs`, `Helper.cs`, `frmScreen.cs`), then all seven files read +top to bottom for CLAUDE.md size/layering/naming/force-unwrap/dead-code +concerns, then a check that nothing logs key material or acts on a +packet before trust. + +Verified faithful, worth recording since they were the areas flagged +for special attention: the nonce-complement handshake and trust gate +(`Session.swift:159-169, 267-339` vs `SocketStuff.cs:1269-1480` — +`Handshake` always answered regardless of trust, `HandshakeAck` after +trust silently skipped, self-connection close); the untrusted-packet +give-back for `Mouse`/`Heartbeat`/`Heartbeat_ex` past 5 +(`Session.swift:303-313` vs `:1502-1521`); the 32-then-32 reassembly +including the invalid-is-64-bytes rule (`Session.swift:174-190`); the +dedup ring's four exemptions (`Sequencing.swift:76-82` vs +`Receiver.cs:58-61`); the one-row vs two-row neighbour search, +including the ascending/descending asymmetry between `MoveRight` and +`MoveLeft`, the "arm chosen before reachability is tested" two-row +quirk, and `MoveDown`'s wrap-overwrites-straight quirk +(`Matrix.swift:108-190` vs `MachineStuff.cs:288-673`, byte-for-byte +arm order checked); `LiveMachineMatrix` blanking in one-row mode only +(`Matrix.swift:94-99` vs `:935-945`); the four-case landing rectangle +rule and the per-direction opposite-edge landing offsets +(`Edge.swift:125-135` vs `MachineStuff.cs:385-421` and the identical +arms in `MoveRight`/`Left`/`Up`/`Down`); the square (not circular) +100 px corner block and the 100 ms debounce ordering +(`Edge.swift:82-100` vs `:203-234`); the relative-move and pixel +biases including the asymmetric `>`/`>=` bias tests +(`Coordinates.swift:109-150` vs `Event.cs:32-33`, `InputHook.cs:271-312`, +`Helper.cs:107-110`); `NextMachine`'s id-in-`WheelDelta` and 100 ms +rate limit (`Switching.swift:229-239` vs `Common.cs:516-539`); the +`Matrix` packet slot/flags encoding and the slot-4 commit rule +(`Matrix.swift:210-241` vs `MachineStuff.cs:952-1006`). No key material +or decrypted keystroke is logged anywhere in these seven files (grepped +for `log`/`Log`/`print`); `Session.deliver` is reached only from the +trusted branch, and nothing else in `Session`/`Switcher` synthesizes +input or touches a pasteboard (both are sans-I/O by construction). +`swift-format`, layering and file/function sizes are all within the +CLAUDE.md targets; no force-unwraps, `try!`, `fatalError` or +`precondition` in any of the seven files. + +Three findings, none touching wire bytes or the trust boundary itself: + +1. **The 10-untrusted-packets rule doesn't count read errors, unlike + Windows.** `SocketStuff.cs:1330-1338` gives a bad/short read its own + `errCount` (closes after 6), but that `Error`-typed package then + *also* falls through the `if (package.Type == PackageType.Handshake)` + check (false) into the untrusted `packageCount` branch + (`:1379-1521`, reached for any non-`Handshake` type including + `Error`) — so on Windows a run of malformed reads during handshake + also spends the same 10-packet budget as garbage packets, and can + trip `InvalidKey` (once `packageCount > 5`) or the full + "`>=10` ⇒ send 10 `Invalid`, close" path before 6 read errors + accumulate. `Session.noteReceiveError()` + (`Sources/MWBCore/Session.swift:192-199`) is wired to a separate + counter that never touches `countUntrusted`/`untrustedCount`, so the + port always closes a bad-read run via `.error` after 6, never via + `.invalidKey`, and never spends any of the 10-packet budget on it. + Not a trust-boundary or wire bug — the connection still closes either + way — but it is a real behavioural divergence in the exact rule the + brief called out for special attention. + +2. **`Switcher.learn` persists the pool on every heartbeat from an + already-known peer; Windows does not.** `AddToMachinePool` + (`MachineStuff.cs:712-745`) returns `machineInfo.Name` immediately + inside the `TryFindMachineByName` branch, *before* reaching + `MachineStuff.UpdateMachinePoolStringSetting()` (the call sits after + the whole if/else, reachable only from the "new machine" branch that + falls through). `Switching.swift:251-258` (`Switcher.learn`) returns + `[.persistMachinePool]` for the known-machine branch too, so the + port asks the app to write `MachinePool` to disk on every heartbeat + cadence tick from a peer it already knows (every 60 s or 300 s, per + connection), not just when a new machine is learned. Harmless + (idempotent, no wire effect) but extra I/O Windows doesn't do, and + worth a one-line fix (drop `.persistMachinePool` from that branch) or + a documented deviation. + +3. **`SwitchAction.parkCursor` doesn't carry what Windows needs to + decide whether to actually move the OS cursor.** `HideMouseCursor` + (`Common.cs:1482-1496`) only calls `SetCursorPos` when + `(desMachineID != Common.MachineID && desMachineID != ID.ALL) || + byHideMouseMessage`. `SwitchToMachine` (`MachineStuff.cs:1008-1028`) + calls `HideMouseCursor(false)` *after* setting + `Common.DesMachineID = id`, so on Windows the real cursor is parked + only when switching control to a **remote** machine — switching + control back to the local machine (exactly what + `ProcessByeByeMessage`, `Common.cs:622-625`, does by calling + `SwitchToMachine(MachineName.Trim())` when the controlling peer says + goodbye) leaves the local cursor alone. `Switcher.switchToMachine` + (`Switching.swift:189-203`) always appends + `.parkCursor(byHideMouseMessage: false)`, and neither the action's + payload nor its doc comment (`Switching.swift:31-34`) tells a + consumer it must additionally check `desMachineID != localID && + != ALL` before actually moving the OS cursor. A straightforward + `input-inject` implementation — built, per this README's stated + goal, "without reading the Windows source again" — would park the + real cursor at the primary screen's top-centre every time control + returns home (e.g. on every peer disconnect), which is a visible, + incorrect cursor jump for the local user. Recommend either adding a + `targetIsLocal`/`shouldMoveCursor` flag to the action, or spelling + out the gating condition in the doc comment and in a `control-channel` + "consumers must" rule alongside the existing ones in Handshakes. + +Verdict: REWORK