Fix review: H-L3-07 (documents), H-L2-01 (relay sentence), H-L3-11 (composer text)

From mnema-talk v3.3.13, rendered on this site.

Reviewer: independent, read-only. I wrote neither the findings nor the fixes. Only the fix commits were reviewed; the base is the lane 3 test state (b3ca83909) on main 56f6a4101.

FixBranchCommitVerdict
H-L3-07msch128/fix-h-l3-0700e3f6f5a (docs)MERGE AFTER FIXES
H-L2-01msch128/fix-h-l2-01b1549fbc4 (docs)MERGE
H-L3-11msch128/fix-h-l3-1128d39a5f7 (fix)MERGE AFTER FIXES (two blockers)

The three commits merge onto main together without conflict (trial merge in a scratch branch, deleted).


1. H-L3-07, commit 00e3f6f5a: MERGE AFTER FIXES

What changed (checked)

  • SECURITY.md: exactly two hunks (word diff read in full). Replay window paragraph (about line 796) and the first sentence of "Key lifetime" (about line 897). Nothing else in the file changed.
  • deploy/monitoring/mnema-alerts.yml: only the summary annotation of MnemaMemoryHigh. The diff has no +/- line on expr; parsed with the yaml package the rule is still process_resident_memory_bytes > 800e6, for: 15m.
  • doc/operations.md: the table row only. doc/architecture.md: the anonymous poll export sentence and the DTX frame size.

Truth of each new sentence against the code

  • D1 "The previous epoch's key is kept for 30 seconds after a switch." TRUE. bounds.ts PREVIOUS_EPOCH_MS = PREVIOUS_GROUP_MS = 30_000; groupEpochCommit.ts:54 sets until = clock.now() + PREVIOUS_EPOCH_MS at the switch; mediaFrameWorker.ts:128 drops the key after it. Agrees with SECURITY.md's own later sentence (receivers hold it 30 seconds). Not weaker or stronger than the code.
  • D2 "A key lives 30 minutes, plus or minus a random two-minute jitter ... the committer notices an old epoch on a 30-second check, so with an awake committer it lasts at most 32.5 minutes, and a committer that sleeps or is skipped can extend that by a time that has not been measured". Parts TRUE: groupEpoch.ts:96 draws rotateMs + (Math.random() * 2 - 1) * rotateJitterMs (so plus or minus, max 32 min); the tick runs every MAINTENANCE_MS = 30_000 (groupEpoch.ts:158); groupEpoch.ts:230 skips maintenance after a sleep. The unmeasured extension is stated honestly. But see SHOULD-FIX 1: "it lasts at most 32.5 minutes" is stronger than the code.
  • D4 "the data export of a member holds only that they took part in an anonymous poll (the poll id, never the choice)". TRUE for votes: account_export_polls.go:39 exports poll_id AS message_id, TRUE AS anonymous from poll_voters WHERE user_id = $1; polls are keyed by their message id, so "poll id" is right. See NOTE 3 for the author's own polls.
  • D6 "107 bytes of overhead plus the one or two bytes of payload". TRUE: frame.ts:26-29 HEADER_BYTES 27 + TAG 16 + SIGNATURE 64 = FRAME_OVERHEAD_BYTES 107; the clear prefix (codec.ts) is used for video only (H.264 NAL header, VP8), not for Opus. The sentence's grammar is broken (SHOULD-FIX 2).
  • D7 "800 MB (about 75% of the default limit)". TRUE: docker-compose.yml mem_limit: ${APP_MEM_LIMIT:-1g}, Docker's 1g is 1 GiB; 800e6 / 2^30 = 74.5 %, "about 75" is right. The old 80 % is gone from both the table and the alert text; the threshold is unchanged.

No promise got weaker than the code delivers: D1 makes it stronger and correct (30 s instead of "until the next rotation"); D2 replaces a bound the code did not keep with the real one plus a disclosed gap.

