15 Commits
Author SHA1 Message Date
lucioandClaude Opus 5 8125cb1ede session-matrix: PacketSequencer is thread-safe (app-engine request 1)
Cross-lane edit, authorised by the lead. Contracts C1 gives the process
one sequencer and two callers: the Engine actor stamps application
packets, each `Session` stamps its own handshake, heartbeat, `Hi` and
`ByeBye` on the channel's queue (`Session.swift:402-403`). `value &+ 1`
with no synchronisation can lose an update and hand two packets the same
`Id`, which the peer's replay ring drops (`Receiver.cs:40-82`). The
counter now lives under an `NSLock` — Foundation only, so MWBCore's
layering holds — and the class is `@unchecked Sendable`, which is the
guarantee Windows gets from `Interlocked.Increment` (`Common.cs:916`).
`ReplayFilter` is unchanged: one queue touches it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-09-16 03:56:52 -07:00
lucioandClaude Fable 5.1 1c24c9f67c control-channel: close lane (lead review); brief: input-capture
Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-16 01:57:56 -07:00
lucioandClaude Opus 5 c03b8cdbcf 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]>
2026-09-16 01:57:03 -07:00
lucioandClaude Fable 5.1 5f9a18cf83 session-matrix: close lane (lead review, topo handshakes 3/4/6)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-16 01:09:13 -07:00
lucioandClaude Sonnet 5 43e5e35885 qa: session-matrix round-2 QA log (PASS) and a stale protocol.md citation
Verified the rework against the reference checkout at 3104d5c: read-error
counting now matches SocketStuff.cs:1330-1529/1531, Switcher.learn persists
only on a new machine (MachineStuff.cs:737/755), parkCursor carries the
HideMouseCursor gate (Common.cs:1488, MachineStuff.cs:1025), and contract
C1's forward(_:)-only stamping matches SkSend (Common.cs:901-935). Fixed a
trivially wrong citation in protocol.md §10.2 note 11 (Common.cs:914 ->
916, the actual PackageID increment line). tools/gates.sh green.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-16 01:07:10 -07:00
lucioandClaude Opus 5 f190157535 session-matrix: CLAUDE.md compliance pass and the rework work-log entry
Re-read all seven files: no force-unwrap, try!, fatalError or
precondition; longest file 422 lines (Session.swift), longest function 26
(countUntrusted); nothing logs. Corrected four SocketStuff.cs citations
that were off by one or two against the reference checkout (:1390->:1389,
:1441->:1439, the untrusted branch :1386-1500 -> :1387-1529).
`xcrun swift-format format -i --recursive Sources Package.swift` made no
further changes; tools/gates.sh green.

Work log gains a dated rework entry answering QA findings 1-3 and
contract C1 by number.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-09-16 01:02:10 -07:00
lucioandClaude Opus 5 9980c685e2 session-matrix: Session cannot stamp an application packet (contracts C1)
Session.send(_:) is gone as a public entry point. Application traffic gets
its Id once from the process-wide PacketSequencer and reaches each target
connection through forward(_:), which never re-stamps; the per-connection
stamp survives only as `private func originate(_:)` for the packets
Windows also sends per connection — the handshake pair, heartbeats, Hi and
ByeBye. Nothing outside the type can now sequence an application packet.

README Assumptions and Handshakes say this is API-enforced rather than a
convention. protocol.md gains §10.2 note 11: SkSend increments PackageID
once before the socket loop (Common.cs:914) and hands the same DATA to
every matching socket, which is exactly what makes the receiver's 50-entry
replay ring collapse a peer pair's duplicate delivery.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-09-16 01:00:39 -07:00
lucioandClaude Opus 5 9252158bbc session-matrix: parkCursor carries the HideMouseCursor gate
QA finding 3. HideMouseCursor moves the real cursor only when
(desMachineID != MachineID && desMachineID != ID.ALL) || byHideMouseMessage
(Common.cs:1488), and SwitchToMachine calls it after setting DesMachineID
(MachineStuff.cs:1025) — so control coming home parks nothing. The action
is now .parkCursor(destinationIsRemote:byHideMouseMessage:), both halves
of that gate pre-evaluated by Switcher (new .destinationIsRemote), so
input-inject can implement it without reading the Windows source. Spelled
out as a consumer rule in the README's Handshakes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-09-16 00:59:29 -07:00
lucioandClaude Opus 5 e0638de0b9 session-matrix: learn() persists only when a new machine is learned
QA finding 2. AddToMachinePool returns inside the TryFindMachineByName
branch (MachineStuff.cs:737), before the UpdateMachinePoolStringSetting()
at :755 — which is reachable only from the fall-through "new machine"
path. Switcher.learn was returning [.persistMachinePool] from the known
branch too, asking the app to write MachinePool to disk on every
heartbeat cadence tick from every already-known peer. It now returns [].

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-09-16 00:58:52 -07:00
lucioandClaude Opus 5 0e6ee77dc7 session-matrix: a failed read spends the untrusted budget, as on Windows
QA finding 1. TcpReceiveData does not signal a bad read out of band: it
rewrites the buffer's type byte to PackageType.Error (0 bytes) or
PackageType.Invalid (short read) (SocketStuff.cs:574-578, 588-593) and
MainTCPRoutine runs that package through the whole loop body — the
private errCount for the Error case (:1332-1364), then the same untrusted
counting as any garbage packet (:1370-1529). So a run of malformed reads
ends in .invalidKey, not .error, and the trusted branch's
`receivedCount > 0` guard (:1531) keeps a 0-byte read out of the receiver.

Session.noteReceiveError now takes the byte count and feeds a synthetic
.error/.invalid packet through the new receive(_:bytesReceived:), which
is the loop body; feed() goes through it too. Written up as protocol
§10.2 note 10 and in the README's Assumptions.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-09-16 00:58:29 -07:00
lucioandClaude Fable 5.1 08b243a29a contracts: sequencing, recovery, concurrency, shared constants, checkpoints
Written after an external review of the plan found cross-module
behaviour under-specified. TODO, topo, loop and the session-matrix
brief now reference docs/contracts.md.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-16 00:54:33 -07:00
lucioandClaude Sonnet 5 e588f1f71c session-matrix: QA log — gates green, three findings, verdict REWORK
Verified handshake/trust gate, dedup ring, one-row/two-row neighbour
search, matrix packet encoding, edge/landing geometry and the relative
and pixel biases against the Windows source; all faithful. Three
findings: the 10-untrusted-packets rule doesn't count read errors like
Windows does, Switcher.learn persists the pool on every known-peer
heartbeat, and SwitchAction.parkCursor doesn't carry enough information
for a future consumer to replicate HideMouseCursor's real-cursor-move
gating without rereading the Windows source.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
2026-09-16 00:52:25 -07:00
lucio 2997c88440 session-matrix: Session.forward for pre-sequenced broadcasts; doc counts 2026-09-16 00:42:52 -07:00
lucio 605a9753b0 session-matrix: README handshakes/status/work log, TODO section 2 2026-09-16 00:42:32 -07:00
lucio 55213cb9d8 brief: session-matrix 2026-09-16 00:22:33 -07:00