qa: control-channel QA log — gates green, two protocol findings, verdict REWORK

Verified gates, TODO ticks against SocketStuff.cs, C1-C4 compliance,
Sendable justification and no key/packet logging. Two undocumented
behavioural deviations from Windows found by line-by-line comparison:
Resolver.addresses merges the Name2IP/DNS same-subnet checks instead of
running them separately (and misses Windows's early return when the
Name2IP group fails its check), and ControlChannel detects machine-id
collision on inbound connections too where Windows gates that on
IsClient. A third, minor, doc-only note on the userActive heuristic.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
lucioandClaude Sonnet 5 committed 2026-09-16 01:37:08 -07:00
1 parent 4e4a6d745c
commit 09ca9906e8
1 file changed
+117
+117
View File
@@ -368,4 +368,121 @@ input event or pasteboard was touched):
## QA log
### 2026-09-16 — QA (Sonnet)
Checked, in order: `tools/gates.sh`; every Status/TODO tick against
`App/Class/SocketStuff.cs` (listeners, `UpdateTCPClients`, `Name2IP`, DNS,
subnet, connect, options, `MainTCPRoutine` I/O, failure budget,
dedup/collision), `TcpServer.cs`, `InitAndCleanup.cs:28-31`,
`frmScreen.cs:427-461`; all four changed files top to bottom for CLAUDE.md
compliance (size, layering, naming, force-unwraps, retain cycles); that
`MWBNet` logs nothing and interprets no packet.
- `tools/gates.sh`: green (`swift-format lint --strict`, MWBCore layering,
`swift build -Xswiftc -warnings-as-errors`). No `Tests/` target exists in
this repo (the user's rule, `TODO.md`/`docs/topo.md` history) so no
`swift test` gate applies; the work log's harnesses are not committed,
consistent with that rule.
- File-by-file read: no force-unwraps, `try!`, `fatalError` or
`precondition` in any of the four files; no `print`/`Logger`/`os_log`
calls anywhere in `MWBNet` (invariant 2 — nothing to leak key material or
packet contents even inadvertently); every closure captured across an
escaping boundary (`NWConnection`/`NWListener`/`NWPathMonitor`/
`DispatchSourceTimer`/`DispatchWorkItem` handlers in both
`PeerConnection` and `ControlChannel`) uses `[weak self]`, so no retain
cycle. File sizes (189/512/356/229) and every function body are inside
CLAUDE.md's targets. Confirmed `Session.forward` → `sendDirect` only
fills `Src` when unset and never touches `Id`
(`Sources/MWBCore/Session.swift:390-395`), so `forward(_:to:)` truly
never re-stamps a packet (C1). Confirmed the 48-byte `writer.header` is
enqueued before `session.start(now:)` in `becameReady()`
(`PeerConnection.swift:158-159`), and `receiveExactly` passes the real
`received.count` to `noteReceiveError(bytesReceived:)`
(`PeerConnection.swift:207-208`). Confirmed `@unchecked Sendable` on both
types: every stored property is touched only from `queue`/`peerQueue`
(which targets `queue`), except `statusStore`, which is its own
`OSAllocatedUnfairLock` — no handler found that touches state off the
channel queue.
- Two undocumented behavioural deviations from the Windows source turned
up from the line-by-line comparison; neither is mentioned in
`docs/protocol.md` §10.3, the README, or the work log's list of
deliberate deviations. Filed below.
- Verified deliberate, documented deviations are in fact what's shipped:
`Name2IpPolicyList` and the bad-IP cache are absent (`grep` clean), the
failure budget is keyed by address only and counts every `.invalidKey`
reason (`ControlChannel.swift:400-406`), Windows's app-quit-on-eleventh
is replaced with per-address blocking — all as the work log states.
Verdict: REWORK
Findings:
1. **`Resolver.addresses` merges the `Name2IP` and DNS address groups
before the same-subnet check, instead of checking each group
separately, and has no equivalent of Windows's early return when the
`Name2IP` group itself fails that check.**
`Sources/MWBNet/Resolver.swift:24-41` builds one `found` array from
`mappedAddresses` then `lookup`, and applies `isSameSubnet` once to the
union. Windows (`SocketStuff.cs:930-944`) runs `CheckForSameSubNet` on
the `Name2IP`-mapped addresses alone and, if it fails, `return`s from
`StartNewTcpClient` **before `Dns.GetHostEntry` is ever called** —
skipping DNS resolution for that round entirely — then separately runs
`CheckForSameSubNet` again on the DNS-resolved group
(`:1035-1044`). Net effect with `sameSubnetOnly` on and a `Name2IP`
mapping configured: (a) a `Name2IP` address outside the local subnet
but a DNS address inside it — Windows dials nothing for that name this
round (the early return skips DNS too); the port dials the DNS
address. (b) A `Name2IP` address inside the subnet but a DNS address
outside it — Windows dials only the `Name2IP` address; the port's
single union check passes (because *some* address in the union
matches) and dials both, including the out-of-subnet DNS address.
`docs/protocol.md` §10.3 note 6 documents the reverse-lookup-filter
half of this same code region but not the subnet-check-per-group
split or the early return. Both `sameSubnetOnly` and `Name2IP` are
off/empty by default, so this needs a live peer with both configured
to reach.
2. **Machine-id collision is detected on inbound (server) connections
too; Windows only detects it on outbound (client) sockets.**
`Sources/MWBNet/ControlChannel.swift:367-372` (`accept(_:name:id:)`)
runs `if id == config.localID { sink.channelDetectedIDCollision(...);
closeAll(.idCollision); return }` for every connection that completes
its handshake, regardless of `peer.isOutbound`. On Windows,
`UpdateTcpSockets`'s entire collision-and-dedup block is gated by
`status == SocketStatus.Connected && tcp.IsClient`
(`SocketStuff.cs:1981`) — the id check at `:1985` never runs for a
server-accepted socket. The port gets the *dedup* half of that same
guard right two lines below (`peer.isOutbound` on the
`duplicateClient` check, `ControlChannel.swift:375`) but drops the
guard for the collision half. `docs/protocol.md` §10.3 note 3
describes the force-close-everything behaviour but not the
client-only gate, so this reads as faithfully ported when it isn't.
Practical effect: a Mac can force-close every connection and
regenerate its machine id reacting to a collision reported over an
*inbound* connection, a case real Windows silently tolerates — not
unsafe (invariant 3 is still satisfied, this only affects other
machines), but an undocumented behavioural difference invariant 1
requires be either matched or explicitly justified.
3. **(Minor, doc-only) The `userActive` heuristic in
`ControlChannel.tick` is a time-window proxy, not what
`SendAwakeBeat` actually checks, and the approximation isn't cited
anywhere.** `ControlChannel.swift:441-442` computes `userActive =
lastUserActivity > 0 && now - lastUserActivity <= interval` (the
heartbeat interval itself, 60 s/300 s). Windows's `SendAwakeBeat`
(`Common.cs:545-558`) instead sends `Awake` when
`lastRealInputEventCount != Event.RealInputEventCount` — i.e. any new
real input since the *previous* heartbeat tick, not "within the last N
seconds of `now`" — plus `IsMyDesktopActive()` and
not-logon/not-screensaver-desktop checks this lane correctly leaves to
another lane. The two proxies agree in the steady state (continuous
activity or continuous idleness) and only diverge at the edges, so
this is low-impact, but note that `docs/protocol.md` §3.3's own
citation for this rule (`Common.cs:499-513, 662-676`) is stale — those
lines are `SendHeartBeat`/screen-capture code, not `SendAwakeBeat` —
which predates this lane and was inherited rather than checked against
source. Worth a one-line fix to protocol.md §3.3's citation and a note
on the approximation next time §3.3 or this file is touched; not
blocking on its own.
## Review