SHOULD-FIX

  1. SECURITY.md Key lifetime (about lines 897-901): "with an awake committer it lasts at most 32.5 minutes" is stronger than the code. 32.5 minutes is the latest moment the committer decides to commit (ROTATE_MS + ROTATE_JITTER_MS + MAINTENANCE_MS). After that the old key still exists and is used: the commit has to be built and delivered; members that only added or rotated go on sealing under the old epoch for SEND_GRACE_MS (1.5 s, bounds.ts) after they apply it; and every receiver keeps opening it for PREVIOUS_EPOCH_MS (30 s) after its switch, which the same document now says ten lines earlier. So the key lives at least about 33 minutes at a receiver even with an awake committer. Suggested wording: "the committer advances the epoch at most 32.5 minutes after it began (receivers then keep the old key 30 seconds, see above)". This is SECURITY.md, so the wording needs the owner's approval again. The pin would then anchor on "at most N minutes after it began".
  2. doc/architecture.md:371: "sealed they would be 107 bytes of overhead plus the one or two bytes of payload, each and go out 50 times a second" does not parse (", each and go out"). Suggested: "sealed, each would be 107 bytes of overhead plus its one or two payload bytes, 50 times a second".
  3. web/src/docClaims.test.ts, D1: the new sentence's "30 seconds" is not pinned; the test only checks the old phrase is absent. Mutation run: PREVIOUS_GROUP_MS = 20_000, the already-pinned sentence near line 937 changed to 20 seconds, the new line 796 left at 30: all 6 tests pass. That is exactly the drift the file exists to catch. Add toContain(\previous epoch's key is kept for ${PREVIOUS_EPOCH_MS / 1000} seconds`)`.
  4. web/src/docClaims.test.ts, D7: the threshold 800e6 is a literal in the test, and the alert's summary is not read at all. Mutation run: expr changed to > 900e6 in mnema-alerts.yml only: all tests pass while both texts say 800 MB. Read the number from the rule's expr and check both the table row and the summary.

NOTE

  1. Brittleness. The D2 and D6 pins match whole phrases: rewording "it lasts at most" to "it lasts no longer than" (D2) or "sealed they would be" to "sealed each would be" (D6) turns them red (mutations M4, M5). They fail loud, not silently, so this is acceptable, but toContain('by a time that has not been measured') pins prose, not a number, and can go. A sturdier shape: locate the paragraph by its bold heading and take the first number before "minutes" or "bytes of overhead".
  2. D4 is an absence check only; there is no constant to pin. The behaviour itself is pinned by the existing integration test named in the finding (not run here; documentation-only change).
  3. D4 "holds only that they took part": a member who created an anonymous poll also finds the poll with its tally in the export (account_export_polls.go:93-106, WHERE m.user_id = $1). That is their own message and holds nobody's choice, so the sentence is not false in its context (votes), but "only" could be read wider. Optional: "for an anonymous poll they voted in, the data export holds only that they took part".
  4. The edited lines in doc/architecture.md are not rewrapped (one is about 170 characters in a wrapped paragraph). Cosmetic.
  5. The D2 hunk in SECURITY.md is now a single 70-word sentence ending in ": once the epoch is that old", where "that old" now refers to "a time that has not been measured". Worth splitting when the owner approves SHOULD-FIX 1.

Do the tests now run as normal tests and fail on revert?

Yes. At 00e3f6f5a: 6 passed. With SECURITY.md, doc/architecture.md, doc/operations.md and the alert file restored to the parent commit: 5 failed, 1 passed (the existing control). Constant drift: MAINTENANCE_MS 60 s turns D2 red; compose default 2g turns D7 red; see SHOULD-FIX 3 and 4 for the two drifts that pass.


2. H-L2-01, commit b1549fbc4: MERGE

New sentence (doc/architecture.md:566): "The server relays the handshakes, checks their framing and that the sender is in the Talk, and never sees keys; the members validate who may commit."

