Repository navigation
Conversation
Deleting an automation, or the user who owns it, now removes the queued messages of that automation in the same transaction. The new chatstate transition DeleteQueuedMessagesByAutomation does the removal under the chat row lock, so the queue version, the paused state and the notifications follow the state machine. The delete of an automation no longer refuses while a queued message names it, and it reports a row that is already gone as not found. The delete of a user takes the lock of each automation of the user, soft deletes the user, and then cleans up the chats, in one transaction. A chat in an invalid state refuses the transition. Both deletes then answer 409, name the chat, and change nothing. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-fable-5-2` • Thinking: `xhigh`_
--- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-fable-5-2` • Thinking: `xhigh`_
Tests for a chat that goes away during the cleanup, the order of the chat locks and of the automation locks, a message of the same automation in another chat, the chat update of a user delete, and a caller who cannot delete the user and must not wait for an automation lock. DeleteQueuedMessages no longer returns early for an empty list. The query finds no chat then, so the branch changed nothing. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-fable-5-2` • Thinking: `xhigh`_
Nothing reads how many queued messages the transition removed, so the query and the transition result no longer carry the count. The user delete test now runs as a user admin, who can read neither the automations nor the chats of the user, and the dbauthz test checks the two reads of the cleanup with real roles. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-fable-5-2` • Thinking: `xhigh`_
--- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-fable-5-2` • Thinking: `xhigh`_
…ed message The exhaustruct lint wants every field of the insert parameters. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-fable-5-2` • Thinking: `xhigh`_
…y chats --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-fable-5-2` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…annot promote From P, DeleteQueuedMessagesByAutomation promotes the message behind a removed blocked head. When that message has no usable model config the promotion failed, and so did the delete of the automation or of its owner. The transition now removes the rows and sets the chat to error with its queue (E1). Paused is valid only with a blocked head, so the chat cannot stay paused with a ready one.
…ion row The purge of old chats deletes a chat row and then sets target_chat_id and created_by_chat_id to NULL in the automations that name the chat. Delete removed the automation row first and locked the chats second, which formed a lock cycle with the purge. Delete now cleans the chats first and deletes the row last. Tests: the order against a chat delete on three connections, the publish after the commit, and a paused chat whose next message has no model.
The transition changes the active history when it promotes from P, and it reaches E1 when the next message has no usable model config. The lock order gains its third step, the write of the automation row, with the reason: the purge of old chats locks a chat row before it updates the automations that name the chat.
DeleteOldChats deleted its batch in plan order. A transaction that holds one chat and waits for another one, as the delete of a chat automation does, could then form a lock cycle with the purge. The query now locks the batch in chat ID order before it deletes it.
…mmits The soft delete trigger removes the automation rows and the API keys of the user. The purge of old chats locks API keys before chat rows, and chat rows before automation rows, so no single transaction can hold all three in an order that fits it. The delete of a user now commits the soft delete with the automation locks and no chat row, and then removes the queued messages one chat per transaction. A chat whose cleanup fails is logged and keeps its messages, and the delete still succeeds.
…rge order test A queued message insert writes a new version of the chat row, so the table held the lower chat first and a purge in plan order met it first too. The test now archives the chats after it queues the messages, and it asserts that the table holds the higher chat first.
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
This reverts the change that made the purge lock its batch in chat ID order. The archive and unarchive of a chat family lock the root chat first and then its children, so the new order formed a lock cycle with them. The purge keeps the order that it has on main.
The purge of old chats locks the chats of a batch in the order of its plan. A cleanup that locks two or more chats in one transaction now takes the advisory lock of the purge job first, so the two never run side by side. A cleanup of one chat takes no purge lock. The delete of an automation checks the delete permission before the cleanup, so an actor who can only read the automation gets 403 and no conflict that names a chat. The delete of a user runs its cleanup last, after the notifications and the response status, so a client that goes away during the cleanup changes neither.
|
@codex review |
|
@codex security review |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6717b60267
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // response is written: the cleanup can wait for a chat lock, and a | ||
| // client that goes away meanwhile must change neither. A failure of the | ||
| // cleanup is logged and does not fail the request. | ||
| defer chatautomation.DeleteQueuedMessagesByChat(ctx, api.Logger, api.Database, api.Pubsub, automationIDs) |
There was a problem hiding this comment.
Run queue cleanup outside the request handler
When any affected chat row is locked or the user has many affected chats, this deferred call runs synchronously before deleteUser returns. Because httpapi.Write does not flush the small response explicitly, the client can remain blocked until cleanup finishes or reaches its 30-second timeout even though the user deletion has already committed; the earlier commitAudit defer is also delayed by LIFO ordering. Dispatch this best-effort cleanup to background work rather than holding the HTTP request open.
Useful? React with 👍 / 👎.
Automations (CODAGT-1135) must leave no work behind when they go away. The RFC says: "Disabling or deleting an automation stops new runs and deletes its queued messages in the same transaction." On the base branch the delete route refuses with an internal error while a queued message names the automation, and the soft delete of a user removes that user's automations in a trigger that does not look at the queue. With this PR both deletes remove the queued messages.
Stacked on #32079. Review only this diff. It merges after #32079.
What changes:
DeleteQueuedMessagesByAutomation. It removes every queued message of the chat that one of the given automations queued. Every valid state allows it, archived chats included, and a chat without such a message does not change.chatautomation.DeleteQueuedMessagesruns that transition for each chat that holds such a message, in chat ID order, in the caller's transaction and as the chatd subject. The removal follows from the change to the automation, so it does not depend on what the actor can do to a chat. The function returns the publish step, which the caller runs after the commit. A disable can call it too.chatautomation.Deleteruns one transaction: the automation lock, the delete permission check, the queue cleanup, then the delete of the row. It reads the row count of the delete, so a row that is already gone answers 404 and writes no audit entry.deleteUsertakes two steps. One transaction takes the lock of each automation of the user in ID order (chatautomation.LockByOwner) and soft deletes the user, whose trigger deletes the automation rows. It locks no chat row. After the commit,chatautomation.DeleteQueuedMessagesByChatremoves the queued messages by the IDs read first, one chat per transaction. A queued message keeps the ID of its automation, becausechat_queued_messages.automation_idhas no foreign key. A user without automations takes no lock and runs no cleanup. The cleanup runs last, after the administrators are notified and the response is written, so a client that disconnects during the cleanup changes neither the notification nor the audit status.InsertChatQueuedMessageWithCreatortakesautomation_idandinput_id. No product code sets them yet. The tests seed queued automation messages through them, and the PR that addsPublishis their first writer.db2sdk.ChatWatchEventChat, so thatchatautomationpublishes the chat list event without an import of chatd.Lock order. Every transaction of an automation path takes the automation lock first, then chat rows in chat ID order, and writes the automation row last. The row write comes last because
dbpurgedeletes a chat first, and the same statement then setstarget_chat_idandcreated_by_chat_idto NULL in the automations that name the chat.dbpurgealso locks the chats of a batch in plan order, so it can form a lock cycle with a transaction that holds one chat and waits for another. This PR does not changedbpurge. A cleanup that will lock two or more chats in one transaction first takes the advisory lock of the purge job (LockIDDBPurge), which a purge tick holds from its start to its commit. A tick that finds the lock taken skips, as it does when another replica runs the purge. A cleanup of one chat takes no purge lock. The archive and unarchive of a chat family on main lock the root chat first and then its children. They keep that order: this PR changes no lock order of a main path.deleteUsercannot follow that order in one transaction. The soft delete trigger deletes the automation rows, so it has to come after the chat locks. It also deletes theapi_keysrows of the user, whichdbpurgelocks before it locks chats. So the soft delete commits first and holds no chat row, and each chat is then cleaned in its own transaction.The RFC sentence "in the same transaction" holds for the automation delete. It does not hold for the delete of the owner, which the RFC does not describe. A run takes the automation lock and reads the automation again, so no run queues a message after the soft delete commits. Queued messages of the user's automations stay in three cases:
In each case the chats belong to the deleted user, so nothing runs those messages: a turn in such a chat stops when it cannot create an API key for the user.
One race stays open for the create path, which is not in this base: a create that commits between the read of the automation IDs and the soft delete. The per-owner create lock of #32096 closes it. Of the two PRs, the one that merges second adds that lock to
chatautomation.LockByOwner, the one place that needs it.What a reviewer must know:
POST /api/v2/chats/{chat}/reconcile-invalid.queue_waittrace record.DeleteExternalAuthLinkdoes on main. The user delete reads only automation IDs.chatstate/transition.gois mostly gofmt realignment of the transition table. Review it with whitespace changes hidden.Live check: none. No path queues an automation message yet, so a deployment cannot hold one. The tests seed them in PostgreSQL.
Part of CODAGT-1135
Generated with
xum• Model:anthropic:claude-fable-5-2• Thinking:xhigh