app-engine: QA log — REWORK (settings 0600 gap, key-release parity, ByeBye-on-signal)

Reviewed against CLAUDE.md, contracts C1-C5, protocol §10.6 and the Windows
source. Gates green; one confirmed finding (Settings.save(to:) does not
reliably enforce 0600 via replaceItemAt on a pre-existing file, verified
empirically) and two plausible ones (releaseAll() parity across switch-to-
local paths; ByeBye not sent on SIGTERM/SIGINT/SIGHUP), filed with file:line
on both sides for the dev.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
lucioandClaude Sonnet 5 committed 2026-09-16 03:52:04 -07:00
1 parent bb873807b8
commit bd7be40186
1 file changed
+147
+147
View File
@@ -438,4 +438,151 @@ Rules the consuming lanes must honour:
## QA log
- **2026-09-16 (QA)** — reviewed against CLAUDE.md, `docs/contracts.md` C1–C5,
`docs/protocol.md` §10.6, and the Windows source (`Core/Receiver.cs`,
`Core/MachineStuff.cs:1007-1050`, `Core/Helper.cs`, `Class/InputHook.cs:539-658`,
`Form/frmScreen.cs:285-300, 425-461`, `Class/Setting.cs`,
`MouseWithoutBordersProperties.cs:165-206`, `MouseWithoutBordersSettings.cs`).
No test suite exists for this lane yet (`swift test` not run — none of the
gates call for it); build-only per CLAUDE.md invariant 5. The app itself was
never launched; only `.build/debug/mwb --version` and `--check-permissions`
were run (confirmed both create no settings file, log file or tap — checked
`~/Library/Application Support/mwb-mac/` and `~/Library/Logs/mwb-mac/` stay
absent after both).
*Gates.* `tools/gates.sh` green: `swift-format lint --strict` clean, `MWBCore`
layering clean, `swift build -Xswiftc -warnings-as-errors` clean.
*Verified clean.* Every Status/TODO tick has code behind it. C1 (single
`PacketSequencer`/`ReplayFilter`, ids stamped once in `Switcher`/`Engine.
stampAndForward`, `Session` re-stamps only its own connection packets) holds;
the open thread-safety request against session-matrix is correctly filed, not
silently worked around. C3's actor/routing-snapshot/queue shape matches, and
`swift build -warnings-as-errors` (Swift 6 strict concurrency) accepting the
file rules out illegal actor-isolation escapes; the only two `@unchecked
Sendable` types (`SettingsStore`, `LogFile`) are lock- or queue-disciplined
and justified in a doc comment, matching `EmergencyRelease`. No force-unwrap,
`try!`, `fatalError` or `precondition` in any changed file. No log call in
`Log.swift`/`Engine.swift`/`EngineActions.swift`/`Recovery.swift` takes a
`KeyboardData` or key string — grepped every `Log.*` call site by hand.
`Permissions.request()` has exactly one call site (`AppLifecycle.swift:271`,
the status-item click). C4's config mapping is complete: `ChannelConfig`,
`CaptureConfig`, `EdgeConfig` and `InjectorConfig` each have every field
populated from `Settings` in `EngineActions.swift`/`Engine.init`, matched
field-by-field against the struct definitions. Settings JSON matches
`MouseWithoutBordersProperties.cs:165-206` and `HotkeySettings.cs:121-136`
property-by-property (envelope, `{"value":…}` boxing, the bare-array
exception for `MachineMatrixString`, lower-case hotkey field names,
non-negative `MachineID`). Hostname validation (D7) matches the table exactly
and gates `Engine.start()`. Single instance (`flock`) runs before anything
else touches the tap or a socket.
*Findings.*
1. **[correctness/security, CONFIRMED] `Settings.save(to:)` does not
reliably enforce 0600 on a pre-existing file.**
`Sources/MWBCore/Settings.swift:437-438` calls
`FileManager.default.replaceItemAt(url, withItemAt: temp)` with no
options. `FileManager.replaceItemAt`'s documented default behaviour is to
preserve the *original* item's metadata (permissions included) onto the
replacement unless `.usingNewMetadataOnly` is passed — I confirmed this
empirically with a standalone Swift snippet (create a 0644 file, replace
it with a 0600 temp file via `replaceItemAt` with no options: the result
stays 0644). The first-ever write for a brand-new install goes through
the `moveItem` branch instead (no pre-existing destination), so a fresh
install does end up at 0600 and *stays* 0600 on every later `update()`,
because the file `replaceItemAt` is "preserving metadata from" is by then
already 0600. But README's own §Settings advertises copying
`settings.json` between a Mac and a PC as a supported way to share a
`SecurityKey` and matrix (D3) — a file arriving that way (scp, AirDrop, a
shared drive, restored from a backup) will generally not already be
0600, and every subsequent `SettingsStore.update()` (a matrix edit, a
pool update, `persistOnExit`, `replaceMachineID`, …) will silently keep
whatever permissive mode it arrived with, forever, because
`replaceItemAt` keeps re-propagating the old mode forward. The file
stores `SecurityKey` in the clear. Fix is one line:
`.usingNewMetadataOnly` on the `replaceItemAt` call, or an explicit
`setAttributes` on `url` after it.
Windows side: `Setting.cs` writes the file with no special ACL either,
but that is a difference worth having on our side, not a reason to drop
the 0600 promise this port's own README (`## Assumptions`, "Stored at
… mode 0600") makes.
2. **[correctness, PLAUSIBLE] the third place Windows releases held keys on
a switch (`Helper.cs:120-123`, cited by this lane's own
`docs/protocol.md` §10.6 note 1) is wired for some switch-to-local paths
and not others.** `injector.releaseAll()` runs on the hotkey path
(`EngineActions.swift:136`, `switchTo(slot:)`), on the broadcast toggle
(`Switching.swift:236`, `switchToBroadcast`'s `.releaseAllKeys` action)
and unconditionally in `recoverLocal` (`Recovery.swift:43`). It does
**not** run when a received `ByeBye` packet ends control locally
(`Engine.swift:509-510`, `case .byeBye: perform(switcher.
handleByeBye(packet, now: now))` → `Switching.swift:307-313` →
`switchToMachine`, which never appends `.releaseAllKeys`), nor when an
edge crossing or a `NextMachine` packet lands the target back on this
machine (`Engine.swift:460-464` `considerCrossing`, `:489-497` the
`.nextMachine` case → `Switching.swift:172-197` `prepareToSwitch`, same
gap). On Windows, `SwitchToMachine` and `PrepareToSwitchToMachine` both
call `Common.EvSwitch.Set()` unconditionally (`MachineStuff.cs:1024`,
`Event.cs:203`), which always wakes `Helper.HelperThread`, which always
calls `ReleaseAllKeys()` once `NewDesMachineID == MachineID` — i.e. on
every one of these paths, not just three of five. Two mitigating facts
keep this from being a CONFIRMED finding: the `ByeBye`-packet gap is
almost always covered moments later when the socket actually closes and
`noteDisconnected` calls `recoverLocal` (idempotent); and this port's
`Injector.releaseAll()` only clears state *this Mac itself injected*
(`Injector.swift:44-49` doc comment — it is the controlled-side release,
not a Windows-style `GetAsyncKeyState`-based physical-key release), so on
the edge-crossing path there is normally nothing for it to release
anyway. Still, the asymmetry is undocumented (no line in "Deviations
from the brief" says this is intentional) and inconsistent with the
belt-and-braces style the rest of `Recovery.swift` uses (e.g.
`cursor.recouple(to: nil)` unconditionally, "Idempotent" in the doc
comment) — worth either a one-line call or a documented reason not to.
3. **[completeness, PLAUSIBLE, low] contracts C2's last row ("sockets send
ByeBye" on the atexit/signal path) is not implemented for
SIGTERM/SIGINT/SIGHUP.** `AppLifecycle.swift:199-213`
(`installSignalHandlers`) only calls `EmergencyRelease.shared.run()`
(cursor + injector, synchronous, no actor — correctly matches CLAUDE.md
invariant 3 and this file's own header comment) and then `exit(0)`; it
never attempts `channel?.sayGoodbye()`. This looks architecturally
forced rather than an oversight — `channel` is actor-isolated state and
the header comment is explicit that this path must not touch the actor
— but the contract table literally promises ByeBye on this row and
nothing in the README flags the gap as a deliberate deviation the way
other trade-offs in the Work log are flagged. A peer that was being
driven when the app receives SIGTERM (e.g. a `kill`, or logout sending
SIGTERM to background apps) will only learn we're gone via its own
socket-level detection, not a `ByeBye`. Worth either attempting
`NSApp.terminate(nil)` (the graceful path already sends `ByeBye` and has
150 ms of headroom) for the three catchable signals, or amending
`docs/contracts.md` C2 to say so.
4. **[docs, trivial, not fixed] stale line count.** The Work log says
"`Engine.swift` 598" lines; `wc -l` on the reviewed tree gives 606. Both
numbers are well under the 800-line "consider splitting" line CLAUDE.md
sets, so the judgment the entry draws from it (no split needed) still
holds — the number is just stale, most likely from a commit after the
one the prose was written against. Not fixed (not a comment, and the
line the instructions permit me to fix without a finding is typos/wrong
comments, not a work-log narrative number); left for the dev to correct
or drop.
*Judgement on the two >600-line files.* `Sources/MWBCore/Settings.swift`
(628) and `Sources/mwb/Engine.swift` (606) are both under the 800-line
"consider splitting" mark, so CLAUDE.md does not require a reason to be
written down at all, let alone a split — the README documents the choice
anyway. Read top to bottom, both pass the one-sentence test: `Settings.
swift` is "the settings schema and the file that stores it" (mostly
mechanical get/set pairs, one per PowerToys property — a split by property
group would just scatter that repetition across files without changing what
a reader needs to hold in their head); `Engine.swift` is "the actor plus its
event pump and packet dispatch" (the `EngineActions.swift`/`Recovery.swift`
extension-file split already pulled the two things that *do* read as
separate responsibilities — switch/hotkey handling and C2 recovery — out of
it). No split recommended.
Verdict: REWORK
## Review