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:
1 parent
23eddb42b9
commit
c03b8cdbcf
5 files changed
+158
-40
No files matched your search
@@ -88,16 +88,21 @@ No packet is interpreted here.
|
||||
dial state and grants a fresh 30 s budget, so a slot edited after the
|
||||
budget expired is actually dialled.
|
||||
- **Ticks**: the channel runs one 100 ms `DispatchSourceTimer` that
|
||||
calls `Session.tick(now:userActive:)` on every connection (the app
|
||||
reports input via `noteUserActivity()`, which is our
|
||||
`Event.RealInputEventCount++`, `InputHook.cs:223, 345`; `userActive` is
|
||||
then "the counter moved since the previous heartbeat", the test
|
||||
`SendAwakeBeat` makes and re-records every time it runs
|
||||
(`Common.cs:545-558`) — not a sliding window around `now`), drains
|
||||
calls `Session.tick(now:inputEventCount:)` on every connection, drains
|
||||
outboxes and events, and detects the C2 "30 s silence while we are
|
||||
sending input"
|
||||
stall: if the connection the sink marked as `controlled` receives
|
||||
nothing for 30 s while packets are being forwarded to it, close it.
|
||||
sending input" stall: if the connection the sink marked as `controlled`
|
||||
receives nothing for 30 s while packets are being forwarded to it,
|
||||
close it.
|
||||
- **The channel counts input; it does not judge it.**
|
||||
`noteUserActivity()` is our `Event.RealInputEventCount++`
|
||||
(`Event.cs:51-55`, `InputHook.cs:223, 345`) and the tick passes the raw
|
||||
counter to every session unchanged. The `Awake`-or-`Heartbeat` test
|
||||
(`lastRealInputEventCount != Event.RealInputEventCount`, re-recorded on
|
||||
the way out — `SendAwakeBeat`, `Common.cs:545-559`) lives in `Session`,
|
||||
because on Windows the beat *is* the send and each of our sessions
|
||||
schedules its own beat. A boundary held here would be out of phase with
|
||||
every connection's heartbeat instant and could report `Heartbeat` for
|
||||
input that postdates that connection's own previous beat.
|
||||
- **`ChannelConfig`** (contracts C4) carries everything: local name,
|
||||
local id, port, security key, matrix names, `Name2IP` text,
|
||||
`sameSubnetOnly`, `validateRemoteIP`, `blockScreenSaver`.
|
||||
@@ -124,7 +129,12 @@ No packet is interpreted here.
|
||||
- `session-matrix`: `Session`, `SessionConfig`, `SessionEvent`,
|
||||
`SocketStatus`, `InvalidKeyReason`, `PacketSequencer`, `ReplayFilter`.
|
||||
|
||||
Nothing in `MWBCore` was changed by this lane.
|
||||
One `MWBCore` change was made by this lane, with the lead's authorisation
|
||||
(rework round 2): `Session.tick(now:userActive:)` became
|
||||
`Session.tick(now:inputEventCount:)`, moving `SendAwakeBeat`'s counter
|
||||
comparison into the session that owns the heartbeat instant
|
||||
(`Common.cs:542-559`). The contract is written up in the session-matrix
|
||||
README's Handshakes section; nothing else in `MWBCore` was touched.
|
||||
|
||||
### Promised (to app-shell, clipboard)
|
||||
|
||||
@@ -228,6 +238,14 @@ Rules the consuming lanes must honour:
|
||||
switch, including back to local (`nil`). It is what arms the C2 30 s
|
||||
stall rule, and nothing else in the channel knows which peer is
|
||||
receiving input.
|
||||
3. **session-matrix**: the "Heartbeats follow the 100 ms timer cadence"
|
||||
bullet in that lane's Assumptions still says `Awake` is sent "if the
|
||||
user was active within the window" and cites `Common.cs:499-513`
|
||||
(`SendPackage`/`SendHeartBeat`). Both are wrong as of this rework: the
|
||||
test is a counter comparison against the session's own previous beat,
|
||||
and the citation is `Common.cs:545-559`. This lane's authorisation
|
||||
covered that README's Handshakes section only, so the Assumptions
|
||||
bullet is left for its owner.
|
||||
|
||||
### Answered from session-matrix
|
||||
|
||||
@@ -452,6 +470,72 @@ reason — and `TODO.md` needed no change (its §3 items were already
|
||||
ticked). No listener was opened, no input event posted and no pasteboard
|
||||
touched during this rework.
|
||||
|
||||
### 2026-09-16 — dev (Opus), rework round 2 after QA verdict REWORK
|
||||
|
||||
One finding: the channel-global `lastBeatAt` / `beatInputEventCount` reset
|
||||
was not synchronised with any connection's own 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 `BlockScreenSaver` mechanism, default on.
|
||||
QA is right, and right about the cause: Windows's beat *is* the send, one
|
||||
`SendAwakeBeat()` call for every socket at once (`Common.cs:545-559`,
|
||||
`frmScreen.cs:565-575`), whereas our sessions each schedule their own
|
||||
heartbeat from their own handshake-completion time
|
||||
(`Session.swift` `start(now:)` / `tick`). A sampling boundary held by the
|
||||
channel is therefore out of phase with every one of them by construction.
|
||||
The previous entry's claim that the channel's boundary "is the one global
|
||||
beat Windows runs for every socket at once" is withdrawn.
|
||||
|
||||
The fix puts Windows's pair of statics where Windows's beat is — at the
|
||||
send:
|
||||
|
||||
1. **`Session` owns the comparison now.**
|
||||
`Session.tick(now:userActive:)` became
|
||||
`Session.tick(now:inputEventCount:)`, taking the raw process-wide
|
||||
real-input counter (`Event.RealInputEventCount`, `Event.cs:51-55`,
|
||||
bumped by the hooks at `InputHook.cs:223, 345`). A new private
|
||||
`beatInputEventCount` is `Common.lastRealInputEventCount`
|
||||
(`Common.cs:543`): the tick sends `.awake` iff `blockScreenSaver` is on
|
||||
**and** the counter differs from the value this session recorded at its
|
||||
own previous beat, and re-records it on both branches, which is exactly
|
||||
what `SendAwakeBeat` does at `Common.cs:547-548` and `:558`. Because
|
||||
the record now happens at the same instant as the send, the
|
||||
out-of-phase case QA constructed cannot arise: a click at `t=10` is
|
||||
still new to a connection whose own previous beat was at `t=0`,
|
||||
whenever between beats the channel happens to tick.
|
||||
`beatInputEventCount` starts at `0`, as the Windows static does, so the
|
||||
first beat of a session on a machine that has seen any input is an
|
||||
`Awake`; that errs towards keeping a peer awake, which is the safe
|
||||
direction for this mechanism.
|
||||
2. **`ControlChannel` no longer has a beat.** `lastBeatAt` and
|
||||
`beatInputEventCount` are gone, along with the heartbeat-interval
|
||||
lookup that existed only to drive them. `noteUserActivity()` still just
|
||||
increments `inputEventCount` (`&+=`, so it wraps rather than traps),
|
||||
and `tick()` reads it once and hands the same value to every
|
||||
connection; `PeerConnection.tick(now:inputEventCount:)` passes it
|
||||
straight through. No `userActive`-shaped name survives anywhere in
|
||||
`Sources` (grep clean), so there is nothing left to reintroduce a
|
||||
window against.
|
||||
|
||||
Scope: this touched `Sources/MWBCore/Session.swift`, which belongs to
|
||||
session-matrix — the lead authorised that one file plus that lane's
|
||||
Handshakes section for this fix, because the finding cannot be answered on
|
||||
the channel side at all (the channel does not and should not know when a
|
||||
session beats). `docs/features/session-matrix/README.md` now carries the
|
||||
new signature in its Promised block and a rule spelling out that the
|
||||
argument is a raw counter and why a caller must not pre-compute the
|
||||
verdict. A stale Assumptions bullet in that same README (a "window" and
|
||||
the `Common.cs:499-513` citation) is outside the authorisation and is
|
||||
filed as open request 3 instead. `docs/protocol.md` §3.3 already describes
|
||||
the rule correctly (`Common.cs:542-559`, corrected in the previous round)
|
||||
and needed no change; `TODO.md` had nothing to tick.
|
||||
|
||||
Verification: `xcrun swift-format format -i --recursive Sources
|
||||
Package.swift` is a no-op, and `tools/guard.sh -m 8 -t 1800 --
|
||||
tools/gates.sh` is green (lint `--strict`, the `MWBCore` layering check,
|
||||
`swift build -Xswiftc -warnings-as-errors`); neither guard limit was hit.
|
||||
No listener was opened, no `CGEvent` posted and no pasteboard touched.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-09-16 — QA (Sonnet)
|
||||
|
||||
Reference in new issue
Block a user