Fix review of H-L3-S1-01 (edits and poll votes after a block in a conversation of two)

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

Reviewer: independent, read-only. Fix: branch msch128/fix-h-l3-edit, commit 33860ed91 (reviewed alone; its parent is the lane-3 test state on main). Production code read at that commit. Tests run in a temporary worktree, removed afterwards; nothing pushed.

Verdict: MERGE

The fix removes the cause the finding and the refuter describe: EditMessageTx never asked the conversation. It now runs the same checkDMReachable that GatePost uses, inside the edit transaction, after the row lock and the authorship and poll checks, and before any write (recordReplacedVersion, the UPDATE messages, RecordMentions, the message_update event). It covers every edit route there is, and the refused edit gives back exactly what a refused post gives back. The poll vote door is closed the same way. Nothing below blocks the merge. One SHOULD-FIX is a pre-existing door of the same kind that this fix does not reach and its commit message says does not exist. It should become its own finding, not be added to this commit.

What I checked

1. Every edit path goes through the new check

  • grep EditMessageTx|EditMessageWith (non-test): EditMessage (internal/chat/messages/message_mutations.go:23) is the only caller of EditMessageTx. It is reached from the REST edit (ServeEditMessage, handler_messages.go:175) and from the bot API edit (botEditMessage, internal/chat/botapi/botapi.go:279, through EditMessageWith). No slash command edits a message: the built-ins in internal/slashcmd/slashcmd.go:50-60 only post. No WebSocket client event edits a message (internal/events/types.go:111-130).
  • Other statements that change a message row (grep -E "UPDATE\s+messages|messages\s+SET"):
    • pins (pins.go:198) need Manage messages, which the snapshot removes in conversations;
    • forum post title, lock and resolve (forum_posts.go:206) do not apply to a conversation;
    • account erase (account_erase.go:42,56) is not a member action. There is no route that removes one attachment from a message or suppresses embeds (embeds are only written at insert, messages.go:345-364). Deleting a whole message stays open on purpose (see 4).
  • Order in EditMessageTx (message_mutations.go:44-79): the message row is locked FOR NO KEY UPDATE. Then come authorship (:57), poll (:60), checkDMEditAllowed (:63), the content check, and the writes. A refused edit writes nothing and broadcasts nothing (EditMessage returns before RecordMessageEvent).
  • Automod for edits (checkEditAutomod) runs before the transaction, as it does for posts. A blocked edit or post that also breaks an automod rule therefore gets automod's 400 in both cases, the same order. That is pre-existing and consistent (NOTE N3).

