Answer not found for a deleted chat channel while its cleanup holds the lock
Why
Integration shard 14 keeps failing on chat-channel-deletion-and-summaries.integration-spec.ts, test "keeps chats out of a deleted destination that a stale cache still lists": it expects CHAT_CHANNEL_NOT_FOUND and gets CHAT_CHANNEL_BUSY. It failed three times in a row on the 2.69.0 version bump PR (#32446) and on unrelated PRs the same day.
Since #32294, deleting a channel queues MoveDeletedAgentChatChannelThreadsJob, which takes the channel's deletion advisory lock while it moves leftover threads to General. A request that files or moves a thread into that channel right after the deletion goes through lockAgentChatChannelForThreadWriteOrThrow, which tried the shared lock first and threw busy before it ever checked that the channel still exists. So a channel that is already gone answered "busy" for as long as its cleanup job ran, in tests (jobs run in-process) and in production.
What
lockAgentChatChannelForThreadWriteOrThrow still tries the lock first, then checks the channel row, and only then decides:
- channel gone:
CHAT_CHANNEL_NOT_FOUND, whether or not the lock was free - channel still there and lock held by a deletion:
CHAT_CHANNEL_BUSY, as before
A deletion in progress keeps its channel row until the end, so writes during a user-triggered deletion still get busy.
The existing util spec is updated for the new order, with one case for a missing channel whose lock is held.
Screenshots
No UI change.