Fix review of H-L3-12 (a block leaves the chat of the conversation's Talk writable)
From mnema-talk v3.3.13, rendered on this site.
Reviewer: independent reviewer of the fix. I filed the finding (as the reviewer of the H-L3-S1-01 fix) but did not write this fix. Fix: branch msch128/fix-h-l3-12, commit 6be8b17fa on top of 33860ed91, reviewed alone. Phase 2: repro-H-L3-12.md REPRODUCED, refute-H-L3-12.md STANDS (S3, gate the Talk's chat by the pair rule and do not close the Talk). Tests ran in a temporary worktree, which was removed afterwards. Nothing was pushed.
Verdict: MERGE AFTER FIXES
The fix removes the cause for a block. Every pair check asked type = 'dm'. Now the posting gate, the edit
check and the reaction and vote query resolve channels.dm_id to the conversation, so every write door of
the Talk's chat answers a block the way the conversation does. Groups, group Talks, server channels and
server Talks are unchanged (measured). The unread count change is correct and keeps the plan test green.
The docs say what is stopped and what is left.
One fix is needed before merge (SHOULD-FIX S1). The new rule lets edits through when the other member of the pair was erased. That undoes the parent commit's behaviour for the conversation itself, and it is not the "disabled or erased" rule that the code comment, the commit message and moderation.md ("follows the same rule with the same answers") claim. It is a one-line condition. Nobody can read what is written there, so it is not a blocker.
What I checked
1. The cause, at every door (real routes)
gatePost(dm_gate.go:32-50) now readsdm_idin the same primary-key query it already ran. A channel withdm_idand no webhook goes throughcheckPairWritable. Uploads, polls, thread replies, forwards, slash commands and scheduled messages all come throughgatePost.EditMessageTxcallscheckPairWritablefor every channel. The function resolvesCOALESCE(c.dm_id, c.id)to admchannel with adm_key(a conversation of two), or returns nil.DMBlockedAtjoins throughCOALESCE(t.dm_id, t.id), so reactions answerErrDMReactand votes answererrDMVote, the same as in the conversation.- The author's nine cells (post and edit by both sides, reaction, vote, upload, thread reply, forward) ran
as part of
TestABlockClosesTheDoorsOfTheConversationsTalkChat: PASS. The scheduled message is not delivered, and the edit's error body equals the conversation's refused post. - My own probes in the Talk's chat after the block:
| Situation | Result |
|---|---|
/shrug by the blocked member through POST /api/channels/{talk}/interactions | 403 {"code":"FORBIDDEN","message":"Couldn't send this message."}, byte for byte the conversation's refused post |
/me by the blocker in the Talk's chat | 403, same body |
| Other account disabled (no block): post in the Talk's chat | 403, same body. Consistent with the conversation, as intended |
| Other account erased (no block): conversation post / conversation edit / Talk post / Talk edit | 403 / 200 / 201 / 200 (see S1). At the parent 33860ed91: 403 / 403 / 201 / 200 |
2. Groups, group Talks, server channels and server Talks behave as before
Three-member group (carol, alice, bob) with its Talk. Bob blocks alice, and alice writes after the block:
| Door | Status |
|---|---|
| group post / group edit | 201 / 200 |
| group Talk post / group Talk edit | 201 / 200 |
| blocker posts in the group Talk | 201 |
| server text channel post / edit | 201 / 200 |
| server voice channel chat post | 201 |
checkPairWritable's join needs d.dm_key IS NOT NULL, so a group (dm_key NULL) and its Talk return no
row and nothing is checked. The gatePost group path (gateDM) is untouched.
Hot path, by reading:
- Posting in a server channel costs nothing extra:
dm_idis one more column of the primary-key querygatePostalready ran, andtalkOf == nilskips the check. - An edit costs one indexed query (channel joined to channel by primary key). That replaces the parent's one query, so the count does not grow. Edits are not a hot path.
3. The unread change (readstate.go:43-52)
pair.talkis true only for a channel whosedm_idpoints at adm_keyconversation. For such a channel,core.AuthorHiddenFrom("$1", "m.user_id")(NOT EXISTSa block by the reader) leaves out blocked authors. I checked the polarity: block_sql.go:13-16.- Measured, blocker bob, blocked alice wrote 2 messages:
| Talk | No block | After the block |
|---|---|---|
| Talk of the pair | 2 | 0 |
| Talk of a group | 2 | 2 (unchanged) |
- Unblocked members' counts are unchanged.
TestUnreadLookupsUseTheChannelIndexInAHugeChannelpasses (50,000 messages, the plan still uses the channel index; 214 ms for 600 unread and 173 ms for 50,000 unread, locally). For a channel withoutdm_id, the new lateral is a constant false. I did not compare a timing against the parent.
4. What a refused write reveals
- Every refusal in the Talk's chat (post, edit, slash command, disabled account) is the conversation's own
403
FORBIDDEN "Couldn't send this message.". Reactions and votes give the conversation's own sentences. The blocked member learns nothing beyond the conversation's 403, which they get anyway. - The Talk, its seats and voice are untouched (refuter's direction), so a block sends no event to the blocked member.
- As in the conversation, reactions and votes check the block alone (NOTE N1 of fixreview-H-L3-S1-01). This is not new.
5. Documents
- doc/moderation.md: the chat of a Talk open before the block "follows the same rule with the same answers"; it adds the unread rule, says taking back is open in both, and that the Talk, seats and voice stay ("removing them would tell the blocked member").
- doc/architecture.md: "in the chat of the conversation's Talk too", and the Talk and its seats are not touched.
- doc/talks.md: "Its chat follows the conversation's writing rule", with a link to the blocking section.
- These match the behaviour for blocks and disabled accounts. They do not match it for an erased account (S1).
- The OpenAPI 403 texts of edit and vote name the Talk's chat. The swag annotations and openapi.json agree.
6. Revert check
With dm_gate.go, message_mutations.go and readstate.go reverted to 33860ed91,
TestABlockClosesTheDoorsOfTheConversationsTalkChat fails on:
- all nine cells (201/200 instead of 403);
- the error body (empty instead of FORBIDDEN);
- the unread count (2);
- both texts the blocker reads ("edited after the block", "later words").
TestABlockLeavesTakingBackOpenInTheTalkChat passes both ways. It pins what stays open, so it is
expected to pass on the parent. With the fix in place, both pass.
7. Gates
- gofmt is clean. go vet is clean with and without
-tags=integrationon the touched packages.make complexity-checkexit 0.check-english-onlypasses. - Unit tests of internal/repo, internal/chat/messages, internal/chat/readstate and internal/poll pass.
- Sizes: dm_gate.go 277, readstate.go 203, new test 123 lines.
- The neighbouring tests pass, including those of 33860ed91 and the erase test.
- Commit type is
fix:, with no!and no AI attribution.
Findings
SHOULD-FIX
S1. An erased other member no longer closes the conversation of two to edits, and never closed the Talk's
chat. (internal/chat/messages/dm_gate.go, checkPairWritable: if (!on && !talk) || active != len(others) || blocked > 0.)
- Erasing an account deletes its
dm_membersrows (internal/chat/account/account_erase.go:52). The pair stays for the survivor, because it is not a sole conversation. othersis then empty:active(0) equalslen(others)(0), so the write passes.checkDMReachable, which the parent used for edits, also refusesactive == 0.
Measured after erasing alice:
| Bob's write | Parent 33860ed91 | This fix |
|---|---|---|
| Post in the conversation | 403 | 403 |
| Edit in the conversation | 403 | 200 |
| Post in the Talk's chat | 201 | 201 |
| Edit in the Talk's chat | 200 | 200 |
This contradicts:
- the function's own comment ("the other side's account disabled or erased, refuses");
- the commit message;
- moderation.md's "the same rule with the same answers";
- the conversation's own post rule.
No one but the survivor can read these messages, so this is consistency, not exposure. Fix: refuse when
nobody else is there, e.g. len(others) == 0 || active != len(others) || .... Add one cell (erase the
other side, then edit in the conversation and post in the Talk's chat: 403) next to
TestNoEditReachesADisabledAccountInAConversationOfTwo.
NOTE
- N1. Once the Talk's chat answers 403 to everything, a pair Talk stays in the sidebar after a block with a chat nobody can write in, until it empties. This is intended (the refuter's direction) and documented. The web client may show a composer that always refuses there. That is UI, not examined.
- N2.
gatePostskips the pair check fornm.WebhookID != nil. Webhooks cannot target a channel withdm_id(internal/webhook/handler.go:106 refuses it), so this is unreachable. The skip is consistent withgateDM, which refuses webhooks outright. A refusal there instead of a skip would fail closed. Optional.
What I ran
git show 6be8b17faand the surrounding code: dm_gate.go, message_mutations.go, readstate.go, block_sql.go, account_erase.go and webhook/handler.go.go test -tags=integration -count=1 -run '...TalkChat|TestABlockClosesTheDoorsOfAConversation$|TestARefusedEditAfterABlock|TestABlockLeavesTakingBackOpen$|TestNoEditReachesADisabled|TestErasingAnAccount|TestUnreadLookupsUseTheChannelIndex' ./internal/server: PASS with the fix, and the revert check as above.- A local probe file (removed with the worktree). It covered slash commands in the Talk's chat, the disabled and erased other side, the group, group Talk, server text and server voice doors, and unread in pair and group Talks with and without a block.
- gofmt, go vet with both tag sets,
make complexity-check,check-english-only, and the unit tests of the touched packages plus internal/repo.
What I did not check
- Voice, seats and talk_reaction after a block. These are unchanged on purpose, and I did not run them (no media on this machine).
- Mention counts in the Talk's chat. Blocked authors were already left out of mentions everywhere, and the diff does not touch that path.
- Push for the Talk's chat after a block.
- The web client in a pair Talk after a block.
- A timing comparison of
GET /api/read-stateagainst the parent. - The bot API edit path. By code it is the same
EditMessage, and bots cannot see a pair's Talk.
Second round: commit 7969e95e0 (the delta alone)
Verdict for the delta: MERGE. S1 is fixed. An erased or disabled partner now closes the conversation of two and the chat of its Talk to posts and edits, with the conversation's own 403. Taking back stays open.
What changed
checkPairWritable (internal/chat/messages/dm_gate.go:209) now also refuses when no other member is left:
len(others) == 0. The comment explains the erased case. The commit adds
TestNoWriteReachesAnErasedAccountInAConversationOfTwoOrItsTalk, with four cells, and adds one sentence
to doc/moderation.md ("New messages and edits in both are refused the same way when the other side's account
is disabled or erased").
What I ran
My erased-partner probe, repeated. The erased side is alice and the survivor is bob, which is the reverse of the author's test. Bob tries to write in the conversation and in the Talk's chat:
Bob's write Result Post in the conversation 403 Edit in the conversation 403 Post in the Talk's chat 403 Edit in the Talk's chat 403 Every refusal is
{"code":"FORBIDDEN","message":"Couldn't send this message."}. In the first round these were 403 / 200 / 201 / 200. The survivor can still delete his own message in the Talk's chat (204), so taking back stays open.Disabled partner in the Talk's chat (the author did not test this). Bob is disabled and there is no block:
Alice's write in the Talk's chat Result Post while bob is disabled 403, same body Edit while bob is disabled 403, same body Post after bob is enabled again 201 The refusal follows the account state and leaves nothing behind.
Revert check. I removed the new condition from the code and kept the tests. The new test then fails on three cells (conversation edit 200, Talk post 201, Talk edit 200). The conversation post stays 403 through
gateDM, as the commit message says. My probe shows the same 403 / 200 / 201 / 200 as in the first round. After restoring the condition, both pass.Neighbouring tests, all PASS:
- TestABlockClosesTheDoorsOfTheConversationsTalkChat
- TestABlockLeavesTakingBackOpenInTheTalkChat
- TestNoEditReachesADisabledAccountInAConversationOfTwo
- TestABlockClosesTheDoorsOfAConversation
- the TestErasingAnAccount* tests
- TestTalkChatNeedsNoCallMembership
- TestPrivateTalkChatStaysHidden
Gates: gofmt is clean, go vet with
-tags=integrationis clean,make complexity-checkexit 0, andcheck-english-onlypasses. The commit type isfix:, with no AI attribution.
Side cases, by reading
- Can the new condition refuse a legitimate write? A conversation of two with one member left
otherwise only exists after the other member leaves. A post there was already refused (
gateDM,active == 0), so refusing edits too is consistent. Nobody can start a conversation with themselves: dm.go:292 answers "user_ids must not contain yourself". - Groups and their Talks are not reached. Their
dm_keyis NULL, socheckPairWritablereturns nil before this condition is evaluated.
Not checked in this round
An account erased while a voice seat is held in the Talk (voice is unchanged by design; not run).