Checked against internal/ws/media.go:21-43 (handleMediaHandshake): it decodes the JSON, requires the connection's current voice room to equal channel_id (sender in the Talk), decodes base64, caps the size at 32 KiB, calls mediaframe.WellFormedHandshake (header bytes only: MLS version and wire format, or the fixed-size heartbeat and capability messages), then relays to the room except the sender with the sender id stamped. internal/ws/mediaframe/mediaframe.go:8-13 says it cannot tell a genuine message from a forged one. The sentence is true. It agrees with SECURITY.md (about lines 778-781: the server relays the handshakes, asserts who is in the room, stamps each sender, and can impersonate the committer). git grep finds no other sentence in doc/ or SECURITY.md that credits the server with a commit check.

Test: web/src/docClaimsRelay.test.ts passes; with doc/architecture.md restored to the parent it fails.

NOTE

  1. The test is a prose guard (old sentence absent, new phrase present), not a pin to code; there is no constant to pin. It will break on rewording of the new phrase; acceptable for a one-line guard.
  2. The sentence omits the size cap and the sender stamping; neither omission makes it false.
  3. The new line is not rewrapped (about 170 characters). Cosmetic.

3. H-L3-11, commit 28d39a5f7: MERGE AFTER FIXES

White-space set: identical to the server's, as far as messageText goes

httpx.CleanText (internal/httpx/request.go:99-110) does strings.TrimSpace, then refuses invalid UTF-8 and NUL, then counts runes. Message content reaches it through core.ValidateContent for create (service_gate.go:114), edit (message_mutations.go:64 and the handler) and scheduled messages (internal/later/scheduled_handler.go:95, 149). Nothing else is stripped on the message path. Go's TrimSpace set is ASCII \t \n \v \f \r space, U+0085, U+00A0 and unicode.IsSpace above Latin-1 (U+1680, U+2000-U+200A, U+2028, U+2029, U+202F, U+205F, U+3000). SERVER_SPACE in textLength.ts lists exactly these. Probe over all BMP code points: messageText's edge trim differs from JavaScript's trim() on exactly U+0000 (stripped, by design), U+0085 and U+FEFF. So the helper itself matches the server.

BLOCKER 1: the store still trims with JavaScript's trim(), so the wire is not what messageText returns

