Skip to content

Scope history deletion to the requested target - #2462

Closed
bitbonsai wants to merge 1 commit into
ergochat:masterfrom
bitbonsai:histserv-delete-target
Closed

bitbonsai wants to merge 1 commit into
ergochat:masterfrom
bitbonsai:histserv-delete-target

Conversation

@bitbonsai

@bitbonsai bitbonsai commented Oct 3, 2026 •

Copy link
Copy Markdown

Problem

A single IRC message sent to multiple targets has the same msgid in each target's history. DeleteMessage receives a target and checks permission against it, but persistent-history lookup used only the msgid with LIMIT 1. It could select and delete a copy from another target, leaving the requested copy in place. In some paths, the wrong row could also trigger a permission failure for a valid request.

Deleting every row with that msgid would be worse: it would erase history from targets the delete did not name, without a corresponding REDACT there.

Change

Scope history lookup and deletion by both msgid and the casefolded sequence.target in SQLite, MySQL, and PostgreSQL. Only the requested target's row is affected; copies in other targets remain intact. This keeps the database mutation aligned with the target used for authorization and avoids cross-target data loss.

Regression test TestDeleteMsgidIsTargetScoped stores one msgid under two targets, verifies lookup selects the requested target, deletes that copy, and confirms the unrelated copy remains.

Checked in golang:1.27: go test -tags "i18n mysql postgresql sqlite" ./... and go vet pass; gofmt is clean. MySQL and PostgreSQL were compile-tested, not run against live databases.

I am new to this codebase, so please flag it if I have misunderstood the target-scoping semantics.

Channel deletes and their authorization lookups now use the casefolded
sequence target as well as the msgid. This prevents a copy under another
target from being selected or deleted. Direct-message lookup behavior stays
unchanged.

Add a SQLite regression test with the same msgid under two channel targets;
deleting one target must leave the other copy intact.
@bitbonsai
bitbonsai force-pushed the histserv-delete-target branch from 664a3ad to 5a278e9 Compare October 3, 2026 14:17
@bitbonsai bitbonsai changed the title Delete every history copy for a msgid Scope history deletion to the requested target Oct 3, 2026
@slingamn

slingamn commented Oct 5, 2026

Copy link
Copy Markdown
Member

A single IRC message sent to multiple targets has the same msgid in each target's history.

I cannot reproduce this, e.g.

>>> privmsg #chat,#test :hi
@msgid=zbmw94cut24r5zrh9sisi36p2e;time=2026-10-05T15:30:04.343Z :c!~u@mzye9rsrvmrrc.irc PRIVMSG #chat :hi
@msgid=97fyebhh6s2zbj9z2cjc3rj7yn;time=2026-10-05T15:30:04.349Z :c!~u@mzye9rsrvmrrc.irc PRIVMSG #test :hi

which accords with my understanding of the implementation here:

ergo/irc/handlers.go

Lines 2469 to 2471 in 6e25291

// each target gets distinct msgids
splitMsg := utils.MakeMessage(message)
dispatchMessageToTarget(client, clientOnlyTags, histType, msg.Command, targetString, splitMsg, rb)

@bitbonsai

Copy link
Copy Markdown
Author

You're right, thanks for checking. I misread the multi-target path: MakeMessage runs per target, so each target gets its own msgid and its own history row, and the LIMIT 1 lookup can't hit another channel's copy. The premise of this PR doesn't hold, so I'm closing it.

The one place I found where a msgid does repeat across channels is NICK/QUIT events, since the same item is written to every channel the user is in (nickname.go, client.go in destroy). That seems too niche to be worth target-scoped deletes in three backends, but I'm happy to revisit if you think otherwise.

@bitbonsai bitbonsai closed this Oct 6, 2026
@bitbonsai
bitbonsai deleted the histserv-delete-target branch October 6, 2026 13:27
@slingamn

slingamn commented Oct 6, 2026

Copy link
Copy Markdown
Member

Thanks, I opened #2464 to look into this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants