control-channel: the Awake test moves into Session, where the beat is

Round-2 QA finding: the channel reset beatInputEventCount on its own
clock, out of phase with every connection's heartbeat instant, so a
session could send Heartbeat (20) where Windows sends Awake (21) — and
Awake is what drives the peer's Common.HumanBeingDetected()
(Receiver.cs:245-248), the default-on BlockScreenSaver mechanism.

Windows's beat is the send: SendAwakeBeat() compares
lastRealInputEventCount against Event.RealInputEventCount and re-records
it in the same call (Common.cs:542-559). So the comparison belongs at the
send. Session.tick(now:userActive:) becomes
Session.tick(now:inputEventCount:), taking the raw process-wide counter
(Event.cs:51-55, InputHook.cs:223, 345) and keeping its own
beatInputEventCount — Common.lastRealInputEventCount, Common.cs:543 —
recorded on both branches (:558).

ControlChannel loses lastBeatAt and beatInputEventCount entirely;
noteUserActivity() only increments the counter and tick() hands the same
value to every connection. No userActive-shaped name is left in Sources.

Sources/MWBCore/Session.swift is session-matrix's file, edited for this
fix with the lead's authorisation, as is that lane's Handshakes section.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 01:57:03 -07:00
1 parent 23eddb42b9
commit c03b8cdbcf
5 files changed
+158 -40

No files matched your search

+18 -1
View File
@@ -168,7 +168,7 @@ public final class Session { // not Sendable: one per connecti
public func feed(_ plaintext: Data) // 32-then-32 reassembly inside
public func noteReceiveError(bytesReceived: Int) // a 0-byte / short read
public func report(_ new: SocketStatus) // .resolving, .sendError, …
public func tick(now: TimeInterval, userActive: Bool)
public func tick(now: TimeInterval, inputEventCount: UInt64)
public func forward(_ packet: Packet) // app-stamped: Src + framing only
public func probe() // Hi
public func sayGoodbye() // ByeBye
@@ -338,6 +338,23 @@ Rules the consuming lanes must honour:
moves unconditionally will jerk the local cursor to the top of the
screen every time control comes home — on every `ByeBye` and every peer
disconnect (`Common.cs:622-625`).
- **`tick(now:inputEventCount:)` takes the raw process-wide real-input
counter, not a verdict.** `inputEventCount` is our
`Event.RealInputEventCount` (`Event.cs:51-55`, bumped by the hooks at
`InputHook.cs:223, 345`): the caller increments it on every real input
event and hands the *same* value to every session on a tick. Each
`Session` remembers the value it saw at its own previous beat and sends
`Awake (21)` instead of `Heartbeat (20)` iff the counter moved since then
and `blockScreenSaver` is on, re-recording it either way
(`SendAwakeBeat`, `Common.cs:545-559`). A caller must not pre-compute
that comparison on a clock of its own: sessions beat on independent
schedules (`nextHeartbeat` is seeded from each connection's own
`start(now:)`), so a shared boundary in the caller is generally out of
phase with a connection's beat and can report `Heartbeat` for input that
postdates *that* connection's previous beat — which silently disables the
peer's `BlockScreenSaver` (`Receiver.cs:245-248` →
`Common.HumanBeingDetected`). Signature changed 2026-09-16, requested by
control-channel; it was `tick(now:userActive:)`.
- **`Matrix.live(connectedNames:)` must be given the local machine's own
name**, because the Windows `IsConnectedTo` answers yes for it without a
socket. `Switcher.crossing` adds it; a direct caller must too.