messageText() is applied in the components, but the store applies .trim() again before the request:

  • web/src/stores/chat/messagePost.ts:73 content: withEmojiTokens(send.content.trim()) (every text POST, the outbox's retries included),
  • web/src/stores/chat/messageActions.ts:23 (!content.trim() guard in sendMessage), :72 and :75 (editMessage guard and PUT body).

Consequences, each traced through the real code:

  • (a) The defect of the finding is still there for a variant. Draft "\u0085": messageText keeps it (U+FEFF is not server white space), so the send button is enabled; the store's trim() removes the two U+FEFF and sends "\u0085"; the server's TrimSpace makes that empty and answers 400 "content is required". The same goes for " \u0085 " and for editing a message to such a text. Evidence: a throwaway vitest (not committed) that mocks api and calls postText with messageText(draft) saw the JSON content "\u0085" for that draft; a Go strings.TrimSpace of it is empty.
  • (b) The commit message's claim "it keeps U+FEFF ... exactly as the server does" is false on the wire: the request still loses U+FEFF at the edges.
  • (c) A draft of only U+FEFF (or U+FEFF with white space): the send button is now enabled (before: disabled); sendMessage returns null because content.trim() is empty; ChatArea.handleSend does not look at the result and clears the composer. The member's draft vanishes, nothing is sent, no hint. Message edit of the same text closes the editor without saving or asking to delete (saveOrDelete now goes to saveEdit, editMessage returns null). An outbox entry edited to "" used to be cancelled; now it is kept and sent as an empty content, which the server refuses with 400.
  • (d) The parity test does not see any of this: composerSends models the components only, not the store. Of the 552 regenerated vectors, 70 differ from what the store actually sends, and for 20 of them the wire content is empty. Their runes are counted on a string that is never sent (the wire is shorter, so the "within the limit" property still holds, on the safe side).

Fix (suggested, smallest): make messageText also remove U+FEFF at the edges (trim with the union of Go's set and trim()'s set). Then the store's trim() is a no-op, the server's TrimSpace is a no-op, the counter equals what is stored, and the U+FEFF behaviour of the web client does not change. Alternatively remove the store's .trim() calls and decide deliberately that the web client may now send U+FEFF-led messages (the server has always stored them for API clients and bots; invisible messages are already possible with U+200B). Either way, model the wire in the test: let composerSends end with what postText puts in the body (or test postText with a mocked api, as above), and add "\u0085" and "" to the unit check.

BLOCKER 2: messageText is quadratic in a run of white space, on the composer's render path

edgeSpace = /^[S]+|[S]+$/g makes the engine try [S]+$ at every position of an inner white-space run and backtrack, so the cost is the square of the longest inner run. Measured in Node 24 (one call; trim() takes under 0.01 ms for all):

inner run of spaces or newlinesmessageText
4 0009 ms
20 000190 ms
50 0001.1 s
100 0004.8 s

It runs on every render of the composer (:disabled in ChatComposer.vue and ThreadComposer.vue, the canScheduleLater and "send later" computeds) and in lengthState from 3 600 UTF-16 units on, so a pasted text with a long blank stretch freezes the tab on each keystroke, and again when the draft is restored. Only the author's own tab is affected, but it is a new cost on a hot path that trim() did not have. Fix: trim with two index loops (or two anchored, non-global regexes applied to a string already known to end in a non-space, e.g. find the last non-space index first). Add a timing-free unit check, for example a 200 000 character inner run that must finish, so a regression shows up as a test timeout.

SHOULD-FIX

  1. web/src/chat/components/ScheduledItem.vue:38 and :43 still use trim(). The schedule creation path (ChatComposer "send later") now uses messageText, but editing a scheduled message to a U+0085-only text is still sent and refused with 400 by the same ValidateContent (scheduled_handler.go:149), and a NUL in it is still refused rather than stripped. Same class as the finding, one line each; the commit message names it but leaves it. Use messageText there too.

NOTE

  1. Outbox entries stored before the update are not re-cleaned on load (outboxStorage.ts:46-54 reads content as stored, clamps it only). An entry with NUL queued by the old client is retried as is and refused once with 400; editing it (saveEdit applies messageText) repairs it. The dedupe key is the nonce, which the change does not touch; the edit-retry path (saveEdit, possiblyDelivered and sending guards) is unchanged apart from the cleaning. Acceptable.
  2. Counter versus server: for every text whose wire equals messageText (all except U+FEFF edges) the counter's rune count equals the server's runes in the vector file. With U+FEFF edges the counter counts one or two more than the server stores, so a 4 001-character draft with a U+FEFF edge is blocked although the server would take it. Safe side; goes away with BLOCKER 1's first fix.
  3. NUL is now stripped, not refused: "a\u0000b" is sent as "ab" where the server used to refuse it. That is a deliberate behaviour change, documented in the commit message, and nothing renders NUL. Fine.
  4. Remaining .trim() uses that do not decide what is sent (typing indicator ChatComposer.vue:105, Escape handling useComposerKeys.ts:53, drafts.ts:200 keep-or-drop of a draft, previews) are harmless; drafts.ts keeps a U+0085-only draft, which is only a stored draft.
  5. contentParity.test.ts unit check line has a stray space before ); ESLint does not flag it.

Vector file and the Go side

Only internal/chat/core/testdata/content_vectors.json changed outside web/. Before: 570 vectors, 88 refused. After: 552 vectors, none refused. TestContentVectorsMatchTheServer still reads the file (content_parity_test.go:24-46) and passes, so the file holds the server's real verdicts for these strings. Reverting messageText to draft.trim() makes "the vector file holds what the composer sends" and the new unit check fail; "the server accepts everything the composer sends" stays green on revert because it reads the static file, which is fine since the equality test guards the file.


