Review of PR #914: timed thread replies, display name cleaning, bot channel options, command permission storage, durable-commit file cleanup
From mnema-talk v3.3.13, rendered on this site.
Two rounds. The first reviewed the five changes as first pushed; its should-fix findings were fixed in the same pull request and checked in the second round (at the end).
Round 1
Verdict: MERGE AFTER FIXES. No blocker. All five changes are correct, the
tests fail without the fixes, and the reviewer found no regressions. Several
read paths still used the old lifetime check instead of core.LiveSQL, two of
them (new report copies, the bulk delete's audit entry) writing stored copies
that outlive the sweep, so doc/timed-messages.md promised more than the code
did.
What was checked
1. A reply ends with its timed root.
LiveSQL(alias)is((a.expires_at IS NULL OR a.expires_at > now()) AND NOT EXISTS (... ended_root.id = a.parent_id AND ended_root.expires_at <= now())). Neither part can be NULL, soNOT LiveSQL(x)(saved list, media serving) means "this row ended, or its root did". A root hasparent_id IS NULLand never matches the subquery.- All 13 callers embed the expression after
AND, and it is fully parenthesised.pins.gousesLiveSQL("messages")on an unaliasedFROM messages; the inner table isended_root, somessages.parent_idis the outer row. No caller usesliveorended_rootas an outer alias.MessageSelectembedsLiveMessagestwice, each in its own scope.TestLiveMessagesSpellsOutLiveSQLkeeps the constant and the function together. - Through
MessageSelect/LiveMessages: history, threads, search, inbox, bot API reads, forum posts, announcements, polls, interaction responses and reply previews leave out replies of an ended root; saved, reminders, forward, reactions, media serving and the reported message itself too. - Still on the raw check: report context, the bulk delete, the conversation list, the account export, the edit and reaction locks (findings below). The other raw uses only see roots (forum activity,
FirstUnread,/thread, reply counts). - Gateway resume replays no stored messages.
- Performance, EXPLAIN ANALYZE on a scratch PostgreSQL 18 with 1M rows and the production indexes: channel history of 50 roots 0.23 ms before, 0.08 ms after (anti join on the primary key, no probes for roots); trigram search with 751 hits 8.5 ms before and after; thread replies 0.08 ms.
2. Display names. cleanDisplayName (httpx.CleanName) is used for registration, UpdateProfile and UpdateDisplayName; /nick goes through UpdateDisplayName. No other path writes a member's display name from input (the admin seed uses the username, bots and webhooks already use CleanName, the erasure writes a fixed string). C0 controls are now refused; the test covers it. On the web, mentionName strips the direction and zero-width characters, keeps ZWJ and ZWNJ, and falls back to @username; unicode-bidi: isolate on .md-mention is right for an inline span.
3. Bot command channel option. The botUser passed in interactions.go is the command's bot. Built-ins pass uuid.Nil and keep the member-only check (none has a channel option today). Categories never get View and fail the type filter; conversations and Talks of conversations fail the bot view and dm_id IS NULL; threads are messages. The SQL filter matches resolveChannels.
4. storedDefaultPerms. A value above MaxInt64, unknown bits or an unparsable value is refused instead of stored as NULL. Clean already refuses them, so this is defence in depth.
5. ErrNotDurable. Both error returns of AwaitDurable wrap it with %w: %w; errors.Is follows it through "record upload: %w". Of every caller of the insert functions only the media upload and the webhook delete objects on error, and both are fixed. Scheduled sends delete their row in the insert transaction; the nonce replay has nothing to clean up.
Tests, limits, docs. On a copy with the origin/main version of each fixed file, TestAReplyEndsWithItsTimedRootBeforeTheSweep, TestAnUploadCommittedButNotConfirmedKeepsItsFile, TestAWebhookFileOfACommittedMessageStaysWhenTheWaitFails and TestSlashCommandRoundTrip fail; the two unit tests call functions that do not exist on origin/main and assert the opposite of its behaviour. Largest changed file 386 lines, largest test 578; gocognit at most 13 on changed functions. doc/bots.md matches; no documented response in api/openapi.json changed.
What was run
- The four integration tests above, alone and on the copy without the fixes (fail as expected).
go test -count=1onchat/core,auth,bot,db,media,webhook,chat/...: ok.go veton the changed packages: clean.npx vitest run src/shared/lib/markdown.test.ts: 31 passed.
Findings
Should-fix:
internal/chat/reports/reports.go:94,96,100: the neighbours of a reported message use the raw check, so a report filed after a root ended and before the sweep stores the thread's replies in its snapshot.internal/chat/messages/moderation.go:222,224: the bulk delete counts a reply of an ended thread and writes its text into the audit entry.internal/chat/dm/dm.go:135,151: the conversation list can show such a reply as the last message.internal/chat/account/account_export_messages.go:36,account_export.go:24: the export includes the member's own replies of an ended thread.doc/timed-messages.md:121promised exports and new report copies leave such replies out.- Names stored before the change are only cleaned inside web mention pills; author lines and member lists show them as stored.
Nits: the edit and reaction locks (message_mutations.go:77,222) still use the raw check (the routes are refused earlier); two different refusal texts for one rule in commands_validate.go; the conversation check is defence in depth and untested on its own; the web strip list is narrower than the server's (U+2060 to U+2064, U+00AD); the option type comment in commands.go could say what the docs say. Not changed by this pull request: after ErrNotDurable an upload still answers 500 for a stored message; bot/components.go loadComponentMessage has no lifetime check.
Not checked
Admin-only reads (media listings, audit log viewer), unread counts in readstate.go (counts, no content), the desktop and mobile clients beyond the shared web bundle, the full integration suite, production query statistics.
Round 2
Verdict: MERGE. All round 1 should-fix items are fixed; three nits remain.
What was checked
- S1 to S4: report context (the anchor and both neighbour selects), the bulk delete (
mand the nestedr), the conversation list (last activity and the preview) and both account export queries usecore.LiveMorcore.LiveSQLwith the alias they embed;editTxandlockMessageuseLiveSQL("messages")against an unaliasedFROM messages.FOR UPDATE OF mandFOR NO KEY UPDATEstill work with the added subquery.TestLiveMSpellsOutLiveSQLkeeps the constant and the function together. - S5:
doc/timed-messages.mdmatches the code for every read it lists. - S6: the character classes of migration 0111, decoded, are exactly the web
NAME_FORMATset (U+00AD, U+061C, U+180E, U+200B, U+200E, U+200F, U+202A to U+202E, U+2060 to U+2064, U+2066 to U+206F, U+FEFF); ZWJ and ZWNJ stay. A name with nothing left becomesLEFT(username, 24), the same asdefaultDisplayNamefor ASCII usernames. The migration does not strip the wider set thatCleanNameremoves on input (all Cf, private use, C1 controls, blank-glyph letters); the direction and zero-width characters are covered. Thedoc/upgrade.mdrow is accurate. - Push: the rewritten mentions reach the notification body only through
clean(plainLine(...))(internal/push/payload.go:182), which turns controls and every Cf except ZWJ and ZWNJ into spaces; sender and channel names go through the sameclean. The round 1 concern about pushes does not hold. - Nits of round 1: one refusal text, "a channel you and the bot can see", for every bot-command case (built-ins keep "a channel you can see"); the option type comment and
api/openapi.jsonsay whatdoc/bots.mdsays. - Size limits: largest changed file
dm.goat 390 lines.
What was run
TestAReplyOfAnEndedThreadIsNotCopiedOrEdited,TestAReplyEndsWithItsTimedRootBeforeTheSweep,TestTheMigrationCleansStoredDisplayNames,TestSlashCommandRoundTrip: ok.go test ./internal/chat/... ./internal/bot/ ./internal/auth/ ./internal/push/: ok.scripts/check-english-only.mjs: ok. Vitestmarkdown.test.ts: 31 passed.TestAReplyOfAnEndedThreadIsNotCopiedOrEditedon a copy with the previous versions ofreports.go,moderation.go,dm.goandmessage_mutations.go: fails on the report copy, the bulk-delete audit entry and the conversation list.
Remaining findings (nits)
- The edit assertion does not prove the
editTxchange: the handler'sLoadMessageRefalready refuses the edit, so the lock change is defence in depth; the account export change has no test of its own. - Migration 0111 held its format characters literally, invisible to readers. Fixed after this round: the classes are written as
\uXXXXescapes (ASCII only), andTestTheMigrationCleansStoredDisplayNamespasses on that file. - Clients see the cleaned names after a reload: the migration sends no
user_update, and it runs at startup before clients connect.
Not checked in round 2
The full suite was not run again by the reviewer (it passed for the author on this state); no new EXPLAIN (the plan shape is unchanged from round 1).