2. Inputs and situations of my own (not in the fix's tests), run through the real routes

Local probe test in internal/server, integration tag, not kept:

Situation after bob blocks alice (1:1)Result
Edit to empty content (a text message)403 FORBIDDEN "Couldn't send this message." (the block is checked before the empty-content 400)
Edit of a message that is a reply (reply_to_id)403, same body
Edit of a thread reply in the conversation (created before the block)403, same body
Edit of the Talk invitation card in the conversation403
Edit after the block is lifted200 (the block is the only reason for the refusal)
Scheduled message created before the block, made due and swept (Later.Sweep)state failed, reason not_allowed (the same reason as a lost permission), no message row
/shrug by the blocked member through POST /api/channels/{dm}/interactions403 "Couldn't send this message."
/me by the blocker403, same body
/msg @blocker text by the blocked member403, same body
Other side disabled (no block): post / edit / vote / reaction403 / 403 / 200 / 200 (see NOTE N1)
Edit and post in the chat of the conversation's Talk, opened before the block200 / 201, and the blocker reads both (see SHOULD-FIX S1)

The door table cells the author marked "by code" now hold through the real routes for the scheduled message (all three cases) and for three slash commands.

3. Does a refused edit tell the blocked member they are blocked?

  • Status, code and text: a refused edit gives back 403 {"code":"FORBIDDEN","message":"Couldn't send this message."}. That is byte for byte the refused post (TestARefusedEditAfterABlockAnswersLikeARefusedPost, and my probe for slash commands). A disabled other account gives the same answer for an edit (checkDMReachable is shared), so an edit does not tell a block from a disabled account.
  • An unblocked conversation gives 200, as before. The refusal tells the member only what a refused post already tells them.
  • Timing, median of 40 local runs: refused post 0.63 ms, refused edit 1.39 ms, accepted edit in an unblocked pair 3.1 ms. A refused edit is quicker than an accepted one because nothing is written. That difference carries no information beyond the status code, which already says "refused". Timing is outside the public contract (doc/api-stability.md "What is not public").

4. The poll vote refusal and what stays open

  • Golden catalogue: internal/repo/testdata/error_messages.golden.json is an internal test catalogue. It makes sure the web app translates every server sentence (errormessages_test.go:14-17). doc/api-stability.md lists status codes and error codes as public, not the message text ("Log formats and messages" and "Anything undocumented" are not public). Adding a sentence is allowed. The FORBIDDEN code and the documented 403 on PUT .../poll/votes already existed; the fix adds a new reason to them and documents it in the OpenAPI text. en/de translations and the errorSentencesA.ts row are there. The vitest catalogue and i18n tests pass.
  • Does "Couldn't vote in this poll." give away the block when a refused post does not? It is the vote's version of the existing reaction refusal "Couldn't react to this message.", which is also raised only by a block. Like the reaction, it tells a block apart from a disabled account (NOTE N1). That adds nothing in practice: account disabling is announced to members (user_update with disabled, internal/events/wire/members.go:8-14), and in an existing 1:1 conversation a refused post next to an active account already means a block. The fix gives away nothing that the reaction door did not already give away.
  • Withdrawing votes stays open (len(optionIDs) == 0 skips the check, store.go:123). I agree, by the documents' own words: moderation.md now says "Taking back stays possible: ... withdraw their votes", and a withdrawal adds nothing, like removing a reaction.
  • Ending one's own poll (POST .../poll/end, internal/poll/handler.go:200-226) stays open after a block. It freezes the poll and puts no new words in front of anybody, so it belongs with "taking back". I agree it stays open, but the new list in moderation.md does not mention it (NOTE N2).
  • Order in Vote: advisory lock, poll row, ended (409) and then the DM check, all before checkChoice and any write. A blocked vote in an ended poll gets 409, like anybody's.

5. The disabled-account side case

Closed for edits (TestNoEditReachesADisabledAccountInAConversationOfTwo; reverted, it fails with 200). Votes and reactions toward a disabled account still succeed (NOTE N1). Nobody can read them while the account is disabled, so this is consistency only.

6. Layering

internal/poll now imports internal/chat/messages for DMBlockedAt. internal/chat/messages does not import internal/poll (the internal/poll that go list -deps shows is the standard library's package). The build has no cycle. The internal/repo tests (boundaries, limits, error catalogue) pass. 18 non-test packages outside the chat tree already import internal/chat/messages (bot, later, media, push, slashcmd, webhook and others), so this is not a new kind of edge.

7. Tests, revert and gates

  • With the fix: TestABlockClosesTheDoorsOfAConversation, TestARefusedEditAfterABlockAnswersLikeARefusedPost, TestABlockLeavesTakingBackOpen and TestNoEditReachesADisabledAccountInAConversationOfTwo pass.
  • With dm_gate.go, message_mutations.go and poll/store.go reverted to the parent: the door table fails on all four new cells (edits and votes, 200) and on the blocker's read, the same-answer test fails (edit 200) and the disabled-account test fails (200). This matches the commit message.
  • The hunter's inverse assertion knownBlockedEdit is gone. The edits are now ordinary 403 cells of the door table. No test was weakened and no allowlist was touched.
  • gofmt clean. go vet (with and without -tags=integration) clean on internal/chat/messages, internal/poll and internal/server. make complexity-check exit 0. check-english-only passes. Unit tests of internal/chat/messages and internal/poll pass. ESLint is clean on errorSentencesA.ts. File sizes are well under the limits (dm_gate.go 248, store.go 256, message_mutations.go 334 lines).
  • Commit type fix:, no !, no AI attribution, English only. The OpenAPI text and the swag annotations match. doc/moderation.md and doc/architecture.md describe the new behaviour.
  • Cost: one primary-key lookup on channels per edit, and two small queries more in a conversation of two. Edits are not a hot path.

Findings

SHOULD-FIX

S1. The chat of a conversation's Talk is outside the pair gate (pre-existing; to be filed as its own lane-3 finding, not added to this commit). A Talk that belongs to a 1:1 conversation is a separate voice channel with dm_id set (internal/chat/talks/talks.go:121). GatePost applies gateDM only when the channel type is dm (dm_gate.go:43), and checkDMEditAllowed returns early for every channel that is not a dm with a dm_key (dm_gate.go:166-172). A block does not end an existing Talk (internal/chat/blocks/blocks.go has no Talk handling). So while a Talk opened before the block still exists (a temporary Talk is removed 30 seconds after its last member leaves, doc/talks.md), both sides can still post and edit in its chat, and the blocker reads it. Measured: post 201, edit 200, and the blocker's GET of the Talk chat returns both texts. The new text in doc/moderation.md ("in a direct message conversation of two, a block stops writing in both directions: new messages ..., edits of earlier messages ...") and the commit message ("a poll vote was the one other open door") overstate what is covered. The fix does not make this worse, and posting there was open before it. Ask for: a separate finding covering posts, edits, reactions and Talk reactions in the chat of a conversation's Talk after a block. Whether voice join is refused was not examined. Either gate those on the conversation's pair, or end the conversation's Talk when a block is set, and say in moderation.md which one.

NOTE

  • N1. Votes and reactions are gated on the block alone, edits on full reachability. DMBlockedAt (dm_gate.go:203-216) checks only user_blocks. checkDMEditAllowed uses checkDMReachable (block, the other side's account active, the DM switch). Measured with the other account disabled and no block: post 403, edit 403, vote 200, reaction 200. The vote copies the reaction's existing behaviour, so this is not a regression, and by the reasoning in section 4 it gives away nothing new. One rule for all four doors would be cleaner. Optional.
  • N2. Ending one's own poll after a block stays open and is not named in moderation.md's new "Taking back stays possible" list. I agree it should stay open (it adds no words). Adding "end their own polls" to the list would make the list complete.
  • N3. Automod runs before the block check for edits as for posts (message_mutations.go:24; service.go:129). A blocked member's edit that also breaks a link or mention rule in a conversation gets automod's 400 and creates a moderation-queue entry, exactly as a refused post does. This is consistent and pre-existing.
  • N4. Block versus a concurrent edit. The block insert takes no lock that the edit transaction waits for, so an edit whose check ran just before a concurrent block commits can still land. It is the same read-committed window that gateDM has for posts, and only a few milliseconds long.
  • N5. Where the check sits. checkDMEditAllowed loads the channel type in a separate query. Joining channels into the message query at message_mutations.go:47 would save a round trip. This is cosmetic.

What I ran

  • git show 33860ed91 and the surrounding code: dm_gate.go, message_mutations.go, handler_messages.go, botapi.go, poll/handler.go, poll/store.go, slashcmd, talks, blocks, automod engine, later reasons, api-stability.md and errormessages_test.go.
  • go test -tags=integration -count=1 -run 'TestABlockClosesTheDoorsOfAConversation|TestARefusedEditAfterABlock|TestABlockLeavesTakingBackOpen|TestNoEditReachesADisabled' ./internal/server with the fix (PASS) and with the production files reverted (FAIL as described).
  • A local probe test file, removed with the worktree. It covered the scheduled send after a block, three slash commands, the edit variants, unblocking, timing, the disabled account with vote and reaction, and the chat of a conversation's Talk.
  • go test ./internal/repo ./internal/chat/messages ./internal/poll, gofmt, go vet with both tag sets, make complexity-check and node scripts/check-english-only.mjs.
  • npm ci in web/, vitest run src/shared/lib/errorDetails.test.ts src/i18n (7 files, 1834 tests pass) and ESLint on errorSentencesA.ts.

What I did not check

  • Whether the live message_update is absent on the blocker's socket after a refused edit (by code: the event is recorded only after a successful EditMessageTx).
  • Voice join, Talk reactions (talk_reaction) and typing indicators after a block.
  • The bot API edit through a real bot token (by code: same EditMessage, and bots are never members of a conversation).
  • Anonymous-poll withdrawals after a block.
  • The web client's handling of the new 403 on edit and vote (by code: the sentence is catalogued and translated; no UI change was made or needed).
  • vue-tsc and the full web suite (only one TS row was added).

Something wrong on this page? Tell us.