What I ran

  • Trial merge of the three commits onto main (no conflict).
  • H-L3-07: npx vitest run src/docClaims.test.ts at the fix (6 passed); with the four documents restored to the parent (5 failed); six mutations of constants and texts (results above). Alert file parsed with the yaml package. node scripts/check-doc-links.mjs, node scripts/check-english-only.mjs: ok.
  • H-L2-01: npx vitest run src/docClaimsRelay.test.ts at the fix (passed) and with the page restored (failed). git grep of doc/ and SECURITY.md for other server-side commit claims.
  • H-L3-11: go test -count=1 -run TestContentVectorsMatchTheServer ./internal/chat/core (ok); npx vitest run src/chat/lib/contentParity.test.ts src/chat/lib/composerLimits.test.ts src/shared/lib/textLength.test.ts (35 passed, 1 skipped: the vector writer); revert of messageText (2 failed); a code-point probe of the white-space set; timing of messageText in Node; a throwaway vitest through postText with a mocked api; a Go TrimSpace check of the wire strings; ESLint on the 9 touched web files (clean); vue-tsc on tsconfig.app.json (no errors printed); English-only check; file sizes (largest touched production file ChatArea.vue, 391 lines). All runs with nice -n 10, one at a time, in one temporary worktree that has been removed.

What I did not check

  • No browser run: whether a clipboard delivers U+0085, U+FEFF or NUL into the textarea, and the toast or composer behaviour on screen, were traced in code only.
  • The D4 integration test and other Go tests were not run (documentation-only change there).
  • make complexity-check was not run (no Go production change; TS complexity is in ESLint, which passed).
  • Fields other than message text (names, topics, poll options), and withEmojiTokens' effect on length.
  • The desktop client repository.

Second round

Only the new commits were reviewed: cce2a2e17 on msch128/fix-h-l3-07 and aca1b8c14 on msch128/fix-h-l3-11. H-L2-01 is unchanged (MERGE stands).

FixNew commitVerdict
H-L3-07cce2a2e17 (docs)MERGE
H-L3-11aca1b8c14 (fix)MERGE

H-L3-07, cce2a2e17: MERGE

  • SECURITY.md: one hunk only (git diff 00e3f6f5a cce2a2e17 -- SECURITY.md), the Key lifetime sentence. New text: "An epoch lasts 30 minutes, plus or minus a random two-minute jitter ..., and the committer notices an old epoch on a 30-second check, so an awake committer advances the epoch at most 32.5 minutes after it began and receivers then keep the old key for 30 more seconds; a committer that sleeps or is skipped can extend that by a time that has not been measured." TRUE of the code: groupEpoch.ts:96 (draw in ROTATE_MS plus or minus ROTATE_JITTER_MS), the 30 s maintenance tick (groupEpoch.ts:158), the committer's commit at the latest at 32 + 0.5 minutes, then PREVIOUS_EPOCH_MS (30 s) at every receiver (groupEpochCommit.ts:54, mediaFrameWorker.ts:128). The senders' 1.5 s SEND_GRACE_MS falls inside the receivers' 30 s, so the sentence now bounds the key's real life with an awake committer; it is neither stronger nor weaker than the code. The "that old" ambiguity of round 1 (NOTE 5) is gone ("Once the epoch is due"). Closes SHOULD-FIX 1.
  • doc/architecture.md:371 now parses ("sealed, each would be 107 bytes of overhead plus its one or two payload bytes, and they would go out 50 times a second"). Closes SHOULD-FIX 2.
  • Mutation PREVIOUS_GROUP_MS = 20_000 with the sentence near line 937 also changed to 20 seconds (the drift that passed in round 1): now 2 tests fail (the new pin of "kept for 30 seconds after a switch" and the "30 more seconds" of the key lifetime pin). Closes SHOULD-FIX 3.
  • Mutation > 900e6 in mnema-alerts.yml only: the memory test fails. Changing only the alert summary to "about 80%": fails too, so both texts are pinned to the rule's expr. Closes SHOULD-FIX 4.
  • Also: MAINTENANCE_MS 60 s fails the key lifetime pin; restoring SECURITY.md and doc/architecture.md to 00e3f6f5a fails 2 tests; at cce2a2e17 6 of 6 pass.
  • NOTE (unchanged, not blocking): the pins still match whole phrases and break on rewording (loud, not silent). The edited DTX lines are still not rewrapped. The alert summary pin hardcodes "default 1g".

