Repository navigation
AI-3226: delete a branch copy when Chat deletes its message - #2677
Conversation
A message.deleted from Stream Chat's delivery or the message webhook now deletes the router's copies of that message: those of the sessions on its conversation in the hook's app (and customer, when the hook names one), with the changes recorded of them emptied, on every shard through a shard job. A delete_for_me deletes nothing. It is done on the request and not checked for staleness, so a late or repeated delivery still deletes, and a failed delete is a 503 Stream delivers again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/jeffery review |
|
Thanks for asking Jeffery for review. I'll stay on this PR until I can approve it. How it works
Commands (each as a whole comment)
|
There was a problem hiding this comment.
✅ Approved dc4035ce38d9 after 1 round
Left open, your call:
- consider: Delete is answered 200 and dropped before the router knows its own app (
acceleration/internal/api/messagehooks.go:220) - consider: Every delete and redelivery queues a new job on every shard (
acceleration/internal/store/branch_message.go:162)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/jeffery review |
Withdrawing approval until a94a841 is reviewed.
…estion An activation sends a copy again as a new message naming it (resent_from), and the newest copy of a chain is what a branch shows. A delete now takes every copy on the chain within the conversation, seeded from the deleted message's own resent_from, so a deleted message sent again is not brought back from the copy it was sent from. A deleted question's response no longer says what was asked. The delete reads the conversation's copies, deletes with RETURNING and forgets only what it deleted; on shards it queues the job only when the session index places the conversation on another shard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A switch finished again now sends what Chat does not hold yet instead of what follows the count, since a copy deleted after it began shifts the rest, and one whose copies are all gone finishes with nothing to send. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Withdrawing approval until 7f7223b is reviewed.
There was a problem hiding this comment.
Round 3 on 7f7223b04bb8 · 🆕 1 new
Still open: 1 should-fix. Full list on the checks tab.
There was a problem hiding this comment.
✅ Approved 7f7223b04bb8 after 3 rounds · 1 fixed · 1 dropped after discussion
Left open, your call:
- should-fix: Activation finishes with nothing resent when the target's own copy is deleted (
acceleration/internal/session/branches.go:1027)
|
/jeffery review |
Nothing changed since round 3 on |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Withdrawing approval until 8fd14df is reviewed.
|
/jeffery review |
Nothing changed since round 4 on |
Why
https://linear.app/stream/issue/AI-3226/delete-a-branch-snapshot-when-its-hidden-chat-message-is-deleted
AI-3198 keeps a router-side copy of every Chat message a regenerate, edit or branch switch hides. A server-side delete of a hidden message never reached the router, so the copy was still shown on ‹ i/n › and sent again when its branch was activated. AI-3198 shipped with that as a documented limitation.
What changed
message.deletedis handled on both paths: Stream Chat's signed delivery (receiveChatInbound) and the message webhook (receiveMessageEvent). Both callreceiveDeletedMessage(internal/api/messagedeleted.go).addressedInand the chat_inbound queue.deleted_for_medeletes nothing.BranchMessages.DeleteMessage(internal/store/branch_message.go) deletes the copies of that message id in the sessions on the conversation (conversation_id=<channel_type>:<channel_id>) within the hook's app (AppScopeonstream_app_pk). When the hook names a customer, it is limited to that customer's sessions.data_changesof those copies too, asDeleteUserandSessions.Deletedo, because they hold the same words.delete_branch_message, and runs this shard's part at once, asDeleteUserdoes. Other shards run theirs from their workers.shard_jobs.kindhas no CHECK constraint, so no migration is needed. A router that does not know the kind leaves its run queued until it is upgraded.agent_sessions_conversation_idxplus the PK. Without one (a hook from the deployment's own app), it scansagent_branch_messages_pkeyonoriginal_message_idand joinsagent_sessions_pkey. Neither plan is a sequential scan.custom.resent_from = m1, andchosenForshows the newest copy per root. A delete therefore takes every copy on that chain within the conversation, seeded from the deleted message's ownresent_from. This covers a hidden m2, and a visible m2, which has no copy of its own.said, so the switcher does not show the question's text.RETURNING, anddata_changesandsaidare updated only for the rows it returns, so a delete with no copy writes nothing. On shards the job is queued only whensession_indexlists a session on the conversation on another shard. With no customer, the index cannot be read, so the job is still queued. No migration was needed: on PG 19 the no-customer path finds its sessions by a skip scan ofagent_sessions_conversation_idx.alreadyResent) instead of resuming at the positional count, because a copy deleted mid-way shifts the rest. An unfinished activation sends what is still kept of its branch and finishes with nothing to send only when nothing is kept. Before, theErrBranchGonefrom the target's own copies failed the resume.receiveChatDeliverydescription is updated inopenapi.yaml, and the Go and JS clients are regenerated (description text only). The JS README's branch limits now say that deleting a hidden message through Chat deletes the router's copy.message.deleted.Not covered (follow-up AI-4307)
message.deleted, so they do not reach the router: user deletion, truncate, channel delete, ban with delete, and moderation actions.Both are stated in the JS README.
Deploy order
Deploy this PR first, then GetStream/chat#21956.
message.deletedthrough the agents-router delivery.message.deletedfor rewound messages to webhooks.Tests
internal/store/branch_message_test.go(StoreSuite and ShardedStoreSuite):said, and an answer's copy leavessaidalone.internal/api/chatinbound_deleted_router_test.go:deleted_for_mekeeps the copy.resent_fromin the event) deletes the copy it was sent from.hookStaleAfterstill deletes.internal/conversation/branches_switch_test.go: an activation stopped mid-way whose sent copy was deleted sends the rest. It fails with the positional resume.internal/session/branches_test.go: an unfinished activation whose copies were deleted has nothing to send. It fails without theErrBranchGonemapping. Also: an unfinished activation whose target's own copies were deleted still sends the rest of its branch. That test fails when the resume answers the empty set.deleted_for_meand no-copy tests pass, since they guard against deleting too much.saidtests (store and handler) fail with the delete limited to the message id and without thesaidupdate, which is the previous head's behaviour. Mutants are caught: dropping thedeleted_for_mecheck, the own-app wait, the app scope, the customer filter, thedata_changesCTE, or the shard-job run each fails at least one test.go test -tags integration ./internal/api -run 'TestChatInbound|TestMessageHook|TestBranch',go test ./internal/apiandgo vetare clean.Overlapping open PRs, with small diffs here: #2532 and #2635 (
chatinbound.go/messagehooks.go), #2381 (handwritten.go), #2167 and #2667 (sdks/js/README.md).🤖 Generated with Claude Code