Fix review: H-L8-04 and H-L8-06 (hygiene)
From mnema-talk v3.3.13, rendered on this site.
Independent reviewer; I wrote neither fix (I was the phase 2 refuter of both findings). Both branches are based on msch128/hunt-lane8 at b5e4195d6. Each was reviewed in its own temporary worktree, removed afterwards. Nothing was pushed.
A. msch128/fix-h-l8-04 (f23a8569b)
Verdict: MERGE.
The change: setIdle (internal/ws/presence.go:66-71) deletes active[user] when the decrement
reaches zero, the same way forget already did (internal/ws/lifecycle.go:345-349). Two tests are
flipped from inverse assertions into guards: TestIdleThenOfflineLeavesNoActiveEntry, and
TestHubConnectTypeDisconnectCycleReturnsToBaseline, which no longer lists active as a known
leak.
Cause removed: yes. The invariant is "active[u] is the number of registered clients of u that
are not idle, and there is no entry at zero". It now holds on every path.
- Every writer and reader of the map, at the fix commit:
register(handshake.go:93) increments, so a missing entry becomes 1;forget(lifecycle.go:346-347) decrements only for a client that is not idle and deletes at zero;setIdle(presence.go:69-73) decrements and deletes, or increments;- the only production reader is
statusLocked(presence.go:27). It reads> 0, so a missing entry and a zero entry mean the same thing there. Nothing used the presence of a zero key. The tests that read the map (limits_test.go:97-119, greeting_order_test.go:31-43) still pass, and greeting_order_test.go:43 already expected the key to be absent.
c.idleis written only insetIdle(presence.go:65), underh.mu, and only for a registered client (presence.go:60-62). So the counter cannot go negative, andforgetcannot decrement a client thatsetIdlehas already counted down.- Lock: the delete is inside the same
safego.Locked(&h.mu, ...)closure as before. - My own situations, in a scratch test that is not committed: 200 seeds of 60 random steps for one
account, mixing new connections, idle, wake, close, and
setIdleafter close. After every step it checks that the entry equals the number of registered non-idle clients, that there is never an entry at zero, and that the status is offline, online or away to match. The map is empty at the end. Wake after deletion, two idle tabs where one wakes, and a latesetIdleon a closed client are all covered. It passed under -race.
What I ran:
go test -race ./internal/ws/: ok (62 s).- Revert check: with presence.go at f23a8569b^ both flipped tests fail. One reports "hub.active = 301 after the cycle, baseline 1", the other "offline account keeps active[user] = 0".
CYCLE_DEEP=1cycle tests: 20 000 connections,activeback to 0; voice cycle 20 000 joins, ok.- gofmt and go vet are clean. presence.go has 239 lines. The commit type is fix, with no attribution lines.
Findings: none blocking.
- NOTE: the fix adds no cost on a hot path;
setIdleruns once per idle change.
B. msch128/fix-h-l8-06-hygiene (90fee2502)
Verdict: MERGE AFTER FIXES. Both fixes are small; neither is a defect in the behaviour.
The change:
- A dropped presence audit event now increments
metrics.WSDropped.With("audit_presence")(internal/server/audit_presence.go:42) before the existing warning. TestAuditPresenceNeverBlocksTheHubnow asserts the count.- doc/moderation.md:517 and doc/operations.md:1518 describe the drop and the label
(operations.md also adds the
voice_churnlabel, which was already in use and undocumented). - The comment in metrics.go lists the reasons.
What I checked:
- The drop itself is unchanged. The
select/defaultbranch, the queue size of 1024 and the log line are the same; the only addition is one counter increment on the drop path. - Cardinality: there is one constant label value, so one new series.
Vecis capped atmaxSeriesanyway (metrics.go:63-64).Withcosts one read-locked map lookup, and only when an event is dropped. - Revert check: with audit_presence.go at 90fee2502^, the unit test fails with "dropped presence events counted = 0, want 1 to 1976". With the fix it passes 3 times in a row. Its upper bound is safe: the writer's context is cancelled before the burst, so at most 1024 events wait and the writer can only take some.
- Docker integration test
TestAuditPresenceBurstLosesJoinsPastTheQueue(-tags=integration): it passes. 3000 joins, 1025 recorded, 1975 lost, writer about 840 events/s in this run. I also added a temporary local line that compared the counter with the loss: counter delta 1975, lost 1975. The metric counts exactly the rows that are missing. - "the server log keeps each" join and leave: true in the default configuration, by reading the
code.
- The only
Presence(..., true)call (voice_join.go:165, throughannounceVoiceJoinat voice_join.go:99) comes directly afterc.logger().Info("voice join", ...)at voice_join.go:98, on the same path. The join line is also written for a rejoin, which is not audited: the log is a superset. - The only
Presence(..., false)call (voice_presence.go:97, inendPresence) comes afterlog.Info("voice leave", ...)under the samewasIncondition. - Both lines are at Info level. LOG_LEVEL is empty by default, which means info in production (cmd/server/main.go:335-351). With LOG_LEVEL=warn or error the lines are not written, and how long they are kept is up to the operator's log retention.
- The only
- gofmt, go vet with and without -tags=integration, and scripts/check-english-only.mjs are clean. The commit type is fix, with no attribution lines.
Findings:
- SHOULD-FIX: doc/moderation.md:517. "the server log keeps each" is true only at the default log
level, and "keeps" claims a retention the server does not control. Suggested wording: "the
server log writes each one at the default log level (
voice join/voice leave)". - SHOULD-FIX: internal/server/audit_presence_burst_integration_test.go, header comment. It still
says the queue drops "with a log line and no metric", which is false after this commit. Update
the comment, and add the check I ran: the counter delta equals
burst - last. That turns the new doc sentence ("counts the misses") into a tested property. - NOTE: the counter does not count entries lost for other reasons: a failed insert (logged by
RecordOrLog, internal/audit/audit.go:104-107) or a failed DM lookup (deliberately not recorded, audit_presence.gowritePresence). "counts the misses" in moderation.md means queue misses; precise enough, but "counts the entries dropped from the queue" would be exact. - NOTE: the admin Ops panel shows
ws_droppedas the total of all reasons (internal/server/system_ops.go:107,WSDropped.Total()), labelled "Events dropped (slow or flooding clients)" (web/src/i18n/en.json:1967) and marked as a warning when it is above 0. An audit queue drop now shows there under a label that blames clients.voice_churnalready did this before this branch, so the problem is older than this branch. Widen the label in a follow-up, or keep the audit reason out of the panel total.
Not checked
- No browser or UI run; the Ops panel finding is from reading the code.
- No production database rate; the integration test runs on a local throwaway database.