H-L3-11, aca1b8c14: MERGE

messageText() now removes NUL (only when present) and trims, with two index loops, a Set that is exactly the union of Go's TrimSpace set and JavaScript's trim() set (checked code point by code point: the round-1 set plus U+FEFF). postText, sendMessage (guard), editMessage (guard and PUT body) and ScheduledItem.vue (validation and content) use it.

Blocker and should-fix items, each re-probed (throwaway vitest through the real store with a mocked api, raw drafts passed in without pre-cleaning, removed afterwards):

  • BLOCKER 1 closed. "\u0085", "" and "  \u0085  ": messageText gives "", sendMessage and editMessage return null and make no request; the composer's button is disabled for them (same messageText). "\u0000x\u0085" and "a\u0085\u0000" put exactly "x" and "a" on the wire for both POST and PUT. A message edited to "" now goes to the delete question (saveOrDelete), an outbox entry edited to it is cancelled, as before the first round. The new test "postText puts on the wire exactly what the composer decided to send" walks every vector through the real postText.
  • BLOCKER 2 closed. 100 000 inner spaces or newlines: 0.3-0.4 ms for messageText plus lengthState; 100 000 NUL: 1.9 ms; 1 000 000 spaces: 7.6 ms (linear). With the round-1 regex restored the new speed test fails (4 s).
  • SHOULD-FIX 1 closed: ScheduledItem.vue uses messageText for validation and the sent content.
  • NOTE 2 closed: the regenerated vectors (533, none refused) have no edge character of either set and their runes equal the client's count for every vector; a 4 000-character draft between two U+FEFF is not "over".

Revert checks: round-1 textLength.ts restored: 3 tests fail (vector file equality, the unit check, the speed test). Only the store's messageText(send.content) turned back into .trim(): all pass, which is correct, because trim() is now a no-op on messageText's output; the wire test guards messageText itself.

NOTE

  1. The speed test's 5 ms limit is about 12 times the measured time on this Mac under load; a heavily loaded CI runner could come close. Low risk; a 50 ms limit would still catch the quadratic version (4 s).
  2. The wire test feeds already-cleaned texts to postText, so it does not by itself show that the store cleans raw input; my probe above did, for send and edit.
  3. Round-1 NOTE 1 (outbox entries stored before the update are not re-cleaned on load) still holds, and now matters less: postText cleans every retry, so a queued NUL text from before the update is sent without NUL.

Gates and regressions: vitest run src/chat src/stores src/shared (3 workers): 289 files passed, 1 skipped; 3 652 tests passed, 7 expected failures, 4 skipped. vue-tsc --noEmit -p tsconfig.app.json and -p tsconfig.tests.json: exit 0, no errors. ESLint on the 5 touched web files: clean. go test -run TestContentVectorsMatchTheServer ./internal/chat/core: ok. English-only check: ok. Only content_vectors.json changed outside web/. File sizes: textLength.ts 90 lines, messageActions.ts 115, contentParity.test.ts 99.

Not checked in this round: a browser run; tsconfig.node/worker/worklet (not touched); the desktop client. Both temporary worktrees have been removed.

Something wrong on this page? Tell us.