control-channel: round-2 QA — findings 1/2 fixed, new heartbeat-phase finding
Verified the rework against SocketStuff.cs, Common.cs, Event.cs and InputHook.cs: finding 1 (Resolver two-group control flow) and finding 2 (id-collision gated to outbound) are both correctly fixed and cited, and the literal ask for finding 3 (counter compare, not sliding window) is met. But reading how ControlChannel's userActive is actually consumed by Session.tick (Sources/MWBCore/Session.swift) turned up a new problem: the channel's own beat-reset clock (ControlChannel.swift:457-471) is not synchronized with any connection's actual heartbeat send, which is decided independently by each Session's own nextHeartbeat. A connection can read userActive == false at its own send instant even though real input happened since its own previous heartbeat, silently downgrading Awake to Heartbeat for that peer — in the default (blockScreenSaver = true) configuration. Documented with a concrete timeline; verdict REWORK. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
1 parent
fa9d914c91
commit
23eddb42b9
1 file changed
+125
@@ -571,4 +571,129 @@ Findings:
|
||||
on the approximation next time §3.3 or this file is touched; not
|
||||
blocking on its own.
|
||||
|
||||
### 2026-09-16 — QA (Sonnet), round 2
|
||||
|
||||
Read the rework Work-log entry, then `git diff 09ca990..HEAD` and
|
||||
`git log --oneline 09ca990..HEAD` (five commits). Checked, in order:
|
||||
`tools/guard.sh -m 8 -t 600 -- tools/gates.sh`; finding 1 against
|
||||
`SocketStuff.cs:920-950, 1030-1046`; finding 2 against `:1975-2005`; finding
|
||||
3's citations against `Common.cs:540-562, 605-620, 910-935`, `Event.cs:45-60`,
|
||||
`InputHook.cs:218-230, 340-350`, `frmScreen.cs:560-578`; the two corrected
|
||||
citations; then read `ChannelConfig.swift`, `ControlChannel.swift`,
|
||||
`PeerConnection.swift`, `Resolver.swift` top to bottom for CLAUDE.md
|
||||
compliance, and, because finding 3 is about a liveness signal that reaches
|
||||
across the `MWBNet`/`MWBCore` boundary, read `Sources/MWBCore/Session.swift`'s
|
||||
`start(now:)` and `tick(now:userActive:)` to see how the channel's
|
||||
`userActive` is actually consumed.
|
||||
|
||||
- `tools/guard.sh -m 8 -t 600 -- tools/gates.sh`: green (lint --strict,
|
||||
MWBCore layering, warnings-as-errors build). Neither limit was hit.
|
||||
- **Finding 1 — fixed, matches Windows.** `Resolver.addresses`
|
||||
(`Resolver.swift:33-47`) now checks the mapped group alone
|
||||
(`!mapped.isEmpty, config.sameSubnetOnly, !isSameSubnet(mapped)`) and
|
||||
returns `[]` before `lookup(name)` is ever called, reproducing
|
||||
`SocketStuff.cs:926-937`'s `return` that skips `Dns.GetHostEntry` at `:950`
|
||||
entirely. The DNS group is then resolved, reverse-validated, and gets its
|
||||
own independent same-subnet check that on failure zeroes only `resolved`
|
||||
(`:1035-1044`), so a rejected DNS group no longer suppresses an
|
||||
already-accepted mapped group. `CheckForSameSubNet` itself returns `true`
|
||||
whenever `!Setting.Values.SameSubNetOnly` or either side has no IPv4
|
||||
address (`SocketStuff.cs:1069-1085`), which the Swift gates (`!mapped/
|
||||
resolved.isEmpty, config.sameSubnetOnly`) and `isSameSubnet`'s own
|
||||
empty-array short-circuits (`Resolver.swift:142, 144`) reproduce. Both QA
|
||||
scenarios from round 1 now dial exactly what Windows dials. `docs/protocol.md`
|
||||
§10.3 note 6 states the two different failure modes; the citations
|
||||
(`:928-944, 950`, `:989-1044`, `:934-937`, `:941, 1037-1040`) all check out
|
||||
against the reference file.
|
||||
- **Finding 2 — fixed, matches Windows.** `ControlChannel.accept(_:name:id:)`
|
||||
(`ControlChannel.swift:377-394`) now runs the id-collision check and the
|
||||
keep-the-first-client check as two branches of one `if peer.isOutbound`
|
||||
block, reproducing `UpdateTcpSockets`'s `status == Connected && tcp.IsClient`
|
||||
gate (`SocketStuff.cs:1980-1981`) around both the id compare (`:1984-1992`)
|
||||
and the dedup (`:1993-1997`). An inbound peer announcing our id now falls
|
||||
through to `dialers[name] = nil; sink.channel(...)` untouched, same as
|
||||
Windows silently accepting it. `docs/protocol.md` §10.3 note 3 states the
|
||||
client-only gate and cross-references note 4; the `DisconnectReason
|
||||
.idCollision` and `channelDetectedIDCollision` doc comments
|
||||
(`ChannelConfig.swift:121-123, 186-189`) say the same. Matches.
|
||||
- **Finding 3, the literal ask — fixed.** `ControlChannel.tick()`
|
||||
(`:457-471`) now compares `inputEventCount != beatInputEventCount`, two
|
||||
counters bumped by `noteUserActivity()` (`:201-203`, our
|
||||
`Event.RealInputEventCount++`) and re-snapshotted on a periodic boundary —
|
||||
a counter compare, not a sliding window, which is what was asked for.
|
||||
`docs/protocol.md` §3.3's citation is now `Common.cs:542-559` (confirmed:
|
||||
`SendAwakeBeat` itself, `lastRealInputEventCount`/`lastInputEventCount`
|
||||
fields included at `542-543`, function body `545-559`) with
|
||||
`Common.cs:547-548` for the `BlockScreenSaver`/`IsMyDesktopActive`/
|
||||
logon-desktop conditions — both check out exactly against
|
||||
`App/Core/Common.cs`. `Event.cs:51-55` (`RealInputEventCount` property) and
|
||||
`InputHook.cs:223, 345` (`Event.RealInputEventCount++` in the mouse and
|
||||
keyboard hooks) also check out.
|
||||
- **Corrected citations — both right.** `Common.SendByeBye` is
|
||||
`Common.cs:611-615` (confirmed exactly: `internal static void
|
||||
SendByeBye()` through the closing brace). `SkSend`'s stamp is
|
||||
`Common.cs:916` (`data.Id = Interlocked.Increment(...)`) and the fan-out
|
||||
loop through the matrix test is `:916-930`, ending at the `sk.TcpSend(t,
|
||||
data)` call — the `ChannelConfig.swift:87` doc comment's narrower
|
||||
`:922-930` for "the `Des == ID.ALL` matrix test" is the `foreach`-through-
|
||||
`TcpSend` sub-range and is consistent with it.
|
||||
- Compliance pass: no force-unwrap, `try!`, `fatalError` or `precondition` in
|
||||
any of the four files (checked with a grep for bare `!`/`try!`/
|
||||
`fatalError`/`precondition(` and manually cleared every hit — all are `!=`,
|
||||
`guard !x`, or `!collection.contains`, none are force-unwraps); no
|
||||
`print`/`Logger`/`os_log`/`NSLog` anywhere in `MWBNet`. File sizes
|
||||
(191/535/356/235) match the work log exactly and stay inside CLAUDE.md's
|
||||
targets; `tick()` (15 lines), `accept(_:name:id:)` (18 lines) and
|
||||
`Resolver.addresses` (15 lines) are all well inside 10–50.
|
||||
|
||||
**New finding — finding 3's fix is incomplete: the channel's beat boundary
|
||||
that resets `beatInputEventCount` is not the moment any connection actually
|
||||
sends its heartbeat, so a connection can report `Heartbeat` when real input
|
||||
happened since *its own* previous heartbeat.** `ControlChannel.tick()`
|
||||
(`ControlChannel.swift:457-471`) resets `beatInputEventCount` on the
|
||||
channel's own clock: `lastBeatAt` starts at `0` (`:61`) and the boundary
|
||||
fires every time `now - lastBeatAt >= interval` on the channel's 100 ms
|
||||
timer, independent of any connection. But no connection's heartbeat is sent
|
||||
on that clock — each `PeerConnection`'s `Session` decides independently,
|
||||
via its own `nextHeartbeat` field, set to `now + heartbeatInterval` in
|
||||
`start(now:)` (`Sources/MWBCore/Session.swift:167`, `now` there being *that
|
||||
connection's* handshake-completion time) and rescheduled the same way from
|
||||
its own fire time in `tick(now:userActive:)`
|
||||
(`Session.swift:218-223`). Nothing ties the two schedules together
|
||||
(`ControlChannel.swift:59-61` has no connection-keyed state at all), so a
|
||||
connection's own heartbeat instant is generally out of phase with the
|
||||
channel's reset instant. Concrete case: channel resets `beatInputEventCount`
|
||||
at `t=50`; a connection's own `nextHeartbeat` fires at `t=60` (phase set by
|
||||
when *that* connection's handshake completed, unrelated to `t=50`); the
|
||||
user's last click was at `t=10`, nothing since. At `t=50` the reset
|
||||
snapshots `beatInputEventCount` to a value that already includes the `t=10`
|
||||
click; at the connection's own send at `t=60`, `inputEventCount ==
|
||||
beatInputEventCount` (no *new* input since `t=50`), so `userActive` reads
|
||||
`false` and the connection sends `Heartbeat (20)` — even though the click at
|
||||
`t=10` postdates that connection's own previous heartbeat and Windows's
|
||||
single, truly-simultaneous `SendAwakeBeat()` call would have sent `Awake
|
||||
(21)` to every socket for it. Round 1's sliding-window version did not have
|
||||
this failure mode: `now - lastUserActivity <= interval`, evaluated fresh at
|
||||
whatever instant a connection ticked, had no shared reset to be out of phase
|
||||
with. `Awake` is not cosmetic: on the peer it drives
|
||||
`Common.HumanBeingDetected()` (`Receiver.cs:245-248`), which is the
|
||||
mechanism the `BlockScreenSaver` feature (default **on** —
|
||||
`ChannelConfig.swift:59`, `blockScreenSaver: Bool = true`) depends on to
|
||||
keep a peer from screen-locking while this machine's user is active. The
|
||||
work log's claim that "the boundary is the channel's, which is the one
|
||||
global beat Windows's 100 ms timer runs for every socket at once"
|
||||
(entry 3, and the matching doc comment at `ControlChannel.swift:450-456`)
|
||||
overstates this: Windows's beat *is* the send, for every socket, in one call
|
||||
(`Common.cs:545-558`, `frmScreen.cs:565-575`); the channel's beat is a
|
||||
sampling boundary that no send is pinned to. Not a safety issue (invariants
|
||||
2–4 are untouched) and it self-corrects once any two beats in a row see
|
||||
continuous activity, but it is a real, default-on regression in exactly the
|
||||
mechanism this finding was reworked to fix, and it needs either a
|
||||
`Session`-side change (a `session-matrix` handshake — `Session` would have to
|
||||
report its own beat, or take the raw counter and do the compare itself) or a
|
||||
different `ControlChannel`-side scheme that doesn't rely on a channel-wide
|
||||
reset. Flagged, not fixed — outside "verify, don't redesign."
|
||||
|
||||
Verdict: REWORK
|
||||
|
||||
## Review
|
||||
Reference in new issue
Block a user